]> bicyclesonthemoon.info Git - cpied/commitdiff
- Saving CPX files main v1.3c
authorb <rowerynaksiezycu@gmail.com>
Mon, 5 Aug 2013 18:14:00 +0000 (20:14 +0200)
committerb <rowerynaksiezycu@gmail.com>
Mon, 5 Aug 2013 18:14:00 +0000 (20:14 +0200)
appinfo/cpied.lsm
doc/cpied/readthis.txt
source/cpied/CPIED.CPP

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