From dad5c8875c20e9756c8d50a44fbd24ec17f3035a Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Tue, 13 Aug 2002 06:45:00 +0000 Subject: [PATCH] added utilities --- utility/hogcreate.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ utility/hogextract.c | 45 ++++++++++++++++++++++++++++++++++ utility/txb2txt.c | 40 +++++++++++++++++++++++++++++++ utility/txt2txb.c | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 utility/hogcreate.c create mode 100644 utility/hogextract.c create mode 100755 utility/txb2txt.c create mode 100755 utility/txt2txb.c diff --git a/utility/hogcreate.c b/utility/hogcreate.c new file mode 100644 index 00000000..bf6aa07f --- /dev/null +++ b/utility/hogcreate.c @@ -0,0 +1,57 @@ +/* Written 1999 Jan 29 by Josh Cogliati + I grant this program to public domain. +*/ +#include +#include +#include +#include +#include + + +void main(int argc, char *argv[]){ + FILE * hogfile, * readfile; + DIR * dp; + struct dirent *ep; + int fp, len, fseekret=0; + char filename[13]; + char * buf; + struct stat statbuf; + if(argc != 2){ + printf("Usage: hogcreate hogfile\n" + "creates hogfile using all the files in the current directory\n" + ); + exit(0); + } + hogfile = fopen(argv[1],"w"); + buf = (char *)malloc(3); + strncpy(buf,"DHF",3); + fwrite(buf,3,1,hogfile); + printf("Creating: %s\n",argv[1]); + free(buf); + dp = opendir("./"); + if (dp != NULL) { + while (ep = readdir(dp)) { + strcpy(filename, ep->d_name); + stat(filename,&statbuf); + if(! S_ISDIR(statbuf.st_mode)) { + printf("Filename: %s \tLength: %i\n",filename,statbuf.st_size); + readfile = fopen(filename,"r"); + buf = (char *)malloc(statbuf.st_size); + if(buf == NULL) { + printf("Unable to allocate memery\n"); + } else { + fwrite(filename, 13,1,hogfile); + fwrite(&statbuf.st_size, sizeof(int),1,hogfile); + fread(buf,statbuf.st_size, 1 , readfile); + fwrite(buf,statbuf.st_size, 1 , hogfile); + } + fclose(readfile); + + } + } + closedir(dp); + } + fclose(hogfile); +} + + diff --git a/utility/hogextract.c b/utility/hogextract.c new file mode 100644 index 00000000..23881aa0 --- /dev/null +++ b/utility/hogextract.c @@ -0,0 +1,45 @@ +/* Written 1999 Jan 29 by Josh Cogliati + I grant this program to public domain. +*/ +#include +#include +#include +#include + + +void main(int argc, char *argv[]){ + FILE * hogfile, * writefile; + int fp, len, fseekret=0; + char filename[13]; + char * buf; + struct stat statbuf; + if(argc != 2){ + printf("Usage: hogextract hogfile\n" + "extracts all the files in hogfile into the current directory\n" + ); + exit(0); + } + hogfile = fopen(argv[1],"r"); + stat(argv[1],&statbuf); + printf("%i\n",statbuf.st_size); + buf = (char *)malloc(3); + fread(buf,3,1,hogfile); + printf("Extracting from: %s\n",argv[1]); + free(buf); + while(ftell(hogfile) + +main(int ac,char *av[]) { + FILE *file,*outfile; + char equals,ch; + int code; + + if (ac!=3) { + printf("TXB2TXT V1.0 Copyright (c) Bryan Aamot, 1995\n" + "TXB to Text converter for Descent HOG files.\n" + "Converts a *.txb descent hog file to an ascii file.\n" + "Usage: TXB2TXT \n" + "Example: TXT2TXB briefing.txb briefing.txt\n"); + exit(1); + } + file = fopen(av[1],"rb"); + if (!file) { + printf("Can't open txb file (%s)\n",av[1]); + exit(2); + } + outfile = fopen(av[2],"wb"); + if (!outfile) { + printf("Can't open file (%s)\n",av[2]); + fclose(file); + exit(2); + } + for (;;) { + code = getc(file); + if (feof(file)) break; + if (code == 0x0a) { + fprintf(outfile,"\x0d\x0a"); + } else { + ch = ( ( (code&0x3f) << 2 ) + ( (code&0xc0) >> 6 ) ) ^ 0xa7; + fprintf(outfile,"%c",ch); + } + } + + fclose(outfile); + fclose(file); +} diff --git a/utility/txt2txb.c b/utility/txt2txb.c new file mode 100755 index 00000000..eee8ed29 --- /dev/null +++ b/utility/txt2txb.c @@ -0,0 +1,44 @@ +#include + +main(int ac,char *av[]) { + FILE *file,*outfile; + char equals,ch; + int code; + + if (ac!=3) { + printf("TXT2TXB V1.0 Copyright (c) Bryan Aamot, 1995\n" + "Text to TXB converter for Descent HOG files.\n" + "Converts a ascii text files to *.txb descent hog file format.\n" + "Usage: TXT2TXB \n" + "Example: TXT2TXB briefing.txt briefing.txb\n"); + exit(1); + } + file = fopen(av[1],"rb"); + if (!file) { + printf("Can't open file (%s)\n",av[1]); + exit(2); + } + + outfile = fopen(av[2],"wb"); + if (!outfile) { + printf("Can't open file (%s)\n",av[2]); + fclose(file); + exit(2); + } + + for (;;) { + ch = getc(file); + if (feof(file)) break; + if (ch!=0x0d) { + if (ch==0x0a) { + fprintf(outfile,"\x0a"); + } else { + code = ( ( (ch &0xfC) >> 2) + ( (ch &0x03) << 6 ) ) ^ 0xe9; + fprintf(outfile,"%c",code); + } + } + } + + fclose(outfile); + fclose(file); +} -- 2.39.2