From 7ec020a057262a84c6ef8f1ab3c7088390ef4ed9 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Sun, 13 Dec 1998 02:50:33 +0000 Subject: [PATCH] Convert CR-->LF in sources; they were checked in with the wrong newline delimiters. --- sys/fileport/fileport/FilePort.Doc | 62 ++- sys/fileport/fileport/Makefile | 30 +- sys/fileport/fileport/c.port.c | 542 ++++++++++++++++++++- sys/fileport/fileport/errormsgs.asm | 104 +++- sys/fileport/fileport/errors.c | 146 +++++- sys/fileport/fileport/errors.h | 82 +++- sys/fileport/fileport/fileport.data | 2 +- sys/fileport/fileport/port.asm | 731 +++++++++++++++++++++++++++- sys/fileport/fileport/port.macros | 324 +++++++++++- sys/fileport/fileport/test.c | 18 +- sys/fileport/fileport/testiw.c | 40 +- sys/fileport/includes/KS.CDEV.h | 523 +++++++++++++++++++- sys/fileport/includes/KS.Defines.h | 206 +++++++- sys/fileport/includes/KS.FileIO.e | 375 +++++++++++++- sys/fileport/includes/KS.Memory.h | 86 +++- sys/fileport/includes/KS.Routines.h | 152 +++++- sys/fileport/includes/Portable.C.h | 110 ++++- sys/fileport/includes/SharedData.h | 168 ++++++- sys/fileport/support/AddPath.c | 84 +++- sys/fileport/support/ChangeAux.c | 100 +++- sys/fileport/support/Close.c | 142 +++++- sys/fileport/support/Create.c | 94 +++- sys/fileport/support/Data.c | 42 +- sys/fileport/support/Delete.c | 85 +++- sys/fileport/support/GetBufSize.c | 70 ++- sys/fileport/support/GetVolume.c | 91 +++- sys/fileport/support/MSGReceive.c | 141 +++++- sys/fileport/support/MSGSend.c | 187 ++++++- sys/fileport/support/Makefile | 68 ++- sys/fileport/support/Open.c | 191 +++++++- sys/fileport/support/Read.c | 344 ++++++++++++- sys/fileport/support/Rename.c | 79 ++- sys/fileport/support/SetBufSize.c | 71 ++- sys/fileport/support/SetDir.c | 92 +++- sys/fileport/support/SetEOF.c | 87 +++- sys/fileport/support/Space.c | 117 ++++- sys/fileport/support/Write.c | 286 ++++++++++- sys/fileport/support/gnfn.c | 106 +++- sys/fileport/support/ks.fileIO.h | 131 ++++- sys/fileport/support/linkit | 21 +- 40 files changed, 6290 insertions(+), 40 deletions(-) diff --git a/sys/fileport/fileport/FilePort.Doc b/sys/fileport/fileport/FilePort.Doc index 58f5e93..1a02315 100644 --- a/sys/fileport/fileport/FilePort.Doc +++ b/sys/fileport/fileport/FilePort.Doc @@ -1 +1,61 @@ - FilePort is a Port Driver that simply prints to a file (instead of a printer port). If you need to capture output from a printer driver to print something on a printer you don't own then this port driver might be what you're looking for. The only restriction that this software has is that appletalk printer drivers aren't supported (so don't try using this port driver with the laserwriter driver, you'll crash into the monitor). NullPort is another Port Driver - this port driver doesn't print to anything. It seems kind of strange, but this is actually very usefull. Especially when you want to time the performance of a printer driver. Almost everyone assumes the printer driver is the slow part, when actually the slowest portions of printing are typically the transfering of data to the printer and actually printing. This port driver can be used by anyone to time just about any printer driver (again, the laserwriter driver isn't supported). Requirements: An Apple IIGS with probably 1.5 meg of memory or more, possibly a hard disk drive and system software 5.0.4 or later. The FilePort driver uses a 64k buffer so you'll need at least that much free memory to be able to use it to print to a file. Installation: Copy all of the files in this archive to your system disk and put them in your system:drivers folder. Select the direct connect printer control panel document and choose FilePort (or NullPort) from the port driver list. To change the folder where printer data files will be generated, simply edit the FilePort.Data file with any text editor and change the pathname. These programs are FreeWare - Do anything you want to with them. The sources to these programs are available to programmers that are interested - simply send me a blank diskette (3.5" only) and a self addressed and stamped return diskette mailer. The sources are a collection or Orca/C and Orca/M. That brings up the runtime libraries of Orca/C so here goes: This program contains material from the Orca/C Run-Time Libraries, copyright 1987-1991 by Byte Works, Inc. Used with permission. I would also like Apple II DTS and Development for their Technotes on printer port drivers - without them I wouldn't have been able to write these drivers. If your computer does something strange with this software then please tell me about it - I'd be interested in what went wrong. If you want to get in contact with me, send regular mail to: Kopriha Software c/o Dave Koppper 81 Main Boulevard Shrewsbury, MA 01545-3146 My electronic mail addresses are: Internet: dave@mystie.webo.dg.com or dave%mystie.webo.dg.com@relay.cs.net GEnie: D.Kopper \ No newline at end of file + +FilePort is a Port Driver that simply prints to a file (instead of a +printer port). If you need to capture output from a printer driver +to print something on a printer you don't own then this port driver +might be what you're looking for. The only restriction that this +software has is that appletalk printer drivers aren't supported +(so don't try using this port driver with the laserwriter driver, +you'll crash into the monitor). + +NullPort is another Port Driver - this port driver doesn't print to +anything. It seems kind of strange, but this is actually very usefull. +Especially when you want to time the performance of a printer driver. +Almost everyone assumes the printer driver is the slow part, when actually +the slowest portions of printing are typically the transfering of data +to the printer and actually printing. This port driver can be used by +anyone to time just about any printer driver (again, the laserwriter +driver isn't supported). + +Requirements: An Apple IIGS with probably 1.5 meg of memory or more, +possibly a hard disk drive and system software 5.0.4 or later. The +FilePort driver uses a 64k buffer so you'll need at least that much +free memory to be able to use it to print to a file. + +Installation: Copy all of the files in this archive to your system +disk and put them in your system:drivers folder. Select the direct +connect printer control panel document and choose FilePort (or NullPort) +from the port driver list. To change the folder where printer data +files will be generated, simply edit the FilePort.Data file with any +text editor and change the pathname. + +These programs are FreeWare - Do anything you want to with them. + +The sources to these programs are available to programmers that are +interested - simply send me a blank diskette (3.5" only) and a self +addressed and stamped return diskette mailer. The sources are a +collection or Orca/C and Orca/M. That brings up the runtime libraries +of Orca/C so here goes: + + This program contains material from the Orca/C + Run-Time Libraries, copyright 1987-1991 + by Byte Works, Inc. Used with permission. + +I would also like Apple II DTS and Development for their Technotes +on printer port drivers - without them I wouldn't have been able to +write these drivers. + +If your computer does something strange with this software then +please tell me about it - I'd be interested in what went wrong. + +If you want to get in contact with me, send regular mail to: + + Kopriha Software + c/o Dave Koppper + 81 Main Boulevard + Shrewsbury, MA 01545-3146 + +My electronic mail addresses are: + + Internet: dave@mystie.webo.dg.com + or dave%mystie.webo.dg.com@relay.cs.net + GEnie: D.Kopper diff --git a/sys/fileport/fileport/Makefile b/sys/fileport/fileport/Makefile index 796e244..6116f71 100644 --- a/sys/fileport/fileport/Makefile +++ b/sys/fileport/fileport/Makefile @@ -1 +1,29 @@ -# # $Id: Makefile,v 1.1 1997/12/19 07:54:44 gdr Exp $ # # Devin Reade, December 1997 ODIR = obj INCLUDE = ../includes CFLAGS += -I$(INCLUDE) -w -v OBJS = $(ODIR)/port.o $(ODIR)/c.port.o $(ODIR)/errors.o $(ODIR)/errormsgs.o LDLIBS = -l ../support/libdvr HDRS = $(INCLUDE)/ks.fileio.e $(INCLUDE)/ks.defines.h \ $(INCLUDE)/portable.c.h $(INCLUDE)/ks.routines.h \ $(INCLUDE)/ks.memory.h build: $(ODIR) FilePort FilePort: $(OBJS) $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS) chtyp -t187 -a2 $@ # 187 == 0xBB $(ODIR): install -d $(ODIR) $(ODIR)/%.o: %.c; $(CC) -o $@ -c $(CFLAGS) $< $(ODIR)/%.o: %.asm; $(CC) -o $@ -c $(CFLAGS) $< port.o:: port.macros c.port.o:: $(HDRS) errors.h errors.o:: $(INCLUDE)/portable.c.h errors.h \ No newline at end of file +# +# $Id: Makefile,v 1.2 1998/12/13 02:47:36 gdr-ftp Exp $ +# +# Devin Reade, December 1997 + +ODIR = obj +INCLUDE = ../includes +CFLAGS += -I$(INCLUDE) -w -v +OBJS = $(ODIR)/port.o $(ODIR)/c.port.o $(ODIR)/errors.o $(ODIR)/errormsgs.o +LDLIBS = -l ../support/libdvr +HDRS = $(INCLUDE)/ks.fileio.e $(INCLUDE)/ks.defines.h \ + $(INCLUDE)/portable.c.h $(INCLUDE)/ks.routines.h \ + $(INCLUDE)/ks.memory.h +build: $(ODIR) FilePort + +FilePort: $(OBJS) + $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS) + chtyp -t187 -a2 $@ +# 187 == 0xBB + +$(ODIR): + install -d $(ODIR) + +$(ODIR)/%.o: %.c; $(CC) -o $@ -c $(CFLAGS) $< +$(ODIR)/%.o: %.asm; $(CC) -o $@ -c $(CFLAGS) $< + +port.o:: port.macros +c.port.o:: $(HDRS) errors.h +errors.o:: $(INCLUDE)/portable.c.h errors.h diff --git a/sys/fileport/fileport/c.port.c b/sys/fileport/fileport/c.port.c index a2cc2d5..27108aa 100644 --- a/sys/fileport/fileport/c.port.c +++ b/sys/fileport/fileport/c.port.c @@ -1 +1,541 @@ - /* * Copyright (c) Kopriha Software, 1990 * All Rights Reserved * * C.Port.CC * * Description: * This module is the heart of the file support of the * printer port driver. * * * Table of Contents: * * c_port_open . . . . . . . . . . Open the data/command files * c_port_write . . . . . . . . . Write the buffer of data * c_port_close . . . . . . . . . Close the data/command files * (if opened) * * * History:Mar 25, 1991 Dave Created this file * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #pragma noroot #include #include #include #include #include #include #include #define PATH_LPQ ":var:spool:lpq" #include "ks.fileio.e" #include "ks.memory.h" #ifndef _ERRORS_ #include "Errors.h" #endif #ifndef __MEMORY__ #include #endif #ifndef __MISCTOOL__ #include #endif #ifndef __WINDOW__ #include #endif #include #include #include #include /* * Local variable declarations... * * Start with structures... */ ResultBuf255 next_filename; Word optionList[20]; DirEntryRecGS dir_entry; GSString32Ptr new_data_path; /* * Now define all the pointers to structures... */ KS_FILE_PTR data_file_ptr = (KS_FILE_PTR) NULL; /* Buffered file structure ptr */ KS_FILE_PTR dir_file_ptr; /* Used to get all of the filenames */ /* from spool directory */ Handle spoolpath_handle; /* Handle allocated for spool path */ GSString32Ptr spool_directory_ptr; /* Pointer to the spoolfile directory */ /* pathname (as we've read it from our */ /* datafile). */ /* * On to the simple variables... */ KS_STRUCT_ID ks_expected_id; /* The structure ID we expected to find */ /* during a structure id check */ Word ProgramID; /* Our Memory Manager UserId */ KS_E_ERROR error; /* Used to catch error codes */ KS_E_ERROR error2; /* Used to catch secondary errors */ size_t pathname_length; /* Length (in bytes) of the spool path */ Word max_spool_number; /* Which is the mac spool number found? */ Word num_entries; /* How many directory entries are there? */ Word spoolfile_number; /* The spoolfile # we decided to use */ char cnumber; /* Used during conversion of spoolfile # */ /* into part of the spool pathname */ char delimiter; /* Delimiter for pathname */ #if 0 Word index1, index2; /* Index variables used in for loops */ #endif Word error_message; /* The error message to display */ Word button; /* Which button of our error dialog did */ /* our user hit? */ Word open_count = 0; /* Count of how many open's we've done...*/ char tmp[128]; Word port_spoolnum = 1; /* count of how many open's we've done */ /* * Now define some constants... */ typedef struct { Word length; char text[35]; } GSString35; /* GSString35 fileport_datapath = {22, ":Natasha:FilePort.Data" }; */ GSString35 fileport_datapath = {30, "*:System:Drivers:FilePort.Data" }; #define SPOOL_FILENAME_EXTENSION 3 /* 2 for ##, 1 for NULL */ #define BASE_SPOOL_FILENAME_LENGTH 9 char base_spool_filename[BASE_SPOOL_FILENAME_LENGTH+1] = {"SpoolFile"}; #define SPOOLFILE_FILETYPE ((Word) 4) #define SPOOLFILE_AUXTYPE ((LongWord) 0) /* * Port flag states */ enum port_flags {PORT_NOT_ACTIVE = 1, PORT_READY, PORT_SPOOLING, PORT_ERROR}; Word port_status = PORT_NOT_ACTIVE; /* Current status of port driver... */ #if 0 /* we take these out of libc instead */ void *malloc(size_t size) { handle h; h = NewHandle(size,ProgramID,0,0l); return *h; } void free(void *data) { DisposeHandle(FindHandle(data)); } #endif /* ****************************************************************** * * c_port_open - Create and open the data/command spool files for * * the port driver. * * * * History: Mar 25, 1991 Dave Created this routine * * * * Dec 23, 1991 Dave Completed pathname expansion (we * * now handle prefixes (#:), * * appleshare users (@:), and system * * disk (*:) references and any * * set of delimiters. * * * * ****************************************************************** */ #define ROUTINE_NAME "c_port_open" void c_port_open(void) { extern GSString32Ptr __C2GSMALLOC(char *); /* ************************************************************** * * No local variables... * * ************************************************************** */ /* ************************************************************** * * Check if we already have a file open... Apple said this should* * never happen... but I really don't believe them... * * ************************************************************** */ if ((data_file_ptr != (KS_FILE_PTR) NULL) || (port_status != PORT_NOT_ACTIVE)) { open_count++; return; }; /* ************************************************************** * * Get the applications memory manager user ID - We'll need it * * to be able to allocate memory... * * ************************************************************** */ ProgramID = MMStartUp(); /* ************************************************************** * * Set the size of the data buffer to 64k... * * ************************************************************** */ KS_FILE_SET_BUFFER_SIZE((LongWord) (64*1024), error); if (error != KS_E_SUCCESS) { error_message = BAD_BUFFER_SIZE; goto ERROR_BAD_BUFFER_SIZE; }; /* > Open our data file in System:filePort.data: and read it * * The line print spool directory is hard-coded */ /* Create a spool file name, and set it up in GS/OS format for use * by the KS_FILE_OPEN routine */ sprintf(tmp,PATH_LPQ ":tmp.%08lX",GetTick()); spool_directory_ptr = __C2GSMALLOC(tmp); /* create the spool file now */ KS_FILE_CREATE((GSString255Ptr) spool_directory_ptr, SPOOLFILE_FILETYPE, SPOOLFILE_AUXTYPE, error); if (error != KS_E_SUCCESS) { error_message = CANT_CREATE_SPOOL_FILE; goto ERROR_CANT_CREATE_SPOOL_FILE; }; /* ************************************************************** * * Open the data spool file * * ************************************************************** */ KS_FILE_OPEN((GSString255Ptr) spool_directory_ptr, KS_FILE_WRITE_ACCESS, KS_FILE_DATA_FORK, KS_FILE_BUFFER_IO, &data_file_ptr, error); if (error != KS_E_SUCCESS) { error_message = CANT_OPEN_SPOOL_FILE; goto ERROR_CANT_OPEN_SPOOL_FILE; }; /* ************************************************************** * * Releasing pathname back to free memory... * * No error checking because what would we do?? * * ************************************************************** */ KS_MEMORY_DEALLOCATE(spoolpath_handle, error); /* ************************************************************** * * Set a flag and a counter... * * ************************************************************** */ port_status = PORT_SPOOLING; open_count = 1; /* ************************************************************** * * Everything is all set - return to our caller... * * ************************************************************** */ return; /* ************************************************************** * * Error processing for all of the error cases of the above code * * * * Once we clean up whatever needs to be cleaned up, then we * * will get around to putting up a dialog box for our user. * * ************************************************************** */ ERROR_CANT_OPEN_SPOOL_FILE: KS_FILE_DELETE((GSString255Ptr) spool_directory_ptr, error2); ERROR_TOO_MANY_SPOOLFILES: ERROR_CANT_CREATE_SPOOL_FILE: ERROR_CANT_GET_NEXT_FILE: ERROR_CANT_GET_ENTRY_COUNT: KS_FILE_CLOSE(dir_file_ptr, error2); ERROR_CANT_OPEN_DIR: KS_MEMORY_DEALLOCATE(spoolpath_handle, error2); goto ERROR_MESSAGE; ERROR_CANT_READ_PATHNAME: KS_MEMORY_DEALLOCATE(spoolpath_handle, error2); ERROR_CANT_ALLOCATE_PATHNAME: KS_FILE_CLOSE(dir_file_ptr, error2); ERROR_CANT_OPEN_CONFIG_FILE: ERROR_BAD_BUFFER_SIZE: ERROR_MESSAGE: port_status = PORT_ERROR; ERROR_DIALOG(error_message, error, button); return; } /* End of c_port_open() */ /* ****************************************************************** * * c_port_write - Write to the data/command spool files for * * the port driver. * * * * History: Mar 27, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "c_port_write" void c_port_write(char *buffer, Word size) { /* ************************************************************** * * No local variables... * * ************************************************************** */ /* ************************************************************** * * Now lets see if it looks like we are allowed to be printing...* * Check for the following: * * 1) We are at level 1 for spool files... * * 2) We have an open spool file * * 3) No errors have occured (yet) * * ************************************************************** */ if ((open_count != 1) || (data_file_ptr == (KS_FILE_PTR) NULL) || (port_status != PORT_SPOOLING)) { return; }; /* ************************************************************** * * Looks good... write this data to the buffered output file. * * Remember to check for an error... * * ************************************************************** */ KS_FILE_WRITE(data_file_ptr, KS_NEXT_FILE_POSITION, (LongWord) size, TO_POINTER(buffer), error); if (error != KS_E_SUCCESS) { error_message = CANT_WRITE_DATA; goto ERROR_CANT_WRITE_DATA; }; /* ************************************************************** * * Everything is all done here - return to our caller... * * ************************************************************** */ return; /* ************************************************************** * * Error processing for all of the error cases of the above code * * * * Something bad happened... that means we have to give up * * on printing and give our user an error dialog that tells * * them what happened. * * ************************************************************** */ ERROR_CANT_WRITE_DATA: /* ************************************************************** * * First we close the spool file (can't use it anymore now...) * * then give our user some feed back (like an error message). * * ************************************************************** */ KS_FILE_CLOSE(data_file_ptr, error2); data_file_ptr = (KS_FILE_PTR) NULL; open_count--; port_status = PORT_ERROR; ERROR_DIALOG(error_message, error, button); return; } /* pragma debug -1 */ /* ****************************************************************** * * c_port_close - Close the data/command spool files for * * the port driver. * * * * History: Mar 27, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "c_port_close" void c_port_close(void) { static char cf[128]; int slf; int lpdport; int cfid; long msg; /* ************************************************************** * * Now lets see if it looks like we can close the spoolfile * * Check for the following: * * 1) We are at level 1 for spool files... * * (otherwise simply decrement the count and return) * * 2) We have an open spool file * * 3) No errors have occured * * ************************************************************** */ if (open_count > 1) { open_count--; return; }; if ((data_file_ptr == (KS_FILE_PTR) NULL) || (port_status != PORT_SPOOLING)) { return; }; /* ************************************************************** * * Close the spool file and reset the file pointer to be NULL * * so we know that the file has been closed. * * * * Note: I haven't added error checking here because there really* * isn't anything we can do if an error occurs... * * ************************************************************** */ KS_FILE_CLOSE(data_file_ptr, error); data_file_ptr = NULL; open_count = 0; port_status = PORT_NOT_ACTIVE; lpdport = pgetport("LPD"); if (lpdport == -1) { error_message = DAEMON_NOT_ACTIVE; goto ERROR_DAEMON_NOT_ACTIVE; } msg = (1l << 16) | getpid(); psend(lpdport,msg); while ((cfid = (int) procreceive()) != -1); sprintf(cf,PATH_LPQ ":cf.%05d",cfid); slf = open(cf,O_WRONLY); if (slf < 0) { SysBeep(); SysBeep(); } write(slf,"l",1); write(slf,tmp,strlen(tmp)); write(slf,"\r",1); write(slf,"U",1); write(slf,tmp,strlen(tmp)); write(slf,"\r",1); close(slf); /* register the job */ msg = (2l << 16) | cfid; if (psend(lpdport,msg) == -1) SysBeep(); /* ************************************************************** * * Everything is all set - return to our caller... * * ************************************************************** */ return; ERROR_DAEMON_NOT_ACTIVE: /* ************************************************************** * * First we close the spool file (can't use it anymore now...) * * then give our user some feed back (like an error message). * * ************************************************************** */ KS_FILE_CLOSE(data_file_ptr, error2); /* delete the spool file */ remove(tmp); data_file_ptr = (KS_FILE_PTR) NULL; open_count--; port_status = PORT_ERROR; ERROR_DIALOG(error_message, error, button); return; } \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990 + * All Rights Reserved + * + * C.Port.CC + * + * Description: + * This module is the heart of the file support of the + * printer port driver. + * + * + * Table of Contents: + * + * c_port_open . . . . . . . . . . Open the data/command files + * c_port_write . . . . . . . . . Write the buffer of data + * c_port_close . . . . . . . . . Close the data/command files + * (if opened) + * + * + * History:Mar 25, 1991 Dave Created this file + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + + +#pragma noroot + +#include +#include +#include +#include +#include +#include +#include + +#define PATH_LPQ ":var:spool:lpq" + +#include "ks.fileio.e" + +#include "ks.memory.h" + +#ifndef _ERRORS_ +#include "Errors.h" +#endif + +#ifndef __MEMORY__ +#include +#endif + +#ifndef __MISCTOOL__ +#include +#endif + +#ifndef __WINDOW__ +#include +#endif +#include +#include +#include +#include + +/* + * Local variable declarations... + * + * Start with structures... + */ + +ResultBuf255 next_filename; +Word optionList[20]; +DirEntryRecGS dir_entry; +GSString32Ptr new_data_path; + + +/* + * Now define all the pointers to structures... + */ + +KS_FILE_PTR data_file_ptr = (KS_FILE_PTR) NULL; + /* Buffered file structure ptr */ +KS_FILE_PTR dir_file_ptr; /* Used to get all of the filenames */ + /* from spool directory */ +Handle spoolpath_handle; /* Handle allocated for spool path */ +GSString32Ptr spool_directory_ptr; + /* Pointer to the spoolfile directory */ + /* pathname (as we've read it from our */ + /* datafile). */ + +/* + * On to the simple variables... + */ + +KS_STRUCT_ID ks_expected_id; /* The structure ID we expected to find */ + /* during a structure id check */ +Word ProgramID; /* Our Memory Manager UserId */ + + +KS_E_ERROR error; /* Used to catch error codes */ +KS_E_ERROR error2; /* Used to catch secondary errors */ + +size_t pathname_length; /* Length (in bytes) of the spool path */ +Word max_spool_number; /* Which is the mac spool number found? */ +Word num_entries; /* How many directory entries are there? */ +Word spoolfile_number; /* The spoolfile # we decided to use */ +char cnumber; /* Used during conversion of spoolfile # */ + /* into part of the spool pathname */ +char delimiter; /* Delimiter for pathname */ +#if 0 +Word index1, index2; /* Index variables used in for loops */ +#endif + +Word error_message; /* The error message to display */ +Word button; /* Which button of our error dialog did */ + /* our user hit? */ +Word open_count = 0; /* Count of how many open's we've done...*/ + +char tmp[128]; +Word port_spoolnum = 1; /* count of how many open's we've done */ + +/* + * Now define some constants... + */ +typedef struct + { + Word length; + char text[35]; + } GSString35; + +/* GSString35 fileport_datapath = {22, ":Natasha:FilePort.Data" }; */ +GSString35 fileport_datapath = {30, "*:System:Drivers:FilePort.Data" }; + +#define SPOOL_FILENAME_EXTENSION 3 /* 2 for ##, 1 for NULL */ +#define BASE_SPOOL_FILENAME_LENGTH 9 + +char base_spool_filename[BASE_SPOOL_FILENAME_LENGTH+1] = + {"SpoolFile"}; + +#define SPOOLFILE_FILETYPE ((Word) 4) +#define SPOOLFILE_AUXTYPE ((LongWord) 0) + +/* + * Port flag states + */ + +enum port_flags {PORT_NOT_ACTIVE = 1, + PORT_READY, + PORT_SPOOLING, + PORT_ERROR}; + +Word port_status = PORT_NOT_ACTIVE; + /* Current status of port driver... */ + +#if 0 /* we take these out of libc instead */ +void *malloc(size_t size) +{ +handle h; + h = NewHandle(size,ProgramID,0,0l); + return *h; +} + +void free(void *data) +{ + DisposeHandle(FindHandle(data)); +} +#endif + +/* ****************************************************************** * + * c_port_open - Create and open the data/command spool files for * + * the port driver. * + * * + * History: Mar 25, 1991 Dave Created this routine * + * * + * Dec 23, 1991 Dave Completed pathname expansion (we * + * now handle prefixes (#:), * + * appleshare users (@:), and system * + * disk (*:) references and any * + * set of delimiters. * + * * + * ****************************************************************** */ + +#define ROUTINE_NAME "c_port_open" + +void c_port_open(void) +{ +extern GSString32Ptr __C2GSMALLOC(char *); + + /* ************************************************************** * + * No local variables... * + * ************************************************************** */ + + + /* ************************************************************** * + * Check if we already have a file open... Apple said this should* + * never happen... but I really don't believe them... * + * ************************************************************** */ + + if ((data_file_ptr != (KS_FILE_PTR) NULL) || + (port_status != PORT_NOT_ACTIVE)) + { + open_count++; + return; + }; + + + /* ************************************************************** * + * Get the applications memory manager user ID - We'll need it * + * to be able to allocate memory... * + * ************************************************************** */ + + ProgramID = MMStartUp(); + + + /* ************************************************************** * + * Set the size of the data buffer to 64k... * + * ************************************************************** */ + + KS_FILE_SET_BUFFER_SIZE((LongWord) (64*1024), + error); + if (error != KS_E_SUCCESS) + { + error_message = BAD_BUFFER_SIZE; + goto ERROR_BAD_BUFFER_SIZE; + }; + + + /* > Open our data file in System:filePort.data: and read it + * + * The line print spool directory is hard-coded + */ + + /* Create a spool file name, and set it up in GS/OS format for use + * by the KS_FILE_OPEN routine + */ + + sprintf(tmp,PATH_LPQ ":tmp.%08lX",GetTick()); + spool_directory_ptr = __C2GSMALLOC(tmp); + + /* create the spool file now */ + KS_FILE_CREATE((GSString255Ptr) spool_directory_ptr, + SPOOLFILE_FILETYPE, + SPOOLFILE_AUXTYPE, + error); + if (error != KS_E_SUCCESS) + { + error_message = CANT_CREATE_SPOOL_FILE; + goto ERROR_CANT_CREATE_SPOOL_FILE; + }; + + /* ************************************************************** * + * Open the data spool file * + * ************************************************************** */ + + KS_FILE_OPEN((GSString255Ptr) spool_directory_ptr, + KS_FILE_WRITE_ACCESS, + KS_FILE_DATA_FORK, + KS_FILE_BUFFER_IO, + &data_file_ptr, + error); + if (error != KS_E_SUCCESS) + { + error_message = CANT_OPEN_SPOOL_FILE; + goto ERROR_CANT_OPEN_SPOOL_FILE; + }; + + + /* ************************************************************** * + * Releasing pathname back to free memory... * + * No error checking because what would we do?? * + * ************************************************************** */ + + + KS_MEMORY_DEALLOCATE(spoolpath_handle, + error); + + + /* ************************************************************** * + * Set a flag and a counter... * + * ************************************************************** */ + + port_status = PORT_SPOOLING; + open_count = 1; + + + /* ************************************************************** * + * Everything is all set - return to our caller... * + * ************************************************************** */ + + return; + + + + /* ************************************************************** * + * Error processing for all of the error cases of the above code * + * * + * Once we clean up whatever needs to be cleaned up, then we * + * will get around to putting up a dialog box for our user. * + * ************************************************************** */ + +ERROR_CANT_OPEN_SPOOL_FILE: + + KS_FILE_DELETE((GSString255Ptr) spool_directory_ptr, + error2); + +ERROR_TOO_MANY_SPOOLFILES: + +ERROR_CANT_CREATE_SPOOL_FILE: + +ERROR_CANT_GET_NEXT_FILE: + +ERROR_CANT_GET_ENTRY_COUNT: + + KS_FILE_CLOSE(dir_file_ptr, error2); + +ERROR_CANT_OPEN_DIR: + + KS_MEMORY_DEALLOCATE(spoolpath_handle, + error2); + + goto ERROR_MESSAGE; + +ERROR_CANT_READ_PATHNAME: + + KS_MEMORY_DEALLOCATE(spoolpath_handle, + error2); + +ERROR_CANT_ALLOCATE_PATHNAME: + + KS_FILE_CLOSE(dir_file_ptr, error2); + +ERROR_CANT_OPEN_CONFIG_FILE: + +ERROR_BAD_BUFFER_SIZE: + +ERROR_MESSAGE: + + port_status = PORT_ERROR; + + ERROR_DIALOG(error_message, error, button); + + return; + + +} /* End of c_port_open() */ + + + +/* ****************************************************************** * + * c_port_write - Write to the data/command spool files for * + * the port driver. * + * * + * History: Mar 27, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "c_port_write" + +void c_port_write(char *buffer, Word size) +{ + /* ************************************************************** * + * No local variables... * + * ************************************************************** */ + + + /* ************************************************************** * + * Now lets see if it looks like we are allowed to be printing...* + * Check for the following: * + * 1) We are at level 1 for spool files... * + * 2) We have an open spool file * + * 3) No errors have occured (yet) * + * ************************************************************** */ + + if ((open_count != 1) || + (data_file_ptr == (KS_FILE_PTR) NULL) || + (port_status != PORT_SPOOLING)) + { + return; + }; + + + /* ************************************************************** * + * Looks good... write this data to the buffered output file. * + * Remember to check for an error... * + * ************************************************************** */ + + KS_FILE_WRITE(data_file_ptr, + KS_NEXT_FILE_POSITION, + (LongWord) size, + TO_POINTER(buffer), + error); + if (error != KS_E_SUCCESS) + { + error_message = CANT_WRITE_DATA; + goto ERROR_CANT_WRITE_DATA; + }; + + + /* ************************************************************** * + * Everything is all done here - return to our caller... * + * ************************************************************** */ + + return; + + + /* ************************************************************** * + * Error processing for all of the error cases of the above code * + * * + * Something bad happened... that means we have to give up * + * on printing and give our user an error dialog that tells * + * them what happened. * + * ************************************************************** */ + +ERROR_CANT_WRITE_DATA: + + /* ************************************************************** * + * First we close the spool file (can't use it anymore now...) * + * then give our user some feed back (like an error message). * + * ************************************************************** */ + + KS_FILE_CLOSE(data_file_ptr, error2); + + data_file_ptr = (KS_FILE_PTR) NULL; + open_count--; + port_status = PORT_ERROR; + + ERROR_DIALOG(error_message, error, button); + + return; +} + +/* pragma debug -1 */ + + +/* ****************************************************************** * + * c_port_close - Close the data/command spool files for * + * the port driver. * + * * + * History: Mar 27, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "c_port_close" + +void c_port_close(void) +{ +static char cf[128]; +int slf; +int lpdport; +int cfid; +long msg; + + + /* ************************************************************** * + * Now lets see if it looks like we can close the spoolfile * + * Check for the following: * + * 1) We are at level 1 for spool files... * + * (otherwise simply decrement the count and return) * + * 2) We have an open spool file * + * 3) No errors have occured * + * ************************************************************** */ + + if (open_count > 1) + { + open_count--; + return; + }; + + if ((data_file_ptr == (KS_FILE_PTR) NULL) || + (port_status != PORT_SPOOLING)) + { + return; + }; + + + /* ************************************************************** * + * Close the spool file and reset the file pointer to be NULL * + * so we know that the file has been closed. * + * * + * Note: I haven't added error checking here because there really* + * isn't anything we can do if an error occurs... * + * ************************************************************** */ + + KS_FILE_CLOSE(data_file_ptr, + error); + + data_file_ptr = NULL; + open_count = 0; + port_status = PORT_NOT_ACTIVE; + + lpdport = pgetport("LPD"); + if (lpdport == -1) { + error_message = DAEMON_NOT_ACTIVE; + goto ERROR_DAEMON_NOT_ACTIVE; + } + msg = (1l << 16) | getpid(); + psend(lpdport,msg); + while ((cfid = (int) procreceive()) != -1); + + sprintf(cf,PATH_LPQ ":cf.%05d",cfid); + slf = open(cf,O_WRONLY); + if (slf < 0) { SysBeep(); SysBeep(); } + write(slf,"l",1); + write(slf,tmp,strlen(tmp)); + write(slf,"\r",1); + write(slf,"U",1); + write(slf,tmp,strlen(tmp)); + write(slf,"\r",1); + close(slf); + /* register the job */ + msg = (2l << 16) | cfid; + if (psend(lpdport,msg) == -1) SysBeep(); + + /* ************************************************************** * + * Everything is all set - return to our caller... * + * ************************************************************** */ + + return; + +ERROR_DAEMON_NOT_ACTIVE: + + /* ************************************************************** * + * First we close the spool file (can't use it anymore now...) * + * then give our user some feed back (like an error message). * + * ************************************************************** */ + + KS_FILE_CLOSE(data_file_ptr, error2); + /* delete the spool file */ + remove(tmp); + + data_file_ptr = (KS_FILE_PTR) NULL; + open_count--; + port_status = PORT_ERROR; + + ERROR_DIALOG(error_message, error, button); + + return; +} diff --git a/sys/fileport/fileport/errormsgs.asm b/sys/fileport/fileport/errormsgs.asm index c1ca894..894bec9 100644 --- a/sys/fileport/fileport/errormsgs.asm +++ b/sys/fileport/fileport/errormsgs.asm @@ -1 +1,103 @@ - ;*********************************************************************** ;* ;* Copyright (C) Kopriha Software, 1990 - 1991 ;* All rights reserved. ;* Licensed material -- property of Kopriha Software ;* ;* This software is made available solely pursuant to the terms ;* of a Kopriha Software license agreement which governs its use. ;* ;* ;* Memory copy of copyright notice ;* Error messages for FilePort Port Driver ;* ;* ;* Description: ;* The copyright notice is included for anyone that gets a copy of ;* this software and decides to disassemble it. ;* ;* The error messages are defined in assembler, because Orca/C makes ;* the errors take up extra space (i.e.: All strings must be of a ;* fixed length). In assembler, no such restriction exists... ;* ;* ;* History: April 13 Dave Created this module ;* ;* ;* ;*********************************************************************** case on Set case sensitivity in assembler objcase on Set case sensitivity in object gen off List generated code trace off List all macro generation dummy start Throw away *.root file end ;*********************************************************************** ;* copyright_strings data ;* ;*********************************************************************** ; First a copyright notice that will be in our executable... dc c'Copyright (C) Kopriha Software, 1990 - 1991 ' dc c'All rights reserved. ' dc c'Licensed material -- property of Kopriha Software ' dc c'This software is made available solely pursuant to the terms ' dc c'of a Kopriha Software license agreement which governs its use. ' dc c'**** If you are reading this message then I''ll assume that you ' dc c'are disassembling this program - Good Luck! It is a collection ' dc c'of Orca/C and Orca/M. If you would like a copy of the sources ' dc c'then send a self addressed diskette mailer with a ProDOS formatted ' dc c'diskette to me: Kopriha Software, c/o Dave Kopper, 81 Main ' dc c'Boulevard, Shrewsbury, MA 01545-3146 ****' ; Define pointers to all the error messages... error_strings entry dc a4'E0' dc a4'E1' dc a4'E2' dc a4'E3' dc a4'E4' dc a4'E5' dc a4'E6' dc a4'E7' dc a4'E8' dc a4'E9' dc a4'E10' dc a4'E11' dc a4'EI' ; Now define all the error message strings... E0 dc c'I can''t set the buffer size correctly',i1'0' E1 dc c'I can''t open the configuration file {FilePort.Data}',i1'0' E2 dc c'I can''t allocate the pathname buffer',i1'0' E3 dc c'I can''t read the configuration file {FilePort.Data}',i1'0' E4 dc c'I can''t open the FilePort output directory',i1'0' E5 dc c'I can''t get the FilePort output directory count',i1'0' E6 dc c'I can''t get the next FilePort output directory entry',i1'0' E7 dc c'I can''t create the FilePort output file. ' dc c'There are too many printer data files in the ' dc c'FilePort output directory. Delete at least one and ' dc c'print your document again.',i1'0' E8 dc c'I can''t create a FilePort output file',i1'0' E9 dc c'I can''t open the FilePort output file',i1'0' E10 dc c'I can''t write to the FilePort output file',i1'0' E11 dc c'The line printer daemon is not active',i1'0' EI dc c'Oops... Invalid error message number (programmer error)',i1'0' end ; End of Error message definitions \ No newline at end of file + +;*********************************************************************** +;* +;* Copyright (C) Kopriha Software, 1990 - 1991 +;* All rights reserved. +;* Licensed material -- property of Kopriha Software +;* +;* This software is made available solely pursuant to the terms +;* of a Kopriha Software license agreement which governs its use. +;* +;* +;* Memory copy of copyright notice +;* Error messages for FilePort Port Driver +;* +;* +;* Description: +;* The copyright notice is included for anyone that gets a copy of +;* this software and decides to disassemble it. +;* +;* The error messages are defined in assembler, because Orca/C makes +;* the errors take up extra space (i.e.: All strings must be of a +;* fixed length). In assembler, no such restriction exists... +;* +;* +;* History: April 13 Dave Created this module +;* +;* +;* +;*********************************************************************** + + case on Set case sensitivity in assembler + objcase on Set case sensitivity in object + + gen off List generated code + trace off List all macro generation + +dummy start Throw away *.root file + end + +;*********************************************************************** +;* +copyright_strings data +;* +;*********************************************************************** + +; First a copyright notice that will be in our executable... + + dc c'Copyright (C) Kopriha Software, 1990 - 1991 ' + dc c'All rights reserved. ' + dc c'Licensed material -- property of Kopriha Software ' + dc c'This software is made available solely pursuant to the terms ' + dc c'of a Kopriha Software license agreement which governs its use. ' + + dc c'**** If you are reading this message then I''ll assume that you ' + dc c'are disassembling this program - Good Luck! It is a collection ' + dc c'of Orca/C and Orca/M. If you would like a copy of the sources ' + dc c'then send a self addressed diskette mailer with a ProDOS formatted ' + dc c'diskette to me: Kopriha Software, c/o Dave Kopper, 81 Main ' + dc c'Boulevard, Shrewsbury, MA 01545-3146 ****' + + +; Define pointers to all the error messages... + +error_strings entry + + dc a4'E0' + dc a4'E1' + dc a4'E2' + dc a4'E3' + dc a4'E4' + dc a4'E5' + dc a4'E6' + dc a4'E7' + dc a4'E8' + dc a4'E9' + dc a4'E10' + dc a4'E11' + + dc a4'EI' + + +; Now define all the error message strings... + +E0 dc c'I can''t set the buffer size correctly',i1'0' +E1 dc c'I can''t open the configuration file {FilePort.Data}',i1'0' +E2 dc c'I can''t allocate the pathname buffer',i1'0' +E3 dc c'I can''t read the configuration file {FilePort.Data}',i1'0' +E4 dc c'I can''t open the FilePort output directory',i1'0' +E5 dc c'I can''t get the FilePort output directory count',i1'0' +E6 dc c'I can''t get the next FilePort output directory entry',i1'0' +E7 dc c'I can''t create the FilePort output file. ' + dc c'There are too many printer data files in the ' + dc c'FilePort output directory. Delete at least one and ' + dc c'print your document again.',i1'0' +E8 dc c'I can''t create a FilePort output file',i1'0' +E9 dc c'I can''t open the FilePort output file',i1'0' +E10 dc c'I can''t write to the FilePort output file',i1'0' +E11 dc c'The line printer daemon is not active',i1'0' + +EI dc c'Oops... Invalid error message number (programmer error)',i1'0' + + + end ; End of Error message definitions diff --git a/sys/fileport/fileport/errors.c b/sys/fileport/fileport/errors.c index 0e19e00..d010f57 100644 --- a/sys/fileport/fileport/errors.c +++ b/sys/fileport/fileport/errors.c @@ -1 +1,145 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * Errors.CC * * Description: * This module is the heart of the file support of the * printer port driver. * * * Table of Contents: * * error_dialog . . . . . . . . . Display an error dialog for * our user - return whatever * button they click on. * * * History:April 13, 1991 Dave Created this file * */ #pragma noroot /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #include #include "errors.h" #ifndef __WINDOW__ #include #endif char error_string1[80]; Pointer substitute_array[10]; extern Pointer error_strings[NUMBER_OF_ERROR_CODES+1]; /* ****************************************************************** * * error_dialog - display an error dialog and return the selected * * button (typically the 'Ok' button). * * * * History: April 13, 1991 Dave Created this routine * * ****************************************************************** */ #define ROUTINE_NAME "error_dialog" Word error_dialog(Word error_message, Word error_code) { Word button; /* ************************************************************** * * Check for validity of the error code - if it is not a known * * error code then we will use the 'invalid error' message. * * ************************************************************** */ if ((error_message < 0) || (error_message > NUMBER_OF_ERROR_CODES)) { error_message = NUMBER_OF_ERROR_CODES+1; }; /* ************************************************************** * * Setup the substitution strings... * * ************************************************************** */ /* ************************************************************** * * Check if the window manager is active or not... * * ************************************************************** */ if (WindStatus() != 0) { /* ********************************************************** * * The window manager is available... so we are allowed to * * put up a simple alert window. Setup the substitution * * array and put up the dialog... * * ********************************************************** */ if (error_message == TOO_MANY_SPOOLFILES) { sprintf(error_string1, "32/FilePort error - *0/^#0", error_code); } else { sprintf(error_string1, "32/FilePort error - *0 (error code $%X)/^#0", error_code); }; substitute_array[0] = (Pointer) error_strings[ ((error_message >= 0) || (error_message < NUMBER_OF_ERROR_CODES)) ? error_message : (NUMBER_OF_ERROR_CODES+1)]; button = AlertWindow((Word) 0, (Pointer) &substitute_array, (Ref) error_string1); } else /* ********************************************************** * * The window manager isn't active... that means we can't * * put up a simple alertwindow... print the error strings * * out to standard out... lets hope a user sees it. * * ********************************************************** */ { printf("FilePort error - %s", (char *) error_strings[ ((error_message >= 0) || (error_message < NUMBER_OF_ERROR_CODES)) ? error_message : (NUMBER_OF_ERROR_CODES+1)]); if (error_message != TOO_MANY_SPOOLFILES) { printf(" (error code $%X)\n", error_code); }; button = 0; } /* ************************************************************** * * Return the button that was pressed. * * ************************************************************** */ return(button); } /* End of error_dialog() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * Errors.CC + * + * Description: + * This module is the heart of the file support of the + * printer port driver. + * + * + * Table of Contents: + * + * error_dialog . . . . . . . . . Display an error dialog for + * our user - return whatever + * button they click on. + * + * + * History:April 13, 1991 Dave Created this file + * + */ + +#pragma noroot + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#include + +#include "errors.h" + +#ifndef __WINDOW__ +#include +#endif + + +char error_string1[80]; + +Pointer substitute_array[10]; + + +extern Pointer error_strings[NUMBER_OF_ERROR_CODES+1]; + + + +/* ****************************************************************** * + * error_dialog - display an error dialog and return the selected * + * button (typically the 'Ok' button). * + * * + * History: April 13, 1991 Dave Created this routine * + * ****************************************************************** */ + +#define ROUTINE_NAME "error_dialog" + +Word error_dialog(Word error_message, Word error_code) +{ + Word button; + + + /* ************************************************************** * + * Check for validity of the error code - if it is not a known * + * error code then we will use the 'invalid error' message. * + * ************************************************************** */ + + if ((error_message < 0) || (error_message > NUMBER_OF_ERROR_CODES)) + { + error_message = NUMBER_OF_ERROR_CODES+1; + }; + + + /* ************************************************************** * + * Setup the substitution strings... * + * ************************************************************** */ + + + /* ************************************************************** * + * Check if the window manager is active or not... * + * ************************************************************** */ + + if (WindStatus() != 0) + { + + /* ********************************************************** * + * The window manager is available... so we are allowed to * + * put up a simple alert window. Setup the substitution * + * array and put up the dialog... * + * ********************************************************** */ + + if (error_message == TOO_MANY_SPOOLFILES) + { + sprintf(error_string1, + "32/FilePort error - *0/^#0", + error_code); + } + else + { + sprintf(error_string1, + "32/FilePort error - *0 (error code $%X)/^#0", + error_code); + }; + + substitute_array[0] = (Pointer) error_strings[ + ((error_message >= 0) || + (error_message < NUMBER_OF_ERROR_CODES)) ? + error_message : + (NUMBER_OF_ERROR_CODES+1)]; + + button = AlertWindow((Word) 0, + (Pointer) &substitute_array, + (Ref) error_string1); + } + else + + /* ********************************************************** * + * The window manager isn't active... that means we can't * + * put up a simple alertwindow... print the error strings * + * out to standard out... lets hope a user sees it. * + * ********************************************************** */ + { + printf("FilePort error - %s", (char *) error_strings[ + ((error_message >= 0) || + (error_message < NUMBER_OF_ERROR_CODES)) ? + error_message : + (NUMBER_OF_ERROR_CODES+1)]); + + if (error_message != TOO_MANY_SPOOLFILES) + { + printf(" (error code $%X)\n", error_code); + }; + + button = 0; + } + + /* ************************************************************** * + * Return the button that was pressed. * + * ************************************************************** */ + + return(button); + + +} /* End of error_dialog() */ diff --git a/sys/fileport/fileport/errors.h b/sys/fileport/fileport/errors.h index f0db1fc..cf9f1c0 100644 --- a/sys/fileport/fileport/errors.h +++ b/sys/fileport/fileport/errors.h @@ -1 +1,81 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * Errors.H * * Description: This include file contains all the error * code definitions required for this program. * * * Table of contents: * * Macros: * * ERROR_DIALOG() . . . . . . . . Display an error dialog and * wait for the user to choose * an option (usually only one). * * * History:April 13, 1991 Dave Created this file * */ #ifndef _ERROR_ #define _ERROR_ #ifndef __TYPES__ #include #endif #ifndef _PORTABLE_C_ #include "Portable.C.h" #endif /* ****************************************************************** * * Error code definitions for this product: * * ****************************************************************** */ #define BAD_BUFFER_SIZE 0 #define CANT_OPEN_CONFIG_FILE BAD_BUFFER_SIZE+1 #define CANT_ALLOCATE_PATHNAME CANT_OPEN_CONFIG_FILE+1 #define CANT_READ_PATHNAME CANT_ALLOCATE_PATHNAME+1 #define CANT_OPEN_DIR CANT_READ_PATHNAME+1 #define CANT_GET_ENTRY_COUNT CANT_OPEN_DIR+1 #define CANT_GET_NEXT_FILE CANT_GET_ENTRY_COUNT+1 #define TOO_MANY_SPOOLFILES CANT_GET_NEXT_FILE+1 #define CANT_CREATE_SPOOL_FILE TOO_MANY_SPOOLFILES+1 #define CANT_OPEN_SPOOL_FILE CANT_CREATE_SPOOL_FILE+1 #define CANT_WRITE_DATA CANT_OPEN_SPOOL_FILE+1 #define DAEMON_NOT_ACTIVE CANT_WRITE_DATA+1 #define NUMBER_OF_ERROR_CODES DAEMON_NOT_ACTIVE+1 /* ****************************************************************** * * Macro definitions: * * ****************************************************************** */ /* * ERROR_DIALOG - display an error dialog (with string substitution). * Returning the button pressed to our caller. */ #define ERROR_DIALOG(_error_msg, _error_code, _button) \ \ /*word*/_button = error_dialog( (_error_msg), (_error_code)) /* ****************************************************************** * * Prototypes of all functions: * * ****************************************************************** */ Word error_dialog(Word, Word); #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * Errors.H + * + * Description: This include file contains all the error + * code definitions required for this program. + * + * + * Table of contents: + * + * Macros: + * + * ERROR_DIALOG() . . . . . . . . Display an error dialog and + * wait for the user to choose + * an option (usually only one). + * + * + * History:April 13, 1991 Dave Created this file + * + */ + +#ifndef _ERROR_ +#define _ERROR_ + +#ifndef __TYPES__ +#include +#endif + +#ifndef _PORTABLE_C_ +#include "Portable.C.h" +#endif + + + + +/* ****************************************************************** * + * Error code definitions for this product: * + * ****************************************************************** */ + + +#define BAD_BUFFER_SIZE 0 +#define CANT_OPEN_CONFIG_FILE BAD_BUFFER_SIZE+1 +#define CANT_ALLOCATE_PATHNAME CANT_OPEN_CONFIG_FILE+1 +#define CANT_READ_PATHNAME CANT_ALLOCATE_PATHNAME+1 +#define CANT_OPEN_DIR CANT_READ_PATHNAME+1 +#define CANT_GET_ENTRY_COUNT CANT_OPEN_DIR+1 +#define CANT_GET_NEXT_FILE CANT_GET_ENTRY_COUNT+1 +#define TOO_MANY_SPOOLFILES CANT_GET_NEXT_FILE+1 +#define CANT_CREATE_SPOOL_FILE TOO_MANY_SPOOLFILES+1 +#define CANT_OPEN_SPOOL_FILE CANT_CREATE_SPOOL_FILE+1 +#define CANT_WRITE_DATA CANT_OPEN_SPOOL_FILE+1 +#define DAEMON_NOT_ACTIVE CANT_WRITE_DATA+1 +#define NUMBER_OF_ERROR_CODES DAEMON_NOT_ACTIVE+1 + + +/* ****************************************************************** * + * Macro definitions: * + * ****************************************************************** */ + +/* + * ERROR_DIALOG - display an error dialog (with string substitution). + * Returning the button pressed to our caller. + */ + +#define ERROR_DIALOG(_error_msg, _error_code, _button) \ + \ + /*word*/_button = error_dialog( (_error_msg), (_error_code)) + + + +/* ****************************************************************** * + * Prototypes of all functions: * + * ****************************************************************** */ + +Word error_dialog(Word, Word); + + +#endif diff --git a/sys/fileport/fileport/fileport.data b/sys/fileport/fileport/fileport.data index fa90928..0ab8c63 100644 --- a/sys/fileport/fileport/fileport.data +++ b/sys/fileport/fileport/fileport.data @@ -1 +1 @@ -:var:spool:lpq: \ No newline at end of file +:var:spool:lpq: diff --git a/sys/fileport/fileport/port.asm b/sys/fileport/fileport/port.asm index b22bceb..9cdbc22 100644 --- a/sys/fileport/fileport/port.asm +++ b/sys/fileport/fileport/port.asm @@ -1 +1,730 @@ - ;*********************************************************************** ;* ;* Copyright (C) Kopriha Software, 1990 - 1991 ;* All rights reserved. ;* Licensed material -- property of Kopriha Software ;* ;* This software is made available solely pursuant to the terms ;* of a Kopriha Software license agreement which governs its use. ;* ;* ;* File Printer Port Driver ;* ;* ;* Description: ;* The goal of this GS port driver is to allow the user of any printer ;* driver to save their printer driver output in a user specified file. ;* ;* There is no user interface (unless error dialogs count...) ;* ;* If this port driver encounters any error, a dialog box will be ;* displayed with the error code and a message saying that the printer ;* output could not be saved. The user will have two buttons - ;* DELETE_OUTPUT and OK. Delete output will simply delete the output ;* file and act as an OK button. ;* ;* Rational for this driver: I want to be able to 'print' a file on ;* my GS, bring the file to work and print the file on a printer here. ;* ;* The other idea is that this approach leaves the door open for ;* utility to print the on a GS (the best approach would be to get ;* Bill Tutor to modify his text spooler to work with printer image ;* files...). ;* ;* ;* Notes: ;* This printer port driver is complies to the version 3.0 printer ;* driver specs. See IIGS technotes 35 (dated March 1990) and ;* technote 36 (dated September 1989) for the printer/port driver ;* specificiations. ;* ;* The resulting port driver must be given filetype $BB ;* auxiliary type $02 (IE: Port driver for local printer). ;* ;* The entire file port driver is designed to fit within one 64K ;* segment/bank of memory. If it must span more than one memory ;* bank, then you will have to correct the dispatch routine and ;* possibly some references to the internal data structures. ;* ;* Further References: ;* Apple IIGS Toolbox Reference, Volumes 1 & 2 ;* Apple IIGS Technical Note #35, Printer Driver Specifications ;* Apple IIGS Technical Note #36, Port Driver Specifications ;* ;* ;* History: Feb 20 1990 Dave Began coding of File Port Driver ;* (started with NullPortDriver) ;* ;* ;* ;*********************************************************************** case on Set case sensitivity in assembler objcase on Set case sensitivity in object gen off List generated code trace off List all macro generation mcopy port.macros Include the port driver macros TRUE gequ 1 Define TRUE and FALSE FALSE gequ 0 PT_Unknown gequ 0 Define the special types PT_ImageWriter gequ 4 of printers (These printers PT_ImageWriterLQ gequ 8 respond to a read after being ; sent a ID/status command) ;*********************************************************************** ;* StartOfDriver start ;* ;* Description: ;* Dispatch to each of the port driver support drivers. ;* ;* Note: ;* This routine must be the first in the port driver - the first two ;* words are used to determine what version port driver specification ;* is installed. ;* ;* History: ;* Most of this routine was provided by GS technote # 35. ;* ;*********************************************************************** using PortData ; Setup the header of the driver (as per the technote) dc i2'0' ; version 3.0 style driver dc i2'12' ; Supported # of port calls ; Set the data bank to our own, saving the previous one for later phb ; Save data bank phk plb ; Set data bank to our own ; Increment a counter of port calls. This counter is used to ; determine the printer driver type (after an open, there is ; usually a write, followed by a read). If we can return the ; right string on the read then all of the options are enabled ; in the printer job dialog. inc PortCallCounter ; Finally, lets dispatch to the port driver routine (X was preset, ; see the technote for details). jmp (PrPortDrvList,x) ; Routine name Toolbox call # PrPortDrvList dc a4'PrDevPrChanged' ; $1913 dc a4'PrDevStartUp' ; $1A13 dc a4'PrDevShutDown' ; $1B13 dc a4'PrDevOpen' ; $1C13 dc a4'PrDevRead' ; $1D13 dc a4'PrDevWrite' ; $1E13 dc a4'PrDevClose' ; $1F13 dc a4'PrDevStatus' ; $2013 dc a4'PrDevAsyncRead' ; $2113 (alias PrDevInitBack) dc a4'PrDevWriteBackground' ; $2213 (alias PrDevFillBack) dc a4'PrPortVer' ; $2413 dc a4'PrDevIsItSafe' ; $3013 end ; of StartOfDriver ;*********************************************************************** ;* PrDevPrChanged start ;* ;* Description: ;* The Print Manager makes this call every time the user accepts ;* this port driver in the Choose Printer dialog. ;* ;* Our version of this routine will set the printer type to Unknown ;* ;* Input: LONG printer name pointer ;* ;*********************************************************************** using PortData port_subroutine (4:printername) ; Set the printer type to unknown ; ; Note: I refused to use stz because that will avoid the predefined ; constants - if I change Unknown to some other value, a STZ ; wouldn't work any more! lda #PT_Unknown sta PrinterType port_return rtl end ; of PrDevPrChanged ;*********************************************************************** ;* PrDevStartUp start ;* ;* Description: ;* This call is not required to do anything. However, if your ;* driver needs to initialize itself by allocating memory or other ;* setup tasks, this is the place to do it. Network drivers should ;* copy the printer name to a local storage area for later use. ;* ;* Our version of this routine will do nothing. ;* ;* Input: LONG printer name pointer ;* LONG zone name pointer ;* ;*********************************************************************** port_subroutine (4:zonename,4:printername) port_return cmp #1 rtl end ; of PrDevPrChanged ;*********************************************************************** ;* PrDevShutDown start ;* ;* Description: ;* This call, like PrDevStartUp, is not required to do anything. ;* However, if your driver performs other tasks when it starts, ;* from the normal (allocating memory) to the obscure (installing ;* heartbeat tasks), it should undo them here. If you allocate ;* anything when you start, you should deallocate it when you ;* shutdown. Note that this call may be made without a balancing ;* PrDevStartUp, so be prepared for this instance. For example, do ;* not try to blindly deallocate a handle that your PrDevStartUp ;* routine allocates and stores in local storage; if you have not ;* called PrDevStartUp, there is no telling what will be in your ;* local storage area. ;* ;* Our version of this routine will do nothing. ;* ;* Input: none ;* ;*********************************************************************** port_subroutine port_return rtl end ; of PrDevShutDown ;*********************************************************************** ;* PrDevOpen start ;* ;* Description: ;* This call basically prepares the firmware for printing. It ;* must initialize the firmware for both input and output. ;* Input is required so the connected printer may be polled ;* for its status. ;* ;* Our version of this routine will display a dialog box (if we ;* haven't already opened a file) and open the specified file ;* for output. Since we don't really have a printer that could ;* respond, I suppose we can't really get it ready for input ;* (besides that, I don't believe all printer interfaces allow ;* input - a parallel interface doesn't have input wires from ;* the printer!) ;* ;* Note: We will have to JSL to the completion routine when we ;* are done! (or RTL if the completion pointer is NIL). ;* ;* Input: LONG completion routine pointer ;* LONG reserved long ;* ;*********************************************************************** using PortData port_subroutine (4:reserved,4:completion_routine) ; Clear the port driver call counter (This counter is used to determine ; what type of printer driver is calling us). stz PortCallCounter ; Go open the spool files (one for the data, one for the commands) jsl >c_port_open port_return 0:stump,completion_routine cmp #1 rtl end ; of PrDevOpen ;*********************************************************************** ;* PrDevRead start ;* ;* Description: ;* This call reads input from the printer. ;* ;* Our version of this routine will return a string based on ;* what we think the printer driver did: ;* ;* ImageWriter: Return Color option ;* ImageWriter LQ: Return Model ID, Multiple bins and Color options ;* Unknown: Return nothing (String of zero length) ;* ;* ;* Input: WORD space for result ;* LONG buffer pointer ;* WORD number of bytes to transfer ;* ;* Output: WORD number of bytes transferred ;* ;*********************************************************************** using PortData port_subroutine (2:bytes_to_send,4:buffer,2:bytes_transfered) ; Dispatch to return the appropriate string (depending on the printer ; type - we determined the printer type from the last two commands... ; see the open/write routine comments for details) ldx PrinterType jmp (ReadDispatch,x) ; Routine name Printer type ReadDispatch anop dc a4'ReadUnknown' ; Unknown dc a4'ReadIMWR' ; ImageWriter dc a4'ReadIMWR_LQ' ; ImageWriter LQ ; For most printers, there aren't any bytes to be read. Return ; the standard zero length string. ReadUnknown anop lda #0 sta bytes_transfered bra read_return ; Set the output buffer up for a ImageWriter returned string... ; (IE: Color) ReadIMWR anop lda ImWr_ReadLen sta bytes_transfered ldy ImWr_ReadLen dey ReadIMWR2 anop dey lda ImWr_Read,y sta [buffer],y cpy #0 bne ReadIMWR2 bra read_return ; Set the output buffer up for a ImageWriter LQ returned string... ; (IE: Multiple bins and Color) ReadIMWR_LQ anop lda ImWr_LQ_ReadLen sta bytes_transfered ldy ImWr_LQ_ReadLen dey ReadIMWR_LQ2 anop dey lda ImWr_LQ_Read,y sta [buffer],y cpy #0 bne ReadIMWR_LQ2 ; Back to our caller we go... read_return anop port_return 2:bytes_transfered rtl end ; of PrDevRead ;*********************************************************************** ;* PrDevWrite start ;* ;* Description: ;* Writes the data in the buffer to the printer and calls ;* the completion routine. ;* ;* Our version of this routine will copy the information to ;* our buffer. Once the buffer is full (check before the copy ;* and if the copy would fill it then only copy what will fill ;* it). If the buffer is full then write it to the output ;* file. If there is still stuff to in the input buffer, then ;* loop to the beginning of this routine again. ;* Once we're done, its time to call the completion routine. ;* ;* Input: LONG write completion pointer ;* LONG buffer pointer ;* WORD buffer length ;* ;*********************************************************************** using PortData port_subroutine (2:bytes_to_send,4:buffer,4:completion_routine) ; Lets see if we can determine the type of printer driver (for special ; printers). We only do this specialness on the first write after an ; open. lda PortCallCounter cmp #1 bne WriteNotSpecial bra ttt ; do no specialness stuff ; Check for an ImageWriter (check length of buffer, then the buffer) WriteIMWR anop lda bytes_to_send cmp ImWr_WriteLen bne WriteIMWR_LQ ldy ImWr_WriteLen dey WriteIMWR2 anop dey lda ImWr_Write,y cmp [buffer],y bne WriteIMWR_LQ cpy #0 bne WriteIMWR2 ; Looks like and ImageWrite status string to me. ; Set the special printer flag for later. ; remove these lines for ImageWriter I. lda #PT_ImageWriter sta PrinterType bra WriteNotSpecial ; Check for an ImageWriter LQ (check length of buffer, then the buffer) WriteIMWR_LQ anop lda bytes_to_send cmp ImWr_LQ_WriteLen bne WriteNotSpecial ldy ImWr_LQ_WriteLen dey WriteIMWR_LQ2 anop dey lda ImWr_LQ_Write,y cmp [buffer],y bne WriteNotSpecial cpy #0 bne WriteIMWR_LQ2 ; Looks like and ImageWrite LQ status string to me. ; Set the special printer flag for later. lda #PT_ImageWriterLQ sta PrinterType ; bra WriteNotSpecial ; Continue with the standard port write WriteNotSpecial anop ; Call the C routine to write the data/command to a file... PushWord bytes_to_send PushLong buffer jsl >c_port_write ; We're all done - return a success to our caller... ttt port_return 0:stump,completion_routine cmp #1 rtl end ; of PrDevWrite ;*********************************************************************** ;* PrDevClose start ;* ;* Description: ;* ;* This call is not required to do anything. However, if ;* you allocate any system resources with PrDevOpen, you ;* should deallocate them at this time. As with start and ;* shutdown, note that PrDevClose could be called without a ;* balancing PrDevOpen (the reverse is not true), and you ;* must be prepared for this if you try to deallocate ;* resources which were never allocated. ;* ;* Our version of this routine will close the file (if it ;* is open). If we find a CANCELLED flag, then we will ;* just reset the flag. ;* ;* Input: none ;* ;*********************************************************************** port_subroutine ; Attempt to close the data/command files ; ; Note: The files may not have been opened! jsl >c_port_close port_return rtl end ; of PrDevClose ;*********************************************************************** ;* PrDevStatus start ;* ;* Description: ;* ;* This call performs differently for direct connect and ;* network drivers. For direct connect drivers, it currently ;* has no required function, although it may return the status ;* of the port in the future. For network drivers, it calls ;* an AppleTalk status routine, which returns a status string ;* in the buffer (normally a string like "Status: The print ;* server is spooling your document"). ;* ;* Our version of this routine will do nothing. ;* ;* Input: LONG status buffer pointer ;* ;*********************************************************************** port_subroutine (4:status) port_return cmp #1 rtl end ; of PrDevStatus ;*********************************************************************** ;* PrDevAsyncRead start ;* ;* Description: ;* Since PrDevRead cannot read asynchronously, this call is ;* provided for that task. Note that this does nothing for ;* direct connect drivers, and if the completion pointer is ;* NIL, it behaves for network drivers exactly as PrDevRead ;* does. ;* ;* Our version of this routine will do nothing. ;* ;* Input: WORD space for result ;* LONG completion pointer ;* WORD buffer length ;* LONG buffer pointer ;* ;* Output: WORD number of bytes transferred ;* ;*********************************************************************** port_subroutine (4:buffer,2:length,4:cmp_rtn,2:bytes_transfered) lda #0 sta bytes_transfered port_return 2:bytes_transfered,cmp_rtn cmp #1 rtl end ; of PrDevAsyncRead ;*********************************************************************** ;* PrDevWriteBackground start ;* ;* Description: ;* This routine is not implemented at this time. ;* ;* Our version of this routine will do nothing. ;* ;* Input: LONG completion procedure pointer ;* WORD buffer length ;* LONG buffer pointer ;* ;*********************************************************************** port_subroutine (4:buffer,2:length,4:completion_routine) port_return 0:stump,completion_routine cmp #1 rtl end ; of PrDevWriteBackground ;*********************************************************************** ;* PrPortVer start ;* ;* Description: ;* Returns the version number of the currently installed ;* port driver. ;* ;* Our version of this routine will do nothing. ;* ;* Note: The internal version number is stored as a major ;* byte and a minor byte (i.e., $0103 represents version 1.3) ;* ;* Input: WORD space for result ;* ;* Output: WORD Port driver's version number ;* ;*********************************************************************** port_subroutine (2:version_number) lda #$0401 ; Rev 4.1 sta version_number ; Save it port_return 2:version_number rtl end ; of PrPortVer ;*********************************************************************** ;* PrDevIsItSafe start ;* ;* Description: ;* This call checks to see if the port or card which your ;* driver controls is enabled. It should check at least ;* the corresponding bit of $E0C02D, and checking the Battery ;* RAM settings wouldn't hurt any either. ;* ;* Our version of this routine will return TRUE - we don't ;* really drive any port, so we can't really check to see if ;* we are allowed to access the port/slot or not. ;* ;* Input: WORD space for result ;* ;* Output: WORD Boolean indicating if port ;* is enabled ;* ;*********************************************************************** port_subroutine (2:port_safe_flag) lda #TRUE ; Its always safe... sta port_safe_flag ; Save it port_return 2:port_safe_flag rtl end ; of PrDevIsItSafe ;*********************************************************************** ;* PortData data ;* ;* File Port Driver Data Section ;* ;* Description: ;* This section is all of the data that the file port driver ;* requires (not very much really...). ;* ;*********************************************************************** ; Special Printer Types PrinterType ds 2 ; Count of the Port calls made since an Open PortCallCounter dc i2'0' ; ImageWriter model ID/status/options string (written) ImWr_Write dc i1'$1b,$3f' ImWr_WriteLen dc i2'*-ImWr_Write' ; ImageWriter model ID/status/options string (read) ImWr_Read dc i1'$49,$57,$31,$30,$43' ImWr_ReadLen dc i2'*-ImWr_Read' ; ImageWriter LQ model ID/status/options string (written) ImWr_LQ_Write dc i1'$1b,$5a,$00,$02,$1b,$3f' ImWr_LQ_WriteLen dc i2'*-ImWr_LQ_Write' ; ImageWriter LQ model ID/status/options string (read) ImWr_LQ_Read dc i1'$4c,$51,$31,$45,$43' ImWr_LQ_ReadLen dc i2'*-ImWr_LQ_Read' end ; End of File Port Driver \ No newline at end of file + +;*********************************************************************** +;* +;* Copyright (C) Kopriha Software, 1990 - 1991 +;* All rights reserved. +;* Licensed material -- property of Kopriha Software +;* +;* This software is made available solely pursuant to the terms +;* of a Kopriha Software license agreement which governs its use. +;* +;* +;* File Printer Port Driver +;* +;* +;* Description: +;* The goal of this GS port driver is to allow the user of any printer +;* driver to save their printer driver output in a user specified file. +;* +;* There is no user interface (unless error dialogs count...) +;* +;* If this port driver encounters any error, a dialog box will be +;* displayed with the error code and a message saying that the printer +;* output could not be saved. The user will have two buttons - +;* DELETE_OUTPUT and OK. Delete output will simply delete the output +;* file and act as an OK button. +;* +;* Rational for this driver: I want to be able to 'print' a file on +;* my GS, bring the file to work and print the file on a printer here. +;* +;* The other idea is that this approach leaves the door open for +;* utility to print the on a GS (the best approach would be to get +;* Bill Tutor to modify his text spooler to work with printer image +;* files...). +;* +;* +;* Notes: +;* This printer port driver is complies to the version 3.0 printer +;* driver specs. See IIGS technotes 35 (dated March 1990) and +;* technote 36 (dated September 1989) for the printer/port driver +;* specificiations. +;* +;* The resulting port driver must be given filetype $BB +;* auxiliary type $02 (IE: Port driver for local printer). +;* +;* The entire file port driver is designed to fit within one 64K +;* segment/bank of memory. If it must span more than one memory +;* bank, then you will have to correct the dispatch routine and +;* possibly some references to the internal data structures. +;* +;* Further References: +;* Apple IIGS Toolbox Reference, Volumes 1 & 2 +;* Apple IIGS Technical Note #35, Printer Driver Specifications +;* Apple IIGS Technical Note #36, Port Driver Specifications +;* +;* +;* History: Feb 20 1990 Dave Began coding of File Port Driver +;* (started with NullPortDriver) +;* +;* +;* +;*********************************************************************** + + case on Set case sensitivity in assembler + objcase on Set case sensitivity in object + + gen off List generated code + trace off List all macro generation + + mcopy port.macros Include the port driver macros + +TRUE gequ 1 Define TRUE and FALSE +FALSE gequ 0 + +PT_Unknown gequ 0 Define the special types +PT_ImageWriter gequ 4 of printers (These printers +PT_ImageWriterLQ gequ 8 respond to a read after being +; sent a ID/status command) + +;*********************************************************************** +;* +StartOfDriver start +;* +;* Description: +;* Dispatch to each of the port driver support drivers. +;* +;* Note: +;* This routine must be the first in the port driver - the first two +;* words are used to determine what version port driver specification +;* is installed. +;* +;* History: +;* Most of this routine was provided by GS technote # 35. +;* +;*********************************************************************** + + using PortData + +; Setup the header of the driver (as per the technote) + + dc i2'0' ; version 3.0 style driver + dc i2'12' ; Supported # of port calls + + +; Set the data bank to our own, saving the previous one for later + + phb ; Save data bank + phk + plb ; Set data bank to our own + + +; Increment a counter of port calls. This counter is used to +; determine the printer driver type (after an open, there is +; usually a write, followed by a read). If we can return the +; right string on the read then all of the options are enabled +; in the printer job dialog. + + inc PortCallCounter + + +; Finally, lets dispatch to the port driver routine (X was preset, +; see the technote for details). + + jmp (PrPortDrvList,x) + + +; Routine name Toolbox call # +PrPortDrvList dc a4'PrDevPrChanged' ; $1913 + dc a4'PrDevStartUp' ; $1A13 + dc a4'PrDevShutDown' ; $1B13 + dc a4'PrDevOpen' ; $1C13 + dc a4'PrDevRead' ; $1D13 + dc a4'PrDevWrite' ; $1E13 + dc a4'PrDevClose' ; $1F13 + dc a4'PrDevStatus' ; $2013 + dc a4'PrDevAsyncRead' ; $2113 (alias PrDevInitBack) + dc a4'PrDevWriteBackground' ; $2213 (alias PrDevFillBack) + dc a4'PrPortVer' ; $2413 + dc a4'PrDevIsItSafe' ; $3013 + + end ; of StartOfDriver + + + +;*********************************************************************** +;* +PrDevPrChanged start +;* +;* Description: +;* The Print Manager makes this call every time the user accepts +;* this port driver in the Choose Printer dialog. +;* +;* Our version of this routine will set the printer type to Unknown +;* +;* Input: LONG printer name pointer +;* +;*********************************************************************** + + using PortData + + port_subroutine (4:printername) + +; Set the printer type to unknown +; +; Note: I refused to use stz because that will avoid the predefined +; constants - if I change Unknown to some other value, a STZ +; wouldn't work any more! + + lda #PT_Unknown + sta PrinterType + + port_return + rtl + + end ; of PrDevPrChanged + + + +;*********************************************************************** +;* +PrDevStartUp start +;* +;* Description: +;* This call is not required to do anything. However, if your +;* driver needs to initialize itself by allocating memory or other +;* setup tasks, this is the place to do it. Network drivers should +;* copy the printer name to a local storage area for later use. +;* +;* Our version of this routine will do nothing. +;* +;* Input: LONG printer name pointer +;* LONG zone name pointer +;* +;*********************************************************************** + + port_subroutine (4:zonename,4:printername) + + port_return + cmp #1 + rtl + + end ; of PrDevPrChanged + + + +;*********************************************************************** +;* +PrDevShutDown start +;* +;* Description: +;* This call, like PrDevStartUp, is not required to do anything. +;* However, if your driver performs other tasks when it starts, +;* from the normal (allocating memory) to the obscure (installing +;* heartbeat tasks), it should undo them here. If you allocate +;* anything when you start, you should deallocate it when you +;* shutdown. Note that this call may be made without a balancing +;* PrDevStartUp, so be prepared for this instance. For example, do +;* not try to blindly deallocate a handle that your PrDevStartUp +;* routine allocates and stores in local storage; if you have not +;* called PrDevStartUp, there is no telling what will be in your +;* local storage area. +;* +;* Our version of this routine will do nothing. +;* +;* Input: none +;* +;*********************************************************************** + + port_subroutine + + port_return + rtl + + end ; of PrDevShutDown + + + +;*********************************************************************** +;* +PrDevOpen start +;* +;* Description: +;* This call basically prepares the firmware for printing. It +;* must initialize the firmware for both input and output. +;* Input is required so the connected printer may be polled +;* for its status. +;* +;* Our version of this routine will display a dialog box (if we +;* haven't already opened a file) and open the specified file +;* for output. Since we don't really have a printer that could +;* respond, I suppose we can't really get it ready for input +;* (besides that, I don't believe all printer interfaces allow +;* input - a parallel interface doesn't have input wires from +;* the printer!) +;* +;* Note: We will have to JSL to the completion routine when we +;* are done! (or RTL if the completion pointer is NIL). +;* +;* Input: LONG completion routine pointer +;* LONG reserved long +;* +;*********************************************************************** + + using PortData + + port_subroutine (4:reserved,4:completion_routine) + +; Clear the port driver call counter (This counter is used to determine +; what type of printer driver is calling us). + + stz PortCallCounter + + +; Go open the spool files (one for the data, one for the commands) + + jsl >c_port_open + + port_return 0:stump,completion_routine + cmp #1 + rtl + + end ; of PrDevOpen + + + +;*********************************************************************** +;* +PrDevRead start +;* +;* Description: +;* This call reads input from the printer. +;* +;* Our version of this routine will return a string based on +;* what we think the printer driver did: +;* +;* ImageWriter: Return Color option +;* ImageWriter LQ: Return Model ID, Multiple bins and Color options +;* Unknown: Return nothing (String of zero length) +;* +;* +;* Input: WORD space for result +;* LONG buffer pointer +;* WORD number of bytes to transfer +;* +;* Output: WORD number of bytes transferred +;* +;*********************************************************************** + + using PortData + + port_subroutine (2:bytes_to_send,4:buffer,2:bytes_transfered) + + +; Dispatch to return the appropriate string (depending on the printer +; type - we determined the printer type from the last two commands... +; see the open/write routine comments for details) + + ldx PrinterType + jmp (ReadDispatch,x) + +; Routine name Printer type +ReadDispatch anop + dc a4'ReadUnknown' ; Unknown + dc a4'ReadIMWR' ; ImageWriter + dc a4'ReadIMWR_LQ' ; ImageWriter LQ + + +; For most printers, there aren't any bytes to be read. Return +; the standard zero length string. + +ReadUnknown anop + lda #0 + sta bytes_transfered + bra read_return + + +; Set the output buffer up for a ImageWriter returned string... +; (IE: Color) + +ReadIMWR anop + lda ImWr_ReadLen + sta bytes_transfered + + ldy ImWr_ReadLen + dey +ReadIMWR2 anop + dey + lda ImWr_Read,y + sta [buffer],y + cpy #0 + bne ReadIMWR2 + bra read_return + + +; Set the output buffer up for a ImageWriter LQ returned string... +; (IE: Multiple bins and Color) + +ReadIMWR_LQ anop + lda ImWr_LQ_ReadLen + sta bytes_transfered + + ldy ImWr_LQ_ReadLen + dey +ReadIMWR_LQ2 anop + dey + lda ImWr_LQ_Read,y + sta [buffer],y + cpy #0 + bne ReadIMWR_LQ2 + + +; Back to our caller we go... + +read_return anop + + port_return 2:bytes_transfered + rtl + + end ; of PrDevRead + + + +;*********************************************************************** +;* +PrDevWrite start +;* +;* Description: +;* Writes the data in the buffer to the printer and calls +;* the completion routine. +;* +;* Our version of this routine will copy the information to +;* our buffer. Once the buffer is full (check before the copy +;* and if the copy would fill it then only copy what will fill +;* it). If the buffer is full then write it to the output +;* file. If there is still stuff to in the input buffer, then +;* loop to the beginning of this routine again. +;* Once we're done, its time to call the completion routine. +;* +;* Input: LONG write completion pointer +;* LONG buffer pointer +;* WORD buffer length +;* +;*********************************************************************** + + using PortData + + port_subroutine (2:bytes_to_send,4:buffer,4:completion_routine) + +; Lets see if we can determine the type of printer driver (for special +; printers). We only do this specialness on the first write after an +; open. + + lda PortCallCounter + cmp #1 + bne WriteNotSpecial + bra ttt ; do no specialness stuff + +; Check for an ImageWriter (check length of buffer, then the buffer) + +WriteIMWR anop + lda bytes_to_send + cmp ImWr_WriteLen + bne WriteIMWR_LQ + + ldy ImWr_WriteLen + dey +WriteIMWR2 anop + dey + lda ImWr_Write,y + cmp [buffer],y + bne WriteIMWR_LQ + cpy #0 + bne WriteIMWR2 + + +; Looks like and ImageWrite status string to me. +; Set the special printer flag for later. +; remove these lines for ImageWriter I. + lda #PT_ImageWriter + sta PrinterType + bra WriteNotSpecial + + +; Check for an ImageWriter LQ (check length of buffer, then the buffer) + +WriteIMWR_LQ anop + lda bytes_to_send + cmp ImWr_LQ_WriteLen + bne WriteNotSpecial + + ldy ImWr_LQ_WriteLen + dey +WriteIMWR_LQ2 anop + dey + lda ImWr_LQ_Write,y + cmp [buffer],y + bne WriteNotSpecial + cpy #0 + bne WriteIMWR_LQ2 + + +; Looks like and ImageWrite LQ status string to me. +; Set the special printer flag for later. + + lda #PT_ImageWriterLQ + sta PrinterType +; bra WriteNotSpecial + + +; Continue with the standard port write + +WriteNotSpecial anop + + +; Call the C routine to write the data/command to a file... + + PushWord bytes_to_send + PushLong buffer + + jsl >c_port_write + + +; We're all done - return a success to our caller... + +ttt port_return 0:stump,completion_routine + cmp #1 + rtl + + end ; of PrDevWrite + + + +;*********************************************************************** +;* +PrDevClose start +;* +;* Description: +;* +;* This call is not required to do anything. However, if +;* you allocate any system resources with PrDevOpen, you +;* should deallocate them at this time. As with start and +;* shutdown, note that PrDevClose could be called without a +;* balancing PrDevOpen (the reverse is not true), and you +;* must be prepared for this if you try to deallocate +;* resources which were never allocated. +;* +;* Our version of this routine will close the file (if it +;* is open). If we find a CANCELLED flag, then we will +;* just reset the flag. +;* +;* Input: none +;* +;*********************************************************************** + + port_subroutine + +; Attempt to close the data/command files +; +; Note: The files may not have been opened! + + jsl >c_port_close + + port_return + rtl + + end ; of PrDevClose + + + +;*********************************************************************** +;* +PrDevStatus start +;* +;* Description: +;* +;* This call performs differently for direct connect and +;* network drivers. For direct connect drivers, it currently +;* has no required function, although it may return the status +;* of the port in the future. For network drivers, it calls +;* an AppleTalk status routine, which returns a status string +;* in the buffer (normally a string like "Status: The print +;* server is spooling your document"). +;* +;* Our version of this routine will do nothing. +;* +;* Input: LONG status buffer pointer +;* +;*********************************************************************** + + port_subroutine (4:status) + + port_return + cmp #1 + rtl + + end ; of PrDevStatus + + + +;*********************************************************************** +;* +PrDevAsyncRead start +;* +;* Description: +;* Since PrDevRead cannot read asynchronously, this call is +;* provided for that task. Note that this does nothing for +;* direct connect drivers, and if the completion pointer is +;* NIL, it behaves for network drivers exactly as PrDevRead +;* does. +;* +;* Our version of this routine will do nothing. +;* +;* Input: WORD space for result +;* LONG completion pointer +;* WORD buffer length +;* LONG buffer pointer +;* +;* Output: WORD number of bytes transferred +;* +;*********************************************************************** + + port_subroutine (4:buffer,2:length,4:cmp_rtn,2:bytes_transfered) + + lda #0 + sta bytes_transfered + + port_return 2:bytes_transfered,cmp_rtn + cmp #1 + rtl + + end ; of PrDevAsyncRead + + + +;*********************************************************************** +;* +PrDevWriteBackground start +;* +;* Description: +;* This routine is not implemented at this time. +;* +;* Our version of this routine will do nothing. +;* +;* Input: LONG completion procedure pointer +;* WORD buffer length +;* LONG buffer pointer +;* +;*********************************************************************** + + port_subroutine (4:buffer,2:length,4:completion_routine) + + port_return 0:stump,completion_routine + cmp #1 + rtl + + end ; of PrDevWriteBackground + + + +;*********************************************************************** +;* +PrPortVer start +;* +;* Description: +;* Returns the version number of the currently installed +;* port driver. +;* +;* Our version of this routine will do nothing. +;* +;* Note: The internal version number is stored as a major +;* byte and a minor byte (i.e., $0103 represents version 1.3) +;* +;* Input: WORD space for result +;* +;* Output: WORD Port driver's version number +;* +;*********************************************************************** + + port_subroutine (2:version_number) + + lda #$0401 ; Rev 4.1 + sta version_number ; Save it + + port_return 2:version_number + rtl + + end ; of PrPortVer + + + +;*********************************************************************** +;* +PrDevIsItSafe start +;* +;* Description: +;* This call checks to see if the port or card which your +;* driver controls is enabled. It should check at least +;* the corresponding bit of $E0C02D, and checking the Battery +;* RAM settings wouldn't hurt any either. +;* +;* Our version of this routine will return TRUE - we don't +;* really drive any port, so we can't really check to see if +;* we are allowed to access the port/slot or not. +;* +;* Input: WORD space for result +;* +;* Output: WORD Boolean indicating if port +;* is enabled +;* +;*********************************************************************** + + port_subroutine (2:port_safe_flag) + + lda #TRUE ; Its always safe... + sta port_safe_flag ; Save it + + port_return 2:port_safe_flag + rtl + + end ; of PrDevIsItSafe + + + +;*********************************************************************** +;* +PortData data +;* +;* File Port Driver Data Section +;* +;* Description: +;* This section is all of the data that the file port driver +;* requires (not very much really...). +;* +;*********************************************************************** + +; Special Printer Types + +PrinterType ds 2 + + +; Count of the Port calls made since an Open + +PortCallCounter dc i2'0' + + +; ImageWriter model ID/status/options string (written) + +ImWr_Write dc i1'$1b,$3f' +ImWr_WriteLen dc i2'*-ImWr_Write' + + +; ImageWriter model ID/status/options string (read) + +ImWr_Read dc i1'$49,$57,$31,$30,$43' +ImWr_ReadLen dc i2'*-ImWr_Read' + + +; ImageWriter LQ model ID/status/options string (written) + +ImWr_LQ_Write dc i1'$1b,$5a,$00,$02,$1b,$3f' +ImWr_LQ_WriteLen dc i2'*-ImWr_LQ_Write' + + +; ImageWriter LQ model ID/status/options string (read) + +ImWr_LQ_Read dc i1'$4c,$51,$31,$45,$43' +ImWr_LQ_ReadLen dc i2'*-ImWr_LQ_Read' + + + + end ; End of File Port Driver diff --git a/sys/fileport/fileport/port.macros b/sys/fileport/fileport/port.macros index 7c5fc53..52cdfcd 100644 --- a/sys/fileport/fileport/port.macros +++ b/sys/fileport/fileport/port.macros @@ -1 +1,323 @@ - ; ; Copyright (C) Kopriha Software, 1990 - 1991 ; All rights reserved. ; Licensed material -- property of Kopriha Software ; ; This software is made available solely pursuant to the terms ; of a Kopriha Software license agreement which governs its use. ; ; ; The following macros (port_routine/port_return) are support ; routines for IIGS port drivers. ; ; ; Macros: port_routine (:[,...])[,] ; - Enter a port driver routine ; ; port_return :[,] ; - Exit a port driver routine ; - This macro must be followed by an RTL. By coding the ; macro this way you can customize the return (some, but ; not all port driver routines must return after a CMP #1. ; See the source to port.asm for the details). ; ; ; Note: These macros are derived from the csubroutine/creturn ; macros supplied with Orca/C (on the demos disk). ; MACRO &lab port_subroutine &parms,&work &lab anop Places the label from macro invocation aif c:&work,.a If there is a work parm goto .a lclc &work Local define work a string &work setc 0 Set work to zero .a .a gbla &totallen Global define totallen gbla &worklen Global define worklen gbla &PClen Global define length of PC &worklen seta &work Set worklen = work (type conversion) &totallen seta 0 Set totallen to zero &PClen seta 8 Set PC length to 8 (6(rtnPC*2)+1(direct page)+1(data bank)) aif c:&parms=0,.e If there are no parms to routine then goto .e lclc &len Local define char len lclc &p Local define char p lcla &i Local define int i &i seta 1 i = 1 .b .b &p setc &parms(&i) p = parms[i] &len amid &p,2,1 len = substr(p,2,1) aif "&len"=":",.c if len == ':' goto .c &len amid &p,1,2 len = substr(p,1,2) {First 2 chars} &p amid &p,4,l:&p-3 p = substr(p,4,strlen(p)-3) {get name} ago .d goto .d .c .c &len amid &p,1,1 len = substr(p,1,1) {only first char} &p amid &p,3,l:&p-2 p = substr(p,3,strlen(p)-2) {get name} .d .d We have a name and its length &p equ &totallen+&PClen+&work {name} equ totallen+PClen+work &totallen seta &totallen+&len totallen = totallen+len (length of parm) &i seta &i+1 i = i + 1 aif &i<=c:&parms,^b if i<#parms goto b (backwards goto) .e .e All parms setup (equ'd) tsc get stack pointer aif &work=0,.f If you need work space... sec add it onto the stack pointer sbc #&work tcs .f Stack is setup by here... phd Save the direct page tcd Set direct page == stack ptr mend Thus lda parm is a direct page reference... MACRO &lab port_return &returnparm,&comproutine ; ; Parse the return parameter (if defined). ; &lab anop Place any label from macro invocation lclc &len Local create len aif c:&returnparm,.a If there is a parameter goto .a lclc &returnparm Local create r (for parm length) &returnparm setc 0 Set returnparm to zero &len setc 0 Set len to zero ago .h Goto skip arguement parsing .a .a We have a parameter - parse it! &len amid &returnparm,2,1 len = substr(r,2,1) aif "&len"=":",.b if (len == ':') goto .b &len amid &returnparm,1,2 len = substr(r,1,2) &returnparm amid &returnparm,4,l:&returnparm-3 r = substr(r,4,strlen(r)-3) ago .c goto .c .b .b One character length... &len amid &returnparm,1,1 len = substr(r,1,1) &returnparm amid &returnparm,3,l:&returnparm-2 r = substr(3,1,strlen(r)-2) ; ; Get the return parameter - if we have something to ; return. The return parameter can be 2,4 or 10 bytes ; (IE: Word, Long or Sane #). ; .c aif &len=0,.h If len == 0 then skip this... aif &len<>2,.d if len != 2 goto .d ldy &returnparm LDY ago .h goto .h .d .d Not length == 2 aif &len<>4,.e if length != 4 goto .e ldx &returnparm+2 LDX +2 (high byte) ldy &returnparm LDY (low byte) ago .h goto .h .e .e Not length == 4 aif &len<>10,.g if length != 10 (IE: Sane #) goto .g ldx #^&returnparm LDX #^ (high byte) ldy #&returnparm LDY # (low byte) &len setc 4 We're returning a pointer...len 4 ago .h goto .h .g .g Not sane # (hehehe) mnote 'Not a valid return length',16 Print error} mexit Oops... stop here ; ; Setup the completion routine - if there is one. ; .h aif c:&comproutine=0,.m ; ; Ok, lets setup the completion routine JSR (but only if its not NIL) ; stz cjmp&SYSCNT+1 Clear the completion routine address stz cjmp&SYSCNT+2 (all three words of it...) ; lda &comproutine ora &comproutine+1 'OR' the other bits in... beq compa&SYSCNT If its NIL, then return to our caller. ; ; Looks non-NIL to me. Setup the completion routine call and then do it. ; (Ug... self modifying code... Its the easy solution for now...) ; lda &comproutine Get low 2 bytes sta cjmp&SYSCNT+1 Save them in our JSR instruction lda &comproutine+1 Get the high bytes (actually, sta cjmp&SYSCNT+2 just the bank byte...) compa&SYSCNT anop ; ; Setup the return parameters on the stack (if any) ; .m aif &len<>2,.k If return nothing, goto .j sty &worklen+&totallen+&PClen-&len .k aif &len<>4,.j stx &worklen+&totallen+&PClen-&len Store low byte sty &worklen+&totallen+&PClen-&len+2 Store high byte .j ; ; If the return PCs need to be moved, then lets move ; them... the determination is based on if we have ; to remove parameters from the stack. ; Note: The order of the moving these PCs is significant! ; We must move the PCs in the order coded... any other ; may cause the first store to overwrite part of the ; PCs before moving them. ; aif &totallen=0,.i if no parms to port_routine, goto .i aif &totallen-&len=0,.i No sense in moving PCs nowhere... lda &worklen+6 Copy return PCs (both of them) sta &worklen+&totallen+6-&len lda &worklen+4 sta &worklen+&totallen+4-&len lda &worklen+2 sta &worklen+&totallen+2-&len .i ; ; If there is a possible completion routine, then ; generate the code to check if it actually exists ; and if it does then call it (jsl) - otherwise rtl. ; aif c:&comproutine=0,.p ; ; Ok, lets go to the completion routine JSR (but only if its not NIL) ; lda cjmp&SYSCNT+1 Is there a completion routine? ora cjmp&SYSCNT+2 'OR' the rest of the address... beq compb&SYSCNT If its NIL, then return to our caller. .i ; ; Looks non-NIL to me. Setup the completion routine call and then do it. ; (Ug... self modifying code... Its the easy solution for now...) ; clc Clear carry - no errors on this call lda #0 (Also need zero in ac for no error!) cjmp&SYSCNT jsr >123456 Jmp to the completion routine compb&SYSCNT anop (Jsl would come back to a rtl, may as well just go there) .p ; ; If we have to then it is time to adjust the stack pointer ; (also get the direct page/data bank restored for our caller) ; pld Restore the direct page plb Restore the data bank aif &worklen+&totallen-&len=0,.o If we aren't changing the stack ptr tsc Fix the stack pointer clc ... adc #&worklen+&totallen-&len ... tcs ... .o clc Clear carry - no errors on this call lda #0 (Also need zero in ac for no error!) mend ;............................................................ ; ; Push long (4 bytes) onto stack ; ; pushlong address - push contents of address ; pushlong address,x - push contents of address,x ; pushlong const,s - push contents of stack+const ; pushlong #address/const - push address or constant ; pushlong [zeropage],offset - push using indirect address ;............................................................... MACRO &lab pushlong &addr,&offset &lab ANOP LCLC &C LCLC &REST &C AMID &addr,1,1 AIF "&C"="#",.immediate AIF "&C"="[",.zeropage AIF C:&offset=0,.nooffset AIF "&offset"="s",.stack pushword &addr+2,&offset pushword &addr,&offset MEXIT .nooffset pushword &addr+2 pushword &addr MEXIT .immediate &REST AMID &addr,2,L:&addr-1 dc I1'$F4',I2'(&REST)|-16' dc I1'$F4',I2'&REST' MEXIT .stack pushword &addr+2,s pushword &addr+2,s MEXIT .zeropage ldy #&offset+2 pushword &addr,y ldy #&offset pushword &addr,y MEND ;............................................................... ; ; Push 3 bytes onto stack ; ; push3 addr -- pushes bytes onto stack from "loc" ; push3 addr,x -- pushes bytes onto stack from "loc,x" ; push3 #n -- pushes constant #n onto stack ;............................................................... MACRO &lab push3 &addr,® &lab ANOP LCLC &C LCLC &REST &C AMID &addr,1,1 &REST AMID &addr,2,L:&addr AIF C:®>0,.indexed AIF "&C"="#",.immediate lda &addr+1 pha AGO .a .immediate lda #(&REST)|-8 pha .a phb lda &addr sta 1,s MEXIT .indexed lda &addr+1,® pha phb lda &addr,® sta 1,s MEND ;............................................................... ; ; Push 2 bytes onto stack ; ; pushword loc -- pushes bytes onto stack from "loc" ; pushword loc,x -- pushes bytes onto stack from "loc,x" ; pushword #n -- pushes constant #n onto stack ; pushword -- pushes bytes onto stack (from A) ;............................................................... MACRO &lab pushword &SYSOPR &lab ANOP AIF C:&SYSOPR=0,.b LCLC &C &C AMID "&SYSOPR",1,1 AIF ("&C"="#").AND.(S:LONGA),.immediate lda &SYSOPR pha MEXIT .b pha MEXIT .immediate LCLC &REST LCLA &BL &BL ASEARCH "&SYSOPR"," ",1 AIF &BL>0,.a &BL SETA L:&SYSOPR+1 .a &REST AMID "&SYSOPR",2,&BL-2 dc I1'$F4',I2'&REST' MEND \ No newline at end of file + +; +; Copyright (C) Kopriha Software, 1990 - 1991 +; All rights reserved. +; Licensed material -- property of Kopriha Software +; +; This software is made available solely pursuant to the terms +; of a Kopriha Software license agreement which governs its use. +; +; +; The following macros (port_routine/port_return) are support +; routines for IIGS port drivers. +; +; +; Macros: port_routine (:[,...])[,] +; - Enter a port driver routine +; +; port_return :[,] +; - Exit a port driver routine +; - This macro must be followed by an RTL. By coding the +; macro this way you can customize the return (some, but +; not all port driver routines must return after a CMP #1. +; See the source to port.asm for the details). +; +; +; Note: These macros are derived from the csubroutine/creturn +; macros supplied with Orca/C (on the demos disk). +; + MACRO +&lab port_subroutine &parms,&work +&lab anop Places the label from macro invocation + aif c:&work,.a If there is a work parm goto .a + lclc &work Local define work a string +&work setc 0 Set work to zero +.a .a + gbla &totallen Global define totallen + gbla &worklen Global define worklen + gbla &PClen Global define length of PC +&worklen seta &work Set worklen = work (type conversion) +&totallen seta 0 Set totallen to zero +&PClen seta 8 Set PC length to 8 (6(rtnPC*2)+1(direct page)+1(data bank)) + aif c:&parms=0,.e If there are no parms to routine then goto .e + lclc &len Local define char len + lclc &p Local define char p + lcla &i Local define int i +&i seta 1 i = 1 +.b .b +&p setc &parms(&i) p = parms[i] +&len amid &p,2,1 len = substr(p,2,1) + aif "&len"=":",.c if len == ':' goto .c +&len amid &p,1,2 len = substr(p,1,2) {First 2 chars} +&p amid &p,4,l:&p-3 p = substr(p,4,strlen(p)-3) {get name} + ago .d goto .d +.c .c +&len amid &p,1,1 len = substr(p,1,1) {only first char} +&p amid &p,3,l:&p-2 p = substr(p,3,strlen(p)-2) {get name} +.d .d We have a name and its length +&p equ &totallen+&PClen+&work {name} equ totallen+PClen+work +&totallen seta &totallen+&len totallen = totallen+len (length of parm) +&i seta &i+1 i = i + 1 + aif &i<=c:&parms,^b if i<#parms goto b (backwards goto) +.e .e All parms setup (equ'd) + tsc get stack pointer + aif &work=0,.f If you need work space... + sec add it onto the stack pointer + sbc #&work + tcs +.f Stack is setup by here... + phd Save the direct page + tcd Set direct page == stack ptr + mend Thus lda parm is a direct page reference... + + MACRO +&lab port_return &returnparm,&comproutine +; +; Parse the return parameter (if defined). +; +&lab anop Place any label from macro invocation + lclc &len Local create len + aif c:&returnparm,.a If there is a parameter goto .a + lclc &returnparm Local create r (for parm length) +&returnparm setc 0 Set returnparm to zero +&len setc 0 Set len to zero + ago .h Goto skip arguement parsing +.a .a We have a parameter - parse it! +&len amid &returnparm,2,1 len = substr(r,2,1) + aif "&len"=":",.b if (len == ':') goto .b +&len amid &returnparm,1,2 len = substr(r,1,2) +&returnparm amid &returnparm,4,l:&returnparm-3 r = substr(r,4,strlen(r)-3) + ago .c goto .c +.b .b One character length... +&len amid &returnparm,1,1 len = substr(r,1,1) +&returnparm amid &returnparm,3,l:&returnparm-2 r = substr(3,1,strlen(r)-2) +; +; Get the return parameter - if we have something to +; return. The return parameter can be 2,4 or 10 bytes +; (IE: Word, Long or Sane #). +; +.c + aif &len=0,.h If len == 0 then skip this... + aif &len<>2,.d if len != 2 goto .d + ldy &returnparm LDY + ago .h goto .h +.d .d Not length == 2 + aif &len<>4,.e if length != 4 goto .e + ldx &returnparm+2 LDX +2 (high byte) + ldy &returnparm LDY (low byte) + ago .h goto .h +.e .e Not length == 4 + aif &len<>10,.g if length != 10 (IE: Sane #) goto .g + ldx #^&returnparm LDX #^ (high byte) + ldy #&returnparm LDY # (low byte) +&len setc 4 We're returning a pointer...len 4 + ago .h goto .h +.g .g Not sane # (hehehe) + mnote 'Not a valid return length',16 Print error} + mexit Oops... stop here +; +; Setup the completion routine - if there is one. +; +.h + aif c:&comproutine=0,.m +; +; Ok, lets setup the completion routine JSR (but only if its not NIL) +; + stz cjmp&SYSCNT+1 Clear the completion routine address + stz cjmp&SYSCNT+2 (all three words of it...) +; + lda &comproutine + ora &comproutine+1 'OR' the other bits in... + beq compa&SYSCNT If its NIL, then return to our caller. +; +; Looks non-NIL to me. Setup the completion routine call and then do it. +; (Ug... self modifying code... Its the easy solution for now...) +; + lda &comproutine Get low 2 bytes + sta cjmp&SYSCNT+1 Save them in our JSR instruction + lda &comproutine+1 Get the high bytes (actually, + sta cjmp&SYSCNT+2 just the bank byte...) +compa&SYSCNT anop +; +; Setup the return parameters on the stack (if any) +; +.m + aif &len<>2,.k If return nothing, goto .j + sty &worklen+&totallen+&PClen-&len +.k + aif &len<>4,.j + stx &worklen+&totallen+&PClen-&len Store low byte + sty &worklen+&totallen+&PClen-&len+2 Store high byte +.j +; +; If the return PCs need to be moved, then lets move +; them... the determination is based on if we have +; to remove parameters from the stack. +; Note: The order of the moving these PCs is significant! +; We must move the PCs in the order coded... any other +; may cause the first store to overwrite part of the +; PCs before moving them. +; + aif &totallen=0,.i if no parms to port_routine, goto .i + aif &totallen-&len=0,.i No sense in moving PCs nowhere... + lda &worklen+6 Copy return PCs (both of them) + sta &worklen+&totallen+6-&len + lda &worklen+4 + sta &worklen+&totallen+4-&len + lda &worklen+2 + sta &worklen+&totallen+2-&len +.i +; +; If there is a possible completion routine, then +; generate the code to check if it actually exists +; and if it does then call it (jsl) - otherwise rtl. +; + aif c:&comproutine=0,.p +; +; Ok, lets go to the completion routine JSR (but only if its not NIL) +; + lda cjmp&SYSCNT+1 Is there a completion routine? + ora cjmp&SYSCNT+2 'OR' the rest of the address... + beq compb&SYSCNT If its NIL, then return to our caller. +.i +; +; Looks non-NIL to me. Setup the completion routine call and then do it. +; (Ug... self modifying code... Its the easy solution for now...) +; + clc Clear carry - no errors on this call + lda #0 (Also need zero in ac for no error!) +cjmp&SYSCNT jsr >123456 Jmp to the completion routine +compb&SYSCNT anop (Jsl would come back to a rtl, may as well just go there) +.p +; +; If we have to then it is time to adjust the stack pointer +; (also get the direct page/data bank restored for our caller) +; + pld Restore the direct page + plb Restore the data bank + aif &worklen+&totallen-&len=0,.o If we aren't changing the stack ptr + tsc Fix the stack pointer + clc ... + adc #&worklen+&totallen-&len ... + tcs ... +.o + clc Clear carry - no errors on this call + lda #0 (Also need zero in ac for no error!) + mend + +;............................................................ +; +; Push long (4 bytes) onto stack +; +; pushlong address - push contents of address +; pushlong address,x - push contents of address,x +; pushlong const,s - push contents of stack+const +; pushlong #address/const - push address or constant +; pushlong [zeropage],offset - push using indirect address +;............................................................... + MACRO +&lab pushlong &addr,&offset +&lab ANOP + LCLC &C + LCLC &REST +&C AMID &addr,1,1 + AIF "&C"="#",.immediate + AIF "&C"="[",.zeropage + AIF C:&offset=0,.nooffset + AIF "&offset"="s",.stack + pushword &addr+2,&offset + pushword &addr,&offset + MEXIT +.nooffset + pushword &addr+2 + pushword &addr + MEXIT +.immediate +&REST AMID &addr,2,L:&addr-1 + dc I1'$F4',I2'(&REST)|-16' + dc I1'$F4',I2'&REST' + MEXIT +.stack + pushword &addr+2,s + pushword &addr+2,s + MEXIT +.zeropage + ldy #&offset+2 + pushword &addr,y + ldy #&offset + pushword &addr,y + MEND +;............................................................... +; +; Push 3 bytes onto stack +; +; push3 addr -- pushes bytes onto stack from "loc" +; push3 addr,x -- pushes bytes onto stack from "loc,x" +; push3 #n -- pushes constant #n onto stack +;............................................................... + MACRO +&lab push3 &addr,® +&lab ANOP + LCLC &C + LCLC &REST +&C AMID &addr,1,1 +&REST AMID &addr,2,L:&addr + AIF C:®>0,.indexed + AIF "&C"="#",.immediate + lda &addr+1 + pha + AGO .a +.immediate + lda #(&REST)|-8 + pha +.a + phb + lda &addr + sta 1,s + MEXIT +.indexed + lda &addr+1,® + pha + phb + lda &addr,® + sta 1,s + MEND +;............................................................... +; +; Push 2 bytes onto stack +; +; pushword loc -- pushes bytes onto stack from "loc" +; pushword loc,x -- pushes bytes onto stack from "loc,x" +; pushword #n -- pushes constant #n onto stack +; pushword -- pushes bytes onto stack (from A) +;............................................................... + MACRO +&lab pushword &SYSOPR +&lab ANOP + AIF C:&SYSOPR=0,.b + LCLC &C +&C AMID "&SYSOPR",1,1 + AIF ("&C"="#").AND.(S:LONGA),.immediate + lda &SYSOPR + pha + MEXIT +.b + pha + MEXIT +.immediate + LCLC &REST + LCLA &BL +&BL ASEARCH "&SYSOPR"," ",1 + AIF &BL>0,.a +&BL SETA L:&SYSOPR+1 +.a +&REST AMID "&SYSOPR",2,&BL-2 + dc I1'$F4',I2'&REST' + MEND + + + + + + + diff --git a/sys/fileport/fileport/test.c b/sys/fileport/fileport/test.c index f2ba8b7..c1e78c2 100644 --- a/sys/fileport/fileport/test.c +++ b/sys/fileport/fileport/test.c @@ -1 +1,17 @@ - #include void c_port_open(void); void c_port_write(char *, int); void c_port_close(void); char buffer[] = {"This is a simple test...\n"}; int main(int argc, char * argv[]) { c_port_open(); c_port_write(&buffer[0], (int) 25); c_port_close(); exit(0); } \ No newline at end of file + +#include + +void c_port_open(void); +void c_port_write(char *, int); +void c_port_close(void); + +char buffer[] = {"This is a simple test...\n"}; + +int main(int argc, char * argv[]) +{ + c_port_open(); + c_port_write(&buffer[0], (int) 25); + c_port_close(); + exit(0); +} + diff --git a/sys/fileport/fileport/testiw.c b/sys/fileport/fileport/testiw.c index 66065f8..b483ce7 100644 --- a/sys/fileport/fileport/testiw.c +++ b/sys/fileport/fileport/testiw.c @@ -1 +1,39 @@ -#include #include void dor(int r) { if (r < 32) { ErrWriteChar(' '); ErrWriteChar('^'); ErrWriteChar(r+64); ErrWriteChar(' '); } else { ErrWriteChar(' '); ErrWriteChar(r); ErrWriteChar(' '); } } int main(int argc, char *argv[]) { int r; SetInputDevice(1,1l); SetOutputDevice(1,1l); InitTextDev(0); WriteChar(27); WriteChar('?'); r = ReadChar(0); dor(r); r = ReadChar(0); dor(r); r = ReadChar(0); dor(r); r = ReadChar(0); dor(r); r = ReadChar(0); dor(r); } \ No newline at end of file +#include +#include + +void dor(int r) +{ + if (r < 32) { + ErrWriteChar(' '); + ErrWriteChar('^'); + ErrWriteChar(r+64); + ErrWriteChar(' '); + } + else { + ErrWriteChar(' '); + ErrWriteChar(r); + ErrWriteChar(' '); + } +} + +int main(int argc, char *argv[]) +{ +int r; + + SetInputDevice(1,1l); + SetOutputDevice(1,1l); + InitTextDev(0); + + WriteChar(27); + WriteChar('?'); + r = ReadChar(0); + dor(r); + r = ReadChar(0); + dor(r); + r = ReadChar(0); + dor(r); + r = ReadChar(0); + dor(r); + r = ReadChar(0); + dor(r); +} diff --git a/sys/fileport/includes/KS.CDEV.h b/sys/fileport/includes/KS.CDEV.h index f53f524..9e03cf1 100644 --- a/sys/fileport/includes/KS.CDEV.h +++ b/sys/fileport/includes/KS.CDEV.h @@ -1 +1,522 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * KS.CDev.h * * Description: This include file contains all the external * variable and routine definitions (prototypes) * for the SpoolMaster CDEV. * * * Table of contents: * * Defined variables: * * All CDEV flags passed the CDEV entry point * All control IDs of the defined controls * The port driver file/aux type * * * External variables: * * static_text_substitution * text0_string * text_control_handle * * * External routines: * * do_about() * do_create() * do_hit() * * scroll_action() * * * * History:May 18, 1991 Dave Created this file * */ #ifndef _KS_CDEV_ #define _KS_CDEV_ /* define HEY_DAVE_WE_MUST_DEBUG_MORE */ #ifndef _KS_FILEIO_ #include "KS.FileIO.E" #endif #ifndef _KS_DEFINES_ #include "KS.Defines.h" #endif #ifndef _KS_ROUTINES_ #include "KS.Routines.h" #endif #ifndef _KS_MEMORY_ #include "ks.memory.h" #endif #ifndef _KS_SHARED_DATA_ #include "SharedData.h" #endif #ifndef __CONTROL__ #include #endif #ifndef __LIST__ #include #endif #ifndef __STDFILE__ #include #endif #ifndef __RESOURCES__ #include #endif #ifndef __LOADER__ #include #endif /* ****************************************************************** * * Macro definitions: * * ****************************************************************** */ /* ****************************************************************** * * The following macro simplifies by global variable definitions... * * * * The reasoning goes like this: * * EXTERNAL is defined as extern by all modules that include this * * file but have not defined EXTERNAL (IE: All but Data.CC). * * Data.CC defines EXTERNAL to be nothing - thus we create the * * data in Data.CC but do not have to duplicate the global * * variable definitions... * * * * This seems to simplify my maintenance - once copy of variable * * definitions to support... * * ****************************************************************** */ #ifndef EXTERNAL #define EXTERNAL extern #endif /* ****************************************************************** * * The following are all of the currently defined 'events' that are * * passed to the CDEV entry point. * * ****************************************************************** */ #define MachineCDEV 1 #define BootCDEV 2 #define Reserved 3 #define InitCDEV 4 #define CloseCDEV 5 #define EventsCDEV 6 #define CreateCDEV 7 #define AboutCDEV 8 #define RectCDEV 9 #define HitCDEV 10 #define RunCDEV 11 /* ****************************************************************** * * The following is a list of all the controls we have defined for * * the spoolmaster CDEV * * * * Note: Static text controls are not included in this list. * * ****************************************************************** */ #define MainControlList (1L) #define PortListControl (3L) #define SpoolDirButtonControl (4L) #define ScrollBarControl (6L) #define BufferSizeTextControl (7L) #define PrintFileCheckBoxCtl (8L) #define DeleteFileCheckBoxCtl (9L) #define HelpControl (0x0100L) #define CantWriteAlert (1L) #define CantWriteOkButton (0) #define CantWriteTryAgain (1) #define SpoolDirPrompt (1L) #ifdef HEY_DAVE_WE_MUST_DEBUG_MORE #define DebugCloseAlert (2L) #define DebugRoutineEntry (3L) #define DebugRoutineExit (4L) #define DebugEndOfLoop (5L) #define DebugStandardFile (6L) #endif /* * Macro definition of print task id (for resource file) */ #define PrintTask (2L) /* * Macro definitions of the saved user parameters */ #define SpoolDefaultsType (0x0a13) #define rMyCodeResource (0x0a14) #define SpoolOptions (0x010L) #define SpoolPrefix (0x010L) /* * Macro definitions of the standard file dialog template item numbers */ #define SFDT_SaveItem 1 #define SFDT_OpenItem 2 #define SFDT_CloseItem 3 #define SFDT_NextItem 4 #define SFDT_CancelItem 5 #define SFDT_ScrollItem 6 #define SFDT_PathItem 7 #define SFDT_FileItem 8 #define SFDT_PromptItem 9 #define SFDT_FilenameItem 10 #define SFDT_FreeSpaceItem 11 #define SFDT_NewFolderItem 12 /* ****************************************************************** * * Port driver filetype and auxtype - used when we're building the * * port driver list... Apple should have defined these... * * ****************************************************************** */ #define PORT_DRIVER_TYPE ((Word) 0x0bb) #define PORT_DRIVER_AUXTYPE ((Long) 2) /* ****************************************************************** * * Structure for the loader (actually InitialLoad2 with flagWord==2. * * ****************************************************************** */ typedef struct { Pointer memoryAddress; Word fileLength; } InitialLoad2_Pkt; /* ****************************************************************** * * Standard file name/path reference description for an undefined * * reference... Apple should have defined this... * * ****************************************************************** */ #define STDFILE_REFERENCE_UNDEFINED ((Word) 3) /* ****************************************************************** * * Non-purgable purge level for memory blocks (setup by the memory * * manager on a SetPurge. Apple should have defined this... * * ****************************************************************** */ #define NOT_PURGEABLE ((Word) 0) /* ****************************************************************** * * Maximum string stubstitution index (apple should have defined * * this) * * ****************************************************************** */ #define MAX_SUB_INDEX 10 /* ****************************************************************** * * Macros to get the filename/pathname from a standard file dialog. * * ****************************************************************** */ #define DerefFileName ((** (ResultBuf255 **) ReplyRecord.nameRef).bufString) #define DerefFilePath ((** (ResultBuf255 **) ReplyRecord.pathRef).bufString) /* ****************************************************************** * * External definitions: * * ****************************************************************** */ /* * static_text_substitution[] - is the static text substitution array. * * We use text substitution to display the selected buffer size. */ EXTERNAL Pointer static_text_substitution[MAX_SUB_INDEX]; /* * text0_string[] - this is the single substitution string we use. */ EXTERNAL char text0_string[10]; /* * cdev_window_handle - is the handle to the window of the CDEV. */ EXTERNAL WindowPtr cdev_window_handle; /* * text_control_handle - handle to the static text that will * display the selected buffer size. * * Note: This is defined here as a performance improvement to * the user interface (I see no reason to continually make * the toolbox call to get this handle to redraw the text...). */ EXTERNAL CtlRecHndl text_control_handle; /* * Flags indicating which toolsets needed to be started... */ EXTERNAL Word QDAuxStarted; EXTERNAL Word IMStarted; EXTERNAL Word FMStarted; EXTERNAL Word TEStarted; EXTERNAL Word LMStackPointer; EXTERNAL Word OriginalStackPtr; /* * Handles to the memory allocated for toolsets that we started. */ EXTERNAL Handle MemoryForFM; EXTERNAL Handle MemoryForTE; EXTERNAL Handle MemoryForLM; /* * list_handle/list_pointer are the handle/pointer to the Member * record for the port driver list. */ EXTERNAL MemRecHndl list_handle; EXTERNAL MemRecPtr list_pointer; EXTERNAL CtlRecHndl list_control; EXTERNAL Word number_of_ports; EXTERNAL Word selected_port; /* * orig_control_values - this is a SHARED_DATA structure that holds * the original copy of all the control values. * * It is currently setup when we process the OPEN event of the CDEV! * This will soon change to the INIT event. */ EXTERNAL KS_SHARED_DATA_HDL shared_data_handle; EXTERNAL KS_SHARED_DATA_PTR shared_data_values; EXTERNAL ResultBuf255Hndl shared_spooldir_hdl; EXTERNAL ResultBuf255Ptr shared_spooldir_ptr; EXTERNAL KS_SHARED_DATA_HDL new_shared_handle; EXTERNAL KS_SHARED_DATA_PTR new_shared_values; /* * dialog_filename - this is the temporary filename that we display * with the standard file dialog. */ typedef struct { Word length; char text[64]; } GSString64; EXTERNAL GSString64 dialog_filename; EXTERNAL GSString64 backup_dialog_filename; /* * Prefix<0,8> - are handles we use to save prefix 0 and prefix 8. */ EXTERNAL Handle Prefix0; EXTERNAL Handle Prefix8; /* * SpoolPrefixDirectory - handle used to save the new spool directory */ EXTERNAL Handle SpoolPrefixDirectory; EXTERNAL Handle SpoolPrefixBackup; /* * handles/pointers to the control templates that are * used only during the save of changed controls. */ EXTERNAL Handle CheckBoxHandle; EXTERNAL RadioButtonTemplate *CheckBoxControlTemplate; EXTERNAL Handle ScrollBarHandle; EXTERNAL ScrollBarTemplate *ScrollBarControlTemplate; /* * The following four variables are from the build_port_list() * routine. This is part of the effort to reduce stack usage * so the finder can work for us... */ EXTERNAL KS_FILE_PTR bpl_file_ptr; EXTERNAL char *bpl_port_name; EXTERNAL DirEntryRecGS bpl_dir_entry; EXTERNAL ResultBuf32 bpl_filename; /* * ReplyRecord - returned filled in by standard file dialog... */ EXTERNAL SFReplyRec2 ReplyRecord; /* * il2_pkt - packet used to load a memory resident code section. */ EXTERNAL InitialLoad2_Pkt il2_pkt; /* * port_rec - used to load the print task code. */ EXTERNAL InitialLoadOutputRec port_rec; /* * The following externals exist only when we are debugging * the close code - if they are defined then when we are * about to write the 'changed' data to the resource fork, * then we will put up an alert window with all the variables * displayed so we can see that they are correct. */ #ifdef HEY_DAVE_WE_MUST_DEBUG_MORE EXTERNAL Pointer debug_sub_array[10]; EXTERNAL char debug_sub1[80]; EXTERNAL char debug_sub2[80]; EXTERNAL char debug_sub3[80]; EXTERNAL char debug_sub4[80]; EXTERNAL char debug_sub5[80]; EXTERNAL Word debug_stackptr; #endif /* * Pathname to directory to select port driver from... * * It is not declared with the EXTERNAL macro because of the * static initialization... */ extern GSString32 port_dir_path; /* * spoolmaster_path - the complete path to where the * spoolmaster CDEV lives... I'd like to remove this * variable... */ extern GSString32 spoolmaster_path; /* * my_sf_dialog_template - is my special standard file dialog templates */ extern Word my_sf_dialog320; extern Word my_sf_dialog640; /* ****************************************************************** * * Function Prototypes: * * ****************************************************************** */ /* * Functions from Spool.CC */ void do_boot(void); void do_about(WindowPtr); Long do_create(WindowPtr); void do_close(void); void do_hit(CtlRecHndl, Long); /* * Functions from Controls.CC */ void scroll_action(CtlRecHndl, Word); void build_port_list(void); void save_control_values(void); void GetRidOfSFMemory(void); /* Standard file support... */ int SFStart(int *, Handle *); void SFStop(int, Handle); void sfdialog_hook(Pointer, Word *); int SFPut(void); int PrefixToHandle (Word, Handle *); void HandleToPrefix (Word, Handle); int SavePrefixes(void); void RestorePrefixes (void); #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * KS.CDev.h + * + * Description: This include file contains all the external + * variable and routine definitions (prototypes) + * for the SpoolMaster CDEV. + * + * + * Table of contents: + * + * Defined variables: + * + * All CDEV flags passed the CDEV entry point + * All control IDs of the defined controls + * The port driver file/aux type + * + * + * External variables: + * + * static_text_substitution + * text0_string + * text_control_handle + * + * + * External routines: + * + * do_about() + * do_create() + * do_hit() + * + * scroll_action() + * + * + * + * History:May 18, 1991 Dave Created this file + * + */ + +#ifndef _KS_CDEV_ +#define _KS_CDEV_ + +/* define HEY_DAVE_WE_MUST_DEBUG_MORE */ + + + +#ifndef _KS_FILEIO_ +#include "KS.FileIO.E" +#endif + +#ifndef _KS_DEFINES_ +#include "KS.Defines.h" +#endif + +#ifndef _KS_ROUTINES_ +#include "KS.Routines.h" +#endif + +#ifndef _KS_MEMORY_ +#include "ks.memory.h" +#endif + +#ifndef _KS_SHARED_DATA_ +#include "SharedData.h" +#endif + +#ifndef __CONTROL__ +#include +#endif + +#ifndef __LIST__ +#include +#endif + +#ifndef __STDFILE__ +#include +#endif + +#ifndef __RESOURCES__ +#include +#endif + +#ifndef __LOADER__ +#include +#endif + + + +/* ****************************************************************** * + * Macro definitions: * + * ****************************************************************** */ + + +/* ****************************************************************** * + * The following macro simplifies by global variable definitions... * + * * + * The reasoning goes like this: * + * EXTERNAL is defined as extern by all modules that include this * + * file but have not defined EXTERNAL (IE: All but Data.CC). * + * Data.CC defines EXTERNAL to be nothing - thus we create the * + * data in Data.CC but do not have to duplicate the global * + * variable definitions... * + * * + * This seems to simplify my maintenance - once copy of variable * + * definitions to support... * + * ****************************************************************** */ + +#ifndef EXTERNAL +#define EXTERNAL extern +#endif + + + +/* ****************************************************************** * + * The following are all of the currently defined 'events' that are * + * passed to the CDEV entry point. * + * ****************************************************************** */ + +#define MachineCDEV 1 +#define BootCDEV 2 +#define Reserved 3 +#define InitCDEV 4 +#define CloseCDEV 5 +#define EventsCDEV 6 +#define CreateCDEV 7 +#define AboutCDEV 8 +#define RectCDEV 9 +#define HitCDEV 10 +#define RunCDEV 11 + + +/* ****************************************************************** * + * The following is a list of all the controls we have defined for * + * the spoolmaster CDEV * + * * + * Note: Static text controls are not included in this list. * + * ****************************************************************** */ + +#define MainControlList (1L) + +#define PortListControl (3L) +#define SpoolDirButtonControl (4L) +#define ScrollBarControl (6L) +#define BufferSizeTextControl (7L) +#define PrintFileCheckBoxCtl (8L) +#define DeleteFileCheckBoxCtl (9L) + +#define HelpControl (0x0100L) + +#define CantWriteAlert (1L) +#define CantWriteOkButton (0) +#define CantWriteTryAgain (1) + +#define SpoolDirPrompt (1L) + + + +#ifdef HEY_DAVE_WE_MUST_DEBUG_MORE + +#define DebugCloseAlert (2L) +#define DebugRoutineEntry (3L) +#define DebugRoutineExit (4L) +#define DebugEndOfLoop (5L) +#define DebugStandardFile (6L) + +#endif + + +/* + * Macro definition of print task id (for resource file) + */ + +#define PrintTask (2L) + + +/* + * Macro definitions of the saved user parameters + */ + +#define SpoolDefaultsType (0x0a13) +#define rMyCodeResource (0x0a14) + + +#define SpoolOptions (0x010L) +#define SpoolPrefix (0x010L) + +/* + * Macro definitions of the standard file dialog template item numbers + */ + +#define SFDT_SaveItem 1 +#define SFDT_OpenItem 2 +#define SFDT_CloseItem 3 +#define SFDT_NextItem 4 +#define SFDT_CancelItem 5 +#define SFDT_ScrollItem 6 +#define SFDT_PathItem 7 +#define SFDT_FileItem 8 +#define SFDT_PromptItem 9 +#define SFDT_FilenameItem 10 +#define SFDT_FreeSpaceItem 11 +#define SFDT_NewFolderItem 12 + + + +/* ****************************************************************** * + * Port driver filetype and auxtype - used when we're building the * + * port driver list... Apple should have defined these... * + * ****************************************************************** */ + +#define PORT_DRIVER_TYPE ((Word) 0x0bb) +#define PORT_DRIVER_AUXTYPE ((Long) 2) + + +/* ****************************************************************** * + * Structure for the loader (actually InitialLoad2 with flagWord==2. * + * ****************************************************************** */ + +typedef struct + { + Pointer memoryAddress; + Word fileLength; + } InitialLoad2_Pkt; + + + +/* ****************************************************************** * + * Standard file name/path reference description for an undefined * + * reference... Apple should have defined this... * + * ****************************************************************** */ + +#define STDFILE_REFERENCE_UNDEFINED ((Word) 3) + + +/* ****************************************************************** * + * Non-purgable purge level for memory blocks (setup by the memory * + * manager on a SetPurge. Apple should have defined this... * + * ****************************************************************** */ + +#define NOT_PURGEABLE ((Word) 0) + + + +/* ****************************************************************** * + * Maximum string stubstitution index (apple should have defined * + * this) * + * ****************************************************************** */ + +#define MAX_SUB_INDEX 10 + + + +/* ****************************************************************** * + * Macros to get the filename/pathname from a standard file dialog. * + * ****************************************************************** */ + +#define DerefFileName ((** (ResultBuf255 **) ReplyRecord.nameRef).bufString) +#define DerefFilePath ((** (ResultBuf255 **) ReplyRecord.pathRef).bufString) + + + +/* ****************************************************************** * + * External definitions: * + * ****************************************************************** */ + +/* + * static_text_substitution[] - is the static text substitution array. + * + * We use text substitution to display the selected buffer size. + */ + +EXTERNAL Pointer static_text_substitution[MAX_SUB_INDEX]; + +/* + * text0_string[] - this is the single substitution string we use. + */ + +EXTERNAL char text0_string[10]; + + +/* + * cdev_window_handle - is the handle to the window of the CDEV. + */ + +EXTERNAL WindowPtr cdev_window_handle; + + +/* + * text_control_handle - handle to the static text that will + * display the selected buffer size. + * + * Note: This is defined here as a performance improvement to + * the user interface (I see no reason to continually make + * the toolbox call to get this handle to redraw the text...). + */ + +EXTERNAL CtlRecHndl text_control_handle; + + +/* + * Flags indicating which toolsets needed to be started... + */ + +EXTERNAL Word QDAuxStarted; +EXTERNAL Word IMStarted; +EXTERNAL Word FMStarted; +EXTERNAL Word TEStarted; +EXTERNAL Word LMStackPointer; +EXTERNAL Word OriginalStackPtr; + + +/* + * Handles to the memory allocated for toolsets that we started. + */ + +EXTERNAL Handle MemoryForFM; +EXTERNAL Handle MemoryForTE; +EXTERNAL Handle MemoryForLM; + + +/* + * list_handle/list_pointer are the handle/pointer to the Member + * record for the port driver list. + */ + +EXTERNAL MemRecHndl list_handle; +EXTERNAL MemRecPtr list_pointer; +EXTERNAL CtlRecHndl list_control; +EXTERNAL Word number_of_ports; +EXTERNAL Word selected_port; + +/* + * orig_control_values - this is a SHARED_DATA structure that holds + * the original copy of all the control values. + * + * It is currently setup when we process the OPEN event of the CDEV! + * This will soon change to the INIT event. + */ + +EXTERNAL KS_SHARED_DATA_HDL shared_data_handle; +EXTERNAL KS_SHARED_DATA_PTR shared_data_values; + +EXTERNAL ResultBuf255Hndl shared_spooldir_hdl; +EXTERNAL ResultBuf255Ptr shared_spooldir_ptr; + + +EXTERNAL KS_SHARED_DATA_HDL new_shared_handle; +EXTERNAL KS_SHARED_DATA_PTR new_shared_values; + + + +/* + * dialog_filename - this is the temporary filename that we display + * with the standard file dialog. + */ + +typedef struct + { + Word length; + char text[64]; + } GSString64; + +EXTERNAL GSString64 dialog_filename; +EXTERNAL GSString64 backup_dialog_filename; + + +/* + * Prefix<0,8> - are handles we use to save prefix 0 and prefix 8. + */ + +EXTERNAL Handle Prefix0; +EXTERNAL Handle Prefix8; + + +/* + * SpoolPrefixDirectory - handle used to save the new spool directory + */ + +EXTERNAL Handle SpoolPrefixDirectory; +EXTERNAL Handle SpoolPrefixBackup; + + +/* + * handles/pointers to the control templates that are + * used only during the save of changed controls. + */ + +EXTERNAL Handle CheckBoxHandle; +EXTERNAL RadioButtonTemplate *CheckBoxControlTemplate; +EXTERNAL Handle ScrollBarHandle; +EXTERNAL ScrollBarTemplate *ScrollBarControlTemplate; + + + +/* + * The following four variables are from the build_port_list() + * routine. This is part of the effort to reduce stack usage + * so the finder can work for us... + */ + +EXTERNAL KS_FILE_PTR bpl_file_ptr; +EXTERNAL char *bpl_port_name; +EXTERNAL DirEntryRecGS bpl_dir_entry; +EXTERNAL ResultBuf32 bpl_filename; + + +/* + * ReplyRecord - returned filled in by standard file dialog... + */ + +EXTERNAL SFReplyRec2 ReplyRecord; + + +/* + * il2_pkt - packet used to load a memory resident code section. + */ + +EXTERNAL InitialLoad2_Pkt il2_pkt; + + +/* + * port_rec - used to load the print task code. + */ + +EXTERNAL InitialLoadOutputRec port_rec; + + + + +/* + * The following externals exist only when we are debugging + * the close code - if they are defined then when we are + * about to write the 'changed' data to the resource fork, + * then we will put up an alert window with all the variables + * displayed so we can see that they are correct. + */ + +#ifdef HEY_DAVE_WE_MUST_DEBUG_MORE + +EXTERNAL Pointer debug_sub_array[10]; +EXTERNAL char debug_sub1[80]; +EXTERNAL char debug_sub2[80]; +EXTERNAL char debug_sub3[80]; +EXTERNAL char debug_sub4[80]; +EXTERNAL char debug_sub5[80]; +EXTERNAL Word debug_stackptr; + +#endif + + +/* + * Pathname to directory to select port driver from... + * + * It is not declared with the EXTERNAL macro because of the + * static initialization... + */ + +extern GSString32 port_dir_path; + + +/* + * spoolmaster_path - the complete path to where the + * spoolmaster CDEV lives... I'd like to remove this + * variable... + */ + +extern GSString32 spoolmaster_path; + + +/* + * my_sf_dialog_template - is my special standard file dialog templates + */ + +extern Word my_sf_dialog320; +extern Word my_sf_dialog640; + + +/* ****************************************************************** * + * Function Prototypes: * + * ****************************************************************** */ + +/* + * Functions from Spool.CC + */ + +void do_boot(void); + +void do_about(WindowPtr); + +Long do_create(WindowPtr); + +void do_close(void); + +void do_hit(CtlRecHndl, + Long); + +/* + * Functions from Controls.CC + */ + +void scroll_action(CtlRecHndl, + Word); + +void build_port_list(void); + +void save_control_values(void); + +void GetRidOfSFMemory(void); /* Standard file support... */ +int SFStart(int *, Handle *); +void SFStop(int, Handle); +void sfdialog_hook(Pointer, Word *); +int SFPut(void); +int PrefixToHandle (Word, Handle *); +void HandleToPrefix (Word, Handle); +int SavePrefixes(void); +void RestorePrefixes (void); + + +#endif diff --git a/sys/fileport/includes/KS.Defines.h b/sys/fileport/includes/KS.Defines.h index f3c9b98..7d32950 100644 --- a/sys/fileport/includes/KS.Defines.h +++ b/sys/fileport/includes/KS.Defines.h @@ -1 +1,205 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * ks.defines.h * * Description: This include file contains all the master * definitions. * * * Table of contents: * * Structures: * * KS_STRUCT_ID . . . . . . . . . Structure for structure id. * * External variables: * * ks_expected_id . . . . . . . . Structure ID that was expected * in the called routine (this will * give the error processing code * a hint as to what structure caused * the error). * * * Macros: * * KS_SUCCESS() . . . . . . . . . Return to a calling procedure * with a success. * KS_ERROR() . . . . . . . . . . Return to a calling procedure * with an error. * * * Structure IDs for all Kopriha Software Structures: * * KS_FILE_ID . . . . . . . . . . KS FILE structure id * * * Error codes for all Kopriha Software: * * KS_E_SUCCESS . . . . . . . Success (same as ((word) 0)) * KS_E_INVALID_STRUCT_ID . . Structure has a bad structure id * KS_E_INVALID_OPTION . . . Invalid option for a routine * * * History:July 13, 1990 Dave Created this file * * March 3, 1991 Dave Added KS_FILE_ID * */ #ifndef _KS_DEFINES_ #define _KS_DEFINES_ #ifndef __TYPES__ #include #endif #ifndef _PORTABLE_C_ #include "Portable.C.h" #endif #ifndef _KS_ROUTINES_ #include "ks.routines.h" #endif #ifndef __orca__ #include #endif #ifndef EXTERNAL #define EXTERNAL extern #endif /* ****************************************************************** * * Structure definitions: * * ****************************************************************** */ /* * KS_E_ERROR . . . . . . . . . Type for any error code returned. */ typedef Word KS_E_ERROR; /* * KS_STRUCT_ID . . . . . . . . . Structure for structure id. * (IE: a unique identifier for each structure) */ typedef Longword KS_STRUCT_ID; /* ****************************************************************** * * External definitions: * * ****************************************************************** */ /* ****************************************************************** * * ks_expected_id - The structure id of the structure we took an * * error dealing with (this may indicate what was * * happening when an error occured...) For memErr * * it indicates which structure we couldn't get * * allocate. * * * * History: July 13, 1990 Dave Created these structures * * ****************************************************************** */ EXTERNAL KS_STRUCT_ID ks_expected_id; /* ****************************************************************** * * Macro definitions: * * ****************************************************************** */ /* * define DEBUG_CODE * - add # to define to create all modules * with debug code. */ /* * KS_SUCCESS macro - used to return a success to our caller. */ #define KS_SUCCESS() \ \ ROUTINE_EXIT( KS_E_SUCCESS ); \ return( KS_E_SUCCESS ) /* * KS_ERROR macro - used to return an error to our caller. */ #define KS_ERROR(_error, _struct_id) \ \ ks_expected_id = (_struct_id); \ ROUTINE_EXIT( (_error) ); \ return( (_error) ) /* * ProgramID - User ID of this program. Used to allocate memory * through the memory manager. * * Note: Secondary user IDs used throughout this program are: * UserID + 0x0100: Used by Orca/C and Tools loaded * UserID + 0x0200: Used for list management * UserID + 0x0300: Used to load the port driver * UserID + 0x0400: Used to allocate memory for buffers/shared data */ EXTERNAL Word ProgramID; #define WORK_USERID (ProgramID + 0x0100) #define LIST_USERID (ProgramID + 0x0200) #define PORT_USERID (ProgramID + 0x0300) #define BUFFER_USERID (ProgramID + 0x0400) /* * Structure IDs for all Kopriha Software Structures. */ #define KS_BASE_STRUCT_ID 0xcbd30000 /* Start of structure ids */ /* (cbd3 == "KS" for Kopriha */ /* Software). */ #define KS_FILE_ID KS_BASE_STRUCT_ID+1 #define KS_SHARED_DATA_ID KS_FILE_ID+1 /* * Define all the Kopriha Software specific error codes: */ #define KS_E_BASE_ID 0xcb00 #define KS_E_SUCCESS noError /* Success (same as ((word) 0)) */ #define KS_E_INVALID_STRUCT_ID KS_E_BASE_ID+1 /* The expected structure has a corrupted structure id */ #define KS_E_INVALID_OPTION KS_E_INVALID_STRUCT_ID+1 /* A routine received an invalid option - this indicates */ /* a programming error somewhere (usually the error */ /* returning function is being called incorrectly). */ #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * ks.defines.h + * + * Description: This include file contains all the master + * definitions. + * + * + * Table of contents: + * + * Structures: + * + * KS_STRUCT_ID . . . . . . . . . Structure for structure id. + * + * External variables: + * + * ks_expected_id . . . . . . . . Structure ID that was expected + * in the called routine (this will + * give the error processing code + * a hint as to what structure caused + * the error). + * + * + * Macros: + * + * KS_SUCCESS() . . . . . . . . . Return to a calling procedure + * with a success. + * KS_ERROR() . . . . . . . . . . Return to a calling procedure + * with an error. + * + * + * Structure IDs for all Kopriha Software Structures: + * + * KS_FILE_ID . . . . . . . . . . KS FILE structure id + * + * + * Error codes for all Kopriha Software: + * + * KS_E_SUCCESS . . . . . . . Success (same as ((word) 0)) + * KS_E_INVALID_STRUCT_ID . . Structure has a bad structure id + * KS_E_INVALID_OPTION . . . Invalid option for a routine + * + * + * History:July 13, 1990 Dave Created this file + * + * March 3, 1991 Dave Added KS_FILE_ID + * + */ + +#ifndef _KS_DEFINES_ +#define _KS_DEFINES_ + +#ifndef __TYPES__ +#include +#endif + +#ifndef _PORTABLE_C_ +#include "Portable.C.h" +#endif + +#ifndef _KS_ROUTINES_ +#include "ks.routines.h" +#endif + +#ifndef __orca__ +#include +#endif + + +#ifndef EXTERNAL +#define EXTERNAL extern +#endif + + + +/* ****************************************************************** * + * Structure definitions: * + * ****************************************************************** */ + +/* + * KS_E_ERROR . . . . . . . . . Type for any error code returned. + */ + +typedef Word KS_E_ERROR; + + +/* + * KS_STRUCT_ID . . . . . . . . . Structure for structure id. + * (IE: a unique identifier for each structure) + */ + +typedef Longword KS_STRUCT_ID; + + + +/* ****************************************************************** * + * External definitions: * + * ****************************************************************** */ + + +/* ****************************************************************** * + * ks_expected_id - The structure id of the structure we took an * + * error dealing with (this may indicate what was * + * happening when an error occured...) For memErr * + * it indicates which structure we couldn't get * + * allocate. * + * * + * History: July 13, 1990 Dave Created these structures * + * ****************************************************************** */ + +EXTERNAL KS_STRUCT_ID ks_expected_id; + + + + + +/* ****************************************************************** * + * Macro definitions: * + * ****************************************************************** */ + +/* + * define DEBUG_CODE + * - add # to define to create all modules + * with debug code. + */ + +/* + * KS_SUCCESS macro - used to return a success to our caller. + */ + +#define KS_SUCCESS() \ + \ + ROUTINE_EXIT( KS_E_SUCCESS ); \ + return( KS_E_SUCCESS ) + + +/* + * KS_ERROR macro - used to return an error to our caller. + */ + +#define KS_ERROR(_error, _struct_id) \ + \ + ks_expected_id = (_struct_id); \ + ROUTINE_EXIT( (_error) ); \ + return( (_error) ) + + + +/* + * ProgramID - User ID of this program. Used to allocate memory + * through the memory manager. + * + * Note: Secondary user IDs used throughout this program are: + * UserID + 0x0100: Used by Orca/C and Tools loaded + * UserID + 0x0200: Used for list management + * UserID + 0x0300: Used to load the port driver + * UserID + 0x0400: Used to allocate memory for buffers/shared data + */ + +EXTERNAL Word ProgramID; + +#define WORK_USERID (ProgramID + 0x0100) +#define LIST_USERID (ProgramID + 0x0200) +#define PORT_USERID (ProgramID + 0x0300) +#define BUFFER_USERID (ProgramID + 0x0400) + + + +/* + * Structure IDs for all Kopriha Software Structures. + */ + +#define KS_BASE_STRUCT_ID 0xcbd30000 /* Start of structure ids */ + /* (cbd3 == "KS" for Kopriha */ + /* Software). */ + +#define KS_FILE_ID KS_BASE_STRUCT_ID+1 + +#define KS_SHARED_DATA_ID KS_FILE_ID+1 + + + +/* + * Define all the Kopriha Software specific error codes: + */ + +#define KS_E_BASE_ID 0xcb00 + +#define KS_E_SUCCESS noError + /* Success (same as ((word) 0)) */ + +#define KS_E_INVALID_STRUCT_ID KS_E_BASE_ID+1 + /* The expected structure has a corrupted structure id */ + +#define KS_E_INVALID_OPTION KS_E_INVALID_STRUCT_ID+1 + /* A routine received an invalid option - this indicates */ + /* a programming error somewhere (usually the error */ + /* returning function is being called incorrectly). */ + + + +#endif diff --git a/sys/fileport/includes/KS.FileIO.e b/sys/fileport/includes/KS.FileIO.e index 3702543..f831799 100644 --- a/sys/fileport/includes/KS.FileIO.e +++ b/sys/fileport/includes/KS.FileIO.e @@ -1 +1,374 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * ks.fileio.e * * Description: This include file contains all the generic file * support macros from Kopriha Software. * * * Table of contents: * * Structures: * * KS_FILE . . . . . . . . . Structure to abstract a file * * Macros: * * + KS_FILE_CLOSE() . . . . . . . Close a file * + KS_FILE_CHANGE_AUXTYPE() . . . Change the aux type of a file * + KS_FILE_CREATE() . . . . . . . Create a file (w ftype,auxtype) * + KS_FILE_DELETE() . . . . . . . Delete a file * + KS_FILE_GET_BUFFER_SIZE(). . . Get the input/output buffer size * + KS_FILE_GET_DIRECTORY() . . . Get the current directory * + KS_FILE_GET_NEXT_FILE() . . . Get next filename from a directory * + KS_FILE_GET_VOLUME() . . . . . Get volume name from pathname * + KS_FILE_GET_VOLUME_SPACE() . . Get the total/available space on * the specified volume * + KS_FILE_OPEN() . . . . . . . . Open a file * + KS_FILE_PATH_ADD_FILE() . . . Append a filename to a path/dir * + KS_FILE_READ() . . . . . . . . Read from a file * KS_FILE_RENAME() . . . . . . . Rename a file (given pathnames) * + KS_FILE_SET_BUFFER_SIZE(). . . Set the input/output buffer size * * KS_FILE_SET_DIRECTORY() . . . Set the current directory * + KS_FILE_WRITE() . . . . . . . Write to a file * * + indicates that the routine was debugged * * indicates the routine exists but was not debugged * * * Notes: * * History:Oct 13, 1990 Dave Created this file for basic * I/O (read/write) * * Feb 25, 1991 Dave Added buffer enhancements/create. * * Mar 5, 1991 Dave Added directory, file, path and * volume calls * * Mar 24, 1991 Dave Added delete and change aux type * * Jun 07, 1991 Dave Broke the ks.fileio.cc module into * lots of pieces so we could easily * build a library. * * Jun 30, 1991 Dave Added a rename function. * */ #ifndef _KS_FILEIO_E_ #define _KS_FILEIO_E_ #ifndef _KS_DEFINES_ #include "ks.defines.h" #endif #ifndef _GSOS_ #include #endif /* * Buffer flag constants - used to determine if a buffer should * be used for I/O. The idea here is that if you specify a buffer, * then you have to read/write without specifying a byte position * (KS_NEXT_FILE_POSITION). */ #define KS_FILE_NO_BUFFER ((Word) 0) #define KS_FILE_BUFFER_IO ((Word) 1) #define KS_NEXT_FILE_POSITION ((Word) -1) /* * The following are definitions that I expected to find in the * APW 1.1/Orca/C update, but could not. I want to be able to * recompile without worrying about hard-coding constants in my * program, I defined the following macros: */ #define KS_FILE_DATA_FORK ((Word) 0) /* For GS/OS Open */ #define KS_FILE_RESOURCE_FORK ((Word) 1) #define KS_FILE_READ_ACCESS ((Word) readEnable) #define KS_FILE_WRITE_ACCESS ((Word) writeEnable) #define KS_BLOCK_DEVICE ((Word) 0x0080) /* used with DInfo */ /* * KS_FILE - generic file structure */ typedef struct { KS_STRUCT_ID struct_id;/* Structure id */ Handle file_handle; /* Handle that created this structure */ Word refNum; /* Reference # (or channel #) of the file */ Word access; /* Access mode of file (read or write) */ LongWord eof; /* End of File of data fork */ LongWord resource_eof; /* End of file for resource fork */ /* Note: Not all systems support filetypes*/ Word fileType; /* Value of file's fileType attribute */ LongWord auxType; /* Auxilary file type */ LongWord data_size; /* Amount of data read/written for user */ Word end_of_file; /* TRUE==We've read to end of file */ Word end_of_dir; /* TRUE==We've read to end of directory */ Handle buffer_handle; /* Handle to the buffer (if specified) */ LongWord buffer_size; /* Size of the buffer (NULL if not */ /* specified) */ LongWord buffer_available; /* Number of bytes read into the buffer */ /* Typically this offset is the same as */ /* buffer_size, however end of file is a */ /* special case where the number of */ /* read bytes typically can't be the same*/ /* the size of the buffer. */ Byte *buffer; /* Pointer to the file buffer */ LongWord buffer_offset; /* Offset of next available byte in buffer*/ } KS_FILE, *KS_FILE_PTR, **KS_FILE_HDL; /* * KS_FILE_CLOSE() - close a file. */ #define KS_FILE_CLOSE(_file_ptr, _error) \ \ (_error) = ks_file_close( (_file_ptr)) /* * KS_FILE_CREATE() - creates a file with the specified name, filetype * and auxtype. */ #define KS_FILE_CREATE(_gspath_ptr, _file_type, _auxtype, _error) \ \ (_error) = ks_file_create( (_gspath_ptr), \ (_file_type), \ (_auxtype)) /* * KS_FILE_CHANGE_AUXTYPE() - change the auxtype of an existing file. * * Note: This call is only works when the file is closed! */ #define KS_FILE_CHANGE_AUXTYPE(_gspath_ptr, _auxtype, _error) \ \ (_error) = ks_file_change_auxtype( (_gspath_ptr), \ (_auxtype)) /* * KS_FILE_DELETE() - Deletes the specified file */ #define KS_FILE_DELETE(_gspath_ptr, _error) \ \ (_error) = ks_file_delete( (_gspath_ptr)) /* * KS_FILE_GET_BUFFER_SIZE() - returns the current buffer size used * * Note: If the buffer size can only be changed if there are no * open files (this restriction will change in the future). */ #define KS_FILE_GET_BUFFER_SIZE(_buffer_size, _error) \ \ (_error) = ks_file_get_buffer_size( (_buffer_size)) /* * KS_FILE_GET_NEXT_FILE(FILE_PTR, DirEntryRecPtrGS) - Get next * filename from a directory */ #define KS_FILE_GET_NEXT_FILE(_file_ptr, _next_file_ptr, _error) \ \ (_error) = ks_file_get_next_file( (_file_ptr), \ (_next_file_ptr)) /* * KS_FILE_GET_VOLUME() - Get volume name from pathname */ #define KS_FILE_GET_VOLUME(_file_ptr, _volume_ptr, _error) \ \ (_error) = ks_file_get_volume( (_file_ptr), \ (_volume_ptr)) /* * KS_FILE_GET_VOLUME_SPACE() - Get the total/available space on * the specified volume */ #define KS_FILE_GET_VOLUME_SPACE(_volume_ptr, _unused, _total, _error) \ \ (_error) = ks_file_get_volume_space( (_volume_ptr), \ (_unused), \ (_total)) /* * KS_FILE_OPEN() - opens a file (either data or resource fork) * returns a KS_FILE structure to our caller. */ #define KS_FILE_OPEN(_gspath_ptr, _access, _file_fork, _buf_flag, _file_ptr_ptr, _error)\ \ (_error) = ks_file_open( (_gspath_ptr), \ (_access), \ (_file_fork), \ (_buf_flag), \ (_file_ptr_ptr)) /* * KS_FILE_PATH_ADD_FILE() - Append a filename to a path/dir */ #define KS_FILE_PATH_ADD_FILE(_path_ptr, _file_ptr, _error) \ \ (_error) = ks_file_path_add_file( (_path_ptr), \ (_file_ptr)) /* * KS_FILE_READ() - read from a file. */ #define KS_FILE_READ(_file_ptr, _position, _byte_size, _buffer, _error)\ \ (_error) = ks_file_read( (_file_ptr), \ (_position), \ (_byte_size), \ (_buffer)) /* * KS_FILE_RENAME() - rename a file. */ #define KS_FILE_RENAME(_old_pathname, _new_pathname, _error) \ \ (_error) = ks_file_rename( (_old_pathname), \ (_new_pathname)) /* * KS_FILE_SET_BUFFER_SIZE() - sets the current buffer size used * * Note: If the buffer size can only be changed if there are no * open files (this restriction will change in the future). */ #define KS_FILE_SET_BUFFER_SIZE(_buffer_size, _error) \ \ (_error) = ks_file_set_buffer_size( (_buffer_size)) /* * KS_FILE_SET_DIRECTORY() - Set the current directory */ #define KS_FILE_SET_DIRECTORY(_directory_ptr, _error) \ \ (_error) = ks_file_set_directory( (_directory_ptr)) /* * KS_FILE_SET_EOF() - set the end of the specified file */ #define KS_FILE_SET_EOF(_file_ptr, _eof, _error) \ \ (_error) = ks_file_set_eof( (_file_ptr), \ (_eof)) /* * KS_FILE_WRITE() - write to a file. */ #define KS_FILE_WRITE(_file_ptr, _position, _byte_size, _buffer, _error)\ \ (_error) = ks_file_write( (_file_ptr), \ (_position), \ (_byte_size), \ (_buffer)) /* ****************************************************************** * * File I/O routine prototypes: * * ****************************************************************** */ KS_E_ERROR ks_file_close(KS_FILE_PTR); KS_E_ERROR ks_file_create(GSString255Ptr, Word, LongWord); KS_E_ERROR ks_file_change_auxtype(GSString255Ptr, LongWord); KS_E_ERROR ks_file_get_buffer_size(LongWord *); KS_E_ERROR ks_file_delete(GSString255Ptr); KS_E_ERROR ks_file_get_next_file(KS_FILE_PTR, DirEntryRecPtrGS); KS_E_ERROR ks_file_get_volume(GSString255Ptr, GSString255Ptr); KS_E_ERROR ks_file_get_volume_space(GSString255Ptr, LongWord *, LongWord *); KS_E_ERROR ks_file_open(GSString255Ptr, Word, Word, Word, KS_FILE_PTR *); KS_E_ERROR ks_file_read(KS_FILE_PTR, LongWord, LongWord, Pointer); KS_E_ERROR ks_file_rename(GSString255Ptr, GSString255Ptr); KS_E_ERROR ks_file_path_add_file(GSString255Ptr, GSString255Ptr); KS_E_ERROR ks_file_set_buffer_size(LongWord); KS_E_ERROR ks_file_set_directory(GSString255Ptr); KS_E_ERROR ks_file_set_eof(KS_FILE_PTR, LongWord); KS_E_ERROR ks_file_write(KS_FILE_PTR, LongWord, LongWord, Pointer); #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * ks.fileio.e + * + * Description: This include file contains all the generic file + * support macros from Kopriha Software. + * + * + * Table of contents: + * + * Structures: + * + * KS_FILE . . . . . . . . . Structure to abstract a file + * + * Macros: + * + * + KS_FILE_CLOSE() . . . . . . . Close a file + * + KS_FILE_CHANGE_AUXTYPE() . . . Change the aux type of a file + * + KS_FILE_CREATE() . . . . . . . Create a file (w ftype,auxtype) + * + KS_FILE_DELETE() . . . . . . . Delete a file + * + KS_FILE_GET_BUFFER_SIZE(). . . Get the input/output buffer size + * + KS_FILE_GET_DIRECTORY() . . . Get the current directory + * + KS_FILE_GET_NEXT_FILE() . . . Get next filename from a directory + * + KS_FILE_GET_VOLUME() . . . . . Get volume name from pathname + * + KS_FILE_GET_VOLUME_SPACE() . . Get the total/available space on + * the specified volume + * + KS_FILE_OPEN() . . . . . . . . Open a file + * + KS_FILE_PATH_ADD_FILE() . . . Append a filename to a path/dir + * + KS_FILE_READ() . . . . . . . . Read from a file + * KS_FILE_RENAME() . . . . . . . Rename a file (given pathnames) + * + KS_FILE_SET_BUFFER_SIZE(). . . Set the input/output buffer size + * * KS_FILE_SET_DIRECTORY() . . . Set the current directory + * + KS_FILE_WRITE() . . . . . . . Write to a file + * + * + indicates that the routine was debugged + * * indicates the routine exists but was not debugged + * + * + * Notes: + * + * History:Oct 13, 1990 Dave Created this file for basic + * I/O (read/write) + * + * Feb 25, 1991 Dave Added buffer enhancements/create. + * + * Mar 5, 1991 Dave Added directory, file, path and + * volume calls + * + * Mar 24, 1991 Dave Added delete and change aux type + * + * Jun 07, 1991 Dave Broke the ks.fileio.cc module into + * lots of pieces so we could easily + * build a library. + * + * Jun 30, 1991 Dave Added a rename function. + * + */ + +#ifndef _KS_FILEIO_E_ +#define _KS_FILEIO_E_ + +#ifndef _KS_DEFINES_ +#include "ks.defines.h" +#endif + +#ifndef _GSOS_ +#include +#endif + + +/* + * Buffer flag constants - used to determine if a buffer should + * be used for I/O. The idea here is that if you specify a buffer, + * then you have to read/write without specifying a byte position + * (KS_NEXT_FILE_POSITION). + */ + +#define KS_FILE_NO_BUFFER ((Word) 0) +#define KS_FILE_BUFFER_IO ((Word) 1) + +#define KS_NEXT_FILE_POSITION ((Word) -1) + +/* + * The following are definitions that I expected to find in the + * APW 1.1/Orca/C update, but could not. I want to be able to + * recompile without worrying about hard-coding constants in my + * program, I defined the following macros: + */ + +#define KS_FILE_DATA_FORK ((Word) 0) /* For GS/OS Open */ +#define KS_FILE_RESOURCE_FORK ((Word) 1) + +#define KS_FILE_READ_ACCESS ((Word) readEnable) +#define KS_FILE_WRITE_ACCESS ((Word) writeEnable) + +#define KS_BLOCK_DEVICE ((Word) 0x0080) /* used with DInfo */ + +/* + * KS_FILE - generic file structure + */ + +typedef struct + { + KS_STRUCT_ID struct_id;/* Structure id */ + Handle file_handle; /* Handle that created this structure */ + Word refNum; /* Reference # (or channel #) of the file */ + Word access; /* Access mode of file (read or write) */ + LongWord eof; /* End of File of data fork */ + LongWord resource_eof; /* End of file for resource fork */ + /* Note: Not all systems support filetypes*/ + Word fileType; /* Value of file's fileType attribute */ + LongWord auxType; /* Auxilary file type */ + + LongWord data_size; /* Amount of data read/written for user */ + + Word end_of_file; /* TRUE==We've read to end of file */ + Word end_of_dir; /* TRUE==We've read to end of directory */ + + Handle buffer_handle; + /* Handle to the buffer (if specified) */ + LongWord buffer_size; /* Size of the buffer (NULL if not */ + /* specified) */ + LongWord buffer_available; + /* Number of bytes read into the buffer */ + /* Typically this offset is the same as */ + /* buffer_size, however end of file is a */ + /* special case where the number of */ + /* read bytes typically can't be the same*/ + /* the size of the buffer. */ + Byte *buffer; /* Pointer to the file buffer */ + LongWord buffer_offset; + /* Offset of next available byte in buffer*/ + + } KS_FILE, *KS_FILE_PTR, **KS_FILE_HDL; + + + +/* + * KS_FILE_CLOSE() - close a file. + */ + +#define KS_FILE_CLOSE(_file_ptr, _error) \ + \ + (_error) = ks_file_close( (_file_ptr)) + + +/* + * KS_FILE_CREATE() - creates a file with the specified name, filetype + * and auxtype. + */ + +#define KS_FILE_CREATE(_gspath_ptr, _file_type, _auxtype, _error) \ + \ + (_error) = ks_file_create( (_gspath_ptr), \ + (_file_type), \ + (_auxtype)) + + +/* + * KS_FILE_CHANGE_AUXTYPE() - change the auxtype of an existing file. + * + * Note: This call is only works when the file is closed! + */ + +#define KS_FILE_CHANGE_AUXTYPE(_gspath_ptr, _auxtype, _error) \ + \ + (_error) = ks_file_change_auxtype( (_gspath_ptr), \ + (_auxtype)) + + +/* + * KS_FILE_DELETE() - Deletes the specified file + */ + +#define KS_FILE_DELETE(_gspath_ptr, _error) \ + \ + (_error) = ks_file_delete( (_gspath_ptr)) + + +/* + * KS_FILE_GET_BUFFER_SIZE() - returns the current buffer size used + * + * Note: If the buffer size can only be changed if there are no + * open files (this restriction will change in the future). + */ + +#define KS_FILE_GET_BUFFER_SIZE(_buffer_size, _error) \ + \ + (_error) = ks_file_get_buffer_size( (_buffer_size)) + + +/* + * KS_FILE_GET_NEXT_FILE(FILE_PTR, DirEntryRecPtrGS) - Get next + * filename from a directory + */ + +#define KS_FILE_GET_NEXT_FILE(_file_ptr, _next_file_ptr, _error) \ + \ + (_error) = ks_file_get_next_file( (_file_ptr), \ + (_next_file_ptr)) + + +/* + * KS_FILE_GET_VOLUME() - Get volume name from pathname + */ + +#define KS_FILE_GET_VOLUME(_file_ptr, _volume_ptr, _error) \ + \ + (_error) = ks_file_get_volume( (_file_ptr), \ + (_volume_ptr)) + + +/* + * KS_FILE_GET_VOLUME_SPACE() - Get the total/available space on + * the specified volume + */ + +#define KS_FILE_GET_VOLUME_SPACE(_volume_ptr, _unused, _total, _error) \ + \ + (_error) = ks_file_get_volume_space( (_volume_ptr), \ + (_unused), \ + (_total)) + + +/* + * KS_FILE_OPEN() - opens a file (either data or resource fork) + * returns a KS_FILE structure to our caller. + */ + +#define KS_FILE_OPEN(_gspath_ptr, _access, _file_fork, _buf_flag, _file_ptr_ptr, _error)\ + \ + (_error) = ks_file_open( (_gspath_ptr), \ + (_access), \ + (_file_fork), \ + (_buf_flag), \ + (_file_ptr_ptr)) + + +/* + * KS_FILE_PATH_ADD_FILE() - Append a filename to a path/dir + */ + +#define KS_FILE_PATH_ADD_FILE(_path_ptr, _file_ptr, _error) \ + \ + (_error) = ks_file_path_add_file( (_path_ptr), \ + (_file_ptr)) + + +/* + * KS_FILE_READ() - read from a file. + */ + +#define KS_FILE_READ(_file_ptr, _position, _byte_size, _buffer, _error)\ + \ + (_error) = ks_file_read( (_file_ptr), \ + (_position), \ + (_byte_size), \ + (_buffer)) + + +/* + * KS_FILE_RENAME() - rename a file. + */ + +#define KS_FILE_RENAME(_old_pathname, _new_pathname, _error) \ + \ + (_error) = ks_file_rename( (_old_pathname), \ + (_new_pathname)) + + +/* + * KS_FILE_SET_BUFFER_SIZE() - sets the current buffer size used + * + * Note: If the buffer size can only be changed if there are no + * open files (this restriction will change in the future). + */ + +#define KS_FILE_SET_BUFFER_SIZE(_buffer_size, _error) \ + \ + (_error) = ks_file_set_buffer_size( (_buffer_size)) + + +/* + * KS_FILE_SET_DIRECTORY() - Set the current directory + */ + +#define KS_FILE_SET_DIRECTORY(_directory_ptr, _error) \ + \ + (_error) = ks_file_set_directory( (_directory_ptr)) + + +/* + * KS_FILE_SET_EOF() - set the end of the specified file + */ + +#define KS_FILE_SET_EOF(_file_ptr, _eof, _error) \ + \ + (_error) = ks_file_set_eof( (_file_ptr), \ + (_eof)) + + +/* + * KS_FILE_WRITE() - write to a file. + */ + +#define KS_FILE_WRITE(_file_ptr, _position, _byte_size, _buffer, _error)\ + \ + (_error) = ks_file_write( (_file_ptr), \ + (_position), \ + (_byte_size), \ + (_buffer)) + + + +/* ****************************************************************** * + * File I/O routine prototypes: * + * ****************************************************************** */ + +KS_E_ERROR ks_file_close(KS_FILE_PTR); + +KS_E_ERROR ks_file_create(GSString255Ptr, + Word, + LongWord); + +KS_E_ERROR ks_file_change_auxtype(GSString255Ptr, + LongWord); + +KS_E_ERROR ks_file_get_buffer_size(LongWord *); + +KS_E_ERROR ks_file_delete(GSString255Ptr); + +KS_E_ERROR ks_file_get_next_file(KS_FILE_PTR, + DirEntryRecPtrGS); + +KS_E_ERROR ks_file_get_volume(GSString255Ptr, + GSString255Ptr); + +KS_E_ERROR ks_file_get_volume_space(GSString255Ptr, + LongWord *, + LongWord *); + +KS_E_ERROR ks_file_open(GSString255Ptr, + Word, + Word, + Word, + KS_FILE_PTR *); + +KS_E_ERROR ks_file_read(KS_FILE_PTR, + LongWord, + LongWord, + Pointer); + +KS_E_ERROR ks_file_rename(GSString255Ptr, + GSString255Ptr); + +KS_E_ERROR ks_file_path_add_file(GSString255Ptr, + GSString255Ptr); + +KS_E_ERROR ks_file_set_buffer_size(LongWord); + +KS_E_ERROR ks_file_set_directory(GSString255Ptr); + +KS_E_ERROR ks_file_set_eof(KS_FILE_PTR, + LongWord); + +KS_E_ERROR ks_file_write(KS_FILE_PTR, + LongWord, + LongWord, + Pointer); + +#endif diff --git a/sys/fileport/includes/KS.Memory.h b/sys/fileport/includes/KS.Memory.h index 4646162..7d3dd85 100644 --- a/sys/fileport/includes/KS.Memory.h +++ b/sys/fileport/includes/KS.Memory.h @@ -1 +1,85 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * ks.memory.h * * Description: This include file contains all the memory * support macros. * * * Table of contents: * * Macros: * * KS_MEMORY_ALLOCATE() . . . . . Allocate a block of memory * KS_MEMORY_FREE() . . . . . . . Free a block of memory * * * Notes: Why create these macros instead of using the standard * C I/O routines? I believe that the support * routines will require some user interface work to handle * cases like when we run out of memory. Standard C memory * routines don't give me the ability to do such processing. * * For now, these macros will simply call the C library * routines (malloc and free). I'm sure this will change * in the future. * * * History: March 2, 1991 Dave Created this file * */ #ifndef _KS_MEMORY_ #define _KS_MEMORY_ #ifndef _PORTABLE_C_ #include "Portable.C.h" #endif #ifndef _stdlib_ #include #endif #ifndef __MEMORY__ #include #endif /* * KS_MEMORY_ALLOCATE() - Allocate some memory */ #define KS_MEMORY_ALLOCATE(_memory_attr,_memory_size,_memory_id,_memory_hdl,_error)\ \ (_memory_hdl) = NewHandle((Long) (_memory_size), \ (_memory_id), \ (_memory_attr), \ 0L); \ (_error) = GET_ERROR() /* * KS_MEMORY_DEALLOCATE() - Release a block of memory back to the * free pool of memory */ #define KS_MEMORY_DEALLOCATE(_memory_hdl, _error) \ \ DisposeHandle( (_memory_hdl)); \ _error = KS_E_SUCCESS /* ****************************************************************** * * Memory routine prototypes: * * ****************************************************************** */ #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * ks.memory.h + * + * Description: This include file contains all the memory + * support macros. + * + * + * Table of contents: + * + * Macros: + * + * KS_MEMORY_ALLOCATE() . . . . . Allocate a block of memory + * KS_MEMORY_FREE() . . . . . . . Free a block of memory + * + * + * Notes: Why create these macros instead of using the standard + * C I/O routines? I believe that the support + * routines will require some user interface work to handle + * cases like when we run out of memory. Standard C memory + * routines don't give me the ability to do such processing. + * + * For now, these macros will simply call the C library + * routines (malloc and free). I'm sure this will change + * in the future. + * + * + * History: March 2, 1991 Dave Created this file + * + */ + +#ifndef _KS_MEMORY_ +#define _KS_MEMORY_ + +#ifndef _PORTABLE_C_ +#include "Portable.C.h" +#endif + +#ifndef _stdlib_ +#include +#endif + +#ifndef __MEMORY__ +#include +#endif + + + + + +/* + * KS_MEMORY_ALLOCATE() - Allocate some memory + */ + +#define KS_MEMORY_ALLOCATE(_memory_attr,_memory_size,_memory_id,_memory_hdl,_error)\ + \ + (_memory_hdl) = NewHandle((Long) (_memory_size), \ + (_memory_id), \ + (_memory_attr), \ + 0L); \ + (_error) = GET_ERROR() + + + +/* + * KS_MEMORY_DEALLOCATE() - Release a block of memory back to the + * free pool of memory + */ + +#define KS_MEMORY_DEALLOCATE(_memory_hdl, _error) \ + \ + DisposeHandle( (_memory_hdl)); \ + _error = KS_E_SUCCESS + + + + +/* ****************************************************************** * + * Memory routine prototypes: * + * ****************************************************************** */ + +#endif diff --git a/sys/fileport/includes/KS.Routines.h b/sys/fileport/includes/KS.Routines.h index 03ed7c2..9bbe18a 100644 --- a/sys/fileport/includes/KS.Routines.h +++ b/sys/fileport/includes/KS.Routines.h @@ -1 +1,151 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * ks.routines.h * * Description: This include file contains the routine entry/exit * macro definitions. * * * Table of contents: * * Macros: * * ROUTINE_ENTER() . . . . . . . Macro to indicate a routine * was entered. * ROUTINE_EXIT() . . . . . . . . Macro to indicate a routine * was exited (success or error). * * * Notes: These macros will be expanded to check the stack pointer * in debugging cases. Also, a performance set of macros * will be created that will count # of entries to a routine * along with total time spent in the routine. * * * History:July 13, 1990 Dave Created this file * */ #ifndef _KS_ROUTINES_ #define _KS_ROUTINES_ #ifdef DEBUG_CODE #ifndef __STDIO__ #include #endif #endif /* ****************************************************************** * * Macro definitions: * * ****************************************************************** */ /* * define DEBUG_CODE * - add # to define to create all modules * with debug code. */ /* * ROUTINE_ENTER macro - used on entry to a routine. */ #ifndef DEBUG_CODE #define ROUTINE_ENTER() #endif #ifdef DEBUG_CODE #define ROUTINE_ENTER() \ \ printf("%s: entered\n", \ ROUTINE_NAME); #endif #ifdef HEY_DAVE_WE_MUST_DEBUG_MORE_RIGHT_NOW #undef ROUTINE_ENTER #define ROUTINE_ENTER() \ \ asm \ { \ tsc \ sta >debug_stackptr \ }; \ \ sprintf(debug_sub1, "%s", \ ROUTINE_NAME); \ sprintf(debug_sub2, "%x", \ debug_stackptr); \ \ debug_sub_array[0] = (Pointer) &debug_sub1; \ debug_sub_array[1] = (Pointer) &debug_sub2; \ \ /* \ * Resource reference with C string substitution array... \ */ \ \ debug_stackptr = AlertWindow((Word) 4, \ (Long) &debug_sub_array, \ DebugRoutineEntry) #endif /* * ROUTINE_EXIT macro - used to return to our caller. */ #ifndef DEBUG_CODE #define ROUTINE_EXIT(_error_code) #endif #ifdef DEBUG_CODE #define ROUTINE_EXIT(_error_code) \ \ printf("%s: error return. Error = %d.\n", \ ROUTINE_NAME, \ _error_code); #endif #ifdef HEY_DAVE_WE_MUST_DEBUG_MORE_RIGHT_NOW #undef ROUTINE_EXIT #define ROUTINE_EXIT(_error_code) \ \ asm \ { \ tsc \ sta >debug_stackptr \ }; \ \ sprintf(debug_sub1, "%s", \ ROUTINE_NAME); \ sprintf(debug_sub2, "%x", \ debug_stackptr); \ sprintf(debug_sub3, "%lx", \ (Long) (_error_code)); \ \ debug_sub_array[0] = (Pointer) &debug_sub1; \ debug_sub_array[1] = (Pointer) &debug_sub2; \ debug_sub_array[2] = (Pointer) &debug_sub3; \ \ /* \ * Resource reference with C string substitution array... \ */ \ \ debug_stackptr = AlertWindow((Word) 4, \ (Long) &debug_sub_array, \ DebugRoutineExit) #endif #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * ks.routines.h + * + * Description: This include file contains the routine entry/exit + * macro definitions. + * + * + * Table of contents: + * + * Macros: + * + * ROUTINE_ENTER() . . . . . . . Macro to indicate a routine + * was entered. + * ROUTINE_EXIT() . . . . . . . . Macro to indicate a routine + * was exited (success or error). + * + * + * Notes: These macros will be expanded to check the stack pointer + * in debugging cases. Also, a performance set of macros + * will be created that will count # of entries to a routine + * along with total time spent in the routine. + * + * + * History:July 13, 1990 Dave Created this file + * + */ + +#ifndef _KS_ROUTINES_ +#define _KS_ROUTINES_ + +#ifdef DEBUG_CODE +#ifndef __STDIO__ +#include +#endif +#endif + + + +/* ****************************************************************** * + * Macro definitions: * + * ****************************************************************** */ + +/* + * define DEBUG_CODE + * - add # to define to create all modules + * with debug code. + */ + +/* + * ROUTINE_ENTER macro - used on entry to a routine. + */ + +#ifndef DEBUG_CODE +#define ROUTINE_ENTER() +#endif + +#ifdef DEBUG_CODE +#define ROUTINE_ENTER() \ + \ + printf("%s: entered\n", \ + ROUTINE_NAME); +#endif + + +#ifdef HEY_DAVE_WE_MUST_DEBUG_MORE_RIGHT_NOW + +#undef ROUTINE_ENTER + +#define ROUTINE_ENTER() \ + \ + asm \ + { \ + tsc \ + sta >debug_stackptr \ + }; \ + \ + sprintf(debug_sub1, "%s", \ + ROUTINE_NAME); \ + sprintf(debug_sub2, "%x", \ + debug_stackptr); \ + \ + debug_sub_array[0] = (Pointer) &debug_sub1; \ + debug_sub_array[1] = (Pointer) &debug_sub2; \ + \ + /* \ + * Resource reference with C string substitution array... \ + */ \ + \ + debug_stackptr = AlertWindow((Word) 4, \ + (Long) &debug_sub_array, \ + DebugRoutineEntry) + +#endif + + + +/* + * ROUTINE_EXIT macro - used to return to our caller. + */ + +#ifndef DEBUG_CODE +#define ROUTINE_EXIT(_error_code) +#endif + +#ifdef DEBUG_CODE +#define ROUTINE_EXIT(_error_code) \ + \ + printf("%s: error return. Error = %d.\n", \ + ROUTINE_NAME, \ + _error_code); +#endif + + +#ifdef HEY_DAVE_WE_MUST_DEBUG_MORE_RIGHT_NOW + +#undef ROUTINE_EXIT + +#define ROUTINE_EXIT(_error_code) \ + \ + asm \ + { \ + tsc \ + sta >debug_stackptr \ + }; \ + \ + sprintf(debug_sub1, "%s", \ + ROUTINE_NAME); \ + sprintf(debug_sub2, "%x", \ + debug_stackptr); \ + sprintf(debug_sub3, "%lx", \ + (Long) (_error_code)); \ + \ + debug_sub_array[0] = (Pointer) &debug_sub1; \ + debug_sub_array[1] = (Pointer) &debug_sub2; \ + debug_sub_array[2] = (Pointer) &debug_sub3; \ + \ + /* \ + * Resource reference with C string substitution array... \ + */ \ + \ + debug_stackptr = AlertWindow((Word) 4, \ + (Long) &debug_sub_array, \ + DebugRoutineExit) + +#endif + +#endif diff --git a/sys/fileport/includes/Portable.C.h b/sys/fileport/includes/Portable.C.h index a0d9284..31651a6 100644 --- a/sys/fileport/includes/Portable.C.h +++ b/sys/fileport/includes/Portable.C.h @@ -1 +1,109 @@ - /* * Copyright (c) Kopriha Software, 1990 * All Rights Reserved * * Portable.C.h * * Description: This include file contains all the portable C language * definitions for Font Forge. * * * Table of contents: * * Structures: * * Macros: * * COPY_BYTES . . . . . . . . . . Copy bytes from one place to another * MAX . . . . . . . . . . . . . Return the maximum of two values * MIN . . . . . . . . . . . . . Return the minimum of two values * TO_POINTER . . . . . . . . . . Convert some pointer type to Pointer * ZERO . . . . . . . . . . . . . Initialize a structure to zero * * * Notes: Wherever possible, the macros defined in this module * will be used!!!! * * History:August 10, 1990 Dave Created this file * */ #ifndef _PORTABLE_C_ #define _PORTABLE_C_ #ifndef __stddef__ #include #endif /* * COPY_BYTES() - Copies the specified number of bytes */ #define COPY_BYTES(_src_ptr, _src_offset, _dest_ptr, _dest_offset, _size)\ \ BlockMove( &(((char *) (_src_ptr))[(_src_offset)]), \ &(((char *) (_dest_ptr))[(_dest_offset)]), \ (Long) (_size)) /* * GET_ERROR() - returns the error from the last toolbox call. * Use this macro only in a assignment statement * (IE: z = MAX(x,y);) */ #define GET_ERROR() \ \ toolerror() /* * MAX(a,b) - returns the minimum value, use this macro only * in a assignment statement (IE: z = MAX(x,y);) */ #define MAX(_arg1, _arg2) \ \ (((_arg1) > (_arg2)) ? (_arg1) : (_arg2)) /* * MIN(a,b) - returns the minimum value, use this macro only * in a assignment statement (IE: z = MIN(x,y);) */ #define MIN(_arg1, _arg2) \ \ (((_arg1) < (_arg2)) ? (_arg1) : (_arg2)) /* * TO_POINTER(some_pointer) - returns some_pointer typecase as * a Pointer. Use this macro only in a assignment * statement (IE: z = MIN(x,y);) */ #define TO_POINTER(_some_pointer) \ \ ((Pointer) (_some_pointer)) /* * ZERO(structure) - sets a structure to zero. */ #define ZERO(_struct) \ \ memset( (char *) &(_struct), \ 0, \ ((size_t) sizeof(_struct)) ) #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990 + * All Rights Reserved + * + * Portable.C.h + * + * Description: This include file contains all the portable C language + * definitions for Font Forge. + * + * + * Table of contents: + * + * Structures: + * + * Macros: + * + * COPY_BYTES . . . . . . . . . . Copy bytes from one place to another + * MAX . . . . . . . . . . . . . Return the maximum of two values + * MIN . . . . . . . . . . . . . Return the minimum of two values + * TO_POINTER . . . . . . . . . . Convert some pointer type to Pointer + * ZERO . . . . . . . . . . . . . Initialize a structure to zero + * + * + * Notes: Wherever possible, the macros defined in this module + * will be used!!!! + * + * History:August 10, 1990 Dave Created this file + * + */ + +#ifndef _PORTABLE_C_ +#define _PORTABLE_C_ + +#ifndef __stddef__ +#include +#endif + + +/* + * COPY_BYTES() - Copies the specified number of bytes + */ + +#define COPY_BYTES(_src_ptr, _src_offset, _dest_ptr, _dest_offset, _size)\ + \ + BlockMove( &(((char *) (_src_ptr))[(_src_offset)]), \ + &(((char *) (_dest_ptr))[(_dest_offset)]), \ + (Long) (_size)) + + + +/* + * GET_ERROR() - returns the error from the last toolbox call. + * Use this macro only in a assignment statement + * (IE: z = MAX(x,y);) + */ + +#define GET_ERROR() \ + \ + toolerror() + + + +/* + * MAX(a,b) - returns the minimum value, use this macro only + * in a assignment statement (IE: z = MAX(x,y);) + */ + +#define MAX(_arg1, _arg2) \ + \ + (((_arg1) > (_arg2)) ? (_arg1) : (_arg2)) + + + +/* + * MIN(a,b) - returns the minimum value, use this macro only + * in a assignment statement (IE: z = MIN(x,y);) + */ + +#define MIN(_arg1, _arg2) \ + \ + (((_arg1) < (_arg2)) ? (_arg1) : (_arg2)) + + + +/* + * TO_POINTER(some_pointer) - returns some_pointer typecase as + * a Pointer. Use this macro only in a assignment + * statement (IE: z = MIN(x,y);) + */ + +#define TO_POINTER(_some_pointer) \ + \ + ((Pointer) (_some_pointer)) + + + +/* + * ZERO(structure) - sets a structure to zero. + */ + +#define ZERO(_struct) \ + \ + memset( (char *) &(_struct), \ + 0, \ + ((size_t) sizeof(_struct)) ) + + +#endif diff --git a/sys/fileport/includes/SharedData.h b/sys/fileport/includes/SharedData.h index d7f2ca4..bc68bb8 100644 --- a/sys/fileport/includes/SharedData.h +++ b/sys/fileport/includes/SharedData.h @@ -1 +1,167 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * SharedData.H * * Description: This include file contains the definition of the * shared data structure that has a pointer to it posted * to the message center. * * * Table of contents: * * Structures: * KS_SHARED_DATA . . . . . . . Shared data structure * * * History:April 21, 1991 Dave Created this file * */ #ifndef _KS_SHARED_DATA_ #define _KS_SHARED_DATA_ #ifndef _KS_DEFINES_ #include "KS.Defines.H" #endif #ifndef __GSOS__ #include #endif /* * Filetype/auxtype of spoolfiles. */ #define SPOOLFILE_FILETYPE ((Word) 4) #define SPOOLFILE_AUXTYPE ((LongWord) 0) #define SPOOL_DONE_AUXTYPE ((LongWord) 256) /* * Shared data spoolport flag states */ enum port_flags {PORT_NOT_ACTIVE = 1, PORT_READY, PORT_SPOOLING, PORT_ERROR}; /* * Shared data spool flag states... */ enum spool_flags {SPOOL_INIT = 0, /* First call - initialize everything */ SPOOL_SCANNING, /* Scanning spool directory for a file */ SPOOL_OPEN, /* Setting up for printing */ SPOOL_WAITING, /* Waiting for port to be ready */ SPOOL_PRINTING, /* Printing a spoolfile */ SPOOL_CLOSE, /* Finished with a spoolfile */ SPOOL_ERROR}; /* Some error stopped spooling */ /* * KS_SHARED_DATA - generic shared data structure */ typedef struct { KS_STRUCT_ID struct_id; /* Structure id */ Word port_driver_length; /* Length of the port driver filename*/ char port_driver_name[64]; /* Name of port driver to print with */ Word spool_filename_length;/* Length of spool basename */ char spool_filename[64]; /* Basename of spool file */ LongWord buffer_size; /* User specified buffer size */ /* (This is the value of the */ /* scrollbar control) */ /* * Flag words (should use bits, but we'll be a little foolish): */ Word delete_flag; /* Delete spoolfile after printing */ Word print_flag; /* Print new spoolfiles */ /* * Data for the spoolport driver */ enum port_flags port_status; Word port_error; Word port_spoolnumber; /* * Now for the background task information. */ Pointer start_address; /* Start address of routine - pass */ /* this to add to run q! */ enum spool_flags spool_status; /* Status of spooler */ Word spool_error; /* Saved Error from spooler */ Word spool_spoolnumber; /* Spoolfile number being printed */ Pointer file_ptr; /* Pointer to the file we're spooling*/ LongWord bytes_written; /* Bytes written to the printer for */ /* the current spool file */ Word driver_user_id; /* Memory manager User ID for spooler*/ Handle buffer_handle; /* Handle to the I/O buffer */ Byte *buffer; /* Pointer to the I/O buffer */ LongWord buffer_bytesize; /* Size of the buffer (in bytes) */ LongWord buffer_offset; /* Offset of next available byte */ } KS_SHARED_DATA, *KS_SHARED_DATA_PTR, **KS_SHARED_DATA_HDL; typedef struct { Word length; char text[768]; } GSString768, *GSString768Ptr, **GSString768Hdl; typedef struct { Word bufSize; GSString768 buffer; } ResultBuf768, *ResultBuf768Ptr, **ResultBuf768Hdl; /* * KS_DATA_MESSAGE - record pointer passed to message center by name * This holds most of the user specifiable data. The only structure * missing is the pathname - and that is in the second message struct... */ typedef struct { Word blockLen; char name_length; /* 123456789 123456789 12345678 */ char message_name[28]; /* = "Kopriha Software SpoolMaster" */ KS_SHARED_DATA_HDL shared_data_handle; ResultBuf768Hdl shared_path_handle; } KS_NAMED_MESSAGE, *KS_NAMED_MSG_PTR, **KS_NAMED_MSG_HDL; /* * Function prototypes (for message center routines): */ void send_message(KS_SHARED_DATA_HDL *, ResultBuf255Hndl *); void receive_message(KS_SHARED_DATA_HDL *, ResultBuf255Hndl *); #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * SharedData.H + * + * Description: This include file contains the definition of the + * shared data structure that has a pointer to it posted + * to the message center. + * + * + * Table of contents: + * + * Structures: + * KS_SHARED_DATA . . . . . . . Shared data structure + * + * + * History:April 21, 1991 Dave Created this file + * + */ + +#ifndef _KS_SHARED_DATA_ +#define _KS_SHARED_DATA_ + +#ifndef _KS_DEFINES_ +#include "KS.Defines.H" +#endif + +#ifndef __GSOS__ +#include +#endif + + +/* + * Filetype/auxtype of spoolfiles. + */ + +#define SPOOLFILE_FILETYPE ((Word) 4) +#define SPOOLFILE_AUXTYPE ((LongWord) 0) +#define SPOOL_DONE_AUXTYPE ((LongWord) 256) + + + +/* + * Shared data spoolport flag states + */ + +enum port_flags {PORT_NOT_ACTIVE = 1, + PORT_READY, + PORT_SPOOLING, + PORT_ERROR}; + +/* + * Shared data spool flag states... + */ + +enum spool_flags {SPOOL_INIT = 0, /* First call - initialize everything */ + SPOOL_SCANNING, /* Scanning spool directory for a file */ + SPOOL_OPEN, /* Setting up for printing */ + SPOOL_WAITING, /* Waiting for port to be ready */ + SPOOL_PRINTING, /* Printing a spoolfile */ + SPOOL_CLOSE, /* Finished with a spoolfile */ + SPOOL_ERROR}; /* Some error stopped spooling */ + + +/* + * KS_SHARED_DATA - generic shared data structure + */ + +typedef struct + { + KS_STRUCT_ID struct_id; /* Structure id */ + + Word port_driver_length; /* Length of the port driver filename*/ + char port_driver_name[64]; /* Name of port driver to print with */ + + Word spool_filename_length;/* Length of spool basename */ + char spool_filename[64]; /* Basename of spool file */ + + LongWord buffer_size; /* User specified buffer size */ + /* (This is the value of the */ + /* scrollbar control) */ + + /* + * Flag words (should use bits, but we'll be a little foolish): + */ + Word delete_flag; /* Delete spoolfile after printing */ + Word print_flag; /* Print new spoolfiles */ + + + /* + * Data for the spoolport driver + */ + + enum port_flags port_status; + Word port_error; + Word port_spoolnumber; + + + /* + * Now for the background task information. + */ + + Pointer start_address; /* Start address of routine - pass */ + /* this to add to run q! */ + enum spool_flags spool_status; /* Status of spooler */ + Word spool_error; /* Saved Error from spooler */ + Word spool_spoolnumber; /* Spoolfile number being printed */ + Pointer file_ptr; /* Pointer to the file we're spooling*/ + LongWord bytes_written; /* Bytes written to the printer for */ + /* the current spool file */ + Word driver_user_id; /* Memory manager User ID for spooler*/ + + Handle buffer_handle; /* Handle to the I/O buffer */ + Byte *buffer; /* Pointer to the I/O buffer */ + LongWord buffer_bytesize; /* Size of the buffer (in bytes) */ + LongWord buffer_offset; /* Offset of next available byte */ + + + } KS_SHARED_DATA, *KS_SHARED_DATA_PTR, **KS_SHARED_DATA_HDL; + + + +typedef struct + { + Word length; + char text[768]; + } GSString768, *GSString768Ptr, **GSString768Hdl; + + +typedef struct + { + Word bufSize; + GSString768 buffer; + } ResultBuf768, *ResultBuf768Ptr, **ResultBuf768Hdl; + + + +/* + * KS_DATA_MESSAGE - record pointer passed to message center by name + * This holds most of the user specifiable data. The only structure + * missing is the pathname - and that is in the second message struct... + */ + +typedef struct + { + Word blockLen; + char name_length; /* 123456789 123456789 12345678 */ + char message_name[28]; /* = "Kopriha Software SpoolMaster" */ + KS_SHARED_DATA_HDL shared_data_handle; + ResultBuf768Hdl shared_path_handle; + } KS_NAMED_MESSAGE, *KS_NAMED_MSG_PTR, **KS_NAMED_MSG_HDL; + + + +/* + * Function prototypes (for message center routines): + */ + +void send_message(KS_SHARED_DATA_HDL *, + ResultBuf255Hndl *); + +void receive_message(KS_SHARED_DATA_HDL *, + ResultBuf255Hndl *); + +#endif diff --git a/sys/fileport/support/AddPath.c b/sys/fileport/support/AddPath.c index 62d2292..76a3419 100644 --- a/sys/fileport/support/AddPath.c +++ b/sys/fileport/support/AddPath.c @@ -1 +1,83 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * AddFile.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_path_add_file - Append a filename (or partial filename) * * to a pathname - although you can pass any* * pait of GS/OS strings. * * * * History: Mar 24, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_path_add_file" KS_E_ERROR ks_file_path_add_file(GSString255Ptr path_ptr, GSString255Ptr file_ptr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ ROUTINE_ENTER(); /* ************************************************************** * * Append the filename to the pathname. * * ************************************************************** */ COPY_BYTES(&file_ptr->text, 0, &path_ptr->text[path_ptr->length], 0, file_ptr->length); path_ptr->length = path_ptr->length + file_ptr->length; /* ************************************************************** * * Return a success to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_path_add_file() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * AddFile.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_path_add_file - Append a filename (or partial filename) * + * to a pathname - although you can pass any* + * pait of GS/OS strings. * + * * + * History: Mar 24, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_path_add_file" + + +KS_E_ERROR ks_file_path_add_file(GSString255Ptr path_ptr, + GSString255Ptr file_ptr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Append the filename to the pathname. * + * ************************************************************** */ + + COPY_BYTES(&file_ptr->text, + 0, + &path_ptr->text[path_ptr->length], + 0, + file_ptr->length); + + path_ptr->length = path_ptr->length + file_ptr->length; + + + /* ************************************************************** * + * Return a success to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_path_add_file() */ + + + diff --git a/sys/fileport/support/ChangeAux.c b/sys/fileport/support/ChangeAux.c index 40bada3..7d73ffa 100644 --- a/sys/fileport/support/ChangeAux.c +++ b/sys/fileport/support/ChangeAux.c @@ -1 +1,99 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * ChangeAux.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_change_auxtype - Change the aux type of a file. * * * * History: March 24, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_change_auxtype" KS_E_ERROR ks_file_change_auxtype(GSString255Ptr GSPathPtr, LongWord new_auxtype) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * First get some information about the file... * * ************************************************************** */ KSf_pkts.fileinfoGSOS.pCount = 4; KSf_pkts.fileinfoGSOS.pathname = GSPathPtr; GetFileInfoGS(&KSf_pkts.fileinfoGSOS); if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; /* ************************************************************** * * Now set the file info (especially the new aux type)... * * ************************************************************** */ KSf_pkts.fileinfoGSOS.pCount = 4; KSf_pkts.fileinfoGSOS.auxType = new_auxtype; SetFileInfoGS(&KSf_pkts.fileinfoGSOS); if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; /* ************************************************************** * * Return the success back to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_change_auxtype() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * ChangeAux.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_change_auxtype - Change the aux type of a file. * + * * + * History: March 24, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_change_auxtype" + +KS_E_ERROR ks_file_change_auxtype(GSString255Ptr GSPathPtr, + LongWord new_auxtype) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * First get some information about the file... * + * ************************************************************** */ + + KSf_pkts.fileinfoGSOS.pCount = 4; + KSf_pkts.fileinfoGSOS.pathname = GSPathPtr; + + GetFileInfoGS(&KSf_pkts.fileinfoGSOS); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Now set the file info (especially the new aux type)... * + * ************************************************************** */ + + KSf_pkts.fileinfoGSOS.pCount = 4; + KSf_pkts.fileinfoGSOS.auxType = new_auxtype; + + SetFileInfoGS(&KSf_pkts.fileinfoGSOS); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Return the success back to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_change_auxtype() */ + + + diff --git a/sys/fileport/support/Close.c b/sys/fileport/support/Close.c index c8672e4..5839be7 100644 --- a/sys/fileport/support/Close.c +++ b/sys/fileport/support/Close.c @@ -1 +1,141 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Close.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_close - close an open file. * * * * History: Oct 13, 1990 Dave Created this routine * * ****************************************************************** */ #define ROUTINE_NAME "ks_file_close" KS_E_ERROR ks_file_close(KS_FILE_PTR file_ptr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Verify the structure ID passed in is the correct one. * * ************************************************************** */ if (file_ptr->struct_id != KS_FILE_ID) { KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); }; /* ************************************************************** * * Flush any remaining buffer to disk (if there is a buffer and * * we are writing to the file). * * ************************************************************** */ if (file_ptr->buffer_size != NULL) { if (file_ptr->access == KS_FILE_WRITE_ACCESS) { if (file_ptr->buffer_offset != 0) { /* ************************************************** * * We have something in a buffer - write the final * * buffer to disk. * * ************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); KSf_pkts.IO.requestCount = file_ptr->buffer_offset; WriteGS(&KSf_pkts.IO); if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; }; /* End if there was something in the buffer */ }; /* End if we were writing to the file */ /* ********************************************************** * * We used buffered I/O on this file - now lets free the * * buffer back to free memory. * * ********************************************************** */ KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, error); }; /* End if we used buffered I/O to the file */ /* ************************************************************** * * Set up the close packet and close the file. * * ************************************************************** */ KSf_pkts.close.pCount = 1; KSf_pkts.close.refNum = file_ptr->refNum; CloseGS(&KSf_pkts.close); /* ************************************************************** * * Clear the FILE structure and give it back to free memory. * * ************************************************************** */ file_ptr->struct_id = 0; KS_MEMORY_DEALLOCATE(file_ptr->file_handle, error); /* ************************************************************** * * Return the success back to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_close() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Close.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_close - close an open file. * + * * + * History: Oct 13, 1990 Dave Created this routine * + * ****************************************************************** */ + +#define ROUTINE_NAME "ks_file_close" + +KS_E_ERROR ks_file_close(KS_FILE_PTR file_ptr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Verify the structure ID passed in is the correct one. * + * ************************************************************** */ + + if (file_ptr->struct_id != KS_FILE_ID) + { + KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Flush any remaining buffer to disk (if there is a buffer and * + * we are writing to the file). * + * ************************************************************** */ + + if (file_ptr->buffer_size != NULL) + { + if (file_ptr->access == KS_FILE_WRITE_ACCESS) + { + if (file_ptr->buffer_offset != 0) + { + + /* ************************************************** * + * We have something in a buffer - write the final * + * buffer to disk. * + * ************************************************** */ + + KSf_pkts.IO.pCount = 4; + KSf_pkts.IO.refNum = file_ptr->refNum; + KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); + KSf_pkts.IO.requestCount = file_ptr->buffer_offset; + + WriteGS(&KSf_pkts.IO); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + }; /* End if there was something in the buffer */ + + }; /* End if we were writing to the file */ + + /* ********************************************************** * + * We used buffered I/O on this file - now lets free the * + * buffer back to free memory. * + * ********************************************************** */ + + KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, + error); + + }; /* End if we used buffered I/O to the file */ + + + /* ************************************************************** * + * Set up the close packet and close the file. * + * ************************************************************** */ + + KSf_pkts.close.pCount = 1; + KSf_pkts.close.refNum = file_ptr->refNum; + + CloseGS(&KSf_pkts.close); + + + /* ************************************************************** * + * Clear the FILE structure and give it back to free memory. * + * ************************************************************** */ + + file_ptr->struct_id = 0; + + KS_MEMORY_DEALLOCATE(file_ptr->file_handle, + error); + + + /* ************************************************************** * + * Return the success back to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_close() */ + + diff --git a/sys/fileport/support/Create.c b/sys/fileport/support/Create.c index 43db496..78148ab 100644 --- a/sys/fileport/support/Create.c +++ b/sys/fileport/support/Create.c @@ -1 +1,93 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Create.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_create - Create a particular type/auxtype file * * * * History: Mar 3, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_create" KS_E_ERROR ks_file_create(GSString255Ptr GSPathPtr, Word file_type, LongWord auxtype) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Create the file for our caller. * * * * Note: The access is setup such that the file is readable, * * writable, can be renamed and can be deleted. * * ************************************************************** */ KSf_pkts.create.pCount = 4; KSf_pkts.create.pathname = GSPathPtr; KSf_pkts.create.access = readWriteEnable | renameEnable | destroyEnable; KSf_pkts.create.fileType = file_type; KSf_pkts.create.auxType = auxtype; CreateGS(&KSf_pkts.create); /* ************************************************************** * * Return the success/error back to our caller. * * ************************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_create() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Create.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_create - Create a particular type/auxtype file * + * * + * History: Mar 3, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_create" + +KS_E_ERROR ks_file_create(GSString255Ptr GSPathPtr, + Word file_type, + LongWord auxtype) + +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Create the file for our caller. * + * * + * Note: The access is setup such that the file is readable, * + * writable, can be renamed and can be deleted. * + * ************************************************************** */ + + KSf_pkts.create.pCount = 4; + KSf_pkts.create.pathname = GSPathPtr; + KSf_pkts.create.access = readWriteEnable | + renameEnable | + destroyEnable; + KSf_pkts.create.fileType = file_type; + KSf_pkts.create.auxType = auxtype; + + CreateGS(&KSf_pkts.create); + + + /* ************************************************************** * + * Return the success/error back to our caller. * + * ************************************************************** */ + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_create() */ + + diff --git a/sys/fileport/support/Data.c b/sys/fileport/support/Data.c index 6225805..1a8e6d2 100644 --- a/sys/fileport/support/Data.c +++ b/sys/fileport/support/Data.c @@ -1 +1,41 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Data.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #pragma noroot #define FILEIO_DATA #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Data.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#pragma noroot + +#define FILEIO_DATA + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + + + + diff --git a/sys/fileport/support/Delete.c b/sys/fileport/support/Delete.c index 3da5c72..c192d5a 100644 --- a/sys/fileport/support/Delete.c +++ b/sys/fileport/support/Delete.c @@ -1 +1,84 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Delete.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_delete - Delete a file. * * * * History: March 24, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_delete" KS_E_ERROR ks_file_delete(GSString255Ptr GSPathPtr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Setup the delete packet and try to get rid of the file. * * Any errors are returned to our caller. * * ************************************************************** */ KSf_pkts.delete.pCount = 1; KSf_pkts.delete.pathname = GSPathPtr; DestroyGS(&KSf_pkts.delete); if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; /* ************************************************************** * * Return the success back to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_delete() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Delete.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_delete - Delete a file. * + * * + * History: March 24, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_delete" + +KS_E_ERROR ks_file_delete(GSString255Ptr GSPathPtr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Setup the delete packet and try to get rid of the file. * + * Any errors are returned to our caller. * + * ************************************************************** */ + + KSf_pkts.delete.pCount = 1; + KSf_pkts.delete.pathname = GSPathPtr; + + DestroyGS(&KSf_pkts.delete); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Return the success back to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_delete() */ + + + diff --git a/sys/fileport/support/GetBufSize.c b/sys/fileport/support/GetBufSize.c index bc2d0d4..9ed0411 100644 --- a/sys/fileport/support/GetBufSize.c +++ b/sys/fileport/support/GetBufSize.c @@ -1 +1,69 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * GetBufSize.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_get_buffer_size - return the currently specified I/O * * buffer size. * * * * History: Mar 3, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_get_buffer_size" KS_E_ERROR ks_file_get_buffer_size(LongWord *buffer_size) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ ROUTINE_ENTER(); /* ************************************************************** * * Return the buffer size back to our caller. * * ************************************************************** */ *buffer_size = KSf_FileBufferSize; KS_SUCCESS(); } /* End of ks_file_get_buffer_size() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * GetBufSize.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_get_buffer_size - return the currently specified I/O * + * buffer size. * + * * + * History: Mar 3, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_get_buffer_size" + +KS_E_ERROR ks_file_get_buffer_size(LongWord *buffer_size) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Return the buffer size back to our caller. * + * ************************************************************** */ + + *buffer_size = KSf_FileBufferSize; + + KS_SUCCESS(); + +} /* End of ks_file_get_buffer_size() */ + + + diff --git a/sys/fileport/support/GetVolume.c b/sys/fileport/support/GetVolume.c index 63853f4..7e457f8 100644 --- a/sys/fileport/support/GetVolume.c +++ b/sys/fileport/support/GetVolume.c @@ -1 +1,90 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * GetVolume.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_get_volume - Return the volume name for the specified * * pathname. * * * * History: Mar 7, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_get_volume" KS_E_ERROR ks_file_get_volume(GSString255Ptr pathname_ptr, GSString255Ptr volume_ptr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ Word counter; /* Counts characters copied */ ROUTINE_ENTER(); /* ************************************************************** * * Copy the volume name out of the pathname. The volume name * * will start with a special delimitor, when we get to either * * the next delimitor or the end of the string then we have * * copied all of the volume name. * * ************************************************************** */ volume_ptr->text[0] = pathname_ptr->text[0]; for (counter = 1; ((counter < (pathname_ptr->length) ) && ((pathname_ptr->text[0]) != (pathname_ptr->text[counter]))); counter++) { volume_ptr->text[counter] = pathname_ptr->text[counter]; }; volume_ptr->length = counter; /* ************************************************************** * * Return a success to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_get_volume() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * GetVolume.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_get_volume - Return the volume name for the specified * + * pathname. * + * * + * History: Mar 7, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_get_volume" + + +KS_E_ERROR ks_file_get_volume(GSString255Ptr pathname_ptr, + GSString255Ptr volume_ptr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + Word counter; /* Counts characters copied */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Copy the volume name out of the pathname. The volume name * + * will start with a special delimitor, when we get to either * + * the next delimitor or the end of the string then we have * + * copied all of the volume name. * + * ************************************************************** */ + + volume_ptr->text[0] = pathname_ptr->text[0]; + + for (counter = 1; + ((counter < (pathname_ptr->length) ) && + ((pathname_ptr->text[0]) != (pathname_ptr->text[counter]))); + counter++) + { + volume_ptr->text[counter] = pathname_ptr->text[counter]; + }; + + volume_ptr->length = counter; + + + /* ************************************************************** * + * Return a success to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_get_volume() */ + + diff --git a/sys/fileport/support/MSGReceive.c b/sys/fileport/support/MSGReceive.c index 0fc3813..0db34d4 100644 --- a/sys/fileport/support/MSGReceive.c +++ b/sys/fileport/support/MSGReceive.c @@ -1 +1,140 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * MSGReceive.CC * * Description: * This module is message center options from the menus.. * * * Table of Contents: * * retrieve_message . . Get message by name for our caller... * * History:April 23, 1991 Dave Created this file * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #include #ifndef __LOCATOR__ #include #endif #ifndef __MISCTOOL__ #include #endif #ifndef _KS_DEFINES_ #include "KS.Defines.h" #endif #ifndef _KS_MEMORY_ #include "KS.Memory.H" #endif #ifndef _KS_SHARED_DATA_ #include "SharedData.H" #endif #pragma noroot /* ****************************************************************** * * receive_message() - Get a pointer to the port data to the message * * center by name... * * * * History: Apr 23, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "receive_message" void receive_message(KS_SHARED_DATA_HDL *data_hdl, ResultBuf255Hndl *path_hdl) { ResponseRecord response_rec; KS_NAMED_MESSAGE named_msg; KS_NAMED_MSG_PTR msg_rec_ptr; Word message_id; Handle msg_handle; KS_E_ERROR error; extern Word ProgramID; *data_hdl = NULL; *path_hdl = NULL; /* ************************************************************** * * Start by getting the message id for the named message * * ************************************************************** */ named_msg.blockLen = sizeof(KS_NAMED_MESSAGE); strcpy(named_msg.message_name, "Kopriha Software SpoolMaster"); named_msg.name_length = strlen(named_msg.message_name); response_rec = MessageByName(FALSE, (void *) &named_msg); if (GET_ERROR() != KS_E_SUCCESS) { return; }; message_id = (response_rec & 0xffff); /* ************************************************************** * * Get the complete message from the message center * * ************************************************************** */ KS_MEMORY_ALLOCATE(attrNoSpec + attrNoCross, sizeof(KS_NAMED_MESSAGE), /* could be anything */ ProgramID, msg_handle, error); if (error != KS_E_SUCCESS) { return; }; MessageCenter((Word) getMessage, (Word) message_id, (Handle) msg_handle); if (GET_ERROR() == KS_E_SUCCESS) { msg_rec_ptr = (KS_NAMED_MSG_PTR) &(((MessageRecPtr) *msg_handle)->messageData); *data_hdl = msg_rec_ptr->shared_data_handle; *path_hdl = (ResultBuf255Hndl) msg_rec_ptr->shared_path_handle; }; KS_MEMORY_DEALLOCATE(msg_handle, error); /* ************************************************************** * * Return to our caller. * * ************************************************************** */ return; } /* End of receive_message() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * MSGReceive.CC + * + * Description: + * This module is message center options from the menus.. + * + * + * Table of Contents: + * + * retrieve_message . . Get message by name for our caller... + * + * History:April 23, 1991 Dave Created this file + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#include + +#ifndef __LOCATOR__ +#include +#endif + +#ifndef __MISCTOOL__ +#include +#endif + +#ifndef _KS_DEFINES_ +#include "KS.Defines.h" +#endif + +#ifndef _KS_MEMORY_ +#include "KS.Memory.H" +#endif + +#ifndef _KS_SHARED_DATA_ +#include "SharedData.H" +#endif + + +#pragma noroot + + + +/* ****************************************************************** * + * receive_message() - Get a pointer to the port data to the message * + * center by name... * + * * + * History: Apr 23, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "receive_message" + +void receive_message(KS_SHARED_DATA_HDL *data_hdl, + ResultBuf255Hndl *path_hdl) +{ + + ResponseRecord response_rec; + KS_NAMED_MESSAGE named_msg; + KS_NAMED_MSG_PTR msg_rec_ptr; + Word message_id; + Handle msg_handle; + KS_E_ERROR error; + extern Word ProgramID; + + + *data_hdl = NULL; + *path_hdl = NULL; + + + /* ************************************************************** * + * Start by getting the message id for the named message * + * ************************************************************** */ + + named_msg.blockLen = sizeof(KS_NAMED_MESSAGE); + + strcpy(named_msg.message_name, "Kopriha Software SpoolMaster"); + + named_msg.name_length = strlen(named_msg.message_name); + + response_rec = MessageByName(FALSE, + (void *) &named_msg); + + if (GET_ERROR() != KS_E_SUCCESS) + { + return; + }; + + message_id = (response_rec & 0xffff); + + + /* ************************************************************** * + * Get the complete message from the message center * + * ************************************************************** */ + + KS_MEMORY_ALLOCATE(attrNoSpec + attrNoCross, + sizeof(KS_NAMED_MESSAGE), /* could be anything */ + ProgramID, + msg_handle, + error); + + if (error != KS_E_SUCCESS) + { + return; + }; + + MessageCenter((Word) getMessage, + (Word) message_id, + (Handle) msg_handle); + + if (GET_ERROR() == KS_E_SUCCESS) + { + msg_rec_ptr = (KS_NAMED_MSG_PTR) + &(((MessageRecPtr) *msg_handle)->messageData); + + *data_hdl = msg_rec_ptr->shared_data_handle; + *path_hdl = (ResultBuf255Hndl) msg_rec_ptr->shared_path_handle; + }; + + + KS_MEMORY_DEALLOCATE(msg_handle, + error); + + + /* ************************************************************** * + * Return to our caller. * + * ************************************************************** */ + + return; + +} /* End of receive_message() */ diff --git a/sys/fileport/support/MSGSend.c b/sys/fileport/support/MSGSend.c index 254dad6..5b2d325 100644 --- a/sys/fileport/support/MSGSend.c +++ b/sys/fileport/support/MSGSend.c @@ -1 +1,186 @@ - /* * Copyright (c) Kopriha Software, 1991 * All Rights Reserved * * MSGSend.CC * * Description: * This module is message center options from the menus.. * * * Table of Contents: * * send_message . . . . Send a message to the message center (by name) * retrieve_message . . Get message by name for our caller... * * History:April 23, 1991 Dave Created this file * * July 2, 1991 Dave Changed the parameters to pointers to * handles (so our caller can work with * the real shared data - not the original * copy that will be purged soon). * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #include #ifndef __LOCATOR__ #include #endif #ifndef __MISCTOOL__ #include #endif #ifndef _KS_DEFINES_ #include "KS.Defines.h" #endif #ifndef _KS_MEMORY_ #include "KS.Memory.H" #endif #ifndef _KS_SHARED_DATA_ #include "SharedData.H" #endif #pragma noroot /* ****************************************************************** * * send_message() - Send a few handles to the message center by name.* * (IE: Create some shared memory for the different * * parts of the print spooler). * * * * Note: This routine used to take a pointer to the data items to * * setup in shared memory (by copying into memory that is * * allocated under a different user id). The problem with * * that scheme is that the caller does not have access to the * * shared structure on our return. The simple change is to * * pass pointers to the handle to the data. This routine * * then change the handles to point to the real shared data * * so our caller can work with it. * * * * History: Apr 23, 1991 Dave Created this routine * * ****************************************************************** */ #define ROUTINE_NAME "send_message" void send_message(KS_SHARED_DATA_HDL *shared_data_template, ResultBuf255Hndl *shared_path_template) { ResponseRecord response_rec; KS_NAMED_MESSAGE named_msg; Word user_id; Handle new_handle; KS_SHARED_DATA_PTR data_ptr; ResultBuf768Ptr path_ptr; KS_E_ERROR error; /* ************************************************************** * * Setup the header of the message center message... We're * * doing this here because the name of the message is not a * * C string to the system - here we can overwrite the element * * beyond of the message name without causing a problem (like * * blowing away the first byte of that element...). * * ************************************************************** */ named_msg.blockLen = sizeof(KS_NAMED_MESSAGE); strcpy(named_msg.message_name, "Kopriha Software SpoolMaster"); named_msg.name_length = strlen(named_msg.message_name); /* ************************************************************** * * Get a new user id for us to allocate the shared structures. * * ************************************************************** */ user_id = GetNewID((Word) 0xA000); /* Using a setup file id... */ (**shared_data_template)->driver_user_id = user_id; /* ************************************************************** * * Grab a couple of chunks of memory to setup the shared data * * structures * * ************************************************************** */ KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, sizeof(KS_SHARED_DATA), user_id, new_handle, error); if (error != KS_E_SUCCESS) { return; }; data_ptr = (KS_SHARED_DATA_PTR) *new_handle; named_msg.shared_data_handle = (KS_SHARED_DATA_HDL) new_handle; KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, sizeof(ResultBuf768), user_id, new_handle, error); if (error != KS_E_SUCCESS) { return; }; path_ptr = (ResultBuf768Ptr) *new_handle; named_msg.shared_path_handle = (ResultBuf768Hdl) new_handle; /* ************************************************************** * * Copy the passed in structures to the new shared structure. * * ************************************************************** */ COPY_BYTES(**shared_data_template, 0, data_ptr, 0, sizeof(KS_SHARED_DATA)); COPY_BYTES(**shared_path_template, 0, path_ptr, 0, sizeof(ResultBuf768)); /* ************************************************************** * * Send the pointer to our shared data by name to the message * * center * * ************************************************************** */ response_rec = MessageByName(TRUE, (void *) &named_msg); /* ************************************************************** * * Ok - We've sent the message to the message center - return * * ************************************************************** */ *shared_data_template = named_msg.shared_data_handle; return; } /* End of send_message() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1991 + * All Rights Reserved + * + * MSGSend.CC + * + * Description: + * This module is message center options from the menus.. + * + * + * Table of Contents: + * + * send_message . . . . Send a message to the message center (by name) + * retrieve_message . . Get message by name for our caller... + * + * History:April 23, 1991 Dave Created this file + * + * July 2, 1991 Dave Changed the parameters to pointers to + * handles (so our caller can work with + * the real shared data - not the original + * copy that will be purged soon). + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#include + +#ifndef __LOCATOR__ +#include +#endif + +#ifndef __MISCTOOL__ +#include +#endif + +#ifndef _KS_DEFINES_ +#include "KS.Defines.h" +#endif + +#ifndef _KS_MEMORY_ +#include "KS.Memory.H" +#endif + +#ifndef _KS_SHARED_DATA_ +#include "SharedData.H" +#endif + + +#pragma noroot + + + +/* ****************************************************************** * + * send_message() - Send a few handles to the message center by name.* + * (IE: Create some shared memory for the different * + * parts of the print spooler). * + * * + * Note: This routine used to take a pointer to the data items to * + * setup in shared memory (by copying into memory that is * + * allocated under a different user id). The problem with * + * that scheme is that the caller does not have access to the * + * shared structure on our return. The simple change is to * + * pass pointers to the handle to the data. This routine * + * then change the handles to point to the real shared data * + * so our caller can work with it. * + * * + * History: Apr 23, 1991 Dave Created this routine * + * ****************************************************************** */ + +#define ROUTINE_NAME "send_message" + +void send_message(KS_SHARED_DATA_HDL *shared_data_template, + ResultBuf255Hndl *shared_path_template) +{ + + ResponseRecord response_rec; + KS_NAMED_MESSAGE named_msg; + Word user_id; + Handle new_handle; + KS_SHARED_DATA_PTR data_ptr; + ResultBuf768Ptr path_ptr; + KS_E_ERROR error; + + + /* ************************************************************** * + * Setup the header of the message center message... We're * + * doing this here because the name of the message is not a * + * C string to the system - here we can overwrite the element * + * beyond of the message name without causing a problem (like * + * blowing away the first byte of that element...). * + * ************************************************************** */ + + named_msg.blockLen = sizeof(KS_NAMED_MESSAGE); + + strcpy(named_msg.message_name, "Kopriha Software SpoolMaster"); + + named_msg.name_length = strlen(named_msg.message_name); + + + /* ************************************************************** * + * Get a new user id for us to allocate the shared structures. * + * ************************************************************** */ + + user_id = GetNewID((Word) 0xA000); /* Using a setup file id... */ + + (**shared_data_template)->driver_user_id = user_id; + + + + /* ************************************************************** * + * Grab a couple of chunks of memory to setup the shared data * + * structures * + * ************************************************************** */ + + KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, + sizeof(KS_SHARED_DATA), + user_id, + new_handle, + error); + + if (error != KS_E_SUCCESS) + { + return; + }; + + data_ptr = (KS_SHARED_DATA_PTR) *new_handle; + named_msg.shared_data_handle = (KS_SHARED_DATA_HDL) new_handle; + + + KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, + sizeof(ResultBuf768), + user_id, + new_handle, + error); + + if (error != KS_E_SUCCESS) + { + return; + }; + + path_ptr = (ResultBuf768Ptr) *new_handle; + named_msg.shared_path_handle = (ResultBuf768Hdl) new_handle; + + + /* ************************************************************** * + * Copy the passed in structures to the new shared structure. * + * ************************************************************** */ + + COPY_BYTES(**shared_data_template, + 0, + data_ptr, + 0, + sizeof(KS_SHARED_DATA)); + + + COPY_BYTES(**shared_path_template, + 0, + path_ptr, + 0, + sizeof(ResultBuf768)); + + + /* ************************************************************** * + * Send the pointer to our shared data by name to the message * + * center * + * ************************************************************** */ + + response_rec = MessageByName(TRUE, + (void *) &named_msg); + + + /* ************************************************************** * + * Ok - We've sent the message to the message center - return * + * ************************************************************** */ + + *shared_data_template = named_msg.shared_data_handle; + + return; + +} /* End of send_message() */ diff --git a/sys/fileport/support/Makefile b/sys/fileport/support/Makefile index ece4f44..e5d9bbf 100644 --- a/sys/fileport/support/Makefile +++ b/sys/fileport/support/Makefile @@ -1 +1,67 @@ -# # $Id: Makefile,v 1.1 1997/12/19 07:54:51 gdr Exp $ # LIB = libdvr ODIR = obj OBJS = \ $(ODIR)/AddPath.o \ $(ODIR)/ChangeAux.o \ $(ODIR)/Close.o \ $(ODIR)/Create.o \ $(ODIR)/Data.o \ $(ODIR)/Delete.o \ $(ODIR)/GetBufSize.o \ $(ODIR)/GetVolume.o \ $(ODIR)/Gnfn.o \ $(ODIR)/MSGReceive.o \ $(ODIR)/MSGSend.o \ $(ODIR)/Open.o \ $(ODIR)/Read.o \ $(ODIR)/Rename.o \ $(ODIR)/SetBufSize.o \ $(ODIR)/SetDir.o \ $(ODIR)/SetEOF.o \ $(ODIR)/Space.o \ $(ODIR)/Write.o INCL2 = ../includes HDRS = ks.fileio.h $(INCL2)/ks.fileio.e $(INCL2)/ks.memory.h \ $(INCL2)/ks.defines.h $(INCL2)/KS.CDEV.h $(INCL2)/KS.Routines.h \ $(INCL2)/Portable.C.h $(INCL2)/SharedData.h SEGMENT = -Slibdvr____ CFLAGS = $(SEGMENT) -I$(INCL2) -r -w -v -O78 build: $(LIB) $(ODIR): install -d $(ODIR) $(LIB): $(OBJS) $(RM) -f $@ makelib.apw -w -r -p -l $@ $(OBJS) $(ODIR)/%.o: %.c $(CC) -o $@ -c $(CFLAGS) $< $(ODIR)/AddPath.o:: $(HDRS) $(ODIR)/Write.o:: $(HDRS) $(ODIR)/Space.o:: $(HDRS) $(ODIR)/SetEOF.o:: $(HDRS) $(ODIR)/SetDir.o:: $(HDRS) $(ODIR)/SetBufSize.o:: $(HDRS) $(ODIR)/Rename.o:: $(HDRS) $(ODIR)/Read.o:: $(HDRS) $(ODIR)/Open.o:: $(HDRS) $(ODIR)/msgsend.o:: $(HDRS) $(ODIR)/msgreceive.o:: $(HDRS) $(ODIR)/gnfn.o:: $(HDRS) $(ODIR)/GetVolume.o:: $(HDRS) $(ODIR)/GetBufSize.o:: $(HDRS) $(ODIR)/Delete.o:: $(HDRS) $(ODIR)/Data.o:: $(HDRS) $(ODIR)/Create.o:: $(HDRS) $(ODIR)/Close.o:: $(HDRS) $(ODIR)/ChangeAux.o:: $(HDRS) \ No newline at end of file +# +# $Id: Makefile,v 1.2 1998/12/13 02:50:33 gdr-ftp Exp $ +# + +LIB = libdvr +ODIR = obj +OBJS = \ + $(ODIR)/AddPath.o \ + $(ODIR)/ChangeAux.o \ + $(ODIR)/Close.o \ + $(ODIR)/Create.o \ + $(ODIR)/Data.o \ + $(ODIR)/Delete.o \ + $(ODIR)/GetBufSize.o \ + $(ODIR)/GetVolume.o \ + $(ODIR)/Gnfn.o \ + $(ODIR)/MSGReceive.o \ + $(ODIR)/MSGSend.o \ + $(ODIR)/Open.o \ + $(ODIR)/Read.o \ + $(ODIR)/Rename.o \ + $(ODIR)/SetBufSize.o \ + $(ODIR)/SetDir.o \ + $(ODIR)/SetEOF.o \ + $(ODIR)/Space.o \ + $(ODIR)/Write.o + +INCL2 = ../includes +HDRS = ks.fileio.h $(INCL2)/ks.fileio.e $(INCL2)/ks.memory.h \ + $(INCL2)/ks.defines.h $(INCL2)/KS.CDEV.h $(INCL2)/KS.Routines.h \ + $(INCL2)/Portable.C.h $(INCL2)/SharedData.h + +SEGMENT = -Slibdvr____ + +CFLAGS = $(SEGMENT) -I$(INCL2) -r -w -v -O78 + +build: $(LIB) + +$(ODIR): + install -d $(ODIR) + +$(LIB): $(OBJS) + $(RM) -f $@ + makelib.apw -w -r -p -l $@ $(OBJS) + +$(ODIR)/%.o: %.c + $(CC) -o $@ -c $(CFLAGS) $< + +$(ODIR)/AddPath.o:: $(HDRS) +$(ODIR)/Write.o:: $(HDRS) +$(ODIR)/Space.o:: $(HDRS) +$(ODIR)/SetEOF.o:: $(HDRS) +$(ODIR)/SetDir.o:: $(HDRS) +$(ODIR)/SetBufSize.o:: $(HDRS) +$(ODIR)/Rename.o:: $(HDRS) +$(ODIR)/Read.o:: $(HDRS) +$(ODIR)/Open.o:: $(HDRS) +$(ODIR)/msgsend.o:: $(HDRS) +$(ODIR)/msgreceive.o:: $(HDRS) +$(ODIR)/gnfn.o:: $(HDRS) +$(ODIR)/GetVolume.o:: $(HDRS) +$(ODIR)/GetBufSize.o:: $(HDRS) +$(ODIR)/Delete.o:: $(HDRS) +$(ODIR)/Data.o:: $(HDRS) +$(ODIR)/Create.o:: $(HDRS) +$(ODIR)/Close.o:: $(HDRS) +$(ODIR)/ChangeAux.o:: $(HDRS) diff --git a/sys/fileport/support/Open.c b/sys/fileport/support/Open.c index 79b754c..df0bdc2 100644 --- a/sys/fileport/support/Open.c +++ b/sys/fileport/support/Open.c @@ -1 +1,190 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Open.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_open - open a file for reading/writing. * * * * History: Oct 12, 1990 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_open" KS_E_ERROR ks_file_open(GSString255Ptr GSPathPtr, Word access, Word file_fork, Word buffer_flag, KS_FILE_HDL file_hdl) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ KS_FILE_PTR file_ptr; /* Pointer to the new KS_FILE struct */ Handle file_handle; /* Handle to the file pointer */ Word file_ref; /* File reference number (for errors) */ ROUTINE_ENTER(); /* ************************************************************** * * Open the file for our caller. * * ************************************************************** */ KSf_pkts.open.pCount = 15; KSf_pkts.open.pathname = GSPathPtr; KSf_pkts.open.requestAccess = access; KSf_pkts.open.resourceNumber = file_fork; KSf_pkts.open.optionList = (ResultBuf255Ptr) &(KSf_pkts2.optionList[0]); KSf_pkts2.optionList[0] = sizeof(KSf_pkts2.optionList) - sizeof(Word); OpenGS(&KSf_pkts.open); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; file_ref = KSf_pkts.open.refNum; /* ************************************************************** * * The file is open, now lets setup the KS_FILE structure. * * * * Allocate a KS_FILE structure, fill it in and return the * * file pointer (actually, store it through the handle). * * ************************************************************** */ KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, sizeof(KS_FILE), BUFFER_USERID, file_handle, error); if (error != KS_E_SUCCESS) { goto CLOSE_EXIT; }; file_ptr = (KS_FILE_PTR) *file_handle; file_ptr->file_handle = file_handle; file_ptr->access = access; file_ptr->refNum = KSf_pkts.open.refNum; file_ptr->eof = KSf_pkts.open.eof; file_ptr->resource_eof = KSf_pkts.open.resourceEOF; file_ptr->fileType = KSf_pkts.open.fileType; file_ptr->auxType = KSf_pkts.open.auxType; file_ptr->end_of_file = FALSE; file_ptr->end_of_dir = TRUE; file_ptr->struct_id = KS_FILE_ID; /* ************************************************************** * * We have a good KS_FILE structure, lets try to setup a buffer * * to do I/O to/from if our caller wants one. * * ************************************************************** */ if (buffer_flag == KS_FILE_BUFFER_IO) { KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, KSf_FileBufferSize, BUFFER_USERID, file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto FREE_CLOSE_EXIT; }; file_ptr->buffer = (Byte *) *(file_ptr->buffer_handle); file_ptr->buffer_size = KSf_FileBufferSize; file_ptr->buffer_offset = 0; if (access == KS_FILE_WRITE_ACCESS) { file_ptr->buffer_available = KSf_FileBufferSize; } else { file_ptr->buffer_available = 0; }; } else { file_ptr->buffer_size = NULL; }; /* ************************************************************** * * Return the open file back to our caller. * * ************************************************************** */ *file_hdl = file_ptr; KS_SUCCESS(); /* ************************************************************** * * Return the error back to our caller after we close file file. * * ************************************************************** */ FREE_CLOSE_EXIT: file_ptr->struct_id = 0; KS_MEMORY_DEALLOCATE(file_handle, error); CLOSE_EXIT: KSf_pkts.close.pCount = 1; KSf_pkts.close.refNum = file_ref; CloseGS(&KSf_pkts.close); EXIT_NOW: KS_ERROR(error, KS_FILE_ID); } /* End of ks_file_open() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Open.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_open - open a file for reading/writing. * + * * + * History: Oct 12, 1990 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_open" + +KS_E_ERROR ks_file_open(GSString255Ptr GSPathPtr, + Word access, + Word file_fork, + Word buffer_flag, + KS_FILE_HDL file_hdl) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + KS_FILE_PTR file_ptr; /* Pointer to the new KS_FILE struct */ + Handle file_handle; /* Handle to the file pointer */ + Word file_ref; /* File reference number (for errors) */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Open the file for our caller. * + * ************************************************************** */ + + KSf_pkts.open.pCount = 15; + KSf_pkts.open.pathname = GSPathPtr; + KSf_pkts.open.requestAccess = access; + KSf_pkts.open.resourceNumber = file_fork; + KSf_pkts.open.optionList = (ResultBuf255Ptr) + &(KSf_pkts2.optionList[0]); + KSf_pkts2.optionList[0] = sizeof(KSf_pkts2.optionList) + - sizeof(Word); + + OpenGS(&KSf_pkts.open); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + file_ref = KSf_pkts.open.refNum; + + + /* ************************************************************** * + * The file is open, now lets setup the KS_FILE structure. * + * * + * Allocate a KS_FILE structure, fill it in and return the * + * file pointer (actually, store it through the handle). * + * ************************************************************** */ + + KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, + sizeof(KS_FILE), + BUFFER_USERID, + file_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto CLOSE_EXIT; + }; + + file_ptr = (KS_FILE_PTR) *file_handle; + + file_ptr->file_handle = file_handle; + file_ptr->access = access; + file_ptr->refNum = KSf_pkts.open.refNum; + file_ptr->eof = KSf_pkts.open.eof; + file_ptr->resource_eof = KSf_pkts.open.resourceEOF; + file_ptr->fileType = KSf_pkts.open.fileType; + file_ptr->auxType = KSf_pkts.open.auxType; + file_ptr->end_of_file = FALSE; + file_ptr->end_of_dir = TRUE; + file_ptr->struct_id = KS_FILE_ID; + + + /* ************************************************************** * + * We have a good KS_FILE structure, lets try to setup a buffer * + * to do I/O to/from if our caller wants one. * + * ************************************************************** */ + + if (buffer_flag == KS_FILE_BUFFER_IO) + { + KS_MEMORY_ALLOCATE(attrNoSpec + attrLocked, + KSf_FileBufferSize, + BUFFER_USERID, + file_ptr->buffer_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto FREE_CLOSE_EXIT; + }; + + file_ptr->buffer = (Byte *) *(file_ptr->buffer_handle); + + file_ptr->buffer_size = KSf_FileBufferSize; + file_ptr->buffer_offset = 0; + + if (access == KS_FILE_WRITE_ACCESS) + { + file_ptr->buffer_available = KSf_FileBufferSize; + } + else + { + file_ptr->buffer_available = 0; + }; + } + else + { + file_ptr->buffer_size = NULL; + }; + + + /* ************************************************************** * + * Return the open file back to our caller. * + * ************************************************************** */ + + *file_hdl = file_ptr; + + KS_SUCCESS(); + + + /* ************************************************************** * + * Return the error back to our caller after we close file file. * + * ************************************************************** */ + +FREE_CLOSE_EXIT: + + file_ptr->struct_id = 0; + + KS_MEMORY_DEALLOCATE(file_handle, + error); + +CLOSE_EXIT: + + KSf_pkts.close.pCount = 1; + KSf_pkts.close.refNum = file_ref; + + CloseGS(&KSf_pkts.close); + +EXIT_NOW: + + KS_ERROR(error, KS_FILE_ID); + +} /* End of ks_file_open() */ diff --git a/sys/fileport/support/Read.c b/sys/fileport/support/Read.c index 2829f3e..b3bf7b5 100644 --- a/sys/fileport/support/Read.c +++ b/sys/fileport/support/Read.c @@ -1 +1,343 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Read.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * * Jun 30, 1991 Dave Added support for no target buffer * (IE: This allows me to open a file * with a buffer then do I/O to only * that buffer - we will assume that * the caller will know what he is doing). * * This functionallity is invoked when * we are called with a data_buffer * pointer to NULL (then the user must * understand that the file_ptr->buffer * is where he will find his data). * * Note: This functionallity is only * implemented for the buffered I/O case! * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_read - Perform an read from an open file (possibly using * * an internal buffer). * * * * History: Feb 26, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_read" KS_E_ERROR ks_file_read(KS_FILE_PTR file_ptr, LongWord position, LongWord data_size, Pointer data_buffer) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutine*/ /* calls */ LongWord data_offset; /* Offset into the buffer to return*/ LongWord remaining_space; /* Space remaining in file buffer */ LongWord buffer_request; /* Size of each copy from the */ /* file buffer */ ROUTINE_ENTER(); /* ************************************************************** * * Verify the structure ID passed in is the correct one. * * ************************************************************** */ if (file_ptr->struct_id != KS_FILE_ID) { KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); }; /* ************************************************************** * * Zero the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = 0; /* ************************************************************** * * If there is a buffer, then lets get data from the file buffer.* * ************************************************************** */ if (file_ptr->buffer_size != NULL) { /* ********************************************************** * * If we hit the end of file last time, then we have no * * choice but to return an error. * * ********************************************************** */ if (file_ptr->end_of_file == TRUE) { error = eofEncountered; goto EXIT_NOW; }; /* ********************************************************** * * Loop till we satisfy the request (or take an error) * * ********************************************************** */ data_offset = 0; while (data_size > 0) { /* ****************************************************** * * Calculate the remaining space in the buffer. If * * there is any space left in the buffer then lets copy * * as much as we need to into the output buffer. * * ****************************************************** */ remaining_space = (file_ptr->buffer_available) - (file_ptr->buffer_offset); if (remaining_space > 0) { buffer_request = MIN(data_size, remaining_space); /* ************************************************** * * Copy the available bytes (or the required bytes) * * to the target buffer (if one was supplied). * * ************************************************** */ if (data_buffer != NULL) { COPY_BYTES(file_ptr->buffer, file_ptr->buffer_offset, data_buffer, data_offset, buffer_request); }; /* ************************************************** * * Now modify the parameters of the buffers by: * * * * 1) Adding the size of the request to the file * * buffer ofset and the data offset (IE: Indices to * * the file buffer and the read request buffer). * * * * 2) Subtracting the request size from the read * * request size and the remaining number of * * characters in the file buffer. * * ************************************************** */ file_ptr->buffer_offset = file_ptr->buffer_offset + buffer_request; data_offset = data_offset + buffer_request; file_ptr->data_size = data_offset; data_size = data_size - buffer_request; remaining_space = remaining_space - buffer_request; }; /* ****************************************************** * * If isn't anything in the file buffer, the we have to * * re-fill it. The problem is that the buffer size may * * have changed due to what our user wants (users are * * bound to be the end of all computing...). This means * * that we'll junp through a few hoops if we must change * * buffer sizes - so expect some weirdness here. * * ****************************************************** */ if (remaining_space == 0) { /* ************************************************** * * This is the above mentioned weirdness - if the * * user specified a different size buffer we will * * no comply with their wishes. * * ************************************************** */ if (file_ptr->buffer_size != KSf_FileBufferSize) { KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; KS_MEMORY_ALLOCATE(attrFixed + attrLocked, KSf_FileBufferSize, BUFFER_USERID, file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; file_ptr->buffer = (Byte *) *(file_ptr->buffer_handle); file_ptr->buffer_size = KSf_FileBufferSize; file_ptr->buffer_available = KSf_FileBufferSize; }; /* ************************************************** * * Issue a Read to the file into our buffer. * * ************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); KSf_pkts.IO.requestCount = file_ptr->buffer_size; ReadGS(&KSf_pkts.IO); /* ************************************************** * * Now for the error processing. * * * * Any error means we return to our caller. * * * * The end of file error (eofEncountered or $4c) is * * special. At EOF we mark the KS_FILE structure * * so the next READ call will return EOF right away. * * We will return SUCCESS in this case because the * * user will be able to find some data in the input * * buffer (total amount == ). * ************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { if (error == eofEncountered) { error = KS_E_SUCCESS; file_ptr->end_of_file = TRUE; } goto EXIT_NOW; }; file_ptr->buffer_available = KSf_pkts.IO.transferCount; file_ptr->buffer_offset = 0; }; /* End if there is no remaining buffer space */ }; /* End while there are characters to be read... */ KS_SUCCESS(); }; /* End if we are doing buffer I/O from the file */ /* ************************************************************** * * Ok, we've done enough buffering... lets do some real input... * * * * Position the 'mark' (where we will read from) in the file. * * Note: We'll move the mark only if our user asks us to. * * ************************************************************** */ if (position != KS_NEXT_FILE_POSITION) { KSf_pkts.position.pCount = 3; KSf_pkts.position.refNum = file_ptr->refNum; KSf_pkts.position.base = startPlus; KSf_pkts.position.displacement = position; SetMarkGS(&KSf_pkts.position); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; }; /* End if we must change the file position */ /* ************************************************************** * * Setup the I/O packet and read what our user is asking for. * * ************************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = data_buffer; KSf_pkts.IO.requestCount = data_size; ReadGS(&KSf_pkts.IO); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; /* ************************************************************** * * Save the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = KSf_pkts.IO.transferCount; /* ************************************************************** * * Return the status back to our caller. * * ************************************************************** */ EXIT_NOW: if (error != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_read() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Read.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + * Jun 30, 1991 Dave Added support for no target buffer + * (IE: This allows me to open a file + * with a buffer then do I/O to only + * that buffer - we will assume that + * the caller will know what he is doing). + * + * This functionallity is invoked when + * we are called with a data_buffer + * pointer to NULL (then the user must + * understand that the file_ptr->buffer + * is where he will find his data). + * + * Note: This functionallity is only + * implemented for the buffered I/O case! + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_read - Perform an read from an open file (possibly using * + * an internal buffer). * + * * + * History: Feb 26, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_read" + +KS_E_ERROR ks_file_read(KS_FILE_PTR file_ptr, + LongWord position, + LongWord data_size, + Pointer data_buffer) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutine*/ + /* calls */ + LongWord data_offset; /* Offset into the buffer to return*/ + LongWord remaining_space; /* Space remaining in file buffer */ + LongWord buffer_request; /* Size of each copy from the */ + /* file buffer */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Verify the structure ID passed in is the correct one. * + * ************************************************************** */ + + if (file_ptr->struct_id != KS_FILE_ID) + { + KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Zero the number of bytes transfered in the KS_FILE structure. * + * ************************************************************** */ + + file_ptr->data_size = 0; + + + /* ************************************************************** * + * If there is a buffer, then lets get data from the file buffer.* + * ************************************************************** */ + + if (file_ptr->buffer_size != NULL) + { + + /* ********************************************************** * + * If we hit the end of file last time, then we have no * + * choice but to return an error. * + * ********************************************************** */ + + if (file_ptr->end_of_file == TRUE) + { + error = eofEncountered; + goto EXIT_NOW; + }; + + + /* ********************************************************** * + * Loop till we satisfy the request (or take an error) * + * ********************************************************** */ + + data_offset = 0; + + while (data_size > 0) + { + + /* ****************************************************** * + * Calculate the remaining space in the buffer. If * + * there is any space left in the buffer then lets copy * + * as much as we need to into the output buffer. * + * ****************************************************** */ + + remaining_space = (file_ptr->buffer_available) - + (file_ptr->buffer_offset); + + if (remaining_space > 0) + { + buffer_request = MIN(data_size, + remaining_space); + + + /* ************************************************** * + * Copy the available bytes (or the required bytes) * + * to the target buffer (if one was supplied). * + * ************************************************** */ + + if (data_buffer != NULL) + { + COPY_BYTES(file_ptr->buffer, + file_ptr->buffer_offset, + data_buffer, + data_offset, + buffer_request); + }; + + + /* ************************************************** * + * Now modify the parameters of the buffers by: * + * * + * 1) Adding the size of the request to the file * + * buffer ofset and the data offset (IE: Indices to * + * the file buffer and the read request buffer). * + * * + * 2) Subtracting the request size from the read * + * request size and the remaining number of * + * characters in the file buffer. * + * ************************************************** */ + + file_ptr->buffer_offset = file_ptr->buffer_offset + + buffer_request; + + data_offset = data_offset + buffer_request; + + file_ptr->data_size = data_offset; + + data_size = data_size - buffer_request; + + remaining_space = remaining_space - buffer_request; + }; + + + /* ****************************************************** * + * If isn't anything in the file buffer, the we have to * + * re-fill it. The problem is that the buffer size may * + * have changed due to what our user wants (users are * + * bound to be the end of all computing...). This means * + * that we'll junp through a few hoops if we must change * + * buffer sizes - so expect some weirdness here. * + * ****************************************************** */ + + if (remaining_space == 0) + { + + /* ************************************************** * + * This is the above mentioned weirdness - if the * + * user specified a different size buffer we will * + * no comply with their wishes. * + * ************************************************** */ + + if (file_ptr->buffer_size != KSf_FileBufferSize) + { + KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + KS_MEMORY_ALLOCATE(attrFixed + attrLocked, + KSf_FileBufferSize, + BUFFER_USERID, + file_ptr->buffer_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + file_ptr->buffer = (Byte *) + *(file_ptr->buffer_handle); + + file_ptr->buffer_size = KSf_FileBufferSize; + + file_ptr->buffer_available = KSf_FileBufferSize; + }; + + + /* ************************************************** * + * Issue a Read to the file into our buffer. * + * ************************************************** */ + + KSf_pkts.IO.pCount = 4; + KSf_pkts.IO.refNum = file_ptr->refNum; + KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); + KSf_pkts.IO.requestCount = file_ptr->buffer_size; + + ReadGS(&KSf_pkts.IO); + + + /* ************************************************** * + * Now for the error processing. * + * * + * Any error means we return to our caller. * + * * + * The end of file error (eofEncountered or $4c) is * + * special. At EOF we mark the KS_FILE structure * + * so the next READ call will return EOF right away. * + * We will return SUCCESS in this case because the * + * user will be able to find some data in the input * + * buffer (total amount == ). + * ************************************************** */ + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + if (error == eofEncountered) + { + error = KS_E_SUCCESS; + file_ptr->end_of_file = TRUE; + } + goto EXIT_NOW; + }; + + file_ptr->buffer_available = KSf_pkts.IO.transferCount; + file_ptr->buffer_offset = 0; + + }; /* End if there is no remaining buffer space */ + + }; /* End while there are characters to be read... */ + + KS_SUCCESS(); + + }; /* End if we are doing buffer I/O from the file */ + + + + + /* ************************************************************** * + * Ok, we've done enough buffering... lets do some real input... * + * * + * Position the 'mark' (where we will read from) in the file. * + * Note: We'll move the mark only if our user asks us to. * + * ************************************************************** */ + + if (position != KS_NEXT_FILE_POSITION) + { + KSf_pkts.position.pCount = 3; + KSf_pkts.position.refNum = file_ptr->refNum; + KSf_pkts.position.base = startPlus; + KSf_pkts.position.displacement = position; + + SetMarkGS(&KSf_pkts.position); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + }; /* End if we must change the file position */ + + + /* ************************************************************** * + * Setup the I/O packet and read what our user is asking for. * + * ************************************************************** */ + + KSf_pkts.IO.pCount = 4; + KSf_pkts.IO.refNum = file_ptr->refNum; + KSf_pkts.IO.dataBuffer = data_buffer; + KSf_pkts.IO.requestCount = data_size; + + ReadGS(&KSf_pkts.IO); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + + /* ************************************************************** * + * Save the number of bytes transfered in the KS_FILE structure. * + * ************************************************************** */ + + file_ptr->data_size = KSf_pkts.IO.transferCount; + + + /* ************************************************************** * + * Return the status back to our caller. * + * ************************************************************** */ + +EXIT_NOW: + + if (error != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_read() */ + + diff --git a/sys/fileport/support/Rename.c b/sys/fileport/support/Rename.c index c97519f..4065f0e 100644 --- a/sys/fileport/support/Rename.c +++ b/sys/fileport/support/Rename.c @@ -1 +1,78 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Rename.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Jun 30, 1991 Dave Created this file * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_rename - Change the name of a file (given complete * * pathnames of the source/destination). * * * * History: June 30, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_rename" KS_E_ERROR ks_file_rename(GSString255Ptr old_path, GSString255Ptr new_path) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Fill in the change path packet then issue the system call... * * ************************************************************** */ KSf_pkts.rename.pCount = 2; KSf_pkts.rename.pathname = old_path; KSf_pkts.rename.newPathname = new_path; ChangePathGS(&KSf_pkts.rename); if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; /* ************************************************************** * * Return the success back to our caller. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_rename() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Rename.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Jun 30, 1991 Dave Created this file + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_rename - Change the name of a file (given complete * + * pathnames of the source/destination). * + * * + * History: June 30, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_rename" + +KS_E_ERROR ks_file_rename(GSString255Ptr old_path, + GSString255Ptr new_path) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Fill in the change path packet then issue the system call... * + * ************************************************************** */ + + KSf_pkts.rename.pCount = 2; + KSf_pkts.rename.pathname = old_path; + KSf_pkts.rename.newPathname = new_path; + + ChangePathGS(&KSf_pkts.rename); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Return the success back to our caller. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_rename() */ + + + diff --git a/sys/fileport/support/SetBufSize.c b/sys/fileport/support/SetBufSize.c index be71516..0d21701 100644 --- a/sys/fileport/support/SetBufSize.c +++ b/sys/fileport/support/SetBufSize.c @@ -1 +1,70 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * SetBufSize.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_set_buffer_size - set the specified I/O buffer size. * * * * Note: Any open files that are using buffering will NOT change * * their buffer sizes until they need to do I/O! * * * * History: Mar 3, 1990 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_set_buffer_size" KS_E_ERROR ks_file_set_buffer_size(LongWord buffer_size) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ ROUTINE_ENTER(); /* ************************************************************** * * Set the buffer size back to our caller. * * ************************************************************** */ KSf_FileBufferSize = buffer_size; KS_SUCCESS(); } /* End of ks_file_set_buffer_size() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * SetBufSize.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_set_buffer_size - set the specified I/O buffer size. * + * * + * Note: Any open files that are using buffering will NOT change * + * their buffer sizes until they need to do I/O! * + * * + * History: Mar 3, 1990 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_set_buffer_size" + +KS_E_ERROR ks_file_set_buffer_size(LongWord buffer_size) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Set the buffer size back to our caller. * + * ************************************************************** */ + + KSf_FileBufferSize = buffer_size; + + KS_SUCCESS(); + +} /* End of ks_file_set_buffer_size() */ + + diff --git a/sys/fileport/support/SetDir.c b/sys/fileport/support/SetDir.c index bd8fea5..e52d11a 100644 --- a/sys/fileport/support/SetDir.c +++ b/sys/fileport/support/SetDir.c @@ -1 +1,91 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * SetDir.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_set_directory - Set the current directory (actually, * * prefix 8). * * * * History: Mar 7, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_set_directory" KS_E_ERROR ks_file_set_directory(GSString255Ptr directory_ptr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Setup the packet to set prefix 8 then make the set prefix * * call. * * * * Note: We have to copy the prefix pathname into the buffer * * because of the way the GS/OS packet is set up. * * It would be nice to simply set a pointer... but we * * can't do that. * * ************************************************************** */ KSf_pkts.prefix.pCount = 2; KSf_pkts.prefix.prefixNum = 8; KSf_pkts.prefix.buffer.setPrefix = directory_ptr; SetPrefixGS(&KSf_pkts.prefix); /* ************************************************************** * * Return to our caller. * * ************************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_set_directory() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * SetDir.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_set_directory - Set the current directory (actually, * + * prefix 8). * + * * + * History: Mar 7, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_set_directory" + +KS_E_ERROR ks_file_set_directory(GSString255Ptr directory_ptr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Setup the packet to set prefix 8 then make the set prefix * + * call. * + * * + * Note: We have to copy the prefix pathname into the buffer * + * because of the way the GS/OS packet is set up. * + * It would be nice to simply set a pointer... but we * + * can't do that. * + * ************************************************************** */ + + KSf_pkts.prefix.pCount = 2; + KSf_pkts.prefix.prefixNum = 8; + + KSf_pkts.prefix.buffer.setPrefix = directory_ptr; + + SetPrefixGS(&KSf_pkts.prefix); + + + /* ************************************************************** * + * Return to our caller. * + * ************************************************************** */ + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_set_directory() */ + + diff --git a/sys/fileport/support/SetEOF.c b/sys/fileport/support/SetEOF.c index 649995a..8a009e9 100644 --- a/sys/fileport/support/SetEOF.c +++ b/sys/fileport/support/SetEOF.c @@ -1 +1,86 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * SetEOF.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_set_eof - Set the end of file of an open file * * * * History: May 27, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_set_eof" KS_E_ERROR ks_file_set_eof(KS_FILE_PTR file_ptr, LongWord new_eof) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Setup the packet then make the set EOF call... * * ************************************************************** */ KSf_pkts.position.pCount = 3; KSf_pkts.position.refNum = file_ptr->refNum; KSf_pkts.position.base = startPlus; KSf_pkts.position.displacement = new_eof; SetEOFGS(&KSf_pkts.position); /* ************************************************************** * * Return to our caller. * * ************************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_set_eof() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * SetEOF.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_set_eof - Set the end of file of an open file * + * * + * History: May 27, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_set_eof" + +KS_E_ERROR ks_file_set_eof(KS_FILE_PTR file_ptr, + LongWord new_eof) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Setup the packet then make the set EOF call... * + * ************************************************************** */ + + KSf_pkts.position.pCount = 3; + KSf_pkts.position.refNum = file_ptr->refNum; + KSf_pkts.position.base = startPlus; + KSf_pkts.position.displacement = new_eof; + + SetEOFGS(&KSf_pkts.position); + + + /* ************************************************************** * + * Return to our caller. * + * ************************************************************** */ + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_set_eof() */ + + + diff --git a/sys/fileport/support/Space.c b/sys/fileport/support/Space.c index 9107ca3..5707a37 100644 --- a/sys/fileport/support/Space.c +++ b/sys/fileport/support/Space.c @@ -1 +1,116 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Space.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_get_volume_space - Return the total/unused space of * * the specified volume * * * * History: Mar 13, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_get_volume_space" KS_E_ERROR ks_file_get_volume_space(GSString255Ptr volume_ptr, LongWord *unused_space, LongWord *total_space) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Now lets generate some code that just shouldn't work... * * * * According to all the reference manuals, GetFileInfo does not * * return valid information on volumes or directories. * * * * The means we have to go back to the ProDOS 16 GET_FILE_INFO * * call that does return the volume size and number of allocated * * blocks (even if the manuals seem to disagree with this). * * * * To do a ProDOS 16 call, you have to pass a pascal string... * * which is a length byte followed by the string. Now a GS/OS * * string is a length word followed by the string. We are going * * to cheat once more by making the GS/OS string a Pascal string * * for the duration of this call... * * * * I don't like doing things this way, but the alternative is * * very ugly (start by scanning all devices with DInfo, the * * get the volume name of each disk device, then compare names * * until you find the specified volume, and finally you have * * the information for a Volume call). * * * * We'll cheat now - this may need fixing in the future. * * ************************************************************** */ (((char *) volume_ptr)[1]) = (((char *) volume_ptr)[0]); KSf_pkts.fileinfo.pathname = &(((char *) volume_ptr)[1]); GET_FILE_INFO(&KSf_pkts.fileinfo); (((char *) volume_ptr)[1]) = '\0'; if ((error = GET_ERROR()) != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; *unused_space = (KSf_pkts.fileinfo.auxType - KSf_pkts.fileinfo.blocksUsed) / 2; *total_space = (KSf_pkts.fileinfo.auxType) / 2; /* ************************************************************** * * We'll never reach this part of the code... However, if by * * some cosmic reason we do - let us return a success. * * ************************************************************** */ KS_SUCCESS(); } /* End of ks_file_get_volume_space() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Space.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_get_volume_space - Return the total/unused space of * + * the specified volume * + * * + * History: Mar 13, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_get_volume_space" + +KS_E_ERROR ks_file_get_volume_space(GSString255Ptr volume_ptr, + LongWord *unused_space, + LongWord *total_space) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Now lets generate some code that just shouldn't work... * + * * + * According to all the reference manuals, GetFileInfo does not * + * return valid information on volumes or directories. * + * * + * The means we have to go back to the ProDOS 16 GET_FILE_INFO * + * call that does return the volume size and number of allocated * + * blocks (even if the manuals seem to disagree with this). * + * * + * To do a ProDOS 16 call, you have to pass a pascal string... * + * which is a length byte followed by the string. Now a GS/OS * + * string is a length word followed by the string. We are going * + * to cheat once more by making the GS/OS string a Pascal string * + * for the duration of this call... * + * * + * I don't like doing things this way, but the alternative is * + * very ugly (start by scanning all devices with DInfo, the * + * get the volume name of each disk device, then compare names * + * until you find the specified volume, and finally you have * + * the information for a Volume call). * + * * + * We'll cheat now - this may need fixing in the future. * + * ************************************************************** */ + + (((char *) volume_ptr)[1]) = (((char *) volume_ptr)[0]); + + KSf_pkts.fileinfo.pathname = &(((char *) volume_ptr)[1]); + + GET_FILE_INFO(&KSf_pkts.fileinfo); + + (((char *) volume_ptr)[1]) = '\0'; + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + *unused_space = (KSf_pkts.fileinfo.auxType - + KSf_pkts.fileinfo.blocksUsed) / 2; + + *total_space = (KSf_pkts.fileinfo.auxType) / 2; + + + /* ************************************************************** * + * We'll never reach this part of the code... However, if by * + * some cosmic reason we do - let us return a success. * + * ************************************************************** */ + + KS_SUCCESS(); + +} /* End of ks_file_get_volume_space() */ + + + diff --git a/sys/fileport/support/Write.c b/sys/fileport/support/Write.c index 7f41b1d..ee574d4 100644 --- a/sys/fileport/support/Write.c +++ b/sys/fileport/support/Write.c @@ -1 +1,285 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Write.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_write - Perform an write to an open file (possibly using * * an internal buffer). * * * * History: Feb 27, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_write" KS_E_ERROR ks_file_write(KS_FILE_PTR file_ptr, LongWord position, LongWord data_size, Pointer data_buffer) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutine*/ /* calls */ LongWord data_offset; /* Offset into the buffer to return*/ LongWord remaining_space; /* Space remaining in file buffer */ LongWord buffer_request; /* Size of each copy from the */ /* file buffer */ ROUTINE_ENTER(); /* ************************************************************** * * Verify the structure ID passed in is the correct one. * * ************************************************************** */ if (file_ptr->struct_id != KS_FILE_ID) { KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); }; /* ************************************************************** * * Zero the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = 0; /* ************************************************************** * * If there is a buffer, then lets put data into the file buffer.* * ************************************************************** */ if (file_ptr->buffer_size != NULL) { /* ********************************************************** * * Loop till we satisfy the request (or take an error) * * ********************************************************** */ data_offset = 0; while (data_size > 0) { /* ****************************************************** * * Calculate the remaining space in the buffer. If * * there is any space left in the buffer then lets copy * * as much as we need to into the file buffer. * * ****************************************************** */ remaining_space = (file_ptr->buffer_available) - (file_ptr->buffer_offset); if (remaining_space > 0) { buffer_request = MIN(data_size, remaining_space); COPY_BYTES(data_buffer, data_offset, file_ptr->buffer, file_ptr->buffer_offset, buffer_request); /* ************************************************** * * Now modify the parameters of the buffers by: * * * * 1) Adding the size of the request to the file * * buffer ofset and the data offset (IE: Indices to * * the file buffer and the read request buffer). * * * * 2) Subtracting the request size from the read * * request size and the remaining number of * * characters in the file buffer. * * ************************************************** */ file_ptr->buffer_offset = file_ptr->buffer_offset + buffer_request; data_offset = data_offset + buffer_request; file_ptr->data_size = data_offset; data_size = data_size - buffer_request; remaining_space = remaining_space - buffer_request; }; /* ****************************************************** * * If the file buffer is full, then we have to write it * * to disk. The problem is that the buffer size may * * have changed due to what our user wants (users are * * bound to be the end of all computing...). This means * * that we'll junp through a few hoops if we must change * * buffer sizes - so expect some weirdness here. * * ****************************************************** */ if (remaining_space == 0) { /* ************************************************** * * Issue a Read to the file into our buffer. * * ************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); KSf_pkts.IO.requestCount = file_ptr->buffer_size; WriteGS(&KSf_pkts.IO); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; file_ptr->buffer_available = file_ptr->buffer_size; file_ptr->buffer_offset = 0; /* ************************************************** * * This is the above mentioned weirdness - if the * * user specified a different size buffer we will * * no comply with their wishes. * * ************************************************** */ if (file_ptr->buffer_size != KSf_FileBufferSize) { KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; KS_MEMORY_ALLOCATE(attrFixed + attrLocked, KSf_FileBufferSize, BUFFER_USERID, file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; file_ptr->buffer = (Byte *) *(file_ptr->buffer_handle); file_ptr->buffer_size = KSf_FileBufferSize; file_ptr->buffer_available = KSf_FileBufferSize; }; }; /* End if there is no remaining buffer space */ }; /* End while there are characters to be read... */ KS_SUCCESS(); }; /* End if we are doing buffer I/O from the file */ /* ************************************************************** * * Ok, we've done enough buffering... lets do some real output...* * * * Position the 'mark' (where we will write to) in the file. * * Note: We'll move the mark only if our user asks us to. * * ************************************************************** */ if (position != KS_NEXT_FILE_POSITION) { KSf_pkts.position.pCount = 3; KSf_pkts.position.refNum = file_ptr->refNum; KSf_pkts.position.base = startPlus; KSf_pkts.position.displacement = position; SetMarkGS(&KSf_pkts.position); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; }; /* End if we must change the file position */ /* ************************************************************** * * Setup the I/O packet and write what our user is asking for. * * ************************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = data_buffer; KSf_pkts.IO.requestCount = data_size; WriteGS(&KSf_pkts.IO); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; /* ************************************************************** * * Save the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = KSf_pkts.IO.transferCount; /* ************************************************************** * * Return the status back to our caller. * * ************************************************************** */ EXIT_NOW: if (error != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_write() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Write.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_write - Perform an write to an open file (possibly using * + * an internal buffer). * + * * + * History: Feb 27, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_write" + +KS_E_ERROR ks_file_write(KS_FILE_PTR file_ptr, + LongWord position, + LongWord data_size, + Pointer data_buffer) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutine*/ + /* calls */ + LongWord data_offset; /* Offset into the buffer to return*/ + LongWord remaining_space; /* Space remaining in file buffer */ + LongWord buffer_request; /* Size of each copy from the */ + /* file buffer */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Verify the structure ID passed in is the correct one. * + * ************************************************************** */ + + if (file_ptr->struct_id != KS_FILE_ID) + { + KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); + }; + + + /* ************************************************************** * + * Zero the number of bytes transfered in the KS_FILE structure. * + * ************************************************************** */ + + file_ptr->data_size = 0; + + + /* ************************************************************** * + * If there is a buffer, then lets put data into the file buffer.* + * ************************************************************** */ + + if (file_ptr->buffer_size != NULL) + { + + /* ********************************************************** * + * Loop till we satisfy the request (or take an error) * + * ********************************************************** */ + + data_offset = 0; + + while (data_size > 0) + { + + /* ****************************************************** * + * Calculate the remaining space in the buffer. If * + * there is any space left in the buffer then lets copy * + * as much as we need to into the file buffer. * + * ****************************************************** */ + + remaining_space = (file_ptr->buffer_available) - + (file_ptr->buffer_offset); + + if (remaining_space > 0) + { + buffer_request = MIN(data_size, + remaining_space); + + COPY_BYTES(data_buffer, + data_offset, + file_ptr->buffer, + file_ptr->buffer_offset, + buffer_request); + + /* ************************************************** * + * Now modify the parameters of the buffers by: * + * * + * 1) Adding the size of the request to the file * + * buffer ofset and the data offset (IE: Indices to * + * the file buffer and the read request buffer). * + * * + * 2) Subtracting the request size from the read * + * request size and the remaining number of * + * characters in the file buffer. * + * ************************************************** */ + + file_ptr->buffer_offset = file_ptr->buffer_offset + + buffer_request; + + data_offset = data_offset + buffer_request; + + file_ptr->data_size = data_offset; + + data_size = data_size - buffer_request; + + remaining_space = remaining_space - buffer_request; + }; + + + /* ****************************************************** * + * If the file buffer is full, then we have to write it * + * to disk. The problem is that the buffer size may * + * have changed due to what our user wants (users are * + * bound to be the end of all computing...). This means * + * that we'll junp through a few hoops if we must change * + * buffer sizes - so expect some weirdness here. * + * ****************************************************** */ + + if (remaining_space == 0) + { + + /* ************************************************** * + * Issue a Read to the file into our buffer. * + * ************************************************** */ + + KSf_pkts.IO.pCount = 4; + KSf_pkts.IO.refNum = file_ptr->refNum; + KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); + KSf_pkts.IO.requestCount = file_ptr->buffer_size; + + WriteGS(&KSf_pkts.IO); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + file_ptr->buffer_available = file_ptr->buffer_size; + file_ptr->buffer_offset = 0; + + + /* ************************************************** * + * This is the above mentioned weirdness - if the * + * user specified a different size buffer we will * + * no comply with their wishes. * + * ************************************************** */ + + if (file_ptr->buffer_size != KSf_FileBufferSize) + { + KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + KS_MEMORY_ALLOCATE(attrFixed + attrLocked, + KSf_FileBufferSize, + BUFFER_USERID, + file_ptr->buffer_handle, + error); + + if (error != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + file_ptr->buffer = (Byte *) + *(file_ptr->buffer_handle); + + file_ptr->buffer_size = KSf_FileBufferSize; + + file_ptr->buffer_available = KSf_FileBufferSize; + }; + + }; /* End if there is no remaining buffer space */ + + }; /* End while there are characters to be read... */ + + KS_SUCCESS(); + + }; /* End if we are doing buffer I/O from the file */ + + + + + /* ************************************************************** * + * Ok, we've done enough buffering... lets do some real output...* + * * + * Position the 'mark' (where we will write to) in the file. * + * Note: We'll move the mark only if our user asks us to. * + * ************************************************************** */ + + if (position != KS_NEXT_FILE_POSITION) + { + KSf_pkts.position.pCount = 3; + KSf_pkts.position.refNum = file_ptr->refNum; + KSf_pkts.position.base = startPlus; + KSf_pkts.position.displacement = position; + + SetMarkGS(&KSf_pkts.position); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + }; /* End if we must change the file position */ + + + /* ************************************************************** * + * Setup the I/O packet and write what our user is asking for. * + * ************************************************************** */ + + KSf_pkts.IO.pCount = 4; + KSf_pkts.IO.refNum = file_ptr->refNum; + KSf_pkts.IO.dataBuffer = data_buffer; + KSf_pkts.IO.requestCount = data_size; + + WriteGS(&KSf_pkts.IO); + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + goto EXIT_NOW; + }; + + + /* ************************************************************** * + * Save the number of bytes transfered in the KS_FILE structure. * + * ************************************************************** */ + + file_ptr->data_size = KSf_pkts.IO.transferCount; + + + /* ************************************************************** * + * Return the status back to our caller. * + * ************************************************************** */ + +EXIT_NOW: + + if (error != KS_E_SUCCESS) + { + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_write() */ diff --git a/sys/fileport/support/gnfn.c b/sys/fileport/support/gnfn.c index 5ad15cb..a5fdd08 100644 --- a/sys/fileport/support/gnfn.c +++ b/sys/fileport/support/gnfn.c @@ -1 +1,105 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * Gnfn.CC * * Description: * This module exists to abstract the data of the file I/O * primitives of GS/OS. * * * History:Oct 13, 1990 Dave Created this file * * Feb 25, 1991 Dave Added I/O buffering * * May 26, 1991 Dave Added set EOF * * Jun 07, 1991 Dave Broke the single source into lots * of small sources so we can build * a library to use... * */ /* * define DEBUG_CODE * - add # to define to create the local * debug code (IE:module) */ #ifndef _KS_FILEIO_ #include "ks.fileio.h" #endif #pragma noroot /* ****************************************************************** * * ks_file_get_next_file - Return the next filename in a directory. * * * * History: Mar 5, 1991 Dave Created this routine * * ****************************************************************** */ #undef ROUTINE_NAME #define ROUTINE_NAME "ks_file_get_next_file" KS_E_ERROR ks_file_get_next_file(KS_FILE_PTR file_ptr, DirEntryRecPtrGS dir_entry_ptr) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutines */ ROUTINE_ENTER(); /* ************************************************************** * * Set the parameters up and get the next directory entry. * * * * If we are at the end of the directory, then we have to do a * * special call to get the first entry - the open code will set * * the flag making it look like we're at the end of the directory* * for our first call. * * ************************************************************** */ dir_entry_ptr->pCount = 13; dir_entry_ptr->refNum = file_ptr->refNum; if (file_ptr->end_of_dir == TRUE) { dir_entry_ptr->base = 0; dir_entry_ptr->displacement = 0; file_ptr->end_of_dir = FALSE; } else { dir_entry_ptr->base = 1; dir_entry_ptr->displacement = 1; }; GetDirEntryGS(dir_entry_ptr); /* ************************************************************** * * Now check for errors. If we are at the end of the directory * * then send the end of directory flag. * * * * The last thing to do is to return to our caller. * * ************************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { if (error == endOfDir) { file_ptr->end_of_dir = TRUE; }; KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_get_next_file() */ \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * Gnfn.CC + * + * Description: + * This module exists to abstract the data of the file I/O + * primitives of GS/OS. + * + * + * History:Oct 13, 1990 Dave Created this file + * + * Feb 25, 1991 Dave Added I/O buffering + * + * May 26, 1991 Dave Added set EOF + * + * Jun 07, 1991 Dave Broke the single source into lots + * of small sources so we can build + * a library to use... + * + */ + +/* + * define DEBUG_CODE + * - add # to define to create the local + * debug code (IE:module) + */ + +#ifndef _KS_FILEIO_ +#include "ks.fileio.h" +#endif + +#pragma noroot + + +/* ****************************************************************** * + * ks_file_get_next_file - Return the next filename in a directory. * + * * + * History: Mar 5, 1991 Dave Created this routine * + * ****************************************************************** */ + +#undef ROUTINE_NAME +#define ROUTINE_NAME "ks_file_get_next_file" + +KS_E_ERROR ks_file_get_next_file(KS_FILE_PTR file_ptr, + DirEntryRecPtrGS dir_entry_ptr) +{ + /* ************************************************************** * + * Local declarations: * + * ************************************************************** */ + + KS_E_ERROR error; /* Holds error codes for subroutines */ + + + ROUTINE_ENTER(); + + + /* ************************************************************** * + * Set the parameters up and get the next directory entry. * + * * + * If we are at the end of the directory, then we have to do a * + * special call to get the first entry - the open code will set * + * the flag making it look like we're at the end of the directory* + * for our first call. * + * ************************************************************** */ + + dir_entry_ptr->pCount = 13; + dir_entry_ptr->refNum = file_ptr->refNum; + if (file_ptr->end_of_dir == TRUE) + { + dir_entry_ptr->base = 0; + dir_entry_ptr->displacement = 0; + file_ptr->end_of_dir = FALSE; + } + else + { + dir_entry_ptr->base = 1; + dir_entry_ptr->displacement = 1; + }; + + GetDirEntryGS(dir_entry_ptr); + + + /* ************************************************************** * + * Now check for errors. If we are at the end of the directory * + * then send the end of directory flag. * + * * + * The last thing to do is to return to our caller. * + * ************************************************************** */ + + if ((error = GET_ERROR()) != KS_E_SUCCESS) + { + if (error == endOfDir) + { + file_ptr->end_of_dir = TRUE; + }; + + KS_ERROR(error, KS_FILE_ID); + }; + + KS_SUCCESS(); + +} /* End of ks_file_get_next_file() */ diff --git a/sys/fileport/support/ks.fileIO.h b/sys/fileport/support/ks.fileIO.h index 947d621..752c5e8 100644 --- a/sys/fileport/support/ks.fileIO.h +++ b/sys/fileport/support/ks.fileIO.h @@ -1 +1,130 @@ - /* * Copyright (c) Kopriha Software, 1990-1991 * All Rights Reserved * * ks.fileio.h * * Description: This include file contains all the generic file * support macros from Kopriha Software. * * * Table of contents: * * External Data Structures: * * Notes: * * History:Oct 13, 1990 Dave Created this file for basic * I/O (read/write) * * Feb 25, 1991 Dave Added buffer enhancements/create. * * Mar 5, 1991 Dave Added directory, file, path and * volume calls * * Mar 24, 1991 Dave Added delete and change aux type * */ #ifndef _KS_FILEIO_H_ #define _KS_FILEIO_H_ #ifndef _KS_FILEIO_E_ #include "ks.fileio.e" #endif #ifndef __GSOS__ #include #endif #ifndef __PRODOS__ #include #endif #ifndef __MEMORY__ #include #endif #ifndef _KS_MEMORY_ #include "ks.memory.h" #endif /* * Define all the external data referenced in this module: * * Note: The routines in this module minimize stack space usage, * which is why all the structures are external... */ /* ****************************************************************** * * KSf_Pkts - This is a union of all the GS/OS packets that are * * used by this module. Since multitasking isn't * * supported on a IIGS, we won't worry about needing * * seperate unions for each task (which is how we will * * solve this problem when multitasking does become * * available). * * * * Note: fileinfo is a ProDOS 16 structure - this is because GS/OS * * does not provide an easy method to determine the amount of * * space used on a volume. * * ****************************************************************** */ #ifdef FILEIO_DATA #ifdef EXTERNAL #undef EXTERNAL #define EXTERNAL #endif #endif #ifndef EXTERNAL #define EXTERNAL extern #endif EXTERNAL union { CreateRecGS create; OpenRecGS open; IORecGS IO; RefNumRecGS close; SetPositionRecGS position; PrefixRecGS prefix; FileRec fileinfo; FileInfoRecGS delete; FileInfoRecGS fileinfoGSOS; ChangePathRecGS rename; } KSf_pkts; /* ****************************************************************** * * KSf_pkts2 - This is the second unionized set of GS/OS packets. * * The reason for these packets is that the first packets* * sometimes have option fields that these packets must * * be used to fill in. * * * * optionList - this is the File System Translator specific * * area returned on the Open call. We don't do * * anything with this data. * * * * ****************************************************************** */ EXTERNAL union { Word optionList[20]; } KSf_pkts2; /* ****************************************************************** * * KSf_FileBufferSize - the specified size of the file buffers * * ****************************************************************** */ EXTERNAL Long KSf_FileBufferSize; #ifdef FILEIO_DATA #undef EXTERNAL #define EXTERNAL extern #endif #endif \ No newline at end of file + +/* + * Copyright (c) Kopriha Software, 1990-1991 + * All Rights Reserved + * + * ks.fileio.h + * + * Description: This include file contains all the generic file + * support macros from Kopriha Software. + * + * + * Table of contents: + * + * External Data Structures: + * + * Notes: + * + * History:Oct 13, 1990 Dave Created this file for basic + * I/O (read/write) + * + * Feb 25, 1991 Dave Added buffer enhancements/create. + * + * Mar 5, 1991 Dave Added directory, file, path and + * volume calls + * + * Mar 24, 1991 Dave Added delete and change aux type + * + */ + +#ifndef _KS_FILEIO_H_ +#define _KS_FILEIO_H_ + +#ifndef _KS_FILEIO_E_ +#include "ks.fileio.e" +#endif + +#ifndef __GSOS__ +#include +#endif + +#ifndef __PRODOS__ +#include +#endif + +#ifndef __MEMORY__ +#include +#endif + +#ifndef _KS_MEMORY_ +#include "ks.memory.h" +#endif + + +/* + * Define all the external data referenced in this module: + * + * Note: The routines in this module minimize stack space usage, + * which is why all the structures are external... + */ + +/* ****************************************************************** * + * KSf_Pkts - This is a union of all the GS/OS packets that are * + * used by this module. Since multitasking isn't * + * supported on a IIGS, we won't worry about needing * + * seperate unions for each task (which is how we will * + * solve this problem when multitasking does become * + * available). * + * * + * Note: fileinfo is a ProDOS 16 structure - this is because GS/OS * + * does not provide an easy method to determine the amount of * + * space used on a volume. * + * ****************************************************************** */ + +#ifdef FILEIO_DATA +#ifdef EXTERNAL +#undef EXTERNAL +#define EXTERNAL +#endif +#endif + +#ifndef EXTERNAL +#define EXTERNAL extern +#endif + +EXTERNAL union + { + CreateRecGS create; + OpenRecGS open; + IORecGS IO; + RefNumRecGS close; + SetPositionRecGS position; + PrefixRecGS prefix; + FileRec fileinfo; + FileInfoRecGS delete; + FileInfoRecGS fileinfoGSOS; + ChangePathRecGS rename; + } KSf_pkts; + + +/* ****************************************************************** * + * KSf_pkts2 - This is the second unionized set of GS/OS packets. * + * The reason for these packets is that the first packets* + * sometimes have option fields that these packets must * + * be used to fill in. * + * * + * optionList - this is the File System Translator specific * + * area returned on the Open call. We don't do * + * anything with this data. * + * * + * ****************************************************************** */ + +EXTERNAL union + { + Word optionList[20]; + } KSf_pkts2; + + +/* ****************************************************************** * + * KSf_FileBufferSize - the specified size of the file buffers * + * ****************************************************************** */ + +EXTERNAL Long KSf_FileBufferSize; + + +#ifdef FILEIO_DATA +#undef EXTERNAL +#define EXTERNAL extern +#endif + +#endif diff --git a/sys/fileport/support/linkit b/sys/fileport/support/linkit index 08a8ab7..309830a 100644 --- a/sys/fileport/support/linkit +++ b/sys/fileport/support/linkit @@ -1 +1,20 @@ -# # --- Link Script --- # # Build the Support library echo echo Putting objects into the Support.LB echo rm -f Support.LB makelib Support.LB +Objects/Close.A +Objects/ChangeAux.A makelib Support.LB +Objects/Create.A +Objects/Delete.A +Objects/GetBufSize.A makelib Support.LB +Objects/Gnfn.A +Objects/GetVolume.A +Objects/Space.A makelib Support.LB +Objects/Open.A +Objects/AddPath.A +Objects/Read.A makelib Support.LB +Objects/SetBufSize.A +Objects/SetDir.A +Objects/SetEOF.A makelib Support.LB +Objects/Write.A +Objects/Rename.A +Objects/Data.A makelib Support.LB +Objects/MSGSend.A +Objects/MSGReceive.A \ No newline at end of file +# +# --- Link Script --- +# + +# Build the Support library + +echo +echo Putting objects into the Support.LB +echo + +rm -f Support.LB + +makelib Support.LB +Objects/Close.A +Objects/ChangeAux.A +makelib Support.LB +Objects/Create.A +Objects/Delete.A +Objects/GetBufSize.A +makelib Support.LB +Objects/Gnfn.A +Objects/GetVolume.A +Objects/Space.A +makelib Support.LB +Objects/Open.A +Objects/AddPath.A +Objects/Read.A +makelib Support.LB +Objects/SetBufSize.A +Objects/SetDir.A +Objects/SetEOF.A +makelib Support.LB +Objects/Write.A +Objects/Rename.A +Objects/Data.A + +makelib Support.LB +Objects/MSGSend.A +Objects/MSGReceive.A