From: b Date: Mon, 5 Aug 2013 18:14:00 +0000 (+0200) Subject: - Saving CPX files X-Git-Tag: v1.3c X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;ds=sidebyside;p=cpied - Saving CPX files --- diff --git a/appinfo/cpied.lsm b/appinfo/cpied.lsm index 9d9f3ce..9b5e1ae 100644 --- a/appinfo/cpied.lsm +++ b/appinfo/cpied.lsm @@ -1,7 +1,7 @@ Begin3 Title: cpied -Version: 1.3a -Entered-date: 2013-08-01 +Version: 1.3c +Entered-date: 2013-08-05 Description: a GUI-driven CPI font editor Keywords: cpi,cpx,font,editor Author: Balthasar Szczepanski diff --git a/doc/cpied/readthis.txt b/doc/cpied/readthis.txt index cdd4a2a..f3c279a 100644 --- a/doc/cpied/readthis.txt +++ b/doc/cpied/readthis.txt @@ -3,11 +3,11 @@ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ Û ÛÛ ÛÛ ÛÛ Û ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ Û Û ÛÛ ÛÛÛÛÛ ÛÛ ÛÛÛÛ ÛÛ ÛÛ Û Û -ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛÛ Û ÛÛ B +ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ ÛÛÛ Û ÛÛ C ÛÛ ÛÛ ÛÛ ÛÛ ÛÛ Û ÛÛ ÛÛ ÛÛÛÛ ÛÛÛÛ ÛÛÛÛ ÛÛÛÛÛÛÛ ÛÛÛÛÛ Balthasar Szczepaäski - CPIED 1.3b - the CPI editor + CPIED 1.3c - the CPI editor ============================================================ @@ -37,7 +37,8 @@ GPL 3 license (see ccopying.txt) The program should be able to run on any IBM-PC compatible computer* with an IBM-VGA compatible video card and DOS** or -Windows*** operating system or a DOS emulator****. +Windows*** operating system or a DOS emulator****. To save +CPX files UPX (upx.sourceforge.net) must be installed **The program should run on any DOS that is not older than 3.3. It was tested on following systems: @@ -93,8 +94,8 @@ The following file formats are supported: This format is not fully supported. Files can be loaded in this format, but can only be saved in FONT format. Windows supports both formats, so this is not a problem. -3.CPX - used by FreeDOS. Files can be loaded in - this format, but can only be saved in CPI format. +3.CPX - used by FreeDOS. To save CPX files + UPX (upx.sourceforge.net) must be installed The following file formats are not supported: @@ -237,12 +238,13 @@ beta: - Dialog boxes can now cancelled with Esc or empty string - Added warnings before deleting a font, a codepage or closing the program when a file is open +1.3c + - Saving CPX files ============================================================ 6. Planned features - - Saving CPX files - Exporting codepages to CP files - Importing codepages from CP flies - Exporting fonts to bitmaps @@ -276,7 +278,7 @@ Watcom's wmake doesn't compile cpx2cpi. Installing: cpied.exe and cpx2cpi.com should be copied to somwere in the -%PATH% +%PATH%. On Windows you may register *.cpi and*.cpx file extensions to CPIED. @@ -285,15 +287,14 @@ to CPIED. 9. Files -BIN: CPIED .EXE The CPI editor CPX2CPI .COM CPX to CPI converter -SRC: + CPIED .CPP Source for the CPI editor CPX2CPI .C Source for the CPX to CPI converter CPITRICK.ASM Source for the CPX to CPI converter MAKEFILE Makefile for both programs -DOC: + COPYING .TXT License information READTHIS.TXT This file diff --git a/source/cpied/CPIED.CPP b/source/cpied/CPIED.CPP index 4f1d637..a5e8203 100644 --- a/source/cpied/CPIED.CPP +++ b/source/cpied/CPIED.CPP @@ -1,4 +1,4 @@ - //CPIED version 1.3b + //CPIED version 1.3c // Balthasar Szczepaäski Copyright 2013 // // This file is part of CPIED @@ -16,6 +16,7 @@ //You should have received a copy of the GNU General Public License along // with CPIED (copying.txt). If not, see . + #define BLACK 0 #define GRAY 8 #define BLUE 1 @@ -227,7 +228,7 @@ int otw2(); void otw3(); int zap (); -int zap2(); +int zap2(int format=0); void zap3(); void use3(); @@ -352,7 +353,7 @@ void new8() _clearscreen(_GCLEARSCREEN); _setcolor(C_SEL); _moveto(0,0); - _outgtext("CPIED 1.3b±"); + _outgtext("CPIED 1.3c±"); _moveto(0,8); _outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±"); } @@ -1337,37 +1338,84 @@ int otw2() { fclose(CPI); deleteCPI(0); - status=spawnlp(P_WAIT,"cpx2cpi","cpx2cpi",nazwap,"tempcpi","q",NULL); - if(status) - { - sprintf(err,"101:Unsupported format, id0=0x81\n"); - if (status<3) - remove("tempcpi"); - return 101; - } - CPX=true; - CPI=fopen("tempcpi","rb"); - if(CPI==NULL) + //First, try using UPX + status=spawnlp(P_WAIT,"upx","upx","-d","-q","-o__TEMP__.com",nazwap,NULL); + if(status==-1) + //There is no UPX installed, try using cpx2cpi { - sprintf(err,"101:Unsupported format, id0=0x81\n"); - return 101; - } - FFH=new FontFileHeader; - if(!FFH) - { - sprintf(err,"116:Not enough memory for FFH\n"); - fclose(CPI); - remove("tempcpi"); - return 116; + status=spawnlp(P_WAIT,"cpx2cpi","cpx2cpi",nazwap,"__TEMP__.com","q",NULL); + if(status==-1)//and there is no cpx2cpi + { + sprintf(err,"150:CPX not supported, install cpx2cpi\n"); + return 150; + } + if(status)//not converted + { + sprintf(err,"151:CPX decompression failed"); + if (status<3)//but file is created + remove("__TEMP__.com"); + return 151; + } + CPX=true; + CPI=fopen("__TEMP__.com","rb"); + if(CPI==NULL)//converted to an unopenable file + { + sprintf(err,"152:Cannot open decompressed file"); + return 152; + } + FFH=new FontFileHeader; + if(!FFH) + { + sprintf(err,"116:Not enough memory for FFH\n"); + fclose(CPI); + remove("__TEMP__.com"); + return 116; + } + fread(FFH,0x19,1,CPI); + if(FFH->id0!=0xff) + //converted to cpi but it's not a cpi + { + sprintf(err,"101:Unsupported format, id0=0x%02x\n",(short)(FFH->id0&0xff)); + fclose(CPI); + remove("__TEMP__.com"); + deleteCPI(0); + return 101; + } } - fread(FFH,0x19,1,CPI); - if(FFH->id0!=0xff) + else//there is upx installed { - sprintf(err,"101:Unsupported format, id0=0x%02x\n",(short)(FFH->id0&0xff)); - fclose(CPI); - remove("tempcpi"); - deleteCPI(0); - return 101; + if(status)//not converted + { + sprintf(err,"151:CPX decompression failed"); + //don't ktow if temp file created, delete anyway + remove("__TEMP__.com"); + return 151; + } + CPX=true; + CPI=fopen("__TEMP__.com","rb"); + if(CPI==NULL)//converted to an unopenable file + { + sprintf(err,"152:Cannot open decompressed file\n"); + return 152; + } + FFH=new FontFileHeader; + if(!FFH) + { + sprintf(err,"116:Not enough memory for FFH\n"); + fclose(CPI); + remove("__TEMP__.com"); + return 116; + } + fread(FFH,0x19,1,CPI); + if(FFH->id0!=0xff) + //converted to cpi but it's not a cpi + { + sprintf(err,"101:Unsupported format, id0=0x%02x\n",(short)(FFH->id0&0xff)); + fclose(CPI); + remove("__TEMP__.com"); + deleteCPI(0); + return 101; + } } } else @@ -1392,7 +1440,7 @@ int otw2() sprintf(err,"102:Unsupported format, id=\"%c%c%c%c%c%c%c\"\n",FFH->id[0],FFH->id[1],FFH->id[2],FFH->id[3],FFH->id[4],FFH->id[5],FFH->id[6]); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(0); return 102; } @@ -1401,7 +1449,7 @@ int otw2() sprintf(err,"103:Wrong no. of pointers (%u)\n",FFH->pnum); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(0); return 103; } @@ -1410,7 +1458,7 @@ int otw2() sprintf(err,"104:Wrong pointer type, (%u)\n",(short)(FFH->ptyp&0xff)); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(0); return 104; } @@ -1421,7 +1469,7 @@ int otw2() sprintf(err,"116:Not enough memory for FIH\n"); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(0); return 116; } @@ -1432,7 +1480,7 @@ int otw2() sprintf(err,"105:Too many codepages (%u)\n",FIH->num_codepages); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(1); return 105; } @@ -1441,7 +1489,7 @@ int otw2() sprintf(err,"117:No codepages\n"); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(1); return 117; } @@ -1456,7 +1504,7 @@ int otw2() sprintf(err,"116:Not enough memory for CPEH[%d]\n",a); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(1); return 116; } @@ -1471,7 +1519,7 @@ int otw2() sprintf(err,"106:Wrong CPEH[%u] size (0x%x)\n",a,CPEH[a]->cpeh_size); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(2,a); return 106; } @@ -1480,7 +1528,7 @@ int otw2() sprintf(err,"107:Wrong device type(%u) in cp%03u\n",CPEH[a]->device_type,CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(2,a); return 107; } @@ -1491,7 +1539,7 @@ int otw2() sprintf(err,"114:cp%03u duplicated in this CPI\n",CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(2,a); return 114; } @@ -1504,7 +1552,7 @@ int otw2() sprintf(err,"116:Not enough memory for CPIH[%d]\n",a); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(2,a); return 116; } @@ -1514,7 +1562,7 @@ int otw2() sprintf(err,"108:Wrong version of CPIH[%u] (%u)\n",a,CPIH[a]->version); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(3,a); return 108; } @@ -1523,7 +1571,7 @@ int otw2() sprintf(err,"109:Too many fonts in cp%03u (%u)\n",CPEH[a]->codepage,CPIH[a]->num_fonts); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(3,a); return 109; } @@ -1532,7 +1580,7 @@ int otw2() sprintf(err,"115:No fonts in cp%03u\n",CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(3,a); return 115; } @@ -1545,7 +1593,7 @@ int otw2() sprintf(err,"116:Not enough memory for SFH[%d][%d]\n",a); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); if(b==0) deleteCPI(3,a); else @@ -1560,7 +1608,7 @@ int otw2() sprintf(err,"113:Height 8 duplicated in cp%03u\n",CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 113; } @@ -1573,7 +1621,7 @@ int otw2() sprintf(err,"113:Height 14 duplicated in cp%03u\n",CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 113; } @@ -1586,7 +1634,7 @@ int otw2() sprintf(err,"113:Height 16 duplicated in cp%03u\n",CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 113; } @@ -1597,7 +1645,7 @@ int otw2() sprintf(err,"110:Wrong height (%u) in cp%03u\n",(short)(SFH[a][b]->height&0xff),CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 110; } @@ -1606,7 +1654,7 @@ int otw2() sprintf(err,"111:Wrong width (%u) in cp%03u\n",(short)(SFH[a][b]->width&0xff),CPEH[a]->codepage); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 111; } @@ -1615,7 +1663,7 @@ int otw2() sprintf(err,"112:Wrong no.of chars(%u)in cp%03ux%02u\n",SFH[a][b]->num_chars,CPEH[a]->codepage,SFH[a][b]->height); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 112; } @@ -1627,7 +1675,7 @@ int otw2() sprintf(err,"116:Not enough memory for SFB16[%d] (%d)\n",a,b); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 116; } @@ -1641,7 +1689,7 @@ int otw2() sprintf(err,"116:Not enough memory for SFB14[%d] (%d)\n",a,b); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 116; } @@ -1655,7 +1703,7 @@ int otw2() sprintf(err,"116:Not enough memory for SFB8[%d] (%d)\n",a,b); fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); deleteCPI(4,a,b); return 116; } @@ -1665,7 +1713,7 @@ int otw2() } fclose(CPI); if(CPX) - remove("tempcpi"); + remove("__TEMP__.com"); offset(); return 0; } @@ -1703,26 +1751,46 @@ void otw3()// int zap() { + int c; if(question("Filename",nazwap)==1) return 1; - return zap2(); + int format; + c=strlen(nazwap)-4; + if(!strcmpi(nazwap+c,".cpx")) + format=1; + else if(!strcmpi(nazwap+c,".cpi")) + format=0; + else if(message("WARNING","Unknown extension,save in CPI format?\n",3)==1) + return 1; + else + format=0; + return zap2(format); } -int zap2() + +int zap2(int format) { + //CPI - 0 + //CPX - 1; int a; int b; - //int c; - //int d; - - CPI=fopen(nazwap,"wb"); - if(CPI==NULL) + if(format==1) { - sprintf(err,"200:Cannot create file at this path\n"); - return 200; + CPI=fopen("__TEMP__.com","wb"); + if(CPI==NULL) + { + sprintf(err,"252:Cannot create temporary CPI file\n"); + return 252; + } } else - sprintf(err,"OK"); - + { + CPI=fopen(nazwap,"wb"); + if(CPI==NULL) + { + sprintf(err,"200:Cannot create file at this path\n"); + return 200; + } + } fwrite(FFH,0x19,1,CPI); fseek(CPI,FFH->fih_offset,0); @@ -1753,8 +1821,24 @@ int zap2() } } - fprintf(CPI,"\r\nThis file was created with the CPI editor version 1.3b",0x1a); + fprintf(CPI,"\r\nThis file was created with CPIED 1.3c.%c",0x1a); fclose(CPI); + if(format==1) + { + status=spawnlp(P_WAIT,"upx","upx","-q","-o",nazwap,"__TEMP__.com",NULL); + if(status==-1) + { + sprintf(err,"250:CPX not supported, UPX required\n"); + return 250; + } + if(status) + { + sprintf(err,"251:CPX compression failed\n"); + remove("__TEMP__.com"); + return 251; + } + remove("__TEMP__.com"); + } return 0; } void zap3()// @@ -2676,6 +2760,7 @@ int delF16(short h) int main(int argc,char* argv[]) { + nullpointers(); if(argc>1) @@ -2802,7 +2887,7 @@ int main(int argc,char* argv[]) //spacja switch(wys) { - case 8: + case 8: spc8(); lit8(1); lin8(3);