Viewing TEXT75 files



#2

I was trying to view a bunch of TEXT75 files from the swap disks in the HP Museum site and was frustrated by the control information that surrounded the data. So I put together the following program which should work on most systems.

I have probably rediscovered the wheel, so if there is something better, do let me know and I will remove this posting.

Program takes a single argument which is assumed to be a TEXT75 file and prints the converted contents on standard output.

--------------------------------------------------------

/*
* pr_text75 -- convert TEXT75 files to ASCII
* Vassilis Prevelakis, CS Dept, Drexel University (2004/3/10)
*
* TEXT75 files use a format similar to that of BASIC programs.
* They have a short header, followed by lines of the format
* 2-byte line number in BCD
* 1-byte line length
* printable text.
*
* pr_text75 has been put together so as to skip the header and
* then print the contents of the file by printing the line number
* followed by the text.
*
* Unprintable characters in the text are printed in expanded form
* i.e. character code 8A will be printed as [8A].
*
* Quick hack to deal with swap-file format files. These have an
* additional 32 byte header. The hack involves looking for
* a bunch of zeros in the TEXT75 header in the file, and if this
* fails, look for the same info 32 bytes later.
* Given the richness of LIF files (i.e. loose standards), this hack
* is bound to fail on some file, so it should be replaced with something
* more decent.
*/
#include <stdio.h>
#include <stdlib.h>

char tohex(char c)
{
return((c < 10) ? (c + '0') : (c + 'A' - 10));
}

int get_str(char *cp, int n, FILE *fd)
{
int c;
while (n-- > 0)
{
if ((c = fgetc(fd)) < 0)
return(-1);
if (isprint(c))
*cp++ = c;
else {
*cp++ = '[';
*cp++ = tohex(c >> 4);
*cp++ = tohex(c & 0xF);
*cp++ = ']';
}
}
*cp = '\0';
return(0);
}
int rd_short(FILE *fd)
{
int msb, lsb;

if ((lsb = getc(fd)) < 0)
return(-1);
if ((msb = getc(fd)) < 0)
return(-1);
return((msb << 8) | lsb);
}

main(int argc, char **argv)
{
unsigned char buf[1025]; // worst case of a string with unprintable characters
int l, c;
char *fname;
FILE *fd;

fname = argv[1];
if ((fd = fopen(fname, "r")) == NULL) {
fprintf(stderr, "Could not open %s.\n", fname);
perror("fopen");
exit(1);
}

// if its just the file then we need to skip 24 bytes,
// if its a swap file, we need to skip another 32
fseek(fd, 26, SEEK_SET);
if ((l = rd_short(fd)) != 0)
{
fseek(fd, 30, SEEK_CUR); // two bytes we have read + 30 = 32
if ((l = rd_short(fd)) != 0)
{
fprintf(stderr, "File is not TEXT75?\n");
exit(1);
}
}

for(;;) {
// read line-number
if ((l = rd_short(fd)) < 0)
break;
// read string length
if ((c = getc(fd)) < 0)
break;
// read string
if (get_str(buf, c, fd) < 0)
break;
// if End-of-File sequence, exit
if (l == 0xA999 && c == 2)
break;
// print line-number: string
printf("%04x %s\n", l, buf);
};
exit(0);
}


#3

There's also a text75 program in my 'LIF Utilities for Linux' (available from http://www.hpcc.org/). It reads an HP75 text file on standard input and outputs a more sane version to standard output. It's written in C and should be fairly portable. There are other translation filters there too, for HP LIF1 text files, HP41 programs, and so on...


Possibly Related Threads...
Thread Author Replies Views Last Post
  How to copy files from 9114B to hard drive via PIL-box? Joe Horn 23 5,205 12-14-2013, 11:57 PM
Last Post: Geoff Quickfall
  How to update PRIME Firmware using Files on PC Harold A Climer 2 989 12-04-2013, 12:05 PM
Last Post: Erwin Ried
  Loading .prgm files to the Prime Thomas Chrapkiewicz 8 1,401 10-25-2013, 09:34 AM
Last Post: Eddie W. Shore
  Proper location for files on the PC for Connectivity Kit ,etc. Harold A Climer 8 1,475 10-23-2013, 02:43 AM
Last Post: Marcus von Cube, Germany
  HHC 2013 speakers' files Joe Horn 2 843 09-26-2013, 02:51 AM
Last Post: Geoff Quickfall
  Nonpareil Rom files davorin 2 677 09-20-2013, 06:20 PM
Last Post: Didier Lachieze
  Calculator, for your viewing pleasure Frank Boehm (Germany) 9 1,325 11-30-2012, 10:16 PM
Last Post: Patrice
  41 and 71B Overlays, DXF Files? aj04062 0 441 11-25-2012, 08:04 AM
Last Post: aj04062
  My HHC2012 Presentations and Files Namir 1 575 09-28-2012, 11:35 AM
Last Post: Eddie W. Shore
  HP42s input output of programs and files aurelio 17 1,951 09-01-2012, 10:18 PM
Last Post: Raymond Del Tondo

Forum Jump: