Beispiel #1
0
/* Set the CGCSGIDs. */
static void
set_cgcsgids(const char *spec)
{
    int n_ids = 0;
    char *spec_copy;
    char *buf;
    char *token;

    if (spec != NULL) {
	buf = spec_copy = NewString(spec);
	while (n_ids >= 0 && (token = strtok(buf, "+")) != NULL) {
	    unsigned long *idp = NULL;

	    buf = NULL;
	    switch (n_ids) {
	    case 0:
		idp = &cgcsgid;
		break;
	    case 1:
		idp = &cgcsgid_dbcs;
		break;
	    default:
		popup_an_error("Extra CGCSGID(s), ignoring");
		break;
	    }
	    if (idp == NULL)
		break;
	    if (!set_cgcsgid(token, idp)) {
		popup_an_error("Invalid CGCSGID '%s', ignoring", token);
		n_ids = -1;
		break;
	    }
	    n_ids++;
	}
	Free(spec_copy);
	if (n_ids > 0) {
	    return;
	}
    }

    if (appres.sbcs_cgcsgid != NULL) {
	cgcsgid = strtoul(appres.sbcs_cgcsgid, NULL, 0);
    } else {
	cgcsgid = DEFAULT_CGEN | DEFAULT_CSET;
    }
    if (appres.dbcs_cgcsgid != NULL) {
	cgcsgid_dbcs = strtoul(appres.dbcs_cgcsgid, NULL, 0);
    } else {
	cgcsgid_dbcs = 0L;
    }
}
Beispiel #2
0
/* Character set init, part 2. */
static enum cs_result
charset_init2(const char *csname, const char *realname, const char *codepage,
	const char *cgcsgid, bool is_dbcs)
{
    /* Can't swap DBCS modes while connected. */
    if (IN_3270 && is_dbcs != dbcs) {
	popup_an_error("Can't change DBCS modes while connected");
	return CS_ILLEGAL;
    }

    if (!screen_new_display_charsets(realname, csname)) {
	return CS_PREREQ;
    }

    /* Set the global DBCS mode. */
    dbcs = is_dbcs;

    /* Set up the cgcsgids. */
    set_cgcsgids(cgcsgid);

    /* Set up the host code page. */
    set_host_codepage((char *)codepage);

    /* Set up the character set name. */
    set_charset_name(csname);

    return CS_OKAY;
}
Beispiel #3
0
/* Pop up an error dialog, based on an error number. */
void
popup_an_errno(int errn, const char *fmt, ...)
{
    va_list args;
    char *s;

    va_start(args, fmt);
    s = xs_vbuffer(fmt, args);
    va_end(args);

    if (errn > 0) {
	popup_an_error("%s: %s", s, strerror(errn));
    } else {
	popup_an_error("%s", s);
    }
    Free(s);
}
Beispiel #4
0
/* Pop up an error dialog, based on an error number. */
void
popup_an_errno(int errn, const char *fmt, ...)
{
	va_list args;
	char *s;

	va_start(args, fmt);
	(void) vsnprintf(vmsgbuf, sizeof(vmsgbuf), fmt, args);
	va_end(args);
	s = NewString(vmsgbuf);

	if (errn > 0)
		popup_an_error("%s: %s", s, strerror(errn));
	else
		popup_an_error("%s", s);
	Free(s);
}
Beispiel #5
0
static bool  
Transfer_action(ia_t ia, unsigned argc, const char **argv)
{
    ft_conf_t *p = NULL;

    action_debug("Transfer", ia, argc, argv);

    /* Make sure we're connected. */
    if (!IN_3270) {
	popup_an_error("Transfer: Not connected");
	return false;
    }

    /* Check for interactive mode. */
    if (argc == 0) {
	if (!gui_conf_initted) {
	    ft_init_conf(&gui_ft_conf);
	    gui_ft_conf.is_action = true;
	    gui_conf_initted = true;
	}
	switch (ft_gui_interact(&gui_ft_conf)) {
	case FGI_NOP:
	    /* Hope the defaults are enough. */
	    break;
	case FGI_SUCCESS:
	    /* Proceed as specified in the ft_state. */
	    p = &gui_ft_conf;
	    break;
	case FGI_ABORT:
	    /* User said no. */
	    return false;
	}
    }

    if (p == NULL) {
	/* Parse the keywords into the ft_state structure. */
	p = parse_ft_keywords(argc, argv);
	if (p == NULL) {
	    return false;
	}
	p->is_interactive = (ia == IA_COMMAND);
    }

    /* Start the transfer. */
    fts.local_file = ft_go(p);
    if (fts.local_file == NULL) {
	return false;
    }

    /* If interactive, tell the user we're waiting. */
    ft_gui_awaiting();

    /* Set a timeout for failed command start. */
    ft_start_id = AddTimeOut(10 * 1000, ft_didnt_start);

    /* Success. */
    return true;
}
Beispiel #6
0
/*
 * 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();
}
Beispiel #7
0
/* Pop up a message, end the transfer. */
void
ft_complete(const char *errmsg)
{
    /* Close the local file. */
    if (fts.local_file != NULL && fclose(fts.local_file) < 0) {
	popup_an_errno(errno, "close(%s)", ftc->local_filename);
    }
    fts.local_file = NULL;

    /* Clean up the state. */
    ft_state = FT_NONE;
    if (ft_start_id != NULL_IOID) {
	RemoveTimeOut(ft_start_id);
	ft_start_id = NULL_IOID;
    }

    /* Get the idle timeout going again. */
    idle_ft_complete();

    /* Pop down the in-progress shell. */
    ft_gui_progress_popdown();

    /* Pop up the text. */
    if (errmsg != NULL) {
	char *msg_copy = NewString(errmsg);

	/* Make sure the error message will fit on the pop-up. */
	ft_gui_errmsg_prepare(msg_copy);

	/* Clear out the progress display. */
	ft_gui_clear_progress();

	/* Pop up the error. */
	popup_an_error("%s", msg_copy);
	Free(msg_copy);
    } else {
	struct timeval t1;
	double bytes_sec;
	char *buf;

	(void) gettimeofday(&t1, NULL);
	bytes_sec = (double)fts.length /
		((double)(t1.tv_sec - t0.tv_sec) + 
		 (double)(t1.tv_usec - t0.tv_usec) / 1.0e6);
	buf = xs_buffer(get_message("ftComplete"), fts.length,
		display_scale(bytes_sec),
		fts.is_cut ? "CUT" : "DFT");
	ft_gui_clear_progress();
	ft_gui_complete_popup(buf);
	Free(buf);
    }

    /* I hope I can do this unconditionally. */
    sms_continue();
}
Beispiel #8
0
/**
 * Initialize the httpd socket.
 *
 * @param[in] sa	address and port to listen on
 * @param[in] sa_len	length of sa
 */
