From e4ec481d3d9d367cf3ded790402fba751de2bfff Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Thu, 27 Apr 2017 20:29:04 +0200 Subject: [PATCH] Add RT11 macro libraries. Hopefully they won't open as RSX ones, because then they still won't work. Can't test this now. --- Makefile | 2 +- macro11.c | 2 +- mlb.c => mlb-rt11.c | 51 +++++++++++++++++++++++++++++++++------------ mlb.h | 14 +++++++++++++ mlb2.c | 4 +++- 5 files changed, 57 insertions(+), 16 deletions(-) rename mlb.c => mlb-rt11.c (88%) diff --git a/Makefile b/Makefile index a330a95..52410c6 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ CFLAGS ?= -O -ggdb -std=gnu99 $(WARNS) MACRO11_SRCS = macro11.c \ assemble.c assemble_globals.c assemble_aux.c \ extree.c listing.c macros.c parse.c rept_irpc.c symbols.c \ - mlb-rsx.c object.c stream2.c util.c rad50.c + mlb2.c mlb-rsx.c mlb-rt11.c object.c stream2.c util.c rad50.c MACRO11_OBJS = $(MACRO11_SRCS:.c=.o) diff --git a/macro11.c b/macro11.c index ef50f88..e134729 100644 --- a/macro11.c +++ b/macro11.c @@ -133,7 +133,7 @@ static void print_help( printf("-h print this help\n"); printf("-l gives the listing file name (.LST)\n"); printf(" -l - enables listing to stdout.\n"); - printf("-m load RT-11 compatible macro library from which\n"); + printf("-m load RSX-11 or RT-11 compatible macro library from which\n"); printf(" .MCALLed macros can be found.\n"); printf(" Multiple allowed.\n"); printf("-o gives the object file name (.OBJ)\n"); diff --git a/mlb.c b/mlb-rt11.c similarity index 88% rename from mlb.c rename to mlb-rt11.c index b5c7d8b..36d2165 100644 --- a/mlb.c +++ b/mlb-rt11.c @@ -48,6 +48,24 @@ DAMAGE. #include "util.h" +static MLB *mlb_rt11_open( + char *name, + int allow_object_library); +static BUFFER *mlb_rt11_entry( + MLB *mlb, + char *name); +static void mlb_rt11_close( + MLB *mlb); +static void mlb_rt11_extract( + MLB *mlb); + +struct mlb_vtbl mlb_rt11_vtbl = { + mlb_rt11_open, + mlb_rt11_entry, + mlb_rt11_extract, + mlb_rt11_close, +}; + #define WORD(cp) ((*(cp) & 0xff) + ((*((cp)+1) & 0xff) << 8)) /* BYTEPOS calculates the byte position within the macro libray file. @@ -84,11 +102,13 @@ static void trim( *cp = 0; } -/* mlb_open opens a file which is given to be a macro library. */ +/* mlb_rt11_open opens a file which is given to be a macro library. */ /* Returns NULL on failure. */ -MLB *mlb_open( - char *name) +static +MLB *mlb_rt11_open( + char *name, + int allow_object_library) { MLB *mlb = memcheck(malloc(sizeof(MLB))); char *buff; @@ -97,24 +117,26 @@ MLB *mlb_open( unsigned start_block; int i; + (void)allow_object_library; /* This parameter is not supported */ + mlb->vtbl = &mlb_rt11_vtbl; mlb->directory = NULL; mlb->fp = fopen(name, "rb"); if (mlb->fp == NULL) { - mlb_close(mlb); + mlb_rt11_close(mlb); return NULL; } buff = memcheck(malloc(044)); /* Size of MLB library header */ if (fread(buff, 1, 044, mlb->fp) < 044) { - mlb_close(mlb); + mlb_rt11_close(mlb); free(buff); return NULL; } if (WORD(buff) != 01001) { /* Is this really a macro library? */ - mlb_close(mlb); /* Nope. */ + mlb_rt11_close(mlb); /* Nope. */ return NULL; } @@ -132,7 +154,7 @@ MLB *mlb_open( /* Read the disk directory */ if (fread(buff, entsize, nr_entries, mlb->fp) < nr_entries) { - mlb_close(mlb); /* Sorry, read error. */ + mlb_rt11_close(mlb); /* Sorry, read error. */ free(buff); return NULL; } @@ -214,8 +236,9 @@ MLB *mlb_open( return mlb; } -/* mlb_close discards MLB and closes the file. */ -void mlb_close( +/* mlb_rt11_close discards MLB and closes the file. */ +static +void mlb_rt11_close( MLB *mlb) { if (mlb) { @@ -234,10 +257,11 @@ void mlb_close( } } -/* mlb_entry returns a BUFFER containing the specified entry from the +/* mlb_rt11_entry returns a BUFFER containing the specified entry from the macro library, or NULL if not found. */ -BUFFER *mlb_entry( +static +BUFFER *mlb_rt11_entry( MLB *mlb, char *name) { @@ -278,7 +302,7 @@ BUFFER *mlb_entry( return buf; } -/* mlb_extract - walk thru a macro library and store its contents +/* mlb_rt11_extract - walk thru a macro library and store its contents into files in the current directory. See, I had decided not to bother writing macro library maintenance @@ -288,7 +312,8 @@ BUFFER *mlb_entry( in the file system from thence forward. */ -void mlb_extract( +static +void mlb_rt11_extract( MLB *mlb) { int i; diff --git a/mlb.h b/mlb.h index 4d65202..e9db913 100644 --- a/mlb.h +++ b/mlb.h @@ -46,13 +46,24 @@ typedef struct mlbent { int length; } MLBENT; +struct mlb_vtbl; + typedef struct mlb { + struct mlb_vtbl *vtbl; + char *name; FILE *fp; MLBENT *directory; int nentries; int is_objlib; /* is really an object library */ } MLB; +typedef struct mlb_vtbl { + MLB *(*mlb_open)(char *name, int allow_object_library); + BUFFER *(*mlb_entry)(MLB *mlb, char *name); + void (*mlb_extract)(MLB *mlb); + void (*mlb_close)(MLB *mlb); +} MLB_VTBL; + extern MLB *mlb_open( char *name, int allow_object_library); @@ -64,4 +75,7 @@ extern void mlb_close( extern void mlb_extract( MLB *mlb); +extern struct mlb_vtbl mlb_rsx_vtbl; +extern struct mlb_vtbl mlb_rt11_vtbl; + #endif /* MLB_H */ diff --git a/mlb2.c b/mlb2.c index 46b9d8a..3f4c25f 100644 --- a/mlb2.c +++ b/mlb2.c @@ -1,9 +1,11 @@ #include #include +#include "util.h" #include "mlb.h" MLB_VTBL *mlb_vtbls[] = { &mlb_rsx_vtbl, + &mlb_rt11_vtbl, NULL }; @@ -18,7 +20,7 @@ MLB *mlb_open( for (i = 0; (vtbl = mlb_vtbls[i]); i++) { mlb = vtbl->mlb_open(name, allow_object_library); if (mlb != NULL) { - mlb->name = strdup(name); + mlb->name = memcheck(strdup(name)); break; } }