From f6b085313fafb34b00298d29578c84d3525a6c5c Mon Sep 17 00:00:00 2001 From: Christopher Watford Date: Tue, 26 Jan 2021 12:42:02 -0500 Subject: [PATCH 1/4] Add support for compiling on MSVC 16+ --- fabdef.h | 3 ++- match.c | 1 + vmsbackup.c | 41 ++++++++++++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/fabdef.h b/fabdef.h index 26aad6c..f5e1d26 100644 --- a/fabdef.h +++ b/fabdef.h @@ -389,9 +389,10 @@ struct fabdef { #pragma pack (pop) - +#ifndef _WIN32 /* declare initialized prototype data structure */ extern struct FAB cc$rms_fab __asm("_$$PsectAttributes_GLOBALSYMBOL$$cc$rms_fab"); /* globalref struct FAB cc$rms_fab; */ +#endif #endif /*_FABDEF_H*/ diff --git a/match.c b/match.c index 137c7c0..257e0c3 100644 --- a/match.c +++ b/match.c @@ -1,4 +1,5 @@ #include +#include #include #define ASTERISK '*' /* The '*' metacharacter */ diff --git a/vmsbackup.c b/vmsbackup.c index 5d638ce..14f7821 100644 --- a/vmsbackup.c +++ b/vmsbackup.c @@ -30,6 +30,7 @@ * * Modification history: * + * 26-JAN-2021 CAW Build on Windows with CMake * 29-SEP-2016 RRL Some changes related structure aligment ... * 20-SEP-2016 RRL Some code cleaning and reformating; * added a logic to recovery broken backup blocks by rescanning Backup Block Header, The, @@ -37,18 +38,30 @@ * */ +/* MSVC uses _DEBUG */ +#ifdef _DEBUG +#define DEBUG 1 +#endif + /* Does this system have the magnetic tape ioctls? The answer is yes for most/all unices, and I think it is yes for VMS 7.x with DECC 5.2 (needs verification), but it is no for VMS 6.2. */ +#ifndef _WIN32 #ifndef HAVE_MT_IOCTLS #define HAVE_MT_IOCTLS 1 #endif +#endif #ifdef HAVE_UNIXIO_H /* Declarations for read, write, etc. */ #include #else +#ifdef _WIN32 +#include +#else #include +#include +#endif #include #endif @@ -67,11 +80,10 @@ #include #include #endif -#include #include "fabdef.h" -#ifndef __vax +#if !defined(__vax) && !defined(_WIN32) /* The help claims that mkdir is declared in stdlib.h but it doesn't seem to be true. AXP/VMS 6.2, DECC ?.?. On the other hand, VAX/VMS 6.2 seems to declare it in a way which conflicts with this definition. @@ -312,7 +324,7 @@ int procf = 1; /* open the file for writing */ if (procf) - return fopen(p, "w"); + return fopen(p, "wb"); return NULL; } @@ -325,7 +337,7 @@ void process_summary ( size_t c; unsigned char *text; unsigned short grp = 0377, usr = 0377, itmcode, itmlen; -unsigned id, blksz = 0, grpsz = 0, bufcnt = 0; +unsigned id = 0, blksz = 0, grpsz = 0, bufcnt = 0; ITM *itm; if (!tflag) @@ -341,7 +353,7 @@ ITM *itm; bufp += 2; for ( itm = (ITM *) bufp, c = 2; c < buflen; c += itmlen + 4, - itm = (ITM *) (((void *) itm) + (itmlen + 4))) + itm = (ITM *) (((char *) itm) + (itmlen + 4))) { itmlen = __cvt_uw (&itm->w_size); itmcode = __cvt_uw (&itm->w_type); @@ -493,7 +505,7 @@ ITM *itm; bufp += 2; for ( itm = (ITM *) bufp, c = 2; c < buflen; c += itmlen + 4, - itm = (ITM *) (((void *) itm) + (itmlen + 4))) + itm = (ITM *) (((char *) itm) + (itmlen + 4))) { itmlen = __cvt_uw (&itm->w_size); itmcode = __cvt_uw (&itm->w_type); @@ -501,7 +513,7 @@ ITM *itm; pdata = itm->t_text; #ifdef DEBUG - debug_dump(data, dsize, dtype); + debug_dump(pdata, itmlen, itmcode); #endif /* Probably should define constants for the cases in this @@ -952,7 +964,7 @@ BCK_BLK_HDR * bbh = (BCK_BLK_HDR *) bufp; #ifdef DEBUG if (debugflag) fprintf(stderr, "[0x%08X] Backup block: header length = %d, size = %d, type (DATA=1/XOR=2) = %5d\n", - lseek (fd, 0, SEEK_CUR) - BBH$K_SZ, bhsize, bsize, bbh->w_applic); + lseek (input_fd, 0, SEEK_CUR) - BBH$K_SZ, bhsize, bsize, bbh->w_applic); #endif status = 0; @@ -1030,7 +1042,7 @@ BCK_REC_HDR * brh; #ifdef DEBUG if (debugflag) printf("[0x%08X] Backup block: header length = %d, size = %d, type (DATA=1/XOR=2) = %5d, csum = %x04\n", - lseek (fd, 0, SEEK_CUR), bhsize, bsize, bbh->w_applic, bbh->w_checksum); + lseek (input_fd, 0, SEEK_CUR), bhsize, bsize, bbh->w_applic, bbh->w_checksum); #endif @@ -1048,7 +1060,7 @@ BCK_REC_HDR * brh; #ifdef DEBUG if (debugflag) printf("+%06d: Record: type = 0x%x, size = %-5d, flags = 0x%x, addr = 0x%08x\n", - i, rtype, rsize, getu32 (brh->l_flags), getu32 (brh->l_address)); + i, rtype, rsize, brh->l_flags, brh->l_address); #endif bufp += sizeof(BCK_REC_HDR); @@ -1226,11 +1238,18 @@ int i, eoffl; a tape. */ int ondisk; +/* Read-only plus binary if on Windows */ +int openflag = O_RDONLY; + +#ifdef _WIN32 + openflag |= O_BINARY; +#endif + if (tapefile == NULL) tapefile = def_tapefile; /* open the tape file */ - if ( 0 > (input_fd = open(tapefile, O_RDONLY)) ) + if ( 0 > (input_fd = open(tapefile, openflag)) ) { perror(tapefile); exit(1); From 611c5d25008b715d3bfad82a590c5de497906d49 Mon Sep 17 00:00:00 2001 From: Christopher Watford Date: Tue, 26 Jan 2021 12:43:07 -0500 Subject: [PATCH 2/4] Fix bug with vfcsize assignment in process_file --- vmsbackup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vmsbackup.c b/vmsbackup.c index 14f7821..5933230 100644 --- a/vmsbackup.c +++ b/vmsbackup.c @@ -576,7 +576,8 @@ ITM *itm; lnch = __cvt_uw (pdata + 12); /* byte 14 unaccounted for */ - if ( !(vfcsize = pdata + 15) ) + vfcsize = *(pdata + 15); + if (vfcsize == 0) vfcsize = 2; /* bytes 16-31 unaccounted for */ From 3a2bb16ebfabdd7585643695c92237e954f7b11f Mon Sep 17 00:00:00 2001 From: Christopher Watford Date: Tue, 26 Jan 2021 13:23:50 -0500 Subject: [PATCH 3/4] Pass the correct args to mkdir on Windows --- vmsbackup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vmsbackup.c b/vmsbackup.c index 5933230..d5e24e3 100644 --- a/vmsbackup.c +++ b/vmsbackup.c @@ -57,6 +57,7 @@ #include #else #ifdef _WIN32 +#include #include #else #include @@ -295,7 +296,12 @@ int procf = 1; s = *q; *q = '\0'; - if(procf && dflag) mkdir(p, 0777); + if (procf && dflag) +#ifndef _WIN32 + mkdir(p, 0777); +#else + mkdir(p); +#endif *q = '/'; From b37f856602a403b813efc634a063ed3da6483ba6 Mon Sep 17 00:00:00 2001 From: Christopher Watford Date: Tue, 26 Jan 2021 13:35:18 -0500 Subject: [PATCH 4/4] Do not use colons for version seps on Windows - FILE.EXT:1 would create a file with an alternate data stream (ADS) of 1. This is awkward on Windows and should instead just use the VMS character of semicolon (or at least that's a reasonable choice). --- vmsbackup.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vmsbackup.c b/vmsbackup.c index d5e24e3..cc36bc0 100644 --- a/vmsbackup.c +++ b/vmsbackup.c @@ -92,6 +92,19 @@ int mkdir (); #endif +/* When the -c flag is used, choose an appropriate separator char + for the platform. */ +#ifdef _WIN32 +/* Windows uses a trailing colon (and text) to mean an alternate + data stream for the file, which is awkward to use in practice + and leads to trouble in the long run as Explorer does not + provide meaningful tools to deal with these. The VMS default + of semicolon works just fine. */ +#define VERSION_SEPARATOR_CHAR ';' +#else +#define VERSION_SEPARATOR_CHAR ':' +#endif + #include "vmsbackup.h" #include "sysdep.h" @@ -318,7 +331,7 @@ int procf = 1; for (; *q && *q != ';'; q++) if( *q == '.') ext = q; - *q = (cflag) ? ':' : '\0'; + *q = (cflag) ? VERSION_SEPARATOR_CHAR : '\0'; if (procf && wflag) {