home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / 3b1tools next >
Encoding:
Internet Message Format  |  1991-08-27  |  41.8 KB

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