home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / seyon197.tz / seyon197 / seyon / SeTrans.c < prev    next >
C/C++ Source or Header  |  1993-02-16  |  5KB  |  219 lines

  1.  
  2. /*
  3.  * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
  4.  * Saggaf. All rights reserved.
  5.  *
  6.  * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
  7.  * statement of rights and permissions for this program.
  8. */
  9.  
  10. #include <X11/Intrinsic.h>
  11. #include <X11/StringDefs.h>
  12. #include <X11/Xaw/List.h>
  13. #include <X11/Xaw/Dialog.h>
  14. #include <X11/Xaw/Viewport.h>
  15.  
  16. #include "seyon.h"
  17. #include "SeDecl.h"
  18.  
  19. extern char    *str_parse();
  20.  
  21. int             ReadParseProtFile();
  22. void            do_transfer(),
  23.                 buf_transfer(),
  24.                 do_upload(),
  25.                 exec_upload(),
  26.                 ReReadProtFile(),
  27.                 SeTransfer();
  28.  
  29. struct _protItem {
  30.   char            name[LIT_BUF];
  31.   char            command[REG_BUF];
  32.   Boolean         reqName;
  33. };
  34.  
  35. struct _protItem *protItems[MAX_ENT];
  36. int             transCurItemIndex;
  37.  
  38. void
  39. top_transfer(widget)
  40.      Widget          widget;
  41. {
  42.   Widget          popup, mBox, uBox, lBox,
  43.                   view,
  44.                   list;
  45.   static char     protocolsFile[REG_BUF];
  46.   static String   disItems[MAX_ENT + 1] = {NULL};
  47.  
  48.   ret_if_up(widget, inhibit_child);
  49.  
  50.   if (disItems[0] == NULL) {
  51.     strcpy(protocolsFile, qres.protocolsFile);
  52.     if (ReadParseProtFile(protocolsFile, disItems) < 0)
  53.       return;
  54.   }
  55.  
  56.   popup = AddSimplePopup("transfer", widget);
  57.   mBox = SeAddPaned("mBox", popup);
  58.   uBox = SeAddBox("uBox", mBox);
  59.   lBox = SeAddBox("lBox", mBox);
  60.  
  61.   view = XtCreateManagedWidget("view", viewportWidgetClass, uBox, NULL, 0);
  62.   list = XtVaCreateManagedWidget("list", listWidgetClass, view,
  63.                  XtNlist, disItems, NULL);
  64.   SeSetViewportDimFromList(view, list, 10);
  65.   XtAddCallback(list, XtNcallback, do_transfer, NULL);
  66.  
  67.   SeAddButton("dismiss", lBox, DestroyShellCallBack);
  68.   SeAddButtonWithClientData("edit", lBox, EditFile, (XtPointer)protocolsFile);
  69.   SeAddButtonWithClientData("reread", lBox, ReReadProtFile,
  70.                 (XtPointer) disItems);
  71.  
  72.   PopupCentered(popup, widget);
  73. }
  74.  
  75. void
  76. ReReadProtFile(widget, disItems)
  77.      Widget          widget;
  78.      XtPointer       disItems[];
  79. {
  80.   DestroyShell(widget);
  81.  
  82.   FreeList(disItems);
  83.   top_transfer(XtParent(GetShell(widget)));
  84. }
  85.  
  86. void
  87. do_transfer(widget, client_data, call_data)
  88.      Widget          widget;
  89.      XtPointer       client_data,
  90.                      call_data;
  91. {
  92.   XawListReturnStruct *item = (XawListReturnStruct *) call_data;
  93.  
  94.   if ((transCurItemIndex = item->list_index) == XAW_LIST_NONE)
  95.     return;
  96.  
  97.   if (protItems[transCurItemIndex]->reqName) {
  98.     do_upload(widget);
  99.     return;
  100.   }
  101.  
  102.   DestroyShell(widget);
  103.   exec_cmd(protItems[transCurItemIndex]->command);
  104. }
  105.  
  106. char            lastUploadFile[REG_BUF];
  107.  
  108. void
  109. do_upload(widget, client_data)
  110.      Widget          widget;
  111.      XtPointer       client_data;
  112. {
  113.   SePopupDialogGetStringE("upload", widget, exec_upload, NULL, lastUploadFile,
  114.                           True);
  115. }
  116.  
  117. void
  118. exec_upload(widget)
  119.      Widget          widget;
  120. {
  121.   Widget          dialog = XtParent(widget);
  122.   static char     cmd[REG_BUF];
  123.  
  124.   strcpy(lastUploadFile, XawDialogGetValueString(dialog));
  125.   sprintf(cmd, "%s %s", protItems[transCurItemIndex]->command,
  126.       lastUploadFile);
  127.  
  128.   DestroyShell(XtParent(GetShell(widget)));
  129.   exec_cmd(cmd);
  130. }
  131.  
  132. void
  133. upload_acc_ok(widget)
  134.      Widget          widget;
  135. {
  136.   exec_upload(widget);
  137. }
  138.  
  139. void
  140. ExecShellCmd(w, client_data)
  141.      Widget          w;
  142.      XtPointer       client_data;
  143. {
  144.   Widget          dialog = (Widget)client_data;
  145.   String          command = XawDialogGetValueString(dialog);
  146.  
  147.   DestroyShell(dialog);
  148.   exec_cmd(command);
  149. }
  150.  
  151. void
  152. top_shell(w)
  153.      Widget          w;
  154. {
  155.   ret_if_up(w, inhibit_child);
  156.   SePopupDialogGetString("shellCommand", w, ExecShellCmd, NULL);
  157. }
  158.  
  159. void
  160. shell_acc_ok(widget)
  161.      Widget          widget;
  162. {
  163.   ExecShellCmd(widget, (XtPointer) XtParent(widget));
  164. }
  165.  
  166. int
  167. ReadParseProtFile(fname, disItems)
  168.      String          fname;
  169.      String          disItems[];
  170. {
  171.   FILE           *fp;
  172.   String          rawItems[MAX_ENT + 1];
  173.   char           *buf,
  174.                   reqName[10];
  175.   int             i,
  176.                   n;
  177.  
  178.   if ((fp = open_file(fname, qres.defaultDirectory)) == NULL)
  179.     return -1;
  180.  
  181.   ReadCommentedFile(fp, rawItems);
  182.   fclose(fp);
  183.  
  184.   FreeList(protItems);
  185.   for (i = 0; (buf = rawItems[i]); i++) {
  186.     /*
  187.      * allocate the record
  188.      */
  189.     protItems[i] = XtNew(struct _protItem);
  190.     /*
  191.      * find the name
  192.      */
  193.     GetWord(buf, protItems[i]->name);
  194.     /*
  195.      * find the command
  196.      */
  197.     GetWord(lptr, protItems[i]->command);
  198.     /*
  199.      * find other stuff
  200.      */
  201.     GetWord(lptr, reqName);
  202.     if (reqName[0] == 'y' || reqName[0] == 'Y')
  203.       protItems[i]->reqName = True;
  204.     else
  205.       protItems[i]->reqName = False;
  206.   }
  207.   protItems[i] = (struct _protItem *)NULL;
  208.  
  209.   FreeList(rawItems);
  210.   FreeList(disItems);
  211.  
  212.   for (n = 0; n < i; n++)
  213.     disItems[n] = XtNewString(protItems[n]->name);
  214.  
  215.   disItems[n] = NULL;
  216.  
  217.   return 0;
  218. }
  219.