lptinfo.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:7k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /*********************************************************************
  2.  * Microsoft Diagnostics Version 2.0
  3.  *
  4.  * A diagnostic utility to detect as much useful information about a
  5.  *   customer's computer system as is possible.
  6.  *
  7.  * Microsoft Diagnostics:  We detect the World.
  8.  *
  9.  * LPTINFO.C - Source file for parallel printer port detection code.
  10.  ********************************************************************/
  11. /* Include Files */
  12. #include "msd.h"
  13. /*********************************************************************
  14.  * GetLptInfo - Gets the LPT port information.
  15.  *
  16.  * Returns:  TRUE if an error occured.
  17.  *********************************************************************/
  18. BOOL GetLptInfo (LPT_STRUCT *pLpt, BOOL fMinimumInfo)
  19. {
  20.   WORD i;                           /* Looping variable    */
  21.   WORD wLptStatus[MAX_LPT_PORTS];   /* Printer port status */
  22.   {
  23.     /* Zero out the count of LPT ports */
  24.     pLpt->wNmbrLptPorts = 0;
  25.     /* Count the number of LPT ports in the system */
  26.     for (i = 0; i < MAX_LPT_PORTS; i++)
  27.       {
  28.         wLptStatus[i] = _bios_printer (_PRINTER_STATUS, i, 0);
  29.         if (!(wLptStatus[i] & 6))
  30.           ++(pLpt->wNmbrLptPorts);
  31.       }
  32.     if (fMinimumInfo)
  33.       return (FALSE);
  34.   }
  35.   {
  36.     /* Set the values in the structure for each port */
  37.     /* 40:8 is the port address of the first valid LPT port */
  38.     WORD FAR * fwPortAddress = (WORD FAR *) 0x00400008;
  39.     for (i = 0; i < MAX_LPT_PORTS; i++)
  40.       {
  41.         pLpt->LptxInfo[i].fLptPortDetected
  42.                                     = (wLptStatus[i] & 0x06) ? FALSE : TRUE;
  43.         pLpt->LptxInfo[i].wPortAddress
  44.                                     = *(fwPortAddress++);
  45.         pLpt->LptxInfo[i].fOnLine   = (wLptStatus[i] & 0x10) ? TRUE  : FALSE;
  46.         pLpt->LptxInfo[i].fPaperOut = (wLptStatus[i] & 0x20) ? TRUE  : FALSE;
  47.         pLpt->LptxInfo[i].fIoError  = (wLptStatus[i] & 0x08) ? TRUE  : FALSE;
  48.         pLpt->LptxInfo[i].fTimeOut  = (wLptStatus[i] & 0x01) ? TRUE  : FALSE;
  49.         pLpt->LptxInfo[i].fBusy     = (wLptStatus[i] & 0x80) ? FALSE : TRUE;
  50.         pLpt->LptxInfo[i].fAck      = (wLptStatus[i] & 0x40) ? TRUE  : FALSE;
  51.       }
  52.   }
  53.   return (FALSE);
  54. }
  55. /*********************************************************************
  56.  * SprintLptInfo - Put LPT port information into a set of strings to
  57.  *                 be printed or displayed.
  58.  *
  59.  * Returns:  NULL if an error occured.
  60.  *********************************************************************/
  61. QSZ * SprintLptInfo (LPT_STRUCT *pLpt,
  62.                      CHAR szSumStrings[][MAX_SUMM_INFO + 5])
  63. {
  64.   WORD wNmbrStrings;        /* Number of strings                     */
  65.   WORD wNmbrChars;          /* Number of characters in the strings   */
  66.   WORD wUnderlineLength;    /* Length of the underline string        */
  67.   WORD wLptIndex;           /* Index to the structure of LPT data    */
  68.   WORD i;                   /* Looping variables                     */
  69.   QSZ  *pqszStrings = NULL; /* Location for storing string pointers  */
  70.   /* Summary information */
  71.   if (szSumStrings != NULL)
  72.     {
  73.       sprintf (szSumStrings[0], "%d", pLpt->wNmbrLptPorts);
  74.       return (NULL);
  75.     }
  76.   /* Calculate the amount of space required for the strings */
  77.   wUnderlineLength = strlen (pszLptUnderline);
  78.   wNmbrChars   = strlen (pszLptHeader1) + 1 +
  79.                  strlen (pszLptHeader2) + 1 +
  80.                  wUnderlineLength       + 1 +
  81.                  (MAX_LPT_PORTS * (wUnderlineLength + 1));
  82.   /* The underline string is expected to be as long as a line of */
  83.   /*   LPT port info.                                            */
  84.   wNmbrStrings = MAX_LPT_PORTS + 4;
  85.   /* "+ 4" is for the 2 header lines, the underline, and the NULL */
  86.   /*   pointer at the end of the array.                           */
  87.   /* Allocate space for the pointer area and string area */
  88.   pqszStrings = AllocStringSpace (wNmbrStrings, wNmbrChars);
  89.   if (pqszStrings == NULL)
  90.     return (NULL);
  91.   /* Put the first three strings in place */
  92.   Qstrcpy (pqszStrings[0], pszLptHeader1);
  93.   pqszStrings[1] = pqszStrings[0] + Qstrlen (pqszStrings[0]) + 1;
  94.   Qstrcpy (pqszStrings[1], pszLptHeader2);
  95.   pqszStrings[2] = pqszStrings[1] + Qstrlen (pqszStrings[1]) + 1;
  96.   Qstrcpy (pqszStrings[2], pszLptUnderline);
  97.   pqszStrings[3] = pqszStrings[2] + wUnderlineLength + 1;
  98.   /* Put the LPT port information in place */
  99.   for (i = 3, wLptIndex = 0; wLptIndex < MAX_LPT_PORTS;
  100.        ++i, ++wLptIndex)
  101.     {
  102.       WORD wLength;       /* Current length of string */
  103.       CHAR chBuffer[80];  /* Buffer for string data   */
  104.       /* Clear out the string */
  105.       Qmemset (pqszStrings[i], ' ', wUnderlineLength);
  106.       /* Port */
  107.       wLength = sprintf (chBuffer, "LPT%d:", wLptIndex + 1);
  108.       Qstrncpy (&pqszStrings[i][LPT_PORT_COL], chBuffer, wLength);
  109.       if (pLpt->LptxInfo[wLptIndex].fLptPortDetected)
  110.         {
  111.           PSZ pszString = NULL;  /* Pointer to a string */
  112.           /* Port Address */
  113.           wLength = sprintf (chBuffer, "%04XH",
  114.                              pLpt->LptxInfo[wLptIndex].wPortAddress);
  115.           Qstrncpy (&pqszStrings[i][LPT_PORT_ADDR_COL], chBuffer, wLength);
  116.           /* Online */
  117.           pszString = (pLpt->LptxInfo[wLptIndex].fOnLine) ?
  118.                       pszYes : pszNo_;
  119.           Qstrncpy (&pqszStrings[i][LPT_ON_LINE_COL], pszString,
  120.                    Qstrlen (pszString));
  121.           /* Paper Out */
  122.           pszString = (pLpt->LptxInfo[wLptIndex].fPaperOut) ?
  123.                       pszYes : pszNo_;
  124.           Qstrncpy (&pqszStrings[i][LPT_PAPER_OUT_COL], pszString,
  125.                    Qstrlen (pszString));
  126.           /* I/O Error */
  127.           pszString = (pLpt->LptxInfo[wLptIndex].fIoError) ?
  128.                       pszYes : pszNo_;
  129.           Qstrncpy (&pqszStrings[i][LPT_I_O_ERROR_COL], pszString,
  130.                    Qstrlen (pszString));
  131.           /* Time Out */
  132.           pszString = (pLpt->LptxInfo[wLptIndex].fTimeOut) ?
  133.                       pszYes : pszNo_;
  134.           Qstrncpy (&pqszStrings[i][LPT_TIME_OUT_COL], pszString,
  135.                    Qstrlen (pszString));
  136.           /* Busy */
  137.           pszString = (pLpt->LptxInfo[wLptIndex].fBusy) ?
  138.                       pszYes : pszNo_;
  139.           Qstrncpy (&pqszStrings[i][LPT_BUSY_COL], pszString,
  140.                    Qstrlen (pszString));
  141.           /* ACK */
  142.           pszString = (pLpt->LptxInfo[wLptIndex].fAck) ?
  143.                       pszYes : pszNo;
  144.           Qstrcpy (&pqszStrings[i][LPT_ACK_COL], pszString);
  145.         }
  146.       else
  147.         {
  148.           /* Not a valid port, fill with dashes */
  149.           pqszStrings[i][LPT_PORT_ADDR_COL + 2] = '-';
  150.           pqszStrings[i][LPT_ON_LINE_COL   + 1] = '-';
  151.           pqszStrings[i][LPT_PAPER_OUT_COL + 1] = '-';
  152.           pqszStrings[i][LPT_I_O_ERROR_COL + 1] = '-';
  153.           pqszStrings[i][LPT_TIME_OUT_COL  + 1] = '-';
  154.           pqszStrings[i][LPT_BUSY_COL      + 1] = '-';
  155.           pqszStrings[i][LPT_ACK_COL       + 1] = '-';
  156.           pqszStrings[i][LPT_ACK_COL       + 2] = '';
  157.         }
  158.       /* Set the pointer for the next string */
  159.       pqszStrings[i + 1] = pqszStrings[i] + Qstrlen (pqszStrings[i]) + 1;
  160.     }
  161.   /* Set the last pointer to a NULL */
  162.   pqszStrings[i] = NULL;
  163.   /* Return the pointer to pqszStrings */
  164.   return (pqszStrings);
  165. }