bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the big term patch


From: Marcus Brinkmann
Subject: Re: the big term patch
Date: Fri, 8 Feb 2002 22:10:57 +0100
User-agent: Mutt/1.3.27i

On Fri, Feb 08, 2002 at 07:03:02PM +0100, Marcus Brinkmann wrote:
> here is a fix on top of the other patch

and here a patch on top of the patch on top of the patch.

The whole patch is now available at
ftp://alpha.gnu.org/gnu/hurd/contrib/marcus/term.diff

This patch adds argp parsing to term, and cleans up a bit of other cruft.  I
know I should supply individual patches for different things, but I am now
so out of sync that I won't bother.  I think it is easier to just be
selective in the final version (if you tell me some things can go in and
others not [yet], I will comply).

Thanks,
Marcus

diff -ru term.new/ChangeLog term.new2/ChangeLog
--- term.new/ChangeLog  Fri Feb  8 19:02:21 2002
+++ term.new2/ChangeLog Fri Feb  8 21:30:54 2002
@@ -1,6 +1,17 @@
 2002-02-08  Marcus Brinkmann  <marcus@gnu.org>
 
-       * term.h (struct bottomhalf): Add new member init().
+       * main.c: Include `argp.h' and `version.h'.
+       (argp_program_version): New global variable.
+       (tty_name, tty_type, tty_arg): Likewise.
+       (parse_opt): New function.
+       (term_argp): New global variable.
+       (main): Call argp_parse, use new global variables to parse the
+       options.  Remove TYPE variable.
+
+2002-02-08  Marcus Brinkmann  <marcus@gnu.org>
+
+       * term.h (struct bottomhalf): Add new member init().  Remove
+       prototype for ptyio_init.
        * main.c (main): Initialize bottom handler (rather than special
        casing this for ptyio).
        * ptyio.c (ptyio_init): Change return type to error_t and return
diff -ru term.new/devio.c term.new2/devio.c
--- term.new/devio.c    Fri Feb  8 19:26:22 2002
+++ term.new2/devio.c   Fri Feb  8 21:12:02 2002
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1995,96,98,99,2000,01 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,98,99,2000,01,02 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
diff -ru term.new/main.c term.new2/main.c
--- term.new/main.c     Fri Feb  8 19:06:05 2002
+++ term.new2/main.c    Fri Feb  8 21:59:11 2002
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -23,17 +23,27 @@
 #include <fcntl.h>
 #include <hurd/trivfs.h>
 #include <stdio.h>
+#include <argp.h>
 #include <hurd/fsys.h>
 #include <string.h>
 
+#include <version.h>
+
+const char *argp_program_version = STANDARD_HURD_VERSION (term);
+
 int trivfs_fstype = FSTYPE_TERM;
-int trivfs_fsid = 0;           /* pid?? */
+int trivfs_fsid = 0;
 int trivfs_support_read = 1;
 int trivfs_support_write = 1;
 int trivfs_support_exec = 0;
 
 int trivfs_allow_open = O_READ|O_WRITE;
 
+/* The argument line options.  */
+char *tty_name;
+enum { T_NONE = 0, T_DEVICE, T_HURDIO, T_PTYMASTER, T_PTYSLAVE } tty_type;
+char *tty_arg;
+
 int
 demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp)
 {
@@ -47,6 +57,58 @@
          || device_reply_server (inp, outp));
 }
 
