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

  1. /*
  2.  * procquery.c : Routines for processing results from Archie
  3.  *
  4.  * Originally part of the Prospero Archie client by Cliff Neuman (bcn@isi.edu).
  5.  * Modified by Brendan Kehoe (brendan@cs.widener.edu).
  6.  * Re-modified by George Ferguson (ferguson@cs.rochester.edu).
  7.  *
  8.  * Copyright (c) 1991 by the University of Washington
  9.  *
  10.  * For copying and distribution information, please see the file
  11.  * <uw-copyright.h>.
  12.  *
  13.  * v1.1.1 - bpk 08/20/91 - took out archie_query from error msg
  14.  */
  15. #include <uw-copyright.h>
  16. #include <stdio.h>
  17. #include <pfs.h>
  18. #include <perrno.h>
  19. #include <pmachine.h>
  20. #include <archie.h>
  21. #ifdef AUX
  22. # include <time.h>
  23. #else
  24. # include <sys/time.h>
  25. #endif
  26. extern int client_dirsrv_timeout,client_dirsrv_retry;    /* dirsend.c */
  27. extern char *progname;
  28.  
  29.  
  30. /*
  31.  * Functions defined here
  32.  */
  33. void display_link(), procquery();
  34.  
  35. /*
  36.  * Data defined here
  37.  */
  38. int perrno, pfs_debug;
  39. static struct tm *presenttime;
  40.  
  41. /*    -    -    -    -    -    -    -    -    */
  42. /*
  43.  * display_link : Prints the contents of the given virtual link. If
  44.  *    listflag is 0, then this uses static variables to save state
  45.  *    between calls for a less verbose output. If listflag is non-zero
  46.  *    then all information is printed every time.
  47.  */
  48. void
  49. display_link(l,listflag)
  50. VLINK l;
  51. int listflag;
  52. {
  53.     static char    lastpath[MAX_VPATH] = "\001";
  54.     static char    lasthost[MAX_VPATH] = "\001";
  55.  
  56.     PATTRIB     ap;
  57.     char    linkpath[MAX_VPATH];
  58.     int        dirflag = 0;
  59.     int        size = 0;
  60.     char    *modes = "";
  61.     char    archie_date[20];
  62.     char    *gt_date = "";
  63.     int        gt_year = 0;
  64.     int        gt_mon = 0;
  65.     int        gt_day = 0;
  66.     int        gt_hour = 0;
  67.     int        gt_min = 0;
  68.     
  69.     /* Initialize local buffers */
  70.     *archie_date = '\0';
  71.  
  72.     /* Remember if we're looking at a directory */
  73.     if (sindex(l->type,"DIRECTORY"))
  74.     dirflag = 1;
  75.     else
  76.     dirflag = 0;
  77.     
  78.     /* Extract the linkpath from the filename */
  79.     strcpy(linkpath,l->filename);
  80.     *(linkpath + (strlen(linkpath) - strlen(l->name) - 1)) = '\0';
  81.     
  82.     /* Is this a new host? */
  83.     if (strcmp(l->host,lasthost) != 0) {
  84.     if (!listflag)
  85.         printf("\nHost %s\n\n",l->host);
  86.     strcpy(lasthost,l->host);
  87.     *lastpath = '\001';
  88.     }
  89.     
  90.     /* Is this a new linkpath (location)? */
  91.     if(strcmp(linkpath,lastpath) != 0) {
  92.     if (!listflag)
  93.         printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
  94.     strcpy(lastpath,linkpath);
  95.     }
  96.     
  97.     /* Parse the attibutes of this link */
  98.     for (ap = l->lattrib; ap; ap = ap->next) {
  99.     if (strcmp(ap->aname,"SIZE") == 0) {
  100.         sscanf(ap->value.ascii,"%d",&size);
  101.     } else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
  102.         modes = ap->value.ascii;
  103.     } else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
  104.         gt_date = ap->value.ascii;
  105.         sscanf(gt_date,"%4d%2d%2d%2d%2d",>_year,
  106.            >_mon, >_day, >_hour, >_min);
  107.         if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
  108.                     presenttime->tm_mon - gt_mon) > 6) 
  109.         sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
  110.             gt_day, gt_year);
  111.         else
  112.         sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
  113.              gt_day, gt_hour, gt_min);
  114.     }
  115.     }
  116.     
  117.     /* Print this link's information */
  118.     if (listflag)
  119.     printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
  120.                             (dirflag ? "/" : ""));
  121.     else
  122.     printf("      %9s %s %10d  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  123.                     modes,size,archie_date,l->name);
  124.  
  125.     /* Free the attibutes */
  126.     atlfree(l->lattrib);
  127.     l->lattrib = NULL;
  128. }
  129.  
  130. /*    -    -    -    -    -    -    -    -    */
  131. /*
  132.  * procquery : Process the given query and display the results. If
  133.  *    sortflag is non-zero, then the results are sorted by increasing
  134.  *    date, else by host/filename. If listflag is non-zero then each
  135.  *    entry is printed on a separate, complete line. Note that listflag
  136.  *    is ignored by xarchie.
  137.  */
  138. void
  139. procquery(host,str,max_hits,offset,query_type,sortflag,listflag)
  140. char *host,*str;
  141. int max_hits,offset;
  142. char query_type;
  143. int sortflag,listflag;
  144. {
  145.     VLINK l;
  146.     long now;
  147.     extern int rdgram_priority;
  148.  
  149.     /* initialize data structures for this query */
  150.     (void)time(&now);
  151.     presenttime = localtime(&now);
  152.  
  153.     /* Do the query */
  154.     if (sortflag == 1)
  155.     l = archie_query(host,str,max_hits,offset,query_type,AQ_INVDATECMP,0);
  156.     else
  157.     l = archie_query(host,str,max_hits,offset,query_type,NULL,0);
  158.  
  159.     /* Error? */
  160.     if (perrno != PSUCCESS) {
  161.     if (*p_err_string)
  162.       fprintf(stderr, "%s: failed: %s - %s\n", progname,
  163.           p_err_text[perrno], p_err_string);
  164.     else
  165.       fprintf(stderr, "%s failed: %s\n", progname, p_err_text[perrno]);
  166.     }
  167.  
  168.     /* Display the results */
  169.     while (l != NULL) {
  170.     display_link(l,listflag);
  171.     l = l->next;
  172.     }
  173. }
  174.