Ticket #1475: fortune.diff
File fortune.diff, 954 bytes (added by , 17 years ago) |
---|
-
src/bin/fortune.c
13 13 14 14 #include <OS.h> 15 15 16 #define FORTUNES "/etc/fortunes "16 #define FORTUNES "/etc/fortunes/default" 17 17 18 18 int 19 19 main(void) … … 49 49 50 50 found = 0; 51 51 for (i = 0; i < stat.st_size; i++) { 52 if (!strncmp(buf + i, " #@#", 3))52 if (!strncmp(buf + i, "%\n", 2)) 53 53 found += 1; 54 54 } 55 55 56 56 if (found > 0) 57 found = 1 + ((system_time() + 3) % found);57 found = 1 + ((system_time() + 1) % found); 58 58 else { 59 59 printf("Out of cookies...\n"); 60 60 return -1; 61 61 } 62 62 63 63 for (i = 0; i < stat.st_size; i++) { 64 if (!strncmp(buf + i, " #@#", 3))64 if (!strncmp(buf + i, "%\n", 2)) 65 65 found -= 1; 66 66 67 67 if (found == 0) { 68 68 unsigned j; 69 69 70 70 for (j = i + 1; j < stat.st_size; j++) { 71 if (!strncmp(buf + j, " #@#", 3))71 if (!strncmp(buf + j, "\n%\n", 3)) 72 72 buf[j] = 0; 73 73 } 74 74 75 printf("%s\n", buf + i + 3);75 printf("%s\n", buf + i + 1); 76 76 break; 77 77 } 78 78 }