Commits

overlord  committed a864f35

Daybo logic checksumming tool

  • Participants

Comments (0)

Files changed (3)

+#
+#   librttb - Official RTTB readonly library.
+#   Copyright (C) 2000 Overlord David Duncan Ross Palmer, Daybo Logic.
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   Daybo Logic,
+#   13 Forest Close,
+#   Newport,
+#   IOW
+#
+#   Overlord@DayboLogic.co.uk
+#   +44 01983 520085
+
+# daybosummer on UNIX, GNU tools
+
+CC=gcc -O5
+UTILROOT=dlutils
+
+daybosummer : daybosummer.o $(UTILROOT)/libdlutils.a
+	$(CC) -odaybosummer daybosummer.o $(UTILROOT)/libdlutils.a
+	strip --strip-all daybosummer
+
+daybosummer.o : daybosummer.c $(UTILROOT)/dlutils.h
+	$(CC) -c -I$(UTILROOT) -ansi -pedantic -odaybosummer.o daybosummer.c
+
+$(UTILROOT)/libdlutils.a :
+	cd $(UTILROOT) && make
+
+clean:
+	rm -f daybosummer.o daybosummer
+	cd $(UTILROOT) && make clean

File Makefile.bor

+#
+#   librttb - Official RTTB readonly library.
+#   Copyright (C) 2000 Overlord David Duncan Ross Palmer, Daybo Logic.
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   Daybo Logic,
+#   13 Forest Close,
+#   Newport,
+#   IOW
+#   Overlord@DayboLogic.co.uk
+#   +44 01983 520085
+#
+
+# Makefile for Daybo Summer on Win32 Borland C++ (might work on DOS to if
+# CC is defined to something else and the filenames changed).
+
+CC=bcc32 -O2
+UTILROOT=dlutils
+
+daybosummer.exe : daybosummer.obj $(UTILROOT)\dlutils.lib
+        $(CC) -edaybosummer.exe daybosummer.obj $(UTILROOT)\dlutils.lib
+
+daybosummer.obj : daybosummer.c $(UTILROOT)\dlutils.h
+        $(CC) -c -I$(UTILROOT) -A daybosummer.c
+
+$(UTILROOT)\dlutils.lib :   # This bit will be broken unless I make a utility to push/top a directory stack
+        cd $(UTILROOT)
+        make -f Makefile.bor
+        cd .. # Here lieth the problem and in clean
+
+cleanlib :
+        cd $(UTILROOT)
+        make -f Makedfile.bor clean
+        cd .. # See above note
+
+clean : cleanlib
+        erase daybosummer.exe
+        erase daybosummer.obj

File daybosummer.c

+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h" /* Daybo Logic utilities library */
+
+/* Types */
+typedef unsigned int BOOL;
+typedef unsigned int UINT;
+#ifndef DWORD_T
+# if ULONG_MAX > 0xFFFFFFFFUL
+   typedef unsigned int DWORD;
+# else
+   typedef unsigned long DWORD;
+# endif
+# define DWORD_T
+#endif /*DWORD_T*/
+
+/* Constants */
+#define TRUE (1U)
+#define FALSE (0U)
+#define ZEROSUM (0U)
+
+/* Functions */
+static BOOL CmdLineFaults(void);
+static DWORD Checksum(const char* FileName, BOOL* FailFlag);
+static void MyExit(int StatusCode);
+static void ProcessLoop(void);
+
+/* Data */
+static char** _GlobalArgumentVector;
+static int _GlobalArgumentCount;
+
+static BOOL CmdLineFaults()
+{
+  if ( !(_GlobalArgumentCount-1) ) {
+    printf("Required parameter missing.\n");
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static DWORD Checksum(const char* FileName, BOOL* FailFlag)
+{
+  FILE* handle;
+  DWORD sum = 0UL;
+
+  if ( FailFlag ) *FailFlag = FALSE; /* No failures */
+  handle = fopen(FileName, "rb");
+  if ( !handle ) {
+    printf("Error: Cannot open %s\n", FileName);
+    if ( FailFlag ) *FailFlag = TRUE;
+    return sum; /* Nothing */
+  }
+  sum = dlutils_CalcFileChecksum32(handle);
+  fclose(handle);
+  return sum;
+}
+
+static void MyExit(int StatusCode)
+{
+  printf("(C)2001 Daybo Logic, all rights reserved.  May be distributed in binary\n"
+         "form to anybody who would find it useful for a distribution charge.\n");
+  exit(StatusCode);
+}
+
+void ProcessLoop()
+{
+  int i;
+  for ( i = 1U; i < _GlobalArgumentCount; i++ ) {
+    BOOL fail;
+    DWORD sum = Checksum(_GlobalArgumentVector[i], &fail);
+    if ( !fail )
+      printf("%s sum %lX (%u)\n", _GlobalArgumentVector[i], sum, sum);
+  }
+}
+
+int main(int argc, char* argv[])
+{
+  /* Make arguments global */
+  _GlobalArgumentCount = argc;
+  _GlobalArgumentVector = argv;
+  if ( !CmdLineFaults() ) /* Check for problems with the command line */
+    MyExit(EXIT_FAILURE);
+
+  printf("Starting summing...\n");
+  ProcessLoop();
+  MyExit(EXIT_SUCCESS);
+  return 0; /* Just to prevent a warning */
+}