+
+static error_t
+parse_opt (int opt, char *arg, struct argp_state *state)
+{
+  switch (opt)
+    {
+    default:
+      return ARGP_ERR_UNKNOWN;
+    case ARGP_KEY_INIT:
+    case ARGP_KEY_SUCCESS:
+    case ARGP_KEY_ERROR:
+      break;
+    case ARGP_KEY_ARG:
+      if (!tty_name)
+       tty_name = arg;
+      else if (!tty_type)
+       {
+         if (!strcmp (arg, "device"))
+           tty_type = T_DEVICE;
+         else if (!strcmp (arg, "hurdio"))
+           tty_type = T_HURDIO;
+         else if (!strcmp (arg, "pty-master"))
+           tty_type = T_PTYMASTER;
+         else if (!strcmp (arg, "pty-slave"))
+           tty_type = T_PTYSLAVE;
+         else
+           argp_error (state, "Invalid terminal type");
+       }
+      else if (!tty_arg)
+       tty_arg = arg;
+      else
+       argp_error (state, "Too many arguments");
+      break;
+    case ARGP_KEY_END:
+      if (!tty_name || !tty_type || !tty_arg)
+       argp_error (state, "Too few arguments");
+      break;
+    }
+  return 0;
+}
+
+static struct argp term_argp =
+  { 0, parse_opt, "NAME TYPE ARG", "A translator that emulates a terminal.\v"\
+    "Possible values for TYPE:\n"\
+    "  device      Use Mach device ARG as bottom handler.\n"\
+    "  hurdio      Use file port ARG as bottom handler.\n"\
+    "  pty-master  Master for slave at ARG.\n"\
+    "  pty-slave   Slave for master at ARG.\n"\
+    "\n"\
+    "The filename of the node that the translator is attached to should be\n"\
+    "supplied in NAME.\n" };
+
 int
 main (int argc, char **argv)
 {
@@ -54,7 +116,6 @@
   struct port_class *peerclass, *peercntlclass;
   struct trivfs_control **ourcntl, **peercntl;
   mach_port_t bootstrap, right;
-  enum {T_DEVICE, T_PTYMASTER, T_PTYSLAVE} type;
   struct stat st;
 
   term_bucket = ports_create_bucket ();
@@ -68,15 +129,11 @@
 
   init_users ();
 
-  if (argc != 4)
-    {
-      fprintf (stderr, "Usage: term ttyname type arg\n");
-      exit (1);
-    }
+  argp_parse (&term_argp, argc, argv, 0, 0, 0);
 
-  if (!strcmp (argv[2], "device"))
+  switch (tty_type)
     {
-      type = T_DEVICE;
+    case T_DEVICE:
       bottom = &devio_bottom;
       ourclass = tty_class;
       ourcntlclass = tty_cntl_class;
@@ -84,11 +141,10 @@
       peerclass = 0;
       peercntlclass = 0;
       peercntl = 0;
-      pterm_name = argv[3];
-    }
-  if (!strcmp (argv[2], "hurdio"))
-    {
-      type = T_DEVICE;
+      pterm_name = tty_arg;
+      break;
+
+    case T_HURDIO:
       bottom = &hurdio_bottom;
       ourclass = tty_class;
       ourcntlclass = tty_cntl_class;
@@ -96,11 +152,10 @@
       peerclass = 0;
       peercntlclass = 0;
       peercntl = 0;
-      pterm_name = argv[3];
-    }
-  else if (!strcmp (argv[2], "pty-master"))
-    {
-      type = T_PTYMASTER;
+      pterm_name = tty_arg;
+      break;
+
+    case T_PTYMASTER:
       bottom = &ptyio_bottom;
       ourclass = pty_class;
       ourcntlclass = pty_cntl_class;
@@ -108,10 +163,9 @@
       peerclass = tty_class;
       peercntlclass = tty_cntl_class;
       peercntl = &termctl;
-    }
-  else if (!strcmp (argv[2], "pty-slave"))
-    {
-      type = T_PTYSLAVE;
+      break;
+
+    case T_PTYSLAVE:
       bottom = &ptyio_bottom;
       ourclass = tty_class;
       ourcntlclass = tty_cntl_class;
@@ -119,11 +173,11 @@
       peerclass = pty_class;
       peercntlclass = pty_cntl_class;
       peercntl = &ptyctl;
-    }
-  else
-    {
-      fprintf (stderr, 
-              "Allowable types are device, hurdio, pty-master, and 
pty-slave.\n");
+      break;
+
+    default:
+      /* Should not happen.  */
+      fprintf (stderr, "Unknown terminal type is unknown.\n");
       exit (1);
     }
   
@@ -147,12 +201,12 @@
 
   /* For ptys, the nodename depends on which half is used.  For now just use
      the hook to store the nodename.  */
-  (*ourcntl)->hook = argv[1];
+  (*ourcntl)->hook = tty_name;
 
   /* Set peer */
   if (peerclass)
     {
-      char *peer_name = argv[3];
+      char *peer_name = tty_arg;
       file_t file = file_name_lookup (peer_name, O_CREAT|O_NOTRANS, 0666);
 
       if (file != MACH_PORT_NULL)
@@ -206,7 +260,7 @@
   
   outputq = create_queue (256, QUEUE_LOWAT, QUEUE_HIWAT);
   
-  errno = (*bottom)->init ();
+  errno = (*bottom->init) ();
   if (errno)
     {
       perror ("Initializing bottom handler");
diff -ru term.new/ptyio.c term.new2/ptyio.c
--- term.new/ptyio.c    Fri Feb  8 18:58:52 2002
+++ term.new2/ptyio.c   Fri Feb  8 21:12:18 2002
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1999, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
diff -ru term.new/term.h term.new2/term.h
--- term.new/term.h     Fri Feb  8 18:39:49 2002
+++ term.new2/term.h    Fri Feb  8 21:30:22 2002
@@ -323,9 +323,6 @@
 void write_character (int);
 void init_users (void);
 
-/* Call this before using ptyio_bottom.  */
-void ptyio_init (void);
-
 /* kludge--these are pty versions of trivfs_S_io_* functions called by
    the real functions in users.c to do work for ptys.  */
 error_t pty_io_write (struct trivfs_protid *, char *,

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



reply via email to

[Prev in Thread] Current Thread [Next in Thread]