int parse_command_line(int argc, const char **argv, const char **cl_hostname) { int cl, i; int hn_argc; int sl; int xcmd_len = 0; char *xcmd; int xargc; const char **xargv; Boolean read_session_or_profile = False; /* Figure out who we are */ #if defined(_WIN32) /*[*/ programname = strrchr(argv[0], '\\'); #else /*][*/ programname = strrchr(argv[0], '/'); #endif /*]*/ if (programname) ++programname; else programname = argv[0]; /* Save the command string for tracing purposes. */ cl = strlen(programname); for (i = 0; i < argc; i++) { cl += 1 + strlen(argv[i]); } cl++; command_string = Malloc(cl); (void) strcpy(command_string, programname); for (i = 0; i < argc; i++) { (void) strcat(strcat(command_string, " "), argv[i]); } /* * Save the command-line options so they can be reapplied after * the session file or profile has been read in. */ xcmd_len = 0; for (i = 0; i < argc; i++) xcmd_len += strlen(argv[i]) + 1; xcmd = Malloc(xcmd_len + 1); xargv = (const char **)Malloc((argc + 1) * sizeof(char *)); xcmd_len = 0; for (i = 0; i < argc; i++) { xargv[i] = xcmd + xcmd_len; (void) strcpy(xcmd + xcmd_len, argv[i]); xcmd_len += strlen(argv[i]) + 1; } xargv[i] = CN; *(xcmd + xcmd_len) = '\0'; xargc = argc; #if defined(LOCAL_PROCESS) /*[*/ /* Pick out the -e option. */ parse_local_process(&argc, argv, cl_hostname); #endif /*]*/ /* Set the defaults. */ set_appres_defaults(); /* Parse command-line options. */ parse_options(&argc, argv); /* Pick out the remaining -set and -clear toggle options. */ parse_set_clear(&argc, argv); /* Now figure out if there's a hostname. */ for (hn_argc = 1; hn_argc < argc; hn_argc++) { if (!strcmp(argv[hn_argc], LAST_ARG)) break; } /* Verify command-line syntax. */ switch (hn_argc) { case 1: break; case 2: no_minus(argv[1]); *cl_hostname = argv[1]; break; case 3: no_minus(argv[1]); no_minus(argv[2]); *cl_hostname = xs_buffer("%s:%s", argv[1], argv[2]); break; default: usage("Too many command-line arguments"); break; } /* Delete the host name and any "--". */ if (argv[hn_argc] != CN && !strcmp(argv[hn_argc], LAST_ARG)) hn_argc++; if (hn_argc > 1) { for (i = 1; i < argc - hn_argc + 2; i++) { argv[i] = argv[i + hn_argc - 1]; } } /* Merge in the session. */ if (*cl_hostname != CN && (((sl = strlen(*cl_hostname)) > SESSION_SFX_LEN && !strcasecmp(*cl_hostname + sl - SESSION_SFX_LEN, SESSION_SFX)) #if defined(_WIN32) /*[*/ || ((sl = strlen(*cl_hostname)) > SESSION_SSFX_LEN && !strcasecmp(*cl_hostname + sl - SESSION_SSFX_LEN, SESSION_SSFX)) #endif /*]*/ )) { const char *pname; if (read_resource_file(*cl_hostname, True) < 0) x3270_exit(1); read_session_or_profile = True; pname = strrchr(*cl_hostname, '\\'); if (pname != CN) pname++; else pname = *cl_hostname; profile_name = NewString(pname); Replace(profile_path, NewString(profile_name)); sl = strlen(profile_name); if (sl > SESSION_SFX_LEN && !strcasecmp(profile_name + sl - SESSION_SFX_LEN, SESSION_SFX)) { profile_name[sl - SESSION_SFX_LEN] = '\0'; #if defined(_WIN32) /*[*/ } else if (sl > SESSION_SSFX_LEN && !strcasecmp(profile_name + sl - SESSION_SSFX_LEN, SESSION_SSFX)) { profile_name[sl - SESSION_SSFX_LEN] = '\0'; #endif /*]*/ } *cl_hostname = appres.hostname; /* might be NULL */ } else { /* There is no session file. */ #if defined(C3270) && !defined(_WIN32) /*[*/ /* * For c3270 only, read in the c3270 profile (~/.c3270pro). */ read_session_or_profile = merge_profile(); #endif /*]*/ /* * If there was a hostname resource defined somewhere, but not * as a positional command-line argument, pretend it was one, * so we will connect to it at start-up. */ if (*cl_hostname == CN && appres.hostname != CN) *cl_hostname = appres.hostname; } /* * Now parse the command-line arguments again, so they take * precedence over the session file or profile. */ if (read_session_or_profile) { parse_options(&xargc, xargv); parse_set_clear(&xargc, xargv); } /* Can't free xcmd, parts of it are still in use. */ Free((char *)xargv); /* * All right, we have all of the resources defined. * Sort out the contradictory and implicit settings. */ if (appres.apl_mode) appres.charset = Apl; if (*cl_hostname == CN) appres.once = False; if (appres.conf_dir == CN) appres.conf_dir = LIBX3270DIR; #if defined(X3270_TRACE) /*[*/ if (!appres.debug_tracing) { appres.toggle[TRACING].value = False; } #endif /*]*/ return argc; }
/* * Set default options */ static void initialize(void) { memset(&appres,0,sizeof(appres)); #ifdef DEBUG init_calls++; Trace("Initializing library (calls: %d)",init_calls); #endif initialize_toggles(&h3270,appres.toggle); #if defined(_WIN32) (void) get_version_info(); #endif Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); /* Set the defaults. */ appres.mono = False; appres.extended = True; #if defined(C3270) /*[*/ appres.m3279 = True; #else /*][*/ appres.m3279 = False; #endif /*]*/ appres.modified_sel = False; appres.apl_mode = False; #if defined(C3270) || defined(TCL3270) /*[*/ // appres.scripted = False; #else /*][*/ appres.scripted = True; #endif /*]*/ appres.numeric_lock = False; // appres.secure = False; #if defined(C3270) /*[*/ appres.oerr_lock = True; #else /*][*/ appres.oerr_lock = False; #endif /*]*/ appres.typeahead = True; appres.debug_tracing = True; #if defined(C3270) /*[*/ appres.compose_map = "latin1"; #endif /*]*/ appres.model = ""; appres.hostsfile = CN; appres.port = "telnet"; #if !defined(_WIN32) /*[*/ appres.charset = "bracket"; #else /*][*/ if (is_nt) appres.charset = "bracket"; else appres.charset = "bracket437"; #endif /*]*/ appres.termname = CN; appres.macros = CN; #if defined(X3270_TRACE) /*[*/ #if !defined(_WIN32) /*[*/ appres.trace_dir = "/tmp"; #endif /*]*/ #if defined(X3270_DISPLAY) || defined(WC3270) /*[*/ appres.trace_monitor = True; #endif /*]*/ #endif /*]*/ appres.oversize = CN; #if defined(C3270) /*[*/ appres.meta_escape = "auto"; // appres.curses_keypad = True; // appres.cbreak_mode = False; #endif /*]*/ #if defined(X3270_ANSI) /*[*/ appres.icrnl = True; appres.inlcr = False; appres.onlcr = True; appres.erase = "^H"; appres.kill = "^U"; appres.werase = "^W"; appres.rprnt = "^R"; appres.lnext = "^V"; appres.intr = "^C"; appres.quit = "^\\"; appres.eof = "^D"; #endif /*]*/ appres.unlock_delay = True; #if defined(X3270_FT) /*[*/ appres.dft_buffer_size = DFT_BUF; #endif /*]*/ #if defined(C3270) && !defined(LIB3270) /*[*/ appres.toggle[CURSOR_POS].value = True; #endif /*]*/ #if defined(X3270_SCRIPT) || defined(TCL3270) /*[*/ appres.toggle[AID_WAIT].value = True; #endif /*]*/ #if defined(C3270) && defined(X3270_SCRIPT) /*[*/ appres.plugin_command = "x3270hist.pl"; #endif /*]*/ #if defined(C3270) && defined(_WIN32) /*[*/ appres.highlight_underline = True; #endif /*]*/ #if defined(C3270) && !defined(_WIN32) && !defined(LIB3270) /*[*/ /* Merge in the profile. */ merge_profile(); #endif /*]*/ }