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

  1. /*
  2.  *    uwtitle
  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. extern char *optarg;
  14. extern int optind;
  15. extern int errno;
  16.  
  17. extern char *getenv();
  18. extern long atol();
  19.  
  20. main(argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.     register int c;
  25.     register char *cp, *cq, **av;
  26.     register uwid_t uwid;
  27.     char *argv0;
  28.     char *cqlimit;
  29.     union uwoptval uwoptval;
  30.  
  31.     /*
  32.      * If called with no arguments, print a syntax message.  Otherwise,
  33.      * set the title of the current window to argv[1..argc-1].  The
  34.      * window ID is obtained from the environment or the "-i" argument.
  35.      */
  36.     argv0 = argv[0];
  37.     uwid = 0;
  38.     while ((c = getopt(argc, argv, "i:")) != EOF) {
  39.         switch (c) {
  40.         case 'i':
  41.             if ((uwid = atol(optarg)) == 0) {
  42.                 fprintf(stderr,
  43.                     "%s: malformed \"-i\" argument\n", argv0);
  44.                 return(1);
  45.             }
  46.             break;
  47.         }
  48.     }
  49.     if (optind >= argc) {
  50.         fprintf(stderr, "Syntax: \"%s [-iID] title ...\"\n", *argv);
  51.         return(1);
  52.     }
  53.  
  54.     if (uwid == 0) {
  55.         if ((cp = getenv("UW_ID")) == NULL) {
  56.             fprintf(stderr,
  57.                 "%s: can't determine window ID\n", argv0);
  58.             return(1);
  59.         }
  60.  
  61.         if ((uwid = (uwid_t)atol(cp)) == 0) {
  62.             fprintf(stderr,
  63.                 "%s: garbaged window ID in environment: %s",
  64.                 argv0, cp);
  65.             return(1);
  66.         }
  67.     }
  68.  
  69.     /*
  70.      * Copy the argv list into "uwoptval" and change the title.
  71.      */
  72.     av = argv + optind - 1;
  73.     cq = uwoptval.uwov_string;
  74.     cqlimit = uwoptval.uwov_string + sizeof uwoptval.uwov_string;
  75.     while ((cp = *++av) != NULL && cq < cqlimit) {
  76.         while (cq < cqlimit && (*cq++ = *cp++) != '\0')
  77.             ;
  78.         cq[-1] = ' ';
  79.     }
  80.     cq[-1] = '\0';
  81.  
  82.     if (uw_rsetopt(uwid, UWOP_TITLE, &uwoptval) < 0) {
  83.         uw_perror("uw_rsetopt", uwerrno, errno);
  84.         return(1);
  85.     } else
  86.         return(0);
  87. }
  88.