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:
nethack.rankin
2008-02-03 06:20:05 +00:00
parent 6f0e178368
commit 6968f45024
+26 -15
View File
@@ -1330,10 +1330,11 @@ bel_copy1(inp, out)
char **inp, *out; char **inp, *out;
{ {
char *in = *inp; char *in = *inp;
out += strlen(out); /* eos() */
while(*in && isspace(*in)) in++; while(*in && isspace(*in)) in++;
while(*in && !isspace(*in)){ while(*in && !isspace(*in)) *out++ = *in++;
*out = *in; out++; in++; *out = '\0';
}
*inp = in; *inp = in;
} }
@@ -1341,29 +1342,39 @@ char *
build_english_list(in) build_english_list(in)
char *in; char *in;
{ {
char *out; char *out, *p = in;
int len = strlen(in); int len = (int)strlen(p), words = wordcount(p);
char *p = in;
int words = wordcount(in); /* +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){ switch(words){
case 0: case 0:
impossible("no words in list"); impossible("no words in list");
break; break;
case 1: case 1:
out = (char *)alloc(len+1); /* "single" */
strcpy(out, in); bel_copy1(&p, out);
break; break;
default: default:
len += 3 + (words-1); if (words == 2) {
bel_copy1(&p, out); words--; /* "first or second" */
while(words>1){ bel_copy1(&p, out);
strcat(out, ", "); Strcat(out, " ");
bel_copy1(&p, out); words--; } 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); bel_copy1(&p, out);
break; break;
} }
return out; return out;
} }
/*end.c*/ /*end.c*/