build fix (trunk only)
The recent SYSCF patch introduced a build problem even though I
haven't attempt to use that new stuff yet. My compiler complained that
`out' in build_english_list() was used without being initialized, which
in turn caused make to quit. The compiler was right; only the words==1
case actually set up the output buffer. Once that buffer was fixed, the
routine to copy a single word was overwriting it on each call instead of
building up via appending as intended.
I changed the 3 or more case to yield "A, B, or C" like Keni wrote
in his description rather than the "A, B or C" which was being produced.
I'm pretty sure that both forms are considered acceptible; I've always
used the first one with an extra comma in front of and/or.
This commit is contained in:
41
src/end.c
41
src/end.c
@@ -1330,10 +1330,11 @@ bel_copy1(inp, out)
|
||||
char **inp, *out;
|
||||
{
|
||||
char *in = *inp;
|
||||
|
||||
out += strlen(out); /* eos() */
|
||||
while(*in && isspace(*in)) in++;
|
||||
while(*in && !isspace(*in)){
|
||||
*out = *in; out++; in++;
|
||||
}
|
||||
while(*in && !isspace(*in)) *out++ = *in++;
|
||||
*out = '\0';
|
||||
*inp = in;
|
||||
}
|
||||
|
||||
@@ -1341,29 +1342,39 @@ char *
|
||||
build_english_list(in)
|
||||
char *in;
|
||||
{
|
||||
char *out;
|
||||
int len = strlen(in);
|
||||
char *p = in;
|
||||
int words = wordcount(in);
|
||||
char *out, *p = in;
|
||||
int len = (int)strlen(p), words = wordcount(p);
|
||||
|
||||
/* +3: " or " - " "; +(words - 1): (N-1)*(", " - " ") */
|
||||
if (words > 1) len += 3 + (words - 1);
|
||||
out = (char *)alloc(len + 1);
|
||||
*out = '\0'; /* bel_copy1() appends */
|
||||
|
||||
switch(words){
|
||||
case 0:
|
||||
impossible("no words in list");
|
||||
break;
|
||||
case 1:
|
||||
out = (char *)alloc(len+1);
|
||||
strcpy(out, in);
|
||||
/* "single" */
|
||||
bel_copy1(&p, out);
|
||||
break;
|
||||
default:
|
||||
len += 3 + (words-1);
|
||||
bel_copy1(&p, out); words--;
|
||||
while(words>1){
|
||||
strcat(out, ", ");
|
||||
bel_copy1(&p, out); words--;
|
||||
if (words == 2) {
|
||||
/* "first or second" */
|
||||
bel_copy1(&p, out);
|
||||
Strcat(out, " ");
|
||||
} else {
|
||||
/* "first, second, or third */
|
||||
do {
|
||||
bel_copy1(&p, out);
|
||||
Strcat(out, ", ");
|
||||
} while (--words > 1);
|
||||
}
|
||||
strcat(out, " or ");
|
||||
Strcat(out, "or ");
|
||||
bel_copy1(&p, out);
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*end.c*/
|
||||
|
||||
Reference in New Issue
Block a user