This patch adds "config-file" style support for lp5250d. It has already
been applied to the development sources, but should also be applied to
0.16.1
The reason for this is that in the old lp5250d.c, you can segfault it
when printing begins by giving it too long of an argument for the -P
option, or -t option, etc. This was fixed with the newer "config-file"
support.
IMHO, lp5250d's options should be consistent with tn5250's anyway.
Please apply this to the 0.16.x branch... thanx
--- lp5250d.c.orig Wed Dec 6 13:39:23 2000
+++ lp5250d.c Wed Dec 20 17:29:58 2000
@@ -41,122 +41,107 @@
Tn5250PrintSession *printsess = NULL;
Tn5250Stream *stream = NULL;
-
-char remotehost[20];
-char sessionname[20];
-char transformname[20];
-char outputcommand[30];
-char *mapname = "37";
-char logname[20] = "";
+Tn5250Config *config = NULL;
int main(int argc, char *argv[])
{
-
- if (parse_options(argc, argv) < 0)
- syntax();
+ config = tn5250_config_new ();
+ if (tn5250_config_load_default (config) == -1) {
+ tn5250_config_unref(config);
+ exit (1);
+ }
+ if (tn5250_config_parse_argv (config, argc, argv) == -1) {
+ tn5250_config_unref(config);
+ syntax();
+ }
+
+ if (tn5250_config_get (config, "help"))
+ syntax();
+ else if (tn5250_config_get (config, "version")) {
+ printf ("tn5250 version %s\n", version_string);
+ exit (0);
+ }
+ else if (!tn5250_config_get (config, "host"))
+ syntax();
+
if (tn5250_daemon(0,0,0) < 0)
{
perror("tn5250_daemon");
exit(2);
- }
+ }
#ifndef NDEBUG
- if(strlen(logname) > 0) {
- tn5250_log_open(logname);
+ if(tn5250_config_get (config, "trace")) {
+ tn5250_log_open(tn5250_config_get (config, "trace"));
TN5250_LOG(("lp5250d version %s, built on %s\n", version_string,
__DATE__));
+ TN5250_LOG(("host = %s\n", tn5250_config_get (config, "host")));
}
#endif
openlog("lp5250d", LOG_PID, LOG_DAEMON);
- stream = tn5250_stream_open (remotehost);
+
+ stream = tn5250_stream_open (tn5250_config_get(config, "host"));
if(stream == NULL) {
- syslog(LOG_INFO, "Couldn't connect to %s", remotehost);
+ syslog(LOG_INFO, "Couldn't connect to %s",
+ tn5250_config_get (config,"host"));
+ exit(1);
+ }
+ if (tn5250_stream_config (stream, config) == -1) {
+ syslog(LOG_INFO, "Couldn't connect config to stream?!");
exit(1);
}
printsess = tn5250_print_session_new();
tn5250_stream_setenv(stream, "TERM", "IBM-3812-1");
- tn5250_stream_setenv(stream, "DEVNAME", sessionname);
+/* tn5250_stream_setenv(stream, "DEVNAME", sessionname); */
tn5250_stream_setenv(stream, "IBMFONT", "12");
- syslog(LOG_INFO, "DEVNAME = %s", sessionname);
- if (strlen(transformname) > 0) {
- syslog(LOG_INFO, "TRANSFORM = %s", transformname);
+ syslog(LOG_INFO, "DEVNAME = %s", tn5250_stream_getenv(stream, "DEVNAME"));
+ if (tn5250_stream_getenv(stream, "IBMMFRTYPMDL")) {
+ syslog(LOG_INFO, "TRANSFORM = %s",
+ tn5250_stream_getenv(stream, "IBMMFRTYPMDL"));
tn5250_stream_setenv(stream, "IBMTRANSFORM", "1");
- tn5250_stream_setenv(stream, "IBMMFRTYPMDL", transformname);
} else
tn5250_stream_setenv(stream, "IBMTRANSFORM", "0");
tn5250_print_session_set_fd(printsess, tn5250_stream_socket_handle(stream));
tn5250_print_session_set_stream(printsess, stream);
- tn5250_print_session_set_char_map(printsess, mapname);
- tn5250_print_session_set_output_command(printsess, outputcommand);
+ if (tn5250_config_get (config, "map")) {
+ tn5250_print_session_set_char_map(printsess,
+ tn5250_config_get (config, "map"));
+ } else {
+ tn5250_print_session_set_char_map(printsess, "37");
+ }
+ if (tn5250_config_get (config, "outputcommand"))
+ tn5250_print_session_set_output_command(printsess,
+ tn5250_config_get (config, "outputcommand"));
+ else
+ tn5250_print_session_set_output_command(printsess,
+ "scs2ascii|lpr");
+
tn5250_print_session_main_loop(printsess);
tn5250_print_session_destroy(printsess);
tn5250_stream_destroy (stream);
+ if (config!=NULL)
+ tn5250_config_unref (config);
#ifndef NDEBUG
tn5250_log_close();
#endif
return 0;
}
-static int parse_options(int argc, char *argv[])
-{
- int arg;
-
- while ((arg = getopt(argc, argv, "t:m:s:T:P:Vwy:")) != EOF) {
- switch (arg) {
-#ifndef NDEBUG
- case 't':
- strcpy(logname,optarg);
- break;
-#endif
- case 'm':
- mapname = optarg;
- break;
-
- case 'P':
- strcpy(outputcommand,optarg);
- break;
-
- case 's':
- strcpy(sessionname,optarg);
- break;
-
- case 'T':
- strcpy(transformname,optarg);
- break;
-
- case 'V':
- printf("tn5250 version %s\n\n", version_string);
- exit(0);
- break;
-
- case ':':
- return -1;
- }
- }
-
- if (optind >= argc)
- return -1;
- strcpy(remotehost,argv[optind++]);
- if (optind != argc)
- return -1;
- return 0;
-}
-
static void syntax()
{
printf("Usage: lp5250d [options] host[:port]\n"
"Options:\n"
- "\t-t name specify FULL path to log file\n"
- "\t-m map specify translation map\n"
- "\t-s name specify session name\n"
- "\t-T name specify host print transform\n"
- "\t-P cmd specify the print output command\n"
- "\t-V display version\n");
+ "\ttrace=FILE specify FULL path to log file\n"
+ "\tmap=NAME specify translation map\n"
+ "\tenv.DEVNAME=NAME specify session name\n"
+ "\tenv.IBMMFRTYPMDL=NAME specify host print transform name\n"
+ "\toutputcommand=CMD specify the print output command\n"
+ "\t+/-version display version\n");
exit (255);
}
+---
| This is the LINUX5250 Mailing List!
| To submit a new message, send your mail to [EMAIL PROTECTED]
| To subscribe to this list send email to [EMAIL PROTECTED]
| To unsubscribe from this list send email to [EMAIL PROTECTED]
| Questions should be directed to the list owner/operator: [EMAIL PROTECTED]
+---