Harry Potter
2023-07-27 22:01:26 UTC
Hi! I am working on a 32-bit mode program in ANSI C format using the Digital Mars C compiler. I was unable to get the version, but it's probably a few years old. The program is to compress strings for certain old 8-bit computers such that a target program can print out individual strings without referring to other strings. I'm working on using tokenization, RLE of spaces (tabs of given sizes) and ways to compress literals without full-blown Huffman. The problem is that, as soon as the program starts, the computer crashes with a BSOD. :( I didn't record the stop code. I don't even get the text that is supposed to display upon start-up. I attached the whole main module:
---------------------------
/***********************************************************************
*
* Individual module for the ANSI compiler.
*
* The template for this file was created by TempC Module Creator by
* Joseph Rose. This template can be used in your programs, provided
* you mention TempC in your software's documentation. If this source
* code is distributed, this copyright must be included in the file.
*
***********************************************************************/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "in.h"
#include "buffer.h"
struct __indata {
enum {
sysCBM,
sysAtari,
sysApple2
} sys;
char toktype[16];
char littype[16];
struct {
unsigned docurchar;
char curcharname[32];
unsigned docharptr;
char curptrname[32];
} dozp;
char outname[256];
} indata;
unsigned loadfile (char* name);
int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
puts ("Ready to start program!"); getchar();
while (--argc) {
//Advance to next arg.
argv++;
printf ("Para %s\n", *argv); getchar();
//Is it a switch?
if (argv[0][0]=='-') {
//Process switch:
putchar ((argv[0][1])); puts(""); getchar();
switch (argv[0][1]) {
case 't':
//puts ("t switch processed.");
--argc; argv++;
if (!strcmp(*argv, "cbm")) indata.sys=sysCBM;
else if (!strcmp(*argv, "apple2")) indata.sys=sysApple2;
else if (!strcmp(*argv, "atari")) indata.sys=sysAtari;
else {
puts ("Error parsing cmdline: unrecognized target system.");
return 1;
}
break;
case 'o':
--argc; argv++;
strcpy (indata.outname, *argv);
break;
case 'c':
// switch (argv[0][2]) {
// case 't':
// case 'l':
// }
c=argv[0][2];
--argc; argv++;
if (c=='t') strcpy (indata.toktype,*argv);
else if (c=='l') strcpy (indata.littype,*argv);
else {
puts ("Error parsing cmdline: unrecognized compression type.");
return 1;
}
break;
case '?': //Print help.
puts ("Help."); return 0;
default: //Trap bad switch.
printf ("Bad switch: %c.", argv[0][1]); return 1;
}
} else { //Handle filename:
//printf ("File: %s\n", argv[0]);
--argc; argv++;
puts (*argv); getchar();
if (loadfile(*argv)) {
printf ("Error in file \"%s\"\n", *argv);
return 2;
}
}
}
// if ()
puts ("Ready to print strings!"); getchar();
if (!strings) {
puts ("No input strings!"); return 2;
}
atstring=strings;
do {
puts (atstring->name);
puts ("----------------");
puts (atstring->in);
printf (">>> len=%d\n", atstring->inlen);
puts ("=================");
atstring=atstring->next;
} while (atstring);
puts ("---end!");
getchar();
return 0;
}
----------------------------------
and the line that compiles the program:
----------------------------------
c:\dm\bin\dmc buffer.c in.c main.c -o -mn -4 -optok_comp.exe
----------------------------------
BTW, What can I do to better my versions of literal compression? I have ways to compress to 7 bits per character and 5 bits per character, can add a bit to some 5-bit codes to add more functionality there, can tag two bits to token specifiers on the literal compression techniques to bring the total of supported tokens to 128, and, if a run of spaces is not a tab, can shorten the length to 3 bits. Also, is there a way to better tokenization? Remember that a string can't reference another string except for tokens, and this is for an 8-bit computer.
---------------------------
/***********************************************************************
*
* Individual module for the ANSI compiler.
*
* The template for this file was created by TempC Module Creator by
* Joseph Rose. This template can be used in your programs, provided
* you mention TempC in your software's documentation. If this source
* code is distributed, this copyright must be included in the file.
*
***********************************************************************/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "in.h"
#include "buffer.h"
struct __indata {
enum {
sysCBM,
sysAtari,
sysApple2
} sys;
char toktype[16];
char littype[16];
struct {
unsigned docurchar;
char curcharname[32];
unsigned docharptr;
char curptrname[32];
} dozp;
char outname[256];
} indata;
unsigned loadfile (char* name);
int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
puts ("Ready to start program!"); getchar();
while (--argc) {
//Advance to next arg.
argv++;
printf ("Para %s\n", *argv); getchar();
//Is it a switch?
if (argv[0][0]=='-') {
//Process switch:
putchar ((argv[0][1])); puts(""); getchar();
switch (argv[0][1]) {
case 't':
//puts ("t switch processed.");
--argc; argv++;
if (!strcmp(*argv, "cbm")) indata.sys=sysCBM;
else if (!strcmp(*argv, "apple2")) indata.sys=sysApple2;
else if (!strcmp(*argv, "atari")) indata.sys=sysAtari;
else {
puts ("Error parsing cmdline: unrecognized target system.");
return 1;
}
break;
case 'o':
--argc; argv++;
strcpy (indata.outname, *argv);
break;
case 'c':
// switch (argv[0][2]) {
// case 't':
// case 'l':
// }
c=argv[0][2];
--argc; argv++;
if (c=='t') strcpy (indata.toktype,*argv);
else if (c=='l') strcpy (indata.littype,*argv);
else {
puts ("Error parsing cmdline: unrecognized compression type.");
return 1;
}
break;
case '?': //Print help.
puts ("Help."); return 0;
default: //Trap bad switch.
printf ("Bad switch: %c.", argv[0][1]); return 1;
}
} else { //Handle filename:
//printf ("File: %s\n", argv[0]);
--argc; argv++;
puts (*argv); getchar();
if (loadfile(*argv)) {
printf ("Error in file \"%s\"\n", *argv);
return 2;
}
}
}
// if ()
puts ("Ready to print strings!"); getchar();
if (!strings) {
puts ("No input strings!"); return 2;
}
atstring=strings;
do {
puts (atstring->name);
puts ("----------------");
puts (atstring->in);
printf (">>> len=%d\n", atstring->inlen);
puts ("=================");
atstring=atstring->next;
} while (atstring);
puts ("---end!");
getchar();
return 0;
}
----------------------------------
and the line that compiles the program:
----------------------------------
c:\dm\bin\dmc buffer.c in.c main.c -o -mn -4 -optok_comp.exe
----------------------------------
BTW, What can I do to better my versions of literal compression? I have ways to compress to 7 bits per character and 5 bits per character, can add a bit to some 5-bit codes to add more functionality there, can tag two bits to token specifiers on the literal compression techniques to bring the total of supported tokens to 128, and, if a run of spaces is not a tab, can shorten the length to 3 bits. Also, is there a way to better tokenization? Remember that a string can't reference another string except for tokens, and this is for an 8-bit computer.