(budg): Create the capital/city name from the d_name field instead of
hard coding the strings. (plurize): New.
This commit is contained in:
parent
2f1b7cd2a3
commit
fdcbb5912d
3 changed files with 33 additions and 6 deletions
|
@ -139,6 +139,7 @@ extern s_char *numstr(s_char buf[], int n);
|
|||
extern s_char *esplur(int n);
|
||||
extern s_char *splur(int n);
|
||||
extern s_char *iesplur(int n);
|
||||
extern char *plurize(char *buf, int max_len, int n);
|
||||
extern char *getstarg(char *input, char *prompt, char buf[]);
|
||||
extern char *getstring(char *prompt, char buf[]);
|
||||
extern char *ugetstring(char *prompt, char buf[]);
|
||||
|
|
|
@ -181,13 +181,13 @@ budg(void)
|
|||
expenses -= mil;
|
||||
}
|
||||
if (p_sect[SCT_CAPIT][0]) {
|
||||
sprintf(in, "%s maintenance\t\t", dchr[SCT_CAPIT].d_name);
|
||||
in[0] = toupper(in[0]);
|
||||
pr(in);
|
||||
n = p_sect[SCT_CAPIT][0];
|
||||
sprintf(in, "%d %s%s",
|
||||
n,
|
||||
opt_BIG_CITY ? "cit" : "capital",
|
||||
opt_BIG_CITY ? iesplur(n) : splur(n));
|
||||
pr("%s maintenance\t\t%-32s%8ld\n",
|
||||
opt_BIG_CITY ? "City" : "Capital", in, p_sect[SCT_CAPIT][1]);
|
||||
sprintf(in, "%d %s", n, dchr[SCT_CAPIT].d_name);
|
||||
plurize(in, sizeof(in), n);
|
||||
pr("%-32s%8ld\n", in, p_sect[SCT_CAPIT][1]);
|
||||
expenses += p_sect[SCT_CAPIT][1];
|
||||
}
|
||||
pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses));
|
||||
|
|
|
@ -51,3 +51,29 @@ iesplur(int n)
|
|||
{
|
||||
return n == 1 ? "y" : "ies";
|
||||
}
|
||||
|
||||
/*
|
||||
* Change suffix of BUF to English plural if N > 1.
|
||||
* Best effort, not 100% accurate English.
|
||||
* Array BUF[MAX_LEN] contains a zero-terminated string.
|
||||
* If there's not enough space for changed suffix, it is truncated.
|
||||
*/
|
||||
char *
|
||||
plurize(char *buf, int max_len, int n)
|
||||
{
|
||||
if (!strlen(buf) || n <= 1)
|
||||
return buf;
|
||||
|
||||
switch(buf[strlen(buf) - 1]) {
|
||||
case 'y':
|
||||
buf[strlen(buf) -1] = '\0';
|
||||
strncat(buf, "ies", max_len - 1);
|
||||
break;
|
||||
case 's':
|
||||
strncat(buf, "es", max_len - 1);
|
||||
break;
|
||||
default:
|
||||
strncat(buf, "s", max_len - 1);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue