From 4f04684ff3cec27d82bca2cbc63304f5d7f93aed Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Tue, 13 Aug 2002 06:56:57 +0000 Subject: [PATCH] formatting --- utility/hogcreate.c | 95 ++++++++++++++++++++++---------------------- utility/hogextract.c | 87 ++++++++++++++++++++-------------------- utility/txb2txt.c | 82 +++++++++++++++++++------------------- utility/txt2txb.c | 90 +++++++++++++++++++++-------------------- 4 files changed, 181 insertions(+), 173 deletions(-) diff --git a/utility/hogcreate.c b/utility/hogcreate.c index bf6aa07f..c0e9a840 100644 --- a/utility/hogcreate.c +++ b/utility/hogcreate.c @@ -1,57 +1,58 @@ -/* Written 1999 Jan 29 by Josh Cogliati - I grant this program to public domain. -*/ +/* + * 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; -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); + if (argc != 2) { + printf("Usage: hogcreate hogfile\n" + "creates hogfile using all the files in the current directory\n"); + exit(0); } - fclose(readfile); + 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); + } + } + closedir(dp); + } + fclose(hogfile); } - - diff --git a/utility/hogextract.c b/utility/hogextract.c index 23881aa0..bd033489 100644 --- a/utility/hogextract.c +++ b/utility/hogextract.c @@ -1,45 +1,48 @@ -/* Written 1999 Jan 29 by Josh Cogliati - I grant this program to public domain. -*/ -#include -#include -#include -#include +/* + * 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); -} +#include + +void +main(int argc, char *argv[]) +{ + FILE *file, *outfile; + char equals, ch; + int code; + + if (argc != 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(argv[1], "rb"); + if (!file) { + printf("Can't open txb file (%s)\n", argv[1]); + exit(2); + } + outfile = fopen(argv[2], "wb"); + if (!outfile) { + printf("Can't open file (%s)\n", argv[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 index eee8ed29..b5b71326 100755 --- a/utility/txt2txb.c +++ b/utility/txt2txb.c @@ -1,44 +1,46 @@ -#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); -} +#include + +void +main(int argc, char *argv[]) +{ + FILE *file, *outfile; + char equals, ch; + int code; + + if (argc != 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(argv[1], "rb"); + if (!file) { + printf("Can't open file (%s)\n", argv[1]); + exit(2); + } + + outfile = fopen(argv[2], "wb"); + if (!outfile) { + printf("Can't open file (%s)\n", argv[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