]> pd.if.org Git - pdclib/commitdiff
Minor cleanups.
authorsolar <unknown>
Fri, 14 Sep 2007 03:48:22 +0000 (03:48 +0000)
committersolar <unknown>
Fri, 14 Sep 2007 03:48:22 +0000 (03:48 +0000)
Notes.txt
Readme.txt
functions/_PDCLIB/print.c
internals/_PDCLIB_int.h
platform/example/functions/_PDCLIB/stdinit.c
platform/example/functions/stdlib/getenv.c
platform/example/internals/_PDCLIB_config.h

index f2fd90a80e3190e8fdd08ebf6bded1544ff29d35..a5ec9d29ac9ebd4bac975745960ec9a09235155d 100644 (file)
--- a/Notes.txt
+++ b/Notes.txt
@@ -21,12 +21,12 @@ would not have been able to create PDCLib at this quality, thanks.
 Paul Bourke (author of mathlib), for allowing me access to a complete math
 library under public domain terms so I could use it as a reference, thanks.
 
-Peter ("Candy") Bindels (netizen of mega-tokyo.com), who located a copy of Cody
+Peter ("Candy") Bindels (netizen of osdev.org), who located a copy of Cody
 & Waite's "Software Manual for the Elementary Functions" for me and saved me
 serious cash in the process, thanks.
 
-Michael Moody, who contributed the generic implementation for <stdarg.h> which
-can now be found in <_PDCLIB_config.h> to the Public Domain, thanks.
+Michael Moody, who contributed the generic implementation for <stdarg.h> to
+the Public Domain which can now be found in <_PDCLIB_config.h>, thanks.
 
 Rod Pemberton, for pointing out several flaws in early versions of PDCLib and
 giving other valuable hints, thanks.
@@ -34,12 +34,16 @@ giving other valuable hints, thanks.
 Everyone involved in the first, "public" attempt at PDCLib, for bearing with me
 when I restarted from scratch, thanks.
 
+Everyone bearing with me during the "stdio block", a period of many months in
+which PDCLib received not a single update because I was stuck and could not
+find the energy to work it out.
+
 Lennart Fridén and Sammy Nordström, who have been great pals even after I sunk
 some other project that had eaten countless hours of work between the three of
 us, thanks.
 
-My wife and daughter, for sharing husband and daddy with this strange machine,
-thanks.
+My wife, daughter, and son for sharing husband and daddy with this strange
+machine, thanks.
 
 
 Style
@@ -58,9 +62,10 @@ obsessive when it comes to coding style. ;-)
   header guards defined in the *including* file, for a tiny bit of performance.
 
 - I always try to minimize the use of local variables. Wherever possible I used
-  the parameters directly, and deferred declaration of locals to the innermost
-  block of statements, in hopes that it might reduce memory footprint when the
-  library is compiled with a compiler that is not that great at optimization.
+  parameters passed by-value directly, and deferred declaration of locals to the
+  innermost block of statements, in hopes that it might reduce memory footprint
+  when the library is compiled with a compiler that is not that great at
+  optimization.
 
 - every function, every static data item that could possibly be shared, got its
   own implementation file. This means the library itself is probably larger than
@@ -96,3 +101,4 @@ obsessive when it comes to coding style. ;-)
   hopefully keeping overly ambitious editors from repeating my mistakes. The
   header files especially should be self-documenting to the point of being a
   suitable replacement for any library reference book you might be using.
+
index 51d9875f5d4358e420b22f6bab7477064874d7f0..3bae131be9255daf3b068e50cc82cd58c96f0793 100644 (file)
@@ -12,6 +12,8 @@ This includes removing authorship notices, re-use of code parts in
 other software (with or without giving credit), and / or creating a
 commercial product based on it.
 
+This permission is not revocable by the author.
+
 This software is provided as-is. Use it at your own risk. There is
 no warranty whatsoever, neither expressed nor implied, and by using
 this software you accept that the author(s) shall not be held liable
@@ -40,6 +42,10 @@ Sick and tired of it, the author brought you this piece of software
 under a "license" that should not be neccessary in the first place:
 "Free" should have been enough.
 
+Unfortunately, German law does not even *allow* to declare a work to
+be "in the Public Domain", so the "free for all" license I intended
+had to be made expressively.
+
 What is it
 ----------
 
