diff options
| author | Jon duSaint | 2022-04-30 16:16:25 -0700 |
|---|---|---|
| committer | Jon duSaint | 2022-04-30 16:16:25 -0700 |
| commit | 3160d814a1a088cfbcbd3c48c02d36273fd56383 (patch) | |
| tree | ee703f562c870ee7ea675b8b682a48da2750ecfa /update | |
| parent | 659f12ede69726f46487d6e44aa79f48c2bd2aae (diff) | |
Commit a bunch of old software
Diffstat (limited to 'update')
| -rwxr-xr-x | update/update.c | 224 | ||||
| -rwxr-xr-x | update/update.exe | bin | 0 -> 60416 bytes | |||
| -rwxr-xr-x | update/update.ico | bin | 0 -> 1078 bytes | |||
| -rwxr-xr-x | update/update.rc | 3 |
4 files changed, 227 insertions, 0 deletions
diff --git a/update/update.c b/update/update.c new file mode 100755 index 0000000..2a27f77 --- /dev/null +++ b/update/update.c @@ -0,0 +1,224 @@ +/* update.c
+ * A very simplified version of make which updates the Perl programs
+ * if needed. The "makefile" used is .\update.txt unless a file has
+ * been specified on the command line. Within that file are several
+ * commands described below.
+ *
+ * FILE = <filepath\filename>
+ * Specify a source file to be updated.
+ *
+ * DEST = <filepath>
+ * Specifiy a destination path.
+ *
+ * Lines starting with # are ignored. There must be one FILE entry per
+ * file to be updated with only one file per entry. When a DEST entry
+ * is encountered, all following FILE entries are updated using the DEST
+ * entry.
+ *
+ * Copyright (C) 2002 Jonathan duSaint under the terms of the GPL.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <windows.h>
+
+#define UPDATE_FILE "update.txt"
+#define LINE_SIZE 256
+#define COMMENT_CHAR '#'
+
+#define CMD_FILE "FILE"
+#define LCMD_FILE 4
+#define CMD_DEST "DEST"
+#define LCMD_DEST 4
+
+
+void *
+xmalloc (size_t amt)
+{
+ void *mem;
+
+ mem = malloc (amt);
+
+ if (mem == NULL)
+ {
+ fprintf (stderr, "update: Unable to allocate %d bytes\n", amt);
+ exit (1);
+ }
+
+ memset (mem, 0, amt);
+
+ return (mem);
+}
+
+
+void
+update_file (char *file, char *dest)
+{
+ int pos, copy = 0;
+ char *filename, *destination;
+ FILETIME fts, ftd;
+ HANDLE hFiles, hFiled;
+ LARGE_INTEGER lis, lid;
+
+ pos = strlen (file) - 1;
+ while (file[pos] != '\\' && pos) pos--;
+ filename = xmalloc (strlen (file) - pos);
+ strcpy (filename, file + pos + 1);
+
+ destination = xmalloc (strlen (dest) + strlen (filename) + 2);
+ sprintf (destination, "%s\\%s", dest, filename);
+
+
+ hFiles = CreateFile (file, GENERIC_READ, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ hFiled = CreateFile (destination, GENERIC_READ, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (hFiles == INVALID_HANDLE_VALUE)
+ {
+ fprintf (stderr, "update: Unable to access %s\n", file);
+ exit (1);
+ }
+ if (hFiled == INVALID_HANDLE_VALUE)
+ copy = 1;
+
+
+ if (copy);
+ else if (!GetFileTime (hFiles, NULL, NULL, &fts))
+ {
+ fprintf (stderr, "update: Unable to access %s\n", file);
+ exit (1);
+ }
+ if (copy);
+ else if (GetFileTime (hFiled, NULL, NULL, &ftd))
+ {
+ lis.u.LowPart = fts.dwLowDateTime;
+ lis.u.HighPart = fts.dwHighDateTime;
+ lid.u.LowPart = ftd.dwLowDateTime;
+ lid.u.HighPart = ftd.dwHighDateTime;
+
+ if (lis.QuadPart > lid.QuadPart) copy = 1;
+ }
+ else
+ copy = 1;
+
+ CloseHandle (hFiles);
+ CloseHandle (hFiled);
+
+ if (copy)
+ {
+ if (!CopyFile (file, destination, FALSE))
+ printf ("failed to ");
+
+ printf ("copy %s to %s\n", file, destination);
+ }
+
+ free (filename);
+ free (destination);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int pos, epos, lineno = 0;
+ char *filename, *line, *dest = NULL;
+ FILE *update;
+
+ if (argc > 1)
+ filename = argv[1];
+ else
+ filename = UPDATE_FILE;
+
+ update = fopen (filename, "rt");
+ if (update == NULL)
+ {
+ fprintf (stderr, "update: Unable to open %s\n", filename);
+ exit (1);
+ }
+
+ line = xmalloc (LINE_SIZE);
+
+ while (fgets (line, LINE_SIZE, update) != NULL)
+ {
+ lineno++;
+ if (line[0] == COMMENT_CHAR) continue;
+ if (line[0] == '\n') continue;
+
+ for (pos = 0; !isalpha (line[pos]); pos++);
+
+ if (!strncmp (line + pos, CMD_FILE, LCMD_FILE))
+ {
+ char *file;
+
+ epos = pos + LCMD_FILE;
+ while (!isspace (line[epos])) epos++;
+ while (isspace (line[epos])) epos++;
+ pos = epos;
+ epos = strlen (line);
+
+ while (isspace(line[epos - 1]))
+ {
+ if (epos <= pos)
+ {
+ fprintf (stderr, "update: invalid FILE command on line %d\n",
+ lineno);
+ exit (1);
+ }
+ epos--;
+ }
+
+ if (dest == NULL)
+ {
+ fprintf (stderr, "update: missing DEST command\n");
+ exit (1);
+ }
+
+ file = xmalloc (epos - pos + 1);
+ strncpy (file, line + pos, epos - pos);
+
+ update_file (file, dest);
+
+ free (file);
+ }
+ else if (!strncmp (line + pos, CMD_DEST, LCMD_DEST))
+ {
+ epos = pos + LCMD_FILE;
+ while (!isspace (line[epos])) epos++;
+ while (isspace (line[epos])) epos++;
+ pos = epos;
+ epos = strlen (line);
+
+ while (isspace(line[epos - 1]))
+ {
+ if (epos <= pos)
+ {
+ fprintf (stderr, "update: invalid DEST command on line %d\n",
+ lineno);
+ exit (1);
+ }
+ epos--;
+ }
+
+ if (dest != NULL) free (dest);
+ dest = xmalloc (epos - pos + 1);
+ strncpy (dest, line + pos, epos - pos);
+ }
+ else
+ {
+ epos = pos;
+ while (isalpha (line[epos])) epos++;
+ line[epos] = '\0';
+
+ fprintf (stderr, "update: unknown command '%s'\n", line + pos);
+ exit (1);
+ }
+
+ }
+
+ if (dest != NULL) free (dest);
+
+ return (0);
+}
diff --git a/update/update.exe b/update/update.exe Binary files differnew file mode 100755 index 0000000..02f5fe4 --- /dev/null +++ b/update/update.exe diff --git a/update/update.ico b/update/update.ico Binary files differnew file mode 100755 index 0000000..62e36f3 --- /dev/null +++ b/update/update.ico diff --git a/update/update.rc b/update/update.rc new file mode 100755 index 0000000..3a73ba6 --- /dev/null +++ b/update/update.rc @@ -0,0 +1,3 @@ +/* update.rc */
+
+UpdateIcon ICON "update.ico"
|