void
hio_init(struct sockaddr *sa, socklen_t sa_len)
{
    int on = 1;

    listen_s = socket(sa->sa_family, SOCK_STREAM, 0);
    if (listen_s == INVALID_SOCKET) {
	popup_an_error("httpd socket: %s", socket_errtext());
	return;
    }
    if (setsockopt(listen_s, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
		sizeof(on)) < 0) {
	popup_an_error("httpd setsockopt: %s", socket_errtext());
	SOCK_CLOSE(listen_s);
	listen_s = INVALID_SOCKET;
	return;
    }
    if (bind(listen_s, sa, sa_len) < 0) {
	popup_an_error("httpd bind: %s", socket_errtext());
	SOCK_CLOSE(listen_s);
	listen_s = INVALID_SOCKET;
	return;
    }
    if (listen(listen_s, 10) < 0) {
	popup_an_error("httpd listen: %s", socket_errtext());
	SOCK_CLOSE(listen_s);
	listen_s = INVALID_SOCKET;
	return;
    }
#if defined(_WIN32) /*[*/
    listen_event = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (listen_event == NULL) {
	popup_an_error("httpd: cannot create listen handle");
	SOCK_CLOSE(listen_s);
	listen_s = INVALID_SOCKET;
	return;
    }
    if (WSAEventSelect(listen_s, listen_event, FD_ACCEPT) != 0) {
	popup_an_error("httpd: WSAEventSelect failed: %s",
		socket_errtext());
	CloseHandle(listen_event);
	listen_event = INVALID_HANDLE_VALUE;
	SOCK_CLOSE(listen_s);
	listen_s = INVALID_SOCKET;
    }
    (void) AddInput(listen_event, hio_connection);
#else /*][*/
    (void) AddInput(listen_s, hio_connection);
#endif /*]*/
}
Beispiel #9
0
/*
 * Start up a window to monitor the trace file.
 *
 * @param[in] path	Trace file path.
 */
static void
start_trace_window(const char *path)
{
    STARTUPINFO startupinfo;
    PROCESS_INFORMATION process_information;

    memset(&startupinfo, 0, sizeof(STARTUPINFO));
    startupinfo.cb = sizeof(STARTUPINFO);
    startupinfo.lpTitle = (char *)path;
    memset(&process_information, 0, sizeof(PROCESS_INFORMATION));
    if (CreateProcess(lazyaf("%scatf.exe", instdir),
		lazyaf("\"%scatf.exe\" \"%s\"", instdir, path),
		NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL,
		NULL, &startupinfo, &process_information) == 0) {
	popup_an_error("CreateProcess(%scatf.exe \"%s\") failed: %s", instdir,
		path, win32_strerror(GetLastError()));
    } else {
	tracewindow_handle = process_information.hProcess;
	CloseHandle(process_information.hThread);
    }
}
Beispiel #10
0
/*
 * Initialize printing to a GDI printer.
 */
gdi_status_t
gdi_print_start(const char *printer_name, unsigned opts)
{
    const char *fail = "";

    if (!uparm.done) {
	/* Set the defaults. */
	uparm.orientation = 0;
	uparm.hmargin = 0.5;
	uparm.vmargin = 0.5;
	uparm.font_name = NULL;
	uparm.font_size = 0; /* auto */
	uparm.spp = 1;

	/* Gather up the parameters. */
	gdi_get_params(&uparm);

	/* Don't do this again. */
	uparm.done = true;
    }

    /* Initialize the printer and pop up the dialog. */
    switch (gdi_init(printer_name, opts, &fail)) {
    case GDI_STATUS_SUCCESS:
	vtrace("[gdi] initialized\n");
	break;
    case GDI_STATUS_ERROR:
	popup_an_error("Printer initialization error: %s", fail);
	return GDI_STATUS_ERROR;
    case GDI_STATUS_CANCEL:
	vtrace("[gdi] canceled\n");
	return GDI_STATUS_CANCEL;
    }

    return GDI_STATUS_SUCCESS;
}
Beispiel #11
0
void lib3270_session_init(H3270 *hSession, const char *model)
{
	int 	ovc, ovr;
	char	junk;
	int		model_number;

	memset(hSession,0,sizeof(H3270));
	hSession->sz = sizeof(H3270);
	hSession->sock = -1;
	hSession->model_num = -1;
//	hSession->first_changed = -1;
//	hSession->last_changed = -1;
	hSession->cstate = NOT_CONNECTED;
	hSession->oia_status = -1;

	strncpy(hSession->full_model_name,"IBM-",FULL_MODEL_NAME_SIZE);
	hSession->model_name = &hSession->full_model_name[4];

	/*
	 * Sort out model and color modes, based on the model number resource.
	 */ /*
	if(appres.model && *appres.model)
		model = appres.model;
	*/

	if(!*model)
		model = "2";	// No model, use the default one

//	Trace("Parsing model: %s",appres.model);
	model_number = parse_model_number(model);
	if (model_number < 0)
	{
		popup_an_error("Invalid model number: %s", model);
		model_number = 0;
	}

	if (!model_number)
	{
#if defined(RESTRICT_3279)
		model_number = 3;
#else
		model_number = 4;
#endif
	}

	if(appres.mono)
		appres.m3279 = False;

	if(!appres.extended)
		appres.oversize = CN;

#if defined(RESTRICT_3279)
	if (appres.m3279 && model_number == 4)
		model_number = 3;
#endif

	Trace("Model_number: %d",model_number);

	if (!appres.extended || appres.oversize == CN || sscanf(appres.oversize, "%dx%d%c", &ovc, &ovr, &junk) != 2)
	{
		ovc = 0;
		ovr = 0;
	}
	ctlr_set_rows_cols(hSession, model_number, ovc, ovr);

	if (appres.termname != CN)
		hSession->termtype = appres.termname;
	else
		hSession->termtype = hSession->full_model_name;

	Trace("Termtype: %s",hSession->termtype);

	if (appres.apl_mode)
		appres.charset = Apl;

}
Beispiel #12
0
/* Finish printing to a GDI printer. */
gdi_status_t
gdi_print_finish(FILE *f, const char *caption)
{
    size_t nr;
    struct ea *ea_tmp;
    gdi_header_t h;
    const char *fail = "";

    /* Save the caption. */
    if (caption != NULL) {
	Replace(pstate.caption, NewString(caption));
    } else {
	Replace(pstate.caption, NULL);
    }

    /* Allocate the buffer. */
    ea_tmp = Malloc((((maxROWS * maxCOLS) + 1) * sizeof(struct ea)));

    /* Set up the fake fa in location -1. */
    memset(&ea_tmp[0], '\0', sizeof(struct ea));
    ea_tmp[0].fa = FA_PRINTABLE | FA_MODIFY;

    /* Rewind the file. */
    rewind(f);

    /* Read it back. */
    while ((nr = fread(&h, sizeof(gdi_header_t), 1, f)) == 1) {
	/* Check the signature. */
	if (h.signature != GDI_SIGNATURE) {
	    popup_an_error("Corrupt temporary file (signature)");
	    goto abort;
	}

	/* Check the screen dimensions. */
	if (h.rows > maxROWS || h.cols > maxCOLS) {
	    popup_an_error("Corrupt temporary file (screen size)");
	    goto abort;
	}

	/* Read the screen image in. */
	if (fread(ea_tmp + 1, sizeof(struct ea), h.rows * h.cols, f) !=
		    h.rows * h.cols) {
	    popup_an_error("Truncated temporary file");
	    goto abort;
	}

	/* Process it. */
	if (gdi_screenful(ea_tmp + 1, h.rows, h.cols, &fail) < 0) {
		popup_an_error("Printing error: %s", fail);
		goto abort;
	}
    }
    if (gdi_done(&fail) < 0) {
	popup_an_error("Final printing error: %s", fail);
	goto abort;
    }
    Free(ea_tmp);

    return GDI_STATUS_SUCCESS;

abort:
    Free(ea_tmp);
    gdi_abort();
    return GDI_STATUS_ERROR;
}
Beispiel #13
0
/* Callback for "OK" button on trace popup */
static void
tracefile_callback(Widget w, XtPointer client_data, XtPointer call_data _is_unused)
{
	char *tfn = CN;
	int devfd = -1;
#if defined(X3270_DISPLAY) /*[*/
	int pipefd[2];
	Boolean just_piped = False;
#endif /*]*/
	char *buf;

#if defined(X3270_DISPLAY) /*[*/
	if (w)
		tfn = XawDialogGetValueString((Widget)client_data);
	else
#endif /*]*/
		tfn = (char *)client_data;
	tfn = do_subst(tfn, DS_VARS | DS_TILDE | DS_UNIQUE);
	if (strchr(tfn, '\'') ||
	    ((int)strlen(tfn) > 0 && tfn[strlen(tfn)-1] == '\\')) {
		popup_an_error("Illegal file name: %s", tfn);
		Free(tfn);
		goto done;
	}

	tracef_max = 0;

	if (!strcmp(tfn, "stdout")) {
		tracef = stdout;
	} else {
#if defined(X3270_DISPLAY) /*[*/
		FILE *pipefile = NULL;

		if (!strcmp(tfn, "none") || !tfn[0]) {
			just_piped = True;
			if (!appres.trace_monitor) {
				popup_an_error("Must specify a trace file "
				    "name");
				free(tfn);
				goto done;
			}
		}

		if (appres.trace_monitor) {
			if (pipe(pipefd) < 0) {
				popup_an_errno(errno, "pipe() failed");
				Free(tfn);
				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(tfn);
				goto done;
			}
			(void) SETLINEBUF(pipefile);
			(void) fcntl(pipefd[1], F_SETFD, 1);
		}

		if (just_piped) {
			tracef = pipefile;
		} else
#endif /*]*/
		{
		    	Boolean append = False;

#if defined(X3270_DISPLAY) /*[*/
			tracef_pipe = pipefile;
#endif /*]*/
			/* Get the trace file maximum. */
			get_tracef_max();

			/* Open and configure the file. */
			if ((devfd = get_devfd(tfn)) >= 0)
				tracef = fdopen(dup(devfd), "a");
			else if (!strncmp(tfn, ">>", 2)) {
			    	append = True;
				tracef = fopen(tfn + 2, "a");
			} else
				tracef = fopen(tfn, "w");
			if (tracef == (FILE *)NULL) {
				popup_an_errno(errno, "%s", tfn);
#if defined(X3270_DISPLAY) /*[*/
				fclose(tracef_pipe);
				(void) close(pipefd[0]);
				(void) close(pipefd[1]);
#endif /*]*/
				Free(tfn);
				goto done;
			}
			tracef_size = ftello(tracef);
			Replace(tracefile_name,
				NewString(append? tfn + 2: tfn));
			(void) SETLINEBUF(tracef);
#if !defined(_WIN32) /*[*/
			(void) fcntl(fileno(tracef), F_SETFD, 1);
#endif /*]*/
		}
	}

#if defined(X3270_DISPLAY) /*[*/
	/* Start the monitor window */
	if (tracef != stdout && appres.trace_monitor) {
		switch (tracewindow_pid = fork_child()) {
		    case 0:	/* child process */
			{
				char cmd[64];

				(void) snprintf(cmd, sizeof(cmd), "cat <&%d",
					pipefd[0]);
				(void) execlp("xterm", "xterm",
				    "-title", just_piped? "trace": tfn,
				    "-sb", "-e", "/bin/sh", "-c",
				    cmd, CN);
			}
			(void) perror("exec(xterm) failed");
			_exit(1);
		    default:	/* parent */
			(void) close(pipefd[0]);
			++children;
			break;
		    case -1:	/* error */
			popup_an_errno(errno, "fork() failed");
			break;
		}
	}
#endif /*]*/

#if defined(_WIN32) && defined(C3270) /*[*/
	/* Start the monitor window. */
	if (tracef != stdout && appres.trace_monitor && is_installed) {
		STARTUPINFO startupinfo;
		PROCESS_INFORMATION process_information;
		char *path;
		char *args;

	    	(void) memset(&startupinfo, '\0', sizeof(STARTUPINFO));
		startupinfo.cb = sizeof(STARTUPINFO);
		startupinfo.lpTitle = tfn;
		(void) memset(&process_information, '\0',
			      sizeof(PROCESS_INFORMATION));
		path = xs_buffer("%scatf.exe", instdir);
		args = xs_buffer("\"%scatf.exe\" \"%s\"", instdir, tfn);
		if (CreateProcess(
		    path,
		    args,
		    NULL,
		    NULL,
		    FALSE,
		    CREATE_NEW_CONSOLE,
		    NULL,
		    NULL,
		    &startupinfo,
		    &process_information) == 0) {
		    	popup_an_error("CreateProcess(%s) failed: %s",
				path, win32_strerror(GetLastError()));
			Free(path);
			Free(args);
		} else {
			Free(path);
		    	Free(args);
			tracewindow_handle = process_information.hProcess;
			CloseHandle(process_information.hThread);
		}
	}
#endif /*]*/

	Free(tfn);

	/* We're really tracing, turn the flag on. */
	appres.toggle[trace_reason].value = True;
	appres.toggle[trace_reason].changed = True;
	menubar_retoggle(&appres.toggle[trace_reason], trace_reason);

	/* Display current status. */
	buf = create_tracefile_header("started");
	do_ts = False;
	wtrace("%s", buf);
	Free(buf);

done:
#if defined(X3270_DISPLAY) /*[*/
	if (w)
		XtPopdown(trace_shell);
#endif /*]*/
	return;
}
Beispiel #14
0
/* 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;
}
Beispiel #15
0
/*
 * 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;
}
Beispiel #16
0
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
	int i, j;
	int argc_out = 0;
	const char **argv_out =
	    (const char **) Malloc((*argcp + 1) * sizeof(char *));

	/* Parse the command-line options. */
	argv_out[argc_out++] = argv[0];

	for (i = 1; i < *argcp; i++) {
		for (j = 0; opts[j].name != CN; j++) {
			if (!strcmp(argv[i], opts[j].name))
				break;
		}
		if (opts[j].name == CN) {
			argv_out[argc_out++] = argv[i];
			continue;
		}

		switch (opts[j].type) {
		    case OPT_BOOLEAN:
			*(Boolean *)opts[j].aoff = opts[j].flag;
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     opts[j].flag? "True": "False");
			break;
		    case OPT_STRING:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(const char **)opts[j].aoff = argv[++i];
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].res_name),
					     NewString(argv[i]));
			break;
		    case OPT_XRM:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			parse_xrm(argv[++i], "-xrm");
			break;
		    case OPT_SKIP2:
			argv_out[argc_out++] = argv[i++];
			if (i < *argcp)
				argv_out[argc_out++] = argv[i];
			break;
		    case OPT_NOP:
			break;
		    case OPT_INT:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(int *)opts[j].aoff = atoi(argv[++i]);
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     NewString(argv[i]));
			break;
		    case OPT_V:
			dump_version();
			break;
		    case OPT_DONE:
			while (i < *argcp)
				argv_out[argc_out++] = argv[i++];
			break;
		}
	}
	*argcp = argc_out;
	argv_out[argc_out] = CN;
	(void) memcpy((char *)argv, (char *)argv_out,
	    (argc_out + 1) * sizeof(char *));
	Free((char *)argv_out);
}
Beispiel #17
0
/*
 * 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 defined(C3270) && !defined(_WIN32) /*[*/
	if (appres.mono)
		appres.m3279 = False;
