File: SeTrans.c

package info (click to toggle)
seyon 2.20c-36
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,456 kB
  • sloc: ansic: 18,424; yacc: 184; sh: 183; makefile: 9
file content (230 lines) | stat: -rw-r--r-- 5,626 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

/*
 * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
 * Saggaf. All rights reserved.
 *
 * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
 * statement of rights and permissions for this program.
*/

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Viewport.h>
#include "MultiList.h"

#include <math.h>

#include "seyon.h"
#include "SeDecl.h"

int             ReadParseProtFile();
void            DoTransfer(),
                DoUpload(),
                exec_upload(),
                ReReadProtFile(),
                SeTransfer();

struct _protItem {
  char            name[LIT_BUF];
  char            command[REG_BUF];
  Boolean         reqName;
};

struct _protItem *protItems[MAX_ENT];
XfwfMultiListWidget mlw;
int             transCurItemIndex;

void
TopTransfer(widget, clientData)
     Widget          widget;
     XtPointer       clientData;
{
  void            EditFile();

  Widget          popup, mBox, uBox, lBox,
                  view,
                  list;
  static char     protocolsFile[REG_BUF];
  static String   disItems[MAX_ENT + 1] = {NULL};

  ErrorIfBusy();

  if (disItems[0] == NULL) {
    strncpy(protocolsFile, qres.protocolsFile, REG_BUF);
    if (ReadParseProtFile(protocolsFile, disItems) < 0)
      return;
  }

  popup = AddSimplePopup("transfer", widget);
  mBox = SeAddPaned("mBox", popup);
  uBox = AddBox("uBox", mBox);
  lBox = AddBox("lBox", mBox);

  view = XtCreateManagedWidget("view", viewportWidgetClass, uBox, NULL, 0);
  list = XtVaCreateManagedWidget("list", xfwfMultiListWidgetClass, view, 
								 XtNlist, disItems, XtNmaxSelectable, 1, NULL);
  mlw = (XfwfMultiListWidget) list;
  SeSetViewportDimFromList(view, list, 10);
  XtAddCallback(list, XtNcallback, DoTransfer, clientData);

  AddButton("dismiss", lBox, DestroyShell, NULL);
  AddButton("ok", lBox, DoTransfer,  clientData);
  AddButton("edit", lBox, EditFile, (XtPointer)protocolsFile);
  AddButton("reread", lBox, ReReadProtFile,	(XtPointer)disItems);

  if (clientData) DoTransfer(list, clientData, NULL);
  else PopupCentered(popup, widget);
}

char            lastUploadFile[REG_BUF];

void
DoTransfer(widget, clientData, callData)
    Widget          widget;
    XtPointer       clientData,
    callData;
{
    XfwfMultiListReturnStruct *item;
    Widget          popup;
    String*         actionData = (String*)clientData;
    char            fullCommand[LRG_BUF];
    int             length_remaining;

    if (clientData)
    {if ((transCurItemIndex = atoi(actionData[0]) - 1) < 0 ||  
         transCurItemIndex > MAX_ENT - 1)
        SimpleError("Invalid Entry Number");}
    else {
        if ((item = XfwfMultiListGetHighlighted(mlw))->num_selected == 0)
	  SimpleError("No Item Selected");
        transCurItemIndex =  item->selected_items[0];
    }
  
    strncpy(fullCommand, protItems[transCurItemIndex]->command, LRG_BUF);

    if (protItems[transCurItemIndex]->reqName)
    {
        if (actionData == NULL ||  actionData[1] == NULL) 
        {
	  popup = GetShell(PopupDialogGetValue("upload", widget, exec_upload, 
				         NULL, lastUploadFile));
	  PopupCentered(popup, (clientData) ? XtParent(GetShell(widget)) : widget);
	  return;
        }
        else
        {	  
	  length_remaining = LRG_BUF - strlen(fullCommand);
	  strncat(fullCommand, " ", length_remaining);
	  length_remaining -= 1;
	  strncat(fullCommand, actionData[1], length_remaining);
        }
    }
    DestroyShell(widget);
    ShellCommand(fullCommand);
}

void
ReReadProtFile(widget, disItems)
     Widget          widget;
     XtPointer       disItems[];
{
  Widget          protWidget = XtParent(GetShell(widget));

  FreeList(disItems);
  DestroyShell(widget);
  TopTransfer(protWidget, NULL);
}

void
exec_upload(widget)
     Widget          widget;
{
  Widget          dialog = XtParent(widget);
  static char    *cmd;

  strncpy(lastUploadFile, XawDialogGetValueString(dialog), REG_BUF);
  cmd = FmtString("%s %s", protItems[transCurItemIndex]->command,
	  lastUploadFile, "");

  DestroyShell(XtParent(GetShell(widget)));
  ShellCommand(cmd);
}

void
upload_acc_ok(widget)
     Widget          widget;
{
  exec_upload(widget);
}

void
DoShellCommand(widget, command)
     Widget          widget;
     XtPointer       command;
{
  ShellCommand((String)command);
}

void
TopShell(widget)
     Widget          widget;
{
  void  GetValueByPopup();
  ErrorIfBusy();
  GetValueByPopup(widget, "shellCommand", DoShellCommand);
}

int
ReadParseProtFile(fname, disItems)
     String          fname;
     String          disItems[];
{
  FILE           *fp;
  String          rawItems[MAX_ENT + 1];
  char           *buf,
                  reqName[10];
  int             i,
                  n;

  if ((fp = open_file(fname, qres.defaultDirectory)) == NULL)
    return -1;

  ReadCommentedFile(fp, rawItems);
  fclose(fp);

  FreeList(protItems);
  for (i = 0; (buf = rawItems[i]); i++) {
    /*
	 * allocate the record
	 */
    protItems[i] = XtNew(struct _protItem);
    /*
	 * find the name
	 */
    GetWord(buf, protItems[i]->name);
    /*
	 * find the command
	 */
    GetWord(lptr, protItems[i]->command);
    /*
	 * find other stuff
	 */
    GetWord(lptr, reqName);
    if (reqName[0] == 'y' || reqName[0] == 'Y')
      protItems[i]->reqName = True;
    else
      protItems[i]->reqName = False;
  }
  protItems[i] = (struct _protItem *)NULL;

  FreeList(rawItems);
  FreeList(disItems);

  for (n = 0; n < i; n++)
    disItems[n] = XtNewString(protItems[n]->name);

  disItems[n] = NULL;

  return 0;
}