summaryrefslogtreecommitdiff
path: root/substrings.c
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2010-03-04 12:50:21 +0000
committerCaolán McNamara <caolanm@redhat.com>2010-03-04 12:50:21 +0000
commit7107dea0c0b64d5f0dc1b7b0c80734ca19a5f5c4 (patch)
treed4134d5ac15a4220f8efa10bae2c6f612bae48af /substrings.c
parent5020b64b0ec461c18c545b868148841a0bb4904b (diff)
downloadhyphen-7107dea0c0b64d5f0dc1b7b0c80734ca19a5f5c4.tar.gz
hun#1724558 tidy substrings.c a little
Diffstat (limited to 'substrings.c')
-rw-r--r--substrings.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/substrings.c b/substrings.c
index 1922db1..3ed6d84 100644
--- a/substrings.c
+++ b/substrings.c
@@ -180,7 +180,7 @@ int main(int argc, const char* argv[]) {
if ((in = fopen(argv[1],"r"))==NULL) die("Could not read input");
if ((out = fopen(argv[2],"w"))==NULL) die("Could not create output");
// read all patterns and split in pure text (_key) & expanded patterns (_val)
- while(fgets(format,132,in)) {
+ while(fgets(format,132,in) != NULL) {
int l = strlen(format);
if (format[l-1]=='\n') { l--; format[l]=0; } // Chomp
if (format[0]=='%' || format[0]==0) {
@@ -193,6 +193,7 @@ int main(int argc, const char* argv[]) {
int i,j;
char *pat = (char*) malloc(l+1);
char *org = (char*) malloc(l*2+1);
+ if (pat==NULL || org==NULL) die("not enough memory");
expand(org,format,l);
// remove hyphenation encoders (digits) from pat
for (i=0,j=0; i<l; i++) {
@@ -224,10 +225,12 @@ int main(int argc, const char* argv[]) {
if ((subpat_ndx = find_in(pattab_key,patterns,subpat))>=0) {
int newpat_ndx;
char *newpat=malloc(l+1);
+ if (newpat==NULL) die("not enough memory");
//printf("%s is embedded in %s\n",pattab_val[subpat_ndx],pattab_val[p]);
strncpy(newpat, pat+0,l); newpat[l]=0;
if ((newpat_ndx = find_in(newpattab_key,newpatterns,newpat))<0) {
char *neworg = malloc(132); // TODO: compute exact length
+ if (neworg==NULL) die("not enough memory");
expand(neworg,newpat,l);
newpattab_key[newpatterns] = newpat;
newpattab_val[newpatterns++] = combine(neworg,pattab_val[subpat_ndx]);