📄 xpromptpar.c
字号:
{ /*convert string parameter value to proper type, check for format and limit errors, and write the parameter file if ok; if the input value strval is out of bounds or has a bad format, the value used is returned via newval*/ float pmin, pmax; /* min and max values for parameter */ int ret; /* return code for this function*/ int putsymret; /* return code from putsym calls */ int ptype; /* parameter data type */ char *lastchar; /* last scanned character */ char *sval; char cval; double dval; int ival; /*return PAR_FORMAT if conversion error*/ /*if limits, check them and return appropriate codes*/ /*if all goes well, write the parameter (where?)*/ ptype = symtype(param); /* convert string to proper type and check for format errors*/ switch (ptype) { case ST_INT: ival = (int) strtol(strval, &lastchar, 10); if (*lastchar != '\0') { ret = PARAM_FORMAT; ival = getsymdef_i(param); *newval = getsymdef_string(param); } else { ret = PARAM_OK; *newval = strval; } break; case ST_CHAR: cval = strval[0]; if (strlen(strval) != 1) { ret = PARAM_FORMAT; cval = getsymdef_c(param); *newval = getsymdef_string(param); } else { ret = PARAM_OK; *newval = strval; } break; case ST_STRING: sval = strval; *newval = strval; ret = PARAM_OK; break; case ST_FLOAT: dval = strtod(strval, &lastchar); if (*lastchar != '\0') { ret = PARAM_FORMAT; dval = getsymdef_d(param); *newval = getsymdef_string(param); } else { ret = PARAM_OK; *newval = strval; } break; case ST_IARRAY: case ST_FARRAY: Fprintf(stderr, "param_checkwrite: type not supported yet\n"); ret = PARAM_FORMAT; break; case ST_UNDEF: Fprintf(stderr, "param_checkwrite: undefined parameter %s\n", param); return(PARAM_FORMAT); default: Fprintf(stderr, "param_checkwrite: unsupported parameter type\n"); break; } /* now check the limits (if any) for numeric types*/ if (ptype == ST_INT) { if (symrange(param, &pmin, &pmax)) { if (ival < pmin) { ival = pmin; *newval = (char *) calloc((unsigned) 25, sizeof (char)); sprintf(*newval, "%d", ival); ret = PARAM_MIN; } if (ival > pmax) { ival = pmax; *newval = (char *) calloc((unsigned) 25, sizeof (char)); sprintf(*newval, "%d", ival); ret = PARAM_MAX; } } } if (ptype == ST_FLOAT) { if (symrange(param, &pmin, &pmax)) { if (dval < pmin) { dval = pmin; *newval = (char *) calloc((unsigned) 25, sizeof (char)); sprintf(*newval, "%g", dval); ret = PARAM_MIN; } if (dval > pmax) { dval = pmax; *newval = (char *) calloc((unsigned) 25, sizeof (char)); sprintf(*newval, "%g", dval); ret = PARAM_MAX; } } } if (debug_level > 1) { switch(ret) { case PARAM_MAX: Fprintf(stderr, "param_checkwrite: value greater than max value\n"); break; case PARAM_MIN: Fprintf(stderr, "param_checkwrite: value less than min value\n"); break; case PARAM_FORMAT: Fprintf(stderr, "param_checkwrite: parameter format error\n"); break; case PARAM_OK: Fprintf(stderr, "param_checkwrite: parameter value OK\n"); break; } } if (debug_level > 1) Fprintf(stderr, "param_checkwrite: writing value %s for %s\n", *newval, param); switch (ptype) { case ST_INT: putsymret = fputsym_i(param, ival, parfile); break; case ST_CHAR: Fprintf(stderr, "param_checkwrite: can't putsym for CHAR type yet\n");/* putsymret = fputsym_c(param, cval, parfile);*/ break; case ST_STRING: putsymret = fputsym_s(param, sval, parfile); break; case ST_FLOAT: putsymret = fputsym_f(param, dval, parfile); break; case ST_IARRAY: case ST_FARRAY: case ST_UNDEF: default: putsymret = -1; Fprintf(stderr, "param_checkwrite: undefined or unsupported parameter type\n"); break; } if (putsymret == -1) { ret = PARAM_NO_WRITE; Fprintf(stderr, "param_checkwrite: trouble writing parameter %s\n", param); } return(ret);}/*all of the functions after this point are ones that really depend on XView -- might want to move them later; the ones above are ones thatcould go into the regular ESPS library*/static int x_fill_param_file(params, outfile, helpname, x_pos, y_pos)char ** params; /* list of indefinite parameters */char *outfile; /* output parameter file */char *helpname; /* intended user of outfile (for help) */int x_pos, y_pos; /* if non-zero, locates X prompt window *//* pop up a window with prompts to fill out the indefinite parameters from a parameter file; we assume that read_params has already been called, and that the output param file already has the definite parameters; */{ Frame frame = NULL; DEBUG(2) (stderr, "Entered x_fill_param_file\n"); spsassert(outfile != NULL, "x_fill_param_file: null outfile"); spsassert(outfile != NULL, "x_fill_param_file: no params (null)"); frame = create_param_frame((Frame) NULL, params, outfile, helpname, x_pos, y_pos); if (frame == NULL) return(EXIT_NOT_DONE); /* set global to indicate frame exit via quit (rather than DONE button) * this is reset appropriately in done() */ frame_exit_status = EXIT_NOT_DONE; xv_main_loop(frame); return(frame_exit_status); }Framecreate_param_frame(parent, params, outfile, helpname, x_pos, y_pos)Frame parent; /* optional parent frame (may be NULL) */char **params; /* list of indefinite parameters */char *outfile; /* output parameter file */char *helpname; /* intended user of outfile (for help) */int x_pos, y_pos; /* if non-zero, locates (possible) X window */{ /* create basic frame with title and buttons for done, help (man page) if program non-NULL, defaults, and items for each parameter This routine also sets the do_color global attribute for access by other- modules *//*pass outfile name as client data or perhaps as key data*/ Frame frame; /* the main frame */ Panel con_panel; /* panel for control buttons */ Panel par_panel; /* panel for parameters */ Panel_item def_button; /* handle for default button */ Panel_item done_button; /* handle for Done button */ Panel_item button; /* temp handle */ Cms e_cms; /* colormap segment */ char *title; /* title for prompt frame */ char *help_title; /* title for help window */ spsassert(outfile != NULL, "create_param_frame: null outfile"); spsassert(outfile != NULL, "create_param_frame: no params (null)"); DEBUG(2) (stderr, "Entered create_param_frame\n"); /* create custom frame titles if ESPS program name*/ title = malloc(80); help_title = malloc(80); if ((helpname != NULL) && (helpname[0] != '.') && (helpname[0] != '/')) { (void) sprintf(title, "ESPS Parameter Request for %s", helpname); (void) sprintf(help_title, "ESPS man page for %s", helpname); } else { (void) sprintf(title, "ESPS Parameter Request"); (void) sprintf(help_title, "ESPS Help Window"); } if ((x_pos >= 0) && (y_pos >= 0)) { frame = (Frame)xv_create(parent, FRAME, XV_LABEL, title, FRAME_SHOW_FOOTER, FALSE, FRAME_SHOW_RESIZE_CORNER, TRUE, XV_X, x_pos, XV_Y, y_pos, NULL); } else { frame = (Frame)xv_create(parent, FRAME, XV_LABEL, title, FRAME_SHOW_FOOTER, FALSE, FRAME_SHOW_RESIZE_CORNER, TRUE, NULL); } /* set global for color treatment*/ do_color = exv_color_status(frame); /* create control panel with buttons*/ con_panel = (Panel)xv_create(frame, PANEL, OPENWIN_SHOW_BORDERS, TRUE, PANEL_LAYOUT, PANEL_HORIZONTAL, XV_X, 0, NULL);/* if (do_color) { e_cms = exv_init_colors(con_panel); xv_set(con_panel, WIN_BACKGROUND_COLOR, CMS_CONTROL_COLORS + EC_GRAY, WIN_FOREGROUND_COLOR, CMS_CONTROL_COLORS + EC_BLACK, NULL); }*/ done_button = xv_create(con_panel, PANEL_BUTTON, PANEL_ITEM_Y, 10, PANEL_NEXT_COL, -1, PANEL_LABEL_STRING, "Done", PANEL_NOTIFY_PROC, done, NULL);/* if (do_color) xv_set(done_button, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS + EC_BLACK, NULL);*/ def_button = (Panel_item) xv_create(con_panel, PANEL_BUTTON, PANEL_ITEM_Y, 10, PANEL_NEXT_COL, -1, PANEL_LABEL_STRING, "Defaults", PANEL_NOTIFY_PROC, set_defaults, NULL);/* if (do_color) xv_set(def_button, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS + EC_BLACK, NULL);*/ if (helpname != NULL) { button = xv_create(con_panel, PANEL_BUTTON, PANEL_ITEM_Y, 10, PANEL_NEXT_COL, -1, XV_KEY_DATA, EXVK_HELP_TITLE, help_title, XV_KEY_DATA, EXVK_HELP_NAME, helpname, PANEL_LABEL_STRING, "Help", PANEL_NOTIFY_PROC, exv_get_help, NULL);/* if (do_color) xv_set(button, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS + EC_BLACK, NULL);*/ } window_fit_height(con_panel); /* create panel with items for all the parameters*/ DEBUG(2) (stderr, "create_param_frame: make parameter items\n"); par_panel = create_param_panels(frame, params, outfile); /* give the default and done buttons a pointer to the parameter panel*/ xv_set(def_button, PANEL_CLIENT_DATA, par_panel, NULL); xv_set(done_button, PANEL_CLIENT_DATA, par_panel, NULL); /*finish fitting things*/ xv_set(con_panel, XV_WIDTH, xv_get(par_panel, XV_WIDTH, NULL), NULL); window_fit(frame); DEBUG(2) (stderr, "create_param_frame: set icon\n"); (void) exv_attach_icon(frame, ERL_NOBORD_ICON, "params", TRANSPARENT); DEBUG(2) (stderr, "create_param_frame: set defaults\n"); return(frame);}staticPanelcreate_param_panels(frame, param_list, outfile)Frame frame;char **param_list;char *outfile;/*This function takes an input panel and creates a panel item for each ESPS parameter in param_list; each time the user modifies a parameter in the panel, the value is written out to the parameter file outfile in a form suitable for later use by ESPS programs (i.e., we use fputsym()). We assume that param_list was derived from an input parameter file after calling read_params (i.e., so that info is available on each parameter). Parameters that have (optional) discrete choices associated with them (in the original parameter file) are displayed as a PANEL_CHOICE. All other parameters are displayed as PANEL_TEXT items. (XView has int support, but not for other types, so the only way to get a uniform interface is to do the conversions ourselves!) */{ Cms e_cms; /* ESPS colormap segment */ char **choices; /* NULL terminated array of strings */ int nchoices; /* number of choices*/ char *param; /* specific parameter */ Panel con_panel; /* handle for parameter panel */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -