home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / image / part01 / lowerbound / main.c++ next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.6 KB  |  61 lines

  1. /*
  2.     This applies an lower bound to a var file
  3.     The syntax is:
  4.     lowerbound bound [input.var [output.var]]
  5. */
  6. #include <stream.h>
  7. #include <stdio.h>
  8. #include <vartools.h++>
  9.  
  10.  
  11. int
  12. main ( int argc , char *argv[] )
  13.     {
  14.     switch(argc)
  15.     {
  16.     // with 1 argument it acts as a pipe
  17.     case 2:
  18.     lower_bound(atof(argv[1]),stdin,stdout,"Bounding file from stdin\n");
  19.     break;
  20.     // with 2 arguments it reads from specified file and writes to stdout
  21.     case 3:
  22.     FILE *input;
  23.     if(NULL == (input = fopen(argv[2],"r")))
  24.         {
  25.         perror(form("lowerbound problem with openning %s:",argv[2]));
  26.         return 5;
  27.         }
  28.     lower_bound(atof(argv[1]),input,stdout,form("bounding file %s\n",argv[2]));
  29.     break;
  30.     // with 3 arguments it reads from specified file and writes to 
  31.     // specified file
  32.     case 4:
  33.     FILE *input;
  34.     FILE *output;
  35.     if(NULL == (input = fopen(argv[2],"r")))
  36.         {
  37.         perror(form("lowerbound problem with openning %s:",argv[2]));
  38.         return 5;
  39.         }
  40.     if(NULL == (output = fopen(argv[3],"w")))
  41.         {
  42.         perror(form("lowerbound problem with openning %s:",argv[3]));
  43.         return 6;
  44.         }
  45.     lower_bound(atof(argv[1]),input,output,form("bounding file %s to file %s\n",argv[2],argv[3]));
  46.     break;
  47.     // otherwise wrong number of arguments failure!
  48.     default:
  49.     cerr << "Syntax is: lowerbound bound [input.var [output.var]]";
  50.     return 1;
  51.     break;
  52.     }
  53.     return 0;
  54.     }
  55. /*
  56. Copyright (C) 1986, David Sher in the University of Rochester
  57. Permission is granted to any individual or institution to use, copy, or
  58. redistribute this software so long as it is not sold for profit, provided
  59. this copyright notice is retained.
  60. */
  61.