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

Function handleExec

popt/popt.c:239–292  ·  view source on GitHub ↗

Only one of longName, shortName should be set, not both. */

Source from the content-addressed store, hash-verified

237
238/* Only one of longName, shortName should be set, not both. */
239static int handleExec(poptContext con,
240 const char * longName, char shortName)
241{
242 poptItem item;
243 int i;
244
245 if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
246 return 0;
247
248 for (i = con->numExecs - 1; i >= 0; i--) {
249 item = con->execs + i;
250 if (longName && !(item->option.longName &&
251 !strcmp(longName, item->option.longName)))
252 continue;
253 else if (shortName != item->option.shortName)
254 continue;
255 break;
256 }
257 if (i < 0) return 0;
258
259
260 if (con->flags & POPT_CONTEXT_NO_EXEC)
261 return 1;
262
263 if (con->doExec == NULL) {
264 con->doExec = con->execs + i;
265 return 1;
266 }
267
268 /* We already have an exec to do; remember this option for next
269 time 'round */
270 if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) {
271 con->finalArgvAlloced += 10;
272 con->finalArgv = realloc(con->finalArgv,
273 sizeof(*con->finalArgv) * con->finalArgvAlloced);
274 }
275
276 i = con->finalArgvCount++;
277 if (con->finalArgv != NULL) /* XXX can't happen */
278 { char *s = malloc((longName ? strlen(longName) : 0) + sizeof("--"));
279 if (s != NULL) { /* XXX can't happen */
280 con->finalArgv[i] = s;
281 *s++ = '-';
282 if (longName)
283 s = stpcpy( stpcpy(s, "-"), longName);
284 else
285 *s++ = shortName;
286 *s = '\0';
287 } else
288 con->finalArgv[i] = NULL;
289 }
290
291 return 1;
292}
293
294/**
295 * Compare long option for equality, adjusting for POPT_ARGFLAG_TOGGLE.

Callers 1

poptGetNextOptFunction · 0.85

Calls 1

stpcpyFunction · 0.85

Tested by

no test coverage detected