}
int inputBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result) {
+ int flags, char ** result) {
newtComponent form, entry, okay, cancel, answer, tb;
const char * val;
int pFlag = (flags & FLAG_PASSWORD) ? NEWT_FLAG_PASSWORD : 0;
addButtons(height, width, form, &okay, &cancel, flags);
answer = newtRunForm(form);
+ *result = NULL;
if (answer == cancel)
rc = DLG_CANCEL;
else if (answer == NULL)
rc = DLG_ESCAPE;
-
- *result = val;
+ else
+ *result = strdup(val);
newtFormDestroy(form);
}
int listBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char *default_item, const char ** result) {
+ int flags, const char *default_item, char ** result) {
newtComponent form, okay, tb, answer, listBox;
newtComponent cancel = NULL;
const char * arg;
addButtons(height, width, form, &okay, &cancel, flags);
answer = newtRunForm(form);
+ *result = NULL;
if (answer == cancel)
rc = DLG_CANCEL;
if (answer == NULL)
rc = DLG_ESCAPE;
-
- i = (long) newtListboxGetCurrent(listBox);
- *result = itemInfo[i].tag;
+ else {
+ i = (long) newtListboxGetCurrent(listBox);
+ *result = strdup(itemInfo[i].tag);
+ }
newtFormDestroy(form);
free(itemInfo);
}
int checkList(const char * text, int height, int width, poptContext optCon,
- int useRadio, int flags, const char *** selections) {
+ int useRadio, int flags, char *** selections) {
newtComponent form, okay, tb, subform, answer;
newtComponent sb = NULL, cancel = NULL;
const char * arg;
addButtons(height, width, form, &okay, &cancel, flags);
answer = newtRunForm(form);
+ *selections = NULL;
if (answer == cancel)
rc = DLG_CANCEL;
if (answer == NULL)
rc = DLG_ESCAPE;
-
- if (useRadio) {
- answer = newtRadioGetCurrent(cbInfo[0].comp);
- *selections = malloc(sizeof(char *) * 2);
- if (*selections == NULL)
- return DLG_ERROR;
- (*selections)[0] = (*selections)[1] = NULL;
- for (i = 0; i < numBoxes; i++)
- if (cbInfo[i].comp == answer) {
- (*selections)[0] = cbInfo[i].tag;
- break;
+ else {
+ if (useRadio) {
+ answer = newtRadioGetCurrent(cbInfo[0].comp);
+ *selections = malloc(sizeof(char *) * 2);
+ if (*selections == NULL)
+ return DLG_ERROR;
+ (*selections)[0] = (*selections)[1] = NULL;
+ for (i = 0; i < numBoxes; i++)
+ if (cbInfo[i].comp == answer) {
+ (*selections)[0] = strdup(cbInfo[i].tag);
+ break;
+ }
+ } else {
+ numSelected = 0;
+ for (i = 0; i < numBoxes; i++) {
+ if (cbStates[i] != ' ') numSelected++;
}
- } else {
- numSelected = 0;
- for (i = 0; i < numBoxes; i++) {
- if (cbStates[i] != ' ') numSelected++;
- }
- *selections = malloc(sizeof(char *) * (numSelected + 1));
- if (*selections == NULL) return DLG_ERROR;
+ *selections = malloc(sizeof(char *) * (numSelected + 1));
+ if (*selections == NULL)
+ return DLG_ERROR;
- numSelected = 0;
- for (i = 0; i < numBoxes; i++) {
- if (cbStates[i] != ' ')
- (*selections)[numSelected++] = cbInfo[i].tag;
- }
+ numSelected = 0;
+ for (i = 0; i < numBoxes; i++) {
+ if (cbStates[i] != ' ')
+ (*selections)[numSelected++] = strdup(cbInfo[i].tag);
+ }
- (*selections)[numSelected] = NULL;
+ (*selections)[numSelected] = NULL;
+ }
}
newtFormDestroy(form);
int messageBox(const char * text, int height, int width, int type, int flags);
int checkList(const char * text, int height, int width, poptContext optCon,
- int useRadio, int flags, const char *** selections);
+ int useRadio, int flags, char *** selections);
int listBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char *default_item, const char ** result);
+ int flags, const char *default_item, char ** result);
int inputBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result);
+ int flags, char ** result);
int gauge(const char * text, int height, int width, poptContext optCon, int fd,
int flags);
void useFullButtons(int state);
int outputfd = 2;
int topLeft = 0;
FILE *output = stderr;
- const char * result;
- const char ** selections, ** next;
+ char * result;
+ char ** selections, ** next;
char * title = NULL;
char *default_item = NULL;
char * backtitle = NULL;
case MODE_INPUTBOX:
rc = inputBox(text, height, width, optCon, flags, &result);
- if (rc == DLG_OKAY) fprintf(output, "%s", result);
+ if (rc == DLG_OKAY) {
+ fprintf(output, "%s", result);
+ free(result);
+ }
break;
case MODE_PASSWORDBOX:
rc = inputBox(text, height, width, optCon, flags | FLAG_PASSWORD,
&result);
- if (rc == DLG_OKAY) fprintf (output, "%s", result);
+ if (rc == DLG_OKAY) {
+ fprintf (output, "%s", result);
+ free(result);
+ }
break;
case MODE_MENU:
rc = listBox(text, height, width, optCon, flags, default_item, &result);
- if (rc == DLG_OKAY) fprintf(output, "%s", result);
+ if (rc == DLG_OKAY) {
+ fprintf(output, "%s", result);
+ free(result);
+ }
break;
case MODE_RADIOLIST:
rc = checkList(text, height, width, optCon, 1, flags, &selections);
- if (rc == DLG_OKAY) {
- if (selections[0])
- fprintf(output, "%s", selections[0]);
+ if (rc == DLG_OKAY && selections[0]) {
+ fprintf(output, "%s", selections[0]);
+ free(selections[0]);
free(selections);
}
break;
} else {
fprintf(output, "%s\n", *next);
}
+ free(*next);
}
free(selections);
int rc = 0;
int flags = 0;
int defaultNo = 0;
- const char * result;
- const char ** selections, ** next;
+ char * result;
+ char ** selections, ** next;
char * title = NULL;
char *default_item = NULL;
struct poptOption optionsTable[] = {
case MODE_INPUTBOX:
rc = inputBox(text, height, width, optCon, flags, &result);
if (rc ==DLG_OKAY) {
- interp->result = strdup(result);
+ interp->result = result;
interp->freeProc = TCL_DYNAMIC;
}
break;
case MODE_MENU:
rc = listBox(text, height, width, optCon, flags, default_item, &result);
if (rc==DLG_OKAY) {
- interp->result = strdup(result);
+ interp->result = result;
interp->freeProc = TCL_DYNAMIC;
}
break;
case MODE_RADIOLIST:
rc = checkList(text, height, width, optCon, 1, flags, &selections);
if (rc==DLG_OKAY) {
- interp->result = strdup(selections[0]);
+ interp->result = selections[0];
interp->freeProc = TCL_DYNAMIC;
+
+ free(selections);
}
break;