fordítás
Elküldve: 2019.05.31. 14:30
Kód: Egész kijelölése
./configure --prefix=/usr --enable-shared --enable-gpl --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libdc1394 --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-zlib --enable-postproc --disable-debug --enable-bzlib --enable-version3 --enable-libtheora --enable-swscale --enable-libcdio --enable-libxvid --disable-libcaca --enable-fontconfig --enable-opengl --enable-openssl --enable-ffplay --enable-sdl2
Kód: Egész kijelölése
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAXC 1024 /* if you need a constant, #define one (or more) */
#define NPTRS 2 /* initial no. of pointers to allocate (lines) */
int main (int argc, char **argv) {
int found = 0;
char *p = strrchr(argv[1], '.');
if (p){
char buf[MAXC], /* fixed buffer to read each line */
**lines = NULL; /* pointer to pointer to hold collection of lines */
size_t nptrs = NPTRS, /* number of pointers available */
used = 0; /* number of pointers used */
/* use filename provided as 1st argument (stdin by default) */
FILE *fp = argc > 1 ? fopen ("kacsa.txt", "r") : stdin;
if (!fp) { /* validate file open for reading */
printf("%s\n", "kacsa.txt needed next to this binary: 1st line: PATH program, 2nd line: FULLPATH program!");
perror ("file open failed");
return 1;
}
/* allocate/validate block holding initial nptrs pointers */
if ((lines = malloc (nptrs * sizeof *lines)) == NULL) {
perror ("malloc-lines");
exit (EXIT_FAILURE);
}
while (fgets (buf, MAXC, fp)) { /* read each line into buf */
size_t len;
buf[(len = strcspn (buf, "\n"))] = 0; /* trim \n, save length */
if (used == nptrs) { /* check if realloc of lines needed */
/* always realloc using temporary pointer (doubling no. of pointers) */
void *tmp = realloc (lines, (2 * nptrs) * sizeof *lines);
if (!tmp) { /* validate reallocation */
perror ("realloc-lines");
break; /* don't exit, lines still good */
}
lines = tmp; /* assign reallocated block to lines */
nptrs *= 2; /* update no. of pointers allocatd */
/* (optionally) zero all newly allocated memory here */
}
/* allocate/validate storage for line */
if (!(lines[used] = malloc (len + 1))) {
perror ("malloc-lines[used]");
break;
}
memcpy (lines[used], buf, len + 1); /* copy line from buf to lines[used] */
used += 1; /* increment used pointer count */
}
/* (optionally) realloc to 'used' pointers to size no. of pointers exactly here */
if (fp != stdin) /* close file if not stdin */
fclose (fp);
/* use lines as needed (simply outputting here) */
/*
for (size_t i = 0; i < used; i++) {
printf ("line[%3zu] : %s\n", i, lines[i]);
free (lines[i]);
}
*/
//printf("%d\n",found);
if(strcmp(p, ".m3u") == 0 || strcmp(p, ".m3u8") == 0 || strcmp(p, ".xspf") == 0){
found = 1;
printf("%d\n",found);
} else {
found = 0;
printf("%d\n",found);
}
if(found == 1){
//printf("%s\n", lines[0]);
char *programName = lines[0];
char *arg1 = "";
execlp(programName, programName, argv[1], NULL);
} else {
char *binaryPath = lines[1];
char *arg1i = "";
execl(binaryPath, binaryPath, argv[1], NULL);
}
free (lines); /* free pointers when done */
}
return 0;
}
Kód: Egész kijelölése
gcc teszt.c -o teszt
Kód: Egész kijelölése
#include <gtk/gtk.h>
#include <stdlib.h>
#include <unistd.h>
static int counter = 0;
void greet(GtkWidget* widget, gpointer data)
{
// printf equivalent in GTK+
g_print("Welcome to GTK\n");
g_print("%s clicked %d times\n",
(char*)data, ++counter);
//int status = system("./fofi8");
char *programName = "fofi8";
char *arg1 = "";
char *arg2 = "";
execlp(programName, programName, arg1, arg2, NULL);
}
void greeti(GtkWidget* widget, gpointer data)
{
// printf equivalent in GTK+
g_print("Welcome to GTKi\n");
g_print("%s clicked %d times\n",
(char*)data, ++counter);
//int status = system("./fofi8");
char *binaryPath = "./s4fofi8p_v1_beta.sh";
char *arg1i = "";
char *arg2i = "";
execl(binaryPath, binaryPath, arg1i, arg2i, NULL);
}
/*
to compile:
gcc cukor.c -o cukorc `pkg-config --cflags --libs gtk+-2.0`
*/
void destroy(GtkWidget* widget, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* vbox;
GtkWidget* button;
GtkWidget* buttoni;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 230, 250);
gtk_window_set_title(GTK_WINDOW(window), "cukorka");
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(window, "destroy",
G_CALLBACK(destroy), NULL);
/* Let's set the border width of the window to 20.
* You may play with the value and see the
* difference. */
vbox = gtk_vbox_new(TRUE, 1);
gtk_container_add(GTK_CONTAINER(window), vbox);
button = gtk_button_new_with_label("fofi8");
buttoni = gtk_button_new_with_label("s4fofi8p_v1_beta.sh");
g_signal_connect(GTK_OBJECT(button),
"clicked", G_CALLBACK(greet),
"button");
g_signal_connect(GTK_OBJECT(buttoni),
"clicked", G_CALLBACK(greeti),
"buttoni");
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), buttoni, TRUE, TRUE, 0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Kód: Egész kijelölése
gcc cukor.c -o cukorc `pkg-config --cflags --libs gtk+-2.0`
Kód: Egész kijelölése
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <libgen.h>
#define MAXC 1024 /* if you need a constant, #define one (or more) */
#define NPTRS 2 /* initial no. of pointers to allocate (lines) */
int main (int argc, char **argv) {
/*
char *symlinkpath = "kacsa.txt";
char actualpath [PATH_MAX+1];
char *ptr;
ptr = realpath(symlinkpath, actualpath);
*/
char datadir[PATH_MAX];
strncpy(datadir, argv[0], sizeof(datadir));
dirname(datadir);
strncat(datadir, "/kacsa.txt", sizeof(datadir));
int found = 0;
char *p = strrchr(argv[1], '.');
if (p){
char buf[MAXC], /* fixed buffer to read each line */
**lines = NULL; /* pointer to pointer to hold collection of lines */
size_t nptrs = NPTRS, /* number of pointers available */
used = 0; /* number of pointers used */
/* use filename provided as 1st argument (stdin by default) */
FILE *fp = argc > 1 ? fopen (datadir, "r") : stdin;
if (!fp) { /* validate file open for reading */
printf("%s\n", "kacsa.txt needed next to this binary: 1st line: PATH program, 2nd line: FULLPATH program!");
perror ("file open failed");
return 1;
}
/* allocate/validate block holding initial nptrs pointers */
if ((lines = malloc (nptrs * sizeof *lines)) == NULL) {
perror ("malloc-lines");
exit (EXIT_FAILURE);
}
while (fgets (buf, MAXC, fp)) { /* read each line into buf */
size_t len;
buf[(len = strcspn (buf, "\n"))] = 0; /* trim \n, save length */
if (used == nptrs) { /* check if realloc of lines needed */
/* always realloc using temporary pointer (doubling no. of pointers) */
void *tmp = realloc (lines, (2 * nptrs) * sizeof *lines);
if (!tmp) { /* validate reallocation */
perror ("realloc-lines");
break; /* don't exit, lines still good */
}
lines = tmp; /* assign reallocated block to lines */
nptrs *= 2; /* update no. of pointers allocatd */
/* (optionally) zero all newly allocated memory here */
}
/* allocate/validate storage for line */
if (!(lines[used] = malloc (len + 1))) {
perror ("malloc-lines[used]");
break;
}
memcpy (lines[used], buf, len + 1); /* copy line from buf to lines[used] */
used += 1; /* increment used pointer count */
}
/* (optionally) realloc to 'used' pointers to size no. of pointers exactly here */
if (fp != stdin) /* close file if not stdin */
fclose (fp);
/* use lines as needed (simply outputting here) */
/*
for (size_t i = 0; i < used; i++) {
printf ("line[%3zu] : %s\n", i, lines[i]);
free (lines[i]);
}
*/
//printf("%d\n",found);
if(strcmp(p, ".m3u") == 0 || strcmp(p, ".m3u8") == 0 || strcmp(p, ".xspf") == 0){
found = 1;
printf("%d\n",found);
} else {
found = 0;
printf("%d\n",found);
}
if(found == 1){
//printf("%s\n", lines[0]);
char *programName = lines[0];
char *arg1 = "";
execlp(programName, programName, argv[1], NULL);
} else {
char *binaryPath = lines[1];
char *arg1i = "";
execl(binaryPath, binaryPath, argv[1], NULL);
}
free (lines); /* free pointers when done */
}
// free(actualpath);
return 0;
}
Kód: Egész kijelölése
gcc teszt.c -o teszt
Kód: Egész kijelölése
fofi8
/root/my-applications/bin/gui_mpv