MCPcopy Create free account
hub / github.com/RsyncProject/rsync / singleOptionDefaultValue

Function singleOptionDefaultValue

popt/popthelp.c:205–275  ·  view source on GitHub ↗

* Display default value for an option. * @param lineLength display positions remaining * @param opt option(s) * @param translation_domain translation domain * @return */

Source from the content-addressed store, hash-verified

203 * @return
204 */
205static char *
206singleOptionDefaultValue(size_t lineLength,
207 const struct poptOption * opt,
208 /* FIX: i18n macros disabled with lclint */
209 const char * translation_domain)
210{
211 const char * defstr = D_(translation_domain, "default");
212 char * le = malloc(4*lineLength + 1);
213 char * l = le;
214
215 if (le == NULL) return NULL; /* XXX can't happen */
216 *le = '\0';
217 *le++ = '(';
218 le = stpcpy(le, defstr);
219 *le++ = ':';
220 *le++ = ' ';
221 if (opt->arg) { /* XXX programmer error */
222 poptArg arg = { .ptr = opt->arg };
223 switch (poptArgType(opt)) {
224 case POPT_ARG_VAL:
225 case POPT_ARG_INT:
226 le += sprintf(le, "%d", arg.intp[0]);
227 break;
228 case POPT_ARG_SHORT:
229 le += sprintf(le, "%hd", arg.shortp[0]);
230 break;
231 case POPT_ARG_LONG:
232 le += sprintf(le, "%ld", arg.longp[0]);
233 break;
234 case POPT_ARG_LONGLONG:
235 le += sprintf(le, "%lld", arg.longlongp[0]);
236 break;
237 case POPT_ARG_FLOAT:
238 { double aDouble = (double) arg.floatp[0];
239 le += sprintf(le, "%g", aDouble);
240 } break;
241 case POPT_ARG_DOUBLE:
242 le += sprintf(le, "%g", arg.doublep[0]);
243 break;
244 case POPT_ARG_MAINCALL:
245 le += sprintf(le, "%p", opt->arg);
246 break;
247 case POPT_ARG_ARGV:
248 le += sprintf(le, "%p", opt->arg);
249 break;
250 case POPT_ARG_STRING:
251 { const char * s = arg.argv[0];
252 if (s == NULL)
253 le = stpcpy(le, "null");
254 else {
255 size_t limit = 4*lineLength - (le - l) - sizeof("\"\")");
256 size_t slen;
257 *le++ = '"';
258 strncpy(le, s, limit); le[limit] = '\0'; le += (slen = strlen(le));
259 if (slen == limit && s[limit])
260 le[-1] = le[-2] = le[-3] = '.';
261 *le++ = '"';
262 }

Callers 1

singleOptionHelpFunction · 0.85

Calls 2

stpcpyFunction · 0.85
_freeFunction · 0.85

Tested by

no test coverage detected