home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE0.TAR / procquery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  6.0 KB  |  228 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.1.1 - bpk 08/20/91 - took out archie_query from error msg
  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. #if defined(AUX) || defined (AIX)
  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. #ifdef XARCHIE
  30. #include <X11/Intrinsic.h>
  31. #include "xarchie.h"
  32. #include "types.h"
  33. #include "appres.h"
  34. #include "db.h"
  35. extern Database *db;                    /* database for all queries */
  36. static HostEntry *currentHostEntry;     /* current host, this query */
  37. static LocEntry *currentLocEntry;       /* current location, this query */
  38. #endif
  39.  
  40. /*
  41.  * Functions defined here
  42.  */
  43. void display_link(), procquery();
  44.  
  45. /*
  46.  * Data defined here
  47.  */
  48. int perrno, pfs_debug;
  49. static struct tm *presenttime;
  50.  
  51. /*    -    -    -    -    -    -    -    -    */
  52. /*
  53.  * display_link : Prints the contents of the given virtual link. If
  54.  *    listflag is 0, then this uses static variables 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.     static char    lastpath[MAX_VPATH] = "\001";
  64.     static char    lasthost[MAX_VPATH] = "\001";
  65.  
  66.     PATTRIB     ap;
  67.     char    linkpath[MAX_VPATH];
  68.     int        dirflag = 0;
  69.     int        size = 0;
  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. #ifdef XARCHIE
  95.     currentHostEntry = addHostEntry(l->host,db,NULL);
  96. #else
  97.     if (!listflag)
  98.         printf("\nHost %s\n\n",l->host);
  99. #endif
  100.     strcpy(lasthost,l->host);
  101.     *lastpath = '\001';
  102.     }
  103.     
  104.     /* Is this a new linkpath (location)? */
  105.     if(strcmp(linkpath,lastpath) != 0) {
  106. #ifdef XARCHIE
  107.         currentLocEntry = addLocEntry((*linkpath ? linkpath : "/"),
  108.                       currentHostEntry,NULL);
  109. #else
  110.     if (!listflag)
  111.         printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
  112. #endif
  113.     strcpy(lastpath,linkpath);
  114.     }
  115.     
  116.     /* Parse the attibutes of this link */
  117.     for (ap = l->lattrib; ap; ap = ap->next) {
  118.     if (strcmp(ap->aname,"SIZE") == 0) {
  119.         sscanf(ap->value.ascii,"%d",&size);
  120.     } else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
  121.         modes = ap->value.ascii;
  122.     } else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
  123.         gt_date = ap->value.ascii;
  124.         sscanf(gt_date,"%4d%2d%2d%2d%2d",>_year,
  125.            >_mon, >_day, >_hour, >_min);
  126.         if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
  127.                     presenttime->tm_mon - gt_mon) > 6) 
  128.         sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
  129.             gt_day, gt_year);
  130.         else
  131.         sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
  132.              gt_day, gt_hour, gt_min);
  133.     }
  134.     }
  135.     
  136. #ifdef XARCHIE
  137.     /* just using linkpath buffer because it's here */
  138.     strcpy(linkpath,l->name);
  139.     if (dirflag)
  140.     strcat(linkpath,"/");
  141.     (void)addFileEntry(linkpath,size,modes,archie_date,currentLocEntry,NULL);
  142.     doPendingEvents();
  143. #else
  144.     /* Print this link's information */
  145.     if (listflag)
  146.     printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
  147.                             (dirflag ? "/" : ""));
  148.     else
  149.     printf("      %9s %s %10d  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  150.                     modes,size,archie_date,l->name);
  151. #endif
  152.  
  153.     /* Free the attibutes */
  154.     atlfree(l->lattrib);
  155.     l->lattrib = NULL;
  156. }
  157.  
  158. /*    -    -    -    -    -    -    -    -    */
  159. /*
  160.  * procquery : Process the given query and display the results. If
  161.  *    sortflag is non-zero, then the results are sorted by increasing
  162.  *    date, else by host/filename. If listflag is non-zero then each
  163.  *    entry is printed on a separate, complete line. Note that listflag
  164.  *    is ignored by xarchie.
  165.  */
  166. void
  167. procquery(host,str,max_hits,offset,query_type,sortflag,listflag)
  168. char *host,*str;
  169. int max_hits,offset;
  170. char query_type;
  171. int sortflag,listflag;
  172. {
  173.     VLINK l;
  174.     long now;
  175.     extern int rdgram_priority;
  176.  
  177.     /* initialize data structures for this query */
  178.     (void)time(&now);
  179.     presenttime = localtime(&now);
  180. #ifdef XARCHIE
  181.     /* initialize Prospero globals from appResources */
  182.     pfs_debug = appResources.debugLevel;
  183.     rdgram_priority = appResources.niceLevel;
  184.     client_dirsrv_timeout = appResources.timeout;
  185.     client_dirsrv_retry = appResources.retries;
  186.     clearDb(db);
  187.     currentHostEntry = HOST_NULL;
  188.     currentLocEntry = LOC_NULL;
  189. #endif
  190.  
  191.     /* Do the query */
  192.     if (sortflag == 1)
  193.     l = archie_query(host,str,max_hits,offset,query_type,AQ_INVDATECMP,0);
  194.     else
  195.     l = archie_query(host,str,max_hits,offset,query_type,NULL,0);
  196.  
  197.     /* Error? */
  198.     if (perrno != PSUCCESS) {
  199. #ifdef XARCHIE
  200.     if (*p_err_string)
  201.         alert2("Prospero error: %.100s - %.100s",p_err_text[perrno],
  202.                              p_err_string);
  203.     else
  204.         alert1("Prospero error: %.200s",p_err_text[perrno]);
  205.         status0("Ready");
  206. #else
  207.     if (*p_err_string)
  208.       fprintf(stderr, "%s: failed: %s - %s\n", progname,
  209.           p_err_text[perrno], p_err_string);
  210.     else
  211.       fprintf(stderr, "%s failed: %s\n", progname, p_err_text[perrno]);
  212. #endif
  213.     }
  214.  
  215.     /* Display the results */
  216. #ifdef XARCHIE
  217.     status0("Parsing");
  218. #endif
  219.     while (l != NULL) {
  220.     display_link(l,listflag);
  221.     l = l->next;
  222.     }
  223. #ifdef XARCHIE
  224.     displayHosts(db);
  225.     status0("Ready");
  226. #endif
  227. }
  228.