home *** CD-ROM | disk | FTP | other *** search
/ Software Collection (I) / TOOLS.iso / b05 / 6.img / PSCRIPT / ATSTUFF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  8.6 KB  |  294 lines

  1. /**[f******************************************************************
  2.  * atstuff.c -
  3.  *
  4.  * Copyright (C) 1988 Aldus Corporation.  All rights reserved.
  5.  * Copyright (C) 1989 Microsoft Corporation.
  6.  * Company confidential.
  7.  *
  8.  **f]*****************************************************************/
  9.  
  10. #include "pscript.h"
  11. #include <winexp.h>
  12. #include "pserrors.h"
  13. #include "debug.h"
  14. #include "atprocs.h"
  15. #include "atstuff.h"
  16. #include "psdata.h"
  17. #include "resource.h"
  18. #include "utils.h"
  19.  
  20. /************************** global data ************************************/
  21.  
  22. BOOL    (FAR PASCAL *lpfnATSelect)(HWND);
  23. void    (FAR PASCAL *lpfnATMessage)(short,WORD,LPSTR);
  24. BOOL    (FAR PASCAL *lpfnATOpenStatusWnd)(HWND);
  25. void    (FAR PASCAL *lpfnATCloseStatusWnd)(void);
  26. short   (FAR PASCAL *lpfnATWrite)(LPSTR, short);
  27. short   (FAR PASCAL *lpfnATClose)(void);
  28. short   (FAR PASCAL *lpfnATSendEOF)(void);
  29. BOOL    (FAR PASCAL *lpfnATChooser)(HWND);
  30. HANDLE  (FAR PASCAL *lpfnATOpen)(LPSTR, LPSTR, HDC);
  31.  
  32. HWND ghATModule = NULL;         /* module handle for AppleTalk DLL */
  33.  
  34.  
  35. /**************************** local functins ***************************/
  36.  
  37. void    PASCAL FixFile(LPSTR,LPSTR,short);
  38. BOOL    PASCAL GetATModName(HANDLE,LPSTR,short);
  39.  
  40.  
  41.  
  42. /**************************** local data ********************************/
  43.  
  44. BOOL gfAT = FALSE;
  45.  
  46.  
  47. #define SIZE 40
  48.  
  49.  
  50. /* ATQuery()
  51.  *
  52.  * check to see if lpFile is "AppleTalk".  Sets global AT flag
  53.  * to enable AppleTalk module loading and output.
  54.  */
  55.  
  56. BOOL FAR PASCAL ATQuery(LPSTR lpFile)
  57. {
  58.         char idsAppleTalk[SIZE];
  59.  
  60.         LoadString(ghInst,IDS_APPLETALK,idsAppleTalk,sizeof(idsAppleTalk));
  61.  
  62.         if (lstrcmpi(idsAppleTalk, lpFile))
  63.                 gfAT = FALSE;           /* not apple talk */
  64.         else
  65.                 gfAT = TRUE;            /* on apple talk */
  66.  
  67.         return(gfAT);
  68. }
  69.  
  70.  
  71. /* allows AppleTalk to be turned off or on */
  72.  
  73. void FAR PASCAL ATChangeState(fValue)
  74.         BOOL fValue;
  75. {
  76.         gfAT=fValue;
  77. }
  78.  
  79.  
  80. /* disables appletalk if lpFileName is something other than AppleTalk
  81.  *
  82.  * returns TRUE if appletalk was bypassed (and should be turned back on
  83.  * when done) */
  84.  
  85. BOOL FAR PASCAL ATBypass(lpFileName)
  86.         LPSTR lpFileName;
  87. {
  88.         BOOL    fBypass = FALSE;
  89.         char    tempString[SIZE];
  90.  
  91.         DBMSG((">ATBypass(): %d\n",ATState()));
  92.  
  93.         if (ATState()) {
  94.                 LoadString(ghInst, IDS_APPLETALK, tempString, sizeof(tempString));
  95.  
  96.                 DBMSG((">ATBypass(): %ls,%ls\n",lpFileName,(LPSTR)tempString));
  97.  
  98.                 if (lstrcmpi(tempString, lpFileName)) {
  99.                         ATChangeState(FALSE);
  100.                         fBypass = TRUE;
  101.                 }
  102.         }
  103.         DBMSG((">ATBypass(): bypass=%d\n",fBypass));
  104.         return fBypass;
  105. }
  106.  
  107.  
  108. void PASCAL FixFile(lpS,lpExt,lenS)
  109.         LPSTR lpS;
  110.         LPSTR lpExt;
  111.         short lenS;
  112. {
  113.         LPSTR lpTemp=lpS;
  114.         BOOL fDot=FALSE;
  115.  
  116.         /* if the path does not have an extension, add the extension requested */
  117.         while(*lpTemp){
  118.                 if(*lpTemp=='.'){
  119.                         fDot=TRUE;
  120.                         break;
  121.                 }
  122.                 lpTmp = AnsiNext(lpTmp);
  123.  
  124.         }
  125.         DBMSG(((LPSTR)" FixFile(): fDot=%d,path=%ls,ext=%ls\n", fDot,lpS,lpExt));
  126.         if(!fDot) lstrncat(lpS,lpExt,lenS);
  127. }
  128.  
  129.  
  130. BOOL PASCAL GetATModName(hInst,lpPathString,sizeofPathString)
  131.         HANDLE hInst;
  132.         LPSTR lpPathString;
  133.         short sizeofPathString;
  134. {
  135.         char tempString[13];
  136.         LPSTR lpLastSep, lpStr;
  137.  
  138.  
  139. !!!  Warning !!!  this code won't work because we must
  140. obtain and pass the name of the printer model to SetKey.
  141. SetKey now requires both the model name and port.
  142.  
  143.         GetProfileStringFromResource(IDS_APPLETALK,1/*use key*/,
  144.                 IDS_ATMODULEFILE,IDS_DEFAULT_ATFILE,lpPathString,
  145.                 sizeofPathString);
  146.         DBMSG((">GetATModName(): path=%ls\n",lpPathString));
  147.  
  148.         /* If there is no path available from the WIN.INI use the path
  149.          * of the PSCRIPT module.
  150.          */
  151.         if(lpPathString[0]==':'){
  152.                 DBMSG(((LPSTR)" GetATModName(): DEFAULT AT path\n"));
  153.                 /* if the PSCRIPT module file name cannot be gotten...ERROR */
  154.                 if(!GetModuleFileName(hInst,lpPathString,sizeofPathString)){
  155.                         goto ERR;
  156.                 }
  157.                 DBMSG(((LPSTR)" GetATModName(): DEFAULT AT path=%ls\n",lpPathString));
  158.  
  159.                 LoadString(hInst,IDS_DEFAULT_ATMODNAME,(LPSTR)tempString,
  160.                         sizeof(tempString));
  161.                 DBMSG(((LPSTR)" GetATModName(): mod=%ls\n",(LPSTR)tempString));
  162.  
  163.                 /* find the end of the "path" portion of the file string */
  164.                 lpLastSep = NULL;
  165.                 for (lpStr = lpPathString; *lpStr; lpStr = AnsiNext(lpStr)) {
  166.                     if (*lpStr == '\\' || *lpStr == ':')
  167.                         lpLastSep = lpStr;
  168.                 }
  169.  
  170.                 lpStr = lpLastSep ? AnsiNext(lpLastSep) : lpPathString;
  171.                 *lpStr = '\0';
  172.  
  173.                 if((lstrlen(lpPathString)+lstrlen((LPSTR)tempString))
  174.                         > sizeofPathString
  175.                 ){
  176.                         goto ERR;
  177.                 };
  178.                 lstrcpy(lpStr,(LPSTR)tempString);
  179.                 DBMSG(((LPSTR)" GetATModName(): path=%ls\n",lpPathString));
  180.         }else{
  181.                 DBMSG(((LPSTR)" GetATModName(): WIN.INI AT path=%ls\n",lpPathString));
  182.                 FixFile(lpPathString,(LPSTR)".dll",sizeofPathString);
  183.                 DBMSG(((LPSTR)" GetATModName(): path=%ls\n",lpPathString));
  184.         }
  185.         return TRUE;
  186.  
  187. ERR:
  188.         return FALSE;
  189. }
  190.  
  191.  
  192. BOOL FAR PASCAL LoadAT()
  193. {
  194.         char buf[100];
  195.  
  196.         DBMSG((">LoadAT()\n"));
  197.  
  198.         if (ghATModule >= 32)
  199.                 return TRUE;    /* already loaded */
  200.  
  201.         if (!GetATModName(ghInst, buf, sizeof(buf))){
  202.                 return FALSE;
  203.         }
  204.  
  205.         if ((ghATModule = LoadLibrary(buf)) < 32) {
  206.                 ghATModule=0;
  207.                 return FALSE;
  208.         }
  209.  
  210.         if (!(lpfnATSelect=GetProcAddress(ghATModule,"ATSelect"))                 ||
  211.             !(lpfnATMessage=GetProcAddress(ghATModule,"ATMessage"))               ||
  212.             !(lpfnATOpenStatusWnd=GetProcAddress(ghATModule,"ATOpenStatusWnd"))   ||
  213.             !(lpfnATCloseStatusWnd=GetProcAddress(ghATModule,"ATCloseStatusWnd")) ||
  214.             !(lpfnATOpen=GetProcAddress(ghATModule,"ATOpen"))                   ||
  215.             !(lpfnATWrite=GetProcAddress(ghATModule,"ATWrite"))                 ||
  216.             !(lpfnATClose=GetProcAddress(ghATModule,"ATClose"))                 ||
  217.             !(lpfnATSendEOF=GetProcAddress(ghATModule,"ATSendEOF"))             ||
  218.             !(lpfnATChooser=GetProcAddress(ghATModule,"ATChooser"))) {
  219.  
  220.                 DBMSG(("GetProcAddresses failed\n"));
  221.                 FreeLibrary(ghATModule);
  222.                 return FALSE;
  223.         }
  224.  
  225.         DBMSG(("<LoadAT()\n"));
  226.         return TRUE;
  227. }
  228.  
  229.  
  230. void FAR PASCAL UnloadAT()
  231. {
  232.         if (ghATModule) {
  233.                 FreeLibrary(ghATModule);
  234.                 ghATModule=0;
  235.         }
  236. }
  237.  
  238.  
  239.  
  240. #define GW_OWNER            4
  241. HWND FAR PASCAL GetWindow(HWND, WORD);
  242.  
  243.  
  244. /* check if on AppleTalk and if so
  245.  * put up dialogs
  246.  *
  247.  * returns:
  248.  *      0       not on apple talk
  249.  *      1       user pressed cancel (abort printing)
  250.  *      -1      failed to load apple talk module
  251.  */
  252.  
  253. short FAR PASCAL TryAT()
  254. {
  255.         HWND hWnd;
  256.  
  257.         DBMSG((">TryAT()\n"));
  258.  
  259.         if (ATState()) {        /* don't try unless we are on AppleTalk */
  260.  
  261.                 /* find the top level window */
  262.  
  263.                 hWnd = GetFocus();
  264.  
  265.                 /* bring up the current selections and display the status box */
  266.                 if (!LoadAT()) {
  267.                         DBMSG(("module load failed\n"));
  268.                         return(-1);     /* failed to load */
  269.                 }
  270.  
  271.                 if (!ATSelect(hWnd)) {
  272.                         DBMSG(("user abort\n"));
  273.                         return(1);      /* user abort */
  274.                 }
  275.  
  276.                 if (!ATOpenStatusWnd(hWnd)) {
  277.                         DBMSG(("open status failed\n"));
  278.                         return(-1);     /* couldn't load status wnd */
  279.                 }
  280.         }
  281.         DBMSG(("<TryAT()\n"));
  282.         return 0;                       /* everything ok */
  283. }
  284.  
  285.  
  286. void FAR PASCAL KillAT()
  287. {
  288.         if(ATState()){
  289.                 if (ghATModule)
  290.                         ATCloseStatusWnd();
  291.                 UnloadAT();
  292.         }
  293. }
  294.