#endif /*]*/

	if (!appres.extended) {
		appres.oversize = CN;
	}

	ovc = 0;
	ovr = 0;
	if (appres.extended && appres.oversize != CN) {
#if defined(C3270) /*[*/
	    	if (!strcasecmp(appres.oversize, "auto")) {
		    	ovc = -1;
			ovr = -1;
		} else
#endif /*]*/
		{
		    	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;
			}
		}
	}
	set_rows_cols(model_number, ovc, ovr);
	if (appres.termname != CN) {
		termtype = appres.termname;
	} else {
		termtype = full_model_name;
	}
}
Beispiel #18
0
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
    int i;
    unsigned j;
    int argc_out = 0;
    const char **argv_out =
	(const char **) Malloc((*argcp + 1) * sizeof(char *));
    optlist_t *o;
    opt_t *opts;

    /* Parse the command-line options. */
    argv_out[argc_out++] = argv[0];

    for (i = 1; i < *argcp; i++) {
	bool found = false;

	for (o = optlist; o != NULL && !found; o = o->next) {
	    opts = o->opts;
	    for (j = 0; j < o->count; j++) {
		if (!strcmp(argv[i], opts[j].name)) {
		    found = true;
		    break;
		}
	    }
	}
	if (!found) {
	    argv_out[argc_out++] = argv[i];
	    continue;
	}

	switch (opts[j].type) {
	case OPT_BOOLEAN:
	    *(bool *)opts[j].aoff = opts[j].flag;
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name),
			opts[j].flag? "true": "false");
	    }
	    break;
	case OPT_STRING:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(const char **)opts[j].aoff = argv[++i];
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].res_name), NewString(argv[i]));
	    }
	    break;
	case OPT_XRM:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    parse_xrm(argv[++i], "-xrm");
	    break;
	case OPT_SKIP2:
	    argv_out[argc_out++] = argv[i++];
	    if (i < *argcp) {
		argv_out[argc_out++] = argv[i];
	    }
	    break;
	case OPT_NOP:
	    break;
	case OPT_INT:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(int *)opts[j].aoff = atoi(argv[++i]);
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name), NewString(argv[i]));
	    }
	    break;
	case OPT_V:
	    dump_version();
	    break;
	case OPT_DONE:
	    while (i < *argcp) {
		argv_out[argc_out++] = argv[i++];
	    }
	    break;
	}
    }
    *argcp = argc_out;
    argv_out[argc_out] = NULL;
    (void) memcpy((char *)argv, (char *)argv_out,
    (argc_out + 1) * sizeof(char *));
    Free((char *)argv_out);
}
Beispiel #19
0
/*
 * Start a file transfer, based on the contents of an ft_state structure.
 *
 * This function will fail if the file exists and the overwrite flag is not
 * set.
 *
 * Returns the local file pointer, or NULL if the transfer could not start.
 * If an error is detected, it will call popup_an_error() with an appropriate
 * message.
 */
