relicense to 0BSD
[pforth] / csrc / pf_save.c
index 2baf297..60eb9a1 100644 (file)
@@ -9,14 +9,17 @@
 ** Author: Phil Burk
 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
 **
 ** Author: Phil Burk
 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
 **
-** The pForth software code is dedicated to the public domain,
-** and any third party may reproduce, distribute and modify
-** the pForth software code or any derivative works thereof
-** without any compensation or license.  The pForth software
-** code is provided on an "as is" basis without any warranty
-** of any kind, including, without limitation, the implied
-** warranties of merchantability and fitness for a particular
-** purpose and their equivalents under the laws of any jurisdiction.
+** Permission to use, copy, modify, and/or distribute this
+** software for any purpose with or without fee is hereby granted.
+**
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 **
 ****************************************************************
 ** 940225 PLB Fixed CodePtr save, was using NAMEREL instead of CODEREL
 **
 ****************************************************************
 ** 940225 PLB Fixed CodePtr save, was using NAMEREL instead of CODEREL
@@ -315,7 +318,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
 /***************************************************************/
 static int Write32ToFile( FileStream *fid, uint32_t Val )
 {
 /***************************************************************/
 static int Write32ToFile( FileStream *fid, uint32_t Val )
 {
-    int numw;
+    size_t numw;
     uint8_t pad[4];
 
     Write32BigEndian(pad,Val);
     uint8_t pad[4];
 
     Write32BigEndian(pad,Val);
@@ -332,8 +335,10 @@ static cell_t WriteChunkToFile( FileStream *fid, cell_t ID, char *Data, int32_t
 
     EvenNumW = EVENUP(NumBytes);
 
 
     EvenNumW = EVENUP(NumBytes);
 
-    if( Write32ToFile( fid, ID ) < 0 ) goto error;
-    if( Write32ToFile( fid, EvenNumW ) < 0 ) goto error;
+    assert(ID <= UINT32_MAX);
+    if( Write32ToFile( fid, (uint32_t)ID ) < 0 ) goto error;
+    assert(EvenNumW <= UINT32_MAX);
+    if( Write32ToFile( fid, (uint32_t)EvenNumW ) < 0 ) goto error;
 
     numw = sdWriteFile( Data, 1, EvenNumW, fid );
     if( numw != EvenNumW ) goto error;
 
     numw = sdWriteFile( Data, 1, EvenNumW, fid );
     if( numw != EvenNumW ) goto error;
@@ -459,7 +464,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
         NameSize = QUADUP(NameSize);  /* Align */
         if( NameSize > 0 )
         {
         NameSize = QUADUP(NameSize);  /* Align */
         if( NameSize > 0 )
         {
-            NameSize = MAX( NameSize, (NameChunkSize + 1024) );
+            NameSize = MAX( (ucell_t)NameSize, (NameChunkSize + 1024) );
         }
         SD.sd_NameSize = NameSize;
     }
         }
         SD.sd_NameSize = NameSize;
     }
@@ -467,7 +472,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
 /* How much real code is there? */
     CodeChunkSize = QUADUP(relativeCodePtr);
     CodeSize = QUADUP(CodeSize);  /* Align */
 /* How much real code is there? */
     CodeChunkSize = QUADUP(relativeCodePtr);
     CodeSize = QUADUP(CodeSize);  /* Align */
-    CodeSize = MAX( CodeSize, (CodeChunkSize + 2048) );
+    CodeSize = MAX( (ucell_t)CodeSize, (CodeChunkSize + 2048) );
     SD.sd_CodeSize = CodeSize;
 
 
     SD.sd_CodeSize = CodeSize;
 
 
@@ -486,7 +491,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
     if( WriteChunkToFile( fid, ID_P4CD, (char *) CODE_BASE,
         CodeChunkSize ) < 0 ) goto error;
 
     if( WriteChunkToFile( fid, ID_P4CD, (char *) CODE_BASE,
         CodeChunkSize ) < 0 ) goto error;
 
-    FormSize = sdTellFile( fid ) - 8;
+    FormSize = (uint32_t) sdTellFile( fid ) - 8;
     sdSeekFile( fid, 4, PF_SEEK_SET );
     if( Write32ToFile( fid, FormSize ) < 0 ) goto error;
 
     sdSeekFile( fid, 4, PF_SEEK_SET );
     if( Write32ToFile( fid, FormSize ) < 0 ) goto error;
 
@@ -515,7 +520,7 @@ error:
 /***************************************************************/
 static int32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr )
 {
 /***************************************************************/
 static int32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr )
 {
-    int32_t numr;
+    cell_t numr;
     uint8_t pad[4];
     numr = sdReadFile( pad, 1, sizeof(pad), fid );
     if( numr != sizeof(pad) ) return -1;
     uint8_t pad[4];
     numr = sdReadFile( pad, 1, sizeof(pad), fid );
     if( numr != sizeof(pad) ) return -1;
@@ -533,7 +538,7 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt
     uint32_t ChunkSize;
     uint32_t FormSize;
     uint32_t BytesLeft;
     uint32_t ChunkSize;
     uint32_t FormSize;
     uint32_t BytesLeft;
-    uint32_t numr;
+    cell_t numr;
     int   isDicBigEndian;
 
 DBUG(("pfLoadDictionary( %s )\n", FileName ));
     int   isDicBigEndian;
 
 DBUG(("pfLoadDictionary( %s )\n", FileName ));
@@ -726,7 +731,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
 /* Find special words in dictionary for global XTs. */
         if( (Result = FindSpecialXTs()) < 0 )
         {
 /* Find special words in dictionary for global XTs. */
         if( (Result = FindSpecialXTs()) < 0 )
         {
-            pfReportError("pfLoadDictionary: FindSpecialXTs", Result);
+            pfReportError("pfLoadDictionary: FindSpecialXTs", (Err)Result);
             goto error;
         }
     }
             goto error;
         }
     }