home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part1 / flagsetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.1 KB  |  80 lines

  1. # include       "sps.h"
  2. # include       "flags.h"
  3. # include       <h/tty.h>
  4.  
  5. /*
  6. ** FLAGSETUP - Replaces any users or processes specified by flagdecode()
  7. ** with numerical equivalents. The lists are terminated by negative values.
  8. ** or null pointers. Ttystatus() must have been previously called to
  9. ** initialise the Info structure with chaos tty values.
  10. */
  11. flagsetup ()
  12. {
  13.     register union flaglist *fp ;
  14.     register char           *chp ;
  15.     register int            i ;
  16.     register struct ttyline *lp ;
  17.     int                     found ;
  18.     extern struct flags     Flg ;
  19.     extern struct info      Info ;
  20.  
  21.     /* Look for specified users */
  22.     if ( Flg.flg_U )                
  23.     {
  24.         if ( !Flg.flg_Ulist->f_chp )
  25.             prexit( "sps - User name was expected after -u flag\n");
  26.         for ( fp = Flg.flg_Ulist ; chp = fp->f_chp ; fp++ )
  27.         {
  28.             found = 0 ;
  29.             for ( i = 0 ; i < MAXUSERID ; i++ )
  30.                 if ( !strncmp( chp, Info.i_hnames[i].h_uname,
  31.                     UNAMELEN ) )
  32.                 {
  33.                     fp->f_uid = Info.i_hnames[i].h_uid ;
  34.                     found = 1 ;
  35.                     break ;
  36.                 }
  37.             if ( !found )
  38.                 prexit( "sps - Unknown user: %s\n", chp ) ;
  39.         }
  40.         fp->f_uid = -1 ;
  41.     }
  42.     /* Look for specified process ids */
  43.     if ( Flg.flg_P )                
  44.     {
  45.         if ( !Flg.flg_Plist->f_chp )
  46.             prexit(
  47.                  "sps - Process id was expected after -p flag\n" ) ;
  48.         for ( fp = Flg.flg_Plist ; chp = fp->f_chp ; fp++ )
  49.         {
  50.             if ( chp[0] < '0' || chp[0] > '9' )
  51.                 prexit( "sps - Bad process id: %s\n", chp ) ;
  52.             fp->f_pid = atoi( chp ) ;
  53.         }
  54.         fp->f_pid = -1 ;
  55.     }
  56.     /* Look for specified ttys */
  57.     if ( !Flg.flg_T )               
  58.         return ;
  59.     if ( !Flg.flg_Tlist->f_chp )
  60.         prexit( "sps - Tty name was expected after -t flag\n" ) ;
  61.     for ( fp = Flg.flg_Tlist ; chp = fp->f_chp ; fp++ )
  62.     {       /* Under VMUNIX, all ttys have two character names.
  63.            Thus, a flag of the form `t 8' should be expanded to
  64.            become `t 08'. */
  65.         if ( !chp[1] )
  66.             chp[1] = chp[0], chp[0] = '0' ;
  67.         found = 0 ;
  68.         for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
  69.             if ( !strncmp( chp, lp->l_name, 2 ) )
  70.             {
  71.                 fp->f_ttyline = lp ;
  72.                 found = 1 ;
  73.                 break ;
  74.             }
  75.         if ( !found )
  76.             prexit( "sps - Unknown tty name: %.2s\n", chp ) ;
  77.     }
  78.     fp->f_ttyline = (struct ttyline*)0 ;
  79. }
  80.