File: main.c

package info (click to toggle)
moxftp 2.2-6
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,236 kB
  • ctags: 3,839
  • sloc: ansic: 43,419; makefile: 270; perl: 262; sh: 244
file content (318 lines) | stat: -rw-r--r-- 6,370 bytes parent folder | download | duplicates (4)
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * Copyright (c) 1992 The Regents of the University of Texas System.
 * Copyright (c) 1993 The Regents of the University of Texas System.
 * Copyright (c) 1994 The Regents of the University of Texas System.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted provided
 * that the above copyright notice and this paragraph are duplicated in all
 * such forms and that any documentation, advertising materials,  and other
 * materials  related to such  distribution  and use  acknowledge  that the
 * software  was  developed  by the  University of Texas.  The  name of the
 * University may not be  used to endorse or promote  products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */


#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1993 The Regents of the University of Texas System.\n\
 All rights reserved.\n";
static char rcsid[] =
"$Id: main.c,v 1.1 1994/03/14 18:55:53 jones Exp $\n";
static char rcspath[] =
"$Source: /mintaka/u0/xx/ss/jones/jones.old/mftp.src/mftpnew/RCS/main.c,v $\n";
#endif

/* $Log: main.c,v $
 * Revision 1.1  1994/03/14  18:55:53  jones
 * Initial revision
 *
 */

#include "machine.h"
#include "defs.h"
#include "popen.h"
#include "patchlevel.h" 
#include "class.h"
#include "wc.h"

#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>


int Debug = 0;

XtAppContext App_context;
Widget       Top;
char *Ftpname = NULL;
char *ver;
char *gateway = NULL;
int  use_gateway = 0;

static  void WM_DELETE_WINDOW();

extern char *Version;
extern String fallback_resources[];
extern do_animate;

#if defined(SIGPIPE)
SIG_TYPE     no_sigpipe();
#endif

main ( argc, argv )
    int   argc;
    char* argv[];
{   
    Display      *dpy;
    char	 *resources;
    Arg          arg[1];
    String       *fb;
    int          i;
    int		 use_fallback = 0;
    extern  void reapem();

    Ftpname =    XFTPNAME;
    argv[0] =    XFTPCLASS;
    resources =  XFTPRESOURCE;


#if defined(DESPERATE)
    malloc_debug(2);
#endif

#if defined(SIGCHLD)
    signal(SIGCHLD, reapem);
#endif

#if defined(SIGPIPE)
    signal(SIGPIPE, no_sigpipe);
#endif

    for (i=0; i<argc; i++) {
	if (strcmp(argv[i], "-debug") == 0) {
    	    resources =  XFTPRESOURCE_DEBUG;
	    Debug++;
 	} else if (strcmp(argv[i], "-ufb") == 0) {
	    use_fallback++;
 	} else if (strcmp(argv[i], "-gateway") == 0 &&
		   (i+1)<argc) {
	    i++;
	    gateway = argv[i];
 	} else if (strcmp(argv[i], "-animate") == 0) {
	    do_animate++;
	}
    }
	  
    /*
     * See if we have an archie c client.
     */
    Check_Archie();

    /*
     * Initialize local storage.
     */
    Initialize();
 
    /*
     * Check and see if fallback resources are needed.
     */
    fb = fallback_resources;
    if (checkdir(getenv("XAPPLRESDIR"), resources)) {
	fb = NULL;
    } else if(!Debug && access(APP_RES, R_OK) == 0) {
	fb = NULL;
    }
    if (use_fallback) fb = fallback_resources;

    /*
     * Initialize Open LOOK tool kit.
     */
#if defined(OPENWINDOW)
    OlToolkitInitialize((XtPointer)NULL);
#endif
    /*
     * Initialize Xt.
     */
    Top = XtAppInitialize (&App_context, 
			   resources,  
			   NULL, 
			   0, 
			   &argc, 
			   argv, 
			   fb, 	
			   NULL, 
			   0);

    /*
     * Get Application resources.
     */
/*
    XtGetApplicationResources(App_context, (char *)&args, arg_resources,
                              XtNumber(arg_resources),
                              (ArgList)NULL, (Cardinal)0);
*/

    /*
     * Register my widgets.
     */
 
    Register(App_context);

    /*
     * Register GUI widgets.
     */
    RegisterWidgets(App_context);

    /*
     * Add call backs.
     */
    Register_App_CallBacks_and_Actions();

    /*
     * Allow dialog to add its callbacks.
     */
    Register_dialog_c_a_a();

    /*
     * Create the childern.
     */
    if ( WcWidgetCreation (Top)  != 0 ) exit (1);
    /*
     * Clear list.
     */
    Clear_List();

    /*
     * So that noop will work on the command shell.
     */
    XtRealizeWidget(WcFullNameToWidget(Top, "*Shellcommand"));

    /*
     * Make visable.
     */
    XtRealizeWidget ( Top );

     /*
     * Set icon.
     */
    set_icon(ICON_DISCONNECT);

    /*
     * Allow for delete function.
     */
    WM_DELETE(Top, WM_DELETE_WINDOW, NULL);
    /*
     * Just for fun.
     */
    ver = (char *)XtMalloc(sizeof(Version)+sizeof(XFTPNAME)+20);
    sprintf(ver, Version, XFTPNAME, PATCHLEVEL);
    Set_Status(ver);
    /*
     * Bug in OPENWINDOW library or ld
     */
#if (defined(OPENWINDOW_XAW)||defined(OPENWINDOW))&&!defined(SVR4)
     force_open(1);
#endif

    /*
     * Initialize ftp.
     */
    Init_Ftp();

    /*
     * Start the main loop.
     */
    XtAppMainLoop(App_context);
}

set_icon(t)
int t;
{
    char *type = NULL;
    
    switch (t) {
	case ICON_CONNECTING:
	    type = "connecting";
	    break;
	case ICON_RECONNECT:
	    type = "reconnect";
	    break;
	case ICON_DISCONNECT:
	    type = "disconnect";
	    if (retry) type = "retry";
	    break;
	case ICON_CONNECT:
	    type = "connected";
	    break;
	case ICON_BUSY1:
	    type = "busy1";
	    break;
	case ICON_BUSY2:
	    type = "busy2";
	    break;
	case ICON_BUSY3:
	    type = "busy3";
	    break;
	case ICON_BUSY4:
	    type = "busy4";
	    break;
	break;
        default: 
	    fprintf(stderr, "Unkown icon\n");
	    return;
    }
   
    Set_Icon(Top, type);
}


static  void
WM_DELETE_WINDOW()
{
#if defined(XAW)
    exit(1);
#endif
}

checkdir(dir, file)
char *dir;
char *file;
{
    char *filename;
    int   good = 0;
 
    if (dir == NULL) return 0;
    if (*dir == '\0') return 0;
    filename = concat(NULL    , dir);
    filename = concat(filename, "/");
    filename = concat(filename, file);
    if (access(filename, R_OK) == 0) good++;
    XtFree(filename);
    return good;
}

#if (defined(OPENWINDOW_XAW)||defined(OPENWINDOW))&&!defined(SVR4)
force_open(i) 
int i;
{
 
    if (i) return;
    get_wmShellWidgetClass() ;
    get_applicationShellWidgetClass () ;
}
#endif

#if defined(SIGPIPE)
SIG_TYPE
no_sigpipe(sig)
int sig;
{
    signal(SIGPIPE, no_sigpipe);
}
#endif