]> pd.if.org Git - pdclib/commitdiff
Intermediate work while migrating CVS -> SVN.
authorsolar <unknown>
Fri, 12 May 2006 14:42:11 +0000 (14:42 +0000)
committersolar <unknown>
Fri, 12 May 2006 14:42:11 +0000 (14:42 +0000)
Makefile
functions/_PDCLIB/print.c
functions/stdio/fopen.c
internals/_PDCLIB_int.h

index 81a353ba0e56d1c42b59ad09eb0c4afbdcddc8af..9aa1c89eb3128824eaa3746c540ff256fbc89ec3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ AUXFILES := Makefile Readme.txt
 PROJDIRS := functions includes internals
 SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c")
 HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h")
-INTFILES := atomax digits lengthmods seed strtox_main strtox_prelim rename remove _Exit
+INTFILES := _Exit atomax digits lengthmods print rename remove seed strtox_main strtox_prelim
 OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
 TSTFILES := $(patsubst %.c,%.t,$(SRCFILES))
 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%.r,$(INTFILES)),$(patsubst %.c,%.r,$(SRCFILES)))
index b0c3341d8dfc6dbbc923293054da65e39bbb9053..986ab43cab2edba91b7fcef8b2779fb9e5bd9790 100644 (file)
@@ -462,3 +462,14 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
     }
     return ++spec;
 }
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
+}
+
+#endif
index 244549c7e8d344e74b81e57f10f836b128b8facc..f11094416066ed91a9f6bb6d358b4dcebea981c9 100644 (file)
 
 static FILE * _PDCLIB_filelist = NULL;
 
-static int filemode( char const * const mode )
+/* Helper function that parses the C-style mode string passed to fopen() into
+   the PDCLib flags.FREAD, FWRITE, FAPPEND, FRW (read-write) and FBIN (
+   mode).
+*/
+static unsigned int filemode( char const * const mode )
 {
     int rc = 0;
     switch ( mode[0] )
@@ -29,27 +33,31 @@ static int filemode( char const * const mode )
             rc |= _PDCLIB_FAPPEND;
             break;
         default:
-            return -1;
+            /* Other than read, write, or append - invalid */
+            return 0;
     }
     for ( size_t i = 1; i < 4; ++i )
     {
         switch ( mode[1] )
         {
             case '+':
-                if ( rc & _PDCLIB_FRW ) return -1;
+                if ( rc & _PDCLIB_FRW ) return 0; /* Duplicates are invalid */
                 rc |= _PDCLIB_FRW;
                 break;
             case 'b':
-                if ( rc & _PDCLIB_FBIN ) return -1;
+                if ( rc & _PDCLIB_FBIN ) return 0; /* Duplicates are invalid */
                 rc |= _PDCLIB_FBIN;
                 break;
             case '\0':
+                /* End of mode */
                 return rc;
             default:
-                return -1;
+                /* Other than read/write or binary - invalid. */
+                return 0;
         }
     }
-    return -1;
+    /* Longer than three chars - invalid. */
+    return 0;
 }
 
 FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode )
@@ -57,14 +65,24 @@ FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restr
     FILE * rc;
     if ( mode == NULL || filename == NULL || filename[0] == '\0' )
     {
+        /* Mode or filename invalid */
         return NULL;
     }
-    if ( ( rc = calloc( 1, sizeof( FILE ) ) ) == NULL ) return rc; /* no space for another FILE */
-    if ( ( rc->status = filemode( mode ) ) == -1 ) goto fail; /* invalid mode given */
-    if ( ( rc->handle = _PDCLIB_open( filename, rc->status ) ) == -1 ) goto fail; /* OS "open" failed */
+    if ( ( rc = calloc( 1, sizeof( FILE ) ) ) == NULL )
+    {
+        /* no memory for another FILE */
+        return NULL;
+    }
+    if ( ( rc->status = filemode( mode ) ) == 0 ) goto fail; /* invalid mode */
+    rc->handle = _PDCLIB_open( filename, rc->status );
+    if ( rc->handle == _PDCLIB_NOHANDLE ) goto fail; /* OS open() failed */
+
+    /* Adding to list of open files */
     rc->next = _PDCLIB_filelist;
     _PDCLIB_filelist = rc;
-    /* TODO: Continue here: Set up PDCLib FILE contents */
+    /* Setting buffer. TODO: Check for unbuffered? */
+    if ( ( rc->buffer = malloc( BUFSIZ ) ) == NULL goto fail;
+    /* TODO: Setting mbstate */
     return rc;
 fail:
     free( rc );
index faac079c3f54dd559eea5b7b28d5b5495f625111..ab35e199526d89d624d9594c1c958fceca75a8bc 100644 (file)
@@ -267,7 +267,7 @@ struct _PDCLIB_file_t
     _PDCLIB_fpos_t          position; /* file position indicator */
     void *                  buffer;   /* file buffer */
     _PDCLIB_size_t          bufsize;  /* size of buffer */
-    int                     status;   /* misc. status bits */
+    unsigned int            status;   /* misc. status bits */
   /*mbstate_t               mbstate;    multibyte parse state - TODO: Unmask. */
     struct _PDCLIB_file_t * next;     /* provisions for linked list handling */
 };