home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / C_ARCHI1.TAR / archie / archie.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-20  |  5.7 KB  |  227 lines

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