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

Function handleAlias

popt/popt.c:333–401  ·  view source on GitHub ↗

Only one of longName, shortName may be set at a time */

Source from the content-addressed store, hash-verified

331
332/* Only one of longName, shortName may be set at a time */
333static int handleAlias(poptContext con,
334 const char * longName, size_t longNameLen,
335 char shortName,
336 const char * nextArg)
337{
338 poptItem item = con->os->currAlias;
339 int rc;
340 int i;
341
342 if (item) {
343 if (longName && item->option.longName != NULL
344 && longOptionStrcmp(&item->option, longName, longNameLen))
345 return 0;
346 else
347 if (shortName && shortName == item->option.shortName)
348 return 0;
349 }
350
351 if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
352 return 0;
353
354 for (i = con->numAliases - 1; i >= 0; i--) {
355 item = con->aliases + i;
356 if (longName) {
357 if (item->option.longName == NULL)
358 continue;
359 if (!longOptionStrcmp(&item->option, longName, longNameLen))
360 continue;
361 } else if (shortName != item->option.shortName)
362 continue;
363 break;
364 }
365 if (i < 0) return 0;
366
367 if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH)
368 return POPT_ERROR_OPTSTOODEEP;
369
370 if (longName == NULL && nextArg != NULL && *nextArg != '\0')
371 con->os->nextCharArg = nextArg;
372
373 con->os++;
374 con->os->next = 0;
375 con->os->stuffed = 0;
376 con->os->nextArg = NULL;
377 con->os->nextCharArg = NULL;
378 con->os->currAlias = con->aliases + i;
379 { const char ** av;
380 int ac = con->os->currAlias->argc;
381 /* Append --foo=bar arg to alias argv array (if present). */
382 if (longName && nextArg != NULL && *nextArg != '\0') {
383 av = malloc((ac + 1 + 1) * sizeof(*av));
384 if (av != NULL) { /* XXX won't happen. */
385 for (i = 0; i < ac; i++) {
386 av[i] = con->os->currAlias->argv[i];
387 }
388 av[ac++] = nextArg;
389 av[ac] = NULL;
390 } else /* XXX revert to old popt behavior if malloc fails. */

Callers 1

poptGetNextOptFunction · 0.85

Calls 2

longOptionStrcmpFunction · 0.85
poptDupArgvFunction · 0.85

Tested by

no test coverage detected