home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lpr32.zip / lpr32.c.ori < prev    next >
Text File  |  2001-05-28  |  27KB  |  873 lines

  1. #define  LINT_ARGS                     /* argument checking enabled          */
  2.  
  3. #define  INCL_DOS
  4. #define  INCL_GPI
  5. #undef   INCL_GPI
  6. #define  INCL_DEV
  7. #define  INCL_DOSMEMMGR                /* Include standard OS/2 support      */
  8. #define  INCL_DOSMODULEMGR             /* For DosLoadModule                  */
  9. #define  INCL_DOSPROCESS
  10. #define  INCL_GPILCIDS
  11. #define  INCL_WINCOMMON                /* Include Window Management support  */
  12. #define  INCL_WINDOWMGR
  13. #define  INCL_WINSWITCHLIST
  14. #define  INCL_WINPROGRAMLIST
  15. #define  INCL_WINMENUS
  16. #define  INCL_WINWINDOWMGR
  17. #define  INCL_WINMESSAGEMGR
  18. #define  INCL_WINDIALOGS
  19. #define  INCL_WINSTATICS
  20. #define  INCL_WINLISTBOXES
  21. #define  INCL_WINMENUS
  22. #define  INCL_WINSYS
  23. #define  INCL_WINFRAMEMGR
  24. #define  INCL_INCLWINACCELERATORS
  25. #define  INCL_WINPOINTERS
  26. #define  INCL_WINERRORS
  27. #define  INCL_WINSHELLDATA
  28.  
  29. #define  INCL_WINTYPES
  30. #define  INCL_WINACCELERATORS
  31. #define  INCL_WINBUTTONS
  32. #define  INCL_WINENTRYFIELDS
  33. #define  INCL_WINRECTANGLES
  34. #define  INCL_WINTIMER
  35. #define  INCL_WINSCROLLBARS
  36. #define  INCL_WINHEAP
  37. #define  INCL_SHLERRORS
  38. #define  INCL_WININPUT
  39. #define  INCL_WINHELP
  40. #define  INCL_WINSTDSPIN
  41.  
  42. #define  INCL_SPL
  43. #define  INCL_SPLP
  44. #define  INCL_SPLERRORS
  45. #define  INCL_SHLERRORS
  46. #define  INCL_DOSERRORS
  47. #define  INCL_WINHOOKS
  48.  
  49. int acrtused=1;                      /* Define variable to say this is a DLL */
  50.  
  51. #include    <os2.h>
  52.  
  53. #include    <stdlib.h>
  54. #include    <string.h>
  55. #include    <ctype.h>
  56. #include    <stdarg.h>
  57. #include    <stdio.h>
  58. #include    <stdlib.h>
  59. #include    <process.h>
  60. #include    "lpr32.h"
  61.  
  62. //
  63. // If port driver is not defined in INI file yet
  64. //   assume it exists in the boot drive's \OS2\DLL directory
  65. //
  66.  
  67. CHAR szDefaultPortDrvPath[] = { PATH_LPR32_PDR };
  68.  
  69.  
  70. //
  71. // Below definition of PORTNAMES structure should be defined in
  72. // common header file pmspl.h.
  73. //
  74.  
  75. typedef struct _PORTNAMES
  76. {
  77.    PSZ pszPortName;         /* -> name of port(ie "LPT1)                    */
  78.    PSZ pszPortDesc;         /* -> description of port(ie "Parallel Port 1") */
  79. } PORTNAMES, *PPORTNAMES;
  80.  
  81. char * lprtok (char *string,char *control)
  82. {
  83.         unsigned char *str;
  84.         const unsigned char *ctrl = control;
  85.  
  86.         unsigned char map[32];
  87.         int count;
  88.  
  89.         static char *nextoken;
  90.  
  91.         for (count = 0; count < 32; count++)
  92.                 map[count] = 0;
  93.  
  94.         do {
  95.                 map[*ctrl >> 3] |= (1 << (*ctrl & 7));
  96.         } while (*ctrl++);
  97.  
  98.         if (string)
  99.                 str = string;
  100.         else
  101.                 str = nextoken;
  102.  
  103.         while ( (map[*str >> 3] & (1 << (*str & 7))) && *str )
  104.                 str++;
  105.  
  106.         string = str;
  107.  
  108.         for ( ; *str ; str++ )
  109.                 if ( map[*str >> 3] & (1 << (*str & 7)) ) {
  110.                         *str++ = '\0';
  111.                         break;
  112.                 }
  113.  
  114.         nextoken = str;
  115.  
  116.         /* Determine if a token has been found. */
  117.         if ( string == str )
  118.                 return NULL;
  119.         else
  120.                 return string;
  121. }
  122. MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 )
  123. {
  124.     PLPRDATA    pLprData;
  125.     ULONG       ulTimeOut = 0 ;
  126.     CHAR        szDesc[ STR_LEN_PORTDESC];
  127.     CHAR        szTitle[ STR_LEN_TITLE + 1];
  128.     CHAR        szTemp[ STR_LEN_PORTDESC ];
  129.     USHORT      i;
  130.     ULONG       rc = 0;
  131.     PUCHAR      token;
  132.  
  133.     switch (msg)
  134.      {
  135.         case WM_INITDLG:
  136.           WinSendDlgItemMsg(hDlg,ID_BINARY,BM_SETCHECK,MPFROM2SHORT(1,0),NULL);
  137.             pLprData = (PLPRDATA)mp2;
  138.             WinSetWindowULong (hDlg, QWL_USER, (ULONG)pLprData);
  139.             if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
  140.                                        pLprData->pszAppName,
  141.                                        KEY_DESCRIPTION,
  142.                                        NULL,
  143.                                        (PSZ)szDesc,
  144.                                        STR_LEN_PORTDESC))
  145.               {
  146.                  WinSetWindowText (WinWindowFromID (hDlg, (USHORT)IDD_LPR32),szDesc);
  147.                  rc = WinLoadString(pLprData->hAB,
  148.                                     pLprData->hModule,
  149.                                     PDR_ID_PROPERTIES,
  150.                                     STR_LEN_PORTDESC, szTemp);
  151.                  if (rc)
  152.                    {
  153.                      strcpy ( szTitle, pLprData->pszPortName );
  154.                      strcat ( szTitle, " - " );
  155.                      strcat ( szTitle, szTemp );
  156.                      WinSetWindowText (hDlg, szTitle);
  157.                    }
  158.               }
  159.             if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
  160.                                         pLprData->pszAppName,
  161.                                         KEY_INITIALIZATION,
  162.                                         NULL,
  163.                                         szTemp,
  164.                                         sizeof(szTemp)))
  165.                {
  166.                    i = 0;
  167.                    token = lprtok(szTemp,"#");
  168.                    while (token != NULL)
  169.                     {
  170.                        switch(i)
  171.                         {
  172.                            case 0:
  173.                                   WinSetDlgItemText(hDlg,ID_IP,token);
  174.                            case 1:
  175.                                   WinSetDlgItemText(hDlg,ID_LPDQUEUE,token);
  176.                                   break;
  177.                            case 2:
  178.                                   if (token[ strlen(token) - 1 ] == ';')
  179.                                     token[ strlen(token)-1 ] = '\0';
  180.                                   WinSetDlgItemText(hDlg,ID_SPOOL_PATH,token);
  181.                                   break;
  182.                         }
  183.                        i++;
  184.                        token = lprtok(NULL,"#");
  185.                     }
  186.                }
  187.             break;
  188.  
  189.         case WM_COMMAND:
  190.             pLprData = (PLPRDATA)WinQueryWindowULong (hDlg, QWL_USER);
  191.             switch (SHORT1FROMMP(mp1))
  192.              {
  193.                case DID_OK:
  194.                    WinQueryDlgItemText (hDlg, ID_IP, sizeof(szTemp), szTemp );
  195.                    sprintf(pLprData->szSaveLprSetting,"%s",szTemp);
  196.                    WinQueryDlgItemText (hDlg, ID_LPDQUEUE, sizeof(szTemp), szTemp );
  197.                    strcat(pLprData->szSaveLprSetting,"#");
  198.                    strcat(pLprData->szSaveLprSetting,szTemp);
  199.                    WinQueryDlgItemText (hDlg, ID_SPOOL_PATH, sizeof(szTemp), szTemp );
  200.                    strcat(pLprData->szSaveLprSetting,"#");
  201.                    strcat(pLprData->szSaveLprSetting,szTemp);
  202.                    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  203.                                                pLprData->pszAppName,
  204.                                                KEY_INITIALIZATION,
  205.                                                pLprData->szSaveLprSetting))
  206.                       WinDismissDlg(hDlg, MBID_CANCEL);
  207.  
  208.                   if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  209.                                               APPNAME_PM_SPOOLER_PORT,
  210.                                               pLprData->pszPortName,
  211.                                               pLprData->szSaveLprSetting))
  212.                      WinDismissDlg(hDlg, MBID_CANCEL);
  213.                   WinDismissDlg(hDlg, TRUE);
  214.                   break;
  215.                case DID_CANCEL:
  216.                   WinDismissDlg(hDlg, MBID_CANCEL);
  217.                   break;
  218.              }
  219.             break;
  220.         default:
  221.             return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
  222.             break;
  223.      }
  224.  return FALSE;
  225. }
  226. ULONG CalcStructLength ( HAB hab,
  227.                          HMODULE hModule,
  228.                          USHORT usID )
  229. {
  230.    ULONG cbRequired;
  231.    CHAR  chString[STR_LEN_PORTDESC];
  232.  
  233.    cbRequired = 0;
  234.  
  235.    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
  236.    cbRequired += strlen (chString) + 1;
  237.    WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
  238.    cbRequired += strlen (chString) + 1;
  239.    cbRequired += sizeof (PORTNAMES);
  240.    return(cbRequired);
  241. }
  242.  
  243. ULONG CalcBufLength ( HAB hab,
  244.                       HMODULE hModule )
  245. {
  246.    ULONG  cbRequired;
  247.    USHORT usID;
  248.  
  249.    cbRequired = 0;
  250.  
  251.       /*
  252.       ** calculate length required to fit all the port info.
  253.       */
  254.    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
  255.    {
  256.       cbRequired += CalcStructLength (hab, hModule, usID);
  257.    }
  258.  
  259.    return(cbRequired);
  260. }
  261.  
  262. ULONG NumPortsCanFit ( HAB hab,
  263.                        HMODULE hModule,
  264.                        ULONG cbBuf )
  265. {
  266.    ULONG  cbRequired;
  267.    USHORT usID;
  268.    ULONG  ulNumPort;
  269.  
  270.    cbRequired = 0;
  271.    ulNumPort = 0;
  272.  
  273.       /*
  274.       ** calculate how many ports we can fit in buf.
  275.       */
  276.    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
  277.    {
  278.       cbRequired += CalcStructLength (hab, hModule, usID);
  279.       if (cbRequired > cbBuf)
  280.       {
  281.          return(ulNumPort);
  282.       }
  283.       ulNumPort++;
  284.    }
  285.  
  286.    return(ulNumPort);
  287. }
  288. VOID CopyStruct ( HAB hab,
  289.                   HMODULE hModule,
  290.                   USHORT usID,
  291.                   PCH pBuf,
  292.                   PULONG pulBeginStruct,
  293.                   PULONG pulBeginText )
  294. {
  295.    PPORTNAMES pPortNames;
  296.  
  297.    pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
  298.    *pulBeginStruct += sizeof (PORTNAMES);
  299.  
  300.       /*
  301.       ** copy port name in the structure
  302.       */
  303.    pPortNames->pszPortName = pBuf + *pulBeginText;
  304.    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
  305.    *pulBeginText += strlen (pPortNames->pszPortName) + 1;
  306.  
  307.       /*
  308.       ** copy port description to the structure
  309.       */
  310.    pPortNames->pszPortDesc = pBuf + *pulBeginText;
  311.    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
  312.    *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
  313. }
  314. VOID  CopyNPorts ( HAB hab,
  315.                    HMODULE hModule,
  316.                    PCH pBuf,
  317.                    ULONG ulReturned )
  318. {
  319.    USHORT usID;
  320.    ULONG  ulBeginText;
  321.    ULONG  ulBeginStruct;
  322.  
  323.    ulBeginText = ulReturned * sizeof (PORTNAMES);
  324.    ulBeginStruct = 0;
  325.  
  326.    for (usID = PORT_ID_FIRST;
  327.         usID <= PORT_ID_LAST && ulReturned;
  328.         usID += 2, --ulReturned)
  329.    {
  330.       CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
  331.    }
  332. }
  333.  
  334. ULONG OpenLprPortDlg ( HAB hab,
  335.                        HMODULE hModule,
  336.                        PSZ pszPortName,
  337.                        PSZ pszAppName )
  338. {
  339.    LPRDATA LprData;
  340.  
  341.    memset (&LprData, 0, sizeof (LPRDATA));
  342.    LprData.hAB = hab;
  343.    LprData.hModule = hModule;
  344.    LprData.pszPortName = pszPortName;
  345.    LprData.pszAppName = pszAppName;
  346.  
  347.    WinDlgBox  (HWND_DESKTOP,
  348.                HWND_DESKTOP,
  349.                (PFNWP)CommDlg,
  350.                (HMODULE)hModule,
  351.                IDD_LPR32,
  352.                &LprData);
  353.  
  354.    return LprData.lfModified;
  355. }
  356. BOOL GetPortDescription ( HAB hab,
  357.                           HMODULE hModule,
  358.                           PSZ pszPortName,
  359.                           PSZ pszPortDesc )
  360. {
  361.    USHORT usID;
  362.    CHAR   chBuf[STR_LEN_PORTDESC];
  363.  
  364.    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
  365.    {
  366.       WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
  367.       if (!strcmp (pszPortName, chBuf))
  368.       {
  369.          strcpy (pszPortDesc, chBuf);
  370.          return(TRUE);
  371.       }
  372.    }
  373.    return(FALSE);
  374. }
  375. APIRET APIENTRY SplPdEnumPort ( HAB hab,
  376.                                 PVOID pBuf,
  377.                                 ULONG cbBuf,
  378.                                 PULONG pulReturned,
  379.                                 PULONG pulTotal,
  380.                                 PULONG pcbRequired )
  381.  
  382. {
  383.    HMODULE hModule;
  384.    ULONG   ulBootDrive;
  385.    ULONG   rcLoadMod;
  386.    CHAR    szPathName[260];
  387.  
  388.    if (!pulReturned ||
  389.        !pulTotal ||
  390.        !pcbRequired)
  391.    {
  392.       return(ERROR_INVALID_PARAMETER);
  393.    }
  394.  
  395.    if (!pBuf && cbBuf)
  396.    {
  397.       return(ERROR_INVALID_PARAMETER);
  398.    }
  399.  
  400.    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
  401.                     sizeof (ULONG));
  402.    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
  403.  
  404.    PrfQueryProfileString (HINI_SYSTEMPROFILE,
  405.                           "PM_PORT_DRIVER",
  406.                           "LPR32",
  407.                           szDefaultPortDrvPath,
  408.                           szPathName,
  409.                           256 );
  410.  
  411.    rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
  412.  
  413.    if (cbBuf == 0L)
  414.    {
  415.       *pulReturned = 0;
  416.       *pcbRequired = CalcBufLength (hab, hModule);
  417.       *pulTotal = 32;               /* Currently support LPRx x = 1 .. 9     */
  418.       if (!rcLoadMod)
  419.         DosFreeModule (hModule);
  420.         return(ERROR_MORE_DATA);
  421.    }
  422.  
  423.       /*
  424.       ** check number of ports info we can fit in supplied buffer
  425.       */
  426.    *pulTotal    = 32;               /* Currently support LPRx x= 1 .. 9      */
  427.    *pcbRequired = CalcBufLength (hab, hModule);
  428.    *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
  429.  
  430.       /*
  431.       ** return error if we can not fit one port.
  432.       */
  433.    if (!(*pulReturned))
  434.    {
  435.       if (!rcLoadMod)
  436.          DosFreeModule (hModule);
  437.       return(ERROR_INSUFFICIENT_BUFFER);
  438.    }
  439.  
  440.       /*
  441.       ** copy all the ports which we can store in the pBuf
  442.       */
  443.    CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
  444.  
  445.       /*
  446.       ** Free the module - we do not need it any more.
  447.       */
  448.    if (!rcLoadMod)
  449.      DosFreeModule (hModule);
  450.  
  451.       /*
  452.       ** copy all the ports which we can store in the pBuf
  453.       */
  454.    if (*pulReturned < *pulTotal)
  455.    {
  456.       return(ERROR_MORE_DATA);
  457.    }
  458.  
  459.    return(NO_ERROR);
  460. }
  461. APIRET APIENTRY SplPdInstallPort ( HAB hab,
  462.                                    PSZ pszPortName )
  463. {
  464.    CHAR    chBuf[STR_LEN_PORTNAME];
  465.    CHAR    chPortDesc[STR_LEN_PORTDESC];
  466.    ULONG   ulBootDrive;
  467.    HMODULE hModule;
  468.    CHAR    szPathName[260];    /* will contain full path to this port driver */
  469.  
  470.    if (!pszPortName)
  471.    {
  472.       return(ERROR_INVALID_PARAMETER);
  473.    }
  474.    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
  475.                     sizeof (ULONG));
  476.    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
  477.  
  478.    PrfQueryProfileString (HINI_SYSTEMPROFILE,
  479.                           "PM_PORT_DRIVER",
  480.                           "LPR32",
  481.                           szDefaultPortDrvPath,
  482.                           szPathName,
  483.                           256 );
  484.    hModule = 0L ;                             /* Init module handle to null */
  485.    DosLoadModule (NULL, 0, szPathName, &hModule);
  486.    if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
  487.    {
  488.       strcpy( chPortDesc, pszPortName );
  489.    }
  490.    DosFreeModule (hModule);
  491.    strcpy (chBuf, APPNAME_LEAD_STR);
  492.    strcat (chBuf, pszPortName);
  493.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  494.                                chBuf,
  495.                                KEY_DESCRIPTION,
  496.                                chPortDesc))
  497.    {
  498.       return (WinGetLastError (hab));
  499.    }
  500.  
  501.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  502.                                chBuf,
  503.                                KEY_INITIALIZATION,
  504.                                DEF_INITIALIZATION))
  505.    {
  506.       return (WinGetLastError (hab));
  507.    }
  508.  
  509.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  510.                                chBuf,
  511.                                KEY_TERMINATION,
  512.                                DEF_TERMINATION))
  513.    {
  514.       return (WinGetLastError (hab));
  515.    }
  516.  
  517.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  518.                                chBuf,
  519.                                KEY_PORTDRIVER,
  520.                                DEF_PORTDRIVER))
  521.    {
  522.       return (WinGetLastError (hab));
  523.    }
  524.  
  525.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  526.                                chBuf,
  527.                                KEY_TIMEOUT,
  528.                                DEF_TIMEOUT))
  529.    {
  530.       return (WinGetLastError (hab));
  531.    }
  532.    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
  533.                                APPNAME_PM_SPOOLER_PORT,
  534.                                pszPortName,
  535.                                DEF_INITIALIZATION))
  536.    {
  537.       return (WinGetLastError (hab));
  538.    }
  539.    return(NO_ERROR);
  540. }
  541. BOOL   APIENTRY SplPdGetPortIcon ( HAB hab,
  542.                                    PULONG idIcon )
  543. {
  544.    if (idIcon)
  545.    {
  546.       *idIcon = LPR32_ICON;
  547.    }
  548.    return(TRUE);
  549. }
  550. APIRET APIENTRY SplPdQueryPort ( HAB hab,
  551.                                  PSZ pszPortName,
  552.                                  PVOID pBufIn,
  553.                                  ULONG cbBuf,
  554.                                  PULONG cItems )
  555. {
  556.    HMODULE hModule;
  557.    CHAR    chString[STR_LEN_DESC];
  558.    USHORT  usNumLines;
  559.    USHORT  usLineID;
  560.    USHORT  usStrLength;
  561.    ULONG   ulBootDrive;
  562.    PCH     pBuf = pBufIn;
  563.    CHAR    szPathName[260];    /* will contain full path to this port driver */
  564.  
  565.    if (!cItems)
  566.    {
  567.       return(ERROR_INVALID_PARAMETER);
  568.    }
  569.  
  570.    if (!pBuf || !cbBuf)
  571.    {
  572.       return(ERROR_INVALID_PARAMETER);
  573.    }
  574.  
  575.  
  576.    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
  577.                     sizeof (ULONG));
  578.    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
  579.  
  580.    PrfQueryProfileString (HINI_SYSTEMPROFILE,
  581.                           "PM_PORT_DRIVER",
  582.                           "LPR32",
  583.                           szDefaultPortDrvPath,
  584.                           szPathName,
  585.                           256 );
  586.  
  587.    hModule = 0L ;
  588.  
  589.    DosLoadModule (NULL, 0, szPathName, &hModule);
  590.  
  591.    chString[0] = '\0' ;
  592.  
  593.    WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
  594.                  chString);
  595.    usNumLines = (USHORT)atoi (chString);
  596.    usLineID = ID_FIRST_DESC_LINES;
  597.    for (*cItems = 0; *cItems < usNumLines; *cItems++)
  598.    {
  599.       WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
  600.       if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
  601.       {
  602.          strcpy (pBuf, chString);
  603.          pBuf += usStrLength;
  604.          cbBuf -= usStrLength;
  605.       }
  606.       else
  607.       {
  608.          DosFreeModule (hModule);
  609.          return(ERROR_INSUFFICIENT_BUFFER);
  610.       }
  611.    }
  612.    DosFreeModule (hModule);
  613.    return(NO_ERROR);
  614. }
  615. APIRET APIENTRY SplPdSetPort ( HAB hab,
  616.                                PSZ pszPortName,
  617.                                PULONG flModified )
  618. {
  619.     CHAR    chBuf[STR_LEN_PORTNAME];
  620.     CHAR    chPortDriver[STR_LEN_PORTNAME];
  621.     ULONG   ulBootDrive;
  622.     HMODULE hModule;
  623.     CHAR    szPathName[260];   /* will contain full path to this port driver */
  624.  
  625.    if (!pszPortName || !flModified)
  626.    {
  627.       return(ERROR_INVALID_PARAMETER);
  628.    }
  629.  
  630.    strcpy (chBuf, APPNAME_LEAD_STR);
  631.    strcat (chBuf, pszPortName);
  632.  
  633.    if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
  634.                                 KEY_PORTDRIVER, NULL, chPortDriver,
  635.                                 STR_LEN_PORTNAME)))
  636.    {
  637.       return(ERROR_INVALID_PARAMETER);
  638.    }
  639.  
  640.    if (strcmp (chPortDriver, DEF_PORTDRIVER))
  641.    {
  642.       return(ERROR_INVALID_PARAMETER);
  643.    }
  644.  
  645.    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
  646.                     sizeof (ULONG));
  647.    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
  648.  
  649.    PrfQueryProfileString (HINI_SYSTEMPROFILE,
  650.                           "PM_PORT_DRIVER",
  651.                           "LPR32",
  652.                           szDefaultPortDrvPath,
  653.                           szPathName,
  654.                           256 );
  655.  
  656.    hModule = 0L ;                              /* Init module handle to null */
  657.  
  658.    DosLoadModule (NULL, 0, szPathName, &hModule);
  659.  
  660.    *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf);
  661.  
  662.    DosFreeModule (hModule);
  663.    return(NO_ERROR);
  664. }
  665.  
  666.  
  667. APIRET APIENTRY SplPdRemovePort ( HAB hab,
  668.                                   PSZ pszPortName )
  669. {
  670.     CHAR chBuf[STR_LEN_PORTNAME];
  671.     CHAR chPortDriver[STR_LEN_PORTNAME];
  672.  
  673.    if (!pszPortName)
  674.    {
  675.       return(ERROR_INVALID_PARAMETER);
  676.    }
  677.  
  678.    strcpy (chBuf, APPNAME_LEAD_STR);
  679.    strcat (chBuf, pszPortName);
  680.  
  681.    if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
  682.                                 KEY_PORTDRIVER, NULL, chPortDriver,
  683.                                 STR_LEN_PORTNAME)))
  684.    {
  685.       return(ERROR_INVALID_PARAMETER);
  686.    }
  687.  
  688.    if (strcmp (chPortDriver, DEF_PORTDRIVER))
  689.    {
  690.       return(ERROR_INVALID_PARAMETER);
  691.    }
  692.  
  693.    PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
  694.  
  695.    PrfWriteProfileString (HINI_SYSTEMPROFILE,
  696.                           APPNAME_PM_SPOOLER_PORT,
  697.                           pszPortName,
  698.                           NULL);
  699.    return(NO_ERROR);
  700.  
  701. }
  702. ULONG APIENTRY SplPdOpen( PSZ     pszPortName,
  703.                           PHFILE  phFile,
  704.                           PULONG  pDeviceFlags,
  705.                           PVOID   pPrtOpenStruct)
  706. {
  707.    APIRET rc;
  708.    ULONG  ulAction       = 0;      /* Action taken by DosOpen */
  709.    ULONG  ulBytesRead    = 0;      /* Number of bytes read by DosRead */
  710.    ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */
  711.    ULONG  ulLocal        = 0;      /* File pointer position after DosSetFilePtr */
  712.    CHAR   szTemp[ 256];
  713.    UCHAR  tmp[256];
  714.    ULONG  pcbWritten ;
  715.    USHORT  i;
  716.    HFILE   control;
  717.    UCHAR  filename[256];
  718.    DATETIME dt;
  719.  
  720.   if (!phFile || !pDeviceFlags )
  721.   {
  722.       return(ERROR_INVALID_PARAMETER);
  723.   }
  724.   DosGetDateTime(&dt);
  725.   sprintf(filename,"f:\\%02d_%02d_%02d_%02d",dt.hours,dt.minutes,dt.seconds,dt.hundredths);
  726.   rc = DosOpen(filename,
  727.                phFile,                         /* File handle */
  728.                &ulAction,                      /* Action taken */
  729.                100L,                           /* File primary allocation */
  730.                FILE_ARCHIVED | FILE_NORMAL,    /* File attribute */
  731.                OPEN_ACTION_CREATE_IF_NEW |
  732.                OPEN_ACTION_OPEN_IF_EXISTS,     /* Open function type */
  733.                OPEN_FLAGS_NOINHERIT |
  734.                OPEN_SHARE_DENYNONE  |
  735.                OPEN_ACCESS_READWRITE,          /* Open mode of the file */
  736.                0L);                            /* No extended attribute */
  737.   sprintf(szTemp,"PM_%s",pszPortName);
  738.   if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
  739.                              szTemp,
  740.                              KEY_INITIALIZATION,
  741.                              NULL,
  742.                              szTemp,
  743.                              sizeof(szTemp)))
  744.    {
  745.       sprintf(tmp   ,"f:\\%d.control",*phFile);
  746.       rc = DosOpen( tmp    ,
  747.                    &control,                         /* File handle */
  748.                    &ulAction,                      /* Action taken */
  749.                    strlen(szTemp),                /* File primary allocation */
  750.                    FILE_ARCHIVED | FILE_NORMAL,    /* File attribute */
  751.                    OPEN_ACTION_CREATE_IF_NEW |
  752.                    OPEN_ACTION_OPEN_IF_EXISTS,     /* Open function type */
  753.                    OPEN_FLAGS_NOINHERIT |
  754.                    OPEN_SHARE_DENYNONE  |
  755.                    OPEN_ACCESS_READWRITE,          /* Open mode of the file */
  756.                    0L);                            /* No extended attribute */
  757.      rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
  758.      rc = DosWrite( control,"#",1,&pcbWritten);
  759.      rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
  760.      rc = DosWrite( control,"@",1,&pcbWritten);
  761.      rc = DosClose(control);
  762.    }
  763.  return rc;
  764.  
  765. }
  766. ULONG  APIENTRY SplPdQuery ( PSZ    pszDeviceName,
  767.                              ULONG  ulFlags,
  768.                              ULONG  ulCommand,
  769.                              PVOID  pInData,
  770.                              ULONG  cbInData,
  771.                              PVOID  pOutData,
  772.                              PULONG pcbOutData )
  773. {
  774. /* return ERROR_NOT_SUPPORTED; */
  775.    return NO_ERROR;
  776. }
  777. ULONG  APIENTRY SplPdSet   ( PSZ    pszDeviceName,
  778.                              ULONG  ulFlags,
  779.                              ULONG  ulCommand,
  780.                              PVOID  pInData,
  781.                              ULONG  cbInData )
  782. {
  783. /* return ERROR_NOT_SUPPORTED; */
  784.    return NO_ERROR;
  785. }
  786. ULONG  APIENTRY SplPdNewPage ( HFILE  hFile, ULONG ulPageNumber )
  787. {
  788.     return NO_ERROR;
  789. }
  790. ULONG APIENTRY SplPdAbortDoc( HFILE   hFile,
  791.                               PVOID   pchData,
  792.                               ULONG   cbData,
  793.                               ULONG   ulFlags )
  794. {
  795.     return NO_ERROR;
  796. }
  797. ULONG  APIENTRY SplPdClose( HFILE  hFile )
  798. {
  799.    APIRET      rc;
  800.    USHORT      i;
  801.    USHORT      j;
  802.    RESULTCODES rc_child;
  803.    ULONG       nbr_lu;
  804.    ULONG       ulAction;
  805.    UCHAR       szTemp[256];
  806.    HFILE       control;
  807.    UCHAR       arg[256];
  808.    UCHAR       filename[256];
  809.    UCHAR       ip_add[256];
  810.    UCHAR       queue_name[256];
  811.    USHORT      pos;
  812.  
  813.    sprintf(szTemp,"f:\\%d.control",hFile);
  814.    rc = DosOpen(szTemp,
  815.                 &control,
  816.                 &ulAction,
  817.                 0L,
  818.                 FILE_ARCHIVED | FILE_NORMAL,
  819.                 OPEN_ACTION_CREATE_IF_NEW |
  820.                 OPEN_ACTION_OPEN_IF_EXISTS,
  821.                 OPEN_FLAGS_NOINHERIT |
  822.                 OPEN_SHARE_DENYNONE  |
  823.                 OPEN_ACCESS_READWRITE,
  824.                 0L);
  825.    rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);
  826.    rc = DosClose( control );
  827.    sprintf(filename,"f:\\%d.control",hFile);
  828.    DosDelete(filename);
  829.  
  830.    i = 0;
  831.    j = 0;
  832.    pos = 0;
  833.    while (szTemp[i] != '@')
  834.      {
  835.        if (szTemp[i] == '#')
  836.          {
  837.            szTemp[i] = '\0';
  838.            switch(j)
  839.             {
  840.                case 0:strcpy(ip_add,&szTemp[pos]);
  841.                       break;
  842.                case 1:strcpy(queue_name,&szTemp[pos]);
  843.                       break;
  844.                 }
  845.                pos = i+1;
  846.                j++;
  847.             }
  848.            i++;
  849.         }
  850.    szTemp[i] = '\0';
  851.    strcpy(filename,&szTemp[pos]);
  852.  
  853.    rc = DosClose( hFile );
  854.  
  855.    sprintf(arg,"d:\\tcpip\\bin\\lpr  -b -s %s -p %s %s",ip_add,queue_name,filename);
  856.    arg[17]  = '\0';
  857.  
  858.    rc = DosExecPgm(NULL,0,EXEC_SYNC,arg,NULL,&rc_child,"lpr.exe");
  859.    strcpy(filename,&szTemp[pos]);
  860.    DosDelete(filename);
  861.    return rc;
  862. }
  863. ULONG APIENTRY SplPdWrite( HFILE   hFile,
  864.                            PVOID   pchData,
  865.                            ULONG   cbData,
  866.                            PULONG  pcbWritten )
  867. {  APIRET rc;
  868.  
  869.    rc = DosWrite( hFile,pchData,cbData,pcbWritten);
  870.    rc = DosSleep(0);
  871.    return rc;
  872. }
  873.