...
 
Commits (1)
  • Deuce's avatar
    Fix font insanity and Clang warnings. · 61d3c0d5
    Deuce authored
    Since this was originally Pascal, there's a tonne of 1-based indexed
    arrays, and the font ones were sized by number of elements, meaning
    it was chock full of buffer overflows.  Also, the Pascal string
    handling was crazy.
    
    There were also some file IO issues floating around.
    
    This fixes all of those issues and also Closes #179
    61d3c0d5
......@@ -208,7 +208,7 @@ blockcenter(void)
blocklefttrim();
for (y = Y1; y <= Y2; y++) {
for (x = X1; x <= X2; x++)
if ((Screen[ActivePage][y][x << 1] == 32))
if (Screen[ActivePage][y][x << 1] == 32)
d++;
d /= 2;
while (d >= 1) {
......
......@@ -29,11 +29,13 @@ insertfont(char *Name)
fseek(fp, 0, SEEK_SET);
/* Read Font Header in TDFont */
TDFont.Sign[0] = fgetc(fp);
for (x = 0; x < 19; x++)
for (x = 1; x < 20; x++)
TDFont.Sign[x] = fgetc(fp);
TDFont.Sign[18] = 0;
if (strcmp(TDFont.Sign, "TheDraw FONTS file") != 0)
TDFont.Sign[19] = 0;
if (strcmp(TDFont.Sign, "\x13" "TheDraw FONTS file") != 0) {
printf("Invalid font file %s\n", Name);
return;
}
for (x = 0; x <= 3; x++)
TDFont.a[x] = fgetc(fp);
for (x = 0; x <= 16; x++)
......@@ -50,7 +52,7 @@ insertfont(char *Name)
Header.NumberofFonts++;
/* Make FontRecord */
memcpy(&fr[Header.NumberofFonts].FontName, &TDFont.Name, 16);
memcpy(&fr[Header.NumberofFonts].FontName, &TDFont.Name, 17);
fr[Header.NumberofFonts].Length = size;
fr[Header.NumberofFonts].FilePos = FilePos;
FilePos += size;
......@@ -82,9 +84,6 @@ int main(int argnum, char *args[])
printf("can't open %s for read\n",args[1]);
return(1);
}
CreateFontFile();
/*Huh ? It 's not open! */
/* fseek(font, 0, SEEK_SET); */
while (1) {
fgets(filename, 255, fp);
if (!feof(fp)) {
......@@ -107,13 +106,13 @@ int main(int argnum, char *args[])
return(1);
}
/* Header */
fwrite(&Header.sign, 1, 10, font);
fwrite("\x09" "Font File", 10, 1, font);
Header.NumberofFonts=LE_SHORT(Header.NumberofFonts);
fwrite(&Header.NumberofFonts, 2, 1, font);
Header.NumberofFonts=LE_SHORT(Header.NumberofFonts);
/* Font Headers */
for (x = 1; x <= Header.NumberofFonts; x++) {
for (y = 0; y <= 16; y++)
for (y = 0; y < 17; y++)
fputc(fr[x].FontName[y], font);
fr[x].FilePos=LE_LONG(fr[x].FilePos);
fwrite(&fr[x].FilePos, 4, 1, font);
......
......@@ -22,24 +22,24 @@ DrawBox(int x1, int y1, int x2, int y2)
exit(1);
i=0;
buf[i++]=218;
buf[i++]='\xda';
buf[i++]=ATTR_NORM_HIGH;
for(x=2;x<=width-4;x++) {
buf[i++]=196;
buf[i++]='\xc4';
buf[i++]=ATTR_NORM_HIGH;
}
buf[i++]=196;
buf[i++]='\xc4';
buf[i++]=ATTR_NORM_HIGH;
buf[i++]=191;
buf[i++]='\xbf';
buf[i++]=ATTR_NORM_HIGH;
puttext(x1,y1,x2,y1,buf);
buf[i-2]=217;
buf[0]=192;
buf[i-2]='\xd9';
buf[0]='\xc0';
puttext(x1,y2,x2,y2,buf);
i=0;
for(y=1; y<=height-2;y++) {
buf[i++]=179;
buf[i++]='\xb3';
if(y==1 || y==height-2)
buf[i++]=ATTR_NORM_HIGH;
else if (y==2 || y==height-3)
......
......@@ -6,14 +6,14 @@
#include "homedir.h"
#include "fonts.h"
#define TheDrawFontSize 254
#define TheDrawFontSize 252
MysticDrawFontHeader Header;
FontRecord FontRec;
TheDrawFont TDFont;
unsigned short SFont;
unsigned char Outline, MaxX, MaxY;
unsigned char Chars[60][24];
unsigned char Chars[61][25];
char *OutlineCharSet[20] = {
"컴납悶悶잎잎늘 ",
"羔납辣悶禿잎돤 ",
......
......@@ -4,18 +4,18 @@
#define HeaderSize 12
#define FontRecordSize 25
typedef struct {
char FontName[16];
char FontName[17];
unsigned long FilePos;
unsigned long Length;
} FontRecord;
typedef struct {
char sign[9];
char sign[10];
unsigned short NumberofFonts;
} MysticDrawFontHeader;
typedef struct {
char Sign[19];
char Sign[20];
char a[3];
char Name[16];
unsigned char FontType;
......@@ -30,7 +30,7 @@ extern FontRecord FontRec;
extern TheDrawFont TDFont;
extern unsigned short SFont;
extern unsigned char Outline, MaxX, MaxY;
extern unsigned char Chars[60][24];
extern unsigned char Chars[61][25];
void CreateFontFile(void);
void Openfont(int num);
......
......@@ -143,6 +143,7 @@ void
ShowFont(int number)
{
int a = 0, x, ch;
textattr(7);
clrscr();
Openfont(number);
do {
......@@ -186,6 +187,7 @@ ShowFont(int number)
break;
}
} while (toupper(ch) != 'Q');
textattr(7);
clrscr();
}
......@@ -241,7 +243,7 @@ main(int argc, char **argv)
textattr(24);
else
textattr(8);
for (x = x; x <= 16; x++)
for (; x <= 16; x++)
putch(250);
textattr(10);
cprintf("%02d", (size[y + c] / 1024));
......@@ -326,6 +328,7 @@ main(int argc, char **argv)
fclose(fp);
fclose(fp2);
fclose(fp3);
textattr(7);
clrscr();
break;
}
......@@ -393,6 +396,7 @@ main(int argc, char **argv)
fclose(fp3);
remove(FontFile);
rename("tmp.fnt", FontFile);
textattr(7);
clrscr();
break;
case 10:
......
......@@ -605,14 +605,14 @@ LoadFile(char *Name)
TxtCol = 7;
LastLine = 0;
ch = strlen(Name) - 3;
if ((toupper(Name[ch++]) == 'B') & (toupper(Name[ch++]) == 'I') & (toupper(Name[ch]) == 'N')) {
if ((toupper(Name[ch++]) == 'B') && (toupper(Name[ch++]) == 'I') && (toupper(Name[ch]) == 'N')) {
unsigned char line[160];
do {
fread(&line, 1, 160, fp);
memcpy(Screen[ActivePage][CursY], &line, 160);
CursY++;
} while (!feof(fp));
} else
} else {
/* Check for "known" extensions */
ext=getfext(Name);
if(ext) {
......@@ -665,6 +665,7 @@ LoadFile(char *Name)
}
} while ((avt_rep && b == 3) || (ans_rep > 0));
} while (!feof(fp));
}
ReadSauce(fp);
fclose(fp);
LastLine = CursY;
......@@ -799,7 +800,7 @@ load(void)
attr=(7 + 16);
else
attr=(7);
buf[(x*77+13)*2]=250;
buf[(x*77+13)*2]='\xfa';
buf[(x*77+13)*2+1]=attr;
if (y == x)
attr=(15 + 16);
......@@ -810,7 +811,7 @@ load(void)
attr=(7 + 16);
else
attr=(7);
buf[(x*77+42)*2]=250;
buf[(x*77+42)*2]='\xfa';
buf[(x*77+42)*2+1]=attr;
if (y == x)
attr=(15 + 16);
......@@ -821,7 +822,7 @@ load(void)
textattr(7 + 16);
else
textattr(7);
buf[(x*77+61)*2]=250;
buf[(x*77+61)*2]='\xfa';
buf[(x*77+61)*2+1]=attr;
if (y == x)
attr=(15 + 16);
......
......@@ -135,7 +135,7 @@ Menues(int x, int y)
int
menue(void)
{
int x, a, b, i;
int a, b, i;
char buf[80*2*2];
b = 0;
ActiveMenue = 1;
......@@ -144,7 +144,7 @@ menue(void)
if (ActiveMenue != b) {
ShowScreen(0, 0);
i=0;
buf[i++]=223;
buf[i++]='\xdf';
buf[i++]=ATTR_NORM_LOW;
i+=bufprintf(buf+i,ActiveMenue==1?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR," FILES ");
i+=bufprintf(buf+i,ActiveMenue==2?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"FONTS ");
......@@ -153,11 +153,11 @@ menue(void)
i+=bufprintf(buf+i,ActiveMenue==5?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"MISC. ");
i+=bufprintf(buf+i,ActiveMenue==6?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"TOGGLES ");
i+=bufprintf(buf+i,ActiveMenue==7?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"HELP");
buf[i++]=219;
buf[i++]='\xdb';
buf[i++]=ATTR_NORM_LOW;
buf[i++]=220;
buf[i++]='\xdc';
buf[i++]=ATTR_NORM_LOW;
buf[i++]=223;
buf[i++]='\xdf';
buf[i]=ATTR_NORM_LOW;
puttext(1,1,80,1,buf);
}
......
......@@ -266,31 +266,31 @@ SelectColor(void)
memset(buf,0,sizeof(buf));
bufprintf(buf+(5*51+21)*2,8,"B - BLINK");
i=(1*51+2)*2;
buf[i++]=176;
buf[i++]='\xb0';
buf[i++]=15;
buf[i++]=176;
buf[i++]='\xb0';
buf[i++]=15;
buf[i++]=32;
buf[i++]=15;
for (a = 1; a <= 15; a++) {
buf[i++]=219;
buf[i++]='\xdb';
buf[i++]=a;
buf[i++]=219;
buf[i++]='\xdb';
buf[i++]=a;
buf[i++]=32;
buf[i++]=a;
}
i=(3*51+13)*2;
buf[i++]=176;
buf[i++]='\xb0';
buf[i++]=15;
buf[i++]=176;
buf[i++]='\xb0';
buf[i++]=15;
buf[i++]=32;
buf[i++]=15;
for (a = 1; a <= 7; a++) {
buf[i++]=219;
buf[i++]='\xdb';
buf[i++]=a;
buf[i++]=219;
buf[i++]='\xdb';
buf[i++]=a;
buf[i++]=32;
buf[i++]=a;
......@@ -415,7 +415,7 @@ translate(char a)
case 'N':
return '';
case 'u':
return 150;
return '\x96';
case 'U':
return '';
case 'Y':
......@@ -464,7 +464,7 @@ inputfield(char *Str, int length, int x1, int y)
oldy=wherey();
do {
for (x = 1; x <= length; x++) {
buf[(x-1)*2]=250;
buf[(x-1)*2]='\xfa';
buf[(x-1)*2+1]=8;
}
bufprintf(buf,7,"%.*s",length,nul);
......
......@@ -309,21 +309,21 @@ SauceSet(void)
do {
bufprintf(buf,15,"%s",SauceDescr.Title);
for (b = strlen(SauceDescr.Title); b < 35; b++) {
buf[b*2]=250;
buf[b*2]='\xfa';
buf[b*2+1]=7;
}
puttext(29,11,63,11,buf);
bufprintf(buf,15,"%s", SauceDescr.Author);
for (b = strlen(SauceDescr.Author); b < 20; b++) {
buf[b*2]=250;
buf[b*2]='\xfa';
buf[b*2+1]=7;
}
puttext(29,12,48,12,buf);
bufprintf(buf,15,"%s", SauceDescr.Group);
for (b = strlen(SauceDescr.Group); b < 20; b++) {
buf[b*2]=250;
buf[b*2]='\xfa';
buf[b*2+1]=7;
}
puttext(29, 13, 48, 13, buf);
......
......@@ -1062,7 +1062,6 @@ main(int argnum, char *args[])
CharSet[9] = NCharSet[9];
CharSet[10] = NCharSet[10];
CharSet[11] = NCharSet[11];
CharSet[12] = NCharSet[12];
for (a = 0; a < 4; a++)
for (y = 0; y <= MaxLines; y++) {
......
......@@ -48,10 +48,10 @@ tabsetup(void)
memset(buf,0,sizeof(buf));
for (y = 1; y <= 80; y++) {
if (tabs[y] == TRUE) {
buf[(y-1)*2]=254;
buf[(y-1)*2]='\xfe';
buf[(y-1)*2+1]=7;
} else {
buf[(y-1)*2]=250;
buf[(y-1)*2]='\xfa';
buf[(y-1)*2+1]=7;
}
}
......