diff options
Diffstat (limited to 'gnu/libexec/uucp/cu/cu.c')
| -rw-r--r-- | gnu/libexec/uucp/cu/cu.c | 157 |
1 files changed, 121 insertions, 36 deletions
diff --git a/gnu/libexec/uucp/cu/cu.c b/gnu/libexec/uucp/cu/cu.c index 5e34601de3b9..3939f6a02ece 100644 --- a/gnu/libexec/uucp/cu/cu.c +++ b/gnu/libexec/uucp/cu/cu.c @@ -1,7 +1,7 @@ /* cu.c Call up a remote system. - Copyright (C) 1992 Ian Lance Taylor + Copyright (C) 1992, 1993, 1994 Ian Lance Taylor This file is part of the Taylor UUCP package. @@ -20,13 +20,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author of the program may be contacted at ian@airs.com or - c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254. + c/o Cygnus Support, Building 200, 1 Kendall Square, Cambridge, MA 02139. */ #include "uucp.h" #if USE_RCS_ID -const char cu_rcsid[] = "$Id: cu.c,v 1.1 1993/08/05 18:23:29 conklin Exp $"; +const char cu_rcsid[] = "$Id: cu.c,v 1.2 1994/05/07 18:09:54 ache Exp $"; #endif #include "cu.h" @@ -66,7 +66,7 @@ boolean fCuvar_binary = FALSE; /* A prefix string to use before sending a binary character from a file; this is only used if fCuvar_binary is TRUE. The default is - ^Z. */ + ^V. */ const char *zCuvar_binary_prefix = "\026"; /* Whether to check for echoes of characters sent when sending a file. @@ -126,9 +126,6 @@ static const struct uuconf_cmdtab asCuvars[] = { NULL, 0, NULL, NULL} }; -/* The program name. */ -char abProgram[] = "cu"; - /* The string printed at the initial connect. */ #if ANSI_C #define ZCONNMSG "\aConnected." @@ -175,6 +172,9 @@ static boolean fCulocalecho; /* Whether we need to call fsysdep_cu_finish. */ static boolean fCustarted; +/* Whether ZCONNMSG has been printed yet. */ +static boolean fCuconnprinted = FALSE; + /* A structure used to pass information to icuport_lock. */ struct sconninfo { @@ -187,6 +187,7 @@ struct sconninfo /* Local functions. */ static void ucuusage P((void)); +static void ucuhelp P((void)); static void ucuabort P((void)); static void uculog_start P((void)); static void uculog_end P((void)); @@ -209,7 +210,24 @@ static boolean fcusend_buf P((struct sconnection *qconn, const char *zbuf, do { if (! fsysdep_terminal_puts (zline)) ucuabort (); } while (0) /* Long getopt options. */ -static const struct option asCulongopts[] = { { NULL, 0, NULL, 0 } }; +static const struct option asCulongopts[] = +{ + { "phone", required_argument, NULL, 'c' }, + { "parity", required_argument, NULL, 2 }, + { "halfduplex", no_argument, NULL, 'h' }, + { "prompt", no_argument, NULL, 'n' }, + { "line", required_argument, NULL, 'l' }, + { "port", required_argument, NULL, 'p' }, + { "speed", required_argument, NULL, 's' }, + { "baud", required_argument, NULL, 's' }, + { "mapcr", no_argument, NULL, 't' }, + { "system", required_argument, NULL, 'z' }, + { "config", required_argument, NULL, 'I' }, + { "debug", required_argument, NULL, 'x' }, + { "version", no_argument, NULL, 'v' }, + { "help", no_argument, NULL, 1 }, + { NULL, 0, NULL, 0 } +}; int main (argc, argv) @@ -252,6 +270,8 @@ main (argc, argv) struct uuconf_dialer *qdialer; char bcmd; + zProgram = argv[0]; + /* We want to accept -# as a speed. It's easiest to look through the arguments, replace -# with -s#, and let getopt handle it. */ for (i = 1; i < argc; i++) @@ -271,7 +291,7 @@ main (argc, argv) } } - while ((iopt = getopt_long (argc, argv, "a:c:dehnI:l:op:s:tx:z:", + while ((iopt = getopt_long (argc, argv, "a:c:dehnI:l:op:s:tvx:z:", asCulongopts, (int *) NULL)) != EOF) { switch (iopt) @@ -347,13 +367,47 @@ main (argc, argv) #endif break; + case 'v': + /* Print version and exit. */ + fprintf + (stderr, + "%s: Taylor UUCP %s, copyright (C) 1991, 1992, 1993, 1994 Ian Lance Taylor\n", + zProgram, VERSION); + exit (EXIT_SUCCESS); + /*NOTREACHED*/ + + case 2: + /* --parity. */ + if (strncmp (optarg, "even", strlen (optarg)) == 0) + feven = TRUE; + else if (strncmp (optarg, "odd", strlen (optarg)) == 0) + fodd = TRUE; + else if (strncmp (optarg, "none", strlen (optarg)) == 0) + { + feven = TRUE; + fodd = TRUE; + } + else + { + fprintf (stderr, "%s: --parity requires even, odd or none\n", + zProgram); + ucuusage (); + } + break; + + case 1: + /* --help. */ + ucuhelp (); + exit (EXIT_SUCCESS); + /*NOTREACHED*/ + case 0: /* Long option found and flag set. */ break; default: ucuusage (); - break; + /*NOTREACHED*/ } } @@ -366,7 +420,10 @@ main (argc, argv) if (optind != argc - 1 || zsystem != NULL || zphone != NULL) - ucuusage (); + { + fprintf (stderr, "%s: too many arguments\n", zProgram); + ucuusage (); + } if (strcmp (argv[optind], "dir") != 0) { if (isdigit (BUCHAR (argv[optind][0]))) @@ -382,7 +439,11 @@ main (argc, argv) && zport == NULL && zline == NULL && ibaud == 0L) - ucuusage (); + { + fprintf (stderr, "%s: must specify system, line, port or speed\n", + zProgram); + ucuusage (); + } if (fprompt) { @@ -395,7 +456,7 @@ main (argc, argv) if (getline (&zphone, &cphone, stdin) <= 0 || *zphone == '\0') { - fprintf (stderr, "%s: No phone number entered\n", abProgram); + fprintf (stderr, "%s: no phone number entered\n", zProgram); exit (EXIT_FAILURE); } } @@ -523,16 +584,20 @@ main (argc, argv) sport.uuconf_u.uuconf_sdirect.uuconf_zdevice = NULL; sport.uuconf_u.uuconf_sdirect.uuconf_ibaud = ibaud; - if (! fsysdep_port_access (&sport)) - ulog (LOG_FATAL, "%s: Permission denied", zline); - - if (! fconn_init (&sport, &sconn)) + if (! fconn_init (&sport, &sconn, UUCONF_PORTTYPE_UNKNOWN)) ucuabort (); if (! fconn_lock (&sconn, FALSE)) ulog (LOG_FATAL, "%s: Line in use", zline); qCuconn = &sconn; + + /* Check user access after locking the port, because on + some systems shared lines affect the ownership and + permissions. In such a case ``Line in use'' is more + clear than ``Permission denied.'' */ + if (! fsysdep_port_access (&sport)) + ulog (LOG_FATAL, "%s: Permission denied", zline); } ihighbaud = 0L; } @@ -544,7 +609,8 @@ main (argc, argv) continue; if (qsys->uuconf_qport != NULL) { - if (fconn_init (qsys->uuconf_qport, &sconn)) + if (fconn_init (qsys->uuconf_qport, &sconn, + UUCONF_PORTTYPE_UNKNOWN)) { if (fconn_lock (&sconn, FALSE)) { @@ -648,7 +714,8 @@ main (argc, argv) || qsys == NULL) ucuabort (); - if (qsys->uuconf_qalternate == NULL) + qsys = qsys->uuconf_qalternate; + if (qsys == NULL) ulog (LOG_FATAL, "%s: No remaining alternates", zsystem); fCuclose_conn = FALSE; @@ -693,6 +760,7 @@ main (argc, argv) only comes out when a special command is received from the terminal. */ printf ("%s\n", ZCONNMSG); + fCuconnprinted = TRUE; if (! fsysdep_terminal_raw (fCulocalecho)) ucuabort (); @@ -719,7 +787,8 @@ main (argc, argv) (void) fconn_unlock (&sconn); uconn_free (&sconn); - printf ("\n%s\n", ZDISMSG); + if (fCuconnprinted) + printf ("\n%s\n", ZDISMSG); ulog_close (); @@ -734,41 +803,56 @@ main (argc, argv) static void ucuusage () { + fprintf (stderr, "Usage: %s [options] [system or phone-number]\n", + zProgram); + fprintf (stderr, "Use %s --help for help\n", zProgram); + exit (EXIT_FAILURE); +} + +/* Print a help message. */ + +static void +ucuhelp () +{ fprintf (stderr, - "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n", + "Taylor UUCP %s, copyright (C) 1991, 1992, 1993, 1994 Ian Lance Taylor\n", VERSION); fprintf (stderr, - "Usage: cu [options] [system or phone-number]\n"); + "Usage: %s [options] [system or phone-number]\n", zProgram); fprintf (stderr, - " -a port, -p port: Use named port\n"); + " -a,-p,--port port: Use named port\n"); fprintf (stderr, - " -l line: Use named device (e.g. tty0)\n"); + " -l,--line line: Use named device (e.g. tty0)\n"); fprintf (stderr, - " -s speed, -#: Use given speed\n"); + " -s,--speed,--baud speed, -#: Use given speed\n"); fprintf (stderr, - " -c phone: Phone number to call\n"); + " -c,--phone phone: Phone number to call\n"); fprintf (stderr, - " -z system: System to call\n"); + " -z,--system system: System to call\n"); fprintf (stderr, " -e: Set even parity\n"); fprintf (stderr, " -o: Set odd parity\n"); fprintf (stderr, - " -h: Echo locally\n"); + " --parity={odd,even}: Set parity\n"); + fprintf (stderr, + " -h,--halfduplex: Echo locally\n"); fprintf (stderr, - " -t: Map carriage return to carriage return/linefeed\n"); + " -t,--mapcr: Map carriage return to carriage return/linefeed\n"); fprintf (stderr, - " -n: Prompt for phone number\n"); + " -n,--prompt: Prompt for phone number\n"); fprintf (stderr, " -d: Set maximum debugging level\n"); fprintf (stderr, - " -x debug: Set debugging type\n"); + " -x,--debug debug: Set debugging type\n"); #if HAVE_TAYLOR_CONFIG fprintf (stderr, - " -I file: Set configuration file to use\n"); + " -I,--config file: Set configuration file to use\n"); #endif /* HAVE_TAYLOR_CONFIG */ - - exit (EXIT_FAILURE); + fprintf (stderr, + " -v,--version: Print version and exit\n"); + fprintf (stderr, + " --help: Print help and exit\n"); } /* This function is called when a fatal error occurs. */ @@ -805,7 +889,8 @@ ucuabort () ulog_close (); - printf ("\n%s\n", ZDISMSG); + if (fCuconnprinted) + printf ("\n%s\n", ZDISMSG); usysdep_exit (FALSE); } @@ -866,7 +951,7 @@ icuport_lock (qport, pinfo) q->fmatched = TRUE; - if (! fconn_init (qport, q->qconn)) + if (! fconn_init (qport, q->qconn, UUCONF_PORTTYPE_UNKNOWN)) return UUCONF_NOT_FOUND; else if (! fconn_lock (q->qconn, FALSE)) { |
