static void set_appres_defaults(void) { /* Set the defaults. */ appres.extended = true; appres.m3279 = true; appres.typeahead = true; appres.debug_tracing = true; appres.conf_dir = LIBX3270DIR; appres.model = "4"; appres.hostsfile = NULL; appres.port = "23"; appres.charset = "bracket"; appres.termname = NULL; appres.macros = NULL; #if !defined(_WIN32) /*[*/ appres.trace_dir = "/tmp"; #endif /*]*/ appres.oversize = NULL; appres.bind_limit = true; appres.new_environ = true; appres.max_recent = 5; appres.linemode.icrnl = true; appres.linemode.onlcr = true; appres.linemode.erase = "^H"; appres.linemode.kill = "^U"; appres.linemode.werase = "^W"; appres.linemode.rprnt = "^R"; appres.linemode.lnext = "^V"; appres.linemode.intr = "^C"; appres.linemode.quit = "^\\"; appres.linemode.eof = "^D"; appres.unlock_delay = true; appres.unlock_delay_ms = 350; set_toggle(CURSOR_POS, true); set_toggle(AID_WAIT, true); #if defined(_WIN32) /*[*/ appres.local_cp = GetACP(); #endif /*]*/ appres.devname = "x3270"; #if defined(HAVE_LIBSSL) /*[*/ appres.ssl.tls = true; #endif /*]*/ /* Let the product set the ones it wants. */ product_set_appres_defaults(); }
static void toggle_tracing(toggle_index_t ix _is_unused, enum toggle_type tt) { /* If turning on trace and no trace file, open one. */ if (toggled(TRACING) && tracef == NULL) { tracefile_on(TRACING, tt); if (tracef == NULL) { set_toggle(TRACING, false); } } else if (!toggled(TRACING)) { /* If turning off trace and not still tracing events, close the trace file. */ tracefile_off(); } }
/* * Turn screen tracing on or off. * * If turning it on, screentrace_how contains TSS_FILE or TSS_PRINTER, * and screentrace_name is NULL (use the default) or the name of a * file, printer command (Unix) or printer (Windows). */ static void toggle_screenTrace(toggle_index_t ix _is_unused, enum toggle_type tt) { char *tracefile_buf = NULL; char *tracefile; if (toggled(SCREEN_TRACE)) { /* Turn it on. */ status_screentrace((screentrace_count = 0)); if (onetime_screentrace_name != NULL) { tracefile = tracefile_buf = onetime_screentrace_name; onetime_screentrace_name = NULL; } else if (screentrace_how == TSS_FILE && appres.screentrace_file != NULL) { tracefile = appres.screentrace_file; } else { if (screentrace_how == TSS_FILE) { tracefile = tracefile_buf = screentrace_default_file(screentrace_ptype); } else { tracefile = tracefile_buf = screentrace_default_printer(); } } if (!screentrace_cb(screentrace_how, screentrace_ptype, NewString(tracefile))) { set_toggle(SCREEN_TRACE, false); status_screentrace((screentrace_count = -1)); } } else { /* Turn it off. */ if (ctlr_any_data() && !trace_skipping) { do_screentrace(false); } end_screentrace(tt == TT_FINAL); screentrace_last_how = screentrace_how; screentrace_how = TSS_FILE; /* back to the default */ screentrace_ptype = P_TEXT; /* back to the default */ status_screentrace((screentrace_count = -1)); } if (tracefile_buf != NULL) { Free(tracefile_buf); } trace_gui_toggle(); }
/* Open the trace file. */ static void tracefile_on(int reason, enum toggle_type tt) { char *tracefile_buf = NULL; char *tracefile; if (tracef != NULL) { return; } trace_reason = reason; if (appres.secure && tt != TT_INITIAL) { tracefile_ok("none"); return; } if (onetime_tracefile_name != NULL) { tracefile = tracefile_buf = onetime_tracefile_name; onetime_tracefile_name = NULL; } else if (appres.trace_file) { tracefile = appres.trace_file; } else { #if defined(_WIN32) /*[*/ tracefile_buf = xs_buffer("%s%sx3trc.$UNIQUE.txt", appres.trace_dir? appres.trace_dir: default_trace_dir(), appres.trace_dir? "\\": ""); #else /*][*/ tracefile_buf = xs_buffer("%s/x3trc.$UNIQUE", appres.trace_dir); #endif /*]*/ tracefile = tracefile_buf; } if (!trace_gui_on(reason, tt, tracefile)) { tracefile_ok(tracefile); } else { /* Turn the toggle _off_ until the popup succeeds. */ set_toggle(reason, false); } if (tracefile_buf != NULL) { Free(tracefile_buf); } }
/* Start tracing, using the specified file. */ void tracefile_ok(const char *tfn) { int devfd = -1; #if !defined(_WIN32) /*[*/ int pipefd[2]; bool just_piped = false; #endif /*]*/ char *buf; char *stfn; stfn = do_subst(tfn, DS_VARS | DS_TILDE | DS_UNIQUE); if (strchr(stfn, '\'') || ((int)strlen(stfn) > 0 && stfn[strlen(stfn)-1] == '\\')) { popup_an_error("Illegal file name: %s", tfn); Free(stfn); goto done; } tracef_max = 0; if (!strcmp(stfn, "stdout")) { tracef = stdout; } else { #if !defined(_WIN32) /*[*/ FILE *pipefile = NULL; if (!strcmp(stfn, "none") || !stfn[0]) { just_piped = true; if (!appres.trace_monitor) { popup_an_error("Must specify a trace file name"); free(stfn); goto done; } } if (appres.trace_monitor) { if (pipe(pipefd) < 0) { popup_an_errno(errno, "pipe() failed"); Free(stfn); goto done; } pipefile = fdopen(pipefd[1], "w"); if (pipefile == NULL) { popup_an_errno(errno, "fdopen() failed"); (void) close(pipefd[0]); (void) close(pipefd[1]); Free(stfn); goto done; } (void) SETLINEBUF(pipefile); (void) fcntl(pipefd[1], F_SETFD, 1); } if (just_piped) { tracef = pipefile; } else #endif /*]*/ { bool append = false; #if !defined(_WIN32) /*[*/ tracef_pipe = pipefile; #endif /*]*/ /* Get the trace file maximum. */ get_tracef_max(); /* Open and configure the file. */ if ((devfd = get_devfd(stfn)) >= 0) tracef = fdopen(dup(devfd), "a"); else if (!strncmp(stfn, ">>", 2)) { append = true; tracef = fopen(stfn + 2, "a"); } else { tracef = fopen(stfn, "w"); } if (tracef == NULL) { popup_an_errno(errno, "%s", stfn); #if !defined(_WIN32) /*[*/ fclose(tracef_pipe); (void) close(pipefd[0]); (void) close(pipefd[1]); #endif /*]*/ Free(stfn); goto done; } tracef_size = ftello(tracef); Replace(tracefile_name, NewString(append? stfn + 2: stfn)); (void) SETLINEBUF(tracef); #if !defined(_WIN32) /*[*/ (void) fcntl(fileno(tracef), F_SETFD, 1); #endif /*]*/ } } /* Start the monitor window. */ if (tracef != stdout && appres.trace_monitor && product_has_display()) { #if !defined(_WIN32) /*[*/ start_trace_window(just_piped? NULL: stfn, pipefd); #else /*][*/ if (windirs_flags && GD_CATF) { start_trace_window(stfn); } #endif /*]*/ } Free(stfn); /* We're really tracing, turn the flag on. */ set_toggle(trace_reason, true); menubar_retoggle(trace_reason); /* Display current status. */ buf = create_tracefile_header("started"); wtrace(false, "%s", buf); Free(buf); done: return; }
/* * Screen tracing callback. * Returns true for success, false for failure. */ static bool screentrace_cb(tss_t how, ptype_t ptype, char *tfn) { char *xtfn = NULL; int srv; if (how == TSS_FILE) { xtfn = do_subst(tfn, DS_VARS | DS_TILDE | DS_UNIQUE); screentracef = fopen(xtfn, "a"); } else { /* Printer. */ #if !defined(_WIN32) /*[*/ screentracef = popen(tfn, "w"); #else /*][*/ int fd; fd = win_mkstemp(&screentrace_tmpfn, ptype); if (fd < 0) { popup_an_errno(errno, "%s", "(temporary file)"); Free(tfn); return false; } screentracef = fdopen(fd, (ptype == P_GDI)? "wb+": "w"); #endif /*]*/ } if (screentracef == NULL) { if (how == TSS_FILE) popup_an_errno(errno, "%s", xtfn); else #if !defined(_WIN32) /*[*/ popup_an_errno(errno, "%s", tfn); #else /*][*/ popup_an_errno(errno, "%s", "(temporary file)"); #endif /*]*/ Free(xtfn); #if defined(_WIN32) /*[*/ Free(screentrace_tmpfn); screentrace_tmpfn = NULL; #endif /*]*/ return false; } if (how == TSS_FILE) Replace(screentrace_name, NewString(xtfn)); else Replace(screentrace_name, NewString(tfn)); Free(tfn); (void) SETLINEBUF(screentracef); #if !defined(_WIN32) /*[*/ (void) fcntl(fileno(screentracef), F_SETFD, 1); #endif /*]*/ srv = fprint_screen_start(screentracef, ptype, (how == TSS_PRINTER)? FPS_FF_SEP: 0, default_caption(), screentrace_name, &screentrace_fps); if (FPS_IS_ERROR(srv)) { if (srv == FPS_STATUS_ERROR) { popup_an_error("Screen trace start failed."); } else if (srv == FPS_STATUS_CANCEL) { popup_an_error("Screen trace canceled."); } fclose(screentracef); return false; } /* We're really tracing, turn the flag on. */ set_toggle(SCREEN_TRACE, true); menubar_retoggle(SCREEN_TRACE); return true; }
static void toggle_reset_action(GtkAction *action,int id) { set_toggle(id,FALSE); }
static void toggle_set_action(GtkAction *action,int id) { set_toggle(id,TRUE); }
static void toggle_action(GtkToggleAction *action, gpointer id) { Trace("%s(%d)",__FUNCTION__,(int) id); set_toggle((int) id,gtk_toggle_action_get_active(action)); }
/* Parse the command line and read in any session file. */ int parse_command_line(int argc, const char **argv, const char **cl_hostname) { size_t cl; int i; int hn_argc; size_t sl; size_t xcmd_len = 0; char *xcmd; int xargc; const char **xargv; bool 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] = NULL; *(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] != NULL && !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 (session_suffix == NULL) { session_suffix = xs_buffer(".%s", app); session_suffix_len = strlen(session_suffix); } #if defined(_WIN32) /*[*/ if (session_short_suffix == NULL) { session_short_suffix = xs_buffer(".%.3s", app); session_short_suffix_len = strlen(session_short_suffix); } #endif /*]*/ if (*cl_hostname != NULL && (((sl = strlen(*cl_hostname)) > session_suffix_len && !strcasecmp(*cl_hostname + sl - session_suffix_len, session_suffix)) #if defined(_WIN32) /*[*/ || ((sl = strlen(*cl_hostname)) > session_short_suffix_len && !strcasecmp(*cl_hostname + sl - session_short_suffix_len, session_short_suffix)) #endif /*]*/ )) { const char *pname; if (!read_resource_file(*cl_hostname, true)) { x3270_exit(1); } read_session_or_profile = true; pname = strrchr(*cl_hostname, '\\'); if (pname != NULL) { pname++; } else { pname = *cl_hostname; } profile_name = NewString(pname); Replace(profile_path, NewString(profile_name)); sl = strlen(profile_name); if (sl > session_suffix_len && !strcasecmp(profile_name + sl - session_suffix_len, session_suffix)) { profile_name[sl - session_suffix_len] = '\0'; #if defined(_WIN32) /*[*/ } else if (sl > session_short_suffix_len && !strcasecmp(profile_name + sl - session_short_suffix_len, session_short_suffix)) { profile_name[sl - session_short_suffix_len] = '\0'; #endif /*]*/ } *cl_hostname = appres.hostname; /* might be NULL */ } else { /* There is no session file. */ /* For c3270 only, read in the c3270 profile (~/.c3270pro). */ if (merge_profilep != NULL) { read_session_or_profile = (*merge_profilep)(); } /* * 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 == NULL && appres.hostname != NULL) { *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 == NULL) { appres.once = false; } if (!appres.debug_tracing) { /* debug_tracing was explicitly cleared */ set_toggle(TRACING, false); } #if defined(_WIN32) /*[*/ if (appres.utf8) { /* utf8 overrides local_cp */ appres.local_cp = CP_UTF8; } #endif /*]*/ return argc; }