• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/rsync-45/rsync/popt/

Lines Matching refs:con

34 /*@unused@*/ static void prtcon(const char *msg, poptContext con)
38 con, con->os,
39 (con->os->nextCharArg ? con->os->nextCharArg : ""),
40 (con->os->nextArg ? con->os->nextArg : ""),
41 con->os->next,
42 (con->os->argv && con->os->argv[con->os->next]
43 ? con->os->argv[con->os->next] : ""));
47 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
49 con->execPath = _free(con->execPath);
50 con->execPath = xstrdup(path);
51 con->execAbsolute = allowAbsolute;
52 /*@-nullstate@*/ /* LCL: con->execPath can be NULL? */
57 static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
66 invokeCallbacksPRE(con, opt->arg);
74 cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip);
80 static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
89 invokeCallbacksPOST(con, opt->arg);
97 cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip);
103 static void invokeCallbacksOPTION(poptContext con,
117 invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty);
137 cb(con, POPT_CALLBACK_REASON_OPTION, myOpt,
138 con->os->nextArg, cbData);
151 poptContext con = malloc(sizeof(*con));
153 if (con == NULL) return NULL; /* XXX can't happen */
154 memset(con, 0, sizeof(*con));
156 con->os = con->optionStack;
157 con->os->argc = argc;
159 con->os->argv = argv;
161 con->os->argb = NULL;
164 con->os->next = 1; /* skip argv[0] */
166 con->leftovers = calloc( (argc + 1), sizeof(*con->leftovers) );
168 con->options = options;
170 con->aliases = NULL;
171 con->numAliases = 0;
172 con->flags = flags;
173 con->execs = NULL;
174 con->numExecs = 0;
175 con->finalArgvAlloced = argc * 2;
176 con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
177 con->execAbsolute = 1;
178 con->arg_strip = NULL;
181 con->flags |= POPT_CONTEXT_POSIXMEHARDER;
185 if (t) con->appName = strcpy(t, name);
189 invokeCallbacksPRE(con, con->options);
192 return con;
205 void poptResetContext(poptContext con)
209 if (con == NULL) return;
210 while (con->os > con->optionStack) {
211 cleanOSE(con->os--);
213 con->os->argb = PBM_FREE(con->os->argb);
214 con->os->currAlias = NULL;
215 con->os->nextCharArg = NULL;
216 con->os->nextArg = NULL;
217 con->os->next = 1; /* skip argv[0] */
219 con->numLeftovers = 0;
220 con->nextLeftover = 0;
221 con->restLeftover = 0;
222 con->doExec = NULL;
224 if (con->finalArgv != NULL)
225 for (i = 0; i < con->finalArgvCount; i++)
227 con->finalArgv[i] = _free(con->finalArgv[i]);
230 con->finalArgvCount = 0;
231 con->arg_strip = PBM_FREE(con->arg_strip);
232 /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */
238 static int handleExec(/*@special@*/ poptContext con,
240 /*@uses con->execs, con->numExecs, con->flags, con->doExec,
241 con->finalArgv, con->finalArgvAlloced, con->finalArgvCount @*/
242 /*@modifies con @*/
247 if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
250 for (i = con->numExecs - 1; i >= 0; i--) {
251 item = con->execs + i;
262 if (con->flags & POPT_CONTEXT_NO_EXEC)
265 if (con->doExec == NULL) {
266 con->doExec = con->execs + i;
272 if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) {
273 con->finalArgvAlloced += 10;
274 con->finalArgv = realloc(con->finalArgv,
275 sizeof(*con->finalArgv) * con->finalArgvAlloced);
278 i = con->finalArgvCount++;
279 if (con->finalArgv != NULL) /* XXX can't happen */
286 con->finalArgv[i] = s;
288 con->finalArgv[i] = NULL;
291 /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */
297 static int handleAlias(/*@special@*/ poptContext con,
300 /*@uses con->aliases, con->numAliases, con->optionStack, con->os,
301 con->os->currAlias, con->os->currAlias->option.longName @*/
302 /*@modifies con @*/
304 poptItem item = con->os->currAlias;
316 if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
319 for (i = con->numAliases - 1; i >= 0; i--) {
320 item = con->aliases + i;
330 if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH)
334 con->os->nextCharArg = nextCharArg;
336 con->os++;
337 con->os->next = 0;
338 con->os->stuffed = 0;
339 con->os->nextArg = NULL;
340 con->os->nextCharArg = NULL;
341 con->os->currAlias = con->aliases + i;
342 rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv,
343 &con->os->argc, &con->os->argv);
344 con->os->argb = NULL;
349 static int execCommand(poptContext con)
352 poptItem item = con->doExec;
361 (!con->execAbsolute && strchr(item->argv[0], '/')))
365 (6 + item->argc + con->numLeftovers + con->finalArgvCount));
368 if (!strchr(item->argv[0], '/') && con->execPath) {
369 char *s = alloca(strlen(con->execPath) + strlen(item->argv[0]) + sizeof("/"));
370 sprintf(s, "%s/%s", con->execPath, item->argv[0]);
382 if (con->finalArgv != NULL && con->finalArgvCount > 0) {
383 memcpy(argv + argc, con->finalArgv,
384 sizeof(*argv) * con->finalArgvCount);
385 argc += con->finalArgvCount;
388 if (con->leftovers != NULL && con->numLeftovers > 0) {
392 memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers);
393 argc += con->numLeftovers;
500 static const char * findNextArg(/*@special@*/ poptContext con,
502 /*@uses con->optionStack, con->os,
503 con->os->next, con->os->argb, con->os->argc, con->os->argv @*/
504 /*@modifies con @*/
506 struct optionStackEntry * os = con->os;
512 while (os->next == os->argc && os > con->optionStack) os--;
513 if (os->next == os->argc && os == con->optionStack) break;
532 if (os > con->optionStack) os--;
538 expandNextArg(/*@special@*/ poptContext con, const char * s)
539 /*@uses con->optionStack, con->os,
540 con->os->next, con->os->argb, con->os->argc, con->os->argv @*/
541 /*@modifies con @*/
563 if ((a = findNextArg(con, 1, 1)) == NULL)
586 static void poptStripArg(/*@special@*/ poptContext con, int which)
587 /*@uses con->arg_strip, con->optionStack @*/
588 /*@defines con->arg_strip @*/
589 /*@modifies con @*/
592 if (con->arg_strip == NULL)
593 con->arg_strip = PBM_ALLOC(con->optionStack[0].argc);
594 if (con->arg_strip != NULL) /* XXX can't happen */
595 PBM_SET(which, con->arg_strip);
597 /*@-compdef@*/ /* LCL: con->arg_strip udefined? */
659 int poptGetNextOpt(poptContext con)
664 if (con == NULL)
674 while (!con->os->nextCharArg && con->os->next == con->os->argc
675 && con->os > con->optionStack) {
676 cleanOSE(con->os--);
678 if (!con->os->nextCharArg && con->os->next == con->os->argc) {
680 invokeCallbacksPOST(con, con->options);
682 if (con->doExec) return execCommand(con);
687 if (!con->os->nextCharArg) {
692 if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) {
693 con->os->next++;
697 thisopt = con->os->next;
698 if (con->os->argv != NULL) /* XXX can't happen */
699 origOptString = con->os->argv[con->os->next++];
704 if (con->restLeftover || *origOptString != '-') {
705 if (con->flags & POPT_CONTEXT_POSIXMEHARDER)
706 con->restLeftover = 1;
707 if (con->flags & POPT_CONTEXT_ARG_OPTS) {
708 con->os->nextArg = xstrdup(origOptString);
711 if (con->leftovers != NULL) /* XXX can't happen */
712 con->leftovers[con->numLeftovers++] = origOptString;
724 con->restLeftover = 1;
737 if (handleAlias(con, optString, '\0', NULL))
740 if (handleExec(con, optString, '\0'))
752 opt = findOption(con->options, optString, '\0', &cb, &cbData,
759 con->os->nextCharArg = origOptString + 1;
761 if (con->os == con->optionStack &&
765 poptStripArg(con, thisopt);
773 if (con->os->nextCharArg) {
774 origOptString = con->os->nextCharArg;
776 con->os->nextCharArg = NULL;
778 if (handleAlias(con, NULL, *origOptString, origOptString + 1))
781 if (handleExec(con, NULL, *origOptString)) {
785 con->os->nextCharArg = origOptString;
789 opt = findOption(con->options, NULL, *origOptString, &cb,
797 con->os->nextCharArg = origOptString;
811 con->os->nextArg = _free(con->os->nextArg);
815 longArg = expandNextArg(con, longArg);
816 con->os->nextArg = longArg;
817 } else if (con->os->nextCharArg) {
818 longArg = expandNextArg(con, con->os->nextCharArg);
819 con->os->nextArg = longArg;
820 con->os->nextCharArg = NULL;
822 while (con->os->next == con->os->argc &&
823 con->os > con->optionStack) {
824 cleanOSE(con->os--);
826 if (con->os->next == con->os->argc) {
828 /*@-compdef@*/ /* FIX: con->os->argv not defined */
831 con->os->nextArg = NULL;
838 if (con->os == con->optionStack &&
841 poptStripArg(con, con->os->next);
844 if (con->os->argv != NULL) { /* XXX can't happen */
846 longArg = con->os->argv[con->os->next++];
847 longArg = expandNextArg(con, longArg);
848 con->os->nextArg = longArg;
858 *((const char **) opt->arg) = (con->os->nextArg)
859 ? xstrdup(con->os->nextArg) : NULL;
867 if (con->os->nextArg) {
868 aLong = strtol(con->os->nextArg, &end, 0);
891 if (con->os->nextArg) {
895 aDouble = strtod(con->os->nextArg, &end);
930 invokeCallbacksOPTION(con, con->options, opt, cbData, shorty);
935 if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) {
936 con->finalArgvAlloced += 10;
937 con->finalArgv = realloc(con->finalArgv,
938 sizeof(*con->finalArgv) * con->finalArgvAlloced);
941 if (con->finalArgv != NULL)
950 con->finalArgv[con->finalArgvCount++] = s;
952 con->finalArgv[con->finalArgvCount++] = NULL;
960 if (con->finalArgv != NULL && con->os->nextArg)
961 con->finalArgv[con->finalArgvCount++] =
962 /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */
963 xstrdup(con->os->nextArg);
971 const char * poptGetOptArg(poptContext con)
975 if (con) {
976 ret = con->os->nextArg;
977 con->os->nextArg = NULL;
983 const char * poptGetArg(poptContext con)
986 if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
987 ret = con->leftovers[con->nextLeftover++];
991 const char * poptPeekArg(poptContext con)
994 if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
995 ret = con->leftovers[con->nextLeftover];
999 const char ** poptGetArgs(poptContext con)
1001 if (con == NULL ||
1002 con->leftovers == NULL || con->numLeftovers == con->nextLeftover)
1006 con->leftovers[con->numLeftovers] = NULL;
1009 return (con->leftovers + con->nextLeftover);
1013 poptContext poptFreeContext(poptContext con)
1018 if (con == NULL) return con;
1019 poptResetContext(con);
1020 con->os->argb = _free(con->os->argb);
1022 if (con->aliases != NULL)
1023 for (i = 0; i < con->numAliases; i++) {
1024 item = con->aliases + i;
1032 con->aliases = _free(con->aliases);
1034 if (con->execs != NULL)
1035 for (i = 0; i < con->numExecs; i++) {
1036 item = con->execs + i;
1044 con->execs = _free(con->execs);
1046 con->leftovers = _free(con->leftovers);
1047 con->finalArgv = _free(con->finalArgv);
1048 con->appName = _free(con->appName);
1049 con->otherHelp = _free(con->otherHelp);
1050 con->execPath = _free(con->execPath);
1051 con->arg_strip = PBM_FREE(con->arg_strip);
1053 con = _free(con);
1054 return con;
1057 int poptAddAlias(poptContext con, struct poptAlias alias,
1071 return poptAddItem(con, item, 0);
1074 /*@-mustmod@*/ /* LCL: con not modified? */
1075 int poptAddItem(poptContext con, poptItem newItem, int flags)
1082 items = &con->execs;
1083 nitems = &con->numExecs;
1086 items = &con->aliases;
1087 nitems = &con->numAliases;
1119 const char * poptBadOption(poptContext con, int flags)
1123 if (con != NULL)
1124 os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
1159 int poptStuffArgs(poptContext con, const char ** argv)
1164 if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
1170 con->os++;
1171 con->os->next = 0;
1172 con->os->nextArg = NULL;
1173 con->os->nextCharArg = NULL;
1174 con->os->currAlias = NULL;
1175 rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv);
1176 con->os->argb = NULL;
1177 con->os->stuffed = 1;
1182 const char * poptGetInvocationName(poptContext con)
1184 return (con->os->argv ? con->os->argv[0] : "");
1187 int poptStrippedArgv(poptContext con, int argc, char ** argv)
1194 if (con->arg_strip)
1196 if (PBM_ISSET(i, con->arg_strip))
1201 if (con->arg_strip && PBM_ISSET(i, con->arg_strip))