FILE *
ft_go(ft_conf_t *p)
{
    FILE *f;
    varbuf_t r;
    unsigned flen;

    /* Adjust the DFT buffer size. */
    p->dft_buffersize = set_dft_buffersize(p->dft_buffersize);

    /* See if the local file can be overwritten. */
    if (p->receive_flag && !p->append_flag && !p->allow_overwrite) {
	f = fopen(p->local_filename, p->ascii_flag? "r": "rb");
	if (f != NULL) {
	    (void) fclose(f);
	    popup_an_error("Transfer: File exists");
	    return NULL;
	}
    }

    /* Open the local file. */
    f = fopen(p->local_filename, ft_local_fflag(p));
    if (f == NULL) {
	popup_an_errno(errno, "Local file '%s'", p->local_filename);
	return NULL;
    }

    /* Build the ind$file command */
    vb_init(&r);
    vb_appendf(&r, "IND\\e005BFILE %s %s %s",
	    p->receive_flag? "GET": "PUT",
	    p->host_filename,
	    (p->host_type != HT_TSO)? "(": "");
    if (p->ascii_flag) {
	vb_appends(&r, "ASCII");
    } else if (p->host_type == HT_CICS) {
	vb_appends(&r, "BINARY");
    }
    if (p->ascii_flag && p->cr_flag) {
	vb_appends(&r, " CRLF");
    } else if (p->host_type == HT_CICS) {
	vb_appends(&r, " NOCRLF");
    }
    if (p->append_flag && !p->receive_flag) {
	vb_appends(&r, " APPEND");
    }
    if (!p->receive_flag) {
	if (p->host_type == HT_TSO) {
	    if (p->recfm != DEFAULT_RECFM) {
		/* RECFM Entered, process */
		vb_appends(&r, " RECFM(");
		switch (p->recfm) {
		case RECFM_FIXED:
		    vb_appends(&r, "F");
		    break;
		case RECFM_VARIABLE:
		    vb_appends(&r, "V");
		    break;
		case RECFM_UNDEFINED:
		    vb_appends(&r, "U");
		    break;
		default:
		    break;
		};
		vb_appends(&r, ")");
		if (p->lrecl) {
		    vb_appendf(&r, " LRECL(%d)", p->lrecl);
		}
		if (p->blksize) {
		    vb_appendf(&r, " BLKSIZE(%d)", p->blksize);
		}
	    }
	    if (p->units != DEFAULT_UNITS) {
		/* Space Entered, processs it */
		vb_appendf(&r, " SPACE(%d", p->primary_space);
		if (p->secondary_space) {
		    vb_appendf(&r, ",%d", p->secondary_space);
		}
		vb_appends(&r, ")");
		switch (p->units) {
		case TRACKS:
		    vb_appends(&r, " TRACKS");
		    break;
		case CYLINDERS:
		    vb_appends(&r, " CYLINDERS");
		    break;
		case AVBLOCK:
		    vb_appendf(&r, " AVBLOCK(%d)", p->avblock);
		    break;
		default:
		    break;
		}
	    }
	} else if (p->host_type == HT_VM) {
	    if (p->recfm != DEFAULT_RECFM) {
		vb_appends(&r, " RECFM ");
		switch (p->recfm) {
		case RECFM_FIXED:
		    vb_appends(&r, "F");
		    break;
		case RECFM_VARIABLE:
		    vb_appends(&r, "V");
		    break;
		default:
		    break;
		};

		if (p->lrecl) {
		    vb_appendf(&r, " LRECL %d", p->lrecl);
		}
	    }
	}
    }
    vb_appends(&r, "\\n");

    /* Erase the line and enter the command. */
    flen = kybd_prime();
    if (!flen || flen < vb_len(&r) - 1) {
	vb_free(&r);
	if (f != NULL) {
	    fclose(f);
	    if (p->receive_flag && !p->append_flag) {
		unlink(p->local_filename);
	    }
	}
	popup_an_error("%s", get_message("ftUnable"));
	return NULL;
    }
    (void) emulate_input(vb_buf(&r), vb_len(&r), false);
    vb_free(&r);

    /* Now proceed with this context. */
    ftc = p;

    /* Finish common initialization. */
    fts.last_cr = false;
    fts.is_cut = false;
    fts.last_dbcs = false;
    fts.dbcs_state = FT_DBCS_NONE;

    ft_state = FT_AWAIT_ACK;
    idle_ft_start();

    return f;
}
Beispiel #20
0
/*
 * Parse the keywords for the Transfer() action.
 *
 * Returns a pointer to the filled-out ft_state structure, or NULL for
 * errors.
 */
