X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FFortuneParse.c;h=24dabd1a51c2cbd0e873a8612b264cbb30d475e9;hp=962ffc53e78da873abd07a96889086c09a114db0;hb=7463fc5258c5afb139286c2509f5161bc0d76290;hpb=198add70c8604fe7ffb05689aa693d782102917e diff --git a/sources/FortuneParse.c b/sources/FortuneParse.c index 962ffc5..24dabd1 100644 --- a/sources/FortuneParse.c +++ b/sources/FortuneParse.c @@ -28,7 +28,7 @@ * Read n fortunes from fortune file file, and put it into the * string array fortune * - * $Id: FortuneParse.c,v 1.1 2002/08/18 10:34:10 piccardi Exp $ + * $Id: FortuneParse.c,v 1.2 2002/08/18 14:38:04 piccardi Exp $ * ****************************************************************/ /* @@ -43,6 +43,8 @@ #include /* error definitions */ #include /* */ +#include "macros.h" + /* Subroutines declaration */ extern void usage(void); @@ -51,7 +53,7 @@ int FortuneParse(char *file, char **fortune, int n) /* Variables definition */ FILE *fortunefile; char line[80]; - int i; + int i, len; /* * fortune file scanning, read string in memory */ @@ -67,16 +69,18 @@ int FortuneParse(char *file, char **fortune, int n) perror("Read error"); exit(-1); } - if (line[0]=='\n') { + debug("i=%d, line=%s", i, line); + if (line[0]=='%') { if (fortune[i]!=NULL) i++; continue; } + len = strlen(line) + 1; if (fortune[i]==NULL) { - fortune[i] = (char *) malloc(strlen(line)+1); - strncpy(fortune[i], line, strlen(line)+1); + fortune[i] = malloc(len); + strncpy(fortune[i], line, len); } else { - fortune[i] = (char *) realloc(fortune[i], strlen(line)+1); - strncat(fortune[i], line, strlen(line)+1); + fortune[i] = realloc(fortune[i], strlen(fortune[i])+len+1); + strncat(fortune[i], line, len); } } while (i