⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cominfo.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
  return (FALSE);
}


/*********************************************************************
 * SprintComInfo - Put Com port information into a set of strings to
 *                 be printed or displayed.
 *
 * Returns:  NULL if an error occured.
 *********************************************************************/

QSZ * SprintComInfo (COM_STRUCT *pCom,
                     CHAR szSumStrings[][MAX_SUMM_INFO + 5])
{
  WORD wNmbrStrings;         /* Number of strings                    */
  WORD wNmbrChars;           /* Number of characters in the strings  */
  WORD wComIndex;            /* Index to the structure of COM data   */
  WORD i;                    /* Looping variables                    */
  QSZ  *pqszStrings = NULL;  /* Location for storing string pointers */


  /* Summary information */
  if (szSumStrings != NULL)
    {
      sprintf (szSumStrings[0], "%d", pCom->wNmbrComPorts);
      return (NULL);
    }


  /* Calculate the amount of space required for the strings */

  wNmbrChars   = (MAX_COM_TITLES + 3) * (MAX_COM_INFO_LINE + 1);

  wNmbrStrings = MAX_COM_TITLES + 3;


  /* Allocate space for the pointer area and string area */
  pqszStrings = AllocStringSpace (wNmbrStrings, wNmbrChars);
  if (pqszStrings == NULL)
    return (NULL);



  /* Put the first two strings in place */

  Qmemset (pqszStrings[0], ' ', COM_TITLE_WIDTH + COM_INFO_COL_WIDTH - 5);
  Qstrcpy (&pqszStrings[0][COM_TITLE_WIDTH + COM_INFO_COL_WIDTH - 5],
          pszComHeader);
  pqszStrings[1] = pqszStrings[0] + Qstrlen (pqszStrings[0]) + 1;

  Qmemset (pqszStrings[1], ' ', COM_TITLE_WIDTH + COM_INFO_COL_WIDTH - 5);
  Qstrcpy (&pqszStrings[1][COM_TITLE_WIDTH + COM_INFO_COL_WIDTH - 5],
          pszComUnderline);
  pqszStrings[2] = pqszStrings[1] + Qstrlen (pqszStrings[1]) + 1;


  /* Put the COM port information in place */

  for (i = 2, wComIndex = 0; wComIndex < MAX_COM_TITLES;
       ++i, ++wComIndex)
    {
      WORD wPort;             /* Port number for each display line */
      WORD wLength;           /* Current length of string          */
      WORD wInfoColumn;       /* Column to place the information   */
      CHAR chBuffer[80];      /* Buffer for string data            */
      PSZ  pszString = NULL;  /* String pointer                    */

      /* Clear out the string */
      Qmemset (pqszStrings[i], ' ', MAX_COM_INFO_LINE);
      pqszStrings[i][MAX_COM_INFO_LINE] = '\0';

      /* Put on the title */
      Qstrncpy (pqszStrings[i], paszComTitles[wComIndex],
               strlen (paszComTitles[wComIndex]));

      for (wPort = 0; wPort < MAX_COM_PORTS; ++wPort)
        {
          wInfoColumn = wPort * COM_INFO_COL_WIDTH + COM_TITLE_WIDTH;


          /* Put the N/A under the Port Address for ports that don't exist */

          if (wComIndex == COM_PORT_ADDRESS &&
              pCom->ComxInfo[wPort].fComPortDetected == FALSE)
            {
              QstrncpyAlign (&pqszStrings[i][wInfoColumn], pszNA,
                            strlen (pszNA), COM_INFO_COL_WIDTH);
            }


          /* Add the strings only if the COM port exists */

          if (pCom->ComxInfo[wPort].fComPortDetected)
            {
              switch (wComIndex)
                {
                  case COM_PORT_ADDRESS:
                    {
                      sprintf (chBuffer, "%04XH",
                               pCom->ComxInfo[wPort].wPortAddress);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], chBuffer,
                                    strlen (chBuffer), COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_BAUD_RATE:
                    {
                      sprintf (chBuffer, "%Lu",
                               pCom->ComxInfo[wPort].dwBaudRate);
                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], chBuffer,
                                    strlen (chBuffer), COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_PARITY:
                    {
                      wLength = strlen (pCom->ComxInfo[wPort].szParity);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn],
                                    pCom->ComxInfo[wPort].szParity,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_DATA_BITS:
                    {
                      sprintf (chBuffer, "%d",
                               pCom->ComxInfo[wPort].wDataBits);
                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], chBuffer,
                                    strlen (chBuffer), COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_STOP_BITS:
                    {
                      if (pCom->ComxInfo[wPort].wStopBits < 3)
                        {
                          sprintf (chBuffer, "%d",
                                   pCom->ComxInfo[wPort].wStopBits);
                          QstrncpyAlign (&pqszStrings[i][wInfoColumn],
                                        chBuffer,
                                        strlen (chBuffer),
                                        COM_INFO_COL_WIDTH);
                        }
                      else
                        {
                          wLength = strlen (psz1point5);
                          QstrncpyAlign (&pqszStrings[i][wInfoColumn],
                                        psz1point5,
                                        wLength,
                                        COM_INFO_COL_WIDTH);
                        }
                      break;
                    }

                  case COM_CARRIER_DETECT:
                    {
                      pszString = (pCom->ComxInfo[wPort].fCarrierDetect) ?
                                  pszYes : pszNo;

                      wLength = strlen (pszString);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], pszString,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_RING_INDICATOR:
                    {
                      pszString = (pCom->ComxInfo[wPort].fRingIndicator) ?
                                  pszYes : pszNo;

                      wLength = strlen (pszString);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], pszString,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_DATA_SET_READY:
                    {
                      pszString = (pCom->ComxInfo[wPort].fDataSetReady) ?
                                  pszYes : pszNo;

                      wLength = strlen (pszString);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], pszString,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_CLEAR_TO_SEND:
                    {
                      pszString = (pCom->ComxInfo[wPort].fClearToSend) ?
                                  pszYes : pszNo;

                      wLength = strlen (pszString);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn], pszString,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }

                  case COM_UART_CHIP:
                    {
                      wLength = strlen (pCom->ComxInfo[wPort].szUartChip);

                      QstrncpyAlign (&pqszStrings[i][wInfoColumn],
                                    pCom->ComxInfo[wPort].szUartChip,
                                    wLength, COM_INFO_COL_WIDTH);
                      break;
                    }
                }
            }
        }

      PrepNextString (pqszStrings, i);
    }

  /* Set the last pointer to a NULL */
  pqszStrings[i] = NULL;

  /* Return the pointer to pqszStrings */
  return (pqszStrings);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -