home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / logo / patch01 / logo.c next >
Encoding:
C/C++ Source or Header  |  1987-07-06  |  3.5 KB  |  157 lines

  1.  
  2. /* Parent process which sets up windows and calls logo itself
  3.  * Ttysw insists on forking, so we need two processes
  4.  * Written by Philippe Lacroute at Sun Microsystems Inc. 1983
  5.  */
  6.  
  7. /*
  8.  * Modified April 1985 for Sun release 2.0 software (PGL)
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <suntool/tool_hs.h>
  13. #include <suntool/ttysw.h>
  14. #include <suntool/emptysw.h>
  15.  
  16. #define LOGOBIN        "logo"
  17.  
  18. struct tool    *tool;
  19. struct toolsw    *ttysw,        /* tty subwindow */
  20.         *gfxsw;        /* to be overlaid with blanket */
  21.  
  22. static short icon_data[256] = {
  23. #include "logo.icon"
  24. };
  25.  
  26. mpr_static(turtle_pr, 64, 64, 1, icon_data);    /* icon */
  27. static struct icon    turtle_icon  =  {
  28.     TOOL_ICONWIDTH, TOOL_ICONHEIGHT, NULL,
  29.     {0, 0, TOOL_ICONWIDTH, TOOL_ICONHEIGHT},
  30.     &turtle_pr, {0, 0, 0, 0}, NULL, NULL, 0
  31. };
  32. static int        sigwinchcatcher(),
  33.             sigchldcatcher(),
  34.             mytoolsigwinchhandler(),
  35.             (*toolsigwinchhandlercached)();
  36. char            tool_name[] = "Sun Logo 2.0",
  37.             name[WIN_NAMESIZE];
  38. int pidchld = -1, killchild();
  39.  
  40. main(argc, argv)
  41. int argc;
  42. char *argv[];
  43. {
  44.     char **tool_attrs = NULL;
  45.     struct rect winsize;
  46.     char *newargv[512];
  47.     int c;
  48.  
  49.     if (tool_parse_all(&argc, argv, &tool_attrs, tool_name) == -1) {
  50.         tool_usage(tool_name);
  51.         exit(1);
  52.     }
  53.     tool = tool_make(WIN_NAME_STRIPE, 1,
  54.             WIN_LABEL, tool_name,
  55.             WIN_ICON, &turtle_icon, 0);
  56.     if (tool == NULL) {
  57.         fprintf(stderr, "Couldn't create tool.\n");
  58.         fprintf(stderr, "Are you running suntools?\n");
  59.         exit(1);
  60.     }
  61.     tool_free_attribute_list(tool_attrs);
  62.  
  63.     toolsigwinchhandlercached = tool->tl_io.tio_handlesigwinch;
  64.     tool->tl_io.tio_handlesigwinch = mytoolsigwinchhandler;
  65.     win_getrect(tool->tl_windowfd, &winsize);
  66.  
  67.     ttysw = ttysw_createtoolsubwindow(tool, "ttysw",
  68.         winsize.r_width - 2 * tool_borderwidth(tool),
  69.         winsize.r_height - tool_borderwidth(tool) - tool_stripeheight(tool));
  70.     gfxsw = esw_createtoolsubwindow(tool, "gfxsw",
  71.         winsize.r_width - 2 * tool_borderwidth(tool),
  72.         winsize.r_height - tool_borderwidth(tool) - tool_stripeheight(tool));
  73.  
  74.     /* Gfxsw must be on the bottom of tree */
  75.  
  76.     win_remove(gfxsw->ts_windowfd);
  77.     win_setlink(gfxsw->ts_windowfd, WL_YOUNGERSIB, win_fdtonumber(ttysw->ts_windowfd));
  78.     win_setlink(gfxsw->ts_windowfd, WL_OLDERSIB, WIN_NULLLINK);
  79.     win_insert(gfxsw->ts_windowfd);
  80.  
  81.     /* set environmanet vars */
  82.  
  83.     win_fdtoname(tool->tl_windowfd, name);
  84.     setenv("LOGO_TOOL", name);
  85.     win_fdtoname(ttysw->ts_windowfd, name);
  86.     setenv("LOGO_TEXT", name);
  87.     win_fdtoname(gfxsw->ts_windowfd, name);
  88.     setenv("LOGO_GFX", name);
  89.  
  90.     /* set signals */
  91.  
  92.     signal(SIGWINCH, sigwinchcatcher);
  93.     signal(SIGCHLD, sigchldcatcher);
  94.     signal(SIGINT, SIG_IGN);
  95.     signal(SIGQUIT, SIG_IGN);
  96.  
  97.     newargv[0] = LOGOBIN;
  98.     for (c = 1; c < argc; c++)
  99.         newargv[c] = argv[c];
  100.     argv[c] = 0;
  101.  
  102.     /* install everything */
  103.  
  104.     tool_install(tool);
  105.     if ((pidchld = ttysw_fork(ttysw->ts_data, newargv, &ttysw->ts_io.tio_inputmask,
  106.         &ttysw->ts_io.tio_outputmask, &ttysw->ts_io.tio_exceptmask)) == -1) {
  107.             perror("logotool");
  108.         exit(1);
  109.     }
  110.  
  111.     /* run the ttysw */
  112.  
  113.     tool_select(tool, 1);    /* 1 child to wait for */
  114.  
  115.     /* clean up */
  116.  
  117.     tool_destroy(tool);
  118.     exit(0);
  119. }
  120.  
  121. static
  122. sigchldcatcher()
  123. {
  124.     tool_sigchld(tool);
  125. }
  126.  
  127. static
  128. sigwinchcatcher()
  129. {
  130.     tool_sigwinch(tool);
  131.     if (pidchld != -1)
  132.         kill(pidchld, SIGWINCH);
  133. }
  134.  
  135. nullfunc()
  136. {
  137. }
  138.  
  139. /*
  140.    toolsigwinchhandlercached will rearrange windows when it
  141.    detects that its size has changed.  The following procedure
  142.    fools toolsigwinchhandlercached into thinking that there
  143.    has been no change. 
  144.  */
  145.  
  146. static int
  147. mytoolsigwinchhandler(tool)
  148.     struct  tool *tool;
  149. {
  150.     struct  rect rect;
  151.  
  152.     win_getsize(tool->tl_windowfd, &rect);
  153.     tool->tl_rectcache = rect;
  154.     toolsigwinchhandlercached(tool);
  155. }
  156.  
  157.