X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/1cb310e62eaf4422ee298d9d87c35f9dd6b4c71c..90975d261c7ab39186c75d8700261faab3427de7:/csrc/pf_save.c diff --git a/csrc/pf_save.c b/csrc/pf_save.c index 6a9d195..f3f9ac0 100644 --- a/csrc/pf_save.c +++ b/csrc/pf_save.c @@ -343,6 +343,33 @@ error: return -1; } +/* Convert dictionary info chunk between native and on-disk (big-endian). */ +static void +convertDictionaryInfoWrite (DictionaryInfoChunk *sd) +{ +/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. + * This assumes they are all 32-bit integers. + */ + int i; + uint32_t *p = (uint32_t *) sd; + for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++) + { + Write32BigEndian( (uint8_t *)&p[i], p[i] ); + } +} + +static void +convertDictionaryInfoRead (DictionaryInfoChunk *sd) +{ +/* Convert all fields in structure from BigEndian to Native. */ + int i; + uint32_t *p = (uint32_t *) sd; + for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++) + { + p[i] = Read32BigEndian( (uint8_t *)&p[i] ); + } +} + /**************************************************************** ** Save Dictionary in File. ** If EntryPoint is NULL, save as development environment. @@ -356,7 +383,6 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, uint32_t NameChunkSize = 0; uint32_t CodeChunkSize; uint32_t relativeCodePtr; - int i; fid = sdOpenFile( FileName, "wb" ); if( fid == NULL ) @@ -423,7 +449,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, uint32_t relativeHeaderPtr; /* Development mode. */ SD.sd_RelContext = ABS_TO_NAMEREL(gVarContext); - relativeHeaderPtr = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr.Byte); + relativeHeaderPtr = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr); SD.sd_RelHeaderPtr = relativeHeaderPtr; /* How much real name space is there? */ @@ -445,16 +471,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, SD.sd_CodeSize = CodeSize; -/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. - * This assumes they are all 32-bit integers. - */ - { - uint32_t *p = (uint32_t *) &SD; - for( i=0; i<((int)(sizeof(SD)/sizeof(uint32_t))); i++ ) - { - Write32BigEndian( (uint8_t *)&p[i], p[i] ); - } - } + convertDictionaryInfoWrite (&SD); if( WriteChunkToFile( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error; @@ -517,7 +534,6 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt uint32_t FormSize; uint32_t BytesLeft; uint32_t numr; - int i; int isDicBigEndian; DBUG(("pfLoadDictionary( %s )\n", FileName )); @@ -568,15 +584,8 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); if( numr != ChunkSize ) goto read_error; BytesLeft -= ChunkSize; -/* Convert all fields in structure from BigEndian to Native. */ - { - uint32_t *p = (uint32_t *) sd; - for( i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++ ) - { - p[i] = Read32BigEndian( (uint8_t *)&p[i] ); - } - } - + convertDictionaryInfoRead (sd); + isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC; if( !gVarQuiet ) @@ -645,13 +654,13 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); if( sd->sd_NameSize > 0 ) { gVarContext = (char *) NAMEREL_TO_ABS(sd->sd_RelContext); /* Restore context. */ - gCurrentDictionary->dic_HeaderPtr.Byte = (uint8_t *) + gCurrentDictionary->dic_HeaderPtr = (ucell_t)(uint8_t *) NAMEREL_TO_ABS(sd->sd_RelHeaderPtr); } else { gVarContext = 0; - gCurrentDictionary->dic_HeaderPtr.Byte = NULL; + gCurrentDictionary->dic_HeaderPtr = (ucell_t)NULL; } gCurrentDictionary->dic_CodePtr.Byte = (uint8_t *) CODEREL_TO_ABS(sd->sd_RelCodePtr); gNumPrimitives = sd->sd_NumPrimitives; /* Must match compiled dictionary. */ @@ -810,7 +819,7 @@ PForthDictionary pfLoadStaticDictionary( void ) if( NAME_BASE != NULL) { /* Setup name space. */ - dic->dic_HeaderPtr.Byte = (uint8_t *) NAMEREL_TO_ABS(HEADERPTR); + dic->dic_HeaderPtr = (ucell_t)(uint8_t *) NAMEREL_TO_ABS(HEADERPTR); gVarContext = (char *) NAMEREL_TO_ABS(RELCONTEXT); /* Restore context. */ /* Find special words in dictionary for global XTs. */