@@ -53,11 +59,11 @@ Internals
 ---------
 
 As a namespace convention, everything (files, typedefs, functions,
-macros) not defined in ISO/IEC 9899 is prefixed with _PDCLIB_*.
+macros) not defined in ISO/IEC 9899 is prefixed with _PDCLIB.
 The standard defines any identifiers starting with '_' and a capital
 letter as reserved for the implementation, and since the chances of
-your compiler using an identifier in the _PDCLIB_* range are slim,
-any strictly conforming application should work with PDCLib.
+your compiler using an identifier in the _PDCLIB range are slim,
+any strictly conforming application should work with this library.
 
 PDCLib consists of several parts:
 
@@ -91,16 +97,16 @@ functions that are not part of the standard.)
 Then there are internal header files (in ./internal/), which contain
 all the "black magic" and "code fu" that was kept out of the standard
 headers. You should not have to touch them if you want to adapt PDCLib
-to a new platform. If you *do* have to touch them, note that the PDCLib
-author would consider it a serious design flaw, and would be happy to
-fix it in the next PDCLib release. Any adaption work should be covered
-by the steps detailed below.
+to a new platform. Note that, if you *do* have to touch them, I would
+consider it a serious design flaw, and would be happy to fix it in the
+next PDCLib release. Any adaption work should be covered by the steps
+detailed below.
 
 For adapting PDCLib to a new platform (the trinity of CPU, operating
-system, and compiler), make a copy of the ./platform/example/ directory
-(named after your target platform), and modify the files of your copy
-to suit the constraints of your platform. When you are done, copy the
-contents of your platform directory over the source directory structure
+system, and compiler), make a copy of ./platform/example/ named
+./platform/{your_platform}/, and modify the files of your copy to suit
+the constraints of your platform. When you are done, copy the contents
+of your platform directory over the source directory structure
 of PDCLib (or link them into the appropriate places). That should be
 all that is actually required to make PDCLib work for your platform.
 
@@ -114,19 +120,19 @@ this, you might want to create an "optimization overlay" for PDCLib.
 Optimization Overlay
 --------------------
 
-The idea is to provide a generic implementation that is useable even
-on platforms the author never heard of - for example, the OS and/or
-compiler *you* just wrote and now need a C library for. That is
-actually what PDCLib was written for: To provide a C library for
+The basic idea of PDCLib is to provide a generic implementation that
+is useable even on platforms I have never heard of - for example, the
+OS and/or compiler *you* just wrote and now need a C library for. That
+is actually what PDCLib was written for: To provide a C library for
 compiler and OS builders that do not want the usual baggage of POSIX
 and GNU extensions, licensing considerations etc. etc.
 
 Thus, PDCLib provides generic implementations. They do work, and do
 so correctly, but they are not very efficient when compared to hand-
-crafted assembler or compiler build-ins. So the author wanted to
-provide a means to modify PDCLib to run more efficiently on a given
-platform, without cluttering the main branch with tons of #ifdef
-statements and "featureset #defines" that grow stale quickly.
+crafted assembler or compiler build-ins. So I wanted to provide a
+means to modify PDCLib to run more efficiently on a given platform,
+without cluttering the main branch with tons of #ifdef statements and
+"featureset #defines" that grow stale quickly.
 
 The solution is the "optimization overlay". Every function has its
 own implementation file, which makes it possible to replace them
@@ -170,3 +176,4 @@ support. Enabled all GCC compiler warnings I could find, and fixed
 everything that threw a warning. (You see this, maintainers of Open
 Source software? No warnings whatsoever. Stop telling me it cannot
 be done.) Fixed all known bugs in the v0.4 release.
+
index ddb6b99fc979d30a7847c8499b7c2fa25e8bdb9a..d47a48d977f18e78e76dbc2c3712100f6ecfec8b 100644 (file)
    n - pointer to maximum number of characters to be delivered in this call
    s - the buffer into which the character shall be delivered
 */
-#define DELIVER( x ) do { if ( status->i < status->n ) { if ( status->stream != NULL ) { status->stream->buffer[status->stream->bufidx++] = x; if ( ( status->stream->bufidx == status->stream->bufsize ) || ( ( status->stream->status & _IOLBF ) && ( x == '\n' ) ) || ( status->stream->status & _IONBF ) ) fflush( status->stream ); } else status->s[status->i] = x; } ++(status->i); } while ( 0 )
+#define DELIVER( x ) \
+do { \
+    if ( status->i < status->n ) { \
+        if ( status->stream != NULL ) { \
+            status->stream->buffer[status->stream->bufidx++] = x; \
+            if ( ( status->stream->bufidx == status->stream->bufsize ) \
+              || ( ( status->stream->status & _IOLBF ) && ( x == '\n' ) ) \
+              || ( status->stream->status & _IONBF ) ) \
+                fflush( status->stream ); \
+        } else \
+            status->s[status->i] = x; \
+    } \
+    ++(status->i); \
+} while ( 0 )
 
 /* This function recursively converts a given integer value to a character
    stream. The conversion is done under the control of a given status struct
index d84cc69d6b011234c011856c08186d11fcdcc942..5d503ccc120ea7152a8895b3ca5f17eac94ea706 100644 (file)
@@ -270,9 +270,9 @@ struct _PDCLIB_file_t
     _PDCLIB_fpos_t          position; /* file position indicator */
     char *                  buffer;   /* file buffer */
     _PDCLIB_size_t          bufsize;  /* size of buffer */
-    _PDCLIB_size_t          bufidx;   /* pointer into buffer */
+    _PDCLIB_size_t          bufidx;   /* index to point of action in buffer */
+    _PDCLIB_size_t          bufend;   /* index to end of pre-read buffer */
     unsigned int            status;   /* misc. status bits */
-  /*mbstate_t               mbstate;    multibyte parse state - TODO: Unmask. */
     struct _PDCLIB_file_t * next;     /* provisions for linked list handling */
 };
 
index 160dac3440412b9d84a31b1b89c5280ec7ff05c4..b1990433ae100a182d05713764232c63445fde11 100644 (file)
@@ -24,9 +24,9 @@ static char _PDCLIB_sout_buffer[BUFSIZ];
 static char _PDCLIB_serr_buffer[BUFSIZ];
 
 /* FIXME: serr should handle one character. Buffering on out / in? */
-static struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0 }, _PDCLIB_serr_buffer, BUFSIZ, 0, _IONBF, /* mbstate, */ NULL };
-static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0 }, _PDCLIB_sout_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_serr };
-static struct _PDCLIB_file_t _PDCLIB_sin  = { 0, { 0 }, _PDCLIB_sin_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_sout };
+static struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0, 0 }, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, _IONBF, NULL };
+static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0, 0 }, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, _IOLBF, &_PDCLIB_serr };
+static struct _PDCLIB_file_t _PDCLIB_sin  = { 0, { 0, 0 }, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, _IOLBF, &_PDCLIB_sout };
 
 struct _PDCLIB_file_t * stdin  = &_PDCLIB_sin;
 struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
index 2a8b63466d913cac629e4e36c30919d33ce827b9..4eb70102e54614867676813e30ba6a4d8ec18184 100644 (file)
@@ -38,7 +38,8 @@ char * getenv( const char * name )
 
 int main( void )
 {
-    TESTCASE( strcmp( getenv( "SHELL" ), "/bin/sh" ) == 0 );
+    TESTCASE( strcmp( getenv( "SHELL" ), "/bin/bash" ) == 0 );
+    /* TESTCASE( strcmp( getenv( "SHELL" ), "/bin/sh" ) == 0 ); */
     return TEST_RESULTS;
 }
 
index 5c7210ad763c693b47cb0d8d693f2cf370eadb0c..c807a1bc0fdd41fcee5c7ffc5a25e2da3b0e87cf 100644 (file)
@@ -235,10 +235,12 @@ typedef int _PDCLIB_fd_t;
 #define _PDCLIB_NOHANDLE -1
 
 /* A type in which to store file offsets. See fgetpos() / fsetpos(). */
+/* FIXME: The 'int' types here are placeholders. When changed, check out
+   stdinit.c, too. */
 typedef struct
 {
     int position;
-    int parse_state;
+    int mbstate;
 } _PDCLIB_fpos_t;
 
 /* The default size for file buffers. Must be at least 256. */