mirror of
https://github.com/rcornwell/sims.git
synced 2026-03-27 02:14:49 +00:00
SEL32: Remove taptools and util directories.
SEL32: Remove testcode files from tests directory. SEL32: Update ICL file to Concept/32 format. SEL32: Update README.md file. SEL32: Add .gitignore in install directory for dsk/tapes files.
This commit is contained in:
3
SEL32/.gitignore
vendored
Normal file
3
SEL32/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
#ignore taptools and util directories.
|
||||
/taptools
|
||||
/util
|
||||
@@ -41,17 +41,16 @@ available configurations.
|
||||
|
||||
# SEL32 test configuration files in the tests directory:
|
||||
|
||||
In the tests directory contains the machine diagnostic command file and
|
||||
The tests directory contains the SEL32 machine diagnostic command file and
|
||||
bootable tape. They are used by the simh makefile to test the SEL32
|
||||
simulator after it built. All of the instruction set and operating modes
|
||||
are validated by the diagnostic. There is a pass/failure indication from
|
||||
the diagnostic. The command file sel32_test.ini is used by the makefile.
|
||||
The command file diag.ini can be run at any time by the user to rerun the
|
||||
diagnostics. There is also some test code used during initial development
|
||||
of the SEL32 simulator. Also an example of the initial configuration file
|
||||
(ICL) used by the diagnostic is provided. The machine configuration is
|
||||
loaded by the diag or the UTX or MPX operating system at boot time. See
|
||||
the MPX manuals at bitsavers.org/pdf/sel/sel32_mpx for using MPX 1X or 3X.
|
||||
diagnostics. There is an example of the initial configuration file (ICL)
|
||||
used by the diagnostic. The machine configuration is loaded by the diag
|
||||
or the UTX or MPX operating system at boot time. See the MPX manuals at
|
||||
bitsavers.org/pdf/sel/sel32_mpx for using MPX 1X or 3X.
|
||||
|
||||
#sel32_test.ini - diag.tap; type "../sel32_test.ini" or run from makefile.
|
||||
Auto run by sel32 makefile to validate build or can be run at any time
|
||||
@@ -96,13 +95,6 @@ diag.tap - bootable level one diagnostic tape w/auto testing.
|
||||
Testing is extremely difficult without any source for the
|
||||
diagnostics. Updates to follow as tests are corrected.
|
||||
|
||||
# SEL32 tap tools available in the taptools directory:
|
||||
|
||||
Available tap tools in taptools directory:
|
||||
./taptools - set of tools to work with .tap formatted tapes. Also tools
|
||||
to convert between MPX and UNIX file formats. See README
|
||||
file in the taptools directory and source for descriptions.
|
||||
|
||||
Other MPX versions support:
|
||||
I have recently received some old MPX 3.X save tapes. Using
|
||||
these I have been able to hand build a MPX3.6 SDT tape that
|
||||
@@ -117,5 +109,5 @@ Other MPX versions support:
|
||||
thankfull. Please keep looking.
|
||||
|
||||
James C. Bevier
|
||||
02/27/2022
|
||||
02/28/2022
|
||||
|
||||
|
||||
6
SEL32/installs/.gitignore
vendored
Normal file
6
SEL32/installs/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#tape files are dynamically downloaded from github.com/AZBevier/SEL32-installs as they are needed.
|
||||
/tape
|
||||
#disk files are created by the simh installation command files. These are SEL32 bootable disks.
|
||||
/dsk
|
||||
#ignore lp output from MPX-1X install.
|
||||
lprout
|
||||
@@ -26,7 +26,7 @@ mkdir tapes
|
||||
; Set tape image filename
|
||||
set env FILE=mpx1xsdt.tap
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if exist "tapes/%FILE%" goto exists
|
||||
if not exist "tapes/%FILE%" echof "file %FILE% missing, trying %FILE%.tgz"
|
||||
cd tapes
|
||||
|
||||
@@ -28,7 +28,7 @@ mkdir tapes
|
||||
; Set tape image filename
|
||||
set env FILE1=utx21b1.tap
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if exist "tapes/%FILE1%" goto exists1
|
||||
if not exist "tapes/%FILE1%" echof "file %FILE1% missing, trying %FILE1%.tgz"
|
||||
cd tapes
|
||||
|
||||
@@ -34,7 +34,7 @@ mkdir tapes
|
||||
set env FILE1=utx21b1.tap
|
||||
if exist "tapes/%FILE1%" goto exists1
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if not exist "tapes/%FILE1%" echof "file %FILE1% missing, trying %FILE1%.tgz"
|
||||
cd tapes
|
||||
if exist "%FILE1%.tgz" goto nocurl1
|
||||
|
||||
@@ -30,7 +30,7 @@ mkdir tapes
|
||||
; Set tape image filename
|
||||
set env FILE=mpxsdt69.tap
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if exist "tapes/%FILE%" goto exists
|
||||
if not exist "tapes/%FILE%" echof "file %FILE% missing, trying %FILE%.tgz"
|
||||
cd tapes
|
||||
|
||||
@@ -26,7 +26,7 @@ mkdir tapes
|
||||
; Set tape image filename
|
||||
set env FILE=mpx1xsdt.tap
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if exist "tapes/%FILE%" goto exists
|
||||
if not exist "tapes/%FILE%" echof "file %FILE% missing, trying %FILE%.tgz"
|
||||
cd tapes
|
||||
|
||||
@@ -38,7 +38,7 @@ mkdir tapes
|
||||
; Set tape image filename
|
||||
set env FILE=user36esdtp2.tap
|
||||
; Set github.com URL for downloading files
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/master/tapes/
|
||||
set env GITURL=https://github.com/AZBevier/SEL32-installs/raw/main/tapes/
|
||||
if exist "tapes/%FILE%" goto exists
|
||||
if not exist "tapes/%FILE%" echof "file %FILE% missing, trying %FILE%.tgz"
|
||||
cd tapes
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
This directory contains several utilites to work with .tap metadata
|
||||
files used by the simh simulators. Some of these would be usable
|
||||
for any simulator, not just the SEL32 simulator. General use MPX
|
||||
utilities are also attached that help with file format conversion
|
||||
between MPX and UNIX files.
|
||||
|
||||
Users should create the directories /system and /system/bin to hold
|
||||
the utilities. The directories should be world readable/writable.
|
||||
chmod 777 /system /system/bin
|
||||
The following two lines should be added to your ~/.bashrc so you
|
||||
will be able to execute the utilities from anywhere:
|
||||
PATH=$PATH:/system/bin
|
||||
export PATH
|
||||
You can test to see if correct by typing 'echo $PATH' and you
|
||||
should get a response with /system/bin in the directory list.
|
||||
|
||||
Compile and install the utilities by typing 'make install' to
|
||||
install utilities into the /system/bin directory.
|
||||
|
||||
|
||||
cutostap - This program scans a metadata .tap file and copies files
|
||||
until an EOF is found. This program is used to remove
|
||||
the sdt image from a .tap file to be used in another
|
||||
.tap sdt image. The mkfmcopy can be used to create a
|
||||
user sdt tape with files following the sdt image.
|
||||
|
||||
command: cutostap <file.tap >stdout
|
||||
input - stdin <file to remove sdt image from
|
||||
output - stdout >file to be written with sdt image
|
||||
|
||||
diskload - This program reads an MPX load module and stores it into
|
||||
a simulated diskfile. The MPX 1.X SMD entry for the file
|
||||
is entered into the SMD for the file. Will not work for
|
||||
MPX 3.X file systems.
|
||||
|
||||
command: diskload -la program diskfile
|
||||
option -a - add filename to diskfile
|
||||
option -l - list files in diskfile SMD, ignore filename
|
||||
input - filename - file to copy to system disk
|
||||
- diskfile - simulated system disk
|
||||
output - modified system disk
|
||||
|
||||
eomtap - This program reads a tape assigned as input device. It
|
||||
copies files until two EOFs are read and then makes sure
|
||||
two EOFs are written followed by an EOM. This program
|
||||
makes sure a .tap tape is readable without errors.
|
||||
|
||||
command: eomtap mt00 filename
|
||||
input - mag tape device or file being read
|
||||
output - disk file containing tape file contents
|
||||
|
||||
filelist - This program scans a metadata .tap file and prints the
|
||||
file count and sizes. Used to determine the file
|
||||
format contained in the metadata .tap file.
|
||||
|
||||
command: filelist <file.tap >stdout
|
||||
input - stdin <file to dump
|
||||
output - stdout
|
||||
|
||||
fmgrcopy - This program reads a MPX 1.X filemgr save tape. The tape
|
||||
must contain a filemgr save image with 4608 byte records.
|
||||
SMD entries and file data are modulo 1152 32 bit words or
|
||||
4608 bytes. The program will create a directory in the
|
||||
current directory for each different username. Null user
|
||||
name will use the system directory. Within each directory
|
||||
each file contained on the tape is extracted and written
|
||||
as binary data to the named file. The .tap file MUST be
|
||||
a filemgr save tape and not a MPX 1.X SDT tape.
|
||||
|
||||
command: fmgrcopy file.tap >stdout
|
||||
input - file.tap file to dump
|
||||
output - stdout filelist and sizes
|
||||
output - directory/files extracted to current directory
|
||||
|
||||
mkfmtape - This program creates an MPX 1.X filemgr save tape. The
|
||||
tape can then be used to restore files to the MPX 1.x
|
||||
system. The output will be in SIMH simulated .tap format.
|
||||
|
||||
command: mkfmtape opts output.tap file1 file2 ...
|
||||
input - list of filename to save to tape.
|
||||
output - output.tap a tap formatted file.
|
||||
options - -p = file type 0xca for programs
|
||||
- -t = ASCII text file type 0xee
|
||||
- -l = library/directory file type 0xff
|
||||
- -o = other type 0x00
|
||||
- -a = append entries to current file
|
||||
- -u = username (directory)
|
||||
|
||||
mkvmtape - This program reads MPX files and stores them into a
|
||||
simulated volmgr save tape. The tape may then become
|
||||
a MPX 3.X sdt boot tape to install MPX 3.X from or a
|
||||
volmgr file restore tape for a running MPX system.
|
||||
The output will be in SIMH simulated .tap format.
|
||||
|
||||
command: mkfmtape [-ptloa] [-bboot] [-iimage] [-jj.vfmt]
|
||||
[-uusername] tapname file1 file2 ...
|
||||
intput - [options] volmtape filename, filename, etc.
|
||||
output - volmtape file, file list to stdout
|
||||
|
||||
options - -p = file type 0xca for programs
|
||||
- -t = ASCII text file type 0xee
|
||||
- -l = library/directory file type 0xff
|
||||
- -o = other type 0x00
|
||||
- -a = append entries to current file
|
||||
- -u = username (username)
|
||||
- -d = dirname (directory)
|
||||
- -v = volname (volume)
|
||||
- -b = bootfile name
|
||||
- -i = system image file
|
||||
- -j = j.vfmt filename
|
||||
|
||||
mkdiagtape.c - This program extracts the diag command file (file 2)
|
||||
from a diagnostic tape in .tap format and replaces it
|
||||
with a new command file. The rest of the tape is copied
|
||||
unchanged. The original command file from the diag tape
|
||||
must be extracted from the diag tape using the diagcopy
|
||||
utility. This file can then be deblocked using the deblk
|
||||
utility. The file can then be editied using VI or your
|
||||
favorite editor. Lines must be blank filled to 80 chars
|
||||
exactly after editing. The mpxblk utility must then be
|
||||
used to restore the file to blocked MPX format before
|
||||
installing it on the new diag tape.
|
||||
|
||||
1. mkdir temp; Create temp directory.
|
||||
2. cp diag.tap temp; Copy in current diag tape.
|
||||
3. cd temp; Move to temp directory.
|
||||
4. diagcopy diag.tap; Extract diag tape contents.
|
||||
5. deblk cmdfile >cmd.txt; Creat unblocked text file.
|
||||
6. vi cmd.txt; Edit text file with new commands and save.
|
||||
7. mpxblk <cmd.txt >cmd.blk; Restore blocked file format.
|
||||
8. mkdiagtape -c cmd.txt diag.tap newdiag.tap.
|
||||
9. copy newdiag.tap to execution directory and run sel32.
|
||||
|
||||
command: mkdiagtape -c cmdfile olddiag newdiag
|
||||
intput - simulated in_diagtape
|
||||
output - simulated newtape
|
||||
option - -c cmdfile
|
||||
|
||||
diagcopy - This program reads a SEL .tap diagnostic boot tape and splits
|
||||
the contents into multiple files. The first tape record
|
||||
is 204 bytes of boot code and is put into the file bootcode.
|
||||
The following records in the file contains the diagnostic
|
||||
overlay program (DOL) and are in 7680 byte blocks. The last
|
||||
record can be <= 7680 bytes. The data is put into the file
|
||||
dolfile. The 2nd file on the tape contains the diagnostic
|
||||
auto execute file. It is a MPX blocked file where the first
|
||||
word of each 768 char block contains 0x0003f3b8. It can be
|
||||
read using the deblk utility in the taptools directory.
|
||||
The following diagnostic files on the tape are written to
|
||||
files named diagfileNN where NN is relative file number on
|
||||
the tape. These records are all multiple of 768 bytes each
|
||||
and contain binary programs.
|
||||
|
||||
command: diagcopy diag.tap
|
||||
input - diag.tap file to dump
|
||||
output - stdout filelist and sizes
|
||||
output - if tape contains a valid diag image, it will be
|
||||
output to files bootfile, cmdfile, dolfile and
|
||||
to diagfileNN, where NN is 3 or larger.
|
||||
|
||||
tapdump - This program reads a metadata .tap file and prints a side
|
||||
by side hexdump of the file contents. The records are
|
||||
displayed as 256 byte chuncks. After each record of 256
|
||||
bytes are displayed, hitting C/R will continue dumping,
|
||||
hitting 'q' will terminate the display, and hitting 's'
|
||||
will skip to the next file on the simulated tape.
|
||||
|
||||
command: tapdump <file.tap >stdout
|
||||
input - stdin <file to dump
|
||||
output - stdout
|
||||
|
||||
tap2disk - This program scans a metadata tape (.tap format) and copies
|
||||
a file until EOF is found. Only one file is read from the
|
||||
the tape. This utility is used to transfer tar files from
|
||||
SEL32 UTX to Linux.
|
||||
|
||||
command: tap2disk <input >output
|
||||
input - .tap formatted file being read
|
||||
output - disk file containing .tap file contents
|
||||
|
||||
tape2disk - This program reads a tape assigned as input device. It
|
||||
generates a .tap metadata file. Stdout will contain a
|
||||
listing of the files and sizes written to disk. The define
|
||||
#define FILEMGR must be compiled in for tapes ending with
|
||||
two EOFs. Unix and MPX 1.X filemgr tapes use that format.
|
||||
MPX 3.X volmgr save tapes contain three EOFs so comment out
|
||||
the define for that case.
|
||||
|
||||
command: tape2disk /dev/mt00 [file.tap]
|
||||
input - mag tape device being read
|
||||
output - list of files and sizes read from input tape
|
||||
output - metadata .tap file optionally specified
|
||||
|
||||
disk2tap - This program reads a file assigned as input device. It
|
||||
generates a .tap formatted metadata file. Stdout will
|
||||
display the file name and size written to disk.
|
||||
|
||||
command: disk2tap file [dest.tap]
|
||||
input - input filename being read
|
||||
output - filename and size read from input
|
||||
output - metadata .tap file specified
|
||||
|
||||
tapscan - This program scans a metadata .tap file and prints the
|
||||
file count and sizes. Used to determine the file
|
||||
format contained in the metadata .tap file.
|
||||
|
||||
command: tapscan file.tap >stdout
|
||||
input - file.tap file to scan
|
||||
output - stdout filelist and sizes
|
||||
|
||||
volmcopy - This program reads a MPX 3.X volmgr save tape. The tape
|
||||
must contain a volmgr save image with 6144 byte records
|
||||
containing a list of saved files. Followed by directory
|
||||
entries of 1536 bytes and finally file data of 1 to 8 768
|
||||
byte records. Files larger than 6144 bytes will be output
|
||||
as modulo 6144 bytes. There is an EOF after each file
|
||||
definition. The program will create a directory in the
|
||||
current directory for each different directory. Within
|
||||
each directory each file contained on the tape is extracted
|
||||
and written as binary data to the named file. The .tap
|
||||
file MUST be a volmgr save tape and not a MPX 1.X SDT/save
|
||||
tape.
|
||||
|
||||
command: fmgrcopy file.tap >stdout
|
||||
input - file.tap file to dump
|
||||
output - stdout filelist and sizes
|
||||
output - directory/files extracted to current directory
|
||||
|
||||
General utilities for MPX
|
||||
|
||||
ddump - Create a side by side ASCII dump of a file. Same operation
|
||||
as the DDUMP utility in MPX. 256 bytes are displayed at
|
||||
a time. Hitting C/R will continue to next 256 bytes. A
|
||||
hex address can be input to display data at a given offset
|
||||
in the file. Optionally, the file data can be modified.
|
||||
|
||||
command: ddump -r filename
|
||||
option - -r means open file read only
|
||||
input - filename file to read
|
||||
output - side by size ASCII dump of file
|
||||
|
||||
deblk - read and convert a MPX blocked file to unblocked UNIX file
|
||||
format. Compressed and uncompressed files records can be
|
||||
read. Output is an ASCII string with '\n' termination.
|
||||
|
||||
command: deblk [filename]
|
||||
input - filename or if non specified, stdin
|
||||
output - ASCII sting to stdout
|
||||
|
||||
mpxblk - Create an MPX blocked file from a '\n' terminated ASCII
|
||||
character string file. Trailing blanks are not deleted
|
||||
from the source file. Max line size is 254 bytes.
|
||||
|
||||
command: mpxblk <filein >fileout
|
||||
input - read a '\n' terminated ASCII file from stdin
|
||||
output - write MPX blocked file to stdout
|
||||
|
||||
renum - Create a numbered file from a '\n' terminated ASCII file.
|
||||
The input file is assumed to be a standard UNIX file. The
|
||||
input lines are truncated or expaned to lines of 72 chars.
|
||||
A line number in the form of XXXX.000 is appended to
|
||||
create 80 char '\n' terminated lines.
|
||||
|
||||
command: renum <filein >fileout
|
||||
input - read ASCII file from stdin
|
||||
output - write numbered ASCII file to stdout
|
||||
|
||||
small - Remove line numbers and trailing blanks from an ASCII '\n'
|
||||
terminated file. Lines are terminated at 72 chars and then
|
||||
stripped of trailing blanks. Output is '\n' terminated
|
||||
ASCII files.
|
||||
|
||||
command: small <filein >fileout
|
||||
input - read ASCII file from stdin
|
||||
output - write stripped ASCII file to stdout
|
||||
|
||||
James C. Bevier
|
||||
02/15/2021
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* cutostap.c
|
||||
*
|
||||
* This program scans a metatape file and copies files until EOF is found.
|
||||
* This program has the net effect of removing the sdt image from a file.
|
||||
* The program will make sure 2 eof's and 1 eom are written to the tape.
|
||||
* input - specified filename
|
||||
* output - specified filename
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <stddef.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
#endif
|
||||
//#include <string.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int oldsize, newsize;
|
||||
FILE *outfp;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
int ln;
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
/* int c, i; */
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), sizeof(char), (size_t)4, infp);
|
||||
if (n1 <= 0) {
|
||||
hc = -1; /* at EOM on disk file */
|
||||
return hc; /* return EOM */
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) { /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
return hc; /* return EOM */
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n",
|
||||
filen, lcount, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: EOF after %d records: %d bytes\n\n",
|
||||
filen, count, size);
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
fprintf(stderr, "second EOF after %d files: %d bytes\n",
|
||||
filen-1, tsize+size);
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
|
||||
/* check for EOM */
|
||||
if (hc == -1) {
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, sizeof(char), (size_t)hc, infp);
|
||||
if (n <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), sizeof(char), (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), sizeof(char), (size_t)4, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n",
|
||||
filen, lcount, ln);
|
||||
}
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
void putrec(int cnt, char *buf)
|
||||
{
|
||||
int n1, n2, nw;
|
||||
int hc = (cnt + 1) & ~1; /* make byte count even */
|
||||
|
||||
//printf("writing %d chars\n", cnt);
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((char *)buf, (size_t)1, (size_t)hc, outfp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t buf_size = 256 * 1024;
|
||||
size_t ll, gotboth = 0;
|
||||
int zero = 0;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n",
|
||||
argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// close(inp); /* close input */
|
||||
fclose(infp); /* close input */
|
||||
outfp = fopen(argv[1], "r"); /* reopen */
|
||||
fseek(outfp, 0, SEEK_END); /* seek to end */
|
||||
oldsize = ftell(outfp); /* get filesize in bytes */
|
||||
fclose(outfp); /* now close it */
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n",
|
||||
argv[0], argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
outfp = fopen(argv[2], "w");
|
||||
if (outfp == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open output file %s\n",
|
||||
argv[0], argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* init counts */
|
||||
// ln = -2; /* look for 2 eof */
|
||||
ln = -1; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
|
||||
/* get a 256k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* get buffers until eof */
|
||||
/*domore:*/
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
//printf("got %d char\n", ll);
|
||||
/* we have data to write */
|
||||
putrec(ll, buf); /* write the buffer */
|
||||
gotboth = 0;
|
||||
}
|
||||
//printf("we have EOF or EOM, DONE\n");
|
||||
/* We have EOM, see if EOF's needed */
|
||||
switch (gotboth) {
|
||||
case 0: /* we have written no EOFs, so write two */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
case 1: /* we have written 1 EOF, so write one more */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
default:
|
||||
case 2: /* we have written 2 EOFs, now do EOM */
|
||||
zero = -1;
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
}
|
||||
fprintf(stderr, "EOM after 2 EOFs %d files: %d bytes\n",
|
||||
filen-1, tsize);
|
||||
|
||||
newsize = ftell(outfp); /* get filesize in bytes */
|
||||
fprintf(stderr, "Size of file changed from %d to %d\n",
|
||||
oldsize, newsize);
|
||||
|
||||
/* we done */
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
/*
|
||||
ddump - file dump utility for listing files in side-by-side hex
|
||||
and ascii, plus having the option to modify the file giving
|
||||
a hexadecimal byte offset into the file and the hex data
|
||||
which will be written to the supplied address.
|
||||
|
||||
Usage is:
|
||||
ddump file
|
||||
|
||||
where:
|
||||
file1 is the file to dump and/or modify.
|
||||
|
||||
written by Rick Beery
|
||||
modified many times by Jim Bevier
|
||||
|
||||
The program fd.c written by M. Kraieski has been incorporated
|
||||
into this program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void dodump();
|
||||
int modify();
|
||||
void modify_file();
|
||||
|
||||
int main(argc,args)
|
||||
int argc;
|
||||
char *args[];
|
||||
{
|
||||
FILE *fp, *fopen();
|
||||
/* int i; */
|
||||
/* char *tempstring; */
|
||||
|
||||
if ((argc < 2) || (argc > 3)) {
|
||||
printf("usage: %s [-r] file\n", args[0]);
|
||||
printf(" -r uses read-only mode\n");
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
if (argc == 3)
|
||||
#ifdef mpx
|
||||
/* open read and unblocked */
|
||||
if (strcmp("-r",args[1]) == 0)
|
||||
fp = fopen(args[2],"ru");
|
||||
#else
|
||||
if (strcmp("-r",args[1]) == 0)
|
||||
fp = fopen(args[2],"r");
|
||||
#endif
|
||||
else {
|
||||
printf("Invalid option %s ignored\n", args[1]);
|
||||
#ifdef mpx
|
||||
/* open read/write unblocked */
|
||||
fp = fopen(args[2],"r+u");
|
||||
#else
|
||||
fp = fopen(args[2],"r+");
|
||||
#endif
|
||||
}
|
||||
#ifdef mpx
|
||||
/* open read/write unblocked */
|
||||
else
|
||||
fp = fopen(args[1],"r+u");
|
||||
#else
|
||||
else
|
||||
fp = fopen(args[1],"r+");
|
||||
#endif
|
||||
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open file %s\n", args[0], args[1]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
dodump(fp,0);
|
||||
fclose(fp);
|
||||
} /* end of main */
|
||||
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
void dodump(fp, fileadr)
|
||||
FILE *fp;
|
||||
int fileadr;
|
||||
{
|
||||
char buff[257];
|
||||
int file_byte_count=0, curchar, buffptr, bufflen;
|
||||
|
||||
buffptr = 0;
|
||||
bufflen = 16;
|
||||
|
||||
fseek(fp,fileadr,0);
|
||||
while ((curchar = getc(fp)) != EOF) {
|
||||
file_byte_count++;
|
||||
if (!buffptr)
|
||||
printf(" %06x : ",fileadr);
|
||||
printf("%02x",curchar);
|
||||
buff[buffptr++] = PRINTABLE(curchar);
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
if (buffptr >= bufflen) {
|
||||
buff[buffptr] = 0;
|
||||
printf(" |%s|\n",buff);
|
||||
buffptr = 0;
|
||||
fileadr += bufflen;
|
||||
if (!(file_byte_count % 256)) {
|
||||
modify_file(fp);
|
||||
} /* end of if */
|
||||
} /* end of if */
|
||||
} /* end of while */
|
||||
|
||||
if (buffptr) {
|
||||
buff[buffptr] = 0;
|
||||
while (buffptr++ < bufflen) {
|
||||
printf(" ");
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
} /* end of while */
|
||||
printf(" |%s|\n",buff);
|
||||
} /* end of if */
|
||||
modify_file(fp);
|
||||
return;
|
||||
} /* end of dodump */
|
||||
|
||||
int modify(fp1)
|
||||
FILE *fp1;
|
||||
{
|
||||
char hexstring[33];
|
||||
int num_chars, digit, i, byte=0, /*stat,*/ file_offset=0, indx=0;
|
||||
int power();
|
||||
void gethex_string();
|
||||
int asciihex_digit_to_decimal();
|
||||
|
||||
gethex_string(hexstring);
|
||||
num_chars = strlen(hexstring);
|
||||
for (i=num_chars-1; i>=0; i--) {
|
||||
digit = asciihex_digit_to_decimal(hexstring[indx++]);
|
||||
file_offset += digit*power(16,i);
|
||||
} /* end of for */
|
||||
if ((fseek(fp1,file_offset,0)) != -1) {
|
||||
/* read characters from the terminal */
|
||||
printf("\nenter new hex data > ");
|
||||
gethex_string(hexstring);
|
||||
num_chars = strlen(hexstring);
|
||||
|
||||
/* convert character to numeric field and
|
||||
new set of data at offset in file specified */
|
||||
for (i=0; i<num_chars; i++) {
|
||||
digit = asciihex_digit_to_decimal(hexstring[i]);
|
||||
if ((i%2)) {
|
||||
byte = byte*16 + digit;
|
||||
fputc(byte, fp1);
|
||||
byte = 0;
|
||||
}
|
||||
else {
|
||||
byte = digit;
|
||||
}
|
||||
} /* end of for */
|
||||
} /* end of "if" part of if - else */
|
||||
else {
|
||||
printf("Unable to seek to that address\n");
|
||||
file_offset = 0;
|
||||
} /* end of if - else */
|
||||
return(file_offset);
|
||||
} /* end of modify */
|
||||
|
||||
void gethex_string(hex)
|
||||
char *hex;
|
||||
{
|
||||
char c;
|
||||
int indx=0;
|
||||
|
||||
while ((c=getchar()) != '\n' ) {
|
||||
if ((c>='0' && c<='9') || (c>='a' && c<='f'))
|
||||
hex[indx++] = c;
|
||||
else {
|
||||
while ((c=getchar()) != '\n')
|
||||
;
|
||||
indx = 0;
|
||||
printf("Invalid hex number; please re-enter > ");
|
||||
}
|
||||
}
|
||||
hex[indx] = '\0';
|
||||
} /* end of gethex_string */
|
||||
|
||||
int asciihex_digit_to_decimal(c)
|
||||
char c;
|
||||
{
|
||||
int digit;
|
||||
|
||||
if (c >= 'a' && c <= 'f')
|
||||
digit = c - 'a' + 10;
|
||||
else
|
||||
if (c >= '0' && c <= '9')
|
||||
digit = c -'0';
|
||||
else
|
||||
digit = -1; /* error */
|
||||
return(digit);
|
||||
} /* end of asciihex_digit_to_decimal */
|
||||
|
||||
int power(x,n)
|
||||
int x, n;
|
||||
{
|
||||
int p;
|
||||
|
||||
for (p=1; n>0; --n)
|
||||
p = p*x;
|
||||
return (p);
|
||||
} /* end of routine power */
|
||||
|
||||
void modify_file(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
int ans, modify(),modified_addr;
|
||||
|
||||
printf("\n hex address, <cr> - continue, q = quit > ");
|
||||
ans = getchar();
|
||||
if ((ans>='0' && ans<='9') || (ans>='a' && ans<='f')) {
|
||||
ungetc(ans, stdin);
|
||||
modified_addr = modify(fp);
|
||||
printf("\n");
|
||||
dodump(fp, (modified_addr/256)*256);
|
||||
} /* end of "if" part of if - then */
|
||||
else {
|
||||
if (ans == 'q') {
|
||||
fclose(fp);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
if (ans != '\n')
|
||||
while ((ans=getchar()) != '\n')
|
||||
;
|
||||
}
|
||||
} /* end of if -then */
|
||||
} /* end of modify_file */
|
||||
@@ -1,604 +0,0 @@
|
||||
/*
|
||||
* deblk.c
|
||||
*
|
||||
* This program reads MPX blocked and/or MPX compressed files and
|
||||
* deblocks blocked files and uncompresses compressed files and
|
||||
* deletes trailing blanks from a source file. The program will
|
||||
* also process standard ASCII newline ('\n') terminated files.
|
||||
* input - [filename] or stdin
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
/*
|
||||
* MPX blocked file format
|
||||
* bytes 0-1 - not used and are zero
|
||||
* bytes 2-3 - next record position in buffer
|
||||
* byte 4 - start/end of block flag
|
||||
* - 0x20 - EOB end of block
|
||||
* - 0x40 - BOB start of block
|
||||
* byte 5 - last record byte count
|
||||
* byte 6 - this blocks flags
|
||||
* - 0x00 - valid data
|
||||
* - 0x20 - EOB end of block
|
||||
* - 0x80 - EOF end of file
|
||||
* - 0xa0 - EOB/EOF end of file
|
||||
* byte 7 - bytes in this record
|
||||
* data byte - cnt data bytes
|
||||
* byte cnt+4- 0x20 EOB status
|
||||
* byte cnt+5- last record count
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compressed record
|
||||
* byte 0 - 0xbf -> start of record
|
||||
* 0x9f -> start of next record
|
||||
* byte 1 - record count
|
||||
* byte 2 - high order byte of 16 bit checksum
|
||||
* byte 3 - low order byte of 16 bit checksum
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* An O.S. compressed record consists of 120 bytes:
|
||||
*
|
||||
* 6 Control bytes and 114 bytes of compressed source
|
||||
*
|
||||
* (The last record can be less than 120 bytes, on that
|
||||
* record the compressed source will be from 4-114 bytes).
|
||||
*
|
||||
* 6 Control bytes
|
||||
*
|
||||
* 1 Byte- Data type code bf or 9f (9f means this is last record)
|
||||
* 1 Byte- Size of compressed record (- 6 for control bytes)
|
||||
* (Usually 114 (72(x)) is the size except last record)
|
||||
* 2 Byte- Checksum
|
||||
* 2 Byte- Record sequence number (starting from zero)
|
||||
*
|
||||
* 4-114 Bytes of one or more groups of compressed source as follows:
|
||||
*
|
||||
* A compressed group consists of:
|
||||
* A blank count byte, a data count byte, data.
|
||||
*
|
||||
* Compressed groups are repeated and terminated by an ff char.
|
||||
* Compressed groups are usually terminated at 114 chars by
|
||||
* the ff char unless this is the last record in the file.
|
||||
*
|
||||
* A line of text usually is compressed as follows:
|
||||
* A blank count byte, a data count byte, compressed data
|
||||
* (one or more of these compressed groups for up to 72 chars of source)
|
||||
* followed by a blank count byte,a data count byte (of 8),
|
||||
* data (8 char sequence number), terminated by a ff char.
|
||||
*
|
||||
* A workfile logical compressed line is similiar to the O.S.
|
||||
* logical compressed line except that an 8 char sequence number
|
||||
* always exists in the workfile format and it is always first
|
||||
* rather than at the end of the record (if sequence numbers did
|
||||
* not exist in columns 73-80 in the O.S. original compressed
|
||||
* records than the editor generates them). Preceding the workfile
|
||||
* compressed record is a 2 byte previous record in the page pointer.
|
||||
* Also note that workfiles are not blocked by the O.S., but have
|
||||
* their own structure of headers, data space, and free space.
|
||||
*
|
||||
* If the sequence number does not exist or the period is not in
|
||||
* the proper place (nnnn.nnn) or the sequence number contains
|
||||
* anything other than numbers, then the editor will generate
|
||||
* its own sequence number.
|
||||
*
|
||||
* The first blank count can range from 0-80 blank chars
|
||||
* subsequent blank counts can range from 3-79 max. That is
|
||||
* since it takes 2 bytes to do blank compression (a blank count
|
||||
* and a data count), only 3 or more blank chars after the first
|
||||
* non-blank char in a line are compressed.
|
||||
* Records to be compressed are assumed to be 80 chars or less
|
||||
* (including an 8 char sequence number).
|
||||
*
|
||||
* The checksum is simply the addition of all the 120 chars in the
|
||||
* compressed record except for the 6 control bytes.
|
||||
*
|
||||
* The smallest compressed line consists of 14 chars:
|
||||
* A blank count byte (of 71), a data count byte (of 8),
|
||||
* data (an 8 char sequence number, a blank count byte (of zero),
|
||||
* a data count byte (of 1), data (one char), and an ff terminator
|
||||
* compressed record format can be processed only by the following:
|
||||
*
|
||||
* Assembler, P4, Source Update, Editor and some functions of Media
|
||||
* and of course some utility programs like flip.
|
||||
*
|
||||
* Note that a text line can be spread across several compressed
|
||||
* records.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define BLKSIZE 768 /* MPX block file sector size */
|
||||
extern int rbl();
|
||||
extern int getloi(); /* right from my mind */
|
||||
extern int putloi(); /* write line */
|
||||
|
||||
/* read file and output to stdout */
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *fp, *fopen();
|
||||
unsigned char s[BUFSIZ];
|
||||
|
||||
if(argc == 1) { /* no args; copy std in */
|
||||
while (1) {
|
||||
if (rbl(stdin, s, BUFSIZ) <= 0) /* read til EOF */
|
||||
exit(0);
|
||||
putloi(s);
|
||||
}
|
||||
} else {
|
||||
while (--argc > 0)
|
||||
if ((fp = fopen(*++argv, "r")) == NULL) {
|
||||
fprintf(stderr, "list: can't open %s\n", *argv);
|
||||
exit(1);
|
||||
} else {
|
||||
while (1) {
|
||||
if (rbl(fp, s, BUFSIZ) <= 0) /* read til EOF */
|
||||
exit(0);
|
||||
putloi(s);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function computes and checks the checksum of a compressed file
|
||||
*/
|
||||
int checksum(buf)
|
||||
unsigned char *buf;
|
||||
{
|
||||
int i = 0;
|
||||
short int ccs = 0; /*zero checksum */
|
||||
/* get checksum */
|
||||
unsigned int rcs = (((buf[2] << 8) & 0xff00) | (buf[3] & 0xff));
|
||||
int cnt = buf[1] & 0xff; /* record count */
|
||||
//fprintf(stderr, "checksum cnt %x data %x %x %x %x %x %x %x %x\n",
|
||||
// cnt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
|
||||
|
||||
while (cnt > 0) {
|
||||
unsigned short v = buf[i+6] & 0xff;
|
||||
ccs += v; /* add the byte */
|
||||
//fprintf(stderr, "checksum cnt %x val %x sum %x\n", i, v, ccs);
|
||||
i++; /* bump address */
|
||||
cnt--; /* reduce count */
|
||||
}
|
||||
//fprintf(stderr, "checksum size %x read %x calc %x\n", buf[1], rcs, ccs);
|
||||
if (ccs == rcs)
|
||||
return 0; /* return OK */
|
||||
return 1; /* return error */
|
||||
}
|
||||
|
||||
int bin = 0;
|
||||
unsigned char si[BLKSIZE];
|
||||
unsigned char bi[BLKSIZE];
|
||||
int ubdp = 0; /* unblocked data pointer */
|
||||
int ubdc = 0; /* unblocked data count */
|
||||
int bdp = 0; /* blocked data pointer */
|
||||
int bdc = 0; /* blocked data count */
|
||||
short filetype = 0;
|
||||
|
||||
#define unknown 0x00
|
||||
#define blocked 0x01
|
||||
#define compress 0x02
|
||||
#define ascii 0x04
|
||||
|
||||
/*
|
||||
* This function reads MPX blocked files
|
||||
*/
|
||||
int readbb(fp, ip, cnt)
|
||||
FILE *fp;
|
||||
char *ip;
|
||||
int cnt;
|
||||
{
|
||||
int c;
|
||||
int i = 0;
|
||||
|
||||
if (bin == 0) {
|
||||
//fprintf(stderr, "read sector a\n");
|
||||
if (fread(si, 1, BLKSIZE, fp) <= 0)
|
||||
return (0); /* this means eof */
|
||||
bin = 6;
|
||||
}
|
||||
/* check for EOF */
|
||||
if (si[bin] & 0x80) {
|
||||
bin = 0;
|
||||
return(0); /* we have EOF */
|
||||
}
|
||||
/* check for EOB in last record */
|
||||
if (si[bin - 2] & 0x20) {
|
||||
//fprintf(stderr, "read sector b\n");
|
||||
if (fread(si, 1, BLKSIZE, fp) <= 0)
|
||||
return (0); /* this means eof */
|
||||
bin = 6;
|
||||
}
|
||||
//fprintf(stderr, "copy block from sector @ bin %x\n", bin);
|
||||
/* copy the block into users buffer */
|
||||
if ((c = si[bin+1]) > 0) {
|
||||
for (i = 0; i < c; i++) {
|
||||
ip[i] = si[bin + 2 + i];
|
||||
if (i >= cnt)
|
||||
break;
|
||||
}
|
||||
bin += (c + 4);
|
||||
ip[i] = '\0';
|
||||
return (i);
|
||||
}
|
||||
bin = 0;
|
||||
return (i);
|
||||
}
|
||||
|
||||
/* function to read a byte from an unblocked file */
|
||||
int getb(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
int c;
|
||||
static int goteof = 0;
|
||||
|
||||
/* file is unblocked, get next record */
|
||||
if (goteof) {
|
||||
goteof = 0;
|
||||
//fprintf(stderr, "getb - returning EOF ubdc=%x\n", ubdc);
|
||||
return (-1); /* this means eof */
|
||||
}
|
||||
if (ubdp < ubdc) /* is count exhausted */
|
||||
c = si[ubdp++] & 0xff; /* copy char */
|
||||
if (ubdp >= ubdc) { /* is count exhausted */
|
||||
/* need to read next block, if not first time */
|
||||
/* we need a new buffer */
|
||||
/* read in 768 byte block of the file */
|
||||
if ((ubdc = fread(si, 1, BLKSIZE, fp)) <= 0)
|
||||
goteof = 1; /* this means eof */
|
||||
//fprintf(stderr, "getb - read unblocked file goteof %x ubdc=%x\n", goteof, ubdc);
|
||||
ubdp = 0;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
/* get a line of input */
|
||||
int getloi(fp, s, lim) /* right from my mind */
|
||||
FILE *fp;
|
||||
unsigned char s[];
|
||||
int lim;
|
||||
{
|
||||
int c, i, cc, bc = 0, rc = 0;
|
||||
|
||||
/* see how we are to process data */
|
||||
if (filetype & blocked) {
|
||||
/* file is blocked, get next record */
|
||||
if (bdp == 0) {
|
||||
/* we need a new buffer */
|
||||
/*newbuf:*/
|
||||
if ((bdc = readbb(fp, bi, lim)) <= 0)
|
||||
return (0); /* this means eof */
|
||||
//fprintf(stderr, "getloi read blocked file %x\n", bdc);
|
||||
bdp = 0;
|
||||
}
|
||||
/* check for compressed data */
|
||||
if (filetype & compress) {
|
||||
if ((bi[bdp] & 0x9f) != 0x9f) {
|
||||
fprintf(stderr, "blocked compressed file read error %x\n", bi[bdp]);
|
||||
return (0); /* this means error */
|
||||
}
|
||||
/* checksum the record */
|
||||
if (checksum(&bi[bdp])) {
|
||||
fprintf(stderr, "blocked compressed file checksum error\n");
|
||||
return (0); /* this means error */
|
||||
}
|
||||
//fprintf(stderr, "getloi blocked compressed file checksum OK @ %x cnt %x\n", bdp, bdc);
|
||||
/* copy in the next record */
|
||||
/* get chars until EOF or limit reached */
|
||||
cc = bi[bdp+1]+6; /* get count */
|
||||
for (i = 0; (--lim > 0) && (i < cc); i++) {
|
||||
s[rc++] = bi[bdp++]; /* copy char */
|
||||
}
|
||||
if ((bdp >= bdc) || (i == cc)) {
|
||||
bdp = 0; /* read new buffer next time */
|
||||
//fprintf(stderr, "getloi blocked compressed read return %x bdc %x bdp %x\n", rc, bdc, bdp);
|
||||
}
|
||||
return (rc); /* return data count */
|
||||
}
|
||||
/* file is uncompressed, so copy MPX records */
|
||||
//fprintf(stderr, "getloi blocked data rc=%x bdc=%x\n", rc, bdc);
|
||||
for (i=0; i<bdc; i++)
|
||||
s[rc++] = bi[bdp++]; /* copy chars */
|
||||
s[rc++] = 0; /* null terminate */
|
||||
bdp = 0; /* read next buffer */
|
||||
return (i); /* return data */
|
||||
}
|
||||
else {
|
||||
/* check for compressed data */
|
||||
if (filetype & compress) {
|
||||
cc = 120;
|
||||
rc = 0;
|
||||
bc = 0;
|
||||
while ((c = getb(fp)) != -1) {
|
||||
/* make sure this is a compressed record */
|
||||
if ((rc == 0) && ((c & 0x9f) != 0x9f)) {
|
||||
fprintf(stderr,
|
||||
"getloi - unblocked compressed file read error %x rc %x\n", c, rc);
|
||||
return (0); /* this means error */
|
||||
}
|
||||
if (rc == 1)
|
||||
cc = c + 6; /* get 'real' record count */
|
||||
s[rc++] = c; /* save the char */
|
||||
|
||||
if (rc == cc) /* compressed record is always <= 120 char buffers */
|
||||
break; /* done */
|
||||
}
|
||||
if (c == -1)
|
||||
return (0); /* this means EOF */
|
||||
|
||||
/* skip any extra chars from short records */
|
||||
bc = rc;
|
||||
while ((s[0] != 0x9f) && (bc < 120)) {
|
||||
if ((c = getb(fp)) == -1)
|
||||
return (0); /* this means EOF */
|
||||
s[bc++] = c; /* fill extra chars */
|
||||
//fprintf(stderr, "getloi - filling extra chars with char %x bc %x\n", c, bc);
|
||||
}
|
||||
/* next char should be bf/9f */
|
||||
if ((si[ubdp] & 0x9f) != 0x9f) { /* copy char */
|
||||
if ((c = getb(fp)) == -1) {
|
||||
//fprintf(stderr, "getloi skipping exit char %0x at end of line, next %x s[0] %0x\n", c, si[ubdp], s[0]);
|
||||
if (s[0] != 0x9f)
|
||||
return (0); /* this means EOF */
|
||||
}
|
||||
//fprintf(stderr, "getloi skipping char %0x at end of line, next %x s[0] %0x\n", c, si[ubdp], s[0]);
|
||||
}
|
||||
|
||||
//fprintf(stderr, "getloi unblked comp read done rc %x cc %x s[0] %x s[rc-1] %x next %x\n",
|
||||
//rc, cc, s[0], s[rc-1], si[ubdp]);
|
||||
|
||||
/* checksum the record */
|
||||
if (checksum(s)) {
|
||||
fprintf(stderr, "getloi - unblocked compressed file checksum error\n");
|
||||
//fprintf(stderr, "getloi A unblocked compressed read return rc=%x cc=%x %x %x\n", rc, cc, s[0], s[rc-1]);
|
||||
//fprintf(stderr, "getloi C unblocked compressed read return %x ubdc %x ubdp %x\n", rc, ubdc, ubdp);
|
||||
return (0); /* this means error */
|
||||
}
|
||||
//fprintf(stderr, "getloi B unblocked compressed read return rc=%x cc=%x %x\n", rc, cc, s[1]);
|
||||
return (rc); /* return data count */
|
||||
}
|
||||
/* file is uncompressed, so copy UNIX records */
|
||||
while ((c = getb(fp)) != -1) {
|
||||
s[rc++] = c; /* save the char */
|
||||
if (c == 0x0a) {
|
||||
//fprintf(stderr, "getloi C unblocked compressed read return %x ubdc %x ubdp %x\n", rc, ubdc, ubdp);
|
||||
s[rc++] = 0; /* terminate the line */
|
||||
return (rc); /* return data */
|
||||
}
|
||||
}
|
||||
return (0); /* EOF */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
** output line of text from the source
|
||||
*/
|
||||
int putloi(s)
|
||||
unsigned char *s;
|
||||
{
|
||||
printf("%s", s);
|
||||
return(0);
|
||||
}
|
||||
|
||||
unsigned char line[BUFSIZ];
|
||||
unsigned char line2[BUFSIZ];
|
||||
int cmpop = 0;
|
||||
int cmpflg = 0;
|
||||
int bcnt = 0;
|
||||
unsigned char *bptr = 0;
|
||||
int binary = 1;
|
||||
int recl = 0;
|
||||
int ubin = 0;
|
||||
|
||||
/* read lines of data from the source file */
|
||||
/* files can be blocked w/wo compression */
|
||||
/* files can be blocked ascii */
|
||||
/* files can be byte strings, newline terminated */
|
||||
int rbl(fp, buf, n)
|
||||
FILE *fp;
|
||||
unsigned char *buf;
|
||||
int n;
|
||||
{
|
||||
register int count = 0;
|
||||
/* register unsigned char *cp; */
|
||||
int i;
|
||||
unsigned char *linadrs = line;
|
||||
|
||||
if (filetype == unknown) { /* see if we know type of file to read */
|
||||
bin = 0;
|
||||
ubin = 0;
|
||||
bdp = 0;
|
||||
bdc = 0;
|
||||
ubdp = 0;
|
||||
ubdc = 0;
|
||||
/* read in 1st 768 Byte block of the file */
|
||||
if ((ubdc = fread(si, 1, BLKSIZE, fp)) <= 0)
|
||||
return (0); /* this means eof */
|
||||
/* test 1st byte for 0x06 and bytes 2, 3, and 4 zero */
|
||||
if ((si[0] == 0x06) && (si[1] == 0) && (si[2] == 0) && (si[3] == 0)) {
|
||||
/* we have a library file, giver error and abort */
|
||||
fprintf(stderr, "deblk - Cannot list library file, aborting\n");
|
||||
return (0); /* this means error exit */
|
||||
}
|
||||
/* test for a directory file, 8 ascii char then 4 zeros */
|
||||
if ((si[8] == 0) && (si[9] == 0) && (si[10] == 0) && (si[11] == 0)) {
|
||||
for (i=0; i<8; i++) {
|
||||
if (!isprint(si[i])) {
|
||||
/* unknown file type, abort */
|
||||
fprintf(stderr, "deblk - Unknown binary file type, aborting\n");
|
||||
return (0); /* this means error exit */
|
||||
}
|
||||
}
|
||||
/* must be directory, abort */
|
||||
fprintf(stderr, "deblk - Cannot list directory file, aborting\n");
|
||||
return (0); /* this means error exit */
|
||||
}
|
||||
i = ((si[2] << 8) & 0xff00) | (si[3] & 0xff); /* get file offset pointer, bytes 2 & 3 */
|
||||
/* test 1st 2 byte of file for zero */
|
||||
if ((si[0] == 0) && (si[1] == 0) && (i < BLKSIZE)) {
|
||||
/* most likely blocked file if 1st 2 bytes 0 and next 2 bytes are less than 768 */
|
||||
filetype |= blocked; /* we have blocked file */
|
||||
bin = 6; /* where we start for data block */
|
||||
|
||||
/* see if we have compressed data */
|
||||
if ((si[bin + 2] == 0xbf) || (si[bin + 2] == 0x9f)) {
|
||||
filetype |= compress; /* data is compressed */
|
||||
bcnt = 0; /* no data in buffer */
|
||||
}
|
||||
else {
|
||||
/* data is not compressed, just ascii without newlines */
|
||||
filetype |= ascii; /* blocked ascii data */
|
||||
}
|
||||
}
|
||||
else
|
||||
/* test for a diag blocked ascii file */
|
||||
/* test 1st 2 byte of file for zero */
|
||||
if ((si[0] == 0) && (si[1] == 3) && (i == 0xf3b8)) {
|
||||
filetype |= blocked; /* we have blocked file */
|
||||
bin = 6; /* where we start for data block */
|
||||
|
||||
/* see if we have compressed data */
|
||||
if ((si[bin + 2] == 0xbf) || (si[bin + 2] == 0x9f)) {
|
||||
filetype |= compress; /* data is compressed */
|
||||
bcnt = 0; /* no data in buffer */
|
||||
}
|
||||
else {
|
||||
/* data is not compressed, just ascii without newlines */
|
||||
filetype |= ascii; /* blocked ascii data */
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* data is unblocked, see if compressed or not */
|
||||
if ((si[ubin] == 0xbf) || (si[ubin] == 0x9f)) {
|
||||
filetype |= compress; /* data is compressed */
|
||||
bcnt = 0; /* no data in buffer */
|
||||
}
|
||||
else
|
||||
if ((si[ubin] == 0xef) || (si[ubin] == 0xcf))
|
||||
{
|
||||
/* file is an macro library, so abort */
|
||||
fprintf(stderr, "deblk - Cannot list macro library file, aborting\n");
|
||||
return (0); /* this means error exit */
|
||||
}
|
||||
else {
|
||||
/* data is not compressed or blocked, just ascii with newlines */
|
||||
filetype |= ascii; /* blocked ascii data */
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((filetype & compress) && !cmpop) { /* see if we tested for compressed */
|
||||
cmpop = 1; /* set compresse tested flag */
|
||||
/* read in the first record */
|
||||
if ((recl = getloi(fp, line, BUFSIZ)) == 0)
|
||||
return (0); /* this means eof */
|
||||
linadrs = line;
|
||||
if (*linadrs == 0xbf) { /* is this file compressed */
|
||||
cmpflg = 1; /* set comp data flag */
|
||||
bcnt = linadrs[1]; /* set record count */
|
||||
bptr = &linadrs[6]; /* set data address */
|
||||
//fprintf(stderr, "rbl - read 1st compressed record cnt %x %x\n", bcnt, linadrs[0]);
|
||||
}
|
||||
else
|
||||
goto re00;
|
||||
}
|
||||
|
||||
if (cmpflg) { /* reading compressed data? */
|
||||
if (bcnt == 0) { /* any data left in buffer */
|
||||
re18:
|
||||
/* read in a data record */
|
||||
if ((recl = getloi(fp, line, BUFSIZ)) == 0)
|
||||
return (0); /* this means eof */
|
||||
linadrs = line;
|
||||
//fprintf(stderr, "rbl re18 - read compressed record recl %x cnt %x 1st %x\n", recl, bcnt, linadrs[0]);
|
||||
if ((*linadrs & 0x9f) != 0x9f) /* is this valid rec */
|
||||
return (EOF); /* error if not */
|
||||
bcnt = linadrs[1]; /* set record count */
|
||||
bptr = &linadrs[6]; /* set data address */
|
||||
//fprintf(stderr, "rbl - read nth compressed record cnt %x %x\n", bcnt, linadrs[0]);
|
||||
}
|
||||
re20:
|
||||
/* see if any blanks */
|
||||
if (i = *bptr++) { /* next buffer pointer */
|
||||
if (i == 0xff)
|
||||
goto re60; /* if eol, get out */
|
||||
/* insert the required number of blanks */
|
||||
while (i--) {
|
||||
if (count < n) {
|
||||
*buf++ = ' '; /* put blank in buffer */
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (--bcnt <= 0)
|
||||
goto re18; /* read next record */
|
||||
|
||||
/* get character count */
|
||||
if (i = *bptr++) { /* next buffer pointer */
|
||||
/*try*/ if (i == 0xff)
|
||||
/*0216*/ goto re60; /* if eol, get out */
|
||||
while (i--) {
|
||||
if (count < n)
|
||||
*buf++ = *bptr; /* put char in buffer */
|
||||
bcnt--; /* decr count */
|
||||
bptr++; /* next buffer pointer */
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (--bcnt <= 0)
|
||||
goto re18; /* read next record */
|
||||
goto re20;
|
||||
|
||||
re60:
|
||||
bcnt--; /* decr count */
|
||||
if ((*--buf == ' ') && (count == 1)) {
|
||||
*buf = '\n'; /* put new line at eol */
|
||||
}
|
||||
else {
|
||||
*++buf = '\n'; /* put new line at eol */
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* non compressed read here */
|
||||
/* read the next record */
|
||||
if ((recl = getloi(fp, line, BUFSIZ)) == 0)
|
||||
return (0); /* this means eof */
|
||||
linadrs = line; /* reset line pointer */
|
||||
|
||||
re00:
|
||||
//fprintf(stderr, "rbl - read nth uncompressed record cnt %x %s\n", recl, line);
|
||||
#if 0
|
||||
/* here we need to strip off blank put in during write */
|
||||
/* this is because mpx does not support zero length blocks */
|
||||
if ((recl == 1) && (*linadrs == ' ')) {
|
||||
recl = 0;
|
||||
/* now append new line to end of buffer */
|
||||
if (!binary)
|
||||
line[recl] = '\n';
|
||||
}
|
||||
#endif
|
||||
count = 0;
|
||||
/* copy this layer buffer to upper caller's buffer */
|
||||
while ((count < n) && (count < recl)) {
|
||||
buf[count] = line[count];
|
||||
count++;
|
||||
}
|
||||
/* if no newline, add one and null terminate */
|
||||
if (line[count-1] != '\n')
|
||||
buf[count++] = '\n';
|
||||
buf[count] = '\0';
|
||||
}
|
||||
//fprintf(stderr, "rbl - read return cnt %x\n", count);
|
||||
return (count);
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
/*
|
||||
* diagcopy.c
|
||||
*
|
||||
* This program scans a diag metatape file and prints file count and
|
||||
* sizes. In addition, it creates a boot directory for the boot code,
|
||||
* a cmd directory for the cmd file, and a diag directory with a file
|
||||
* for each defined diagnostic. The file must be a bootable diagnostic
|
||||
* tape in .tap format. The output files are non .tap format, i.e. just
|
||||
* binary output of each file.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
//#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int lfilen, filen = 1;
|
||||
int diag = 0;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp, outp;
|
||||
FILE *infp, *outfp;
|
||||
int smd = 0;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
/* int c, i; */
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
// printf("EOF found after file %d\n", filen);
|
||||
lfilen = filen;
|
||||
filen++; /* set next file number */
|
||||
smd = 1; /* look for smd again */
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1) {
|
||||
printf("EOM found after file %d\n", filen);
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll;
|
||||
// char path[64], command[128];
|
||||
int boot = 0;
|
||||
int dol = 0;
|
||||
int sdt = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
printf("%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
//fprintf(stderr, "Can't allocate memory for tscan\n");
|
||||
printf("Can't allocate memory for tscan\n");
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
printf("got ll = %d filen %d\n", ll, filen);
|
||||
if (ll == 204) {
|
||||
diag = 1; /* process diag boot record */
|
||||
printf("process diag ll = %d\n", ll);
|
||||
}
|
||||
if ((dol == 1) || ((ll == 7680) && (diag))) {
|
||||
dol = 1; /* process DOL record */
|
||||
printf("process dol ll = %d\n", ll);
|
||||
}
|
||||
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
printf("\nfile complete %d:\n", filen);
|
||||
break;
|
||||
//continue; /* go look for another SDT bootfile or SMD entry */
|
||||
} else
|
||||
if (ll == 1920) {
|
||||
printf("File is a MPX SDT tape and can not be processed!\n");
|
||||
break;
|
||||
} else
|
||||
if (ll == 4608) {
|
||||
printf("File is a MPX filemgr save tape and can not be processed!\n");
|
||||
break;
|
||||
} else
|
||||
if ((diag == 0) && (ll != 204)) {
|
||||
printf("File type is unknown and can not be processed!\n");
|
||||
break;
|
||||
} else {
|
||||
int cc = 0;
|
||||
// unsigned int curchar;
|
||||
char filename[16];
|
||||
// int i, j, m;
|
||||
|
||||
/* A diag tape has a 204 byte boot loader in the first record. */
|
||||
/* It is followed by multiple 7680 byte records of the diagnostic */
|
||||
/* overlay loader (DOL) */
|
||||
|
||||
if (diag == 1) {
|
||||
int no, ct = 0;;
|
||||
/* get more diag data */
|
||||
/* open output file, create it if necessary */
|
||||
// if (outp == -1) {
|
||||
if (outfp == NULL) {
|
||||
sprintf(filename, "bootfile\0");
|
||||
// if ((outp = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(filename, "w")) == NULL) {
|
||||
printf("Can't open bootfile\n");
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
printf("got2 ll = %d writing to bootfile -> %s\n", ll, filename);
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file bootfile\n", no, ll);
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* now put the rest of the code in another file */
|
||||
sprintf(filename, "dolfile");
|
||||
// if ((outp = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(filename, "w")) == NULL) {
|
||||
printf("Can't open dolfile\n");
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
ct++;
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file dolfile\n", no, ll);
|
||||
}
|
||||
diag = 2;
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
printf("wrote %d records to dolfile %s\n", ct, filename);
|
||||
continue; /* go look for diag command file */
|
||||
} else
|
||||
if (diag == 2) {
|
||||
/* read the command file in and write to cmdfile */
|
||||
int no, ct = 0;;
|
||||
/* get more data */
|
||||
/* open output file, create it if necessary */
|
||||
// if (outp == -1) {
|
||||
if (outfp == NULL) {
|
||||
sprintf(filename, "cmdfile\0");
|
||||
// if ((outp = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(filename, "w")) == NULL) {
|
||||
printf("Can't open cmdfile\n");
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
printf("got2 ll = %d writing to cmdfile -> %s\n", ll, filename);
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file cmdfile\n", no, ll);
|
||||
|
||||
/* now put the rest of the code in the file */
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
ct++;
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file cmdfile\n", no, ll);
|
||||
}
|
||||
diag = 3;
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
printf("wrote %d records to cmdfile %s\n", ct, filename);
|
||||
continue; /* go look for diag command file */
|
||||
} else
|
||||
if (diag == 3) {
|
||||
/* read the diag file in and write to diagfile */
|
||||
int no, ct = 0;;
|
||||
/* get more data */
|
||||
/* open output file, create it if necessary */
|
||||
// if (outp == -1) {
|
||||
if (outfp == NULL) {
|
||||
sprintf(filename, "diagfile%02d\0", filen);
|
||||
// if ((outp = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(filename, "w")) == NULL) {
|
||||
printf("Can't open %s\n", filename);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
printf("got2 ll = %d writing to %s\n", ll, filename);
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file %s\n", no, ll, filename);
|
||||
|
||||
/* now put the rest of the code in the file */
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
ct++;
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
printf("write (%d) != read (%d) on file %s\n", no, ll, filename);
|
||||
}
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
printf("wrote %d records to cmdfile %s\n", ct, filename);
|
||||
continue; /* go look for diag command file */
|
||||
} /* read cmd file records */
|
||||
} /* process read of tape */
|
||||
} /* end of getloi read */
|
||||
/*dostop:*/
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
* MPX uses 2 EOF in a row to separate sections of MPX3.x master SDT tapes.
|
||||
* It uses 3 EOF in a row to indicate the EOT on MPX 3.X tapes. So we
|
||||
* cannot assume EOT is at the 1st or 2nd EOF in a row. Keep looking
|
||||
* for a third one. Comment out the #define FMGRTAPE below to read an
|
||||
* MPX 3.x master SDT. For user SDT tapes or MPX 1.X master SDT tapes
|
||||
* leave the #define FMGRTAPE uncommented so it will be defined. The
|
||||
* program will stop on two EOFs. For non MPX tapes, the 2nd EOF means
|
||||
* EOT. Some tapes have only one EOT and will terminate on EOT detected.
|
||||
* Leave off the output file name to just scan the tape and output record
|
||||
* sizes and counts.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <signal.h>
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <sys/fcntl.h>
|
||||
//#include <sys/mtio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <unistd.h>
|
||||
//#include <limits.h>
|
||||
//#include <errno.h>
|
||||
|
||||
//#define FMGRTAPE /* defined for filemgr tapes, undefined for volmgr tape */
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 uint8;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef signed __int64 t_int64;
|
||||
typedef unsigned __int64 t_uint64;
|
||||
typedef t_int64 off_t;
|
||||
#else
|
||||
/* All modern/standard compiler environments */
|
||||
/* any other environment needa a special case above */
|
||||
#include <stdint.h>
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif /* end standard integers */
|
||||
|
||||
char *buff; /* buffer for read/write */
|
||||
int filen = 1; /* file number being processed */
|
||||
long count=0, lcount=0; /* number of blocks for file */
|
||||
extern void RUBOUT(); /* handle user DELETE key signal */
|
||||
off_t size=0, tsize=0; /* number of bytes in file, total */
|
||||
int ln;
|
||||
char *inf, *outf;
|
||||
int copy;
|
||||
int32 size_1K = 1024;
|
||||
#if 0
|
||||
int32_t size_128K = 128 * 1024;
|
||||
int32_t size_256K = 256 * 1024;
|
||||
#endif
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
// int n, nw, inp, outp;
|
||||
int n, nw;
|
||||
FILE *inp, *outp;
|
||||
// struct mtop op;
|
||||
// int32_t buf_size = size_256K;
|
||||
int32 buf_size = size_1K;
|
||||
int EOFcnt = 0; /* count the number of EOFs in a row. */
|
||||
|
||||
if (argc <= 1 || argc > 3) {
|
||||
(void)fprintf(stderr, "Usage: disk2tap src [dest]\n");
|
||||
return (1);
|
||||
}
|
||||
inf = argv[1];
|
||||
if (argc == 3) {
|
||||
outf = argv[2];
|
||||
copy = 1;
|
||||
}
|
||||
// if ((inp = open(inf, O_RDONLY, 0666)) < 0) {
|
||||
if ((inp = fopen(inf, "r")) == NULL) {
|
||||
(void)fprintf(stderr, "Can't open %s\n", inf);
|
||||
return (1);
|
||||
}
|
||||
if (copy) {
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(outf, O_WRONLY|O_CREAT, 0666)) < 0) {
|
||||
if ((outp = fopen(outf, "w")) == NULL) {
|
||||
(void)fprintf(stderr, "Can't open %s\n", outf);
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
/* get a 1k buffer */
|
||||
if ((buff = malloc(buf_size)) == NULL) {
|
||||
(void)fprintf(stderr, "Can't allocate memory for disk2tap\n");
|
||||
return (4);
|
||||
}
|
||||
// if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
// (void)signal(SIGINT, RUBOUT);
|
||||
|
||||
ln = -2;
|
||||
for (;;) {
|
||||
count++;
|
||||
// errno = 0;
|
||||
/* read first record to get size for buffer, doubling each time unsuccessful */
|
||||
// while ((n = read(inp, buff, buf_size)) < 0) {
|
||||
while ((n = fread(buff, (size_t)1, (size_t)buf_size, inp)) <= 0) {
|
||||
#if 0
|
||||
if (errno == ENOMEM) {
|
||||
#if 0
|
||||
if (buf_size < size_256K)
|
||||
buf_size = size_256K;
|
||||
else
|
||||
buf_size *= 2;
|
||||
#endif
|
||||
free(buff);
|
||||
if ((buff = malloc(buf_size)) == NULL) {
|
||||
(void)fprintf(stderr, "Can't allocate memory for tapecopy\n");
|
||||
return (4);
|
||||
}
|
||||
op.mt_op = MTFSF; /* Rewind to start of file */
|
||||
op.mt_count = (daddr_t) 0;
|
||||
if (ioctl(inp, MTIOCTOP, (char *)&op) < 0) {
|
||||
perror("Read buffer size error");
|
||||
return (6);
|
||||
}
|
||||
errno = 0;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
perror("Unknown read error");
|
||||
// errno = 0;
|
||||
return (6); /* abort on error, comment out to ignore taoe errors */
|
||||
}
|
||||
if (n > 0) {
|
||||
/* we read some data, see if scanning or writing */
|
||||
EOFcnt = 0; /* not at EOF anymore */
|
||||
if (copy) {
|
||||
int32 n1, n2;
|
||||
/* we have data to write */
|
||||
int32 hc = (n + 1) & ~1; /* make byte count even */
|
||||
int32 wc = n; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
// n1 = write(outp, (char *)(&wc), (int32_t)4);
|
||||
n1 = fwrite((char *)(&wc), (size_t)1, (size_t)4, outp);
|
||||
/* write the data mod 2 */
|
||||
// nw = write(outp, buff, (int32_t)hc);
|
||||
nw = fwrite(buff, (size_t)1, (size_t)hc, outp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
// n2 = write(outp, (char *)(&wc), (int32_t)4);
|
||||
n2 = fwrite((char *)(&wc), (size_t)1, (size_t)4, outp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4) {
|
||||
fprintf(stderr, "write (%d) !=" " read (%d)\n", nw, n);
|
||||
fprintf(stderr, "COPY " "Aborted\n");
|
||||
return (5);
|
||||
}
|
||||
}
|
||||
size += n; /* update bytes read */
|
||||
if (n != ln) { /* must be last record of file if different */
|
||||
if (ln > 0) {
|
||||
/* we read something */
|
||||
if ((count - lcount) > 1)
|
||||
(void)printf("file %d: records %ld to %ld: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
(void)printf("file %d: record %ld: size %d\n",
|
||||
filen, lcount, ln);
|
||||
}
|
||||
ln = n; /* save last record size */
|
||||
lcount = count; /* also record count */
|
||||
}
|
||||
} else {
|
||||
/* we did not read data, it must be an EOF */
|
||||
/* if ln is -1, last operation was EOF, now we have a second */
|
||||
#ifdef FMGRTAPE
|
||||
/* filemgr has 2 EOF's at end of tape */
|
||||
if (++EOFcnt > 1) {
|
||||
/* two EOFs mean we are at EOT */
|
||||
(void)printf("fmgr eot\n");
|
||||
break;
|
||||
}
|
||||
#else
|
||||
/* volmgr has 3 EOF's at end of tape */
|
||||
if (++EOFcnt > 2) {
|
||||
/* three EOFs mean we are at EOT on MPX */
|
||||
(void)printf("volm eot\n");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
(void)printf("file %d: records %ld to %ld: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
(void)printf("file %d: record %ld: size %d\n",
|
||||
filen, lcount, ln);
|
||||
}
|
||||
#ifdef FMGRTAPE
|
||||
(void)printf("file %d: eof after %ld records: %ld bytes\n",
|
||||
filen, count - 1, size);
|
||||
#else
|
||||
if (EOFcnt == 2) /* if 2nd EOF, print file info */
|
||||
(void)printf("second eof after %d files: %ld bytes\n",
|
||||
filen, size);
|
||||
#endif
|
||||
if (copy) {
|
||||
/* write a sudo EOF to disk file as a zero 4 byte record */
|
||||
int n1, hc = 0;
|
||||
/* write the EOF */
|
||||
/* write a zero as the byte count in 32 bit word as EOF */
|
||||
// n1 = write(outp, (char *)(&hc), (int32_t)4);
|
||||
n1 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outp);
|
||||
if (n1 != 4) {
|
||||
perror("Write EOF");
|
||||
return (6);
|
||||
}
|
||||
}
|
||||
#ifdef FMGRTAPE
|
||||
filen++; /* advance number of files */
|
||||
#else
|
||||
if (EOFcnt < 2) /* not really a file if 2nd EOF */
|
||||
filen++; /* advance number of files */
|
||||
#endif
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = n; /* set ln to -1 showing we are at EOF */
|
||||
}
|
||||
}
|
||||
if (copy) {
|
||||
/* write a sudo EOM to disk file as a -1 4 byte record */
|
||||
int32 n1, hc = 0xffffffff;
|
||||
/* write the EOM to disk */
|
||||
/* write a -1 as the byte count in 32 bit word as EOM */
|
||||
// n1 = write(outp, (char *)(&hc), (int32_t)4);
|
||||
n1 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outp);
|
||||
if (n1 != 4) {
|
||||
perror("Write EOM");
|
||||
return (6);
|
||||
}
|
||||
// (void)close(outp);
|
||||
fclose(outp);
|
||||
}
|
||||
/* print out total tape size in bytes */
|
||||
(void)printf("total length: %ld bytes\n", tsize);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* entered when user hit the DELETE key */
|
||||
void RUBOUT()
|
||||
{
|
||||
if (count > lcount)
|
||||
--count;
|
||||
if (count)
|
||||
if (count > lcount)
|
||||
(void)printf("file %d: records %ld to %ld: size" " %d\n", filen, lcount, count, ln);
|
||||
else
|
||||
(void)printf("file %d: record %ld: size %d\n", filen, lcount, ln);
|
||||
(void)printf("interrupted at file %d: record %ld\n", filen, count);
|
||||
(void)printf("total length: %ld bytes\n", tsize + size);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
@@ -1,356 +0,0 @@
|
||||
/*
|
||||
* diskload.c
|
||||
*
|
||||
* This program reads an MPX load module and stores it into the
|
||||
* sumulated diskfile. The SMD entry is changed to reflect the
|
||||
* new file entry.
|
||||
* input - filename
|
||||
* - simulated diskfile
|
||||
* output - modified diskfile with SMD entry modified
|
||||
* 08/11/2018
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define BLKSIZE 768 /* MPX file sector size */
|
||||
unsigned char os[BLKSIZE * 100]; /* O/S code */
|
||||
|
||||
/* read program file and output to simulated mpx1.x diskfile using filemgr format */
|
||||
/* dload file diskfile */
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *fp, *dp, *fopen();
|
||||
unsigned char si[BUFSIZ];
|
||||
char *p;
|
||||
int i, j;
|
||||
#define DOLIST 1
|
||||
#define DOADD 2
|
||||
unsigned int option = DOLIST; /* what to do */
|
||||
unsigned char *fnp; /* file name pointer */
|
||||
unsigned int size; /* size in 768 byte sectors */
|
||||
unsigned int word,tmp; /* just a temp word variable */
|
||||
unsigned char name[9]; /* LM name */
|
||||
unsigned int lmname[2], passwd[2];
|
||||
unsigned int smds; /* size of smd */
|
||||
unsigned int smdd[2]; /* SMD space definition */
|
||||
unsigned char *smd;
|
||||
unsigned int hash1; /* SMD hash value for name */
|
||||
unsigned int udtp; /* UDT pointer */
|
||||
unsigned int *mptr; /* word ptr for SMD entries */
|
||||
unsigned int boff;
|
||||
unsigned int rem;
|
||||
unsigned int blk;
|
||||
unsigned int lmblk; /* sector addess of load module on disk */
|
||||
unsigned int smdudt; /* smd udt index */
|
||||
unsigned int spau; /* sectors per allocation unit */
|
||||
unsigned int fileau; /* file size in allocation units */
|
||||
// unsigned int auptr; /* pointer to allocation unit on disk */
|
||||
unsigned int lsblk; /* lowest block address of SMD entries */
|
||||
|
||||
if (argc <= 1) { /* see if correct # args */
|
||||
// fprintf(stderr, "Error: incorrect number of parameters\n");
|
||||
fprintf(stderr, "Usage: %s -la program diskfile\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
if (--argc > 0) {
|
||||
p = *++argv;
|
||||
// printf("argv %s\n", p);
|
||||
if (*p++ == '-') {
|
||||
while (*p != '\0') {
|
||||
switch (*p++) {
|
||||
case 'l':
|
||||
case 'L':
|
||||
option |= DOLIST;
|
||||
break;
|
||||
case 'A':
|
||||
case 'a':
|
||||
option |= DOADD;
|
||||
break;
|
||||
default:
|
||||
// fprintf(stderr, "Error: incorrect option %c specified\n", *--p);
|
||||
fprintf(stderr, "Usage: %s -la program diskfile\n", *--argv);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*--p == '-') {
|
||||
fprintf(stderr, "Error: no option specified\n");
|
||||
fprintf(stderr, "Usage: %s -la program diskfile\n", *--argv);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
argc++;
|
||||
argv--;
|
||||
}
|
||||
if (--argc > 0) {
|
||||
p = *++argv;
|
||||
// printf("argv2 %s\n", p);
|
||||
if ((fp = fopen(*argv, "r")) == NULL) {
|
||||
fprintf(stderr, "error: can't open load module %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
fnp = *argv; /* get file name pointer */
|
||||
fseek(fp, 0, SEEK_END); /* seek to end */
|
||||
word = ftell(fp); /* get filesize in bytes */
|
||||
fseek(fp, 0, SEEK_SET); /* rewind file */
|
||||
}
|
||||
}
|
||||
if (--argc <= 0) {
|
||||
fprintf(stderr, "Error: incorrect number of parameters\n");
|
||||
fprintf(stderr, "Usage: %s -la program diskfile\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
/* open diskfile */
|
||||
if ((dp = fopen(*++argv, "r+")) == NULL) {
|
||||
fprintf(stderr, "error: can't open disk file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* determine size of file */
|
||||
size = word/BLKSIZE; /* get sector count */
|
||||
if ((word % BLKSIZE) != 0)
|
||||
size++; /* add in 1 for partial sector */
|
||||
/* size now has load module size in sectors */
|
||||
/* we need the file name and password for entry */
|
||||
for (i=0; i<8; i++)
|
||||
name[i] = 0x20; /* pre blank name */
|
||||
name[8] = '\0'; /* NULL terminate */
|
||||
for (i=0; (i<8) && (fnp[i] != 0); i++)
|
||||
name[i] = toupper(fnp[i]); /* upper case name */
|
||||
// fprintf(stderr, "file %s is size %d sectors\n", name, size);
|
||||
lmname[0] = (name[0] << 24) | (name[1] << 16) | (name[2] << 8) | (name[3]);
|
||||
lmname[1] = (name[4] << 24) | (name[5] << 16) | (name[6] << 8) | (name[7]);
|
||||
passwd[0] = passwd[1] = 0; /* no password */
|
||||
/* the disk data has the O/S starting at 0x780 in the file */
|
||||
/* add 0x780 to any O/S location you want to load */
|
||||
/* C.SMDS (#smd entries) is at 0xb00 + 0x780 = 0x1280 */
|
||||
/* read the O/S diskfile into buffer, 7680 bytes */
|
||||
// fprintf(stderr, "reading 100*BLKSIZE bytes from disk\n", 100*BLKSIZE);
|
||||
if (fread(os, 1, BLKSIZE*100, dp) <= 0)
|
||||
return (0); /* this means bad read */
|
||||
smds = (os[0x780+0xb00] << 24) | (os[0x780+0xb01] << 16) | (os[0x780+0xb02] << 8) | (os[0x780+0xb03]);
|
||||
|
||||
/* get udt index for SMD location */
|
||||
smdudt = (os[0x780+0xc2c] << 8) | (os[0x780+0xc2d]);
|
||||
/* udt size id 0x40, C.UDTA is at 0xb40 */
|
||||
word = (os[0x780+0xb40] << 24) | (os[0x780+0xb41] << 16) | (os[0x780+0xb42] << 8) | (os[0x780+0xb43]);
|
||||
udtp = (smdudt * 0x40 + word); /* get udt address */
|
||||
/* spau is in byte 0x0f of udt */
|
||||
spau = os[0x780+udtp+0x0f] & 0xff; /* get word with spau */
|
||||
|
||||
/* get file size in au's */
|
||||
fileau = size / spau; /* get number of au's required for file */
|
||||
if ((size % spau) != 0)
|
||||
fileau++; /* round up to next au of overflow */
|
||||
fprintf(stderr, "file %s is size %d sectors (%d au) requiring %d sectors on disk\n",
|
||||
name, size, fileau, fileau*spau);
|
||||
// fprintf(stderr, "UDTP 0x%x SPAU 0x%x\n", udtp, spau); /* display udtp & spau */
|
||||
fprintf(stderr, "C.SMDS(0xB00) - SMD size is 0x%x %d entries C.SMDUDT is %x\n", smds, smds, smdudt);
|
||||
|
||||
/* get SMD space definition */
|
||||
smdd[0] = (os[0x780+0x840] << 24) | (os[0x780+0x841] << 16) | (os[0x780+0x842] << 8) | (os[0x780+0x843]);
|
||||
smdd[1] = (os[0x780+0x844] << 24) | (os[0x780+0x845] << 16) | (os[0x780+0x846] << 8) | (os[0x780+0x847]);
|
||||
fprintf(stderr, "C.SMDD(0x840) - SMD space definition wd0 0x%x wd1 0x%x wd0 %d wd1 %d entries %d\n",
|
||||
smdd[0], smdd[1], smdd[0] ,smdd[1], smdd[1] * 24);
|
||||
fprintf(stderr, "SMD space def: blk 0x%x seek 0x%x size 0x%x (%d)\n",
|
||||
smdd[0], smdd[0]*BLKSIZE, smdd[1], smdd[1]);
|
||||
|
||||
/* rewind the disk */
|
||||
fseek(dp, 0, 0); /* seek home */
|
||||
/* seek to the smd */
|
||||
fseek(dp, smdd[0]*BLKSIZE, 0); /* seek smd */
|
||||
if ((smd = (unsigned char *)malloc(smdd[1] * BLKSIZE)) < 0)
|
||||
return (0); /* this means bad read */
|
||||
/* read the SMD into memory */
|
||||
if (fread(smd, 1, smdd[1]*BLKSIZE, dp) <= 0)
|
||||
return (0); /* this means bad read */
|
||||
/* use lowest space definition from SMD entries */
|
||||
lsblk = smdd[0]; /* set lowest to start of SMD */
|
||||
/* loop through the SMD looking for a match to the load module name */
|
||||
for (i=0; i<((int)smds*32); i+=32) {
|
||||
unsigned int sblk, len, udt, pw;
|
||||
int yep = 0;
|
||||
for (j=0; j<8; j++) {
|
||||
if (smd[i+j] != 0) {
|
||||
fprintf(stderr, "%c", smd[i+j]);
|
||||
yep = 1;
|
||||
}
|
||||
}
|
||||
if (yep) {
|
||||
int bit;
|
||||
unsigned int lmn[2]; /* load module name */
|
||||
|
||||
sblk = (smd[i+8] << 24) | (smd[i+9] << 16) | (smd[i+10] << 8) | (smd[i+11]);
|
||||
if ((sblk & 0xffffff) < lsblk)
|
||||
lsblk = sblk & 0xffffff;/* save the new lowest address */
|
||||
len = (smd[i+12] << 24) | (smd[i+13] << 16) | (smd[i+14] << 8) | (smd[i+15]);
|
||||
pw = (smd[i+24] << 8) | (smd[i+25]);
|
||||
udt = (smd[i+26] << 8) | (smd[i+27]);
|
||||
|
||||
/* hash the name to see if pointer is to current SMD entry */
|
||||
mptr = (unsigned int *)smd; /* get word pointer for SMD data */
|
||||
j = i/32; /* offset in SMD file (entry #) */
|
||||
lmn[0] = mptr[j*8]; /* get filename first 4 chars to R5 and shift right circular by 1 */
|
||||
word = ((lmn[0] & 0xff) << 24) | ((lmn[0] & 0xff00) << 8) |
|
||||
((lmn[0] & 0xff0000) >> 8) | ((lmn[0] & 0xff000000) >> 24);
|
||||
bit = word & 1; /* save bit 31 */
|
||||
word = word >> 1; /* shift right 1 */
|
||||
if (bit)
|
||||
word |= 0x80000000; /* copy old bit 31 to bit 0 */
|
||||
lmn[1] = mptr[j*8+1]; /* get 2nd 4 chars of filename */
|
||||
rem = ((lmn[1] & 0xff) << 24) | ((lmn[1] & 0xff00) << 8) |
|
||||
((lmn[1] & 0xff0000) >> 8) | ((lmn[1] & 0xff000000) >> 24);
|
||||
word = word ^ rem; /* EOR with 2nd half of load module name */
|
||||
rem = word % smds; /* get remainder as relative entry number */
|
||||
fprintf(stderr, " entry %d (calc %d) off 0x%x typ 0x%x blk 0x%x len 0x%x, pw 0x%x udt 0x%x\n",
|
||||
j, rem, (sblk & 0xffffff)*BLKSIZE, sblk>>24, sblk, len, pw, udt);
|
||||
// fprintf(stderr, "offset index %d calc %d\n", i/32, rem); /* display entry # */
|
||||
}
|
||||
}
|
||||
|
||||
/* see if user want list only */
|
||||
if ((option & DOLIST) && !(option & DOADD))
|
||||
goto doexit; // getout
|
||||
|
||||
#if 0
|
||||
/* get file size in au's */
|
||||
fileau = size / spau; /* get number of au's required for file */
|
||||
if ((size % spau) != 0)
|
||||
fileau++; /* round up to next au of overflow */
|
||||
#endif
|
||||
|
||||
/* lsblk has the lowest space definition from SMD entries */
|
||||
lmblk = lsblk - fileau * spau; /* get sector address of where to store lm */
|
||||
fprintf(stderr, "lmblk 0x%x lsblk 0x%x fileau 0x%x spau 0x%x\n", lmblk, lsblk, fileau, spau);
|
||||
|
||||
/* hash filename into SMD entry number */
|
||||
fprintf(stderr, "1 hashing lmname[0] %x lmname[1] %x\n", lmname[0], lmname[1]);
|
||||
word = lmname[0]; /* get filename first 4 chars to R5 and shift right circular by 1 */
|
||||
i = word & 1; /* save bit 31 */
|
||||
word = word >> 1; /* shift right 1 */
|
||||
if (i)
|
||||
word |= 0x80000000; /* copy old bit 31 to bit 0 */
|
||||
word = word ^ lmname[1]; /* EOR with 2nd half of load module name */
|
||||
hash1 = word / smds; /* calc SMD hash number and save */
|
||||
rem = word % smds; /* get remainder as relative entry number */
|
||||
|
||||
/* get relative 192W block in SMD */
|
||||
blk = rem/24; /* divide entry # by # entries/block */
|
||||
boff = (rem%24) * 32; /* get byte offset in block of entry */
|
||||
tmp = (blk * 24 + (boff/32)); /* make word offset in smd array */
|
||||
fprintf(stderr, "hash1 %x rem %x blk 0x%x %d boff %x index %d\n", hash1, rem, blk, blk, boff, tmp);
|
||||
/* populate the 32 byte SMD entry */
|
||||
/* smd has entire SMD in memory */
|
||||
tmp = (blk * BLKSIZE + boff) >> 2; /* make word offset in smd array */
|
||||
mptr = (unsigned int *)smd; /* get word pointer for smd data */
|
||||
/* word 1 and 2 has filename */
|
||||
blk = lmname[0]; /* 1st 4 char of lmname */
|
||||
word = ((blk & 0xff) << 24) | ((blk & 0xff00) << 8) | ((blk & 0xff0000) >> 8) | ((blk & 0xff000000) >> 24);
|
||||
mptr[tmp] = word; /* set 1st 4 char of name */
|
||||
|
||||
blk = lmname[1]; /* set 2nd 4 char of name */
|
||||
word = ((blk & 0xff) << 24) | ((blk & 0xff00) << 8) | ((blk & 0xff0000) >> 8) | ((blk & 0xff000000) >> 24);
|
||||
mptr[tmp+1] = word; /* set 2nd 4 char of name */
|
||||
|
||||
// blk = 0xca000000 | lmblk; /* type ca and blk address */
|
||||
blk = 0xee000000 | lmblk; /* type ca and blk address */
|
||||
word = ((blk & 0xff) << 24) | ((blk & 0xff00) << 8) | ((blk & 0xff0000) >> 8) | ((blk & 0xff000000) >> 24);
|
||||
mptr[tmp+2] = word; /* set type and blk addr */
|
||||
/* size now has load module size in sectors */
|
||||
blk = 0x80000000 | size; /* file flags and size */
|
||||
word = ((blk & 0xff) << 24) | ((blk & 0xff00) << 8) | ((blk & 0xff0000) >> 8) | ((blk & 0xff000000) >> 24);
|
||||
mptr[tmp+3] = word; /* set flags and size */
|
||||
mptr[tmp+4] = 0; /* no username */
|
||||
mptr[tmp+5] = 0; /* no username */
|
||||
blk = 0x00000000 | smdudt; /* no password and smd udt */
|
||||
word = ((blk & 0xff) << 24) | ((blk & 0xff00) << 8) | ((blk & 0xff0000) >> 8) | ((blk & 0xff000000) >> 24);
|
||||
mptr[tmp+6] = word; /* set password and udt index */
|
||||
mptr[tmp+7] = 0; /* not used */
|
||||
|
||||
/* loop through the SMD looking for a match to the load module name */
|
||||
for (i=0; i<((int)smds*32); i+=32) {
|
||||
unsigned int sblk, len, udt, pw;
|
||||
int yep = 0;
|
||||
for (j=0; j<8; j++) {
|
||||
if (smd[i+j] != 0) {
|
||||
fprintf(stderr, "%c", smd[i+j]);
|
||||
yep = 1;
|
||||
}
|
||||
}
|
||||
if (yep) {
|
||||
int bit;
|
||||
unsigned int lmn[2]; /* load module name */
|
||||
sblk = (smd[i+8] << 24) | (smd[i+9] << 16) | (smd[i+10] << 8) | (smd[i+11]);
|
||||
len = (smd[i+12] << 24) | (smd[i+13] << 16) | (smd[i+14] << 8) | (smd[i+15]);
|
||||
pw = (smd[i+24] << 8) | (smd[i+25]);
|
||||
udt = (smd[i+26] << 8) | (smd[i+27]);
|
||||
#if 0
|
||||
fprintf(stderr, " entry %d blk # 0x%x off 0x%x len 0x%x, pw 0x%x udt 0x%x\n",
|
||||
i/32, sblk, (sblk & 0xffffff) * BLKSIZE, len, pw, udt);
|
||||
/* udt size id 0x40, C.UDTA is at 0xb40 */
|
||||
word = (os[0x780+0xb40] << 24) | (os[0x780+0xb41] << 16) | (os[0x780+0xb42] << 8) | (os[0x780+0xb43]);
|
||||
udtp = (udt * 0x40 + word); /* get udt address */
|
||||
fprintf(stderr, "UDTP 0x%x\n", udtp); /* display word */
|
||||
/* spau is in byte 0x0f */
|
||||
spau = os[0x780+udtp+0x0f] & 0xff; /* get word with spau */
|
||||
fprintf(stderr, "SPAU 0x%x\n", spau); /* display spau */
|
||||
#endif
|
||||
|
||||
/* hash the name to see if pointer is to current SMD entry */
|
||||
mptr = (unsigned int *)smd; /* get word pointer for SMD data */
|
||||
j = i/32; /* offset in SMD file (entry #) */
|
||||
lmn[0] = mptr[j*8]; /* get filename first 4 chars to R5 and shift right circular by 1 */
|
||||
word = ((lmn[0] & 0xff) << 24) | ((lmn[0] & 0xff00) << 8) |
|
||||
((lmn[0] & 0xff0000) >> 8) | ((lmn[0] & 0xff000000) >> 24);
|
||||
bit = word & 1; /* save bit 31 */
|
||||
word = word >> 1; /* shift right 1 */
|
||||
if (bit)
|
||||
word |= 0x80000000; /* copy old bit 31 to bit 0 */
|
||||
lmn[1] = mptr[j*8+1]; /* get 2nd 4 chars of filename */
|
||||
rem = ((lmn[1] & 0xff) << 24) | ((lmn[1] & 0xff00) << 8) |
|
||||
((lmn[1] & 0xff0000) >> 8) | ((lmn[1] & 0xff000000) >> 24);
|
||||
word = word ^ rem; /* EOR with 2nd half of load module name */
|
||||
rem = word % smds; /* get remainder as relative entry number */
|
||||
fprintf(stderr, " entry %d (calc %d) off 0x%x typ 0x%x blk 0x%x len 0x%x, pw 0x%x udt 0x%x\n",
|
||||
j, rem, (sblk & 0xffffff)*BLKSIZE, sblk>>24, sblk, len, pw, udt);
|
||||
// fprintf(stderr, "offset index %d calc %d\n", i/32, rem); /* display entry # */
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "file space def: blk 0x%x seek 0x%x size 0x%x %d\n", lmblk, lmblk*BLKSIZE, size, size);
|
||||
if (option & DOADD) { /* see if user wants file written to disk */
|
||||
/* write the load module to disk */
|
||||
/* rewind the disk */
|
||||
fseek(dp, 0, 0); /* seek home */
|
||||
/* seek to where the load module is to be stored */
|
||||
fseek(dp, lmblk*BLKSIZE, 0); /* seek sector for saving load module */
|
||||
/* rewind the load module */
|
||||
fseek(fp, 0, 0); /* seek home */
|
||||
/* copy all of the sectors */
|
||||
for (i=0; i<(int)size; i++) {
|
||||
/* read a block of the load module */
|
||||
if (fread(si, 1, BLKSIZE, fp) <= 0)
|
||||
return (0); /* this means eof */
|
||||
/* write it to the disk file */
|
||||
if (fwrite(si, 1, BLKSIZE, dp) <= 0)
|
||||
return (0); /* this means eof */
|
||||
}
|
||||
|
||||
/* write the updated smd to disk */
|
||||
/* rewind the disk */
|
||||
fseek(dp, 0, 0); /* seek home */
|
||||
/* seek to the smd */
|
||||
fseek(dp, smdd[0]*BLKSIZE, 0); /* seek smd */
|
||||
/* write the SMD from memory to disk */
|
||||
if (fwrite(smd, 1, smdd[1]*BLKSIZE, dp) <= 0)
|
||||
return (0); /* this means bad write */
|
||||
}
|
||||
doexit:
|
||||
fclose(fp);
|
||||
fclose(dp);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
/*
|
||||
* eomtap.c
|
||||
*
|
||||
* This program scans a metatape file and copies files until EOM is found.
|
||||
* The program will make sure 2 eof's and 1 eom are written to the tape.
|
||||
* input - specified filename
|
||||
* output - specified filename
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int oldsize, newsize;
|
||||
FILE *outfp;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
int ln;
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0) {
|
||||
hc = -1; /* at EOM on disk file */
|
||||
return hc; /* return EOM */
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) { /* check for garbage, assume EOF */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
#if 0
|
||||
return hc; /* return EOM */
|
||||
#endif
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: EOF after %d records: %d bytes\n\n", filen, count, size);
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
fprintf(stderr, "second EOF after %d files: %d bytes\n", filen-1, tsize+size);
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
|
||||
/* check for EOM */
|
||||
if (hc == -1) {
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
if (n <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
#if 0
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
#endif
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
void putrec(int cnt, char *buf)
|
||||
{
|
||||
int n1, n2, nw;
|
||||
int hc = (cnt + 1) & ~1; /* make byte count even */
|
||||
int ac = cnt; /* get actual byte count */
|
||||
|
||||
//printf("writing %d chars\n", cnt);
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((char *)buf, (size_t)1, (size_t)hc, outfp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t buf_size = 256 * 1024;
|
||||
size_t ll, gotboth = 0;
|
||||
int zero = 0;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// close(inp); /* close input */
|
||||
fclose(infp); /* close input */
|
||||
outfp = fopen(argv[1],"r"); /* reopen */
|
||||
fseek(outfp, 0, SEEK_END); /* seek to end */
|
||||
oldsize = ftell(outfp); /* get filesize in bytes */
|
||||
fclose(outfp); /* now close it */
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
outfp = fopen(argv[2], "w");
|
||||
if (outfp == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open output file %s\n", argv[0], argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
|
||||
/* get a 256k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
return (4);
|
||||
}
|
||||
|
||||
/* get buffers until eof */
|
||||
domore:
|
||||
//??while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
//printf("got %d char\n", ll);
|
||||
/* we have data to write */
|
||||
putrec(ll, buf); /* write the buffer */
|
||||
gotboth = 0;
|
||||
}
|
||||
printf("we have EOF %d\n", gotboth+1);
|
||||
/* we have an EOF or an EOM */
|
||||
if (ll == 0) {
|
||||
/* we have EOF, write a zero */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
gotboth++; /* one more EOF */
|
||||
if (gotboth == 2) {
|
||||
/* we have written both EOF's, now write EOM */
|
||||
ll = -1;
|
||||
} else {
|
||||
goto domore; /* get more data */
|
||||
}
|
||||
}
|
||||
|
||||
printf("we have EOM, DONE\n");
|
||||
/* We have EOM, see if EOF's needed */
|
||||
switch (gotboth) {
|
||||
case 0: /* we have written no EOFs, so write two */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
case 1: /* we have written 1 EOF, so write one more */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
default:
|
||||
case 2: /* we have written 2 EOFs, now do EOM */
|
||||
zero = -1;
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
}
|
||||
fprintf(stderr, "EOM after 2 EOFs %d files: %d bytes\n", filen-1, tsize);
|
||||
|
||||
newsize = ftell(outfp); /* get filesize in bytes */
|
||||
fprintf(stderr, "Size of file changed from %d to %d\n", oldsize, newsize);
|
||||
|
||||
/* we done */
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,335 +0,0 @@
|
||||
/*
|
||||
* filelist.c
|
||||
*
|
||||
* This program scans a metatape file and prints file count and sizes.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
//#define NOTDUMP
|
||||
#define DUMPFILES
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
//#include <string.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
#ifdef NOTDUMP
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: eof after %d records: %d bytes\n", filen, count, size);
|
||||
#endif
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
#ifdef NOTDUMP
|
||||
fprintf(stderr, "second eof after %d files: %d bytes\n", filen, size);
|
||||
#endif
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1) {
|
||||
#ifdef NOTDUMP
|
||||
/* we have EOM */
|
||||
fprintf(stderr, "mpx eot\n");
|
||||
/* print out total tape size in bytes */
|
||||
fprintf(stderr, "total length: %ld bytes\n", tsize);
|
||||
#endif
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
#ifdef NOTDUMP
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
#endif
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
// char in[BUFSIZ], out[BUFSIZ];
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll, gotboth = 0;
|
||||
int lfilen = filen;
|
||||
unsigned int fileaddr, file_byte_count=0, /*curchar,*/ buffptr, bufflen;
|
||||
int skipfile = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = filen;
|
||||
buffptr = 0;
|
||||
bufflen = 16;
|
||||
fileaddr = 0;
|
||||
file_byte_count = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
skipfile = 0;
|
||||
file_byte_count = 0;
|
||||
fileaddr = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
} else {
|
||||
int cc = 0;
|
||||
// char buff[257];
|
||||
// int ans;
|
||||
int w1, w2, i, j;
|
||||
char path[64], command[128];
|
||||
buffptr = 0;
|
||||
{
|
||||
/* dump first 2 words */
|
||||
w1 = (buf[0] & 0xff) << 24 | buf[1] << 16 | buf[2] << 8 | (buf[3] & 0xff);
|
||||
w2 = (buf[4] & 0xff) << 24 | buf[5] << 16 | buf[6] << 8 | (buf[7] & 0xff);
|
||||
#ifdef NODATA
|
||||
if (filen > 480)
|
||||
printf("w1 = %x, w2 = %x count = %d\n", w1, w2, count);
|
||||
#endif
|
||||
if (count == 1 && w1 == 1) {
|
||||
char file[20], dir[20], vol[20];
|
||||
int off = 8;
|
||||
int l = 0;
|
||||
/* we have directory entries */
|
||||
for (j=0; j<w2; j++) {
|
||||
int k = l++ * 48;
|
||||
if (k > (6144-48-off)) {
|
||||
ll=getloi(buf, buf_size);
|
||||
off = 0;
|
||||
l = 0;
|
||||
k = 0;
|
||||
#ifdef NODATA
|
||||
printf("reread: got ll= %d\n", ll);
|
||||
#endif
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[k+off+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
printf("file %s\n", file);
|
||||
}
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[k+off+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[k+off+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[k+off+32+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
sprintf(path, "./%s/%s", vol, dir);
|
||||
/* create the directory/file */
|
||||
#ifdef DUMPFILES
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
printf("path %s\n", path);
|
||||
#ifdef DUMPFILES
|
||||
sprintf(command, "touch %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
}
|
||||
} else
|
||||
if (count == 1 && w1 == 2 && w2 == 0) {
|
||||
char file[20], dir[20], vol[20];
|
||||
/* process file definition */
|
||||
/* we have a file definition entry */
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[8+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[24+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[40+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
printf("path2 = %s\n", path);
|
||||
}
|
||||
}
|
||||
/* see if skipping to next file */
|
||||
if (skipfile == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef NODUMP
|
||||
/* process the returned buffer */
|
||||
while (cc < ll) {
|
||||
curchar = (unsigned int)buf[cc++] & 0xff;
|
||||
file_byte_count++;
|
||||
if (!buffptr)
|
||||
printf(" %06x : ",fileaddr);
|
||||
printf("%02x", curchar & 0xff);
|
||||
buff[buffptr++] = PRINTABLE(curchar);
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
if (buffptr >= bufflen) {
|
||||
buff[buffptr] = 0;
|
||||
printf(" |%s|\n",buff);
|
||||
buffptr = 0;
|
||||
fileaddr += bufflen;
|
||||
if (!(file_byte_count % 256)) {
|
||||
printf("\n<cr> - continue, q = quit, s = skip > ");
|
||||
ans = getchar();
|
||||
if (ans == 'q') {
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
if (ans == 's')
|
||||
skipfile = 1;
|
||||
if (ans != '\n')
|
||||
while ((ans=getchar()) != '\n' )
|
||||
;
|
||||
} /* end of if */
|
||||
if (skipfile == 1)
|
||||
break;
|
||||
} /* end of if */
|
||||
} /* end of while */
|
||||
#endif
|
||||
|
||||
#ifdef NODUMP
|
||||
if (buffptr && !skipfile) {
|
||||
buff[buffptr] = 0;
|
||||
while (buffptr++ < bufflen) {
|
||||
printf(" ");
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
} /* end of while */
|
||||
printf(" |%s|\n",buff);
|
||||
|
||||
/* see what user wants to do */
|
||||
printf("\n<cr> - continue, q = quit > ");
|
||||
ans = getchar();
|
||||
if (ans == 'q') {
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
if (ans != '\n')
|
||||
while ((ans=getchar()) != '\n' )
|
||||
;
|
||||
} /* end of if */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
/*
|
||||
* fmgrcopy.c
|
||||
*
|
||||
* This program scans a metatape file and prints file count and sizes.
|
||||
* In addition, it creats a directory for each username specified in
|
||||
* the filemanager tape and then creates a file containing the file
|
||||
* contents. The file must be a filemgr save tape and not an SDT
|
||||
* tape.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int lfilen, filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp, outp;
|
||||
FILE *infp, *outfp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
lfilen = filen;
|
||||
filen++; /* set next file number */
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll;
|
||||
char path[64], command[128];
|
||||
|
||||
if (argc != 2) {
|
||||
//fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
printf("usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
//fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
printf("%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
//fprintf(stderr, "Can't allocate memory for tscan\n");
|
||||
printf("Can't allocate memory for tscan\n");
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
printf("\nfile %d:\n", filen);
|
||||
} else {
|
||||
int cc = 0;
|
||||
// unsigned int curchar;
|
||||
|
||||
/* filemgr smd entries are 8 words, and are in 1152 words (4608 bytes)
|
||||
* (6 sector) blocks. Saved data files are modulo 1152 words also */
|
||||
/* 8 wds per SMD entry, 24 entries per sector, 144 entries per 6 sector
|
||||
* block. */
|
||||
int i, j, m;
|
||||
// if (filen == 1)
|
||||
{
|
||||
/* read smd entry */
|
||||
char file[20], dir[20];
|
||||
int l = 0;
|
||||
int smddone = 0;
|
||||
int totent = 0;
|
||||
char *buf2 = buf;
|
||||
printf("\nfile %d:\n", filen);
|
||||
/* see how man entries here */
|
||||
while(!smddone) {
|
||||
/* process entries in this record */
|
||||
for (j=0; j<144; j++) {
|
||||
int k = l++ * 32;
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
/* stop processing on first zero smd entry */
|
||||
if (w1 <= 0) {
|
||||
smddone = 1;
|
||||
break;
|
||||
}
|
||||
totent++;
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
sprintf(dir, "%s", "system");
|
||||
sprintf(path, "./%s/%s", dir, file);
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0)
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d path = %s\n", w1, path);
|
||||
else
|
||||
printf("active file: w1 = %d path = %s\n", w1, path);
|
||||
}
|
||||
if (smddone)
|
||||
break;
|
||||
buf2 += 4608; /* next buffer */
|
||||
ll=getloi(buf2, 4608);
|
||||
}
|
||||
printf("%d smd entries found\n", totent);
|
||||
/* we have directory entries */
|
||||
for (j=0; j<totent; j++) {
|
||||
int k = j * 32;
|
||||
/* get file size in blocks */
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
int blks = w1; /* save block count */
|
||||
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
sprintf(dir, "%s", "system");
|
||||
sprintf(path, "./%s", dir);
|
||||
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0) {
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d\n", w1);
|
||||
}
|
||||
printf("active file: w1 = %d\n", w1);
|
||||
if (w1 <= 0)
|
||||
break;
|
||||
/* create the directory/file */
|
||||
printf("path = %s\n", path);
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
printf("command = %s\n", command);
|
||||
system(command);
|
||||
sprintf(path, "./%s/%s", dir, file);
|
||||
printf("file %d = %s\n", j+1, path);
|
||||
sprintf(command, "touch %s", path);
|
||||
printf("command = %s\n", command);
|
||||
system(command);
|
||||
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
#ifndef DO_LATER
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(path, "w")) == NULL) {
|
||||
//fprintf(stderr, "Can't open %s\n", path);
|
||||
printf("Can't open %s\n", path);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
#endif
|
||||
/* get the file data */
|
||||
for (m=0; m<((w1+5)/6); m++) {
|
||||
char data[5000]; /* data buffer */
|
||||
ll=getloi(data, 4608);
|
||||
|
||||
/* process file data for file */
|
||||
if (ll == 4608) {
|
||||
#ifndef DO_LATER
|
||||
/* blks/w1 have number of blocks to write */
|
||||
int bcnt, no; /* block count */
|
||||
if (blks >= 6) {
|
||||
blks -= 6; /* enough for 6 block, write them */
|
||||
bcnt = 6*768; /* write all 6 blocks */
|
||||
} else {
|
||||
bcnt = blks*768;/* just write what we need */
|
||||
blks = 0;
|
||||
}
|
||||
/* only write number of sectors on save tape, not all 4608 */
|
||||
/* if zero, just reading excess blocks */
|
||||
if (bcnt != 0) {
|
||||
// no = write(outp, data, bcnt);
|
||||
no = fwrite(data, (size_t)1, (size_t)bcnt, outfp);
|
||||
if (no != bcnt)
|
||||
// fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
printf("write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
}
|
||||
#else
|
||||
printf("read (%d) on file %s\n", ll, path);
|
||||
#endif
|
||||
} else {
|
||||
printf("Bad file size read! %d instead of 4608\n", ll);
|
||||
/// if (ll == -1) break;
|
||||
if (ll == -1)
|
||||
goto dostop;
|
||||
}
|
||||
} /* end writing file */
|
||||
} /* end of smd scan */
|
||||
} /* read smd entries 4608 byte records */
|
||||
} /* process read of smd or sdt */
|
||||
} /* end of getloi read */
|
||||
dostop:
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
/*
|
||||
* instcopy.c
|
||||
*
|
||||
* This program scans an ISC install metatape file and prints file count and
|
||||
* sizes. It is only for special ISC install save images. The first set of
|
||||
* files on the tape are in volmgr format and the second set of files on the
|
||||
* tape are in filemgr format. The files in filemgr format are prefixed with
|
||||
* ./fm/ before being saved. Volmgr save images have the following format:
|
||||
* One or more 6144 byte records containing a list of files saved 16 char file
|
||||
* name followed my 16 char directory name followed by 16 char volume name.
|
||||
* A 1536 byte file definition entry will be followed by 1 to 8 768 byte
|
||||
* file data records followed by an EOF for each file. If the file size is
|
||||
* greater than 6144 bytes, 1 or more 6144 byte records are output followed
|
||||
* by last record modulo 768 bytes. Filemgr SMD entries are 8 words, and are
|
||||
* in 1152 words (4608 bytes) (6 sector) blocks. Saved data files are modulo
|
||||
* 1152 words also; 8 wds per SMD entry, 24 entries per sector, 144 entries
|
||||
* per 6 sector block. Three EOFs in a row define the EOT.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp, outp;
|
||||
FILE *infp, *outfp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
filen++; /* set next file number */
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
unsigned char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll;
|
||||
int lfilen = filen;
|
||||
unsigned int mpxtime[2];
|
||||
char path[64], command[128], dtime[64];
|
||||
time_t utime=0;
|
||||
struct tm *dt;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for tscan\n");
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = filen;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
// printf("got ll = %d filen %d count %d size %d\n", ll, filen, count, size);
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
printf("\nfile %d:\n", filen);
|
||||
} else
|
||||
if ((ll == 4608) && (count == 1)) {
|
||||
int smd = 1;
|
||||
/* see if ISC install tape with filemgr records */
|
||||
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
/* filemgr smd entries are 8 words, and are in 1152 words (4608 bytes)
|
||||
* (6 sector) blocks. Saved data files are modulo 1152 words also */
|
||||
/* 8 wds per SMD entry, 24 entries per sector, 144 entries per 6 sector
|
||||
* block. */
|
||||
// printf("gotx ll = %d filen %d count %d size %d\n", ll, filen, count, size);
|
||||
if (smd == 1) {
|
||||
/* check for SMD entry instead of SDT entry */
|
||||
/* read smd entry */
|
||||
char file[20], dir[20];
|
||||
int j, m, i, l = 0;
|
||||
int smddone = 0;
|
||||
int totent = 0;
|
||||
char *buf2 = buf;
|
||||
// printf("\nfile %d: %d\n", filen, ll);
|
||||
/* see how many entries here */
|
||||
while(!smddone) {
|
||||
/* process entries in this record */
|
||||
for (j=0; j<144; j++) {
|
||||
int k = l++ * 32;
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
/* stop processing on first zero smd entry */
|
||||
if (w1 <= 0) {
|
||||
smddone = 1;
|
||||
break;
|
||||
}
|
||||
totent++;
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
sprintf(dir, "%s", "system");
|
||||
sprintf(path, "./%s/%s", dir, file);
|
||||
#if 0
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0)
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d path = %s\n", w1, path);
|
||||
else
|
||||
printf("active file: w1 = %d path = %s\n", w1, path);
|
||||
#else
|
||||
printf("blks: %d file: path = %s\n", w1, path);
|
||||
#endif
|
||||
}
|
||||
if (smddone)
|
||||
break;
|
||||
buf2 += 4608; /* next buffer */
|
||||
ll=getloi(buf2, 4608);
|
||||
}
|
||||
// printf("%d smd entries found\n", totent);
|
||||
/* we have directory entries */
|
||||
for (j=0; j<totent; j++) {
|
||||
int k = j * 32;
|
||||
/* get file size in blocks */
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
int blks = w1; /* save block count */
|
||||
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
// sprintf(dir, "%s", "system");
|
||||
sprintf(dir, "%s", "./fm/system");
|
||||
// sprintf(path, "./%s", dir);
|
||||
sprintf(path, "./fm/%s", dir);
|
||||
|
||||
#if 0
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0) {
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d\n", w1);
|
||||
}
|
||||
printf("active file: w1 = %d\n", w1);
|
||||
#endif
|
||||
if (w1 <= 0)
|
||||
break;
|
||||
/* create the directory/file */
|
||||
// printf("path = %s\n", path);
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
// printf("command = %s\n", command);
|
||||
system(command);
|
||||
// sprintf(path, "./%s/%s", dir, file);
|
||||
sprintf(path, "./fm/%s/%s", dir, file);
|
||||
printf("entry %d blks %d = %s\n", j+1, w1, path);
|
||||
sprintf(command, "touch %s", path);
|
||||
// printf("command = %s\n", command);
|
||||
system(command);
|
||||
|
||||
// printf("blks: %d file: path = %s\n", w1, path);
|
||||
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(path, "w")) == NULL) {
|
||||
//fprintf(stderr, "Can't open %s\n", path);
|
||||
printf("Can't open %s\n", path);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
|
||||
/* get the file data */
|
||||
for (m=0; m<((w1+5)/6); m++) {
|
||||
char data[5000]; /* data buffer */
|
||||
ll=getloi(data, 4608);
|
||||
|
||||
/* process file data for file */
|
||||
if (ll == 4608) {
|
||||
/* blks/w1 have number of blocks to write */
|
||||
int bcnt, no; /* block count */
|
||||
if (blks >= 6) {
|
||||
blks -= 6; /* enough for 6 block, write them */
|
||||
bcnt = 6*768; /* write all 6 blocks */
|
||||
} else {
|
||||
bcnt = blks*768;/* just write what we need */
|
||||
blks = 0;
|
||||
}
|
||||
/* only write number of sectors on save tape, not all 4608 */
|
||||
/* if zero, just reading excess blocks */
|
||||
if (bcnt != 0) {
|
||||
// no = write(outp, data, bcnt);
|
||||
no = fwrite(data, (size_t)1, (size_t)bcnt, outfp);
|
||||
if (no != bcnt)
|
||||
//fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
printf("write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
}
|
||||
} else {
|
||||
printf("Bad file size read! %d instead of 4608\n", ll);
|
||||
/// if (ll == -1) break;
|
||||
if (ll == -1)
|
||||
goto dostop;
|
||||
}
|
||||
} /* end writing file */
|
||||
} /* end of smd scan */
|
||||
} /* read smd entries 4608 byte records */
|
||||
// } /* process read of smd or sdt */
|
||||
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
} else {
|
||||
int cc = 0;
|
||||
// unsigned int curchar;
|
||||
|
||||
/* dump first 2 words */
|
||||
int w1, w2, i, j;
|
||||
w1 = (buf[0] & 0xff) << 24 | buf[1] << 16 | buf[2] << 8 | (buf[3] & 0xff);
|
||||
w2 = (buf[4] & 0xff) << 24 | buf[5] << 16 | buf[6] << 8 | (buf[7] & 0xff);
|
||||
// printf("w1 = %x, w2 = %d count = %d\n", w1, w2, count);
|
||||
if (count == 1 && w1 == 1) {
|
||||
char file[20], dir[20], vol[20];
|
||||
int off = 8;
|
||||
int l = 0;
|
||||
printf("Directory with %d entries\n", w2);
|
||||
/* we have directory entries */
|
||||
for (j=0; j<w2; j++) {
|
||||
int k = l++ * 48;
|
||||
if (k > (6144-48-off)) {
|
||||
ll=getloi(buf, buf_size);
|
||||
off = 0;
|
||||
l = 0;
|
||||
k = 0;
|
||||
// printf("reread: got ll= %d\n", ll);
|
||||
}
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[k+off+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[k+off+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[k+off+32+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
sprintf(path, "./%s/%s", vol, dir);
|
||||
#if 0
|
||||
/* create the directory/file */
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
#if 0
|
||||
sprintf(command, "touch %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
// printf("path0 = %s\n", path);
|
||||
}
|
||||
} else
|
||||
if (count == 1 && w1 == 2 && w2 == 0) {
|
||||
char file[20], dir[20], vol[20];
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL) {
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
sprintf(command, "touch -a -m -t %s %s", dtime, path);
|
||||
// sprintf(command, "touch -t %s %s", dtime, path);
|
||||
// printf("1cmd [%s] path[%s]\n", command, path);
|
||||
// fflush(stdout);
|
||||
system(command);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
/* process file definition */
|
||||
/* we have a file definition entry */
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[8+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[24+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[40+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
|
||||
i = 0x300 + 0x38; /* last modified date */
|
||||
// i = 0x300 + 0x20; /* creation date */
|
||||
/* get last modification time for file */
|
||||
/* day number since 1/1/1960 */
|
||||
// printf("D %02x%02x%02x%02x M %02x%02x%02x%02x\n",
|
||||
// buf[i+0],buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]);
|
||||
mpxtime[0] = buf[i+0] << 24 | buf[i+1] << 16 | buf[i+2] << 8 | (buf[i+3] & 0xff);
|
||||
/* .1ms count in day 0-864,000,000 */
|
||||
mpxtime[1] = (buf[i+4] << 24) | (buf[i+5] << 16) | (buf[i+6] << 8) | (buf[i+7] & 0xff);
|
||||
/* get UNIX time, secs sense 1970, not 1960 */
|
||||
utime =(time_t)((mpxtime[0]-3653)*86400)+(time_t)(mpxtime[1]/10000);
|
||||
dt = gmtime(&utime);
|
||||
j = dt->tm_year+1900;
|
||||
if (j > 2037)
|
||||
j -= 100;
|
||||
sprintf(dtime, "%04d%02d%02d%02d%02d", j, dt->tm_mon+1,
|
||||
dt->tm_mday, dt->tm_hour, dt->tm_min);
|
||||
// printf("mpx day %x ms %x utime %ld dtime %s\n", mpxtime[0], mpxtime[1], utime, dtime);
|
||||
// fflush(stdout);
|
||||
|
||||
sprintf(path, "./%s/%s", vol, dir);
|
||||
/* create the directory/file */
|
||||
// printf("dir path = %s\n", path);
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
system(command);
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
printf("path = %s\n", path);
|
||||
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(path, "w")) == NULL) {
|
||||
(void)fprintf(stderr, "Can't open %s\n", path);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
/* process file data for file */
|
||||
if (ll > 1536) {
|
||||
// int no = write(outp, buf+1536, ll-1536);
|
||||
int no = fwrite(buf+1536, (size_t)1, (size_t)(ll-1536), outfp);
|
||||
if (no != ll)
|
||||
fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
}
|
||||
} else
|
||||
if (count > 1) {
|
||||
/* process file data for file */
|
||||
// int no = write(outp, buf, ll);
|
||||
int no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
}
|
||||
} /* end if */
|
||||
} /* end while */
|
||||
dostop:
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL) {
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
sprintf(command, "touch -a -m -t %s %s", dtime, path);
|
||||
// sprintf(command, "touch -t %s %s", dtime, path);
|
||||
// printf("2cmd [%s]\n", command);
|
||||
// fflush(stdout);
|
||||
system(command);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
Following are the instructions for loading an ASCII file to an
|
||||
MPX-1.X system. It is assumed that the reader has compiled the
|
||||
utilities in the taptools directory using the provided makefile.
|
||||
Filenames on MPX-1.X must be 8 chars or less.
|
||||
|
||||
1. Create an ASCII file on Windows or Linux using your favorite editor.
|
||||
The EDIT program on MPX works with numbered or unnumbered text files.
|
||||
Each record in the text file uses columns 1-72 for text and columns
|
||||
73-80 for a line number (xxx.xxx). This is 80 column card format.
|
||||
|
||||
2. To convert a newline terminated file to an MPX file use the utility
|
||||
"renum" included in the taptools directory. Lines in the file will
|
||||
be expanded to 72 characters or truncated to 72 characters. The
|
||||
carriage return characters (\r) will be removed and lines will be
|
||||
terminated with a newline (\n). Line numbers of the form (xxx.xxx)
|
||||
will then be appended to the text line to create the card format.
|
||||
/somewhere/renum <textfile >cardfile
|
||||
|
||||
3. The next step is to convert the card image text file to an MPX
|
||||
blocked file format. This involves removing the carriage return
|
||||
character and then encoding the line into the blocked format.
|
||||
The block file format is the standard file format for MPX.
|
||||
/somewhere/mpxblk <cardfile >blkfile
|
||||
|
||||
4. Once we have the files converted, the next step involves creating
|
||||
a FILEMGR formatted save tape. The output file will be in SIMH
|
||||
.tap simulated tape format. The tape can then be read by the
|
||||
FILEMGR on MPX to load the files into the desired directory.
|
||||
The file system on MPX is a flat file where all files are in
|
||||
the same file system. A username is used to separate files for
|
||||
each user. A blank filename implies the system directory.
|
||||
/somewhere/mkfmtape -t -u username usertape.tap file1 file2 ...
|
||||
Valid options are:
|
||||
-p : use file type 0xca for executable programs
|
||||
-t : use file type 0xee for text files
|
||||
-l : use file type 0xff for library files
|
||||
-a : append current files to output tape
|
||||
-u username : the username (directory) for the files
|
||||
|
||||
Make sure the usertape.tap file is assigned to the tape drive
|
||||
in the .ini file or use the following commands at the sim>
|
||||
prompt for SEL32.
|
||||
hit ^E to get the sim> prompt.
|
||||
sim>detach mta0 remove current assignment
|
||||
sim>attach mta0 usertape.tap assign your restore tape
|
||||
sim>go
|
||||
|
||||
5. Boot MPX-1.X. Input @@A to get OPCOM prompt ??. Use cap lock for
|
||||
uppercase input. Type "EXIT" to OPCOM prompt to get a TSM> prompt.
|
||||
If you type WHO, TSM will display your current logon information.
|
||||
|
||||
TSM>WHO
|
||||
ADDRESS OWNERNAME USERNAME
|
||||
======= ========= ========
|
||||
*TY7EFC CONSOLE
|
||||
|
||||
The username will be blank for system directory. Use the command
|
||||
TSM>USERNAME JOHNDOE to set username to the one specified in the
|
||||
-u option above or just TSM>USERNAME to make it blank. There is a
|
||||
command file on MPX that is handy to restore files from tape that
|
||||
does the device assignments to the FILEMGR program. The file is
|
||||
FMGR and can be run to input files from the assigned tape. MPX-1.X
|
||||
has been SYSGEN'd to have 4 tape drives defined at 1000, 1001, 1002,
|
||||
& 1003. SIMH names are mta0, mta1, mta2, & mta3. So attach the
|
||||
restore file to mta0 as show above. Now execute the FILEMGR program.
|
||||
TSM>FMGR 1000
|
||||
TSM>FMGR 1000
|
||||
* * * F I L E M A N A G E R * * *
|
||||
FUNCTION USER NAME FILE NAME DEVICE START LENGTH SPEED
|
||||
(FIRST BLK) (# BLKS)
|
||||
|
||||
FILEMGR output will be assigned to the terminal and tape input from
|
||||
device MT1000. The FILEMGR will output a heading and then the FILEMGR
|
||||
prompt FIL>. At this point you can use the command FIL>SAVELOG to
|
||||
list the files on the tape or you can use the command FIL>RESTORE to
|
||||
restore the files to the disk. You can then type EXIT or X to the
|
||||
FIL> prompt to exit the FILEMGR.
|
||||
FIL>RESTORE
|
||||
RESTORE JOHNDOE FILE1 DM0800 234656 1052 SLOW
|
||||
FIL>REWIND IN
|
||||
REWIND (IN)
|
||||
FIL>X
|
||||
TSM>
|
||||
If you would like to see your files listed in the system, use
|
||||
FMGR again without any parameters. Then use LOGU to log your
|
||||
username files or LOG to log all files.
|
||||
TSM>FMGR
|
||||
heading here
|
||||
FIL>LOGU
|
||||
LOG JOHNDOE FILE1 DM0800 234656 1052 SLOW
|
||||
LOG JOHNDOE XX*WRKFL DM0800 233536 1120 SLOW
|
||||
FIL>LOG
|
||||
LOG 1X.PRE DM0800 302916 24 SLOW
|
||||
LOG 7X.PRE DM0800 302892 24 SLOW
|
||||
LOG ALOC.L DM0800 241312 800 SLOW
|
||||
LOG ASM DM0800 302884 8 SLOW
|
||||
LOG ASSEMBLE DM0800 296784 84 SLOW
|
||||
LOG ASSM DM0800 302872 12 SLOW
|
||||
LOG ASSMJ DM0800 302864 8 SLOW
|
||||
LOG ASSML DM0800 302860 4 SLOW
|
||||
LOG BOOT27 DM0800 303424 24 SLOW
|
||||
all files list here
|
||||
|
||||
6. You can use the program EDIT to view or modify the file. At the
|
||||
TSM> prompt type EDIT XX, where XX is a two character editor
|
||||
workfile name. It will show up in the directory listing as XX*WRKFL.
|
||||
At the EDT> prompt type USE FILE1. You will get another prompt when
|
||||
the editor is done reading the file. Hit return to list the file.
|
||||
|
||||
TSM>EDIT XX
|
||||
BEGIN TEXT EDITOR
|
||||
XX*WRKFL CLEAR
|
||||
EDT> USE FILE1
|
||||
File listing will be here.
|
||||
|
||||
See the MPX-1.X reference manuals for the other FILEMGR and EDIT commands.
|
||||
|
||||
Jim Bevier
|
||||
03/10/2020
|
||||
@@ -1,227 +0,0 @@
|
||||
# Makefile for taptools
|
||||
SHELL = /bin/sh
|
||||
|
||||
# Adapt the flags in the following paragraph to your system
|
||||
# for Linux
|
||||
ROOT = .
|
||||
OPTC = -O #-m32
|
||||
|
||||
#B = $(ROOT)
|
||||
#B = $(ROOT)/bin
|
||||
B = /system/bin
|
||||
#I = $(ROOT)/include
|
||||
I =
|
||||
#L = $(ROOT)/lib
|
||||
#D = $L/mylib.a
|
||||
D =
|
||||
|
||||
##CFLAGS= $(OPTC) -I$I
|
||||
CFLAGS= $(OPTC) -I$I -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
# For Linux
|
||||
#LFLAGS= -L$L
|
||||
LFLAGS=
|
||||
|
||||
PROGS = \
|
||||
$(ROOT)/diskload \
|
||||
$(ROOT)/filelist \
|
||||
$(ROOT)/fmgrcopy \
|
||||
$(ROOT)/mkfmtape \
|
||||
$(ROOT)/mkvmtape \
|
||||
$(ROOT)/sdtfmgrcopy \
|
||||
$(ROOT)/mkdiagtape \
|
||||
$(ROOT)/tapdump \
|
||||
$(ROOT)/tape2disk \
|
||||
$(ROOT)/disk2tap \
|
||||
$(ROOT)/tapscan \
|
||||
$(ROOT)/eomtap \
|
||||
$(ROOT)/volmcopy \
|
||||
$(ROOT)/instcopy \
|
||||
$(ROOT)/diagcopy \
|
||||
$(ROOT)/ddump \
|
||||
$(ROOT)/deblk \
|
||||
$(ROOT)/mpxblk \
|
||||
$(ROOT)/renum \
|
||||
$(ROOT)/tap2disk \
|
||||
$(ROOT)/cutostap \
|
||||
$(ROOT)/small
|
||||
## $(ROOT)/fileread
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
#install :$(PROGS)
|
||||
# @cp $(@F) $B
|
||||
# @echo $(@F) installed in $B
|
||||
# @echo
|
||||
## @chmod 755 $(@F)
|
||||
|
||||
##$(PROGS): $D $$(@F).c
|
||||
## @-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
##$(PROGS): $D $$(@F).c
|
||||
## @chmod 755 $@
|
||||
## @cp $(@F) $B
|
||||
## @echo $(@F) installed in $B
|
||||
## @echo
|
||||
|
||||
$B/diskload: $D diskload.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/filelist: $D filelist.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/fmgrcopy: $D fmgrcopy.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/mkfmtape: $D mkfmtape.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/mkvmtape: $D mkvmtape.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/sdtfmgrcopy: $D sdtfmgrcopy.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/mkdiagtape: $D mkdiagtape.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/tapdump: $D tapdump.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/tape2disk: $D tape2disk.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
##$B/fileread: $D fileread.c
|
||||
## @-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
## @chmod 755 $@
|
||||
## @cp $(@F) $B
|
||||
## @echo $(@F) installed in $B
|
||||
|
||||
$B/disk2tap: $D disk2tap.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/tapsca: $D tapscan.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/eomtap: $D eomtap.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/volmcopy: $D volmcopy.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/instcopy: $D instcopy.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/diagcopy: $D diagcopy.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/ddump: $D ddump.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/deblk: $D deblk.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/mpxblk: $D mpxblk.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/renum: $D renum.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/cutostap: $D cutostap.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/tap2disk: $D tap2disk.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
$B/small: $D small.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
# Some makes don't understand the $$ notation above. In this case
|
||||
# you have to type out the compile paragraph for each PROG. Sigh.
|
||||
# Here's a start, good luck.
|
||||
#
|
||||
#$B/abshw: abshw.c
|
||||
# $(CC) $(CFLAGS) $? $(LFLAGS) -o $@
|
||||
# @chmod 751 $@
|
||||
# @echo $(@F) installed in $B
|
||||
|
||||
remake : clobber
|
||||
@make ROOT=$(ROOT) OPTC=$(OPTC)
|
||||
|
||||
clean :
|
||||
@-rm -f a.out junk* JUNK* core
|
||||
@-rm -f *.o
|
||||
|
||||
clobber : clean
|
||||
@-rm -f $(PROGS)
|
||||
|
||||
install : $(PROGS)
|
||||
@cp $(PROGS) $B
|
||||
@echo $(PROGS) installed in $B
|
||||
@echo
|
||||
# @chmod 755 $(@F)
|
||||
@@ -1,301 +0,0 @@
|
||||
/*
|
||||
* mkdiagtape.c
|
||||
*
|
||||
* This program extracts the diag command file (file 2) from a
|
||||
* diagnostic tape in .tap format and replaces it with a new
|
||||
* command file. The rest of the tape is copied unchanged.
|
||||
* intput - simulated indiagtape outdiagtape
|
||||
* output - simulated newtape
|
||||
* option - -c = cmdfile
|
||||
* 08/22/2020
|
||||
* 02/14/2022
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#ifdef _WIN32
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
//#include <unistd.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 uint8;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef signed __int64 t_int64;
|
||||
typedef unsigned __int64 t_uint64;
|
||||
typedef t_int64 off_t;
|
||||
#else
|
||||
/* All modern/standard compiler environments */
|
||||
/* any other environment needa a special case above */
|
||||
#include <stdint.h>
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif /* end standard integers */
|
||||
|
||||
#define BLKSIZE 768 /* MPX file sector size */
|
||||
unsigned char data[7680]; /* room for 10*768=(7680) 768 byte sectors per 7680 byte block */
|
||||
|
||||
/* write 1 file to tape in 768 byte records */
|
||||
/* mblks is the maximum blockes to write from a file, 0=all */
|
||||
/* chunks is the number of sectors to wrote at a time 1-8 */
|
||||
int writefile(FILE *tp, char *fnp, uint32 mblks, int32 chunks) {
|
||||
int32 word, blks=mblks; /* just a temp word variable */
|
||||
int32 size, bsize, csize; /* size in 768 byte sectors */
|
||||
FILE *fp;
|
||||
int32_t n1, n2, hc, nw, cs;
|
||||
|
||||
memset((char *)data, 0, sizeof(data)); /* zero data storage */
|
||||
/* write file to tape */
|
||||
if ((fp = fopen(fnp, "r")) == NULL) {
|
||||
fprintf(stderr, "error: can't open user file %s\n", fnp);
|
||||
exit(1);
|
||||
}
|
||||
fseek(fp, 0, SEEK_END); /* seek to end */
|
||||
word = ftell(fp); /* get filesize in bytes */
|
||||
//printf("MPX file %s is %x (%d) bytes\n", fnp, word, word);
|
||||
fseek(fp, 0, SEEK_SET); /* rewind file */
|
||||
size = (word/768); /* filesize in sectors */
|
||||
if (word%768 != 0) /* see if byte left over */
|
||||
size += 1; /* partial sector, add 1 */
|
||||
if (mblks == 0) {
|
||||
mblks = (word/768); /* blocks */
|
||||
if ((word%768) != 0) /* round up blks if remainder */
|
||||
mblks++; /* total block to write */
|
||||
}
|
||||
blks = mblks/chunks; /* chunks */
|
||||
if (mblks%768 != 0) /* see if blks left over */
|
||||
blks += 1; /* partial blks, add 1 */
|
||||
|
||||
bsize = mblks; /* save # blks */
|
||||
|
||||
//printf("MPX file %s is %x (%d) bytes blks %d chk %d\n",
|
||||
// fnp, word, word, bsize, (bsize+1)/chunks);
|
||||
csize = 0;
|
||||
/* read in the image file */
|
||||
while (bsize > 0) {
|
||||
if (bsize > chunks) /* see if there is a chunk left to read */
|
||||
csize = chunks; /* yes, do max chunk size */
|
||||
else
|
||||
csize = bsize; /* no, use what is left */
|
||||
cs = fread((char *)data, 1, csize*768, fp);
|
||||
/* we have data to write */
|
||||
hc = (csize*768 + 1) & ~1; /* make byte count even */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&hc), 1, (size_t)sizeof(hc), tp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((unsigned char *)data, 1, (size_t)hc, tp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), 1, (size_t)sizeof(hc), tp);
|
||||
if (n1 != sizeof(hc) || nw != hc || n2 != sizeof(hc))
|
||||
{
|
||||
fprintf(stderr, "write to %s failure\n", fnp);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
exit(1);
|
||||
}
|
||||
bsize -= csize; /* do next chunk */
|
||||
memset((char *)data, 0, csize); /* zero data storage */
|
||||
}
|
||||
//printf("write file %s (size %d bytes) (%d sect) (%d blocks) (%d chunks)\n",
|
||||
// fnp, word, size, mblks, blks);
|
||||
//HUH fclose(fp);
|
||||
//HUH exit(0);
|
||||
//printf("return from write file\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* read program file and output to a simulated diagnostic tape */
|
||||
/* mkdiagtape -c cmdfile diagtape diagtapeout */
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *dp, *fp, *fopen();
|
||||
char **targv;
|
||||
char *p, *cmdp;
|
||||
int i;
|
||||
unsigned int word; /* just a temp word variable */
|
||||
int goteof; /* end flags */
|
||||
int writing; /* writing output */
|
||||
|
||||
memset((char *)data, 0, 4608); /* zero data storage */
|
||||
|
||||
targv = argv; /* save filename */
|
||||
if (argc <= 1) { /* see if correct # args */
|
||||
fprintf(stderr, "Usage: %s [-ptloa] [-uusername] fmgrtape file1 file2 ...\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
while(--argc > 0) {
|
||||
printf("argc %d argv %s\n", argc, *argv);
|
||||
p = *++argv;
|
||||
if (*p++ == '-') {
|
||||
if (*p == '\0') {
|
||||
fprintf(stderr, "Error: no option specified\n");
|
||||
fprintf(stderr, "Usage: %s -c cmdfile infile outfile\n", *targv);
|
||||
exit(1);
|
||||
}
|
||||
printf("doing options %s\n", p);
|
||||
while (*p != '\0') {
|
||||
switch (*p++) {
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (*p == '\0') {
|
||||
p = *++argv; /* next parameter */
|
||||
--argc; /* one less arg */
|
||||
};
|
||||
cmdp = p; /* save ptr to file name */
|
||||
while (*p != '\0')
|
||||
p++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Error: no cmd file specified\n");
|
||||
fprintf(stderr, "Usage: %s -c cmdfile infile outfile\n", *targv);
|
||||
exit(1);
|
||||
break;
|
||||
} /* end switch */
|
||||
continue;
|
||||
} /* end while */
|
||||
}
|
||||
else {
|
||||
if ((dp = fopen(*argv, "r")) == NULL) {
|
||||
fprintf(stderr, "error: can't open input diag tape file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
printf("opening %s file for tape\n", *argv);
|
||||
*++argv;
|
||||
break; /* go handle files now */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
/* end while --argc */
|
||||
if ((argc-1) <= 0) {
|
||||
fprintf(stderr, "Error: incorrect number of parameters\n");
|
||||
fprintf(stderr, "Usage: %s -c cmdfile infile outfile\n", *targv);
|
||||
exit(1);
|
||||
}
|
||||
/* got input tapefile and options, handle output file now */
|
||||
//printf("AT 3 argc %d argv %s\n", argc, *argv);
|
||||
if (--argc > 0) {
|
||||
p = *argv++;
|
||||
printf("argc %d argv3 %s\n", argc, p);
|
||||
if ((fp = fopen(p, "w")) == NULL) {
|
||||
fprintf(stderr, "error: can't open tape output file %s\n", p);
|
||||
fprintf(stderr, "Usage: %s -c cmdfile infile outfile\n", *targv);
|
||||
exit(1);
|
||||
}
|
||||
printf("opened output file %s\n", p);
|
||||
}
|
||||
|
||||
/* now copy input tape until 1st EOF */
|
||||
goteof = 0; /* no eof yet */
|
||||
writing = 1; /* we are copying in to out */
|
||||
while (goteof == 0) {
|
||||
int n1, n2, hc, tc, n, nw;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
n1 = fread((char *)(&hc), 1, (size_t)4, dp);
|
||||
|
||||
/* check for EOM on tape */
|
||||
if ((n1 <= 0) || (hc & 0xffff0000)) { /* check for garbage, assume EOM */
|
||||
fprintf(stderr, "Premature EOM on input file bad tape\n");
|
||||
exit(1);
|
||||
}
|
||||
/* see if at EOF */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (writing == 0)
|
||||
break; /* done with copy */
|
||||
writing = 0; /* stop writing */
|
||||
/* copy the EOF to the output tape */
|
||||
n1 = fwrite((char *)(&hc), 1, (size_t)4, fp);
|
||||
if (n1 != 4) {
|
||||
fprintf(stderr, "Error write EOF to output file\n");
|
||||
exit(1);
|
||||
}
|
||||
continue; /* continue processing */
|
||||
}
|
||||
|
||||
/* read the data to copy to output */
|
||||
n = fread(data, 1, (size_t)hc, dp);
|
||||
if (n <= 0) {
|
||||
fprintf(stderr, "Read error on input file bad tape\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
n2 = fread((char *)(&tc), 1, (size_t)1, dp);
|
||||
if (n2 <= 0) {
|
||||
fprintf(stderr, "Read error on input file bad tape\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
/* if writing, write out the record */
|
||||
if (writing) {
|
||||
int wc = n; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&wc), 1, (size_t)4, fp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite(data, 1, (size_t)hc, fp);
|
||||
if (n1 != 4 || nw != hc) {
|
||||
fprintf(stderr, "write error to tape\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
n2 = fread((char *)(&tc), 1, (size_t)4, dp);
|
||||
if (n2 <= 0) {
|
||||
fprintf(stderr, "Read error on input file bad tape\n");
|
||||
exit(1);
|
||||
}
|
||||
if (writing) {
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&tc), 1, (size_t)4, fp);
|
||||
if (n2 != 4) {
|
||||
fprintf(stderr, "write error to tape\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now handle new command file */
|
||||
/* we have copied the first file and bypassed the second */
|
||||
/* copy in the new com file and write out 768 byte records */
|
||||
writefile(fp, cmdp, 0, 1); /* write command file out in 768 byte blks */
|
||||
|
||||
word = 0;
|
||||
/* copy the EOF to the output tape */
|
||||
i = fwrite((char *)(&word), 1, (size_t)4, fp);
|
||||
if (i != 4) {
|
||||
fprintf(stderr, "Error writing EOF to output file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* read the data to copy to output */
|
||||
i = fread(data, 1, (size_t)7680, dp);
|
||||
//printf("got i = %x after fread call\n", i);
|
||||
if (i <= 0) {
|
||||
fprintf(stderr, "EOM input file, done\n");
|
||||
break;
|
||||
}
|
||||
/* write the data to output */
|
||||
i = fwrite(data, 1, (size_t)i, fp);
|
||||
if (i <= 0) {
|
||||
fprintf(stderr, "Error writing data to output file\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(dp);
|
||||
fclose(fp);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,427 +0,0 @@
|
||||
/*
|
||||
* mkfmtape.c
|
||||
*
|
||||
* This program reads MPX files and stores it into a simulated
|
||||
* filemgr save tape. The tape may then be restored to a MPX
|
||||
* running system using the filemgr.
|
||||
* new file entry.
|
||||
* intput - simulated fmgrtape filename, filename, etc.
|
||||
* output - simulated fmgrtape, file list to stdout
|
||||
* options - -p = file type 0xca for programs
|
||||
* - -t = ascii text file 0xee
|
||||
* - -l = library/directory file 0xff
|
||||
* - -o = other 0x00
|
||||
* - -a = append entries to current file
|
||||
* - -u = username (directory)
|
||||
* 11/26/2018
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 uint8;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef signed __int64 t_int64;
|
||||
typedef unsigned __int64 t_uint64;
|
||||
typedef t_int64 off_t;
|
||||
#else
|
||||
/* All modern/standard compiler environments */
|
||||
/* any other environment needa a special case above */
|
||||
#include <stdint.h>
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif /* end standard integers */
|
||||
|
||||
#define BLKSIZE 768 /* MPX file sector size */
|
||||
uint32 dir[1152]; /* room for 144 8w smd entries */
|
||||
unsigned char data[4608]; /* room for 6*768=(4608) 768 byte sectors per 4608 byte block */
|
||||
unsigned char bigdata[19200]; /* room for 6*768=(4608) 768 byte sectors per 4608 byte block */
|
||||
|
||||
/* read program file and output to a simulated mpx1.x filemgr savetape */
|
||||
/* mkfmtape -ltoa fmgrtape, filename, filename, ... */
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *fp, *dp, *fopen();
|
||||
int targc;
|
||||
char **targv;
|
||||
unsigned char username[8];
|
||||
char *p;
|
||||
int i;
|
||||
#define DOPROG 1
|
||||
#define DOADD 2
|
||||
#define DOOTHER 4
|
||||
#define DOTEXT 8
|
||||
#define DOLIB 16
|
||||
#define DOUSER 32
|
||||
unsigned int option = DOTEXT; /* what to do */
|
||||
unsigned char *fnp; /* file name pointer */
|
||||
unsigned int size; /* size in 768 byte sectors */
|
||||
unsigned int word; /* just a temp word variable */
|
||||
unsigned char name[9]; /* LM name */
|
||||
unsigned int typ; /* file type requested by user */
|
||||
char *userp = username; /* pointer to username */
|
||||
// int ofd; /* output file number */
|
||||
int filen; /* file number */
|
||||
uint32 *dirp; /* directory entry pointer */
|
||||
int totent; /* total smd entries */
|
||||
|
||||
memset((char *)dir, 0, 4608); /* zero smd storage */
|
||||
memset((char *)data, 0, 4608); /* zero data storage */
|
||||
for (i=0; i<8; i++)
|
||||
username[i] = 0; /* use zero for system username */
|
||||
typ = 0xee000000; /* set type */
|
||||
if (argc <= 1) { /* see if correct # args */
|
||||
fprintf(stderr, "Usage: %s [-ptloa] [-uusername] fmgrtape file1 file2 ...\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
while(--argc > 0) {
|
||||
// printf("argc %d argv %s\n", argc, *argv);
|
||||
p = *++argv;
|
||||
if (*p++ == '-') {
|
||||
if (*p == '\0') {
|
||||
fprintf(stderr, "Error: no option specified\n");
|
||||
fprintf(stderr, "Usage: %s [-ptloa] [-uusername] fmgrtape file1 file2 ...\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
// printf("doing options %s\n", p);
|
||||
while (*p != '\0') {
|
||||
switch (*p++) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
option |= DOPROG; /* save program modules */
|
||||
typ = 0xca; /* set type */
|
||||
break;
|
||||
case 'A':
|
||||
case 'a':
|
||||
option |= DOADD; /* append to save tape */
|
||||
break;
|
||||
case 'O':
|
||||
case 'o':
|
||||
option |= DOOTHER; /* other type files */
|
||||
typ = 0x00; /* set type */
|
||||
break;
|
||||
case 'T':
|
||||
case 't':
|
||||
option |= DOTEXT; /* save text files */
|
||||
typ = 0xee; /* set type */
|
||||
break;
|
||||
case 'L':
|
||||
case 'l':
|
||||
option |= DOLIB; /* save library files */
|
||||
typ = 0xff; /* set type */
|
||||
break;
|
||||
case 'U':
|
||||
case 'u':
|
||||
option |= DOUSER; /* save username for files */
|
||||
if (*p == '\0') {
|
||||
p = *++argv; /* next parameter */
|
||||
--argc; /* one less arg */
|
||||
};
|
||||
userp = p;
|
||||
while (*p != '\0')
|
||||
p++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Error: no option specified\n");
|
||||
fprintf(stderr, "Usage: %s [-ptloa] [-uusername] fmgrtape file1 file2 ...\n", *argv);
|
||||
exit(1);
|
||||
break;
|
||||
} /* end switch */
|
||||
continue;
|
||||
} /* end while */
|
||||
}
|
||||
else {
|
||||
// printf("option set to %x\n", option);
|
||||
if (option & DOADD) {
|
||||
long bytes;
|
||||
/* open read/write */
|
||||
if ((dp = fopen(*argv, "r+")) == NULL) {
|
||||
/* file not there, create one by opening w+ */
|
||||
if ((dp = fopen(*argv, "w")) == NULL) {
|
||||
fprintf(stderr, "error: can't create/open simulated tape disk file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
// printf("1 opened output in w mode, write at start\n");
|
||||
}
|
||||
// else
|
||||
// printf("2 opened output in r+ mode write at end\n");
|
||||
|
||||
fseek(dp, 0, SEEK_END); /* seek to end */
|
||||
bytes = ftell(dp); /* get filesize in bytes */
|
||||
printf("file length %ld bytes\n", bytes);
|
||||
printf("start writing at %ld bytes offset\n", bytes-8);
|
||||
fseek(dp, 0, SEEK_SET); /* rewind file to beginning */
|
||||
if (bytes > 8) { /* see if file written to already */
|
||||
/* we need to find the EOT */
|
||||
int n1, n2, hc, tc, n;
|
||||
int EOFcnt = 0;
|
||||
readmore:
|
||||
n1 = fread((char *)(&hc), 1, (size_t)4, dp); /* read 4 byte record size */
|
||||
if (n1 <=0) /* check for read error */
|
||||
goto doabort; /* bad tape format */
|
||||
|
||||
if (hc & 0xffff0000) /* check for garbage */
|
||||
hc = 0; /* assume EOF on disk */
|
||||
|
||||
if (hc == 0) { /* check for EOF on file */
|
||||
/* EOF found */
|
||||
if (++EOFcnt == 2) {
|
||||
/* we have second EOF, we need to backup 4 bytes */
|
||||
backup4:
|
||||
bytes = ftell(dp); /* get file position in bytes */
|
||||
fseek(dp, bytes-4, SEEK_SET); /* backspace over 2nd EOF */
|
||||
goto getout; /* start our processing */
|
||||
}
|
||||
/* we have first EOF, keep reading */
|
||||
goto readmore; /* read more records */
|
||||
} else
|
||||
if (hc == -1) { /* check for EOM */
|
||||
if (EOFcnt == 1)
|
||||
/* see if one EOF followed by EOM (-1) */
|
||||
goto backup4; /* start write over the EOM */
|
||||
/* we have an EOM without any EOF, so bad tape */
|
||||
goto doabort; /* bad tape format */
|
||||
}
|
||||
|
||||
/* we have data, so no EOF */
|
||||
EOFcnt = 0; /* reset EOF count */
|
||||
|
||||
/* read the data */
|
||||
tc = hc; /* save record size */
|
||||
n = fread(bigdata, 1, (size_t)hc, dp); /* read in record size */
|
||||
if (n <= 0) { /* check for read error */
|
||||
goto doabort; /* bad tape format */
|
||||
}
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
n2 = fread((char *)(&hc), (size_t)1, (size_t)1, dp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
n2 = fread((char *)(&hc), 1, (size_t)4, dp); /* read 4 byte record size */
|
||||
if (n2 <= 0) { /* check for read error */
|
||||
doabort:
|
||||
/* error, abort the operation */
|
||||
fprintf(stderr, "error: formatting error on simulated tape disk file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
/* verify counts & sizes */
|
||||
if ((tc != hc) || (hc != n))
|
||||
goto doabort; /* bad tape format */
|
||||
goto readmore; /* read more records */
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((dp = fopen(*argv, "w")) == NULL) {
|
||||
fprintf(stderr, "error: can't create/open simulated tape disk file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
// printf("3 opened output in w mode, write at start\n");
|
||||
}
|
||||
getout:
|
||||
// printf("opening %s file for tape\n", *argv);
|
||||
*++argv;
|
||||
break; /* go handle files now */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
/* end while --argc */
|
||||
if ((argc-1) <= 0) {
|
||||
fprintf(stderr, "Error: incorrect number of parameters\n");
|
||||
fprintf(stderr, "Usage: %s [-ptloa] [-uusername] fmgrtape, file1 file2 ...\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
/* got tapefile and options, handle files now */
|
||||
targc = argc; /* save argc to reread list */
|
||||
targv = argv; /* save argv to reread list */
|
||||
// printf("AT 3 argc %d argv %s\n", argc, *argv);
|
||||
filen = 0; /* no files yet */
|
||||
totent = 0; /* no files yet */
|
||||
/* populate the 32 byte SMD entry */
|
||||
dirp = (uint32 *)dir; /* get word pointer for smd data */
|
||||
while (--argc > 0) {
|
||||
uint32 smd[8]; /* smd entry data */
|
||||
int blks;
|
||||
|
||||
for (i=0; i<8; i++) /* zero smd entry */
|
||||
smd[i] = 0;
|
||||
p = *argv++;
|
||||
i = strlen(p); /* filename size */
|
||||
if (i == 0 || i > 8) {
|
||||
fprintf(stderr, "error: Filename too long (%d>8) %s, Aborting\n", i, p);
|
||||
exit(1);
|
||||
}
|
||||
// printf("argc %d argv3 %s\n", argc, p);
|
||||
if ((fp = fopen(p, "r")) == NULL) {
|
||||
fprintf(stderr, "error: can't open user file %s\n", p);
|
||||
exit(1);
|
||||
}
|
||||
fnp = p; /* get file name pointer */
|
||||
fseek(fp, 0, SEEK_END); /* seek to end */
|
||||
word = ftell(fp); /* get filesize in bytes */
|
||||
fseek(fp, 0, SEEK_SET); /* rewind file */
|
||||
size = (word/768); /* filesize in sectors */
|
||||
if (word%768 != 0) /* see if byte left over */
|
||||
size += 1; /* partial sector, add 1 */
|
||||
blks = (word/4608); /* blocks */
|
||||
if ((word%4608) != 0)
|
||||
blks++;
|
||||
printf("write SMD %s user %s size %d bytes %d sect %d blocks\n",
|
||||
fnp, userp, word, size, blks);
|
||||
fclose(fp);
|
||||
/* create smd entry for this file */
|
||||
memset(name, ' ', 8); /* blank filename */
|
||||
for (i=0; i<8; i++) {
|
||||
if (p[i] == '\0') /* check for null termination char */
|
||||
break;
|
||||
name[i] = toupper(p[i]); /* uppercase filename */
|
||||
}
|
||||
/* populate the 32 byte SMD entry */
|
||||
/* word 1 and 2 has filename */
|
||||
smd[0] = name[3] << 24 | name[2] << 16 | name[1] << 8 | name[0];
|
||||
smd[1] = name[7] << 24 | name[6] << 16 | name[5] << 8 | name[4];
|
||||
/* type and smd loc in wd 2 */
|
||||
smd[2] = typ; /* save the type of file */
|
||||
/* size now has load module size in sectors */
|
||||
size = 0x80000000 | (blks * 6); /* file flags and size */
|
||||
smd[3] = (size & 0xff) << 24 | (size & 0xff00) << 8 |
|
||||
(size & 0xff0000) >> 8 | (size & 0xff000000) >> 24;
|
||||
memset(name, ' ', 8); /* blank username */
|
||||
for (i=0; i<8; i++) {
|
||||
if (userp[i] == '\0') /* check for null termination char */
|
||||
break;
|
||||
name[i] = toupper(userp[i]); /* uppercase username */
|
||||
}
|
||||
/* set username */
|
||||
smd[4] = name[3] << 24 | name[2] << 16 | name[1] << 8 | name[0];
|
||||
smd[5] = name[7] << 24 | name[6] << 16 | name[5] << 8 | name[4];
|
||||
if (((smd[4] == 0x20202020) && (smd[5] == 0x20202020)) ||
|
||||
((smd[4] == 0) && (smd[5] == 0))) {
|
||||
smd[4] = smd[5] = 0; /* use null for system */
|
||||
}
|
||||
smd[6] = 0x00080000; /* no password or udt index */
|
||||
smd[7] = 0x00000080; /* fmgr has 0x80000000 in it so I will too */
|
||||
for (i=0; i<8; i++)
|
||||
*dirp++ = smd[i]; /* save smd entry */
|
||||
filen++; /* bump the file count */
|
||||
totent++; /* bump total count */
|
||||
if (filen == 144) { /* see if entry is full */
|
||||
/* we need to write out the directory entries */
|
||||
int32 n1, nw;
|
||||
/* we have data to write */
|
||||
int32 hc = (4608 + 1) & ~1; /* make byte count even */
|
||||
int32 n2 = 4608; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&n2), 1, (size_t)4, dp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((unsigned char *)dir, 1, (size_t)hc, dp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), 1, (size_t)4, dp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
exit(1);
|
||||
}
|
||||
memset((char *)dir, 0, 4608); /* zero smd storage */
|
||||
filen = 0; /* restart count */
|
||||
dirp = (uint32 *)dir; /* get word pointer for smd data */
|
||||
}
|
||||
}
|
||||
/* write out the directory entries for the files to save */
|
||||
if (filen != 0) {
|
||||
/* we need to write out the directory entries */
|
||||
int32 n1, nw;
|
||||
/* we have data to write */
|
||||
int32 hc = (4608 + 1) & ~1; /* make byte count even */
|
||||
int32 n2 = 4608; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&n2), 1, (size_t)4, dp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((unsigned char *)dir, 1, (size_t)hc, dp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), 1, (size_t)4, dp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
exit(1);
|
||||
}
|
||||
memset(dir, 0, 4608); /* zero smd storage */
|
||||
filen = 0; /* restart count */
|
||||
}
|
||||
/* totcnt has total number of files to output */
|
||||
memset((char *)data, 0, 4608); /* zero data storage */
|
||||
argc = targc; /* restore argc for reread */
|
||||
argv = targv; /* restore argv for reread */
|
||||
/* read each file and output to save tape file in 6 sector blocks */
|
||||
while (--argc > 0) {
|
||||
int blks;
|
||||
|
||||
p = *argv++;
|
||||
// printf("argc %d argv3 %s\n", argc, p);
|
||||
if ((fp = fopen(p, "r")) == NULL) {
|
||||
fprintf(stderr, "error: can't open user file %s\n", p);
|
||||
exit(1);
|
||||
}
|
||||
fnp = p; /* get file name pointer */
|
||||
fseek(fp, 0, SEEK_END); /* seek to end */
|
||||
word = ftell(fp); /* get filesize in bytes */
|
||||
fseek(fp, 0, SEEK_SET); /* rewind file */
|
||||
size = (word/768); /* filesize in sectors */
|
||||
if (word%768 != 0) /* see if byte left over */
|
||||
size += 1; /* partial sector, add 1 */
|
||||
blks = (word/4608); /* blocks */
|
||||
if ((word%4608) != 0)
|
||||
blks++;
|
||||
// rewind(fp); /* back to beginning */
|
||||
while (fread((char *)data, 1, 4608, fp) > 0) {
|
||||
int32 n1, nw;
|
||||
/* we have data to write */
|
||||
int32 hc = (4608 + 1) & ~1; /* make byte count even */
|
||||
int32 n2 = 4608; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&n2), 1, (size_t)4, dp);
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((unsigned char *)data, 1, (size_t)hc, dp);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), 1, (size_t)4, dp);
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
exit(1);
|
||||
}
|
||||
memset((char *)data, 0, 4608); /* zero data storage */
|
||||
}
|
||||
printf("write file %s user %s (size %d bytes) (%d sect) (%d blocks)\n",
|
||||
fnp, userp, word, size, blks);
|
||||
fclose(fp);
|
||||
}
|
||||
/* write EOF (zero) to file */
|
||||
filen = 0; /* zero count */
|
||||
fwrite((char *)(&filen), 1, (size_t)4, dp);
|
||||
/* do second EOF */
|
||||
fwrite((char *)(&filen), 1, (size_t)4, dp);
|
||||
filen = -1; /* make in -1 for EOM */
|
||||
/* do EOM */
|
||||
fwrite((char *)(&filen), 1, (size_t)4, dp);
|
||||
// printf("setting at %ld bytes in file after EOM\n", ftell(dp));
|
||||
fclose(dp);
|
||||
exit(0);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* mpxblk.c
|
||||
*
|
||||
* This program converts a unix/dos ascii file to an mpx blocked file
|
||||
* trailing blanks are not deleted from the source file
|
||||
* input - stdin
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
//#include <unistd.h>
|
||||
#define MPXMAX 254
|
||||
int mpxbb();
|
||||
int getloi();
|
||||
#define BLKSIZE 768
|
||||
|
||||
int main (argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char s[MPXMAX];
|
||||
int i;
|
||||
// int fn = fileno(stdout);
|
||||
FILE *fn = stdout;
|
||||
|
||||
while (1) {
|
||||
// if ((i = getloi(s, MPXMAX)) == 0) {
|
||||
if ((i = getloi(stdin, s, MPXMAX)) == 0) {
|
||||
mpxbb(fn, s, 0, 1); /* last write to output */
|
||||
exit(0);
|
||||
}
|
||||
if (i == 1 && s[0] == '\n')
|
||||
s[0] = ' '; /* replace single n/l with blank */
|
||||
if (s[i-1] == '\n')
|
||||
i--; /* remove trailing n/l */
|
||||
if (mpxbb(fn, s, i, 0) < 0) { /* last data record out */
|
||||
fprintf(stderr, "output file error\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* get a line of input. */
|
||||
/* terminate line on \n or \r\n */
|
||||
/* allow max of 254 chars in a line */
|
||||
|
||||
//int getloi(s, lim)
|
||||
int getloi(ifp, s, lim)
|
||||
FILE *ifp;
|
||||
char s[];
|
||||
int lim;
|
||||
{
|
||||
int c, i;
|
||||
|
||||
for(i = 0; --lim > 0; ) {
|
||||
// c = getchar();
|
||||
c = fgetc(ifp);
|
||||
switch (c) {
|
||||
case '\n':
|
||||
/* terminate on \n */
|
||||
s[i++] = c;
|
||||
goto linedone;
|
||||
case '\r':
|
||||
// c = getchar();
|
||||
c = fgetc(ifp);
|
||||
/* terminate on \r\n */
|
||||
if (c == '\n') {
|
||||
s[i++] = c;
|
||||
goto linedone;
|
||||
}
|
||||
/* put back the character */
|
||||
// ungetc(c, stdin);
|
||||
ungetc(c, ifp);
|
||||
/* output the \r to the stream */
|
||||
c = '\r';
|
||||
/* drop through */
|
||||
default:
|
||||
s[i++] = c;
|
||||
break;
|
||||
case EOF:
|
||||
return (0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
linedone:
|
||||
return (i);
|
||||
}
|
||||
|
||||
/*
|
||||
** output line of text from the source
|
||||
*/
|
||||
|
||||
static unsigned char bb[BLKSIZE]; /* blocking buffer */
|
||||
static char first = 0; /* 1st time thru flag */
|
||||
|
||||
/*
|
||||
* mpxbb - make up mpx block file output
|
||||
* input - buffer address
|
||||
* - byte count
|
||||
* - last write flag
|
||||
*/
|
||||
|
||||
int
|
||||
// mpxbb(fd, buf, cnt, last)
|
||||
mpxbb(fd, buf, cnt, last)
|
||||
//int fd;
|
||||
FILE *fd;
|
||||
unsigned char *buf;
|
||||
int cnt;
|
||||
int last;
|
||||
{
|
||||
int boff; /* next write address offset */
|
||||
|
||||
if (!first) { /* is this 1st time thru */
|
||||
first = 1; /* set the flag */
|
||||
memset (bb, '\0', BLKSIZE); /* zero the buffer */
|
||||
bb[3] = 4; /* next write byte offset */
|
||||
bb[4] = 0x60; /* set beg/end of block */
|
||||
bb[5] = 0; /* 1st block count is 0 bytes */
|
||||
}
|
||||
boff = (bb[2] << 8) | (bb[3]); /* get next write address offset */
|
||||
if (last)
|
||||
goto alldone; /* close out the file */
|
||||
|
||||
/* see if enough room in buffer for this record */
|
||||
/* add current offset + 2 (for last record info) plus new */
|
||||
/* record size plus 4 (2 for this rec, 2 for last) */
|
||||
if ((boff + 2 + cnt + 4) >= BLKSIZE) {
|
||||
/* not enough space, write out this record */
|
||||
// if (write(fd, bb, BLKSIZE) < 0)
|
||||
if (fwrite(bb, (size_t)1, BLKSIZE, fd) <= 0)
|
||||
return(-1);
|
||||
memset (bb, '\0', BLKSIZE); /* zero the buffer */
|
||||
bb[4] = 0x60; /* set beg/end of block */
|
||||
bb[5] = 0; /* 1st block count is 0 bytes */
|
||||
/* after 1st write */
|
||||
boff = 4; /* init count at 4 bytes */
|
||||
}
|
||||
/* we have enough room, move in the record */
|
||||
/* clear last record end of block flag, set up this record */
|
||||
/* info and last rec info at end of data, and update cnt */
|
||||
bb[boff] &= ~0x20; /* clear end of block flag */
|
||||
bb[boff+2] = 0x00; /* clear this blocks flags */
|
||||
bb[boff+3] = cnt; /* set this record count */
|
||||
memcpy(&bb[boff+4], buf, cnt); /* copy in the data */
|
||||
boff += (cnt+4); /* update count */
|
||||
bb[boff] = 0x20; /* set eob status flag */
|
||||
bb[boff+1] = cnt; /* set last rec byte count */
|
||||
bb[2] = (boff & 0xff00) >> 8; /* set hi byte of count */
|
||||
bb[3] = (boff & 0xff); /* set lo byte of count */
|
||||
return(cnt); /* done */
|
||||
|
||||
alldone:
|
||||
/* that was the last record, set eof flag in bb, write it and exit */
|
||||
/* see if enough room in buffer for EOM record */
|
||||
/* add current offset + 2 (for last record info) plus new */
|
||||
/* EOF record size of 4 (2 for this rec, 2 for last) */
|
||||
if ((boff + 2 + 4) >= BLKSIZE) {
|
||||
/* not enough space, write out this record */
|
||||
// if (write(fd, bb, BLKSIZE) < 0)
|
||||
if (fwrite(bb, (size_t)1, BLKSIZE, fd) <= 0)
|
||||
return(-1);
|
||||
memset (bb, '\0', BLKSIZE); /* zero the buffer */
|
||||
bb[4] = 0x60; /* set beg/end of block */
|
||||
bb[5] = 0; /* 1st block count is 0 bytes */
|
||||
/* after 1st write */
|
||||
boff = 4; /* init count at 4 bytes */
|
||||
}
|
||||
bb[boff] &= ~0x20; /* clear end of block flag */
|
||||
/* bb[boff+2] = 0xa0; /* clear this blocks flags */
|
||||
bb[boff+2] = 0x80; /* clear this blocks flags */
|
||||
bb[boff+3] = 0; /* set record count of 0 */
|
||||
bb[boff+4] = 0xa0; /* set EOF/EOB flags */
|
||||
boff += 4; /* 4 more bytes */
|
||||
bb[2] = (boff & 0xff00) >> 8; /* set hi byte of count */
|
||||
bb[3] = (boff & 0xff); /* set lo byte of count */
|
||||
/* write out EOF record */
|
||||
// if (write(fd, bb, BLKSIZE) < 0)
|
||||
if (fwrite(bb, (size_t)1, BLKSIZE, fd) <= 0)
|
||||
return(-1);
|
||||
first = 0; /* reset 1st time flag */
|
||||
return(cnt); /* get out, done */
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* renum.c
|
||||
*
|
||||
* This program truncates a line or expands a line with blanks to
|
||||
* have a line length of 72 chars. A 7 digit line number is then
|
||||
* append to the line. Numbers are in the form XXXX.000.
|
||||
* input - stdin
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* get a line of input. */
|
||||
int ln = 1;
|
||||
int getloi(s, lim) /* right from the book. */
|
||||
char s[];
|
||||
int lim;
|
||||
{
|
||||
int c, i, j;
|
||||
char line[12];
|
||||
|
||||
for (i=0; --lim > 0;)
|
||||
{
|
||||
if ((c = getchar()) == EOF)
|
||||
return 0;
|
||||
if (c == '\r')
|
||||
continue;
|
||||
if (c == '\n')
|
||||
break;
|
||||
s[i++] = c;
|
||||
}
|
||||
if (i > 72) /* truncate at char 72 */
|
||||
i = 72;
|
||||
for (; i<72; i++)
|
||||
s[i] = ' ';
|
||||
// sprintf(line, "%04d.000", ln++);
|
||||
sprintf(line, "%04d.%01d00", ln/10, ln%10);
|
||||
ln++;
|
||||
for (j=0; j<8; j++)
|
||||
s[72+j] = line[j];
|
||||
s[80] = '\n';
|
||||
s[81] = '\0';
|
||||
return (i);
|
||||
}
|
||||
|
||||
int main (argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char s[BUFSIZ];
|
||||
|
||||
while (1) {
|
||||
if (getloi(s, BUFSIZ) == 0)
|
||||
exit(0);
|
||||
/* output line of text from the source */
|
||||
printf("%s", s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,384 +0,0 @@
|
||||
/*
|
||||
* sdtfmgrcopy.c
|
||||
*
|
||||
* This program scans a metatape file and prints file count and sizes.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int lfilen, filen = 1;
|
||||
int smd = 0;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp, outp;
|
||||
FILE *infp, *outfp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
// printf("EOF found after file %d\n", filen);
|
||||
lfilen = filen;
|
||||
filen++; /* set next file number */
|
||||
smd = 1; /* look for smd again */
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1) {
|
||||
printf("EOM found after file %d\n", filen);
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll;
|
||||
char path[64], command[128];
|
||||
// int sdt = 1;
|
||||
int sdt = 0;
|
||||
|
||||
smd = 1;
|
||||
|
||||
if (argc != 2) {
|
||||
//fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
printf("usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
//fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
printf("%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
//fprintf(stderr, "Can't allocate memory for tscan\n");
|
||||
printf("Can't allocate memory for tscan\n");
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
printf("got ll = %d filen %d\n", ll, filen);
|
||||
if (ll == 1920) {
|
||||
sdt = 1; /* process SDT tape */
|
||||
smd = 0;
|
||||
printf("process sdt ll = %d\n", ll);
|
||||
}
|
||||
if (ll == 4608) {
|
||||
sdt = 0; /* process SMD tape */
|
||||
smd = 1;
|
||||
printf("process smd ll = %d\n", ll);
|
||||
}
|
||||
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
printf("\nfile %d:\n", filen);
|
||||
smd = 1;
|
||||
sdt = 0;
|
||||
continue; /* go look for another SDT bootfile or SMD entry */
|
||||
} else
|
||||
if (ll != 1920 && ll != 4608) {
|
||||
printf("File is not in MPX filemgr format and can not be processed!\n");
|
||||
break;
|
||||
} else {
|
||||
int cc = 0;
|
||||
// unsigned int curchar;
|
||||
char filename[16];
|
||||
int i, j, m;
|
||||
|
||||
/* SDT entries have 1920 bytes as first record. This is */
|
||||
/* followed by multiple 768 byte records to finish the SDT image */
|
||||
/* read the boot data from the sdt tape */
|
||||
/* check for SDT entry instead of SMD entry */
|
||||
// if (ll == 1920)
|
||||
// if (sdt == 1 && filen == 1)
|
||||
if (sdt == 1) {
|
||||
int no, ct = 0;;
|
||||
/* get more sdt data */
|
||||
/* open output file, create it if necessary */
|
||||
// if (outp == -1) {
|
||||
if (outfp == NULL) {
|
||||
sprintf(filename, "bootfile%d\0", filen);
|
||||
// if ((outp = open("bootfile", O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
|
||||
// if ((outp = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(filename, "w")) == NULL) {
|
||||
printf("Can't open bootfile\n");
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
}
|
||||
printf("got2 ll = %d writing to bootfile -> %s\n", ll, filename);
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
// fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
printf("write (%d) != read (%d) on file bootfile\n", no, ll);
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
ct++;
|
||||
// no = write(outp, buf, ll);
|
||||
no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
// fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
printf("write (%d) != read (%d) on file bootfile\n", no, ll);
|
||||
}
|
||||
sdt = 0;
|
||||
smd = 1;
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
printf("wrote %d records to bootfile %s\n", ct, filename);
|
||||
continue; /* go look for another SDT bootfile or SMD entry */
|
||||
} else
|
||||
|
||||
/* filemgr smd entries are 8 words, and are in 1152 words (4608 bytes)
|
||||
* (6 sector) blocks. Saved data files are modulo 1152 words also */
|
||||
/* 8 wds per SMD entry, 24 entries per sector, 144 entries per 6 sector
|
||||
* block. */
|
||||
// printf("gotx ll = %d filen %d\n", ll, filen);
|
||||
// if (filen == 1)
|
||||
if (smd == 1) {
|
||||
/* check for SMD entry instead of SDT entry */
|
||||
/* read smd entry */
|
||||
char file[20], dir[20];
|
||||
int l = 0;
|
||||
int smddone = 0;
|
||||
int totent = 0;
|
||||
char *buf2 = buf;
|
||||
// printf("\nfile %d: %d\n", filen, ll);
|
||||
/* see how many entries here */
|
||||
while(!smddone) {
|
||||
/* process entries in this record */
|
||||
for (j=0; j<144; j++) {
|
||||
int k = l++ * 32;
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
/* stop processing on first zero smd entry */
|
||||
if (w1 <= 0) {
|
||||
smddone = 1;
|
||||
break;
|
||||
}
|
||||
totent++;
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
sprintf(dir, "%s", "system");
|
||||
sprintf(path, "./%s/%s", dir, file);
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0)
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d path = %s\n", w1, path);
|
||||
else
|
||||
printf("active file: w1 = %d path = %s\n", w1, path);
|
||||
}
|
||||
if (smddone)
|
||||
break;
|
||||
buf2 += 4608; /* next buffer */
|
||||
ll=getloi(buf2, 4608);
|
||||
}
|
||||
printf("%d smd entries found\n", totent);
|
||||
/* we have directory entries */
|
||||
for (j=0; j<totent; j++) {
|
||||
int k = j * 32;
|
||||
/* get file size in blocks */
|
||||
int w1 = (buf[k+13] & 0xff) << 16 | (buf[k+14] & 0xff) << 8 | (buf[k+15] & 0xff);
|
||||
int blks = w1; /* save block count */
|
||||
|
||||
/* get file/dir name */
|
||||
for (i=0; i<8; i++) {
|
||||
file[i] = tolower(buf[k+0+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[8] = '\0';
|
||||
for (i=0; i<8; i++) {
|
||||
dir[i] = tolower(buf[k+0+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[8] = '\0';
|
||||
if (dir[0] == '\0')
|
||||
sprintf(dir, "%s", "system");
|
||||
sprintf(path, "./%s", dir);
|
||||
|
||||
// see if active file
|
||||
if ((buf[k+12] & 0x80) == 0) {
|
||||
// not active goon
|
||||
printf("inactive file: w1 = %d\n", w1);
|
||||
}
|
||||
printf("active file: w1 = %d\n", w1);
|
||||
if (w1 <= 0)
|
||||
break;
|
||||
/* create the directory/file */
|
||||
// printf("path = %s\n", path);
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
// printf("command = %s\n", command);
|
||||
system(command);
|
||||
sprintf(path, "./%s/%s", dir, file);
|
||||
printf("file %d = %s\n", j+1, path);
|
||||
sprintf(command, "touch %s", path);
|
||||
// printf("command = %s\n", command);
|
||||
system(command);
|
||||
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
#ifndef DO_LATER
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(path, "w")) == NULL) {
|
||||
//fprintf(stderr, "Can't open %s\n", path);
|
||||
printf("Can't open %s\n", path);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
#endif
|
||||
/* get the file data */
|
||||
for (m=0; m<((w1+5)/6); m++) {
|
||||
char data[5000]; /* data buffer */
|
||||
ll=getloi(data, 4608);
|
||||
|
||||
/* process file data for file */
|
||||
if (ll == 4608) {
|
||||
#ifndef DO_LATER
|
||||
/* blks/w1 have number of blocks to write */
|
||||
int bcnt, no; /* block count */
|
||||
if (blks >= 6) {
|
||||
blks -= 6; /* enough for 6 block, write them */
|
||||
bcnt = 6*768; /* write all 6 blocks */
|
||||
} else {
|
||||
bcnt = blks*768;/* just write what we need */
|
||||
blks = 0;
|
||||
}
|
||||
/* only write number of sectors on save tape, not all 4608 */
|
||||
/* if zero, just reading excess blocks */
|
||||
if (bcnt != 0) {
|
||||
// no = write(outp, data, bcnt);
|
||||
no = fwrite(data, (size_t)1, (size_t)bcnt, outfp);
|
||||
if (no != bcnt)
|
||||
//fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
printf("write (%d) != read (%d) on file %s\n", no, bcnt, path);
|
||||
}
|
||||
#else
|
||||
if (m == 0)
|
||||
printf("reading file %s\n", path);
|
||||
#endif
|
||||
} else {
|
||||
printf("Bad file size read! %d instead of 4608\n", ll);
|
||||
/// if (ll == -1) break;
|
||||
if (ll == -1)
|
||||
goto dostop;
|
||||
}
|
||||
} /* end writing file */
|
||||
} /* end of smd scan */
|
||||
} /* read smd entries 4608 byte records */
|
||||
} /* process read of smd or sdt */
|
||||
} /* end of getloi read */
|
||||
dostop:
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL)
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* small.c
|
||||
*
|
||||
* This program deletes trailing blanks from a source file
|
||||
* option - -a to remove all trailing spaces
|
||||
* -h help
|
||||
* input - file or stdin
|
||||
* output - file or stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int getloi();
|
||||
int putloi();
|
||||
int all = 0; /* do all, set non zero by -a */
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *ifp=NULL, *ofp=NULL, *fopen();
|
||||
int iu=0, ou=0;
|
||||
char *p, *name = *argv;
|
||||
char s[BUFSIZ];
|
||||
|
||||
all = 0;
|
||||
if (argc <= 1) {
|
||||
doerr:
|
||||
fprintf(stderr, "Usage: %s [-ah] [infile] [outfile]\n", name);
|
||||
exit(1);
|
||||
}
|
||||
/* check for any options */
|
||||
while(--argc > 0) {
|
||||
p = *++argv;
|
||||
if (*p == '-') {
|
||||
if (*++p == '\0') {
|
||||
fprintf(stderr, "Error: no option specified\n");
|
||||
goto doerr;
|
||||
}
|
||||
while (*p != '\0') {
|
||||
switch (*p++) {
|
||||
case 'a': /* user wants all spaces removed */
|
||||
case 'A':
|
||||
all = 1; /* remove all trailing blanks */
|
||||
break;
|
||||
case 'h': /* user wants help */
|
||||
case 'H':
|
||||
default:
|
||||
goto doerr;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
/* process in, then out file */
|
||||
if (ifp == NULL) {
|
||||
fprintf(stderr, "4 argc %x argv %s\n", argc, p);
|
||||
if ((ifp = fopen(*argv, "r")) == NULL) {
|
||||
fprintf(stderr,
|
||||
"Error: can't open input file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
/* process out file */
|
||||
if (ofp == NULL) {
|
||||
if ((ofp = fopen(*argv, "w")) == NULL) {
|
||||
fprintf(stderr,
|
||||
"Error: can't open output file %s\n", *argv);
|
||||
exit(1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"Error: too many parameters %s\n", *argv);
|
||||
goto doerr;
|
||||
}
|
||||
if (ifp == NULL) {
|
||||
ifp = stdin; /* use stdin */
|
||||
iu = 1;
|
||||
}
|
||||
if (ofp == NULL) {
|
||||
ofp = stdout; /* use stdout */
|
||||
ou = 1;
|
||||
}
|
||||
fflush(stderr);
|
||||
|
||||
/* copy in to out */
|
||||
while (1) {
|
||||
if (getloi(ifp, s, BUFSIZ) <= 0) { /* read til EOF */
|
||||
if (iu == 0)
|
||||
fclose(ifp);
|
||||
if (ou == 0)
|
||||
fclose(ofp);
|
||||
exit(0);
|
||||
}
|
||||
putloi(ofp, s);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(ifp, s, lim) /* right from the book. */
|
||||
FILE *ifp;
|
||||
char s[];
|
||||
int lim;
|
||||
{
|
||||
int c, i, cr=0;
|
||||
|
||||
#ifdef _WIN32
|
||||
cr = 1; /* if on windows, add c/r */
|
||||
#endif
|
||||
for (i=0; --lim > 0;) {
|
||||
if ((c = fgetc(ifp)) == EOF)
|
||||
return 0;
|
||||
if (c == '\r') {
|
||||
cr = 1;
|
||||
continue;
|
||||
}
|
||||
if (c == '\n')
|
||||
break;
|
||||
s[i++] = c;
|
||||
}
|
||||
if (i > 72) /* truncate at char 72 */
|
||||
i = 72;
|
||||
for (; i<72; )
|
||||
s[i++] = ' ';
|
||||
if (cr) /* only put in c/r if one wanted */
|
||||
s[i++] = '\r';
|
||||
s[i++] = '\n'; /* add a newline */
|
||||
s[i] = '\0';
|
||||
|
||||
if (all == 0) /* see if all spaces to be removed */
|
||||
return (i); /* no, just return */
|
||||
|
||||
/* the user wants to keep removing spaces */
|
||||
if ((i > 1) && ((s[i-1] == '\n') || s[i-1] == '\r')) {
|
||||
while (((s[i-2] == ' ') || (s[i-2] == '\r') ||
|
||||
(s[i-2] == '\n')) && (i > 1))
|
||||
--i;
|
||||
if (cr) { /* put in c/r if required */
|
||||
s[i-1] = '\r';
|
||||
i++;
|
||||
}
|
||||
s[i-1] = '\n'; /* add the newline */
|
||||
}
|
||||
s[i] = '\0';
|
||||
return (i);
|
||||
}
|
||||
|
||||
/*
|
||||
** output line of text from the source
|
||||
*/
|
||||
int putloi(ofp, s)
|
||||
FILE *ofp;
|
||||
char *s;
|
||||
{
|
||||
fprintf(ofp, "%s", s); /* printf the line */
|
||||
return(0);
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* tap2disk.c
|
||||
*
|
||||
* This program scans a metadata tape (.tap format) and copies
|
||||
* a file until EOF is found. Only one file is read from the
|
||||
* the tape. This utility is used to transfer tar files from
|
||||
* SEL32 UTX to Linux.
|
||||
*
|
||||
* command: tap2disk <input >output
|
||||
* input - .tap formatted file being read
|
||||
* output - disk file containing .tap file contents
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int oldsize, newsize;
|
||||
FILE *outfp;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
int ln;
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0) {
|
||||
hc = -1; /* at EOM on disk file */
|
||||
return hc; /* return EOM */
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) { /* check for garbage, assume EOF */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
return hc; /* return EOM */
|
||||
}
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: EOF after %d records: %d bytes\n\n", filen, count, size);
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
fprintf(stderr, "second EOF after %d files: %d bytes\n", filen-1, tsize+size);
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
|
||||
/* check for EOM */
|
||||
if (hc == -1) {
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
if (n <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d\n", filen, lcount, count - 1, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
void putrec(int cnt, char *buf)
|
||||
{
|
||||
// int n1, n2, nw;
|
||||
int nw;
|
||||
int hc = (cnt + 1) & ~1; /* make byte count even */
|
||||
int ac = cnt; /* get actual byte count */
|
||||
|
||||
//printf("writing %d chars\n", cnt);
|
||||
#if 0
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
#endif
|
||||
/* write the data mod 2 */
|
||||
nw = fwrite((char *)buf, (size_t)1, (size_t)hc, outfp);
|
||||
#if 0
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = fwrite((char *)(&hc), (size_t)1, (size_t)4, outfp);
|
||||
#endif
|
||||
#if 0
|
||||
if (n1 != 4 || nw != hc || n2 != 4)
|
||||
#else
|
||||
if (nw != hc)
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "write (%d) failure\n", nw);
|
||||
fprintf(stderr, "Operation aborted\n");
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
size_t buf_size = 256 * 1024;
|
||||
size_t ll, gotboth = 0;
|
||||
int zero = 0;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1],"r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// close(inp); /* close input */
|
||||
fclose(infp); /* close input */
|
||||
outfp = fopen(argv[1],"r"); /* reopen */
|
||||
fseek(outfp, 0, SEEK_END); /* seek to end */
|
||||
oldsize = ftell(outfp); /* get filesize in bytes */
|
||||
fclose(outfp); /* now close it */
|
||||
|
||||
/* open input file */
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1],"r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
outfp = fopen(argv[2],"w");
|
||||
if (outfp == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open output file %s\n", argv[0], argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
|
||||
/* get a 256k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
return (4);
|
||||
}
|
||||
|
||||
/* get buffers until eof */
|
||||
domore:
|
||||
while ((ll=getloi(buf, buf_size)) > 0) {
|
||||
//printf("got %d char\n", ll);
|
||||
/* we have data to write */
|
||||
putrec(ll, buf); /* write the buffer */
|
||||
gotboth = 0;
|
||||
}
|
||||
//printf("we have EOF %d\n", gotboth+1);
|
||||
/* we have an EOF or an EOM */
|
||||
if (ll == 0) {
|
||||
/* we have EOF, write a zero */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
gotboth++; /* one more EOF */
|
||||
if (gotboth == 2) {
|
||||
/* we have written both EOF's, now write EOM */
|
||||
ll = -1;
|
||||
} else {
|
||||
goto domore; /* get more data */
|
||||
}
|
||||
}
|
||||
|
||||
//printf("we have EOM, DONE\n");
|
||||
/* We have EOM, see if EOF's needed */
|
||||
switch (gotboth) {
|
||||
case 0: /* we have written no EOFs, so write two */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
case 1: /* we have written 1 EOF, so write one more */
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
/* drop through */
|
||||
default:
|
||||
case 2: /* we have written 2 EOFs, now do EOM */
|
||||
zero = -1;
|
||||
fwrite((char *)(&zero), (size_t)1, (size_t)4, outfp);
|
||||
}
|
||||
fprintf(stderr, "EOM after 2 EOFs %d files: %d bytes\n", filen-1, tsize);
|
||||
|
||||
newsize = ftell(outfp); /* get filesize in bytes */
|
||||
fprintf(stderr, "Size of file changed from %d to %d\n", oldsize, newsize);
|
||||
|
||||
/* we done */
|
||||
fclose(outfp);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,274 +0,0 @@
|
||||
/*
|
||||
* tapdump.c
|
||||
*
|
||||
* This program scans a metatape file and displays the file content as
|
||||
* a side by side hex dump of the contents.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
//#include <errno.h>
|
||||
#define NOTDUMP
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
#ifndef NOTDUMP
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d (%x)\n", filen, lcount, count-1, ln, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d (%x)\n", filen, lcount, ln, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: eof after %d records: %d bytes (%x)\n", filen, count, size, size);
|
||||
fprintf(stderr, "file %d EOFcnt %d offset %x\n", filen, EOFcnt, tsize);
|
||||
#endif
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
#ifndef NOTDUMP
|
||||
fprintf(stderr, "second eof after %d files: %d bytes (%x)\n", filen, size, size);
|
||||
fprintf(stderr, "second file %d EOFcnt %d offset %x\n", filen, EOFcnt, tsize);
|
||||
#endif
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1) {
|
||||
#ifndef NOTDUMP
|
||||
/* we have EOM */
|
||||
fprintf(stderr, "mpx eot\n");
|
||||
/* print out total tape size in bytes */
|
||||
fprintf(stderr, "total length: %ld bytes (%x)\n", tsize, tsize);
|
||||
#endif
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
#ifndef NOTDUMP
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d to %d: size %d (%x)\n", filen, lcount, count-1, ln, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d: size %d (%x)\n", filen, lcount, ln, ln);
|
||||
}
|
||||
#endif
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
// char in[BUFSIZ], out[BUFSIZ];
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll, gotboth = 0;
|
||||
int lfilen = filen;
|
||||
unsigned int fileaddr, file_byte_count=0, curchar, buffptr, bufflen;
|
||||
int skipfile = 0, skip, cc;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = filen;
|
||||
buffptr = 0;
|
||||
bufflen = 16;
|
||||
fileaddr = 0;
|
||||
skip = 0;
|
||||
cc = 0;
|
||||
file_byte_count = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
skipfile = 0;
|
||||
file_byte_count = 0;
|
||||
fileaddr = 0;
|
||||
printf("\nfile %d:\n", filen);
|
||||
buffptr = 0;
|
||||
} else {
|
||||
// int cc = 0;
|
||||
char buff[257];
|
||||
int ans;
|
||||
// buffptr = 0;
|
||||
|
||||
/* see if skipping to next file */
|
||||
if (skipfile == 1) {
|
||||
buffptr = 0;
|
||||
cc = 0;
|
||||
skip = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* process the returned buffer */
|
||||
while (cc < ll) {
|
||||
if (skip != 0) {
|
||||
printf(" %06x : ",fileaddr);
|
||||
while (buffptr < skip) {
|
||||
buff[buffptr++] = 0x20;
|
||||
printf(" ");
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
} /* end of while */
|
||||
skip = 0;
|
||||
}
|
||||
if (!buffptr)
|
||||
printf(" %06x : ",fileaddr);
|
||||
curchar = (unsigned int)buf[cc++] & 0xff;
|
||||
file_byte_count++;
|
||||
printf("%02x", curchar & 0xff);
|
||||
buff[buffptr++] = PRINTABLE(curchar);
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
if (buffptr >= bufflen) {
|
||||
buff[buffptr] = 0;
|
||||
printf(" |%s|\n",buff);
|
||||
buffptr = 0;
|
||||
fileaddr += bufflen;
|
||||
if (!(fileaddr % 256)) {
|
||||
// if (!(file_byte_count % 256)) {
|
||||
// if (!(file_byte_count % 768)) {
|
||||
printf("\n<cr> - continue, q = quit, s = skip > ");
|
||||
ans = getchar();
|
||||
if (ans == 'q') {
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
if (ans == 's') {
|
||||
skipfile = 1;
|
||||
cc = 0;
|
||||
skip = 0;
|
||||
}
|
||||
if (ans != '\n')
|
||||
while ((ans=getchar()) != '\n' )
|
||||
;
|
||||
} /* end of if */
|
||||
if (skipfile == 1)
|
||||
break;
|
||||
} /* end of if */
|
||||
} /* end of while */
|
||||
|
||||
if ((ll % 256) == 0) {
|
||||
cc = 0;
|
||||
continue;
|
||||
}
|
||||
if (buffptr && !skipfile) {
|
||||
buff[buffptr] = 0;
|
||||
// fileaddr += buffptr;
|
||||
skip = buffptr;
|
||||
while (buffptr++ < bufflen) {
|
||||
printf(" ");
|
||||
if (!(buffptr % 4))
|
||||
printf(" ");
|
||||
} /* end of while */
|
||||
printf(" |%s|\n",buff);
|
||||
|
||||
/* see what user wants to do */
|
||||
printf("\n<cr> - continue, q = quit > ");
|
||||
ans = getchar();
|
||||
if (ans == 'q') {
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(1);
|
||||
}
|
||||
if (ans != '\n')
|
||||
while ((ans=getchar()) != '\n' )
|
||||
;
|
||||
buffptr = 0;
|
||||
file_byte_count = 0;
|
||||
// else
|
||||
// skipfile = 0;
|
||||
} /* end of if */
|
||||
printf("ll %x buf_size %x skip %x skipfile %x fileaddr %x\n",
|
||||
ll, buf_size, skip, skipfile, fileaddr);
|
||||
}
|
||||
}
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* tape2disk.c
|
||||
*
|
||||
* MPX uses 2 EOF in a row to separate sections of MPX3.x master SDT tapes.
|
||||
* It uses 3 EOF in a row to indicate the EOT on MPX 3.X tapes. So we
|
||||
* cannot assume EOT is at the 1st or 2nd EOF in a row. We keep looking
|
||||
* for a third one. For user SDT tapes or MPX 1.X master SDT tapes use
|
||||
* option -f for 2 EOFs. Use option -v for 3 eof's on VOLM tapes. For
|
||||
* non MPX tapes, the 2nd EOF means EOT. Some tapes (Unix) have only one
|
||||
* EOF and will terminate on EOT detected. Leave off the output file name
|
||||
* to just scan the tape and output record sizes and counts.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
//#include <sys/mtio.h>
|
||||
#include <stdlib.h> /* for exit() */
|
||||
#ifdef _WIN32
|
||||
#include <fcntl.h> /* for O_RDONLY, O_WRONLY, O_CREAT */
|
||||
#include <io.h> /* for _read, _open, _write, _close */
|
||||
#define open _open
|
||||
#define read _read
|
||||
#define write _write
|
||||
#define close _close
|
||||
#else
|
||||
#include <sys/fcntl.h> /* for O_RDONLY, O_WRONLY, O_CREAT */
|
||||
#include <unistd.h> /* for open, read, write */
|
||||
#include <sys/signal.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 uint8;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef signed __int64 t_int64;
|
||||
typedef unsigned __int64 t_uint64;
|
||||
//typedef t_int64 off_t;
|
||||
#else
|
||||
/* All modern/standard compiler environments */
|
||||
/* any other environment needa a special case above */
|
||||
#include <stdint.h>
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif /* end standard integers */
|
||||
//#define FMGRTAPE /* defined for filemgr tapes, undefined for volmgr tape */
|
||||
|
||||
int usefmgr = 1; /* use fmgr format with 2 EOF's, else 3 EOF's */
|
||||
char *buff; /* buffer for read/write */
|
||||
int filen = 1; /* file number being processed */
|
||||
long count=0, lcount=0; /* number of blocks for file */
|
||||
#ifndef _WIN32
|
||||
extern void RUBOUT(); /* handle user DELETE key signal */
|
||||
#endif
|
||||
off_t size=0, tsize=0; /* number of bytes in file, total */
|
||||
int ln;
|
||||
char *inf, *outf;
|
||||
int copy;
|
||||
int32 size_256K = 256 * 1024;
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int n, nw, inp, outp;
|
||||
// struct mtop op;
|
||||
int32 buf_size = size_256K;
|
||||
int EOFcnt = 0; /* count the number of EOFs in a row. */
|
||||
char *name = *argv;
|
||||
char *p = *++argv;
|
||||
|
||||
if (argc <= 1 || argc > 4) {
|
||||
fprintf(stderr, "Usage: tape2disk -vf src [dest]\n");
|
||||
exit(1);
|
||||
}
|
||||
if (*p == '-') {
|
||||
char ch = *++p;
|
||||
argc--; /* one less arg */
|
||||
if (ch == 'v')
|
||||
usefmgr = 0; /* use volmgr format */
|
||||
else
|
||||
if (ch == 'f')
|
||||
usefmgr = 1; /* use fmgr format */
|
||||
else {
|
||||
fprintf(stderr, "Invalid option %c\n", ch);
|
||||
fprintf(stderr, "Usage: tape2disk -vf src [dest]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
inf = argv[1];
|
||||
if (argc == 3) {
|
||||
outf = argv[2];
|
||||
copy = 1;
|
||||
}
|
||||
if ((inp = open(inf, O_RDONLY, 0666)) < 0) {
|
||||
fprintf(stderr, "Can't open %s\n", inf);
|
||||
exit(1);
|
||||
}
|
||||
if (copy) {
|
||||
/* open output file, create it if necessary */
|
||||
if ((outp = open(outf, O_WRONLY|O_CREAT, 0666)) < 0) {
|
||||
fprintf(stderr, "Can't open %s\n", outf);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
/* get a 256k buffer */
|
||||
if ((buff = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for tapecopy\n");
|
||||
exit(4);
|
||||
}
|
||||
#ifndef _WIN32
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
(void)signal(SIGINT, RUBOUT);
|
||||
#endif
|
||||
|
||||
ln = -2;
|
||||
for (;;) {
|
||||
count++;
|
||||
/* read record */
|
||||
while ((n = read(inp, buff, buf_size)) < 0) {
|
||||
perror("Unknown read error");
|
||||
// errno = 0;
|
||||
exit(6); /* abort on error, comment out to ignore tape errors */
|
||||
}
|
||||
if (n > 0) {
|
||||
/* we read some data, see if scanning or writing */
|
||||
EOFcnt = 0; /* not at EOF anymore */
|
||||
if (copy) {
|
||||
int32 n1, n2;
|
||||
/* we have data to write */
|
||||
int32 hc = (n + 1) & ~1; /* make byte count even */
|
||||
int32 wc = n; /* get actual byte count */
|
||||
/* write actual byte count to 32 bit word as header */
|
||||
n1 = write(outp, (char *)(&wc), (int32)4);
|
||||
/* write the data mod 2 */
|
||||
nw = write(outp, buff, (int32)hc);
|
||||
/* write the byte count in 32 bit word as footer */
|
||||
n2 = write(outp, (char *)(&wc), (int32)4);
|
||||
if (n1 != 4 || nw != hc || n2 != 4) {
|
||||
fprintf(stderr, "write (%d) !=" " read (%d)\n", nw, n);
|
||||
fprintf(stderr, "COPY " "Aborted\n");
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
size += n; /* update bytes read */
|
||||
if (n != ln) { /* must be last record of file if different */
|
||||
if (ln > 0) {
|
||||
/* we read something */
|
||||
if ((count - lcount) > 1)
|
||||
printf("file %d: records %ld to %ld: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
printf("file %d: record %ld: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
ln = n; /* save last record size */
|
||||
lcount = count; /* also record count */
|
||||
}
|
||||
} else {
|
||||
/* we did not read data, it must be an EOF */
|
||||
/* if ln is -1, last operation was EOF, now we have a second */
|
||||
/* see if fmgr or volm */
|
||||
if (usefmgr) {
|
||||
/* filemgr has 2 EOF's at end of tape */
|
||||
if (++EOFcnt > 1) {
|
||||
/* two EOFs mean we are at EOT */
|
||||
printf("fmgr eot\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* volmgr has 3 EOF's at end of tape */
|
||||
if (++EOFcnt > 2) {
|
||||
/* three EOFs mean we are at EOT on MPX */
|
||||
printf("volm eot\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ln > 0) {
|
||||
if ((count - lcount) > 1)
|
||||
printf("file %d: records %ld to %ld: size %d\n",
|
||||
filen, lcount, count - 1, ln);
|
||||
else
|
||||
printf("file %d: record %ld: size %d\n", filen, lcount, ln);
|
||||
}
|
||||
if (usefmgr) {
|
||||
printf("file %d: eof after %ld records: %ld bytes\n",
|
||||
filen, count - 1, size);
|
||||
} else {
|
||||
if (EOFcnt == 2) /* if 2nd EOF, print file info */
|
||||
printf("second eof after %d files: %ld bytes\n", filen, size);
|
||||
}
|
||||
|
||||
if (copy) {
|
||||
/* write a sudo EOF to disk file as a zero 4 byte record */
|
||||
int n1, hc = 0;
|
||||
/* write the EOF */
|
||||
/* write a zero as the byte count in 32 bit word as EOF */
|
||||
n1 = write(outp, (char *)(&hc), (int32)4);
|
||||
if (n1 != 4) {
|
||||
perror("Write EOF");
|
||||
exit(6);
|
||||
}
|
||||
}
|
||||
if (usefmgr)
|
||||
filen++; /* advance number of files */
|
||||
else
|
||||
if (EOFcnt < 2) /* not really a file if 2nd EOF */
|
||||
filen++; /* advance number of files */
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = n; /* set ln to -1 showing we are at EOF */
|
||||
}
|
||||
}
|
||||
if (copy) {
|
||||
/* write a sudo EOM to disk file as a -1 4 byte record */
|
||||
int32 n1, hc = 0xffffffff;
|
||||
/* write the EOM to disk */
|
||||
/* write a -1 as the byte count in 32 bit word as EOM */
|
||||
n1 = write(outp, (char *)(&hc), (size_t)sizeof(hc));
|
||||
if (n1 != 4) {
|
||||
perror("Write EOM");
|
||||
return(6);
|
||||
}
|
||||
(void)close(outp);
|
||||
}
|
||||
/* print out total tape size in bytes */
|
||||
(void)printf("total length: %ld bytes\n", tsize);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* entered when user hit the DELETE key */
|
||||
void RUBOUT()
|
||||
{
|
||||
if (count > lcount)
|
||||
--count;
|
||||
if (count)
|
||||
if (count > lcount)
|
||||
(void)printf("file %d: records %ld to %ld: size" " %d\n", filen, lcount, count, ln);
|
||||
else
|
||||
(void)printf("file %d: record %ld: size %d\n", filen, lcount, ln);
|
||||
(void)printf("interrupted at file %d: record %ld\n", filen, count);
|
||||
(void)printf("total length: %ld bytes\n", tsize + size);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* tapscan.c
|
||||
*
|
||||
* This program scans a metatape file and prints file count and sizes.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
//#include <errno.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp;
|
||||
FILE *infp;
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d (0x%x) to %d (0x%x): size %d (0x%x)\n",
|
||||
filen, lcount, lcount, count-1, count-1, ln, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d (0x%x): size %d (0x%x)\n",
|
||||
filen, lcount, lcount, ln, ln);
|
||||
}
|
||||
fprintf(stderr, "file %d: eof after %d (0x%x) records: %d (0x%x) bytes\n",
|
||||
filen, count, count, size, size);
|
||||
filen++; /* set next file number */
|
||||
} else {
|
||||
fprintf(stderr, "second eof after %d (0x%x) files: %d (0x%x) bytes\n",
|
||||
filen-1, filen-1, size, size);
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1) {
|
||||
/* we have EOM */
|
||||
fprintf(stderr, "mpx eot\n");
|
||||
/* print out total tape size in bytes */
|
||||
fprintf(stderr, "total length: %ld (0x%lx) bytes\n", tsize, tsize);
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
if (ln > 0) {
|
||||
if (count - lcount > 1)
|
||||
fprintf(stderr, "file %d: records %d (0x%x) to %d (0x%x): size %d (0x%x)\n",
|
||||
filen, lcount, lcount, count-1, count-1, ln, ln);
|
||||
else
|
||||
fprintf(stderr, "file %d: record %d (0x%x): size %d (0x%x)\n",
|
||||
filen, lcount, lcount, ln, ln);
|
||||
}
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
// char in[BUFSIZ], out[BUFSIZ];
|
||||
char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll, gotboth = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
/* open input file */
|
||||
infp = fopen(argv[1],"r");
|
||||
if (infp == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for %s\n", argv[0]);
|
||||
return (4);
|
||||
}
|
||||
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
|
||||
/* get lines until eof */
|
||||
while (((ll=getloi(buf, buf_size)) != EOF)) {
|
||||
;
|
||||
}
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
/*
|
||||
* volmcopy.c
|
||||
*
|
||||
* This program scans a metatape file and prints file count and sizes.
|
||||
* It is only for volmgr save images. Save images have the following format:
|
||||
* One or more 6144 byte records containing a list of files saved 16 char file
|
||||
* name followed my 16 char directory name followed by 16 char volume name.
|
||||
* A 1536 byte file definition entry will be followed by 1 to 8 768 byte
|
||||
* file data records followed by an EOF for each file. If the file size is
|
||||
* greater than 6144 bytes, 1 or more 6144 byte records are output followed
|
||||
* by last record modulo 768 bytes. Two EOFs in a row define the EOT.
|
||||
* input - stdin or specified filename
|
||||
* output - stdout
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <sys/file.h>
|
||||
//#include <unistd.h>
|
||||
//#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
int filen = 1;
|
||||
int EOFcnt = 0;
|
||||
int count=0, lcount=0;
|
||||
int size=0, tsize=0;
|
||||
int size_512K = 512 * 1024;
|
||||
int ln;
|
||||
//int inp, outp;
|
||||
FILE *infp, *outfp;
|
||||
#define PRINTABLE(x) ((x < 32) || (x > 126)) ? '.' : x
|
||||
|
||||
/* get a line of input. */
|
||||
int getloi(char *s, int lim)
|
||||
{
|
||||
// int c, i;
|
||||
int n1, n2, hc, tc, n;
|
||||
|
||||
// errno = 0;
|
||||
/* read the byte count in 32 bit word as header */
|
||||
// n1 = read(inp, (char *)(&hc), (size_t)4);
|
||||
n1 = fread((char *)(&hc), (size_t)1, (size_t)4, infp);
|
||||
if (n1 <= 0)
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc & 0xffff0000) /* check for garbage, assume EOM */
|
||||
hc = -1; /* at EOM on disk file */
|
||||
|
||||
/* check for EOF & EOM on tape data */
|
||||
if (hc == 0) {
|
||||
/* we are at tape EOF */
|
||||
if (++EOFcnt < 2) { /* if 1st EOF, print file info */
|
||||
filen++; /* set next file number */
|
||||
}
|
||||
count = 0; /* file record count back to zero */
|
||||
lcount = 0; /* last record count back to zero */
|
||||
tsize += size; /* add to total tape size */
|
||||
size = 0; /* file size back to zero */
|
||||
ln = -1; /* set ln to -1 showing we are at EOF */
|
||||
|
||||
/* we have EOF */
|
||||
return 0; /* return EOF on tape data */
|
||||
}
|
||||
if (hc == -1)
|
||||
return -1; /* at EOM on disk file */
|
||||
|
||||
/* read the data */
|
||||
// n = read(inp, s, (size_t)hc);
|
||||
n = fread(s, (size_t)1, (size_t)hc, infp);
|
||||
|
||||
/* if odd byte record, read extra byte and throw it away */
|
||||
if (n & 0x1) {
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)1);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)1, infp);
|
||||
if (n2 <= 0)
|
||||
return -1; /* at EOM on disk file */
|
||||
}
|
||||
|
||||
/* read the byte count in 32 bit word as trailer */
|
||||
// n2 = read(inp, (char *)(&tc), (size_t)4);
|
||||
n2 = fread((char *)(&tc), (size_t)1, (size_t)4, infp);
|
||||
count++; /* bump record count */
|
||||
size += n; /* update bytes read */
|
||||
EOFcnt = 0; /* not an EOF */
|
||||
if (n != ln) {
|
||||
ln = n;
|
||||
lcount = count;
|
||||
}
|
||||
/* return bytes in buffer */
|
||||
return n;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
unsigned char *buf;
|
||||
size_t size_512K = 512 * 1024;
|
||||
size_t buf_size = 512 * 1024;
|
||||
// char *cp, *np;
|
||||
int ll;
|
||||
int lfilen = filen;
|
||||
unsigned int mpxtime[2];
|
||||
char path[64], command[128], dtime[64];
|
||||
time_t utime=0;
|
||||
struct tm *dt;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s infile\n", argv[0]);
|
||||
exit(1);
|
||||
} /* end of if */
|
||||
|
||||
// if ((inp = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
if ((infp = fopen(argv[1], "r")) == NULL) {
|
||||
fprintf(stderr,"%s: fopen: unable to open input file %s\n", argv[0], argv[1]);
|
||||
return (1);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
|
||||
/* get a 512k buffer */
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory for tscan\n");
|
||||
return (4);
|
||||
}
|
||||
/* init counts */
|
||||
ln = -2; /* look for 2 eof */
|
||||
count = 0;
|
||||
size = 0;
|
||||
tsize = 0;
|
||||
lcount = 0;
|
||||
filen = 1;
|
||||
lfilen = filen;
|
||||
printf("\nfile %d:\n", filen);
|
||||
path[0] = '\0';
|
||||
command[0] = '\0';
|
||||
|
||||
/* get lines until eof */
|
||||
while ((ll=getloi(buf, buf_size)) != EOF) {
|
||||
if (ll == 0) {
|
||||
/* eof found, process new file */
|
||||
// printf("\nfile %d:\n", filen);
|
||||
printf("file %d:\n", filen);
|
||||
} else {
|
||||
int cc = 0;
|
||||
// unsigned int curchar;
|
||||
|
||||
/* dump first 2 words */
|
||||
int w1, w2, i, j;
|
||||
w1 = (buf[0] & 0xff) << 24 | buf[1] << 16 | buf[2] << 8 | (buf[3] & 0xff);
|
||||
w2 = (buf[4] & 0xff) << 24 | buf[5] << 16 | buf[6] << 8 | (buf[7] & 0xff);
|
||||
// printf("w1 = %x, w2 = %x count = %d\n", w1, w2, count);
|
||||
if (count == 1 && w1 == 1) {
|
||||
char file[20], dir[20], vol[20];
|
||||
int off = 8;
|
||||
int l = 0;
|
||||
printf("Directory with %d entries\n", w2);
|
||||
/* we have directory entries */
|
||||
for (j=0; j<w2; j++) {
|
||||
int k = l++ * 48;
|
||||
if (k > (6144-48-off)) {
|
||||
ll=getloi(buf, buf_size);
|
||||
off = 0;
|
||||
l = 0;
|
||||
k = 0;
|
||||
// printf("reread: got ll= %d\n", ll);
|
||||
}
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[k+off+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[k+off+16+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[k+off+32+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
sprintf(path, "./%s/%s", vol, dir);
|
||||
#if 0
|
||||
/* create the directory/file */
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
#if 0
|
||||
sprintf(command, "touch %s", path);
|
||||
system(command);
|
||||
#endif
|
||||
// printf("path0 = %s\n", path);
|
||||
}
|
||||
} else
|
||||
if (count == 1 && w1 == 2 && w2 == 0) {
|
||||
char file[20], dir[20], vol[20];
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL) {
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
sprintf(command, "touch -a -m -t %s %s", dtime, path);
|
||||
// sprintf(command, "touch -t %s %s", dtime, path);
|
||||
// printf("1cmd [%s] path[%s]\n", command, path);
|
||||
// fflush(stdout);
|
||||
system(command);
|
||||
}
|
||||
// outp = -1;
|
||||
outfp = NULL;
|
||||
/* process file definition */
|
||||
/* we have a 1536 byte file definition entry */
|
||||
for (i=0; i<16; i++) {
|
||||
file[i] = tolower(buf[8+i]);
|
||||
if (file[i] == ' ')
|
||||
file[i] = '\0';
|
||||
}
|
||||
file[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
dir[i] = tolower(buf[24+i]);
|
||||
if (dir[i] == ' ')
|
||||
dir[i] = '\0';
|
||||
}
|
||||
dir[16] = '\0';
|
||||
for (i=0; i<16; i++) {
|
||||
vol[i] = tolower(buf[40+i]);
|
||||
if (vol[i] == ' ')
|
||||
vol[i] = '\0';
|
||||
}
|
||||
vol[16] = '\0';
|
||||
|
||||
i = 0x300 + 0x38; /* last modified date */
|
||||
// i = 0x300 + 0x20; /* creation date */
|
||||
/* get last modification time for file */
|
||||
/* day number since 1/1/1960 */
|
||||
// printf("D %02x%02x%02x%02x M %02x%02x%02x%02x\n",
|
||||
// buf[i+0],buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]);
|
||||
mpxtime[0] = buf[i+0] << 24 | buf[i+1] << 16 | buf[i+2] << 8 | (buf[i+3] & 0xff);
|
||||
/* .1ms count in day 0-864,000,000 */
|
||||
mpxtime[1] = (buf[i+4] << 24) | (buf[i+5] << 16) | (buf[i+6] << 8) | (buf[i+7] & 0xff);
|
||||
/* get UNIX time, secs sense 1970, not 1960 */
|
||||
utime =(time_t)((mpxtime[0]-3653)*86400)+(time_t)(mpxtime[1]/10000);
|
||||
dt = gmtime(&utime);
|
||||
j = dt->tm_year+1900;
|
||||
if (j > 2037)
|
||||
j -= 100;
|
||||
sprintf(dtime, "%04d%02d%02d%02d%02d", j, dt->tm_mon+1,
|
||||
dt->tm_mday, dt->tm_hour, dt->tm_min);
|
||||
// printf("mpx day %x ms %x utime %ld dtime %s\n", mpxtime[0], mpxtime[1], utime, dtime);
|
||||
// fflush(stdout);
|
||||
|
||||
sprintf(path, "./%s/%s", vol, dir);
|
||||
/* create the directory/file */
|
||||
// printf("dir path = %s\n", path);
|
||||
sprintf(command, "mkdir -p %s", path);
|
||||
system(command);
|
||||
sprintf(path, "./%s/%s/%s", vol, dir, file);
|
||||
printf("size bytes %d[0x%x] path = %s\n", ll, ll, path);
|
||||
// fflush(stdout);
|
||||
|
||||
/* open output file, create it if necessary */
|
||||
// if ((outp = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
|
||||
if ((outfp = fopen(path, "w")) == NULL) {
|
||||
(void)fprintf(stderr, "Can't open %s\n", path);
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
return (3);
|
||||
}
|
||||
// printf("opened path = %s ll = %d\n", path, ll);
|
||||
// fflush(stdout);
|
||||
/* process file data for file */
|
||||
if (ll > 1536) {
|
||||
// int no = write(outp, buf+1536, ll-1536);
|
||||
int no = fwrite(buf+1536, (size_t)1, (size_t)(ll-1536), outfp);
|
||||
if (no != ll)
|
||||
fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
}
|
||||
} else
|
||||
if (count > 1) {
|
||||
/* process file data for file */
|
||||
// int no = write(outp, buf, ll);
|
||||
int no = fwrite(buf, (size_t)1, (size_t)ll, outfp);
|
||||
if (no != ll)
|
||||
fprintf(stderr, "write (%d) != read (%d) on file %s\n", no, ll, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
// close(inp);
|
||||
fclose(infp);
|
||||
free(buf);
|
||||
// if (outp >= 0)
|
||||
if (outfp != NULL) {
|
||||
// close(outp);
|
||||
fclose(outfp);
|
||||
sprintf(command, "touch -a -m -t %s %s", dtime, path);
|
||||
// sprintf(command, "touch -t %s %s", dtime, path);
|
||||
// printf("2cmd [%s]\n", command);
|
||||
// fflush(stdout);
|
||||
system(command);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
6
SEL32/tests/.gitignore
vendored
Normal file
6
SEL32/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#ignore testcode and testcpu files.
|
||||
testcode0.l
|
||||
testcode0.mem
|
||||
testcode.mem
|
||||
testcpu.l
|
||||
testcpu.s
|
||||
@@ -1,25 +1,114 @@
|
||||
# Example ICL file for 32/7x
|
||||
# this line ignored
|
||||
*DEV04=0E150400,02 Cartridge disc with two platters
|
||||
*DEV08=0E160800,04 Moving head disc
|
||||
*DEV10=0E181000,04 9-Track magnetic tape
|
||||
*DEV20=0E1A2000,10 GPMC with 16 terminals
|
||||
*DEV60=0E1E6000,08 ADS
|
||||
*DEV78=01207800 Primary card reader
|
||||
*DEV7A=00217802 Primary line printer
|
||||
*DEV7E=02237801 Primary Teletype
|
||||
*INT00=1F Power fail/Auto restart
|
||||
*INT01=1E System Overide
|
||||
*INT12=1D Memory parity
|
||||
*INT13=1C Console Interrupt
|
||||
*INT24=1B Nonpresent memory
|
||||
*INT25=1A Undefined instruction trap
|
||||
*INT26=19 Privlege violation
|
||||
*INT27=18 Call Monitor
|
||||
*INT28=16 Real-time clock
|
||||
*INT29=17 Arithmetic exception
|
||||
*INT2A=15 External interrupt
|
||||
*INT2B=14 External interrupt
|
||||
*INT2C=13 External interrupt
|
||||
*INT2D=12 External interrupt
|
||||
*END
|
||||
*COM CONCEPT/VIRTUAL ICL FILE #111039-003C 27JUN88 HEADER CVICL800
|
||||
*DEV04=0F040400
|
||||
*DEV08=0F050800
|
||||
*DEV0C=0F060C00
|
||||
*DEV10=0F071000
|
||||
*DEV14=0F081400,4
|
||||
*DEV18=0F091800
|
||||
*DEV20=0E0A2000,10
|
||||
*DEV30=0E0B3000,10
|
||||
*DEV40=0E0C4000,10
|
||||
*DEV50=0E0D5000,4
|
||||
*DEV56=0F0E5600
|
||||
*DEV57=036B5704
|
||||
*DEV5E=0F0F5E00
|
||||
*DEV5F=035B5F04
|
||||
*DEV66=0F106600
|
||||
*DEV67=034B6704
|
||||
*DEV6E=0F116E00
|
||||
*DEV6F=033B6F04
|
||||
*DEV76=0F127600
|
||||
*DEV77=032B7704
|
||||
*DEV7E=0F137E00
|
||||
*DEV7F=031B7F04
|
||||
*INT00=7F0F
|
||||
*INT01=7F0E
|
||||
*INT02=7F0D
|
||||
*INT03=7F0C
|
||||
*INT14=7F0B
|
||||
*INT15=7F0A
|
||||
*INT16=7F09
|
||||
*INT17=7F08
|
||||
*INT18=7F06
|
||||
*INT19=7F07
|
||||
*INT1A=7F05
|
||||
*INT1C=7F03
|
||||
*INT1D=7F02
|
||||
*INT1E=7F01
|
||||
*INT1F=7F00
|
||||
*INT20=770F
|
||||
*INT21=770E
|
||||
*INT22=770D
|
||||
*INT23=770C
|
||||
*INT24=770B
|
||||
*INT25=770A
|
||||
*INT26=7709
|
||||
*INT27=7708
|
||||
*INT28=7707
|
||||
*INT29=7706
|
||||
*INT2A=7705
|
||||
*INT2C=7703
|
||||
*INT2D=7702
|
||||
*INT2E=7701
|
||||
*INT2F=7700
|
||||
*INT30=6F0F
|
||||
*INT31=6F0E
|
||||
*INT32=6F0D
|
||||
*INT33=6F0C
|
||||
*INT34=6F0B
|
||||
*INT35=6F0A
|
||||
*INT36=6F09
|
||||
*INT37=6F08
|
||||
*INT38=6F07
|
||||
*INT39=6F06
|
||||
*INT3A=6F05
|
||||
*INT3C=6F03
|
||||
*INT3D=6F02
|
||||
*INT3E=6F01
|
||||
*INT3F=6F00
|
||||
*INT40=670F
|
||||
*INT41=670E
|
||||
*INT42=670D
|
||||
*INT43=670C
|
||||
*INT44=670B
|
||||
*INT45=670A
|
||||
*INT46=6709
|
||||
*INT47=6708
|
||||
*INT48=6707
|
||||
*INT49=6706
|
||||
*INT4A=6705
|
||||
*INT4C=6703
|
||||
*INT4D=6702
|
||||
*INT4E=6701
|
||||
*INT4F=6700
|
||||
*INT50=5F0F
|
||||
*INT51=5F0E
|
||||
*INT52=5F0D
|
||||
*INT53=5F0C
|
||||
*INT54=5F0B
|
||||
*INT55=5F0A
|
||||
*INT56=5F09
|
||||
*INT57=5F08
|
||||
*INT58=5F07
|
||||
*INT59=5F06
|
||||
*INT5A=5F05
|
||||
*INT5C=5F03
|
||||
*INT5D=5F02
|
||||
*INT5E=5F01
|
||||
*INT5F=5F00
|
||||
*INT60=570F
|
||||
*INT61=570E
|
||||
*INT62=570D
|
||||
*INT63=570C
|
||||
*INT64=570B
|
||||
*INT65=570A
|
||||
*INT66=5709
|
||||
*INT67=5708
|
||||
*INT68=5707
|
||||
*INT69=5706
|
||||
*INT6A=5705
|
||||
*INT6C=5703
|
||||
*INT6D=5702
|
||||
*INT6E=5701
|
||||
*INT6F=5700
|
||||
*END
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,25 +0,0 @@
|
||||
00001 00000 ABS
|
||||
00002 P00000 DSECT
|
||||
00003 P00000 ORG 0
|
||||
00004 P00000 START EQU $
|
||||
00005 P00000 0002 NOP
|
||||
00006 P00002 0002 NOP
|
||||
00007 P00004 0103 LCS 2
|
||||
00008 P00006 0289 RDSTS 5
|
||||
00009 P00008 0006 BEI
|
||||
00010 P0000A 0007 UEI
|
||||
00011 P0000C F9800020 P00020 LPSD L20
|
||||
00012 P00010 AC800004 00004 LW 1,4
|
||||
00013 P00014 AD000009 00008 LH 2,8
|
||||
00014 P00018 AF000022 P00020 LD 6,L20
|
||||
00015 P0001C EC000029 P00028 BU GON
|
||||
00016 P00020 BOUND 1D
|
||||
00017 P00020 80000010 L20 DATAW X'80000010'
|
||||
00018 P00024 00004000 DATAW X'00004000'
|
||||
00019 P00028 CA0000FF GON LI 4,X'FF'
|
||||
00020 P0002C D6000100 00100 STW 4,X'100'
|
||||
00021 P00030 D6000103 00102 STH 4,X'102'
|
||||
00022 P00034 D700010A 00108 STD 6,X'108'
|
||||
00023 P00038 EC000001 P00000 BU START
|
||||
00024 P0003C P00000 END START
|
||||
* 0000 ERRORS IN MAIN
|
||||
@@ -1,24 +0,0 @@
|
||||
ABS
|
||||
DSECT
|
||||
ORG 0
|
||||
START EQU $
|
||||
NOP
|
||||
NOP
|
||||
LCS 2
|
||||
RDSTS 5
|
||||
BEI
|
||||
UEI
|
||||
LPSD L20
|
||||
LW 1,4
|
||||
LH 2,8
|
||||
LD 6,L20
|
||||
BU GON
|
||||
BOUND 1D
|
||||
L20 DATAW X'80000010'
|
||||
DATAW X'00004000'
|
||||
GON LI 4,X'FF'
|
||||
STW 4,X'100'
|
||||
STH 4,X'102'
|
||||
STD 6,X'108'
|
||||
BU START
|
||||
END START
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
# Makefile for utils
|
||||
SHELL = /bin/sh
|
||||
|
||||
# Adapt the flags in the following paragraph to your system
|
||||
# for Linux
|
||||
ROOT = .
|
||||
OPTC = -O #-m32
|
||||
|
||||
#B = $(ROOT)
|
||||
#B = $(ROOT)/bin
|
||||
B = /system/bin
|
||||
#I = $(ROOT)/include
|
||||
I =
|
||||
#L = $(ROOT)/lib
|
||||
#D = $L/mylib.a
|
||||
D =
|
||||
|
||||
##CFLAGS= $(OPTC) -I$I
|
||||
CFLAGS= $(OPTC) -I$I -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
# For Linux
|
||||
#LFLAGS= -L$L
|
||||
LFLAGS=
|
||||
|
||||
PROGS = \
|
||||
$(ROOT)/makecode
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
#install :$(PROGS)
|
||||
# @cp $(@F) $B
|
||||
# @echo $(@F) installed in $B
|
||||
# @echo
|
||||
## @chmod 755 $(@F)
|
||||
|
||||
##$(PROGS): $D $$(@F).c
|
||||
## @-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
##$(PROGS): $D $$(@F).c
|
||||
## @chmod 755 $@
|
||||
## @cp $(@F) $B
|
||||
## @echo $(@F) installed in $B
|
||||
## @echo
|
||||
|
||||
$B/makecode: $D makecode.c
|
||||
@-$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@
|
||||
@chmod 755 $@
|
||||
@cp $(@F) $B
|
||||
@echo $(@F) installed in $B
|
||||
|
||||
# Some makes don't understand the $$ notation above. In this case
|
||||
# you have to type out the compile paragraph for each PROG. Sigh.
|
||||
# Here's a start, good luck.
|
||||
#
|
||||
#$B/abshw: abshw.c
|
||||
# $(CC) $(CFLAGS) $? $(LFLAGS) -o $@
|
||||
# @chmod 751 $@
|
||||
# @echo $(@F) installed in $B
|
||||
|
||||
remake : clobber
|
||||
@make ROOT=$(ROOT) OPTC=$(OPTC)
|
||||
|
||||
clean :
|
||||
@-rm -f a.out junk* JUNK* core
|
||||
@-rm -f *.o
|
||||
|
||||
clobber : clean
|
||||
@-rm -f $(PROGS)
|
||||
|
||||
install : $(PROGS)
|
||||
@cp $(PROGS) $B
|
||||
@echo $(PROGS) installed in $B
|
||||
@echo
|
||||
# @chmod 755 $(@F)
|
||||
Reference in New Issue
Block a user