home *** CD-ROM | disk | FTP | other *** search
- /*
- * Routines to manipulate the pcomm.param file.
- */
-
- #include <stdio.h>
- #include "param.h"
- #include "status.h"
-
- /*
- * Read the parameter structure from the pcomm.param file. Returns a
- * pointer to the PARAM structure. All errors are fatal.
- */
-
- struct PARAM *
- read_param()
- {
- FILE *fp;
- int i, oops;
- char buf[80], *temp_token, *str, *strdup();
- char message[80], *str_tok();
- static char *token[NUM_PARAM] = {"D_BAUD", "D_PARITY", "D_DBITS",
- "D_SBITS", "HOT", "ASCII_HOT", "D_DUPLEX", "FLOW", "CR_IN", "CR_OUT",
- "LOGFILE", "DUMPFILE", "STRIP", "PAUSE_CHAR", "CR_CHAR", "CTRL_CHAR",
- "ESC_CHAR", "ABORT", "CDELAY", "PAUSE", "LECHO", "EXPAND", "CR_DELAY",
- "PACE", "CR_UP", "LF_UP", "TIMER", "CR_DN", "LF_DN", "LD_PLUS",
- "LD_MINUS", "LD_AT", "LD_POUND"};
- static struct PARAM p;
- void error_win();
- /* read permission already checked */
- fp = fopen(status->p_path, "r");
-
- oops = 0;
- for (i=0; i<NUM_PARAM; i++) {
- if (fgets(buf, 80, fp) == NULL) {
- sprintf(message, "is truncated at line %d", i+1);
- oops++;
- break;
- }
- /* parse the input line */
- if (!(temp_token = str_tok(buf, '='))) {
- sprintf(message, "is missing a token at line %d", i+1);
- oops++;
- break;
- }
- if (!(str = str_tok((char *) NULL, '\n'))) {
- sprintf(message, "is missing a parameter at line %d", i+1);
- oops++;
- break;
- }
- /* sanity checking */
- if (strcmp(temp_token, token[i])) {
- sprintf(message, "is corrupted at line %d", i+1);
- oops++;
- break;
- }
-
- switch(i) {
- /* used in line_set_menu() */
- case LINE_SET:
- p.d_baud = atoi(str);
- break;
- case LINE_SET+1:
- p.d_parity = *str;
- break;
- case LINE_SET+2:
- p.d_dbits = atoi(str);
- break;
- case LINE_SET+3:
- p.d_sbits = atoi(str);
- break;
-
- /* used in term_setup() */
- case TERM_SETUP:
- p.hot = atoi(str);
- break;
- case TERM_SETUP+1:
- p.ascii_hot = strdup(str);
- break;
- case TERM_SETUP+2:
- p.d_duplex = strdup(str);
- break;
- case TERM_SETUP+3:
- p.flow = strdup(str);
- break;
- case TERM_SETUP+4:
- p.cr_in = strdup(str);
- break;
- case TERM_SETUP+5:
- p.cr_out = strdup(str);
- break;
-
- /* used in gen_setup() */
- case GEN_SETUP:
- p.logfile = strdup(str);
- break;
- case GEN_SETUP+1:
- p.dumpfile = strdup(str);
- break;
- case GEN_SETUP+2:
- p.strip = strdup(str);
- break;
- case GEN_SETUP+3:
- p.pause_char = *str;
- break;
- case GEN_SETUP+4:
- p.cr_char = *str;
- break;
- case GEN_SETUP+5:
- p.ctrl_char = *str;
- break;
- case GEN_SETUP+6:
- p.esc_char = *str;
- break;
- case GEN_SETUP+7:
- p.abort = strdup(str);
- break;
-
- /* used in gen_setup() delay_times() */
- case DELAY_TIMES:
- p.cdelay = atoi(str);
- break;
- case DELAY_TIMES+1:
- p.pause = atoi(str);
- break;
-
- /* used in ascii_xfer_setup() */
- case ASCII_SETUP:
- p.lecho = strdup(str);
- break;
- case ASCII_SETUP+1:
- p.expand = strdup(str);
- break;
- case ASCII_SETUP+2:
- p.cr_delay = atoi(str);
- break;
- case ASCII_SETUP+3:
- p.pace = strdup(str);
- break;
- case ASCII_SETUP+4:
- p.cr_up = strdup(str);
- break;
- case ASCII_SETUP+5:
- p.lf_up = strdup(str);
- break;
- case ASCII_SETUP+6:
- p.timer = atoi(str);
- break;
- case ASCII_SETUP+7:
- p.cr_dn = strdup(str);
- break;
- case ASCII_SETUP+8:
- p.lf_dn = strdup(str);
- break;
-
- /* used in d_revise() */
- case LD_CODES:
- p.ld_plus = strdup(str);
- break;
- case LD_CODES+1:
- p.ld_minus = strdup(str);
- break;
- case LD_CODES+2:
- p.ld_at = strdup(str);
- break;
- case LD_CODES+3:
- p.ld_pound = strdup(str);
- break;
- }
- }
- fclose(fp);
- if (oops) {
- sprintf(buf, "Parameter file '%s'", status->p_path);
- error_win(1, buf, message);
- }
- return(&p);
- }
-
- /*
- * Write the updated param structure to disk. The values in memory should
- * have already been "purified". Later, we'll update only the entries that
- * have been explicitly asked for. A return code of 1 means non-fatal error.
- */
-
- int
- update_param()
- {
- FILE *fp;
- char buf[80];
- void error_win();
- /* open for write */
- if (!(fp = fopen(status->p_path, "w"))) {
- sprintf(buf, "'%s'", status->p_path);
- error_win(0, "No write permission on parameter file", buf);
- return(1);
- }
-
- fprintf(fp, "D_BAUD=%d\n", param->d_baud);
- fprintf(fp, "D_PARITY=%c\n", param->d_parity);
- fprintf(fp, "D_DBITS=%d\n", param->d_dbits);
- fprintf(fp, "D_SBITS=%d\n", param->d_sbits);
- fprintf(fp, "HOT=%d\n", param->hot);
- fprintf(fp, "ASCII_HOT=%s\n", param->ascii_hot);
- fprintf(fp, "D_DUPLEX=%s\n", param->d_duplex);
- fprintf(fp, "FLOW=%s\n", param->flow);
- fprintf(fp, "CR_IN=%s\n", param->cr_in);
- fprintf(fp, "CR_OUT=%s\n", param->cr_out);
- fprintf(fp, "LOGFILE=%s\n", param->logfile);
- fprintf(fp, "DUMPFILE=%s\n", param->dumpfile);
- fprintf(fp, "STRIP=%s\n", param->strip);
- fprintf(fp, "PAUSE_CHAR=%c\n", param->pause_char);
- fprintf(fp, "CR_CHAR=%c\n", param->cr_char);
- fprintf(fp, "CTRL_CHAR=%c\n", param->ctrl_char);
- fprintf(fp, "ESC_CHAR=%c\n", param->esc_char);
- fprintf(fp, "ABORT=%s\n", param->abort);
- fprintf(fp, "CDELAY=%d\n", param->cdelay);
- fprintf(fp, "PAUSE=%d\n", param->pause);
- fprintf(fp, "LECHO=%s\n", param->lecho);
- fprintf(fp, "EXPAND=%s\n", param->expand);
- fprintf(fp, "CR_DELAY=%d\n", param->cr_delay);
- fprintf(fp, "PACE=%s\n", param->pace);
- fprintf(fp, "CR_UP=%s\n", param->cr_up);
- fprintf(fp, "LF_UP=%s\n", param->lf_up);
- fprintf(fp, "TIMER=%d\n", param->timer);
- fprintf(fp, "CR_DN=%s\n", param->cr_dn);
- fprintf(fp, "LF_DN=%s\n", param->lf_dn);
- fprintf(fp, "LD_PLUS=%s\n", param->ld_plus);
- fprintf(fp, "LD_MINUS=%s\n", param->ld_minus);
- fprintf(fp, "LD_AT=%s\n", param->ld_at);
- fprintf(fp, "LD_POUND=%s\n", param->ld_pound);
-
- fclose(fp);
- return(0);
- }
-