|
|
@ -14,12 +14,12 @@ |
|
|
|
char buf[BUF_SIZE]; |
|
|
|
char buf[BUF_SIZE]; |
|
|
|
|
|
|
|
|
|
|
|
/* FD's */ |
|
|
|
/* FD's */ |
|
|
|
int in; |
|
|
|
FILE *in; |
|
|
|
int out; |
|
|
|
FILE *out; |
|
|
|
|
|
|
|
|
|
|
|
void (*handler)(int); |
|
|
|
void (*handler)(void); |
|
|
|
|
|
|
|
|
|
|
|
void (*select_handler(char chr))(int) |
|
|
|
void (*select_handler(char chr))(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
handler = NULL; |
|
|
|
handler = NULL; |
|
|
|
|
|
|
|
|
|
|
@ -48,25 +48,13 @@ main(int argc, char **argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int chr = '\0'; |
|
|
|
int chr = '\0'; |
|
|
|
|
|
|
|
|
|
|
|
in = dup(0); |
|
|
|
in = stdin; |
|
|
|
out = dup(1); |
|
|
|
out = stdout; |
|
|
|
|
|
|
|
|
|
|
|
read(in, &chr, 1); |
|
|
|
while ((chr = fgetc(in)) != EOF); |
|
|
|
if (chr != 'd') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fprintf(stderr, "Malformed torrent file\n"); |
|
|
|
|
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* some work here */ |
|
|
|
|
|
|
|
while (true) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
handler = select_handler(chr); |
|
|
|
handler = select_handler(chr); |
|
|
|
|
|
|
|
handler(); |
|
|
|
if (handler == NULL) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler(in); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
exit(EXIT_SUCCESS); |
|
|
|