I made a couple more places use stpcpy() in the code, optimizing away a
couple strlen() calls in the process. I also tweaked the help code that
was abbreviating a long value using "..." to allow a string to fit if it
can, rather than always reserving space for the "..." chars. I.e. if we
had room for 4 word chars, instead of outputting "w...", it would allow
a full "word" to be output, since it fits.
..wayne..
--- popthelp.c 10 Mar 2008 08:13:09 -0000 1.86
+++ popthelp.c 15 Mar 2008 05:09:45 -0000
@@ -271,12 +271,12 @@ singleOptionDefaultValue(size_t lineLeng
if (s == NULL)
le = stpcpy(le, "null");
else {
- size_t slen = 4*lineLength - (le - l) - sizeof("\"...\")");
+ size_t limit = 4*lineLength - (le - l) - sizeof("\"\")");
+ size_t slen;
*le++ = '"';
- strncpy(le, s, slen); le[slen] = '\0'; le += strlen(le);
- if (slen < strlen(s)) {
- strcpy(le, "..."); le += strlen(le);
- }
+ strncpy(le, s, limit); le[limit] = '\0'; le += (slen = strlen(le));
+ if (slen == limit && s[limit])
+ le[-1] = le[-2] = le[-3] = '.';
*le++ = '"';
}
} break;
@@ -363,7 +363,6 @@ static void singleOptionHelp(FILE * fp,
strlen(defs) + sizeof(" "));
if (t) {
char * te = t;
- *te = '\0';
if (help)
te = stpcpy(te, help);
*te++ = ' ';
@@ -417,24 +416,22 @@ static void singleOptionHelp(FILE * fp,
case POPT_ARG_DOUBLE:
case POPT_ARG_STRING:
*le++ = (opt->longName != NULL ? '=' : ' ');
- strcpy(le, argDescrip); le += strlen(le);
+ le = stpcpy(le, argDescrip);
break;
default:
break;
}
} else {
- size_t lelen;
+ char *leo;
/* XXX argDescrip[0] determines "--foo=bar" or "--foo bar". */
if (!strchr(" =(", argDescrip[0]))
*le++ = ((poptArgType(opt) == POPT_ARG_MAINCALL) ? ' ' :
(poptArgType(opt) == POPT_ARG_ARGV) ? ' ' : '=');
- strcpy(le, argDescrip);
- lelen = strlen(le);
- le += lelen;
+ le = stpcpy(leo = le, argDescrip);
/* Adjust for (possible) wide characters. */
- displaypad = (int)(lelen - stringDisplayWidth(argDescrip));
+ displaypad = (int)((le - leo) - stringDisplayWidth(argDescrip));
}
if (F_ISSET(opt, OPTIONAL))
*le++ = ']';