static ft_conf_t *
parse_ft_keywords(unsigned argc, const char **argv)
{
    ft_conf_t *p = &transfer_ft_conf;
    int i, k;
    unsigned j;
    char *ptr;

    /* Unlike the GUIs, always set everything to defaults. */
    ft_init_conf(p);
    p->is_action = true;
    for (i = 0; i < N_PARMS; i++) {
	Replace(tp[i].value, NULL);
    }

    /* The special keyword 'Defaults' means 'just use the defaults'. */
    if (argc == 1 && !strcasecmp(argv[0], "Defaults")) {
	argc--;
	argv++;
    }

    /* See what they specified. */
    for (j = 0; j < argc; j++) {
	for (i = 0; i < N_PARMS; i++) {
	    char *eq;
	    size_t kwlen;

	    eq = strchr(argv[j], '=');
	    if (eq == NULL || eq == argv[j] || !*(eq + 1)) {
		popup_an_error("Transfer: Invalid option syntax: '%s'",
			argv[j]);
		return NULL;
	    }
	    kwlen = eq - argv[j];
	    if (!strncasecmp(argv[j], tp[i].name, kwlen)
		    && !tp[i].name[kwlen]) {
		if (tp[i].keyword[0]) {
		    for (k = 0; tp[i].keyword[k] != NULL && k < 4; k++) {
			if (!strncasecmp(eq + 1, tp[i].keyword[k],
				    strlen(eq + 1))) {
			    break;
			}
		    }
		    if (k >= 4 || tp[i].keyword[k] == NULL) {
			popup_an_error("Transfer: Invalid option value: '%s'",
				eq + 1);
			return NULL;
		    }
		} else switch (i) {
		    case PARM_LRECL:
		    case PARM_BLKSIZE:
		    case PARM_PRIMARY_SPACE:
		    case PARM_SECONDARY_SPACE:
		    case PARM_BUFFER_SIZE:
#if defined(_WIN32) /*[*/
		    case PARM_WINDOWS_CODEPAGE:
#endif /*]*/
			(void) strtol(eq + 1, &ptr, 10);
			if (ptr == eq + 1 || *ptr) {
			    popup_an_error("Transfer: Invalid option value: "
				    "'%s'", eq + 1);
			    return NULL;
			}
			break;
		    default:
			break;
		}
		tp[i].value = NewString(eq + 1);
		break;
	    }
	}
	if (i >= N_PARMS) {
	    popup_an_error("Transfer: Unknown option: '%s'", argv[j]);
	    return NULL;
	}
    }

    /* Transfer from keywords to the ft_state. */
    if (tp[PARM_DIRECTION].value) {
	p->receive_flag = !strcasecmp(tp[PARM_DIRECTION].value, "receive");
    }
    if (tp[PARM_HOST_FILE].value) {
	p->host_filename = NewString(tp[PARM_HOST_FILE].value);
    }
    if (tp[PARM_LOCAL_FILE].value) {
	p->local_filename = NewString(tp[PARM_LOCAL_FILE].value);
    }
    if (tp[PARM_HOST].value) {
	(void) ft_encode_host_type(tp[PARM_HOST].value, &p->host_type);
    }
    if (tp[PARM_MODE].value) {
	p->ascii_flag = !strcasecmp(tp[PARM_MODE].value, "ascii");
    }
    if (tp[PARM_CR].value) {
	if (!strcasecmp(tp[PARM_CR].value, "auto")) {
	    p->cr_flag = p->ascii_flag;
	} else {
	    if (!p->ascii_flag) {
		popup_an_error("Transfer: Invalid 'Cr' option for ASCII mode");
		return NULL;
	    }
	    p->cr_flag = !strcasecmp(tp[PARM_CR].value, "remove") ||
			 !strcasecmp(tp[PARM_CR].value, "add");
	}
    }
    if (p->ascii_flag && tp[PARM_REMAP].value) {
	p->remap_flag = !strcasecmp(tp[PARM_REMAP].value, "yes");
    }
    if (tp[PARM_EXIST].value) {
	p->append_flag = !strcasecmp(tp[PARM_EXIST].value, "append");
	p->allow_overwrite = !strcasecmp(tp[PARM_EXIST].value, "replace");
    }
    if (tp[PARM_RECFM].value) {
	(void) ft_encode_recfm(tp[PARM_RECFM].value, &p->recfm);
    }
    if (tp[PARM_LRECL].value) {
	p->lrecl = atoi(tp[PARM_LRECL].value);
    }
    if (tp[PARM_BLKSIZE].value) {
	p->blksize = atoi(tp[PARM_BLKSIZE].value);
    }
    if (tp[PARM_ALLOCATION].value) {
	(void) ft_encode_units(tp[PARM_ALLOCATION].value, &p->units);
    }
    if (tp[PARM_PRIMARY_SPACE].value) {
	p->primary_space = atoi(tp[PARM_PRIMARY_SPACE].value);
    }
    if (tp[PARM_SECONDARY_SPACE].value) {
	p->secondary_space = atoi(tp[PARM_SECONDARY_SPACE].value);
    }
    if (tp[PARM_BUFFER_SIZE].value != NULL) {
	p->dft_buffersize = atoi(tp[PARM_BUFFER_SIZE].value);
    }
    if (tp[PARM_AVBLOCK].value) {
	p->avblock = atoi(tp[PARM_AVBLOCK].value);
    }
#if defined(_WIN32) /*[*/
    if (tp[PARM_WINDOWS_CODEPAGE].value != NULL) {
	p->windows_codepage = atoi(tp[PARM_WINDOWS_CODEPAGE].value);
    }
#endif /*]*/

    /* Check for required values. */
    if (!p->host_filename) {
	popup_an_error("Transfer: Missing 'HostFile' option");
	return NULL;
    }
    if (!p->local_filename) {
	popup_an_error("Transfer: Missing 'LocalFile' option");
	return NULL;
    }
    if (p->host_type == HT_TSO &&
	    !p->receive_flag &&
	    p->units != DEFAULT_UNITS &&
	    p->primary_space <= 0) {
	popup_an_error("Transfer: Missing or invalid 'PrimarySpace'");
	return NULL;
    }
    if (p->host_type == HT_TSO &&
	    !p->receive_flag &&
	    p->units == AVBLOCK &&
	    p->avblock <= 0) {
	popup_an_error("Transfer: Missing or invalid 'Avblock'");
	return NULL;
    }

    /* Check for contradictory values. */
    if (tp[PARM_CR].value && !p->ascii_flag) {
	popup_an_error("Transfer: 'Cr' is only for ASCII transfers");
	return NULL;
    }
    if (tp[PARM_REMAP].value && !p->ascii_flag) {
	popup_an_error("Transfer: 'Remap' is only for ASCII transfers");
	return NULL;
    }
    if (tp[PARM_RECFM].value && p->receive_flag) {
	popup_an_error("Transfer: 'Recfm' is only for sending files");
	return NULL;
    }
    if (tp[PARM_RECFM].value && p->host_type != HT_TSO &&
	    p->host_type != HT_VM) {
	popup_an_error("Transfer: 'Recfm' is only for TSO and VM hosts");
	return NULL;
    }
    if (tp[PARM_LRECL].value && p->receive_flag) {
	popup_an_error("Transfer: 'Lrecl' is only for sending files");
	return NULL;
    }
    if (tp[PARM_BLKSIZE].value && p->receive_flag) {
	popup_an_error("Transfer: 'Blksize' is only for sending files");
	return NULL;
    }
    if (tp[PARM_BLKSIZE].value && p->host_type != HT_TSO) {
	popup_an_error("Transfer: 'Blksize' is only for TSO hosts");
	return NULL;
    }
    if (tp[PARM_ALLOCATION].value && p->receive_flag) {
	popup_an_error("Transfer: 'Allocation' is only for sending files");
	return NULL;
    }
    if (tp[PARM_ALLOCATION].value && p->host_type != HT_TSO) {
	popup_an_error("Transfer: 'Allocation' is only for TSO hosts");
	return NULL;
    }
    if (tp[PARM_PRIMARY_SPACE].value && p->receive_flag) {
	popup_an_error("Transfer: 'PrimarySpace' is only for sending files");
	return NULL;
    }
    if (tp[PARM_PRIMARY_SPACE].value && p->host_type != HT_TSO) {
	popup_an_error("Transfer: 'PrimarySpace' is only for TSO hosts");
	return NULL;
    }
    if (tp[PARM_SECONDARY_SPACE].value && p->receive_flag) {
	popup_an_error("Transfer: 'SecondarySpace' is only for sending files");
	return NULL;
    }
    if (tp[PARM_SECONDARY_SPACE].value && p->host_type != HT_TSO) {
	popup_an_error("Transfer: 'SecondarySpace' is only for TSO hosts");
	return NULL;
    }
    if (tp[PARM_AVBLOCK].value && p->receive_flag) {
	popup_an_error("Transfer: 'Avblock' is only for sending files");
	return NULL;
    }
    if (tp[PARM_AVBLOCK].value && p->host_type != HT_TSO) {
	popup_an_error("Transfer: 'Avblock' is only for TSO hosts");
	return NULL;
    }
#if defined(_WIN32) /*[*/
    if (tp[PARM_WINDOWS_CODEPAGE].value && !p->ascii_flag) {
	popup_an_error("Transfer: 'WindowsCodePage' is only for ASCII "
		"transfers");
	return NULL;
    }
#endif /*]*/

    /* All set. */
    return p;
}