home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1483 < prev    next >
Text File  |  1990-12-28  |  2KB  |  109 lines

  1. Newsgroups: alt.sources
  2. From: jimf@SABER.COM
  3. Subject: [xpert] Re: dynamic updating of title string in twm title for an Xterm.
  4. Message-ID: <1990Jun20.012038.21900@math.lsa.umich.edu>
  5. Date: Wed, 20 Jun 90 01:20:38 GMT
  6.  
  7. Archive-name: window-label/19-Jun-90
  8. Original-posting-by: jimf@SABER.COM
  9. Original-subject: Re: dynamic updating of title string in twm title for an Xterm.
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.windows.x.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. |Back under X11R3 I had copied an escape sequence from someone that updated
  16. |the title string on the twm title bar on my xterm windows from the command
  17. |line.  Now that I have progressed to R4 and the twm version distributed 
  18. |with it, I find I can no longer do this.  Can someone tell me how to do this?
  19.  
  20. The following program, "l.c" does this under both X and SunView.
  21.  
  22. jim frost
  23. saber software
  24. jimf@saber.com
  25.  
  26. -- cut here --
  27. /* l.c:
  28.  *
  29.  * icon/window labelling program for sunview/X
  30.  *
  31.  * jim frost 11.27.89
  32.  */
  33.  
  34. #include <stdio.h>
  35.  
  36. char *prgname;
  37.  
  38. void usage()
  39. {
  40.   fprintf(stderr, "Usage: %s [-sun|-sunview|-x11|-r4|-x11r4] window_label\n",
  41.       prgname);
  42.   exit(1);
  43. }
  44.  
  45. #define SUNVIEW 0 /* sunview is a zero */
  46. #define X11     1 /* X11 xterm */
  47.  
  48. main(argc, argv)
  49.      int argc;
  50.      char **argv;
  51. { char     buf[BUFSIZ];
  52.   int      type= -1;
  53.  
  54.   prgname= *(argv++);
  55.  
  56.   if (! *argv)
  57.     usage();
  58.  
  59.   if (**argv == '-') {
  60.     if (!strcmp(*argv, "-sun") || !strcmp(*argv, "-sunview"))
  61.       type= SUNVIEW;
  62.     else if (!strcmp(*argv, "-x11") || !strcmp("-x") ||
  63.          !strcmp(*argv, "-X11") || !strcmp("-X"))
  64.       type= X11;
  65.     else
  66.       usage();
  67.   }
  68.   else
  69.     --argv;
  70.  
  71.   /* no type given, try to figure it out from the environment
  72.    */
  73.  
  74.   if (type < 0) {
  75.     if (getenv("WINDOW_PARENT") ||
  76.     getenv("WINDOW_ME") ||
  77.     getenv("WINDOW_GFX") ||
  78.     getenv("WMGR_ENV_PLACEHOLDER"))
  79.       type= SUNVIEW;
  80.     else
  81.       type= X11;
  82.   }
  83.  
  84.   /* build string to send
  85.    */
  86.  
  87.   buf[0]= '\0';
  88.   while (*(++argv)) {
  89.     strcat(buf, *argv);
  90.     if (*(argv + 1))
  91.       strcat(buf, " ");
  92.   }
  93.  
  94.   /* send the proper escape for whatever type
  95.    */
  96.  
  97.   switch(type) {
  98.   case SUNVIEW: /* in days of old these were nice enough to have the same */
  99.     printf("\033]l%s\033\\\033]L%s\033\\", buf, buf);
  100.     break;
  101.   case X11:
  102.     printf("\033]0;%s\007", buf);
  103.     break;
  104.   default:
  105.     fprintf(stderr, "%s: Internal error (unknown terminal type)\n");
  106.   }
  107.   exit(0);
  108. }
  109.