home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE1.TAR / actions.c next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  3.6 KB  |  145 lines

  1. /*
  2.  * actions.c : Widget action procedures
  3.  *
  4.  * This file defines the global actionTable used in XtAppAddActions() and
  5.  * defines the action procedures, except those used on the settingsPanel
  6.  * which are imported. Eventually there may be more actions, and they'll
  7.  * be put here.
  8.  *
  9.  * George Ferguson, ferguson@cs.rochester.edu, 12 Sep 1991.
  10.  *
  11.  */
  12.  
  13. #include <X11/Intrinsic.h>
  14. #include <X11/StringDefs.h>
  15. #include <X11/Xaw/Text.h>
  16. #include <X11/Xaw/Cardinals.h>
  17. #include "procquery.h"
  18. #include "xarchie.h"
  19. #include "types.h"
  20. #include "appres.h"
  21. #include "db.h"
  22. #include "settings.h"        /* for settings actions */
  23. #include "ftp.h"
  24. #include "alert.h"
  25. #include "regex.h"
  26.  
  27. /*
  28.  * Functions defined here
  29.  */
  30. static void quitAction(),queryAction(),ftpAction();
  31.  
  32. /*
  33.  * Data defined here:
  34.  */
  35. XtActionsRec actionTable[15] = {    /* check size in actions.h! */
  36.     { "quit",            quitAction },
  37.     { "query",            queryAction },
  38.     { "ftp",            ftpAction },
  39.     { "settings",        settingsAction },
  40.     { "apply-settings",        applySettingsAction },
  41.     { "default-settings",    defaultSettingsAction },
  42.     { "done-settings",        doneSettingsAction },
  43.     { "set-search-type",    setSearchTypeAction },
  44.     { "set-search-type-now",    setSearchTypeNowAction },
  45.     { "set-sort-type",        setSortTypeAction },
  46.     { "set-sort-type-now",    setSortTypeNowAction },
  47.     { "set-host",        setHostAction },
  48.     { "set-host-now",        setHostNowAction },
  49.     { "set-nice-level",        setNiceLevelAction },
  50.     { "set-nice-level-now",    setNiceLevelNowAction },
  51. };
  52.  
  53. /*    -    -    -    -    -    -    -    -    */
  54.  
  55. /*ARGSUSED*/
  56. static void
  57. quitAction(w,event,params,num_params)
  58. Widget w;
  59. XEvent *event;
  60. String *params;
  61. Cardinal *num_params;
  62. {
  63.     XtDestroyApplicationContext(appContext);
  64.     exit(0);
  65. }
  66.  
  67. /*ARGSUSED*/
  68. static void
  69. queryAction(w,event,params,num_params)
  70. Widget w;
  71. XEvent *event;
  72. String *params;
  73. Cardinal *num_params;
  74. {
  75.     Arg args[1];
  76.     char *s;
  77.     int len;
  78.     Boolean gif;
  79.  
  80.     XtSetArg(args[0],XtNstring,&s);
  81.     XtGetValues(searchText,args,ONE);
  82.     if (*s == '\0') {
  83.     alert0("No search term specified.");
  84.     return;
  85.     }
  86. #ifndef DONT_CATCH_GIFS
  87.     len = strlen(s);
  88.     gif = False;
  89.     switch (appResources.searchType) {
  90.     case GfExact:
  91.         gif = ((len > 4 &&
  92.             (!strcmp(s+len-4,".gif") || !strcmp(s+len-4,".GIF"))) ||
  93.            (len > 6 &&
  94.             (!strcmp(s+len-6,".gif.Z") || !strcmp(s+len-6,".GIF.Z"))));
  95.         break;
  96.     case GfSubstr:
  97.     case GfExactSubstr:
  98.     case GfSubcase:
  99.     case GfExactSubcase:
  100.         gif = (sindex(s,"gif") || sindex(s,"GIF"));
  101.         break;
  102.     case GfRegexp:
  103.     case GfExactRegexp:
  104.         gif = (re_comp(s) == NULL &&
  105.            (re_exec("@PrObAbLyNoTaFiLe@.gif") ||
  106.             re_exec("@PrObAbLyNoTaFiLe@.gif.Z")));
  107.         break;
  108.     }
  109.     if (gif) {
  110.     if (!confirm0("Your search term will match GIFs. Do it anyway?"))
  111.         return;
  112.     else if (appResources.niceLevel <= 0 &&
  113.          !confirm0("Really do it without increasing niceness?"))
  114.         return;
  115.     }
  116. #endif /* DONT_CATCH_GIFS */
  117.     if (appResources.sortType == GfInvdate)
  118.     procquery(appResources.archieHost,s,appResources.maxHits,
  119.           appResources.offset,appResources.searchType,True,0);
  120.     else
  121.     procquery(appResources.archieHost,s,appResources.maxHits,
  122.           appResources.offset,appResources.searchType,False,0);
  123. }
  124.  
  125. /*ARGSUSED*/
  126. static void
  127. ftpAction(w,event,params,num_params)
  128. Widget w;
  129. XEvent *event;
  130. String *params;
  131. Cardinal *num_params;
  132. {
  133.     if (selectedHostEntry == HOST_NULL || selectedLocEntry == LOC_NULL ||
  134.     selectedFileEntry == FILE_NULL) {
  135.     alert0("You must specify a host, location and file before invoking ftp()");
  136.     return;
  137.     }
  138.     if (selectedFileEntry->modes[0] == 'd') {
  139.     alert0("Sorry, can't fetch whole directories yet.");
  140.     return;
  141.     }
  142.     ftp(selectedHostEntry->hostname,selectedLocEntry->linkpath,
  143.     selectedFileEntry->name);
  144. }
  145.