home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / atap.c / streams.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-04  |  1.4 KB  |  82 lines

  1.  
  2. #include <stdio.h>
  3. #include <sys/stropts.h> 
  4.  
  5. #ifndef lint
  6. static    char sccsid[] = "@(#)streams.c    1.25 5/8/93";
  7. #endif
  8.  
  9. int silence = 0;
  10.  
  11. pop(fd,namewanted)
  12. char *namewanted;
  13. {
  14.     char name[64];
  15.  
  16.     if(ioctl(fd, I_LOOK, name) != -1) {
  17.         if(!strcmp(name,namewanted)){
  18.             if(!silence)
  19.                 (void)fprintf(stderr,"popping module: %s\n", name);
  20.             if(ioctl(fd,I_POP,0) == -1)
  21.                 if(!silence)
  22.                     perror("ioctl I_POP");
  23.         }else{
  24.  
  25.             if(!silence)
  26.                 (void)fprintf(stderr,
  27.                 "module %s not pop,module %s is on stack top\n",
  28.                 namewanted,name);
  29.         }
  30.     } else {
  31.         if(!silence)
  32.             (void)fprintf(stderr,"no module on stack\n");
  33.     }
  34. }
  35.  
  36. push(fd,name)
  37. char *name;
  38. {
  39.     int r;
  40.  
  41.     if(!silence)
  42.         (void)fprintf(stderr,"pushing module: %s\n", name);
  43.     if ((r=ioctl(fd, I_PUSH, name)) < 0) 
  44.         if(!silence)
  45.             perror(name);
  46. }
  47.  
  48. main(argc, argv)
  49. int argc;
  50. char **argv;
  51. {
  52.     int c,errflg=0;
  53.     extern char *optarg;
  54.     extern int optind;
  55.  
  56.     while ((c = getopt(argc, argv, "so:u:")) != -1){
  57.         switch (c) {
  58.         case 'o':
  59.             pop(0,optarg);
  60.             break;
  61.         case 'u':
  62.             push(0,optarg);
  63.             break;
  64.         case 's':
  65.             silence = ~silence;
  66.             break;
  67.         case '?':
  68.         default:
  69.             errflg++;
  70.         }
  71.     }
  72.     if (errflg||optind!=argc||argc==1) {
  73.         (void)fprintf(stderr, 
  74.             "Usage: %s [-s] [-o module-to-pop] [-u module-to-push] ...\n",
  75.             argv[0]);
  76.         (void)fprintf(stderr,
  77.             "       the order of all options is important\n");
  78.         exit (2);
  79.     }
  80.     return(0);
  81. }
  82.