home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / archie / part01 / archie.c next >
C/C++ Source or Header  |  1991-08-21  |  5KB  |  190 lines

  1. /*
  2.  * Copyright (c) 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <uw-copyright.h>.
  6.  */
  7.  
  8. #include <uw-copyright.h>
  9.  
  10. /*
  11.  * Archie client using the Prospero protocol
  12.  *
  13.  * Suggestions and improvements to Clifford Neuman (bcn@isi.edu)
  14.  */
  15.  
  16. #include <stdio.h>
  17.  
  18. #include <pfs.h>
  19. #include <rdgram.h>
  20. #include <archie.h>
  21.  
  22. int        listflag = 0;
  23. int        sortflag = 0;   /* 1 = by date                    */
  24. char        *progname;
  25. #ifdef DEBUG
  26. int            pfs_debug = 0;
  27. #endif
  28. extern int    rdgram_priority;
  29.  
  30. main(argc,argv)
  31.     int        argc;
  32.     char    *argv[];
  33.     {
  34.     char        *cur_arg;
  35.     char        qtype = '=';    /* Default to exact string match  */
  36.     char        etype = '=';    /* Type if only -e is specified   */
  37.     int        eflag = 0;    /* Exact flag specified          */
  38.     int        max_hits = MAX_HITS;
  39.     int        offset = 0;
  40.     int        versionflag = 0;/* Display release identifier     */
  41.     int        tmp;
  42.     char        *host = ARCHIE_HOST;
  43.  
  44.     int        sort_ins_link(), display_link();
  45.  
  46.     progname = *argv;
  47.     argc--;argv++;
  48.  
  49.     while (argc > 0 && **argv == '-') {
  50.         cur_arg = argv[0]+1;
  51.  
  52.         /* If a - by itself, or --, then no more arguments */
  53.         if(!*cur_arg || ((*cur_arg == '-') && (!*(cur_arg+1)))) {
  54.             argc--, argv++;
  55.         goto scandone;
  56.         }
  57.  
  58.         while (*cur_arg) {
  59.         switch (*cur_arg++) {
  60. #ifdef DEBUG        
  61.         case 'D':  /* Debug level */
  62.             pfs_debug = 1; /* Default debug level */
  63.             if(*cur_arg && index("0123456789",*cur_arg)) {
  64.             sscanf(cur_arg,"%d",&pfs_debug);
  65.             cur_arg += strspn(cur_arg,"0123456789");
  66.             }
  67.             else if(argc > 2) {
  68.                 tmp = sscanf(argv[1],"%d",&pfs_debug);
  69.             if (tmp == 1) {argc--;argv++;}
  70.             }
  71.             break;
  72. #endif
  73.         case 'N':  /* Priority (nice) */
  74.             rdgram_priority = RDGRAM_MAX_PRI; /* Use this if no # */
  75.             if(*cur_arg && index("-0123456789",*cur_arg)) {
  76.             sscanf(cur_arg,"%d",&rdgram_priority);
  77.             cur_arg += strspn(cur_arg,"-0123456789");
  78.             }
  79.             else if(argc > 2) {
  80.                 tmp = sscanf(argv[1],"%d",&rdgram_priority);
  81.             if (tmp == 1) {argc--;argv++;}
  82.             }
  83.             if(rdgram_priority > RDGRAM_MAX_SPRI) 
  84.             rdgram_priority = RDGRAM_MAX_PRI;
  85.             if(rdgram_priority < RDGRAM_MIN_PRI) 
  86.             rdgram_priority = RDGRAM_MIN_PRI;
  87.               break;
  88.  
  89.         case 'c':  /* substring (case sensitive) */
  90.             qtype = 'C';
  91.             etype = 'c';
  92.             break;
  93.  
  94.         case 'e':  /* Exact match */
  95.             /* If -e specified by itself, then we use the  */
  96.             /* default value of etype which must be '='    */
  97.             eflag++;
  98.             break;
  99.  
  100.         case 'h':  /* Host */
  101.             host = argv[1];
  102.             argc--;argv++;
  103.             break;
  104.  
  105.         case 'l':  /* List one match per line */
  106.             listflag++;
  107.             break;
  108.  
  109.         case 'm':  /* Max hits */
  110.             max_hits = -1;  
  111.             if(*cur_arg && index("0123456789",*cur_arg)) {
  112.             sscanf(cur_arg,"%d",&max_hits);
  113.             cur_arg += strspn(cur_arg,"0123456789");
  114.             }
  115.             else if(argc > 1) {
  116.                 tmp = sscanf(argv[1],"%d",&max_hits);
  117.             if (tmp == 1) {argc--;argv++;}
  118.             }
  119.             if (max_hits < 1) {
  120.             fprintf(stderr, "%s: -m option requires a value for max hits (>= 1)\n",
  121.                 progname);
  122.             exit(1);
  123.             }
  124.             break;
  125.  
  126.         case 'o':  /* Offset */
  127.             if(argc > 1) {
  128.               tmp = sscanf(argv[1],"%d",&offset);
  129.               if (tmp != 1)
  130.             argc = -1;
  131.               else {
  132.             argc--;argv++;
  133.               }
  134.             }
  135.             break;
  136.  
  137.         case 'r':  /* Regular expression search */
  138.             qtype = 'R';
  139.             etype = 'r';
  140.             break;
  141.  
  142.         case 's':  /* substring (case insensitive) */
  143.             qtype = 'S';
  144.             etype = 's';
  145.             break;
  146.  
  147.         case 't':  /* Sort inverted by date */
  148.             sortflag = 1;
  149.             break;
  150.  
  151.         case 'v':  /* Display version */
  152.             fprintf(stderr,
  153.             "Client version %s based upon Prospero version %s\n",
  154.                 CLIENT_VERSION, PFS_RELEASE);
  155.             versionflag++;
  156.             break;
  157.  
  158.         default:
  159.             fprintf(stderr,"Usage: %s [-[cers][l][t][m #][h host][N#]] string\n", progname);
  160.             exit(1);
  161.         }
  162.         }
  163.         argc--, argv++;
  164.     }
  165.  
  166.       scandone:
  167.  
  168.     if (eflag) qtype = etype;
  169.  
  170.     if ((argc != 1) && versionflag) exit(0);
  171.  
  172.     if (argc != 1) {
  173.         fprintf(stderr, "Usage: %s [-[cers][l][t][m #][h host][N#]] string\n", progname);
  174.         fprintf(stderr,"       -c : case sensitive substring search\n");
  175.         fprintf(stderr,"       -e : exact string match (default)\n");
  176.         fprintf(stderr,"       -r : regular expression search\n");
  177.         fprintf(stderr,"       -s : case insensitive substring search\n");
  178.         fprintf(stderr,"       -l : list one match per line\n");
  179.         fprintf(stderr,"       -t : sort inverted by date\n");
  180.         fprintf(stderr,"     -m # : specifies maximum number of hits to return (default %d)\n", max_hits);
  181.         fprintf(stderr,"  -h host : specifies server host\n");
  182.         fprintf(stderr,"      -N# : specifies query niceness level (0-35765)\n");
  183.         exit(1);
  184.     }
  185.  
  186.     procquery(host, argv[0], max_hits, offset, qtype, sortflag, listflag);
  187.  
  188.     exit(0);
  189.     }
  190.