static char * prompt(struct pkginfo *info, int npkgs) { CKMENU *menup; char *inst; char ans[MAX_INPUT]; char header[256]; char temp[256]; int i; int n; if (maxinst > npkgs) { /* * the user may choose to install a completely new * instance of this package */ n = ckyorn(ans, NULL, NULL, MSG_GETINST_HELP1, MSG_GETINST_PROMPT1); if (n != 0) { quit(n); } if (strchr("yY", *ans) != NULL) { return ("new"); } } (void) snprintf(header, sizeof (header), MSG_GETINST_HEADER, pkgabrv); menup = allocmenu(header, CKALPHA); for (i = 0; i < npkgs; i++) { (void) snprintf(temp, sizeof (temp), "%s %s\n(%s) %s", info[i].pkginst, info[i].name, info[i].arch, info[i].version); if (setitem(menup, temp)) { progerr("no memory"); quit(99); } } if (npkgs == 1) { printmenu(menup); if (n = ckyorn(ans, NULL, NULL, NULL, MSG_GETINST_PROMPT0)) quit(n); if (strchr("yY", *ans) == NULL) quit(3); (void) strcpy(newinst, info[0].pkginst); } else { if (n = ckitem(menup, &inst, 1, NULL, NULL, MSG_GETINST_HELP2, MSG_GETINST_PROMPT2)) quit(n); (void) strcpy(newinst, inst); } (void) setitem(menup, 0); /* clear resource usage */ free(menup); /* clear resource usage */ return (newinst); }
int list::insert(void *item) { list::list_elem *next = current->next; current->next = (list::list_elem*)malloc(sizeof(list::list_elem)); current = current->next; current->next = next; return setitem(item); }
inline object const& item_policies::set( object const& target , object const& key , object const& value) { setitem(target, key, value); return value; }
void setitem(object const& target, Key const& key, Value const& value) { return setitem(target, object(key), object(value)); }
int main(int argc, char **argv) { CKMENU *mp; FILE *fp = NULL; int c, i; char **item; char temp[LSIZE * MB_LEN_MAX]; size_t mmax; size_t invismaxsize = INVISMAXSIZE; size_t n, r; wchar_t wline[LSIZE], wtemp[LSIZE]; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); prog = prog_name(argv[0]); invis = (char **)calloc(invismaxsize, sizeof (char *)); if (!invis) { (void) fprintf(stderr, gettext("Not enough memory\n")); exit(1); } while ((c = getopt(argc, argv, "m:oni:l:f:ud:p:e:h:k:s:QW:?")) != EOF) { /* check for invalid option */ if ((*prog == 'e') && !strchr(eusage, c)) usage(); /* no valid options */ if ((*prog == 'h') && !strchr(husage, c)) usage(); switch (c) { case 'Q': ckquit = 0; break; case 'W': ckwidth = atol(optarg); if (ckwidth < 0) { (void) fprintf(stderr, gettext("%s: ERROR: negative display width specified\n"), prog); exit(1); } break; case 'm': max = atoi(optarg); if (max > SHRT_MAX || max < SHRT_MIN) { (void) fprintf(stderr, gettext("%s: ERROR: too large or too small max value specified\n"), prog); exit(1); } break; case 'o': attr |= CKONEFLAG; break; case 'n': attr &= ~CKALPHA; break; case 'i': invis[ninvis++] = optarg; if (ninvis == invismaxsize) { invismaxsize += INVISMAXSIZE; invis = (char **)realloc(invis, invismaxsize * sizeof (char *)); if (!invis) { (void) fprintf(stderr, gettext("Not enough memory\n")); exit(1); } (void) memset(invis + ninvis, 0, (invismaxsize - ninvis) * sizeof (char *)); } break; case 'l': label = optarg; break; case 'f': if ((fp = fopen(optarg, "r")) == NULL) { (void) fprintf(stderr, gettext("%s: ERROR: can't open %s\n"), prog, optarg); exit(1); } break; case 'u': attr |= CKUNNUM; break; case 'd': deflt = optarg; break; case 'p': prompt = optarg; break; case 'e': error = optarg; break; case 'h': help = optarg; break; case 'k': kpid = atoi(optarg); break; case 's': signo = atoi(optarg); break; default: usage(); } } if (signo) { if (kpid == BADPID) usage(); } else signo = SIGTERM; mp = allocmenu(label, attr); if (fp) { *wtemp = L'\0'; while (fgetws(wline, LSIZE, fp)) { /* * Skip comment lines, those beginning with '#'. * Note: AT&T forgot this & needs the next 2 lines. */ if (*wline == L'#') continue; n = wcslen(wline); if ((n != 0) && (wline[n - 1] == L'\n')) wline[n - 1] = L'\0'; /* * if the line begins with a space character, * this is a continuous line to the previous line. */ if (iswspace(*wline)) { (void) wcscat(wtemp, L"\n"); (void) wcscat(wtemp, wline); } else { if (*wtemp) { n = wcslen(wtemp); r = wcstombs(temp, wtemp, n * MB_LEN_MAX); if (r == (size_t)-1) { (void) fprintf(stderr, gettext("Invalid character in the menu definition.\n")); exit(1); } if (setitem(mp, temp)) { (void) fprintf(stderr, gettext(INTERR), prog); exit(1); } } (void) wcscpy(wtemp, wline); } } if (*wtemp) { n = wcslen(wtemp); r = wcstombs(temp, wtemp, n * MB_LEN_MAX); if (r == (size_t)-1) { (void) fprintf(stderr, gettext("Invalid character in the menu definition.\n")); exit(1); } if (setitem(mp, temp)) { (void) fprintf(stderr, gettext(INTERR), prog); exit(1); } } } while (optind < argc) { if (setitem(mp, argv[optind++])) { (void) fprintf(stderr, gettext(INTERR), prog); exit(1); } } for (n = 0; n < ninvis; ) { if (setinvis(mp, invis[n++])) { (void) fprintf(stderr, gettext(INTERR), prog); exit(1); } } if (*prog == 'e') { ckindent = 0; ckitem_err(mp, error); exit(0); } else if (*prog == 'h') { ckindent = 0; ckitem_hlp(mp, help); exit(0); } if (max < 1) { mmax = mp->nchoices; } else { mmax = max; } /* * if -o option is specified, mp->nchoices is 1, and if no invisible * item is specified, ckitem() will consume two entries of item, * even though 'max' is set to 1. So to take care of that problem, we * allocate one extra element for item */ item = (char **)calloc(mmax+1, sizeof (char *)); if (!item) { (void) fprintf(stderr, gettext("Not enough memory\n")); exit(1); } n = ckitem(mp, item, max, deflt, error, help, prompt); if (n == 3) { if (kpid > -2) (void) kill(kpid, signo); (void) puts("q"); } else if (n == 0) { i = 0; while (item[i]) (void) puts(item[i++]); } return (n); }