home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / C_ARCHI2.TAR / archie-1.3.2 / procquery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-05  |  5.4 KB  |  223 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.  * <copyright.h>.
  12.  *
  13.  */
  14.  
  15. #include <copyright.h>
  16. #include <stdio.h>
  17. #include <pfs.h>
  18. #include <perrno.h>
  19. #include <pmachine.h>
  20. #include <archie.h>
  21.  
  22. #ifdef NEED_TIME_H
  23. # include <time.h>
  24. #else
  25. # ifndef VMS
  26. #  include <sys/time.h>
  27. # endif
  28. #endif
  29.  
  30. extern int client_dirsrv_timeout,client_dirsrv_retry;    /* dirsend.c */
  31. extern char *progname;
  32.  
  33.  
  34. /*
  35.  * Functions defined here
  36.  */
  37. void display_link(), procquery();
  38.  
  39. /*
  40.  * Data defined here
  41.  */
  42. extern int pwarn, perrno;
  43. #ifdef DEBUG
  44. int pfs_debug;
  45. #endif
  46. static struct tm *presenttime;
  47. static char lastpath[MAX_VPATH] = "\001";
  48. static char lasthost[MAX_VPATH] = "\001";
  49.  
  50. /*    -    -    -    -    -    -    -    -    */
  51. /*
  52.  * display_link : Prints the contents of the given virtual link. If
  53.  *    listflag is 0, then this uses last{host,path} to save state
  54.  *    between calls for a less verbose output. If listflag is non-zero
  55.  *    then all information is printed every time.
  56.  */
  57. void
  58. display_link(l,listflag)
  59. VLINK l;
  60. int listflag;
  61. {
  62.     PATTRIB     ap;
  63.     char    linkpath[MAX_VPATH];
  64.     int        dirflag = 0;
  65. #ifdef MSDOS
  66.     unsigned long size = 0L;
  67. #else
  68.     int        size = 0;
  69. #endif
  70.     char    *modes = "";
  71.     char    archie_date[20];
  72.     char    *gt_date = "";
  73.     int        gt_year = 0;
  74.     int        gt_mon = 0;
  75.     int        gt_day = 0;
  76.     int        gt_hour = 0;
  77.     int        gt_min = 0;
  78.     
  79.     /* Initialize local buffers */
  80.     *archie_date = '\0';
  81.  
  82.     /* Remember if we're looking at a directory */
  83.     if (sindex(l->type,"DIRECTORY"))
  84.     dirflag = 1;
  85.     else
  86.     dirflag = 0;
  87.     
  88.     /* Extract the linkpath from the filename */
  89.     strcpy(linkpath,l->filename);
  90.     *(linkpath + (strlen(linkpath) - strlen(l->name) - 1)) = '\0';
  91.     
  92.     /* Is this a new host? */
  93.     if (strcmp(l->host,lasthost) != 0) {
  94.     if (!listflag)
  95.         printf("\nHost %s\n\n",l->host);
  96.     strcpy(lasthost,l->host);
  97.     *lastpath = '\001';
  98.     }
  99.     
  100.     /* Is this a new linkpath (location)? */
  101.     if(strcmp(linkpath,lastpath) != 0) {
  102.     if (!listflag)
  103.         printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
  104.     strcpy(lastpath,linkpath);
  105.     }
  106.     
  107.     /* Parse the attibutes of this link */
  108.     for (ap = l->lattrib; ap; ap = ap->next) {
  109.     if (strcmp(ap->aname,"SIZE") == 0) {
  110. #ifdef MSDOS
  111.         sscanf(ap->value.ascii,"%lu",&size);
  112. #else
  113.         sscanf(ap->value.ascii,"%d",&size);
  114. #endif
  115.     } else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
  116.         modes = ap->value.ascii;
  117.     } else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
  118.         gt_date = ap->value.ascii;
  119.         sscanf(gt_date,"%4d%2d%2d%2d%2d",>_year,
  120.            >_mon, >_day, >_hour, >_min);
  121.         if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
  122.                     presenttime->tm_mon - gt_mon) > 6) 
  123.         sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
  124.             gt_day, gt_year);
  125.         else
  126.         sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
  127.              gt_day, gt_hour, gt_min);
  128.     }
  129.     }
  130.     
  131.     /* Print this link's information */
  132.     if (listflag)
  133. #if defined(MSDOS)
  134.     printf("%s %6lu %s %s%s\n",gt_date,size,l->host,l->filename,
  135.            (dirflag ? "/" : ""));
  136. #else
  137.     printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
  138.            (dirflag ? "/" : ""));
  139. #endif
  140.     else
  141. #ifdef MSDOS
  142.     printf("      %9s %s %10lu  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  143.                     modes,size,archie_date,l->name);
  144. #else
  145.     printf("      %9s %s %10d  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  146.                     modes,size,archie_date,l->name);
  147. #endif /* MSDOS */
  148.  
  149.  
  150.     /* Free the attibutes */
  151.     atlfree(l->lattrib);
  152.     l->lattrib = NULL;
  153. }
  154.  
  155. /*    -    -    -    -    -    -    -    -    */
  156. /*
  157.  * procquery : Process the given query and display the results. If
  158.  *    sortflag is non-zero, then the results are sorted by increasing
  159.  *    date, else by host/filename. If listflag is non-zero then each
  160.  *    entry is printed on a separate, complete line. Note that listflag
  161.  *    is ignored by xarchie.
  162.  */
  163. void
  164. procquery(host,str,max_hits,offset,query_type,sortflag,listflag)
  165. char *host,*str;
  166. int max_hits,offset;
  167. char query_type;
  168. int sortflag,listflag;
  169. {
  170.     VLINK l;
  171.     long now;
  172.     extern int rdgram_priority;
  173.  
  174.     /* initialize data structures for this query */
  175.     (void)time(&now);
  176.     presenttime = localtime(&now);
  177.  
  178.     /* Do the query */
  179.     if (sortflag == 1)
  180.     l = archie_query(host,str,max_hits,offset,query_type,AQ_INVDATECMP,0);
  181.     else
  182.     l = archie_query(host,str,max_hits,offset,query_type,NULL,0);
  183.  
  184.     /* Error? */
  185.     if (perrno != PSUCCESS) {
  186.     if (p_err_text[perrno]) {
  187.         if (*p_err_string)
  188.         fprintf(stderr, "%s: failed: %s - %s\n", progname,
  189.                 p_err_text[perrno], p_err_string);
  190.         else
  191.             fprintf(stderr, "%s failed: %s\n", progname, p_err_text[perrno]);
  192.     } else
  193.         fprintf(stderr, "%s failed: Undefined error %d (prospero)", perrno);
  194.     }
  195.  
  196.     /* Warning? */
  197.     if (pwarn != PNOWARN) {
  198.     if (*p_warn_string)
  199.         fprintf(stderr, "%s: Warning! %s - %s\n", progname,
  200.         p_warn_text[pwarn], p_warn_string);
  201.     else
  202.         fprintf(stderr, "%s: Warning! %s\n", progname, p_warn_text[pwarn]);
  203.     }
  204.  
  205.  
  206.     /* Display the results */
  207.  
  208.     if (l == (VLINK)NULL && pwarn == PNOWARN && perrno == PSUCCESS) {
  209.     if (! listflag) puts ("No matches.");
  210. #ifdef CUTCP
  211.     netshut();
  212. #endif
  213.     exit (1);
  214.     }
  215.  
  216.     *lasthost = '\001';
  217.     *lastpath = '\001';
  218.     while (l != NULL) {
  219.     display_link(l,listflag);
  220.     l = l->next;
  221.     }
  222. }
  223.