From 7b358424ebad9349421acd533c2fa1cbf6cf3e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 28 Dec 2016 16:52:56 +0100 Subject: Initial import of xtrkcad version 1:4.0.2-2 --- app/wlib/mswlib/mswchksm.c | 125 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 app/wlib/mswlib/mswchksm.c (limited to 'app/wlib/mswlib/mswchksm.c') diff --git a/app/wlib/mswlib/mswchksm.c b/app/wlib/mswlib/mswchksm.c new file mode 100644 index 0000000..602c204 --- /dev/null +++ b/app/wlib/mswlib/mswchksm.c @@ -0,0 +1,125 @@ +#include +#include +#include "../include/wlib.h" +#ifdef WINDOWS +#include +#include "mswint.h" +#endif + +#define HEWHDROFFSET (0x3C) + +static FILE * openfile( const char * fn, const char * mode, long * fileSize ) +{ + unsigned short PageCnt; + long FileSize; + FILE *fp; + struct stat Stat; + fp = fopen( fn, mode ); + if (fp == NULL) { + perror( "fopen" ); + return NULL; + } + fread( &PageCnt, sizeof(PageCnt), 1, fp ); /* Read past signature */ + fread( &PageCnt, sizeof(PageCnt), 1, fp ); /* Read past pagesize */ + FileSize = PageCnt; + fread( &PageCnt, sizeof(PageCnt), 1, fp ); /* Read past pagesize */ + if ( FileSize == 0L ) + FileSize = PageCnt * 512L; + else + FileSize += (PageCnt - 1) * 512L; + *fileSize = FileSize; + stat( fn, &Stat ); + *fileSize = (long)Stat.st_size; + fprintf( stderr, "size1 = %ld, size2 = %ld\n", FileSize, (long)Stat.st_size ); + return fp; +} + + +static unsigned short mswCheck16( FILE * fp, long FileSize, unsigned short * sum16stored ) +{ + unsigned short int sum16, NxtInt; + long x; + unsigned char NxtChar; + sum16 = 0; + fseek(fp, 0, SEEK_SET); + + for (x=0L; x