projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Alcune aggiunte alla tabella degli header
[gapil.git]
/
sources
/
FortuneParse.c
diff --git
a/sources/FortuneParse.c
b/sources/FortuneParse.c
index 962ffc53e78da873abd07a96889086c09a114db0..24dabd1a51c2cbd0e873a8612b264cbb30d475e9 100644
(file)
--- 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
*
* 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 <errno.h> /* error definitions */
#include <fcntl.h> /* */
#include <errno.h> /* error definitions */
#include <fcntl.h> /* */
+#include "macros.h"
+
/* Subroutines declaration */
extern void usage(void);
/* 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];
/* Variables definition */
FILE *fortunefile;
char line[80];
- int i;
+ int i
, len
;
/*
* fortune file scanning, read string in memory
*/
/*
* fortune file scanning, read string in memory
*/
@@
-67,16
+69,18
@@
int FortuneParse(char *file, char **fortune, int n)
perror("Read error");
exit(-1);
}
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;
}
if (fortune[i]!=NULL) i++;
continue;
}
+ len = strlen(line) + 1;
if (fortune[i]==NULL) {
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 {
} 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<n);
return i;
}
} while (i<n);
return i;