home *** CD-ROM | disk | FTP | other *** search
- /*
- DUFTP
- */
-
- // Initialisation code
-
- #include <DULIB.H>
- #include <SIGNAL.H>
- #include <SETJMP.H>
- #include "globals.h"
- #include "duftp_n.h"
- #include "dispatch.h"
- #include "ftp.h"
- #include "servers.h"
- #include "gui2ftp.h"
- #include "dip.h"
- #include "local_fs.h"
-
- // Debug code
-
- void illegal_sig(int a)
- {
- form_alert(1,"[1][ Illegal instruction. | Please use QUIT to exit correctly. ][ OK ]");
- signal(a,illegal_sig);
- longjmp(recover_main,1);
- }
-
- void berr_sig(int a)
- {
- form_alert(1,"[1][ Bus Error. | Please use QUIT to exit correctly. ][ OK ]");
- signal(a, berr_sig);
- longjmp(recover_main,1);
- }
-
- void int_sig_handler(int a)
- {
-
- form_alert(1,"[1][ Please use QUIT to exit correctly. ][ OK ]");
- signal(a,int_sig_handler);
- longjmp(recover_main,1);
- }
-
- short scan_code_reporter(void)
- {
- char al[200];
- sprintf(al,"[1][ Scan code = 0x%x ][ ok ]", kc_key);
- form_alert(1,al);
- return TRUE;
- }
-
- char version_string[100];
-
- void initialise(void)
- {
- char al[FMSIZE],*rsc1,*rsc2;
- short d,inv[512];
-
- original_SIGCHLD=signal(SIGCHLD,SIG_IGN);
-
- initial_dir=(char*)malloc(sizeof(char)*FMSIZE);
-
- getcwd(al,FMSIZE);
-
- if (!strncmp("/dev",al,4))
- {
- if ((al[5]=='u')&&(al[6]=='/'))
- sprintf(initial_dir,"u:%s",al+6);
- else
- sprintf(initial_dir,"u:%s",al+4);
- }else{
- sprintf(initial_dir,"%s",al);
- }
-
- load_servers();
-
- // DULIB GUI INITIALISATION
- enviroment_initialise();
-
- if ((AESversion>=3)&&(AESversion_m>=6)) // Have we got a new enough AES to use CICONS?
- {
- rsc1="DUFTP_N.RSC";
- rsc2="duftp_n.rsc";
- }else{
- rsc1="DUFTP_O.RSC";
- rsc2="duftp_o.rsc";
- }
-
- d=rsrc_load(rsc1); // Load resources
- if (!d)
- {
- d=rsrc_load(rsc2); // Load resources (minixFS support, check both cases)
- if (!d)
- {
- sprintf(al,"[1][ Cann't load resource ? | File: '%s'. ][ EXIT ]",rsc1);
- form_alert(1,al);
- exit(1);
- }
- }
-
- install_menu(Mainmenu); // Install menu
-
- // Configure for mono displays if we need to
- vq_extnd(x_handle,0,inv);
- if (inv[13]<16)
- {
- rsrc_form2mono(Mainwindow, 0);
- rsrc_form2mono(Hosts, 0);
- rsrc_form2mono(Open_new, 0);
- rsrc_form2mono(Dip_dialing,0);
- rsrc_form2mono(Dip_connected,0);
- rsrc_form2mono(Ftp_progress,0);
- rsrc_form2mono(About,1);
- }
-
- // Set up the events
- Set_object_event(Mainmenu, File_quit, mev_QUIT);
- Set_object_callback(Mainmenu, Dial_connect, &dip_dialup);
- Set_object_callback(Mainmenu, Dial_disconnect, &dip_hangup);
- Set_object_callback(Mainmenu, File_save_bm, &save_servers);
- Set_object_callback(Mainmenu, Mftp_open, &dispatcher);
- Set_object_callback(Mainmenu, Mftp_close, &close_current_session);
- Set_object_callback(Mainmenu, Help, &dialog_help);
- Set_object_event(Mainmenu, Mftp_stop, mev_STOPTRANSFER);
- Set_object_callback(Mainwindow, This_server, &popup_select_server);
- Set_object_callback(Mainwindow, Open_server, &open_selected_server);
- Set_object_callback(Mainwindow, Close_server, &close_current_session);
- Set_object_callback(Mainwindow, Open_new_server, &dispatcher);
- Set_object_callback(Mainwindow, Add_new_bookmark, &add_current_server);
- Set_object_event(Ftp_progress, Pftp_stop, mev_STOPTRANSFER);
- Set_scroll_list(Hosts, Listhosts, mev_SELBOOKMARK, server_name_list, server_count, 5);
- Set_object_callback(Hosts, Save_servers, &save_servers);
- Set_object_callback(Hosts, New_server, &add_new_server);
- Set_object_callback(Hosts, Delete_server, &delete_server);
-
- // Attach a few automatic close options
- Set_object_callback(Open_new, Open_new_open, &destructor);
- Set_object_callback(Open_new, Open_new_cancel, &destructor);
- Set_dialog_Kcallback(Open_new, &Kdestructor); // In Open_new dialog, Return==Open FTP
-
- // Editable text fields in the open new server dialog
- sprintf(new_server_address," ");
- sprintf(new_server_login,"anonymous ");
- sprintf(new_server_password,"me@localhost ");
- set_dialog_text(Open_new, Open_new_name,new_server_address);
- set_dialog_text(Open_new, Open_new_login,new_server_login);
- set_dialog_text(Open_new, Open_new_pass,new_server_password);
- set_dialog_text(Open_new, Open_new_path,new_server_path);
- Set_object_editable(Open_new, Open_new_path);
- Set_object_editable(Open_new, Open_new_pass);
- Set_object_editable(Open_new, Open_new_login);
- Set_object_editable(Open_new, Open_new_name);
- Set_dialog_Kfocus(Open_new, Open_new_name);
-
- // Editable text fields in the Hosts dialog
- set_dialog_text(Hosts, Server_name, selected_server->name);
- set_dialog_text(Hosts, Ip_address, selected_server->ip_name);
- set_dialog_text(Hosts, Login_name, selected_server->login);
- set_dialog_text(Hosts, Login_password, selected_server->password);
- set_dialog_text(Hosts, Login_path, selected_server->path);
- Set_object_editable(Hosts, Login_path);
- Set_object_editable(Hosts, Login_password);
- Set_object_editable(Hosts, Login_name);
- Set_object_editable(Hosts, Ip_address);
- Set_object_editable(Hosts, Server_name);
- Set_dialog_Kfocus(Hosts, Server_name);
-
- // Setup the GEMLIST standard keyboard shortcuts.
- Set_standard_keyboard();
- Set_dialog_Kfocus_policy(Hosts, FOCUS_FIELD);
- Set_dialog_Kfocus_policy(Open_new, FOCUS_FIELD);
- Set_key_callback(0x3000, &Kdispatcher); // ALT+B = Bookmarks
- Set_key_callback(0x2100, &Kdispatcher); // ALT+F = File transfer
- Set_key_callback(0x1f13, &save_servers); // ^S = Save Bookmarks
- Set_key_callback(0x1800, &Kdispatcher); // ALT+O = Open FTP
- Set_key_callback(0x2e00, &close_current_session); // ALT+C = Close current session
-
- // Attatch the dialog dispatcher to menu options that open windows
- Set_object_callback(Mainmenu, About_ftp, &dispatcher);
- Set_object_callback(Mainmenu, Win_ftp, &dispatcher);
- Set_object_callback(Mainmenu, Win_hosts, &dispatcher);
-
- // debug stuff - setup a scan code reporter in the About Dialog
- Set_dialog_Kcallback(About, &scan_code_reporter);
-
- initialise_ftp();
-
- // Hook in a few signal handlers
- // signal(SIGINT, int_sig_handler); // Interupt
- // signal(SIGILL, illegal_sig); // Illegal instruction - try to catch errors
- // signal(SIGBUS, berr_sig); // Bus error - hope to catch bad pointers
-
- // Initially, localhost is the selected server - always last entry in file:ie. first server in list
- selected_server=servers;
- set_dialog_text(Mainwindow, This_server, selected_server->name);
-
- // Remote directory listing - set to empty
- remote_directory=NULL;
- remote_files=(char **)malloc(sizeof(char*));
- file_count=0;
- remote_files[0]=" ";
- Set_scroll_list(Mainwindow, Remote_fs, mev_REMOTEFILE, remote_files, 1, 11);
- Set_scroll_list(Mainwindow, Local_fs, mev_LOCALFILE, remote_files, 1, 11);
- Set_object_devent(Mainwindow, Remote_fs+scroll_text_area, mev_CHANGEREMOTEDIR);
- set_dialog_text(Mainwindow, Remote_path, " ");
-
- // Local directory listing
- sprintf(current_local_path, "%s", initial_dir);
- local_files=NULL;
- local_directory=NULL;
- get_local_files();
- if (local_files) free(local_files);
- d=file_count;
- local_files=extract_filenames(local_directory);
- local_file_count=file_count;
- file_count=d;
- Change_scroll_list(Mainwindow, Local_fs, local_files, local_file_count+1);
- Set_object_devent(Mainwindow, Local_fs+scroll_text_area, mev_CHANGELOCALDIR);
- set_dialog_text(Mainwindow, Local_path, current_local_path);
-
- // Set the version date in the about dialog
- sprintf(version_string, "Version date:%s time:%s",__DATE__,__TIME__);
- set_dialog_text(About, Version_date, version_string);
-
- // Hypertext help
- Set_application_helpfile("DUFTP.HYP"); // The application's help file
- Set_dialog_help_topic(Mainwindow,"Getting Files"); // Setup the context sensitive help system
- Set_dialog_help_topic(Open_new,"FTP Connections");
- Set_dialog_help_topic(Hosts,"Bookmarks");
- Set_dialog_help_topic(About,"Introduction");
- }
-
- void reset_remote_list(void)
- {
- file_count=0;
- if (remote_files) free(remote_files);
- remote_files=(char **)malloc(sizeof(char*));
- file_count=0;
- remote_files[0]=" ";
- Change_scroll_list(Mainwindow, Remote_fs, remote_files, 1);
- set_dialog_text(Mainwindow, Remote_path, " ");
- }
-