home *** CD-ROM | disk | FTP | other *** search
- /**************************/
- /* ANSI standard includes */
- /**************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <kernel.h>
- #include <swis.h>
-
- /***********************/
- /* risc_oslib includes */
- /***********************/
-
- #include "risc_oslib:wimp.h"
- #include "risc_oslib:menu.h"
- #include "risc_oslib:wimpt.h"
- #include "risc_oslib:baricon.h"
- #include "risc_oslib:werr.h"
- #include "RISC_OSlib:res.h"
- #include "RISC_OSlib:resspr.h"
- #include "RISC_OSlib:event.h"
- #include "RISC_OSlib:win.h"
- #include "RISC_OSlib:template.h"
- #include "RISC_OSlib:dbox.h"
- #include "RISC_OSlib:os.h"
- #include "RISC_OSlib:bbc.h"
-
- /********************/
- /* desklib includes */
- /********************/
-
- #include "Desklib:mem.h"
-
- /********************/
- /* worzlib includes */
- /********************/
-
- #include "Worzlib:hglass.h"
-
- /******************/
- /* local includes */
- /******************/
-
- #include "LZWmodule.h"
- #include "LZWstuff.h"
- /* #include "hglass.h" */
-
- /*****************/
- /* local defines */
- /*****************/
-
- /* none */
-
- /********************/
- /* global variables */
- /********************/
-
- dbox main_window; /* the window number of the main window */
- int state=STATE_no_backup; /* the state of the program i.e. no_backup, load file etc. */
- FILE *include_handle=0; /* file handle of the include file */
- void *exclude_file_pointer=0; /* pointer to exclude file in memory */
- int exclude_file_length=0; /* length of exclude file in memory */
- void *compressed_data=0; /* pointer to the compressed file in memory */
- void *original_data=0; /* pointer to the source file in memory */
- void *floppy_data=0; /* pointer to the data in memory that will be written to the floppy */
- int compressed_data_length=0; /* length of compressed data in memory */
- int original_data_length=0; /* length of source file in memory */
- int floppy_data_length=0; /* length of the data to be written to the floppy */
- char header_block[FILE_HEADER_LENGTH]; /* for the header info to be created in */
- int floppy_count; /* number of the floppy disc in the series */
- char floppy_file_name[255]; /* partial file name of the floppy file */
- int event_count=0; /* for keeping count of events processed in the main loop */
- char version[]="1.0 (Nov 1994)"; /* version string in info box */
-
- /***********************/
- /* function prototypes */
- /***********************/
-
- static void ibar_select(wimp_i icon_number); /**/
- static void main_window_handler(dbox dbox_number, void *handle); /**/
- static void ibar_load(wimp_eventstr *data_block, void *handle); /**/
- static void load_next_file(void); /**/
- static void compress_next_file(void); /**/
- static void write_next_file(void); /**/
- static void abort_button_clicked(void); /**/
- static void go_button_clicked(void); /**/
- static void continue_button_clicked(void); /**/
- static void open_main_window(void); /**/
- static void show_info_box(void); /**/
- static void list_files(char *dir_name, FILE *list_handle); /**/
- static void end_backup(void); /**/
- static int in_exclude_list(char *filename); /**/
- static void write_next_directory(void); /**/
- static int prompt_for_floppy(void); /**/
- static void ibar_menu(void *h, char *hit); /**/
- static int floppy_free_space(void); /**/
- static int erase_floppy(void); /**/
- static void create_empty_file(char *file_name); /**/
-
- /****************/
- /* program code */
- /****************/
-
- /* start of main */
- int main(void)
- {
- /* create variables */
- menu icon_menu; /* the menu number of the menu attached to the icon bar icon */
-
- /* do the initialisations */
- wimpt_init("LZW Backup");
- res_init("LZWbackup");
- resspr_init();
- template_init();
- dbox_init();
- Mem_Initialise();
-
- /* show the icon on the icon bar */
- baricon("!lzwbackup", 1, ibar_select);
-
- /* create the menu for the icon bar icon */
- icon_menu=menu_new("LZW Backup",">Info,Show Include List,Show Exclude List,Clear Include List,Clear Exclude List,Show Main Window,Quit");
-
- /* attach the menu to the icon bar icon, quit with a message if the attach fails */
- if(!event_attachmenu(win_ICONBAR, icon_menu, ibar_menu, 0))
- werr(1,"Unable to attach icon bar menu");
-
- /* create main window, quit with an error message if it fails */
- main_window=dbox_new("main");
- if(!main_window)
- werr(1,"Error creating dbox for main");
-
- /* set the fields in the main window to default values */
- dbox_setfield(main_window, MAIN_WINDOW_osize, "\0");
- dbox_setfield(main_window, MAIN_WINDOW_csize, "\0");
- dbox_setfield(main_window, MAIN_WINDOW_fspace, "\0");
- dbox_setfield(main_window, MAIN_WINDOW_comment, "Hello World");
- dbox_setfield(main_window, MAIN_WINDOW_source_fname, "\0");
- dbox_setfield(main_window, MAIN_WINDOW_floppy_fname, "Backup");
-
- /* activate/deactivate the required buttons */
- dbox_unfadefield(main_window, MAIN_WINDOW_go);
- dbox_unfadefield(main_window, MAIN_WINDOW_inc_disc_name);
- dbox_unfadefield(main_window, MAIN_WINDOW_inc_dirs);
- dbox_fadefield(main_window, MAIN_WINDOW_continue);
- dbox_fadefield(main_window, MAIN_WINDOW_abort);
-
- /* register main_window_handler() as the function to decode mouse clicks on the main window */
- dbox_eventhandler(main_window, main_window_handler, 0);
-
- /* register ibar_load() as the function to handle a file icon being dropped on the icon bar icon */
- win_register_event_handler(win_ICONBARLOAD, ibar_load, 0);
-
- /* main Wimp_Poll loop */
- while(TRUE)
- {
- event_process();
- if(!event_count--)
- {
- event_count=4; /* only does one of our jobs every n events */
- switch(state)
- {
- case STATE_no_backup: /* do nothing */
- break;
- case STATE_load: /* load a file into memory */
- load_next_file();
- /* new state gets set by load_next_file */
- break;
- case STATE_compress: /* compress the file in memory */
- compress_next_file();
- state=STATE_write_file;
- break;
- case STATE_write_file: /* write file to floppy */
- write_next_file();
- state=STATE_load;
- break;
- case STATE_write_directory: /* write directory to floppy */
- write_next_directory();
- state=STATE_load;
- break;
- default: /* what sort of state is this ?? */
- abort_button_clicked();
- }
- }
- }
- }
- /* end of main() */
-
- /* start of ibar_select */
- static void ibar_select(wimp_i icon_number)
- {
- open_main_window();
- }
- /* end of ibar_select */
-
- /* start of main_window_handler */
- /* called when the mouse is clicked on the main window */
- static void main_window_handler(dbox dbox_number, void *handle)
- {
- /* create variables */
-
- switch (dbox_get(dbox_number))
- {
- case MAIN_WINDOW_go: /* the go button */
- go_button_clicked();
- break;
- case MAIN_WINDOW_abort: /* the abort button */
- abort_button_clicked();
- break;
- case MAIN_WINDOW_continue: /* the continue button */
- continue_button_clicked();
- break;
- case -1: /* the go away button */
- dbox_hide(dbox_number);
- break;
- /* default: */
- /* do nothing */
- }
- }
- /* end of main_window_handler */
-
- /* start of go_button_clicked */
- static void go_button_clicked(void)
- {
- /* create variables */
- _kernel_swi_regs regs;
- _kernel_oserror *error;
- char floppy_full_name[255];
-
- /* activate/deactivate the required buttons */
- dbox_unfadefield(main_window, MAIN_WINDOW_abort);
- dbox_fadefield(main_window, MAIN_WINDOW_go);
- dbox_fadefield(main_window, MAIN_WINDOW_continue);
- dbox_fadefield(main_window, MAIN_WINDOW_floppy_fname);
- dbox_fadefield(main_window, MAIN_WINDOW_inc_dirs);
- dbox_fadefield(main_window, MAIN_WINDOW_inc_disc_name);
-
- /* get the filename to use on the floppy */
- dbox_getfield(main_window, MAIN_WINDOW_floppy_fname, floppy_file_name,7);
-
- /* open the include file */
- include_handle=fopen("<LZWbackup$include>","r");
- if(!include_handle)
- {
- open_main_window();
- dbox_setfield(main_window, MAIN_WINDOW_comment,"No Include list file available");
- bbc_vdu(7);
- end_backup();
- return;
- }
-
- /* load the exclude file */
- /* get info on the exclude file */
- regs.r[0]=5;
- regs.r[1]=(int)"<LZWbackup$exclude>";
- error=_kernel_swi(OS_File,®s,®s);
- if(error)
- werr(1,"Error %d in OS_File 5 in main_window_handler, %s.",error->errnum,error->errmess);
- exclude_file_length=regs.r[4];
-
- switch(regs.r[0])
- {
- case 0: /* exclude file not found */
- exclude_file_pointer=0;
- exclude_file_length=0;
- break;
- case 1: /* exclude file found ok */
- if(exclude_file_length>0)
- {
- Mem_Alloc(&exclude_file_pointer, exclude_file_length+1);
- if(!exclude_file_pointer)
- werr(1,"Unable to malloc %d bytes for the exclude file.",exclude_file_length);
- regs.r[0]=0xff; /* load file */
- regs.r[1]=(int)"<LZWbackup$exclude>";
- regs.r[2]=(int)exclude_file_pointer;
- regs.r[3]=0;
- error=_kernel_swi(OS_File,®s,®s);
- if(error)
- werr(1,"Error %d in OS_File 0xff in main_window_handler, %s.",error->errnum,error->errmess);
- }
- else
- {
- exclude_file_pointer=0;
- exclude_file_length=0;
- }
- break;
- default: /* exclude file of an unrecognised type */
- werr(0,"Exclude file is of an unrecognised type");
- exclude_file_pointer=0;
- exclude_file_length=0;
- }
-
- /* allow null events */
- event_setmask(0);
-
- /* erase the floppy in the drive */
- do {
- if(prompt_for_floppy()==MAIN_WINDOW_abort)
- {
- abort_button_clicked();
- return;
- }
- } while(!erase_floppy());
-
- /* reset the floppy disc counter */
- floppy_count=0;
-
- /* create the empty file */
- sprintf(floppy_full_name,"ADFS::0.$.%s_%0.2d",floppy_file_name,floppy_count);
- create_empty_file(floppy_full_name);
-
- /* set the state variable to load next file */
- state=STATE_load;
- }
- /* end of go_button_clicked() */
-
- /* start of abort_button_clicked() */
- static void abort_button_clicked(void)
- {
- dbox_setfield(main_window, MAIN_WINDOW_comment, "Backup Aborted");
- end_backup();
- }
- /* end of abort_button_clicked() */
-
- /* start of ibar_load() */
- /* this takes the filename given and appends it to the include file */
- /* if it is a directory, it appends the contents to the include file */
- static void ibar_load(wimp_eventstr *data_block, void *handle)
- {
- /* create variables */
- FILE *out_handle; /* file handle for include file */
- os_filestr os_file_block; /* data block for os_file */
- os_error *error; /* pointer to data block for any error returned from os_file */
-
- os_file_block.action = 5; /* read catalog info */
- os_file_block.name = data_block->data.msg.data.dataload.name; /* set pointer to file name */
- error = os_file(&os_file_block);
- if(error)
- werr(0,"Error %d in os_file in ibar_load. %s", error->errnum, error->errmess);
-
- out_handle=fopen("<LZWbackup$include>","a");
- if(!out_handle)
- werr(1,"Error opening include file for append in extend_include_file");
-
- hglass_on();
- switch (os_file_block.action)
- {
- case 1: /* it's a file */
- fprintf(out_handle,"%s\n",os_file_block.name);
- break;
- case 2: /* it's a directory */
- fprintf(out_handle,"%s\n",os_file_block.name);
- list_files(os_file_block.name, out_handle);
- break;
- default: /* what the #$!* is that ??? */
- break;
- }
- hglass_off();
-
- fclose(out_handle);
- }
-
- /* start of show_info_box */
- void show_info_box(void)
- {
- dbox d=dbox_new("info");
- if(d!=NULL)
- {
- dbox_show(d);
- dbox_setfield(d, 0, version);
- dbox_fillin(d);
- dbox_dispose(&d);
- }
- }
- /* end of show_info_box() */
-
- /* start of list_files */
- void list_files(char *dir_name, FILE *list_handle)
- {
- /* create variables */
- char dir_space[33*77], file_name[12], full_file_name[200];
- char *dir_space_pointer;
- int number_of_files, file_count;
- _kernel_oserror *error;
- _kernel_swi_regs regs;
-
- regs.r[0]=10; /* read directory info */
- regs.r[1]=(int)dir_name;
- regs.r[2]=(int)dir_space;
- regs.r[3]=77; /* number of entries in a directory */
- regs.r[4]=0;
- regs.r[5]=77*32;
- regs.r[6]=(int)"*";
- error=_kernel_swi(OS_GBPB, ®s, ®s);
- if(error)
- {
- werr(1,"Error %d in OS_GPBP in list_files() %s",error->errnum,error->errmess);
- hglass_off();
- }
-
- number_of_files=regs.r[3];
- dir_space_pointer=dir_space;
- for(file_count=1; file_count<=number_of_files; file_count++)
- {
- strcpy(file_name,(dir_space_pointer+0x14));
- sprintf(full_file_name,"%s.%s",dir_name,file_name);
- printf("%s\n",full_file_name);
- fprintf(list_handle,"%s\n",full_file_name);
- if(*(dir_space_pointer+0x10)==2)
- list_files(full_file_name, list_handle);
- dir_space_pointer+=0x14;
- while(*(dir_space_pointer++)!=0);
- while((int)dir_space_pointer%4 !=0) dir_space_pointer++;
- }
- }
- /* end of list_files() */
-
- /* start of open_main_window */
- static void open_main_window(void)
- {
- dbox_showstatic(main_window);
- }
- /* end of open_main_window */
-
- /* start of end_backup */
- static void end_backup(void)
- {
- /* activate/deactivate the required buttons */
- dbox_unfadefield(main_window, MAIN_WINDOW_go);
- dbox_unfadefield(main_window, MAIN_WINDOW_floppy_fname);
- dbox_unfadefield(main_window, MAIN_WINDOW_inc_dirs);
- dbox_unfadefield(main_window, MAIN_WINDOW_inc_disc_name);
- dbox_fadefield(main_window, MAIN_WINDOW_continue);
- dbox_fadefield(main_window, MAIN_WINDOW_abort);
-
- /* close the include file */
- if(include_handle)
- {
- fclose(include_handle);
- include_handle=0;
- }
-
- /* free the space used by the exclude file */
- if(exclude_file_pointer)
- {
- Mem_Free(&exclude_file_pointer);
- exclude_file_pointer=0;
- exclude_file_length=0;
- }
-
- /* dissallow null events */
- event_setmask(1);
-
- /* set the state variable go dormant */
- state=STATE_no_backup;
- }
- /* end of end_backup */
-
- /* start of load_next_file */
- static void load_next_file(void)
- {
- /* create variables */
- char next_file_name[255]; /* next filename read from the include list */
- _kernel_swi_regs regs,file_info;
- _kernel_oserror *error;
- char comment[100]; /* string for comments */
- int gp_count; /* GP counter */
- char *filename_to_use; /* the file name written to the floppy */
-
- /* get next filename from include list */
- fgets(next_file_name, 254, include_handle);
-
- /* remove any non-alpha characters from next_file_name */
- for(gp_count=0; next_file_name[gp_count]>32; gp_count++);
- next_file_name[gp_count]=0;
-
- if(feof(include_handle))
- {
- dbox_setfield(main_window,MAIN_WINDOW_comment,"Backup completed");
- end_backup();
- return;
- }
-
- dbox_setfield(main_window, MAIN_WINDOW_source_fname, next_file_name);
- if(exclude_file_pointer)
- if(in_exclude_list(next_file_name))
- {
- dbox_setfield(main_window, MAIN_WINDOW_comment, "File Excluded");
- return;
- }
-
- /* get info for source file */
- regs.r[0]=5; /* read catalog info */
- regs.r[1]=(int)next_file_name;
- error = _kernel_swi(OS_File, ®s, &file_info);
- if(error)
- werr(1,"Error %d in OS_File in load_next_file(). %s",error->errnum,error->errmess);
-
- switch(file_info.r[0])
- {
- case 0: /* file not found */
- dbox_setfield(main_window, MAIN_WINDOW_comment, "Not Found");
- return;
- break;
- case 1: /* file found ok */
- dbox_setfield(main_window, MAIN_WINDOW_comment, "\0");
- original_data_length=file_info.r[4];
- dbox_setnumeric(main_window, MAIN_WINDOW_osize, original_data_length);
-
- /* allocate memory for the source file */
- Mem_Alloc(&original_data, original_data_length + EXTRA_WORK_SPACE);
- if(!original_data)
- werr(1,"Unable to allocate %d bytes for original data",original_data_length);
-
- /* load file into memory */
- regs.r[0]=0xff; /* load file */
- regs.r[1]=(int)next_file_name;
- regs.r[2]=(int)original_data;
- regs.r[3]=0;
- error=_kernel_swi(OS_File,®s,®s);
- if(error)
- werr(1,"Error %d in OS_File 0xff in load_next_file, %s.",error->errnum,error->errmess);
-
- /* fill header block */
- /*
- 0: compressed length including header (gets written later)
- 4: load address r2
- 8: execute address r3
- 12: uncompressed length r4
- 16: file attributes r5
- 20: object type r0 (probably not needed, but it's here anyway)
- 24: full file name (0 terminated)
- */
-
- *(int *)(header_block+4)=file_info.r[2];
- *(int *)(header_block+8)=file_info.r[3];
- *(int *)(header_block+12)=file_info.r[4];
- *(int *)(header_block+16)=file_info.r[5];
- *(int *)(header_block+20)=file_info.r[0];
-
- /* chop the disc name off the full file name if required */
- filename_to_use=next_file_name;
- if(!dbox_getnumeric(main_window,MAIN_WINDOW_inc_disc_name) )
- while(*filename_to_use != '$')
- filename_to_use++;
- strncpy((header_block+24),filename_to_use,(FILE_HEADER_LENGTH-25));
-
- state=STATE_compress;
- break;
- case 2: /* found a directory */
- if(!dbox_getnumeric(main_window, MAIN_WINDOW_inc_dirs) )
- {
- state=STATE_load;
- return;
- }
- dbox_setfield(main_window, MAIN_WINDOW_comment, "Directory");
-
- /* fill header block */
- /*
- 0: compressed length including header (0 for a directory)
- 4: load address r2
- 8: execute address r3
- 12: uncompressed length r4 (0 for a directory)
- 16: file attributes r5
- 20: object type r0 (probably not needed, but it's here anyway)
- 24: full file name (0 terminated)
- */
-
- *(int *)(header_block+0)=0;
- *(int *)(header_block+4)=file_info.r[2];
- *(int *)(header_block+8)=file_info.r[3];
- *(int *)(header_block+12)=0;
- *(int *)(header_block+16)=file_info.r[5];
- *(int *)(header_block+20)=file_info.r[0];
-
- /* chop the disc name off the full file name if required */
- filename_to_use=next_file_name;
- if(!dbox_getnumeric(main_window,MAIN_WINDOW_inc_disc_name) )
- while(*filename_to_use != '$')
- filename_to_use++;
- strncpy((header_block+24),filename_to_use,(FILE_HEADER_LENGTH-25));
-
- state=STATE_write_directory;
- break;
- default:
- sprintf(comment,"%s is of unknown type %d\n",next_file_name,file_info.r[0]);
- dbox_setfield(main_window, MAIN_WINDOW_comment, comment);
- break;
- }
- }
- /* end of load_next_file */
-
- /* start of compress_next_file */
- static void compress_next_file(void)
- {
- /* create variables */
- _kernel_swi_regs regs;
- _kernel_oserror *error;
-
- /* allocate memory to compress file into */
- Mem_Alloc(&compressed_data, original_data_length * 3/2 + EXTRA_WORK_SPACE);
- if(!compressed_data)
- werr(1,"Unable to allocate %d bytes for compressed data",original_data_length * 3/2 + EXTRA_WORK_SPACE);
-
- /* compress the file into memory */
- regs.r[0]=3; /* source and destination in memory */
- regs.r[1]=(int)original_data;
- regs.r[2]=(int)compressed_data;
- regs.r[3]=original_data_length;
- regs.r[4]=original_data_length * 3/2 + EXTRA_WORK_SPACE;
-
- hglass_on();
- hglass_leds(HGLASS_LEDS_top);
- error=_kernel_swi(LZW_Compress, ®s, ®s);
- hglass_off();
- if(error)
- werr(1,"Error %d in LZW_Compress in compress_next_file. %s",error->errnum, error->errmess);
-
- compressed_data_length=regs.r[5];
- dbox_setnumeric(main_window, MAIN_WINDOW_csize, compressed_data_length);
- if(compressed_data_length >= original_data_length)
- {
- /* announce the fact */
- dbox_setfield(main_window, MAIN_WINDOW_comment, "The compressed version is longer than the original");
-
- /* set floppy pointer and length to the original data */
- floppy_data=original_data;
- floppy_data_length=original_data_length;
- }
- else
- {
- /* set floppy_pointer and length to the compressed data */
- floppy_data=compressed_data;
- floppy_data_length=compressed_data_length;
- }
-
- *(int *)header_block=floppy_data_length;
- }
- /* end of compress_next_file */
-
- /* start of prompt_for_floppy */
- static int prompt_for_floppy(void)
- {
- /* create variables */
- int quit,button;
-
- /* enable/disable the required buttons */
- dbox_unfadefield(main_window, MAIN_WINDOW_abort);
- dbox_unfadefield(main_window, MAIN_WINDOW_continue);
- dbox_fadefield(main_window, MAIN_WINDOW_go);
- dbox_fadefield(main_window, MAIN_WINDOW_inc_dirs);
- dbox_fadefield(main_window, MAIN_WINDOW_inc_disc_name);
-
- open_main_window();
- dbox_setfield(main_window, MAIN_WINDOW_comment, "Insert new floppy disc in drive 0");
- bbc_vdu(7);
-
- dbox_eventhandler(main_window,0,0);
- quit=FALSE;
- while(!quit)
- {
- button=(int)dbox_fillin(main_window);
- switch(button)
- {
- case MAIN_WINDOW_continue:
- case MAIN_WINDOW_abort:
- quit=TRUE;
- break;
- /* default: */
- /* not interested in any other buttons */
- }
- }
- dbox_eventhandler(main_window,main_window_handler,0);
-
- /* disable continue button */
- dbox_fadefield(main_window, MAIN_WINDOW_continue);
- return(button);
- }
- /* end of prompt_for_floppy */
-
- /* start of write_next_file */
- static void write_next_file(void)
- {
- /* create variables */
- FILE *floppy_handle; /* handle of the file on the floppy */
- int space_on_floppy; /* space left on the floppy */
- char floppy_full_name[255]; /* complete name of the floppy file */
- int count; /* GP counter for writing stuff, byte at a time */
- char *gp_count; /* GP char pointer for writing the compressed file */
-
- space_on_floppy=floppy_free_space();
-
- /* wait for a floppy with enough free space */
- while(space_on_floppy < (floppy_data_length+24+strlen(header_block+24)))
- {
- do {
- if(prompt_for_floppy()==MAIN_WINDOW_abort)
- {
- abort_button_clicked();
- return;
- }
- } while(!erase_floppy());
- floppy_count++;
-
- /* create the empty file */
- sprintf(floppy_full_name,"ADFS::0.$.%s_%0.2d",floppy_file_name,floppy_count);
- create_empty_file(floppy_full_name);
-
- space_on_floppy=floppy_free_space();
- }
-
- sprintf(floppy_full_name,"ADFS::0.$.%s_%0.2d",floppy_file_name,floppy_count);
-
- dbox_setnumeric(main_window, MAIN_WINDOW_fspace, space_on_floppy);
-
- /* open floppy file for appending */
- floppy_handle=fopen(floppy_full_name,"a");
- if(!floppy_handle)
- werr(1,"Unable to open %s for appending",floppy_full_name);
-
- /* append header to floppy */
- for(count=0; count<24; fputc(header_block[count++], floppy_handle)); /* file info */
- fputs(header_block+24, floppy_handle); /* file name */
- fputc(0, floppy_handle); /* terminating null */
-
- /* append file to floppy */
- hglass_on();
- hglass_leds(HGLASS_LEDS_bottom);
- gp_count=floppy_data;
- for(count=0; count<floppy_data_length; count++, gp_count++)
- fputc(*gp_count,floppy_handle);
-
- /* close floppy file */
- fclose(floppy_handle);
- hglass_off();
-
- /* free memory */
- Mem_Free(&original_data);
- Mem_Free(&compressed_data);
- compressed_data=0;
- original_data=0;
- compressed_data_length=0;
- original_data_length=0;
- }
- /* end of write_next_file */
-
- /* start of in_exclude_list */
- int in_exclude_list(char *f_name)
- {
- /* create variables */
- char *exclude_file_place=exclude_file_pointer; /* pointer to current place in exclude file in memory */
- char name_in_list[255]; /* file name extracted from list */
- int count; /* GP counter */
- char file_name[255]; /* local copy of the file name */
-
- /* if there is no list, return FALSE */
- if(!exclude_file_pointer)
- return(FALSE);
-
- strcpy(file_name,f_name);
-
- while((int)exclude_file_place<(int)exclude_file_pointer+exclude_file_length-1)
- {
- /* advance to next alpha-numeric character */
- for(; *exclude_file_place<33 || *exclude_file_place>126; exclude_file_place++);
-
- /* get name from list into name_in_list */
- for(count=0; *exclude_file_place>31; name_in_list[count++]=*exclude_file_place++);
- name_in_list[count]=0;
-
- /* strip trailing * from name_in_list */
- for(count=0; name_in_list[count] && name_in_list[count]!='*'; count++);
- name_in_list[count]=0;
-
- /*
- werr(0,"name_in_list= %s",name_in_list);
- werr(0,"file_name= %s",file_name);
- */
-
- /* do the comparison */
- /* if(!strncmp(name_in_list, file_name, strlen(name_in_list) ) ) */
- file_name[strlen(name_in_list)]=0;
- if(!strcmp(name_in_list, file_name) )
- {
- /* werr(0,"returning TRUE"); */
- return(TRUE);
- }
-
- }
- /* werr(0,"returning FALSE"); */
- return(FALSE);
- }
- /* end of in_exclude_list */
-
- /* start of write_next_directory */
- static void write_next_directory(void)
- {
- /* create variables */
- FILE *floppy_handle; /* handle of the file on the floppy */
- int space_on_floppy; /* space left on the floppy */
- char floppy_full_name[255]; /* complete name of the floppy file */
- int count; /* GP counter for writing stuff, byte at a time */
-
- space_on_floppy=floppy_free_space();
-
- /* wait for a floppy with enough free space */
- while(space_on_floppy < (24+strlen(header_block+24)))
- {
- do {
- if(prompt_for_floppy()==MAIN_WINDOW_abort)
- {
- abort_button_clicked();
- return;
- }
- } while(!erase_floppy());
- floppy_count++;
-
- /* create the empty file */
- sprintf(floppy_full_name,"ADFS::0.$.%s_%0.2d",floppy_file_name,floppy_count);
- create_empty_file(floppy_full_name);
-
- space_on_floppy=floppy_free_space();
- }
-
- sprintf(floppy_full_name,"ADFS::0.$.%s_%0.2d",floppy_file_name,floppy_count);
-
- dbox_setnumeric(main_window, MAIN_WINDOW_fspace, space_on_floppy);
-
- /* open floppy file for appending */
- floppy_handle=fopen(floppy_full_name,"a");
- if(!floppy_handle)
- werr(1,"Unable to open %s for appending",floppy_full_name);
-
- /* append header to floppy */
- for(count=0; count<24; fputc(header_block[count++], floppy_handle)); /* file info */
- fputs(header_block+24, floppy_handle); /* file name */
- fputc(0, floppy_handle); /* terminating null */
-
- /* close floppy file */
- fclose(floppy_handle);
-
- }
- /* end of write_next_directory */
-
- /* start of ibar_menu */
- static void ibar_menu(void *handle, char *hit)
- {
- switch(hit[0])
- {
- case 1:
- show_info_box();
- break;
- case 2:
- wimp_starttask("taskwindow \"type <LZWbackup$include>\" -name \"LZWbackup include\" -wimpslot 32K -quit");
- break;
- case 3:
- wimp_starttask("taskwindow \"type <LZWbackup$exclude>\" -name \"LZWbackup exclude\" -wimpslot 32K -quit");
- break;
- case 4:
- _kernel_oscli("wipe <LZWbackup$include> ~cf~r~v");
- break;
- case 5:
- _kernel_oscli("wipe <LZWbackup$exclude> ~cf~r~v");
- break;
- case 6:
- open_main_window();
- break;
- case 7:
- exit(0);
- break;
- }
- }
- /* end of ibar_menu */
-
- /* start of floppy_free_space */
- static int floppy_free_space(void)
- {
- /* create variables */
- _kernel_swi_regs regs;
- _kernel_oserror *error;
-
- regs.r[0]=(int)"0";
- error=_kernel_swi(ADFS_FreeSpace, ®s, ®s);
- if(error)
- werr(1,"Error %d in ADFS_FreeSpace in floppy_free_space(). %s",error->errnum, error->errmess);
-
- return(regs.r[0]);
- }
- /* end of floppy_free_space */
-
- /* start of erase_floppy */
- static int erase_floppy(void)
- {
- /* create variables */
- _kernel_swi_regs regs;
- _kernel_oserror *error;
-
- dbox_setfield(main_window,9,"Erasing Drive 0.");
- regs.r[0]=(int)"wipe ADFS::0.$.* ~cfr~v \n";
- error = _kernel_swi(OS_CLI, ®s, ®s);
- if(error)
- {
- switch(error->errnum)
- {
- case 1046: /* nothing to delete */
-
- /* so just exit */
- return(TRUE);
- break;
- default:
- werr(0,"Error %d in OS_CLI in erase_floppy(). %s",error->errnum, error->errmess);
- return(FALSE);
- break;
- }
- }
- return(TRUE);
- }
- /* end of erase_floppy */
-
- /* start of create_empty_file */
- static void create_empty_file(char *file_name)
- {
- /* create variables */
- _kernel_swi_regs regs;
- _kernel_oserror *error;
-
- regs.r[0]=0x0b; /* create empty file */
- regs.r[1]=(int)file_name;
- regs.r[2]=BACKUP_FILE_TYPE;
- regs.r[4]=0;
- regs.r[5]=0;
- error = _kernel_swi(OS_File, ®s, ®s);
- if(error)
- werr(1,"Error %d in OS_File in create_empty_file(). %s",error->errnum, error->errmess);
- }
- /* end of create_empty_file */
-
- /* start of continue_button_clicked */
- static void continue_button_clicked(void)
- {
- if(state & STATE_wait_for_continue)
- state&=(!STATE_wait_for_continue);
- }
- /* end of continue_button_clicked */
-
-