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