| 1 | #define INCL_DOS | 
|---|
| 2 | #include <os2.h> | 
|---|
| 3 | #include <stdio.h> | 
|---|
| 4 | #include <string.h> | 
|---|
| 5 | #include    "pdfdebug.h" | 
|---|
| 6 | #include "gsdll.h" | 
|---|
| 7 |  | 
|---|
| 8 | PFN_gsdll_init pgsdll_init; | 
|---|
| 9 | PFN_gsdll_revision pgsdll_revision; | 
|---|
| 10 | PFN_gsdll_execute_begin pgsdll_execute_begin; | 
|---|
| 11 | PFN_gsdll_execute_cont pgsdll_execute_cont; | 
|---|
| 12 | PFN_gsdll_execute_end pgsdll_execute_end; | 
|---|
| 13 | PFN_gsdll_exit pgsdll_exit; | 
|---|
| 14 | int _System gsdll_callback(int message, char *str, unsigned long count); | 
|---|
| 15 |  | 
|---|
| 16 | VOID    DE (PCH str); | 
|---|
| 17 |  | 
|---|
| 18 | FILE *logfile; | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | /**************************************************************************** | 
|---|
| 22 | * | 
|---|
| 23 | * FUNCTION NAME = RunGhostScript | 
|---|
| 24 | * | 
|---|
| 25 | * DESCRIPTION   = Runs GhostScript command | 
|---|
| 26 | * | 
|---|
| 27 | * INPUT         = command       - invocation command for GhostScript | 
|---|
| 28 | *                 parameters    - parameters to GhostScript | 
|---|
| 29 | * | 
|---|
| 30 | * OUTPUT        = true if okay false if not | 
|---|
| 31 | * | 
|---|
| 32 | * REMARKS       = This function is taken out of SPLPDClose for the purpose | 
|---|
| 33 | *                 of easy transistion to GS.DLL call interface in future | 
|---|
| 34 | *                 releases | 
|---|
| 35 | * | 
|---|
| 36 | ****************************************************************************/ | 
|---|
| 37 | //BOOL    RunGhostScript(char *command,char *parameters[],int numparms) | 
|---|
| 38 | BOOL    RunGhostScript(char *command,char *parameters,int numparms) | 
|---|
| 39 | { | 
|---|
| 40 | UCHAR LoadError[CCHMAXPATH] = {0}; | 
|---|
| 41 | ULONG rc2,action; | 
|---|
| 42 | RESULTCODES rc; | 
|---|
| 43 | char Temp[256]; | 
|---|
| 44 | //PmPrintf("%s - %s",parameters,parameters[7]); | 
|---|
| 45 | rc2 = DosExecPgm(LoadError,sizeof(LoadError),0,parameters,0,&rc,command); | 
|---|
| 46 | if(rc2!=0) | 
|---|
| 47 | DE("Probably not Able to find GSOS2.EXE\nplease verify the settings of\nthe port driver"); | 
|---|
| 48 | if (rc.codeResult!=0) | 
|---|
| 49 | { | 
|---|
| 50 | sprintf(Temp,"Error in GhostScript processing, code:%d - %s",rc.codeResult,LoadError); | 
|---|
| 51 | DE(Temp); | 
|---|
| 52 | return rc.codeResult; | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | return 0; | 
|---|
| 56 | /*int code; | 
|---|
| 57 | HMODULE hmodule_gsdll; | 
|---|
| 58 | char buf[256]; | 
|---|
| 59 | char *product,*copyright; | 
|---|
| 60 | long een,twee; | 
|---|
| 61 | APIRET rc; | 
|---|
| 62 | char *parsedParms[256]; | 
|---|
| 63 | int iNumWords; | 
|---|
| 64 | PSZ pszPos,pszPosEnd; | 
|---|
| 65 |  | 
|---|
| 66 | char *testparms[] = {"gsos2.exe", | 
|---|
| 67 | "-Ie:\\gs\\gs8.00\\lib;e:\\gs\gs8.00\\..\\fonts;c:\\psfonts", | 
|---|
| 68 | "-dBATCH", | 
|---|
| 69 | "-dNOPAUSE", | 
|---|
| 70 | "-dNOPLATFONTS", | 
|---|
| 71 | "-sFONTPATH=c:\\psfonts", | 
|---|
| 72 | "-sDEVICE=pdfwrite", | 
|---|
| 73 | "-dPDFSETTINGS=/screen", | 
|---|
| 74 | "-dEmbedAllFonts=true", | 
|---|
| 75 | "-sOutputFile=e:\\testpdfs\\test2.pdf", | 
|---|
| 76 | "e:\\tmp\\pmpdf.ps", | 
|---|
| 77 | NULL}; | 
|---|
| 78 |  | 
|---|
| 79 | _PmpfF(("in: %s",command)); | 
|---|
| 80 |  | 
|---|
| 81 | if (!DosLoadModule(buf, sizeof(buf), command, &hmodule_gsdll)) { | 
|---|
| 82 | _PmpfF(("Loaded DLL")); | 
|---|
| 83 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_INIT", (PFN *)(&pgsdll_init)); | 
|---|
| 84 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_REVISION", (PFN*)&pgsdll_revision); | 
|---|
| 85 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_EXECUTE_BEGIN", (PFN *)(&pgsdll_execute_begin)); | 
|---|
| 86 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_EXECUTE_CONT", (PFN *)(&pgsdll_execute_cont)); | 
|---|
| 87 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_EXECUTE_END", (PFN *)(&pgsdll_execute_end)); | 
|---|
| 88 | DosQueryProcAddr(hmodule_gsdll, 0, "GSDLL_EXIT", (PFN *)(&pgsdll_exit)); | 
|---|
| 89 | _PmpfF(("Resolved Imports")); | 
|---|
| 90 | } | 
|---|
| 91 | else { | 
|---|
| 92 | _PmpfF(("Can't load GSDLL2")); | 
|---|
| 93 | return(FALSE); | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | pszPos = strchr(parameters,' ') +1; | 
|---|
| 98 | pszPos = strchr(pszPos,' ') +1; | 
|---|
| 99 | iNumWords=0; | 
|---|
| 100 | while(pszPos !=NULL) | 
|---|
| 101 | { | 
|---|
| 102 |  | 
|---|
| 103 | pszPosEnd= strchr(pszPos,' '); | 
|---|
| 104 | if(pszPosEnd!=NULL) | 
|---|
| 105 | { | 
|---|
| 106 | *pszPosEnd ='\0'; | 
|---|
| 107 | PmpfF(("%d: %s,%s",iNumWords,pszPos,pszPosEnd+1)); | 
|---|
| 108 | parsedParms[iNumWords] = pszPos; | 
|---|
| 109 | pszPos=pszPosEnd+1; | 
|---|
| 110 | iNumWords++; | 
|---|
| 111 | } | 
|---|
| 112 | else | 
|---|
| 113 | { | 
|---|
| 114 | pszPos=NULL; | 
|---|
| 115 | iNumWords++; | 
|---|
| 116 | parsedParms[iNumWords]=NULL; | 
|---|
| 117 |  | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | iNumWords=11; | 
|---|
| 123 | for(een=0;een <iNumWords;een++) | 
|---|
| 124 | if(testparms[een]==NULL) | 
|---|
| 125 | PmpfF(("%d: NULL",een)); | 
|---|
| 126 | else | 
|---|
| 127 | PmpfF(("%d: %s",een,testparms[een])); | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | code = (*pgsdll_revision)(&product,©right, &een, &twee); | 
|---|
| 131 |  | 
|---|
| 132 | _PmpfF(("gsdll_revision returns %d,%s,%s,%d,%d\n", code,product,copyright,een,twee)); | 
|---|
| 133 |  | 
|---|
| 134 | code = (*pgsdll_init)(gsdll_callback, 0, 11, testparms); | 
|---|
| 135 | _PmpfF(("gsdll_init returns %d\n", code)); | 
|---|
| 136 | if(code!=0) | 
|---|
| 137 | _PmpfF(("gsdll_init returns %d\n", code)); | 
|---|
| 138 | code = (*pgsdll_execute_begin)(); | 
|---|
| 139 | if(code!=0) | 
|---|
| 140 | _PmpfF(("\ngsdll_execute returns %d\n", code)); | 
|---|
| 141 | if (code==0) { | 
|---|
| 142 | while (fgets(buf, sizeof(buf), stdin)) { | 
|---|
| 143 | code = (*pgsdll_execute_cont)(buf, strlen(buf)); | 
|---|
| 144 | _PmpfF(("gsdll_execute returns %d\n", code)); | 
|---|
| 145 | if (code < 0) | 
|---|
| 146 | break; | 
|---|
| 147 | } | 
|---|
| 148 | if (!code) | 
|---|
| 149 | { | 
|---|
| 150 | code = (*pgsdll_execute_end)(); | 
|---|
| 151 | if(code!=0) | 
|---|
| 152 | _PmpfF(("\ngsdll_execute_end returns %d\n", code)); | 
|---|
| 153 | } | 
|---|
| 154 | code = (*pgsdll_exit)(); | 
|---|
| 155 | if(code!=0) | 
|---|
| 156 | _PmpfF(("gsdll_exit returns %d\n", code)); | 
|---|
| 157 | } | 
|---|
| 158 | rc = DosFreeModule(hmodule_gsdll); | 
|---|
| 159 | if(rc!=0) | 
|---|
| 160 | _PmpfF(("DosFreeModule returns %d\n", rc)); | 
|---|
| 161 |  | 
|---|
| 162 |  | 
|---|
| 163 | _PmpfF(("uit")); | 
|---|
| 164 | return 0;*/ | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 | int _System gsdll_callback(int message, char *str, unsigned long count) | 
|---|
| 168 | { | 
|---|
| 169 | char *p; | 
|---|
| 170 | switch (message) { | 
|---|
| 171 | case GSDLL_STDIN: | 
|---|
| 172 | p = fgets(str, count, stdin); | 
|---|
| 173 | if (p) | 
|---|
| 174 | return strlen(str); | 
|---|
| 175 | else | 
|---|
| 176 | return 0; | 
|---|
| 177 | case GSDLL_STDOUT: | 
|---|
| 178 | if (str != (char *)NULL) | 
|---|
| 179 | { | 
|---|
| 180 | str[count]='\0'; | 
|---|
| 181 | _PmpfF(("stdout: %s",str)); | 
|---|
| 182 | } | 
|---|
| 183 | //fwrite(str, 1, count, logfile); | 
|---|
| 184 | return count; | 
|---|
| 185 | case GSDLL_DEVICE: | 
|---|
| 186 | _PmpfF(("Callback: DEVICE %p %s\n", str, | 
|---|
| 187 | count ? "open" : "close")); | 
|---|
| 188 | break; | 
|---|
| 189 | case GSDLL_SYNC: | 
|---|
| 190 | _PmpfF(("Callback: SYNC %p\n", str)); | 
|---|
| 191 | break; | 
|---|
| 192 | case GSDLL_PAGE: | 
|---|
| 193 | _PmpfF(("Callback: PAGE %p\n", str)); | 
|---|
| 194 | break; | 
|---|
| 195 | case GSDLL_SIZE: | 
|---|
| 196 | _PmpfF(("Callback: SIZE %p width=%d height=%d\n", str, | 
|---|
| 197 | (int)(count & 0xffff), (int)((count>>16) & 0xffff) )); | 
|---|
| 198 | break; | 
|---|
| 199 | case GSDLL_POLL: | 
|---|
| 200 | return 0; /* no error */ | 
|---|
| 201 | default: | 
|---|
| 202 | _PmpfF(("\nCallback: Unknown message=%d,%s,%d\n",message,str,count)); | 
|---|
| 203 | break; | 
|---|
| 204 | } | 
|---|
| 205 | return 0; | 
|---|
| 206 | } | 
|---|