home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / COMM / MISC / UWPC201.ZIP / UWSERVER.TAR / utility / uwtool.c < prev   
Encoding:
C/C++ Source or Header  |  1991-01-25  |  2.5 KB  |  120 lines

  1. /*
  2.  *    uwtool
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8. #include <strings.h>
  9. #include <stdio.h>
  10.  
  11. #include "uwlib.h"
  12.  
  13. main(argc, argv)
  14. int argc;
  15. char **argv;
  16. {
  17.     register uwid_t uwid;
  18.     register char *fname, *term;
  19.     register int c;
  20.     register uwtype_t wtype;
  21.     char *argv0;
  22.     char *av[2];
  23.     int vflag;
  24.     int wflag;
  25.     char *title;
  26.     union uwoptval uwoptval;
  27.     extern int errno;
  28.     extern int optind;
  29.     extern char *optarg;
  30.     extern char *getenv();
  31.  
  32.     /*
  33.      * If called with no arguments, create a new window using the
  34.      * current shell according to the SHELL environment variable
  35.      * (or "/bin/sh" if that doesn't exist).  If called with
  36.      * arguments, argv[optind] through argv[argc-1] are the arguments
  37.      * to the command.
  38.      *
  39.      * Options which are recognized directly are:
  40.      *
  41.      *    -v    (verbose) print new window ID on stdout
  42.      *    -wtype    create window with emulation "type"
  43.      *    -ttitle    label window with "title"
  44.      *
  45.      * If no explicit title is specified, the command name is used.
  46.      */
  47.     argv0 = argv[0];
  48.     wflag = 0;
  49.     vflag = 0;
  50.     title = (char *)0;
  51.     while ((c = getopt(argc, argv, "vw:t:")) != EOF) {
  52.         switch (c) {
  53.         case 'v':
  54.             vflag++;
  55.             break;
  56.         case 'w':
  57.             wflag++;
  58.             wtype = uw_ttype(optarg);
  59.             break;
  60.         case 't':
  61.             title = optarg;
  62.             break;
  63.         }
  64.     }
  65.             
  66.     if (optind < argc) {
  67.         /*
  68.          * Adjust the "argv" pointer according to the number of
  69.          * arguments we've processed.
  70.          */
  71.         argv += optind;
  72.         fname = *argv;
  73.     } else {
  74.         /*
  75.          * No (non-option) arguments -- use SHELL
  76.          */
  77.         if ((fname = getenv("SHELL")) == (char *)0)
  78.             fname = "/bin/sh";
  79.         av[0] = fname;
  80.         av[1] = (char *)0;
  81.         argv = av;
  82.     }
  83.  
  84.     if (title == (char *)0) {
  85.         /*
  86.          * If there was no "-t" argument, then "title" will still
  87.          * be NULL.  In this case we use the command name as
  88.          * the title.
  89.          */
  90.         title = fname;
  91.     }
  92.     
  93.     if (!wflag) {
  94.         /*
  95.          * If there was no "-w" argument, fetch the window
  96.          * type from the environment.  If that fails, use
  97.          * a default.
  98.          */
  99.         if ((term=getenv("TERM")) != (char *)0)
  100.             wtype = uw_ttype(term);
  101.         else
  102.             wtype = UWT_ADM31;
  103.     }
  104.     
  105.     if ((uwid = uw_cmd(wtype, fname, argv)) > 0) {
  106.         (void)strncpy(uwoptval.uwov_string, title,
  107.             sizeof uwoptval.uwov_string);
  108.         (void)uw_rsetopt(uwid, UWOP_TITLE, &uwoptval);
  109.         if (vflag)
  110.             printf("%d\n", uwid);
  111.         return(0);
  112.     } else {
  113.         if (uwerrno != UWE_NXSERV)
  114.             uw_perror(fname, uwerrno, errno);
  115.         else
  116.             uw_perror(argv0, uwerrno, errno);
  117.         return(1);
  118.     }
  119. }
  120.