home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / 3b1tools next >
Encoding:
Text File  |  1989-02-03  |  41.6 KB  |  1,531 lines

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: benten@tigger.UUCP (Muhammad S. Benten)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i033: 3b1tools - windows and icons management for the Unix-pc
  5. Message-ID: <4418@boulder.Colorado.EDU>
  6. Date: 6 Nov 88 20:32:23 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: benten@tigger.UUCP (Muhammad S. Benten)
  9. Organization: University of Colorado, Boulder
  10. Lines: 1518
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 5, Issue 33
  14. Submitted-by: "Muhammad S. Benten" <benten@tigger.UUCP>
  15. Archive-name: 3b1tools
  16.  
  17. [Aside from some wishful thinking wrt. process stopping via ptrace (BSD,
  18. anyone? ;-) it almost makes me wish I hadn't sold the 3B1....  ++bsa]
  19.  
  20.             This posting contains the sources for a tool for the
  21. AT&T Unix-pc.  It is called "3b1tools". It will allow Unix-pc users  
  22. to do less! than what Sun users do with suntools.   Thanks.
  23.  
  24.  
  25.    ============================================================================ 
  26.    || Muhammad S. Benten                                                      |
  27.    || Elect. & Comp. Eng. Dept.                                               |
  28.    || University of Colorado, Boulder                                         |
  29.    ||                                                                         |
  30.    || email   ---->      benten@boulder.Colorado.EDU                          |
  31.    ||        or        ..{ncar|nbires}!boulder!benten                         |
  32.    ============================================================================ 
  33.  
  34.  
  35. ----------------------------Cut here----------------------------------------
  36. #! /bin/sh
  37. #
  38. # Wrapped by tigger!benten on Tue Nov  1 14:07:53 MST 1988
  39. #
  40. # This is a shell archive, meaning:
  41. # 1. Remove everything above the #! /bin/sh line.
  42. # 2. Save the resulting text in a file.
  43. # 3. Execute the file with /bin/sh (not csh) to create the files:
  44. #
  45. # Contents:  3b1tools.c 3b1tools.doc 3b1tools.h Makefile README nkbd.c.patch
  46. # picture.c tools.c
  47.  
  48. echo x - 3b1tools.c
  49. sed 's/^@//' > "3b1tools.c" <<'@//E*O*F 3b1tools.c//'
  50. /* 3b1tools.c - This file parses the command argument and performs
  51. **              all "windy" related processing. It will then call
  52. **              the icon handler.
  53. **
  54. ** Copyright (C) 1988 by Muhammad S. Benten.
  55. **                       benten@boulder.colorado.edu
  56. **
  57. **
  58. ** Permission to use, copy, modify, and distribute this software and its
  59. ** documentation for any purpose and without fee is hereby granted, provided
  60. ** that the above copyright notice appear in all copies and that both that
  61. ** copyright notice and this permission notice appear in supporting
  62. ** documentation.  This software is provided "as is" without express or
  63. ** implied warranty.
  64. **
  65. **
  66. **    A major portion of this file is extracted from the program windy
  67. **    which is available from "The STORE" with its sources.
  68. **    It will preserve most of windy's arguments.
  69. */
  70. #include "3b1tools.h"
  71. #define        NA      0xffff
  72.  
  73. struct uwdata xuw = {
  74.        NA, NA, NA, NA, NA};
  75. struct utdata xut[WTXTNUM];
  76. int bflag = 0;
  77. int Kflag = 0;
  78. char blot[81];
  79. char *ttyname();
  80. char * filenam;
  81. extern struct termio argg;
  82. extern char *optarg;
  83. extern int optind;
  84.  
  85. main(ac,av)
  86. int ac;
  87. char **av;
  88. {
  89.        int nflag = 0;
  90.        char avname[256];
  91.        char *env,cavname[256];
  92.        int i, c,rows,cols,pid;
  93.        FILE * ifd;
  94.        ioctl(Wn,TCGETA,&argg);
  95.        cols = 0;
  96.        rows = 0;
  97.        maxw = 672;
  98.        maxh = 288;
  99.        invert = 0;
  100.        iconopen = 0;
  101.        transpose = 0;
  102.  
  103.        if ( ac == 1 ) { /* no argument, get commands */
  104.           strcat(avname,".3b1tool");
  105.           if ( (ifd = fopen( avname, "r" )) != NULL) {
  106.                   startup(ifd,av);
  107.                   exit(0);} else {
  108.           strcpy(avname,getenv("HOME"));
  109.           strcat(avname,"/.3b1tool");
  110.           if ( (ifd = fopen( avname, "r" )) != NULL) {
  111.                   startup(ifd,av);
  112.                   exit(0);}
  113.         else {
  114.            printf("3b1tools: File .3b1tool doesn't exist\n3b1tools: Use 3b1tools -S for full screen shell\n");
  115.            exit(1);
  116.        }}}
  117.  
  118.        else {
  119.        ifd = (FILE *) -1;
  120.        while((c = getopt(ac, av, "robSRTp:c:l:u:1:2:n:f:h:w:x:y:K:X:Y:I:W:H:")) != EOF) {
  121.                switch(c) {
  122.                case 'b':{
  123.                        bflag++;
  124.                        break;}
  125.                case 'h':{
  126.                        xuw.uw_height = atoi(optarg);
  127.                     break;}
  128.                case 'w':{
  129.                        xuw.uw_width = atoi(optarg);
  130.                        break;}
  131.                case 'x':{
  132.                        xuw.uw_x = atoi(optarg);
  133.                        break;}
  134.                case 'y':{
  135.                        xuw.uw_y = atoi(optarg);
  136.                        break;}
  137.                case 'f':{
  138.                        xuw.uw_uflags = htoi(optarg);
  139.                        xuw.uw_uflags &= ~NOSETUFLAGS;
  140.                        break;}
  141.                case 'p':
  142.                        utset(WTXTPROMPT, optarg);{
  143.                        break;}
  144.                case 'c':{
  145.                        utset(WTXTCMD, optarg);
  146.                        break;}
  147.                case 'l':{
  148.                        utset(WTXTLABEL, optarg);
  149.                        break;}
  150.                case 'n':
  151.                case 'u':{
  152.                        nflag = 1;
  153.                        utset(WTXTUSER, optarg);
  154.                        break;}
  155.                case '1':{
  156.                        utset(WTXTSLK1, optarg);
  157.                        break;}
  158.                case '2':{
  159.                        utset(WTXTSLK2, optarg);
  160.                        break;}
  161.                case '?':{
  162.                        fprintf(stderr, "usage: 3b1tools [args] [command-args]\n");
  163.                        exit(2);}
  164.                case 'K':{
  165.                        strncpy(blot, optarg, 80);
  166.                        Kflag ++;
  167.                        break;}
  168.  
  169.                case 'I': {  /*  image file name */
  170.                          if ( optarg[0] == '-' ) {
  171.                             ifd = stdin;}
  172.                          else {
  173.                          ifd = fopen( optarg, "r" );
  174.                          if ( ifd == NULL )
  175.                      {
  176.                          fprintf( stderr, "Image %s: can't open.\n", optarg);
  177.                          exit( 1 ); }
  178.                              filenam = optarg;}
  179.                              break;}
  180.                 case 'W': { /* overwrite image height */
  181.                           cols = atoi(optarg);
  182.                           break;}
  183.                 case 'H': { /* overwrite image width */
  184.                           rows = atoi(optarg);
  185.                           break;}
  186.                 case 'X': { /* icon width */
  187.                           maxw = atoi(optarg);
  188.                           if (maxw > 672 )
  189.                              maxw = 672;
  190.                           break;}
  191.                  case 'Y': { /* icon height */
  192.                            maxh = atoi(optarg);
  193.                            if (maxh > 288 )
  194.                               maxh = 288;
  195.                            break;}
  196.                  case 'R': { /* reverse image */
  197.                            invert++;
  198.                            break;}
  199.                  case 'o': { /* start with an open window */
  200.                            iconopen++;
  201.                            break;}
  202.                  case 'r': { /* start with an open window */
  203.                            normal++;
  204.                            break;}
  205.                   case 'S':{
  206.                            xuw.uw_x = 0;
  207.                            xuw.uw_y = 12;
  208.                            xuw.uw_width = 720;
  209.                            xuw.uw_height = 288;
  210.                            xuw.uw_uflags = 0x1;
  211.                            break;}
  212.                  case 'T': { /* transpoe icon */
  213.                            transpose++;
  214.                            break;}}
  215.  
  216.        }}
  217.        /*
  218.         * if gave command args, put it in a new window
  219.         * if gave window args, or no args at all, change window params
  220.         */
  221.        if(optind < ac) {
  222.                if( bflag)
  223.                   newwind();
  224.                avname[0] = 0;
  225.                for(i=optind; i<ac; i++) {
  226.                        strcat(avname, av[i]);
  227.                        strcat(avname, " ");
  228.                }
  229.                if( bflag)
  230.                  if(!nflag)
  231.                        utset(WTXTUSER, avname);
  232.        }
  233.        fixwind();
  234.                
  235.                if(bflag) {
  236.                        pid = fork();
  237.                        if(pid > 0)
  238.                                exit(1);
  239.                        else if(pid == 0) {
  240.                                setpgrp();
  241.                                ioctl(0, WIOCPGRP);
  242.                        }
  243.                }
  244.                icon_exec(av,rows,cols,ifd);
  245.        exit(0);
  246. }
  247. utset(n, s)
  248. char *s;
  249. {
  250.        xut[n].ut_num = 1;
  251.        strncpy(xut[n].ut_text, s, WTXTLEN);
  252. }
  253. newwind() {
  254.        char name[10];
  255.        struct termio t;
  256.        int bad = 0, i, fd;
  257.  
  258.        if (!isatty(0)) return;
  259.        if(strncmp("/dev/w", ttyname(0), 6)!=0 ) return;
  260.  
  261.        if (ioctl(0, TCGETA, &t) < 0) {
  262.                perror("getting tty chars");
  263.                bad = 1;
  264.        }
  265.        fd = open("/dev/window",2);
  266.        if (fd < 0) {
  267.                perror("opening window");
  268.                return;
  269.        }
  270.        if(bflag) {
  271.                ioctl(fd, WIOCSELECT);
  272.                sprintf(name, "[w%d]\n", ioctl(fd, WIOCGCURR));
  273.                write(0, name, strlen(name));
  274.        }
  275.  
  276.        close(0);
  277.        dup(fd);
  278.        close(1);
  279.        dup(fd);
  280.        close(2);
  281.        dup(fd);
  282.        close(fd);
  283.        /* Set in the previous edit characters to the new window */
  284.        if (!bad && ioctl(0, TCSETAF, &t) < 0)
  285.                perror("setting tty chars");
  286.        for (i=0; environ[i]; ++i) {
  287.                if (!strncmp(environ[i],"TERMCAP=",8)) {
  288.                        environ[i] = "TERMCAP=/etc/termcap";
  289.                }
  290.                if (!strncmp(environ[i],"TERM=",5)) {
  291.                        environ[i] = "TERM=s4";
  292.                }
  293.        }
  294. }
  295. fixwind() {
  296.        struct uwdata uw;
  297.        int i;
  298.  
  299.        if(Kflag) {
  300.                xut[WTXTSLK1].ut_num = WTXTSLK1;
  301.                xut[WTXTSLK2].ut_num = WTXTSLK2;
  302.                keyfix(xut[WTXTSLK1].ut_text);
  303.                keyfix(xut[WTXTSLK2].ut_text);
  304.        }
  305.        for(i=0; i<WTXTNUM; i++) {
  306.                if(xut[i].ut_num) {
  307.                        xut[i].ut_num = i;
  308.                        ioctl(0, WIOCSETTEXT, &xut[i]);
  309.                }
  310.        }
  311.        ioctl(0, WIOCGETD, &uw);
  312.        if(xuw.uw_x != NA) {uw.uw_x = xuw.uw_x;new_wind++;}
  313.        if(xuw.uw_y != NA) {uw.uw_y = xuw.uw_y;new_wind++;}
  314.        if(xuw.uw_width != NA) {uw.uw_width = xuw.uw_width;new_wind++;}
  315.        if(xuw.uw_height != NA) {uw.uw_height = xuw.uw_height;new_wind++;}
  316.        if(xuw.uw_uflags != NA) {uw.uw_uflags = xuw.uw_uflags;new_wind++;}
  317.        ioctl(0, WIOCSETD, &uw);
  318. }
  319. keyfix(s)
  320. char *s;
  321. {
  322.        int c, i;
  323.  
  324.        for(i=0; i<80; i++) {
  325.                c = s[i] & 0177;
  326.                if(c == 0) c = ' ';
  327.                switch(blot[i]) {
  328.                case ' ':
  329.                case 0:
  330.                        c = ' ';
  331.                        break;
  332.                case 'r':
  333.                case 'R':
  334.                        c |= 0200;
  335.                        break;
  336.                }
  337.                s[i] = c;
  338.        }
  339. }
  340. char *utname[] = {
  341.        "Prompt line",
  342.        "Command line",
  343.        "Label",
  344.        "User",
  345.        "SLK1",
  346.        "SLK2",
  347. };
  348. report(s)
  349. char *s;
  350. {
  351.        struct uwdata uw;
  352.        struct utdata ut;
  353.        int i;
  354.  
  355.        printf("%s:  ", s);
  356.        ioctl(0, WIOCGETD, &uw);
  357.        uwshow(&uw, (char *)0);
  358.  
  359.        for(i=0; i<WTXTNUM; i++) {
  360.                ut.ut_num = i;
  361.                ioctl(0, WIOCGETTEXT, &ut);
  362.                if(ut.ut_text[0]) {
  363.                        printf("%s=<%.81s>\n", utname[i], ut.ut_text);
  364.                }
  365.        }
  366. }
  367. uwshow(p, s)
  368. struct uwdata *p;
  369. char *s;
  370. {
  371.        printf("(x,y)=(%d,%d)  ", p->uw_x, p->uw_y);
  372.        printf("(width,height)=(%d,%d)  ", p->uw_width, p->uw_height);
  373.        printf("flags=%x\n  ", p->uw_uflags);
  374.        printf("(hs,vs)=(%d, %d)[RO]  ", p->uw_hs, p->uw_vs);
  375.        printf("baseline=%d[RO]  ", p->uw_baseline);
  376.        printf("(cx,cy)=(%d, %d)[RO]\n", p->uw_cx, p->uw_cy);
  377. }
  378. htoi(s)
  379. char *s;
  380. {
  381.        int x = NA;
  382.  
  383.        sscanf(s, "%x", &x);
  384.        return x;
  385. }
  386.  
  387.  
  388. startup(ifi,argv)
  389. int ifi;
  390. char *argv;
  391. {
  392.    char cavname[256],avname[256],*sy;
  393.  
  394.    while ( fgets(avname,256,ifi) != 0 ) {
  395.       cavname[0] =0;
  396.       strcat(cavname,avname);
  397.       sy = (char *) strtok(avname," ");
  398.       if ( sy[0] != 0 )
  399.       if ( strncmp(sy,"3b1tools",5)  !=0 ) {
  400.       avname[0] =0;
  401.       strcat(avname,cavname);
  402.       strcpy(cavname , "3b1tools -b "); 
  403.       strcat(cavname,avname);
  404.       system(cavname);} else{
  405.       printf("3b1tools: error in .3b1tool file\n");
  406.       printf("3b1tools: in %s\n",avname);
  407.       printf("3b1tools: only arguments to 3b1tools are specified\n");}}
  408.    close(ifi);
  409. }
  410. @//E*O*F 3b1tools.c//
  411. chmod u=rw,g=r,o=r 3b1tools.c
  412.  
  413. echo x - 3b1tools.doc
  414. sed 's/^@//' > "3b1tools.doc" <<'@//E*O*F 3b1tools.doc//'
  415.  
  416.  
  417.  
  418.  
  419. 3b1tools                     1                         draft
  420.  
  421.  
  422. Name:   3b1tools -  A Unix-pc windowing environment and image
  423.                      display tool.
  424.                      Copyright (c) 1988 by Muhammad S. Benten.
  425.  
  426. Author: Muhammad S. Benten
  427.         University Of Colorado
  428.         Electrical & Computer Engineering
  429.         Boulder, Co 80309
  430.  
  431. Usage:  3b1tools [-b] [-S] [-o] [-I <icon>]  [-R] [-T] [-X nnn] [-Y nnn]
  432.                 [-H nnn]  [-W nnn] [-x nnn] [-y nnn] [-h nnn] [-w nnn]
  433.                 [-n <string>]  [-1 <string>] [-2 <string>] [-p <string>]
  434.                 [-c <string>]  [-f <hex>]  [-l <string>]  [-K <string>]
  435.                 [ <command> [ <arguments>]]
  436.  
  437. Description:
  438.          3b1tools is a general purpose windowing program designed
  439.          to utilize the capabilities of the Unix-pc. It replaces the
  440.          functionality of the program "windy", and can also be used as
  441.          a general purpose image and icon display tool. The borders of 
  442.          a displayed icon, can be toggled on/off by the middle mouse button,
  443.          B2. It can also be toggled by the function keys F2 or F7. You
  444.          can open an icon by using the left mouse button B1, or using
  445.          the functions keys F1 or F6. To exit and destroy an icon, you
  446.          can use the right mouse button B3, or the function keys, F3 or F8.
  447.          A confirmation will be requested when you destry an icon.
  448.          Icons displayed using 3b1tools can be scrolled up, down,
  449.          left and right using the scroll indicators on the icon borders.
  450.          The size of the icon can also be controlled by the user through
  451.          the -X and -Y options .  A closed icon is either idle
  452.          or stopped.  A stopped icon can be resumed by the function key
  453.          F1 in which case the screen would be restored and execution of
  454.          the stopped command continues.  Opening an idle icon would
  455.          restore the screen to its last state before the icon was
  456.          either created or closed and the execution of the command
  457.          argument is attempted.  This execution can be stopped at any
  458.          point by the stop key ( CTRL-Z ). In this case the execution
  459.          of the command would stop and the icon will close in a stopped
  460.          state.
  461.          
  462.  
  463.          There are five modes of operation in 3b1tools which can be specified 
  464.          by the options used to invoke 3b1tools.  These modes are:
  465.  
  466.  
  467.      mode-1:  no command argument and no -b option
  468.  
  469.          In this mode, 3b1tools will close the invoking window saving
  470.          its contents and display an icon as specified by the  -I
  471.          option. It will display a default icon if no icon is specfied.
  472.          Note that the -S option must be specified if no argument is
  473.          given to 3b1tools.
  474.          Example:
  475.  
  476.                  3b1tools  -I girls
  477.  
  478.  
  479.      mode-2:  no -b option but a command and its arguments are supplied
  480.  
  481.          In this mode, 3b1tools will close the invoking window saving
  482.          its contents and display an icon as specified by the  -I option.
  483.          It will display a default icon if no icon is specfied. Upon
  484.          exiting the executing command, the window will be closed and
  485.          the icon is displayed again. You can also start with an open
  486.          window executing the command argument by specifying the -o
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497. 3b1tools                     2                         draft
  498.  
  499.  
  500.          option which will be iconified when the command terminates.
  501.          Example:
  502.  
  503.                  3b1tools  -I office  ua
  504.  
  505.  
  506.      mode-3:  no command argument and a -b option
  507.  
  508.          This is similar to mode-1, except that the original window
  509.          is left intact and the icon is displayed in a new window.
  510.          Example:
  511.  
  512.                  3b1tools -b -I girls
  513.  
  514.  
  515.      mode-4:  with a command argument and a -b option
  516.  
  517.          This is similar to mode-2, except that the original window
  518.          is left intact and the icon and its execution window will
  519.          occupy a new window.
  520.          Example:
  521.  
  522.                  3b1tools -b -I moon vi
  523.  
  524.  
  525.      mode-5: no arguments at all.
  526.  
  527.          In this mode, 3b1tools will search for the file ./.3b1tool.
  528.          If this file doesn't exist it searches for the file $HOME/3b1tool.
  529.          If this file is not found 3b1tools will terminate with an error
  530.          message.  In this mode, 3b1tools expects the lines of either
  531.          of these files to conain arguments for 3b1tools that will
  532.          be executed with the -b option.
  533.          Example:
  534.  
  535.            command:  3b1tools
  536.  
  537.            The file .3b1tool contain:
  538.  
  539.                      -I horse ls -l
  540.                      -I dog   ua
  541.  
  542. options:
  543.  
  544.    -b
  545.          dettach the new icon-window from the parent process.
  546.          3b1tools will create a new window.
  547.  
  548.    -S
  549.          This flag is usefull only if it is the only argument
  550.          to 3b1tools. It will  expand the current window into full screen
  551.          without executing commands from ~/.3b1tool or .3b1tool.
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563. 3b1tools                     3                         draft
  564.  
  565.  
  566.    -o
  567.          This option will instruct 3b1tools to start with an opened
  568.          window. 3b1tools will default to a closed window (iconified).
  569.  
  570.    -I  <icon>
  571.          Use the file <icon> as the image file for the icon when
  572.          the window is closed.a If <icon> is in a cbm (compact
  573.          bitmap) format, height and width are taken from the file,
  574.          if it isn't, they must be specified by the -H -W option.
  575.  
  576.    -R
  577.          Reverse the bits in the displayed icon.
  578.  
  579.    -T
  580.          Transpose the image of the icon. (not implemented).
  581.  
  582.    -X  nnn
  583.          Let the displayed width of the icon be nnn.
  584.  
  585.    -Y  nnn
  586.          Let the displayed height of the icon window be nnn.
  587.  
  588.    -W  nnn
  589.          Override the picture pixcell width to be nnn.
  590.  
  591.    -H  nnn
  592.          Override the picture pixcell height to be nnn.
  593.  
  594.    -w  nnn
  595.          Let the displayed width of the execution window be nnn.
  596.  
  597.    -h  nnn
  598.          Let the displayed height of the execution window window be nnn.
  599.  
  600.    -x  nnn
  601.          Position the icon and its execution window at x=nnn
  602.  
  603.    -y  nnn
  604.          Position the icon and its execution window at y=nnn
  605.  
  606.    -n  <string>
  607.          Use <string> as the name of the window as displayed
  608.          by the window manager.
  609.  
  610.    -l  <string>
  611.          Use <string> as the window label.
  612.  
  613.    -1  <string>
  614.          Use <string> as the string that will appear in the first
  615.          line of the function keys lables.
  616.  
  617.    -2  <string>
  618.          Use <string> as the string that will appear in the second
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629. 3b1tools                     4                         draft
  630.  
  631.  
  632.          line of the function keys lables.
  633.  
  634.    -K  <string>
  635.          Use <string> as the pattern for the function keys lables.
  636.          An "r" in <string> means reverse vedio at that position.
  637.  
  638.    -c  <string>
  639.          Display <string> in the command line.
  640.  
  641.    -p  <string>
  642.          Display <string> in the prompt line.
  643.  
  644.    -f  <hex>
  645.          Use <hex> as the flag that control the shape of the
  646.          execution window.
  647.  
  648.  
  649.    command [<arguments>]
  650.          Any unix command and its arguments that will be executed
  651.          when the icon is opened.
  652. @//E*O*F 3b1tools.doc//
  653. chmod u=rw,g=r,o=r 3b1tools.doc
  654.  
  655. echo x - 3b1tools.h
  656. sed 's/^@//' > "3b1tools.h" <<'@//E*O*F 3b1tools.h//'
  657. #include <termio.h>
  658. #include <sys/window.h>
  659. #include <stdio.h>
  660.  
  661. extern int maxw,maxh;
  662. extern int invert;
  663. extern int transpose;
  664. extern int iconopen;
  665. extern int normal;
  666. extern int new_wind;
  667. extern int Wn;
  668. extern char **environ;
  669. @//E*O*F 3b1tools.h//
  670. chmod u=rw,g=r,o=r 3b1tools.h
  671.  
  672. echo x - Makefile
  673. sed 's/^@//' > "Makefile" <<'@//E*O*F Makefile//'
  674.  
  675. MAKEINC=/usr/include
  676. include $(MAKEINC)/Makepre.h
  677.  
  678.  
  679. OBJ=tools.o picture.o 3b1tools.o 
  680.  
  681. all: $(OBJ)
  682.     $(LD) $(LDFLAGS) $(SHAREDLIB) $(OBJ) $(LIBM) -o 3b1tools  
  683.  
  684.  
  685. include $(MAKEINC)/Makepost.h
  686.  
  687.  
  688.  
  689. @//E*O*F Makefile//
  690. chmod u=rw,g=rw,o=rw Makefile
  691.  
  692. echo x - README
  693. sed 's/^@//' > "README" <<'@//E*O*F README//'
  694.  
  695.  
  696. /* 3b1tools
  697. **
  698. **
  699. **
  700. ** Copyright (C) 1988 by Muhammad S. Benten.
  701. **                       benten@boulder.colorado.edu
  702. **
  703. **
  704. ** Permission to use, copy, modify, and distribute this software and its
  705. ** documentation for any purpose and without fee is hereby granted, provided
  706. ** that the above copyright notice appear in all copies and that both that
  707. ** copyright notice and this permission notice appear in supporting
  708. ** documentation.  This software is provided "as is" without express or
  709. ** implied warranty.
  710. **
  711. **
  712. ** 
  713. **
  714. */
  715.  
  716. This program was originally written to display AT&T demo graphics on 
  717. the Unix-pc.  It was later on modified to display Compact BitMap (CBM)
  718. files, which opened the machine to a huge number of icon editors and
  719. raytracers.  The program close.c triggered the idea of closing windows
  720. to a graphical icon.  This idea was then modified to start with this
  721. program that can be opened to an executing window. It used to be invoked
  722. with "windy" for the purpose of detaching it from the invoking shell.
  723. With the availability of windy's sources I couldn't resist incorporating
  724. the whole shpang as a single tool that I called "pctools". Due to
  725. a name conflict, this was then renamed "3b1tools".  The posting of
  726. the executable of this program provided me with great suggestions
  727. about the user interface and the choice of interaction keys.  With
  728. some head knocking I decided to search for a way to suspend windows.
  729. I then wrote my own primitive keyboard device driver, which I then
  730. realized that it will interfere with both CAPSCTRL loadable
  731. device driver and the "keyfix" programs.  I then though of using
  732. Ditto's kbd driver with minimal changes to support the interception
  733. of the suspend key and passing it to 3b1tools.
  734.  
  735. The program as it stands now works fine and does most of what
  736. Sun's  suntools (c)  does.  However, some minor problems may
  737. result from the way processes are suspended. This program suspends
  738. processes executing in 3b1tools windows in a trace mode (ptrace(2)).
  739. These processes when resumed will report their status to their
  740. parents through the wait(2) call.  Thus, parent processes that
  741. call wait(2) and only check for signals wakeup otherwise they
  742. assume the child is dead will be executing with their children
  743. when the child is resumed.  In this situation both the parent
  744. and its child will be competing for the keybord input.  If the
  745. child wins this should present no problem, however, if the
  746. parent wins you may want to do something about.
  747.  
  748.  
  749. Enjoy using this tool and I'll try to respond to questions and
  750. bug reports. I also would like to hear about any modifications
  751. or enhancement to 3b1tools.  It was my baby, but it has grown
  752. enough to fight its way by itself.
  753.  
  754. You will need -=> Ford <=- CAPCTRL sources to be able to use the
  755. suspension feature of 3b1tools.  The patches to the file nkbd.c
  756. are included in the file nkbd.c.patch.
  757.  
  758. ** Copyright (C) 1988 by Muhammad S. Benten.
  759. **                       benten@boulder.colorado.edu
  760. **
  761. **
  762. ** Permission to use, copy, modify, and distribute this software and its
  763. ** documentation for any purpose and without fee is hereby granted, provided
  764. ** that the above copyright notice appear in all copies and that both that
  765. ** copyright notice and this permission notice appear in supporting
  766. ** documentation.  This software is provided "as is" without express or
  767. ** implied warranty.
  768. @//E*O*F README//
  769. chmod u=rw,g=r,o=r README
  770.  
  771. echo x - nkbd.c.patch
  772. sed 's/^@//' > "nkbd.c.patch" <<'@//E*O*F nkbd.c.patch//'
  773. 78a79
  774. 516,524d516
  775. <    /* changes required for 3b1tools */ 
  776. <     if (  tp->t_cc[7] == 253 ) 
  777. <        if  (  ch == 26 ) {
  778. <           tp->t_cc[7] = 254;
  779. <           return;
  780. <     }
  781. <    /* end changes required for 3b1tools */ 
  782. @//E*O*F nkbd.c.patch//
  783. chmod u=rw,g=r,o=r nkbd.c.patch
  784.  
  785. echo x - picture.c
  786. sed 's/^@//' > "picture.c" <<'@//E*O*F picture.c//'
  787. /* picture.c - reads a compact bitmap and converts it into the Unix-pc
  788. **             format.
  789. **
  790. ** Copyright (C) 1988 by Muhammad S. Benten.
  791. **                       benten@boulder.colorado.edu
  792. **
  793. **
  794. ** Permission to use, copy, modify, and distribute this software and its
  795. ** documentation for any purpose and without fee is hereby granted, provided
  796. ** that the above copyright notice appear in all copies and that both that
  797. ** copyright notice and this permission notice appear in supporting
  798. ** documentation.  This software is provided "as is" without express or
  799. ** implied warranty.
  800. */
  801.  
  802. #include <stdio.h>
  803.  
  804. /* default icon */
  805.  
  806. short deflt[]={
  807. -1, -1, 1, -32768, -63, -30721, 1729, -27136, 193, -27136, 193,
  808. -27136, 193, -27136, 193, -27136, 193, -27136, 193, -27136, 193,
  809. -27136, 193, -29184, -159, -29185, -127, -30721, 16385, -32760,
  810. 32705, -24592, -31, -24577, -31, -28673, -31, -28673, 1, -32768, 1,
  811. -32768, 1, -32768, 1, -32768, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  812. -1, -1, -1, -1
  813. };
  814.  
  815. extern char * filenam;
  816.  
  817. extern int transpose;
  818.  
  819. icon_exec(comm,rows,cols,ifd)
  820. char **comm;
  821. FILE *ifd;
  822. int rows, cols;
  823.     {
  824.     char engl[256];
  825.     char *bits;
  826.     char tst,cbm;
  827.     int i,index1, row, col,byte1,cols1,rows1;
  828.  
  829.     /*
  830.       Was there an icon file specified?
  831.     */
  832.  
  833.     if (ifd != ((FILE *) -1) ) {
  834.  
  835.     /*
  836.       Oh, yeh!  Is it a Compact BitMap?
  837.     */
  838.  
  839.  
  840.     if ( (tst = getc( ifd ) ) == 42 ){
  841.       if ( getc( ifd ) == 23 )
  842.     {
  843.           cbm = 1;
  844.           cols1 = getc( ifd ) << 8;
  845.           cols1 += getc( ifd );
  846.           rows1 = getc( ifd ) << 8;
  847.           rows1 += getc( ifd );
  848.           if (cols == 0)
  849.              cols = cols1;
  850.           if (rows == 0)
  851.              rows = rows1;
  852.           cols = cols /8;
  853.         }}  
  854.         else
  855.  
  856.     /*
  857.       Or is it Unix-pc  raw BitMap?
  858.     */
  859.  
  860.         {
  861.           cbm = 0;
  862.           if ( ( rows == 0) || (cols == 0)){
  863.              printf("3b1tools: You must specify width and height. This is a raw icon!");
  864.              exit(1);}
  865.           cols = cols/8;
  866.         }
  867.         rows = (rows/8)*8;
  868.  
  869.         bits = (char *) malloc(cols*rows) ;
  870.  
  871.         for (col = 0; col <= cols ; col++)
  872.           for(row = 0; row < rows ; row += 2)
  873.  
  874.         /* handle CBM format ===> Unix-pc */
  875.  
  876.             if  (cbm == 1)  {
  877.         byte1 = 0;
  878.         tst = getc( ifd );
  879.  
  880.         /* flip the high byte */
  881.  
  882.         if (tst & 0x1)
  883.            byte1 |=  0x80;
  884.         if (tst & 0x2)
  885.            byte1 |=  0x40;
  886.         if (tst & 0x4)
  887.            byte1 |=  0x20;
  888.         if (tst & 0x8)
  889.            byte1 |=  0x10;
  890.         if (tst & 0x10)
  891.            byte1 |=  0x8;
  892.         if (tst & 0x20)
  893.            byte1 |=  0x4;
  894.         if (tst & 0x40)
  895.            byte1 |=  0x2;
  896.         if (tst & 0x80)
  897.            byte1 |=  0x1;
  898.          bits[col*rows + (row+1)] =  byte1;
  899.         byte1 = 0;
  900.         tst = getc( ifd );
  901.  
  902.         /* flip the the low byte */
  903.  
  904.         if (tst & 0x1)
  905.             byte1 |=  0x80;
  906.         if (tst & 0x2)
  907.                byte1 |=  0x40;
  908.         if (tst & 0x4)
  909.                byte1 |=  0x20;
  910.         if (tst & 0x8)
  911.                byte1 |=  0x10;
  912.         if (tst & 0x10)
  913.            byte1 |=  0x8;
  914.         if (tst & 0x20)
  915.            byte1 |=  0x4;
  916.         if (tst & 0x40)
  917.            byte1 |=  0x2;
  918.         if (tst & 0x80)
  919.            byte1 |=  0x1;
  920.  
  921.         bits[col*rows + row] =  byte1;}
  922.         else 
  923.  
  924.        /*  It is already in Unix-pc format */
  925.  
  926.             if ( col == 0 && row == 0) {
  927.            bits[1] =  tst;
  928.            bits[0] =  getc(ifd);
  929.             } 
  930.             else {
  931.            bits[col*rows + (row+1)] =  getc(ifd);
  932.            bits[col*rows + row] =  getc(ifd);
  933.             }
  934.        fclose(ifd);
  935.         }
  936.      else
  937.  
  938.       /*  use the built in (default) icon */
  939.  
  940.      {  
  941.         cols = 4;
  942.         rows = 32;
  943.         bits = (char *) deflt;
  944.         }
  945.  
  946.      /*
  947.        transpose the bitmap
  948.      */
  949.  
  950.      if ( transpose ) {
  951.  
  952.         /* Not implemented. 
  953.  
  954.        A1:Why?         
  955.        A2:very slooow.
  956.        A1:But only for big pictures, isn't it?
  957.        A2:Any way, who wants to transpose a small icon?
  958.        A1:I do. 
  959.        A2:Go ahead and do it then.
  960.  
  961.     transpose_bits ( bits , rows , cols);
  962.         i = rows/8;
  963.         rows = cols*8;
  964.         cols = i;
  965.  
  966.     */
  967.      }
  968.     
  969.     /* invoke the window manager in tools.c */
  970.  
  971.         windowinit( comm,bits, cols , cols*8 ,rows);
  972.  
  973.     exit( 0 );
  974.     }
  975.  
  976.  
  977. @//E*O*F picture.c//
  978. chmod u=rw,g=r,o=r picture.c
  979.  
  980. echo x - tools.c
  981. sed 's/^@//' > "tools.c" <<'@//E*O*F tools.c//'
  982. /* tools.c -   Displays, opens, closes and resumes an icon.
  983. **
  984. **
  985. ** Copyright (C) 1988 by Muhammad S. Benten.
  986. **                       benten@boulder.colorado.edu
  987. **
  988. **
  989. ** Permission to use, copy, modify, and distribute this software and its
  990. ** documentation for any purpose and without fee is hereby granted, provided
  991. ** that the above copyright notice appear in all copies and that both that
  992. ** copyright notice and this permission notice appear in supporting
  993. ** documentation.  This software is provided "as is" without express or
  994. ** implied warranty.
  995. **
  996. **   
  997. */
  998. # include     <sys/ioctl.h>
  999. # include     <signal.h>
  1000. # include       <sys/mouse.h>
  1001. # include       <kcodes.h>
  1002. # include     <message.h>
  1003. # include       "3b1tools.h"
  1004.  
  1005. #define up        196
  1006. #define down        197
  1007. #define left        190
  1008. #define right        204
  1009. #define xdelta        40
  1010. #define ydelta        20
  1011. #define XMAX1        uwidth
  1012. #define YMAX1           uheight
  1013.  
  1014. /* inside the window */
  1015.  
  1016. #define XMAX    uw.uw_width                     /* in pixels            */
  1017. #define YMAX    uw.uw_height                    /* in pixels            */
  1018. #define BPERBY  8                               /* bits per byte        */
  1019. #define XMAXB   ((XMAX+(BPERBY-1))/BPERBY)      /* in bytes             */
  1020. #define YMAXB   YMAX                            /* same as pixels       */
  1021. extern unsigned short patwhite[];
  1022.  
  1023. int Wn=1; 
  1024. int new_wind1;
  1025. int new_wind;
  1026. int maxw;
  1027. int maxh;
  1028. int transpose;
  1029. int invert;
  1030. int bord_flag;
  1031. int iconopen=0;
  1032. int normal=0;
  1033. unsigned isig=0;
  1034. short done=0;
  1035. int statch;
  1036.  
  1037. struct uwdata   uw;             /* current window data */
  1038. struct uwdata   Suw;            /* Saved window data */
  1039. struct uwdata   Puw;            /* Saved window data */
  1040. struct uwdata   suw;            /* Saved window data */
  1041. struct urdata urt;
  1042. unsigned short Bitmap[ 15660 ];             /* Saved screen */
  1043. unsigned short Bitmap1[ 15660 ];            /* Saved screen */
  1044. struct umdata mouse;
  1045. struct umdata mouse1;
  1046. struct termio argg;
  1047. struct termio argg1;
  1048. struct termio argg2;
  1049. struct termcb argcb;
  1050. int xstart,ystart,width,height,uwidth,uheight;
  1051. struct     utdata sut[6];
  1052. struct     utdata suti[6];
  1053. int      (*intsig)(),(*quitsig)();
  1054. int     closeit();
  1055. int     sendit();
  1056. int     frk=1;
  1057. int     pid=-9;
  1058. int     pppid,ppid;
  1059. extern     char *optarg;
  1060. extern     int optind;
  1061.  
  1062.  
  1063. /*
  1064. **   save the window state and close window
  1065. **   then go and wait for user response
  1066. */
  1067.  
  1068. windowinit(comm,ico,wid,wid1,hit1)
  1069. char * ico, **comm;
  1070. int wid,wid1,hit1;
  1071. {
  1072.     int i;
  1073.     /* save original parameters */
  1074.     if ( ioctl( Wn, WIOCGETD, &uw) != 0 )
  1075.     {
  1076.         fprintf(stderr, "Can't close a non-window.\n");
  1077.         exit(1);
  1078.     }
  1079.     
  1080.     winit();
  1081.     keypad(0,1);
  1082.  
  1083.  
  1084.     /* save the bitmap */
  1085.  
  1086.     new_wind = wrastop(Wn, 0,0, Bitmap, XMAXB, 0,0, 0,0, XMAX, YMAX,
  1087.         SRCSRC, DSTSRC, 0 );
  1088.     new_wind1 = wrastop(Wn, 0,0, Bitmap1, XMAXB, 0,0, 0,0, XMAX, YMAX,
  1089.         SRCSRC, DSTSRC, 0 );
  1090.  
  1091.     /* save the window state */
  1092.     Suw = uw;
  1093.     Puw = uw;
  1094.     suw = uw;
  1095.  
  1096.  
  1097.     /*  save USER  texts */
  1098.     for ( i=0; i<6 ; i++) {
  1099.         sut[i].ut_num=i;
  1100.         suti[i].ut_num=i;
  1101.         ioctl(Wn,WIOCGETTEXT,&sut[i]);
  1102.         ioctl(Wn,WIOCGETTEXT,&suti[i]);
  1103.     }
  1104.  
  1105.     sprintf(suti[WTXTCMD].ut_text,"Press CTRL-Z to close window");
  1106.  
  1107.     /* Turn cursor off */
  1108.     fprintf(stderr, "\033[=1C" );
  1109.  
  1110.     /* set up function keys */
  1111.     wslk(Wn, 0, "   OPEN    TOGGLE   EXIT                             B1 TO    B2 TO    ",
  1112.             "           BORDER                                    OPEN     TOGGLE   EXIT");
  1113.  
  1114.     /* set icon limits */
  1115.  
  1116.     xstart=0;
  1117.     ystart=0;
  1118.     width = wid1;
  1119.     height = hit1;
  1120.     if (wid1 > maxw )
  1121.        wid1 = maxw;
  1122.     if (hit1 > maxh )
  1123.        hit1 = maxh;
  1124.     uwidth = wid1;
  1125.     uheight = hit1;
  1126.     bord_flag = 1;
  1127.  
  1128.     /* close window */
  1129.  
  1130.     iconify(ico,wid,wid1,hit1);
  1131.  
  1132.     ioctl(Wn, WIOCGETMOUSE, &mouse);
  1133.     ioctl(Wn, WIOCGETMOUSE, &mouse1);
  1134.     mouse.um_flags = MSDOWN;
  1135.     ioctl(Wn, WIOCSETMOUSE, &mouse);
  1136.            
  1137.     manage_window(ico,wid,comm); 
  1138. }
  1139.  
  1140.  
  1141.  
  1142.  
  1143. /*
  1144. ** Turn the window into an "icon".
  1145. */
  1146.  
  1147. iconify(ico,wid,wid1,hit1)
  1148. char * ico;
  1149. int wid,wid1,hit1;
  1150. {
  1151.  int i;
  1152.  
  1153.     
  1154.     uw = suw;
  1155.     if (done != 1) {
  1156.     if ( bord_flag ) { 
  1157.        uw.uw_uflags |= NBORDER ;
  1158.     } 
  1159.     else {
  1160.           uw.uw_uflags &= ~(NBORDER);
  1161.           uw.uw_uflags |=  BORDHSCROLL ;
  1162.           uw.uw_uflags |=  BORDVSCROLL ;
  1163.     }
  1164.     uw.uw_height = hit1;
  1165.     uw.uw_width = wid1;
  1166.     ioctl( Wn, WIOCSETD, &uw );
  1167.     done=1;}
  1168.  
  1169.     urt.ur_srcbase = (unsigned short *) ico;
  1170.     urt.ur_srcwidth = wid;
  1171.     urt.ur_height = 1;
  1172.     urt.ur_width = wid1;
  1173.     urt.ur_srcx = xstart;
  1174.     if (invert)  {
  1175.        urt.ur_srcop = SRCXOR;
  1176.        urt.ur_pattern = patwhite;
  1177.     }
  1178.  
  1179.     for (i =0 ; i < hit1 ; i++) {
  1180.         urt.ur_srcy = ystart+i;
  1181.         urt.ur_dsty = i;
  1182.         ioctl( Wn, WIOCRASTOP, &urt ) ;}
  1183.  
  1184. }
  1185.  
  1186.  
  1187.  
  1188. /*
  1189. ** Restore the window to the saved size and state.
  1190. */
  1191.  
  1192. restore_window(restore)
  1193. int restore;
  1194. {
  1195.     int i;
  1196.     if (restore) {
  1197.       uw = Suw;
  1198.       ioctl( Wn, WIOCSETD, &uw );
  1199.         
  1200.       if (new_wind >= 0)
  1201.       wrastop(Wn, Bitmap, XMAXB, 0,0, 0,0, 0,0, XMAX, YMAX,
  1202.             SRCSRC, DSTSRC, 0 );
  1203.  
  1204.       /* position cursor and turn it on */
  1205.  
  1206.       fprintf(stderr, "\033[10;8H\033[=0C");
  1207.     }
  1208.  
  1209.     /*  restore USER  texts */
  1210.     for (i=0; i<6;i++) {
  1211.         sut[i].ut_num=i;
  1212.         ioctl(Wn,WIOCSETTEXT,&sut[i]);
  1213.     }
  1214.  
  1215.     if (restore) {
  1216.        if ( pid > 0 )
  1217.           kill(pid,9);
  1218.        kill(pppid,9);
  1219.        wexit( 0 );
  1220.     }
  1221. }
  1222.  
  1223.  
  1224.  
  1225. manage_window(ico, wid,com1)
  1226. unsigned short *ico;
  1227. int wid;
  1228. char **com1;
  1229. {
  1230.     int c,cc;
  1231.     int x,y,b,r,io,i;
  1232.     ppid = getpid();
  1233.     ioctl(Wn,TCGETA,&argg1);
  1234.     intsig =  signal ( SIGINT , sendit );
  1235.     quitsig=  signal ( SIGQUIT , sendit );
  1236.     (void) signal ( SIGTRAP , SIG_IGN );
  1237.     (void) signal ( SIGUSR2 , sendit );
  1238.  
  1239.  
  1240.     /* spawn a daemon process that would tell us
  1241.        if a CTRL-Z is caught
  1242.     */
  1243.  
  1244.     if ( (pppid =fork()) == 0 ) {
  1245.          (void) signal ( SIGUSR2 , closeit );
  1246.  
  1247.          /* It should have no control over the window */
  1248.  
  1249.          setpgrp();
  1250. loop:
  1251.          /* sleep until the window is opened */
  1252.  
  1253.          pause();
  1254.  
  1255.          /* take short naps until a suspend key is pressed */
  1256.  
  1257.          ioctl(0,TCGETA,&argg);
  1258.          while ( argg.c_cc[7] != 254 )  {
  1259.                sleep(1);
  1260.                ioctl(0,TCGETA,&argg);
  1261.          }
  1262.  
  1263.          /* tell the parent about it 
  1264.             and go back to sleep
  1265.          */
  1266.          argg.c_cc[7] = 0;
  1267.          ioctl(0,TCSETA,&argg);
  1268.          kill ( ppid , SIGUSR2 );
  1269.          goto loop;
  1270.     }
  1271.  
  1272.     /* the paraent should loop forever
  1273.     */
  1274.  
  1275.     for (;;)
  1276.     {
  1277.         if ( iconopen  ) {
  1278.           iconopen=0;
  1279.           c = F1;
  1280.         } else
  1281.            c = wgetc(Wn);
  1282.  
  1283.         ioctl( Wn, WIOCGETD, &suw );
  1284.         
  1285.         /* is it an exit command */
  1286.  
  1287.         if ( c == Exit || c == Cancl || c == s_Cancl || 
  1288.              c == F3 || c == F8 || c == EOF ) {
  1289.              if ( frk == 1 ) {
  1290.                 confirm();
  1291.                 iconify(ico,wid,XMAX1,YMAX1);
  1292.              }
  1293.         }
  1294.         else
  1295.         
  1296.         /* is it a scroll left command */
  1297.  
  1298.         if ( c == left ) {
  1299.             if ( xstart != 0 ) 
  1300.                  if ( (xstart - xdelta ) > 0 ) 
  1301.                       {xstart = xstart - xdelta; } else
  1302.                  xstart =0;
  1303.         iconify(ico,wid,XMAX1,YMAX1);
  1304.         } else
  1305.  
  1306.         
  1307.         /* is it a scroll right command */
  1308.  
  1309.         if ( c == right )  {
  1310.            if ((xstart + xdelta + XMAX1) < width ) {
  1311.                xstart = xstart + xdelta; }
  1312.            else
  1313.                xstart = width - XMAX1;
  1314.         iconify(ico,wid,XMAX1,YMAX1);
  1315.         } else
  1316.                 
  1317.         
  1318.         /* is it a scroll down command */
  1319.  
  1320.         if ( c == down ){
  1321.             if ( ystart != 0 ) 
  1322.                  if ( (ystart - ydelta ) > 0 )
  1323.                       {ystart = ystart - ydelta; } else
  1324.                   ystart =0;
  1325.         iconify(ico,wid,XMAX1,YMAX1);
  1326.         } else
  1327.                
  1328.         
  1329.         /* is it a scroll up command */
  1330.  
  1331.         if ( c == up ){
  1332.            if ((ystart + ydelta + YMAX1) < height ) 
  1333.               { ystart = ystart + ydelta; }
  1334.            else
  1335.                ystart = height - YMAX1;
  1336.         iconify(ico,wid,XMAX1,YMAX1);
  1337.         } else
  1338.  
  1339.  
  1340.         if ( c == Mouse || c == F1 || c == F2 || c == F6 || c == F7) {
  1341.           b=0;
  1342.           if ( c == Mouse )
  1343.              wreadmouse(Wn,&x,&y,&b,&r);
  1344.         
  1345.           /* is it open or resume command */
  1346.  
  1347.           if ( b == 4 || c == F1 || c == F6) {
  1348.              uw = Puw;
  1349.              ioctl( Wn, WIOCSETD, &uw );
  1350.              ioctl(Wn, WIOCSETMOUSE, &mouse1);
  1351.              if ( (new_wind >= 0) || (new_wind1 >= 0))
  1352.                 wrastop(Wn, Bitmap1, XMAXB, 0,0, 0,0, 0,0, XMAX
  1353.                                , YMAX, SRCSRC, DSTSRC, 0 );
  1354.              for ( i=0; i<6 ; i++) {
  1355.                  suti[i].ut_num=i;
  1356.                  ioctl(Wn,WIOCSETTEXT,&suti[i]);
  1357.              }
  1358.              fprintf(stderr, "\033[24;1H\033[=0C");
  1359.              /*fprintf(stderr, "\033[=0C");
  1360.              ioctl(0,LDSETT,argcb);*/
  1361.              if ( frk  == 1 ) {
  1362.  
  1363.                 /* execute the user command */
  1364.                 /* the suspend key sould be in effect */
  1365.  
  1366.                 argg.c_cc[7] = 253;
  1367.                 ioctl(0,TCSETA,&argg);
  1368.                 frk = 0;
  1369.                 if ( (pid=fork()) == 0 ) {
  1370.  
  1371.                    /* I should have no control over the window */
  1372.                    /* my parent should, Hmmmm  */
  1373.  
  1374.                    setpgrp();
  1375.                    
  1376.                    (void) signal ( SIGINT , intsig );
  1377.                    (void) signal ( SIGQUIT , quitsig );
  1378.                    (void) signal ( SIGUSR2 , SIG_IGN );
  1379.                    ptrace(0,0,0,0);
  1380.                    com1 +=optind;
  1381.                    execvp(com1[0],com1);
  1382.                    perror(com1[0]);
  1383.                    exit(2);
  1384.                  }
  1385.              } else {
  1386.                    argg2.c_cc[7] = 253;
  1387.                    ioctl(0,TCSETA,&argg2);
  1388.              }
  1389.  
  1390.              /* wakeup the daemon child */
  1391.  
  1392.              kill (pppid , SIGUSR2 );
  1393.  
  1394.              /* wakeup the executing child */
  1395.  
  1396.              if ( isig != 0 )
  1397.                 ptrace(7, pid ,1,0);
  1398. wait_it:
  1399.              /* uuuuh, it is my turn to sleep */
  1400.  
  1401.              if ((wait(&statch)) == -1 ) {
  1402.  
  1403.              /* uuuuh, what is this noise? */
  1404.  
  1405.                   goto wait_it;
  1406.              } else {
  1407.              if  ( (statch & 0xff) != 0x7f ) {
  1408.                  isig = 0;
  1409.                  pid = -1;
  1410.                  frk = 1; } 
  1411.               else {
  1412.                  isig = statch >> 8;  
  1413.                  if ( isig != SIGUSR2 ) {
  1414.  
  1415.                     /* wakeup son, it is no time to sleep */
  1416.  
  1417.                     ptrace(7,pid,1,isig);
  1418.                     goto wait_it;
  1419.                   }
  1420.               }
  1421.               }
  1422.  
  1423.              /* Oh, I'm late..
  1424.                 I should be working by now
  1425.              */
  1426.  
  1427.              ioctl(0,TCGETA,&argg2);
  1428.              ioctl( Wn, WIOCGETD, &Puw );
  1429.              for ( i=0; i<6 ; i++) {
  1430.                  suti[i].ut_num=i;
  1431.                  ioctl(Wn,WIOCGETTEXT,&suti[i]);
  1432.              }
  1433.              wcmd(Wn,0);
  1434.               
  1435.              /* set up function keys */
  1436.              if ( frk == 0 ) {
  1437.          wslk(Wn, 0, "  RESUME   TOGGLE                                    B1 TO    B2 TO",
  1438.             "           BORDER                                   RESUME    TOGGLE       "); } else
  1439.          wslk(Wn, 0, "   OPEN    TOGGLE   EXIT                             B1 TO    B2 TO    B3 TO",
  1440.             "           BORDER                                    OPEN     TOGGLE   EXIT");
  1441.              new_wind1 = wrastop(Wn, 0,0, Bitmap1, XMAXB, 0,0, 0,0, XMAX
  1442.                                , YMAX, SRCSRC, DSTSRC, 0 );
  1443.              ioctl(Wn,TCSETA,&argg1);
  1444.              keypad(0,1);
  1445.              ioctl(Wn, WIOCGETMOUSE, &mouse1);
  1446.              ioctl(Wn, WIOCSETMOUSE, &mouse);
  1447.              done = 0;
  1448.              bord_flag = 1;
  1449.              fprintf(stderr, "\033[=1C" );
  1450.              /*ioctl(0,LDGETT,argcb);*/
  1451.  
  1452.              iconify(ico,wid,XMAX1,YMAX1);
  1453.          
  1454.         } else
  1455.         
  1456.         /* is it toggle border command */
  1457.  
  1458.         if ( b == 2 || c == F2 || c == F7) {
  1459.             done = 0;
  1460.             if ( bord_flag )
  1461.                {bord_flag = 0;}
  1462.             else
  1463.                bord_flag = 1;
  1464.             iconify(ico,wid,XMAX1,YMAX1);
  1465.         } else
  1466.  
  1467.         if ( b == 1 )
  1468.         if ( frk == 1 ) {
  1469.              confirm();
  1470.              iconify(ico,wid,XMAX1,YMAX1);
  1471.        }
  1472.       }
  1473.  
  1474.            
  1475.     }
  1476. }
  1477.  
  1478.  
  1479. confirm()
  1480. {
  1481. int c,i,j,k,l;
  1482.  
  1483.    done=0;
  1484.    uw.uw_uflags = 0;
  1485.    uw.uw_height = 64;
  1486.    uw.uw_width = 140;
  1487.    ioctl( Wn, WIOCSETD, &uw );
  1488.    wlabel(Wn,"CONFIRM EXIT");
  1489.    wprompt(Wn,"Do you want to exit?             (Y/N  or  Enter/Cancel)");
  1490.    wcmd(Wn,"Touch Enter to continue          Cancel to STOP\n");
  1491.    c= wgetc(Wn);
  1492.    if( (c == Return) || (c == Enter) || 
  1493.        (c == 'y') || (c == 'Y') ) {
  1494.          wlabel(Wn,0);
  1495.          wprompt(Wn,0);
  1496.          wcmd(Wn,0);
  1497.          restore_window(1);
  1498.    }
  1499.    if (c == Mouse)
  1500.       wreadmouse(Wn,&i,&j,&k,&l);
  1501.       if ( k == 4 ) {
  1502.          wlabel(Wn,0);
  1503.          wprompt(Wn,0);
  1504.          wcmd(Wn,0);
  1505.          restore_window(1);
  1506.    }
  1507.    wlabel(Wn,0);
  1508.    wprompt(Wn,0);
  1509.    wcmd(Wn,0);
  1510. }
  1511.  
  1512.  
  1513. sendit(sig)
  1514. int sig;
  1515. {
  1516.     (void) signal ( sig , sendit );
  1517.     kill ( (0 - pid ) , sig );
  1518. }
  1519.  
  1520. closeit()
  1521. {
  1522.    (void) signal ( SIGUSR2 , closeit );
  1523. }
  1524. @//E*O*F tools.c//
  1525. chmod u=rw,g=r,o=r tools.c
  1526.  
  1527. exit 0
  1528.