/* * Initialize the model number and oversize. This needs to happen before the * screen is initialized. */ void model_init(void) { int model_number; int ovc, ovr; /* * Sort out model and color modes, based on the model number resource. */ model_number = parse_model_number(appres.model); if (model_number < 0) { popup_an_error("Invalid model number: %s", appres.model); model_number = 0; } if (!model_number) { #if defined(RESTRICT_3279) /*[*/ model_number = 3; #else /*][*/ model_number = 4; #endif /*]*/ } #if defined(RESTRICT_3279) /*[*/ if (appres.m3279 && model_number == 4) { model_number = 3; } #endif /*]*/ if (appres.interactive.mono) { appres.m3279 = false; } if (!appres.extended) { appres.oversize = NULL; } ovc = 0; ovr = 0; if (appres.extended && appres.oversize != NULL) { if (product_auto_oversize() && !strcasecmp(appres.oversize, "auto")) { ovc = -1; ovr = -1; } else { int x_ovc, x_ovr; char junk; if (sscanf(appres.oversize, "%dx%d%c", &x_ovc, &x_ovr, &junk) == 2) { ovc = x_ovc; ovr = x_ovr; } else { xs_warning("Invalid %s value '%s'", ResOversize, appres.oversize); } } } set_rows_cols(model_number, ovc, ovr); net_set_default_termtype(); }
void parse_xrm(const char *arg, const char *where) { const char *name; unsigned rnlen; const char *s; int i; char *t; void *address = NULL; enum resource_type type = XRM_STRING; Boolean quoted; char c; #if defined(C3270) /*[*/ char *hide; Boolean arbitrary = False; #endif /*]*/ /* Validate and split. */ if (validate_and_split_resource(where, arg, &name, &rnlen, &s) < 0) return; /* Look up the name. */ for (i = 0; resources[i].name != CN; i++) { if (!strncapcmp(resources[i].name, name, rnlen)) { address = resources[i].address; type = resources[i].type; break; } } if (address == NULL) { for (i = 0; toggle_names[i].name != NULL; i++) { if (!strncapcmp(toggle_names[i].name, name, rnlen)) { address = &appres.toggle[toggle_names[i].index].value; type = XRM_BOOLEAN; break; } } } /* XXX: This needs to work for s3270, too. */ #if defined(C3270) /*[*/ if (address == NULL && valid_explicit(name, rnlen) == 0) { /* * Handle resources that are accessed only via get_resource(). */ address = &hide; type = XRM_STRING; arbitrary = True; } #endif /*]*/ if (address == NULL) { xs_warning("%s: Unknown resource name: %.*s", where, (int)rnlen, name); return; } switch (type) { case XRM_BOOLEAN: if (!strcasecmp(s, "true") || !strcasecmp(s, "t") || !strcmp(s, "1")) { *(Boolean *)address = True; } else if (!strcasecmp(s, "false") || !strcasecmp(s, "f") || !strcmp(s, "0")) { *(Boolean *)address = False; } else { xs_warning("%s: Invalid Boolean value: %s", where, s); *(Boolean *)address = False; } break; case XRM_STRING: t = Malloc(strlen(s) + 1); *(char **)address = t; quoted = False; #if defined(WC3270) /*[*/ /* * Hack to allow unquoted UNC-path printer names from older * versions of the Session Wizard to continue to work, even * though the rules now require quoted backslashes in resource * values. */ if (!strncapcmp(ResPrinterName, name, rnlen) && s[0] == '\\' && s[1] == '\\' && s[2] != '\\' && strchr(s + 2, '\\') != NULL) { strcpy(t, s); break; } #endif /*]*/ while ((c = *s++) != '\0') { if (quoted) { switch (c) { case 'b': *t++ = '\b'; break; case 'f': *t++ = '\f'; break; case 'n': *t++ = '\n'; break; case 'r': *t++ = '\r'; break; case 't': *t++ = '\t'; break; case '\\': /* Quote the backslash. */ *t++ = '\\'; break; default: /* Eat the backslash. */ *t++ = c; break; } quoted = False; } else if (c == '\\') { quoted = True; } else { *t++ = c; } } *t = '\0'; break; case XRM_INT: { long n; char *ptr; n = strtol(s, &ptr, 0); if (*ptr != '\0') { xs_warning("%s: Invalid Integer value: %s", where, s); } else { *(int *)address = (int)n; } break; } } #if defined(C3270) /*[*/ /* Add a new, arbitrarily-named resource. */ if (arbitrary) { char *rsname; rsname = Malloc(rnlen + 1); (void) strncpy(rsname, name, rnlen); rsname[rnlen] = '\0'; add_resource(rsname, hide); } #endif /*]*/ }
/* * Initialize or re-initialize an ft_conf structure from the appres * defaults. */ void ft_init_conf(ft_conf_t *p) { /* Initialize the private state. */ p->receive_flag = true; p->host_type = HT_TSO; p->ascii_flag = true; p->cr_flag = p->ascii_flag; p->remap_flag = p->ascii_flag; p->allow_overwrite = false; p->append_flag = false; p->recfm = DEFAULT_RECFM; p->units = DEFAULT_UNITS; p->lrecl = 0; p->blksize = 0; p->primary_space = 0; p->secondary_space = 0; p->avblock = 0; p->dft_buffersize = set_dft_buffersize(0); #if defined(_WIN32) /*[*/ p->windows_codepage = appres.ft.codepage? appres.ft.codepage: (appres.ft.codepage_bc? appres.ft.codepage_bc: appres.local_cp); #endif /*]*/ /* Apply resources. */ if (appres.ft.blksize) { p->blksize = appres.ft.blksize; } if (appres.ft.direction) { if (!strcasecmp(appres.ft.direction, "receive")) { p->receive_flag = true; } else if (!strcasecmp(appres.ft.direction, "send")) { p->receive_flag = false; } else { xs_warning("Invalid %s '%s', ignoring", ResFtDirection, appres.ft.direction); appres.ft.direction = NULL; } } if (appres.ft.host && !ft_encode_host_type(appres.ft.host, &p->host_type)) { xs_warning("Invalid %s '%s', ignoring", ResFtHost, appres.ft.host); appres.ft.host = NULL; } if (appres.ft.host_file) { Replace(p->host_filename, NewString(appres.ft.host_file)); } else { Replace(p->host_filename, NULL); } if (appres.ft.local_file) { Replace(p->local_filename, NewString(appres.ft.local_file)); } else { Replace(p->local_filename, NULL); } if (appres.ft.mode) { if (!strcasecmp(appres.ft.mode, "ascii")) { p->ascii_flag = true; } else if (!strcasecmp(appres.ft.mode, "binary")) { p->ascii_flag = false; } else { xs_warning("Invalid %s '%s', ignoring", ResFtMode, appres.ft.mode); appres.ft.host = NULL; } } if (appres.ft.cr) { /* must come after processing "ascii" */ if (!strcasecmp(appres.ft.cr, "auto")) { p->cr_flag = p->ascii_flag; } else if (!strcasecmp(appres.ft.cr, "add") || !strcasecmp(appres.ft.cr, "remove")) { p->cr_flag = true; } else if (!strcasecmp(appres.ft.cr, "keep")) { p->cr_flag = false; } else { xs_warning("Invalid %s '%s', ignoring", ResFtCr, appres.ft.cr); appres.ft.cr = NULL; } } if (appres.ft.remap) { if (!strcasecmp(appres.ft.remap, "yes")) { p->remap_flag = true; } else if (!strcasecmp(appres.ft.remap, "no")) { p->remap_flag = false; } else { xs_warning("Invalid %s '%s', ignoring", ResFtRemap, appres.ft.remap); appres.ft.remap = NULL; } } if (appres.ft.exist) { if (!strcasecmp(appres.ft.exist, "keep")) { p->allow_overwrite = false; p->append_flag = false; } else if (!strcasecmp(appres.ft.exist, "replace")) { p->allow_overwrite = true; p->append_flag = false; } else if (!strcasecmp(appres.ft.exist, "append")) { p->allow_overwrite = false; p->append_flag = true; } else { xs_warning("Invalid %s '%s', ignoring", ResFtExist, appres.ft.exist); appres.ft.exist = NULL; } } if (appres.ft.primary_space) { p->primary_space = appres.ft.primary_space; } if (appres.ft.recfm && !ft_encode_recfm(appres.ft.recfm, &p->recfm)) { xs_warning("Invalid %s '%s', ignoring", ResFtRecfm, appres.ft.recfm); appres.ft.recfm = NULL; } if (appres.ft.secondary_space) { p->secondary_space = appres.ft.secondary_space; } if (appres.ft.lrecl) { p->lrecl = appres.ft.lrecl; } if (appres.ft.allocation && !ft_encode_units(appres.ft.allocation, &p->units)) { xs_warning("Invalid %s '%s', ignoring", ResFtAllocation, appres.ft.allocation); appres.ft.allocation = NULL; } if (appres.ft.avblock) { p->avblock = appres.ft.avblock; } p->dft_buffersize = set_dft_buffersize(0); }
/* Read resources from a file. */ int read_resource_file(const char *filename, Boolean fatal) { FILE *f; int ilen; char buf[4096]; char *where; int lno = 0; f = fopen(filename, "r"); if (f == NULL) { if (fatal) xs_warning("Cannot open '%s': %s", filename, strerror(errno)); return -1; } /* Merge in what's in the file into the resource database. */ where = Malloc(strlen(filename) + 64); ilen = 0; while (fgets(buf + ilen, sizeof(buf) - ilen, f) != CN || ilen) { char *s, *t; unsigned sl; Boolean bsl; lno++; /* Stip any trailing newline. */ sl = strlen(buf + ilen); if (sl && (buf + ilen)[sl-1] == '\n') (buf + ilen)[--sl] = '\0'; /* * Translate backslash-n to real newline characters, and * remember if the last character is a backslash. */ for (bsl = False, s = buf + ilen, t = s; *s; s++) { if (bsl) { if (*s == 'n') *t++ = '\n'; else *t++ = *s; bsl = False; } else if (*s == '\\') bsl = True; else { *t++ = *s; bsl = False; } } *t = '\0'; /* Skip leading whitespace. */ s = buf; while (isspace(*s)) s++; /* Skip comments _before_ checking for line continuation. */ if (*s == '!') { ilen = 0; continue; } if (*s == '#') { (void) sprintf(where, "%s:%d: Invalid profile " "syntax ('#' ignored)", filename, lno); Warning(where); ilen = 0; continue; } /* If this line is a continuation, try again. */ if (bsl) { ilen += strlen(buf + ilen); if (ilen >= sizeof(buf) - 1) { (void) sprintf(where, "%s:%d: Line too long\n", filename, lno); Warning(where); break; } continue; } /* Strip trailing whitespace and check for empty lines. */ sl = strlen(s); while (sl && isspace(s[sl-1])) s[--sl] = '\0'; if (!sl) { ilen = 0; continue; } /* Digest it. */ (void) sprintf(where, "%s:%d", filename, lno); parse_xrm(s, where); /* Get ready for the next iteration. */ ilen = 0; } Free(where); return 0; }
void parse_xrm(const char *arg, const char *where) { static char me_dot[] = ME "."; static char me_star[] = ME "*"; unsigned match_len; const char *s; unsigned rnlen; int i; char *t; void *address = NULL; enum resource_type type = XRM_STRING; #if defined(C3270) /*[*/ char *add_buf = CN; char *hide; Boolean arbitrary = False; #endif /*]*/ /* Enforce "-3270." or "-3270*" or "*". */ if (!strncmp(arg, me_dot, sizeof(me_dot)-1)) match_len = sizeof(me_dot)-1; else if (!strncmp(arg, me_star, sizeof(me_star)-1)) match_len = sizeof(me_star)-1; else if (arg[0] == '*') match_len = 1; else { xs_warning("%s: Invalid resource syntax '%.*s', name must " "begin with '%s'", where, (int) sizeof(me_dot)-1, arg, me_dot); return; } /* Separate the parts. */ s = arg + match_len; while (*s && *s != ':' && !isspace(*s)) s++; rnlen = s - (arg + match_len); if (!rnlen) { xs_warning("%s: Invalid resource syntax, missing resource " "name", where); return; } while (isspace(*s)) s++; if (*s != ':') { xs_warning("%s: Invalid resource syntax, missing ':'", where); return; } s++; while (isspace(*s)) s++; /* Look up the name. */ for (i = 0; resources[i].name != CN; i++) { if (!strncapcmp(resources[i].name, arg + match_len, rnlen)) { address = resources[i].address; type = resources[i].type; #if defined(C3270) /*[*/ if (address == NULL) { add_buf = Malloc(strlen(s) + 1); address = add_buf; } #endif /*]*/ break; } } #if defined(C3270) /*[*/ if (address == NULL) { if (!strncasecmp(ResKeymap ".", arg + match_len, strlen(ResKeymap ".")) || !strncasecmp(ResCharset ".", arg + match_len, strlen(ResCharset ".")) || !strncasecmp(ResDisplayCharset ".", arg + match_len, strlen(ResDisplayCharset ".")) || !strncasecmp(ResCodepage ".", arg + match_len, strlen(ResCodepage ".")) || !strncasecmp("host.", arg + match_len, 5) || !strncasecmp("printer.", arg + match_len, 8) || #if defined(_WIN32) /*[*/ !strncasecmp(ResHostColorFor, arg + match_len, strlen(ResHostColorFor)) || !strncasecmp(ResConsoleColorForHostColor, arg + match_len, strlen(ResConsoleColorForHostColor)) #else /*][*/ !strncasecmp(ResCursesColorFor, arg + match_len, strlen(ResCursesColorFor)) #endif /*]*/ ) { address = &hide; type = XRM_STRING; arbitrary = True; } } #endif /*]*/ if (address == NULL) { xs_warning("%s: Unknown resource name: %.*s", where, (int)rnlen, arg + match_len); return; } switch (type) { case XRM_BOOLEAN: if (!strcasecmp(s, "true") || !strcasecmp(s, "t") || !strcmp(s, "1")) { *(Boolean *)address = True; } else if (!strcasecmp(s, "false") || !strcasecmp(s, "f") || !strcmp(s, "0")) { *(Boolean *)address = False; } else { xs_warning("%s: Invalid Boolean value: %s", where, s); } break; case XRM_STRING: t = Malloc(strlen(s) + 1); *(char **)address = t; if (*s == '"') { Boolean quoted = False; char c; s++; while ((c = *s++) != '\0') { if (quoted) { switch (c) { case 'n': *t++ = '\n'; break; case 'r': *t++ = '\r'; break; case 'b': *t++ = '\b'; break; default: *t++ = c; break; } quoted = False; } else if (c == '\\') { quoted = True; } else if (c == '"') { break; } else { *t++ = c; } } *t = '\0'; } else { (void) strcpy(t, s); } break; case XRM_INT: { long n; char *ptr; n = strtol(s, &ptr, 0); if (*ptr != '\0') { xs_warning("%s: Invalid Integer value: %s", where, s); } else { *(int *)address = (int)n; } break; } } #if defined(C3270) /*[*/ /* Add a new, arbitrarily-named resource. */ if (arbitrary) { char *rsname; rsname = Malloc(rnlen + 1); (void) strncpy(rsname, arg + match_len, rnlen); rsname[rnlen] = '\0'; add_resource(rsname, hide); } #endif /*]*/ }