home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume1 / 8711 / 3 / startmgr.c < prev   
C/C++ Source or Header  |  1990-07-13  |  3KB  |  112 lines

  1. /*    startmgr:  Create a one-line window on the top line of the Unix-PC
  2.     (7300/3B1) screen and start a program running in that window.
  3.     Declare this window to be the Window Manager, which gives it control
  4.     over the Suspend, Resume and Print keys.  This is meant to be used to
  5.     start newmgr, but can probably be adapted to be a fairly generic program
  6.     starter.  It was designed to mimic the observed operation of things like
  7.     cron, smgr, etc.
  8.  
  9.     This software is Copyright (c) 1987 by Scott Hazen Mueller.
  10.  
  11.     Permission is hereby granted to copy, reproduce, redistribute or
  12.     otherwise use this software as long as: there is no monetary
  13.     profit gained specifically from the use or reproduction or this
  14.     software, it is not sold, rented, traded or otherwise marketed, and
  15.     this copyright notice is included prominently in any copy
  16.     made.
  17.  
  18.     The author make no claims as to the fitness or correctness of
  19.     this software for any use whatsoever, and it is provided as is. 
  20.     Any use of this software is at the user's own risk.
  21.  
  22.     (Copyright notice courtesy of News 2.11 :-)
  23.  
  24.     Additionally:  you break it, you bought it.  I've listed the problems
  25.     that I know of in comments in the code; if you come up with fixes, I'd
  26.     like to see them, but I'm not planning on supporting anything.  It's
  27.     "good enough"; that's all that I'm looking for.    */
  28.  
  29. #include    <stdio.h>
  30. #include    <sys/types.h>
  31. #include    <wind.h>
  32. #include    <sys/window.h>
  33. #include    <fcntl.h>
  34. #include    <termio.h>
  35.  
  36. /*    Parameters defining the window and the program for that window.  You'll
  37.     almost certainly have to change barprog to correspond with whatever
  38.     directory you use for your local stuff.
  39.  
  40.     Note:  WFLAGS was determined empirically, by looking at the flags for
  41.     the AT&T-supplied smgr window.  No guarantees here.    */
  42.  
  43. #define        BARPROG        "/usr/local/newmgr"
  44. #define        WXSTART        0
  45. #define        WYSTART        0
  46. #define        WWIDTH        720
  47. #define        WHEIGHT        12
  48. #define        WFLAGS        257
  49.  
  50. main()
  51. {
  52. int    wd, dummy;
  53. struct uwdata winbar;
  54. struct utdata winname;
  55. struct termio bartty;
  56.  
  57. winbar.uw_x = WXSTART;
  58. winbar.uw_y = WYSTART;
  59. winbar.uw_width = WWIDTH;
  60. winbar.uw_height = WHEIGHT;
  61. winbar.uw_uflags = WFLAGS;
  62. winname.ut_num = WTXTUSER;
  63.  
  64. strcpy( winname.ut_text, "Invisible" );
  65. if ( fork() )
  66.     exit( 0 );
  67. else {
  68.  
  69. /*    Setpgrp() cannot be called from processes associated with windows.
  70.     From the manual.  Since it's a cleaner model for the parent to redirect
  71.     the child's stdin, stdout and stderr, we do that.  We have to setpgrp(),
  72.     or else the child would be killed when the process group leader exited.    */
  73.  
  74.     fclose( stdin );
  75.     fclose( stdout );
  76.     fclose( stderr );
  77.     setpgrp();
  78.  
  79. /*    Get a window, and set it up according to our parameters.  Since stdin
  80.     was closed above, wd gets to be stdin (roughly).    */
  81.  
  82.     wd = open( "/dev/window", O_RDWR|O_EXCL, 0 );
  83.     ioctl( wd, WIOCSETD, &winbar );
  84.     ioctl( wd, WIOCSETTEXT, &winname );
  85.     ioctl( wd, WIOCSYS, SYSWMGR );
  86.  
  87. /*    Set up the child's stdout and stderr to point at the window.    */
  88.  
  89.     dup( wd );
  90.     dup( wd );
  91.  
  92. /*    Set terminal parameters; after all, we'll want to read escape codes and
  93.     other neat stuff.    */
  94.  
  95.     ioctl( wd, TCGETA, &bartty );
  96.     bartty.c_iflag &= ~IGNBRK;
  97.     bartty.c_lflag &= ~( ICANON | ECHO );
  98.  
  99. /*    Read three characters at a time; 1 second timeout interval.  Whether
  100.     this really does anything, I don't know.    */
  101.  
  102.     bartty.c_cc[4] = 3;
  103.     bartty.c_cc[5] = 10;
  104.     ioctl( wd, TCSETA, &bartty );
  105.     
  106. /*    Execute with no command line arguments.    */
  107.  
  108.     execl( BARPROG, BARPROG, 0 );
  109.     }
  110. }
  111.  
  112.