home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / x / scommands.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-04  |  4.8 KB  |  193 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4.  
  5.    This is part of the X user-interface for the WAIS software.  Do with it
  6.    as you please.
  7.  
  8.    jonathan@Think.COM
  9. */
  10.  
  11. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  12.  
  13.  
  14. /*
  15.  * $Log: scommands.c,v $
  16.  * Revision 1.2  1994/08/05  07:26:41  pfeifer
  17.  * Release beta 04
  18.  *
  19.  * Revision 1.1  1993/02/16  15:10:18  freewais
  20.  * Initial revision
  21.  *
  22.  * Revision 1.9  92/05/19  09:26:58  jonathan
  23.  * Fixed bug in CancelSourceEdit where new source caused core dump.
  24.  * 
  25.  * Revision 1.8  92/04/28  15:30:17  jonathan
  26.  * Cleaned up use of scrollists.
  27.  * 
  28.  * Revision 1.7  92/03/17  14:17:00  jonathan
  29.  * Generally cleaned up.
  30.  * 
  31. */
  32.  
  33. #ifndef lint
  34. static char *RCSid = "$Header: /usr/local/ls6/src+data/src/freeWAIS-sf/x/RCS/scommands.c,v 1.2 1994/08/05 07:26:41 pfeifer Exp $";
  35. #endif
  36.  
  37. #define _C_SCOMMANDS
  38. #define XWAIS
  39. #include "xwais.h"
  40.  
  41. int last_source = NO_ITEM_SELECTED;
  42.  
  43. static Source edit_source = NULL;
  44.  
  45. int get_selected_source()
  46. {
  47.   return(get_selected_item(sourcewindow->ListWidget));
  48. }
  49.  
  50. /* widget commands */
  51.  
  52. /* ARGSUSED */
  53. void
  54. EditSource(w, closure, call_data)
  55. Widget w;
  56. XtPointer closure, call_data;
  57. {
  58.   SList s;
  59.   char msg[1000];
  60.   int CurrentSource;
  61.  
  62.   double_click = FALSE;
  63.   LastClicked = w;
  64.  
  65.   if ((CurrentSource = get_selected_source())
  66.       != NO_ITEM_SELECTED) {
  67. #ifdef MOTIF
  68.     last_source = CurrentSource;
  69. #endif
  70.     if (last_source == CurrentSource) {
  71.       if(edit_source == NULL) 
  72.     edit_source = (Source)s_malloc(sizeof(_Source));
  73.  
  74.       if(!ReadSourceFile(edit_source, 
  75.              Source_items[CurrentSource],
  76.              app_resources.userSourceDirectory))
  77.     ReadSourceFile(edit_source, 
  78.                Source_items[CurrentSource],
  79.                app_resources.commonSourceDirectory);
  80.  
  81.       sprintf(msg, "Opening source: %s\n", edit_source->name);
  82.       XwaisPrintf(msg);
  83.       PopupSource(edit_source);
  84.     }
  85.     else last_source = CurrentSource;
  86.   } 
  87.   else {
  88.     last_source = -1;
  89.     XwaisPrintf("No source selected.\nPlease selected one and try again.\n");
  90.   }
  91. }
  92.  
  93. /* ARGSUSED */
  94. void
  95. AddSource(w, closure, call_data)
  96. Widget w;
  97. XtPointer closure, call_data;
  98. {
  99.  
  100.   double_click = FALSE;
  101.   LastClicked = w;
  102.  
  103.   if(edit_source == NULL) 
  104.     edit_source = (Source)s_malloc(sizeof(_Source));
  105.  
  106.   edit_source->name = s_strdup("new.src");
  107.   edit_source->directory = s_strdup(app_resources.userSourceDirectory);
  108.   strncpy(edit_source->server, "localhost", STRINGSIZE);
  109.   strncpy(edit_source->service, "8000", STRINGSIZE);
  110.   strncpy(edit_source->database, "database_name", STRINGSIZE);
  111.   edit_source->maintainer = s_strdup("");
  112.   edit_source->description = s_strdup("");
  113.   XwaisPrintf("Opening new source\n");
  114.   PopupSource(edit_source);
  115. }
  116.  
  117. void PopupSource(s)
  118. Source s;
  119. {
  120.   Arg arglist[10];
  121.   Cardinal num_args;
  122.  
  123.   if (s != NULL) {
  124.     num_args = 0;
  125.     XtSetArg(arglist[num_args], XtNtitle, s->name); num_args++;
  126.     XtSetValues(sourcepopup, arglist, num_args);
  127.     ReplaceText(snamewid, s->name);
  128.     ReplaceText(serverwid, s->server);
  129.     ReplaceText(servicewid, s->service);
  130.     ReplaceText(dbwid, s->database);
  131.     ReplaceText(costwid, s->cost);
  132.     ReplaceText(unitwid, s->units);
  133.     ReplaceText(maintainerwid, s->maintainer);
  134.     if(s->description == NULL) s->description = s_strdup("");
  135.     ReplaceAsciiText(descwid, s->description);
  136.     XtPopup(sourcepopup, XtGrabNone);
  137.   }
  138. }
  139.  
  140. /* ARGSUSED */
  141. void CloseSourceEdit(w, closure, call_data)
  142. Widget w;
  143. XtPointer closure, call_data;
  144. {
  145.   char name[STRINGSIZE];
  146.  
  147.   double_click = FALSE;
  148.   LastClicked = w;
  149.  
  150.   if (edit_source != NULL) {
  151.     strcpy(name, GetString(snamewid));
  152.  
  153.     if(!((strlen(name) > 4) && 
  154.      strstr(name, ".src") &&
  155.      (!strcmp(".src", strstr(name, ".src")))))
  156.       strcat(name, ".src");
  157.  
  158.     if(edit_source->name != NULL) s_free(edit_source->name);
  159.     edit_source->name = s_strdup(name);
  160.  
  161.     if (edit_source->maintainer != NULL) s_free(edit_source->maintainer);
  162.     edit_source->maintainer = s_strdup(GetString(maintainerwid));
  163.  
  164.     if (edit_source->description != NULL) s_free(edit_source->description);
  165.     edit_source->description = s_strdup(GetAsciiString(descwid));
  166.  
  167.     strncpy(edit_source->server, GetString(serverwid), STRINGSIZE);
  168.     strncpy(edit_source->service, GetString(servicewid), STRINGSIZE);
  169.     strncpy(edit_source->database, GetString(dbwid), STRINGSIZE);
  170.     strncpy(edit_source->cost, GetString(costwid), STRINGSIZE);
  171.     strncpy(edit_source->units, GetString(unitwid), STRINGSIZE);
  172.  
  173.     WriteSource(app_resources.userSourceDirectory, edit_source, TRUE);
  174.  
  175.     /* ScanDirs(NULL, NULL);*/
  176.   }
  177.   else XwaisPrintf("No currently selected source.  This shouldn't happen.\n");
  178.   XtPopdown(sourcepopup);
  179. }
  180.  
  181. /* ARGSUSED */
  182. void CancelSourceEdit(w, closure, call_data)
  183. Widget w;
  184. XtPointer closure, call_data;
  185. {
  186.   SList s;
  187.  
  188.   double_click = FALSE;
  189.   LastClicked = w;
  190.  
  191.   XtPopdown(sourcepopup);
  192. }
  193.