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

📄 rptinfo.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
BOOL WritePageBreak (FILE *fileOutput)
{
  static struct dosdate_t daDate;   /* Dos date structure               */
  static struct dostime_t tiTime;   /* Dos time structure               */
  BOOL fReturnValue = FALSE;        /* Return Value from Write___ funcs */
  INT  i;                           /* Looping variable                 */

  /* Create the header line only on the first page */

  if (wPageCount == 0)
    {
      ++wPageCount;

      /* Create the header line */
      pszHeaderLine = malloc (REPORT_WIDTH);

      if (pszHeaderLine == NULL)
        {
          OutOfMemory();
          return (TRUE);
        }

      /* Obtain the current date and time */

      _dos_getdate (&daDate);
      _dos_gettime (&tiTime);
    }

  if (fReportOnly)
    {
      CHAR chBuffer[20];
      WORD i = 0;

      /* Display the page number on the screen */
      sprintf (chBuffer, "\rPage %u", wPageCount);

      while (chBuffer[i])
        putch (chBuffer[i++]);
    }
#if CW_INCLUDED
  else
    {
      CHAR chBuffer[20];

      /* Display the page number on the status line */
      sprintf (chBuffer, "Page %u", wPageCount);
      ShowStatus (chBuffer);
    }
#endif


  /* Write the formfeed, followed by 2 linefeeds */

  if (wPageCount > 1)
    {
      fReturnValue = WriteChar ('\f', fileOutput);
      if (fReturnValue)
        return (fReturnValue);
    }

  for (i = 0; !fReturnValue && i < 2; ++i)
    fReturnValue = WriteChar ('\n', fileOutput);

  if (fReturnValue)
    return (fReturnValue);


  /* Create header string */

  sprintf (pszHeaderLine,
           pszHeaderFormatString,
           pszVersionNumber,
           daDate.month,
           daDate.day,
           daDate.year % 100,
           (tiTime.hour > 12) ? tiTime.hour-12 : tiTime.hour,
           tiTime.minute,
           (tiTime.hour > 12) ? "pm" : "am",
           wPageCount++);


  /* Print the header line */

  fReturnValue = WriteLine (pszHeaderLine, fileOutput, TRUE);
  if (fReturnValue)
    return (fReturnValue);


  /* Print the underline, followed by 1 linefeed */

  i = REPORT_WIDTH;

  while (!fReturnValue && i--)
    fReturnValue = WriteChar ('=', fileOutput);

  if (fReturnValue)
    return (fReturnValue);

  for (i = 0; !fReturnValue && i < 1; ++i)
    fReturnValue = WriteChar ('\n', fileOutput);

  if (fReturnValue)
    return (fReturnValue);

  return (FALSE);
}


/********************************************************************
 * ReportFile - Writes a set of strings to the output file
 *
 *
 * Returns: TRUE if an error condition occured.
 ********************************************************************/

BOOL ReportFile (PSZ  pszTitle,
                 PSZ  pszFilename,
                 FILE *fileOutput)
{
  BOOL fReturnValue = FALSE;  /* Return value from various functions    */
  FILE *fileInput;            /* Input file handle                      */
  CHAR chBuffer[80];          /* Input buffer                           */


  /* Determine if a page break is required */
  if (wLineCount + 6 > LINES_PER_PAGE)
    fReturnValue = WritePageBreak (fileOutput);


  /* Write the separator line, if requested */
  if (pszTitle != NULL && pszTitle[0] != '\0')
    fReturnValue = WriteSepLine (fileOutput, pszTitle);


  /* Open the file */
  fileInput = OpenFile (pszFilename, "rb", TRUE);
  if (fileInput == NULL)
    return (TRUE);


  /* Write the strings */
  while (fReturnValue == FALSE &&
         ReadLine (chBuffer, REPORT_WIDTH, fileInput, FALSE) != EOF)
    {
      fReturnValue = WriteLine (chBuffer, fileOutput, TRUE);
    }

  /* Flush the buffer contents */

  if (!fReturnValue)
    {
      if (fflush (fileOutput) == EOF)
        fReturnValue = TRUE;
      else
        fReturnValue = FALSE;
    }

  CloseFile (fileInput);

  return (fReturnValue);
}


#if CW_INCLUDED

/*********************************************************************
 * TestPrinter - Performs the printer test.
 *
 * fPostscript - TRUE if the Postscript test is requested
 * f8BitTest   - TRUE if the 8-bit ASCII test is requested
 * fSerialTest - TRUE if serial port, FALSE for parallel port
 * wPort       - Printer port number for the test
 *********************************************************************/

BOOL TestPrinter (BOOL fPostscript,
                  BOOL f8BitTest,
                  BOOL fSerialTest,
                  WORD wPort)
{
  VOID *pPortStruct = NULL;   /* Structure for storing printer port data */
  COM_STRUCT *pCom;           /* COM Port data struct pointer            */
  LPT_STRUCT *pLpt;           /* LPT Port data struct pointer            */
  WORD wSize;                 /* Size of the structure                   */
  WORD wReturnValue;          /* Return value from various functions     */
  CHAR szPort[5];             /* Port's filename                         */


  /* Set up the port's filename */
  if (fSerialTest)
    strcpy (szPort, "COM");
  else
    strcpy (szPort, "LPT");

  szPort[3] = (CHAR) (wPort + '1');
  szPort[4] = '\0';


  /* Obtain the appropriate port information */

  if (fSerialTest)
    wSize = GetInfoSize (IDI_COM_RECORD, FALSE);
  else
    wSize = GetInfoSize (IDI_LPT_RECORD, FALSE);


  if (wSize == 0)
    return (TRUE);

  pPortStruct = malloc (wSize);

  if (pPortStruct == NULL)
    {
      OutOfMemory();
      return (TRUE);
    }

  /* Zero out the structure */
  memset (pPortStruct, '\0', wSize);

  if (fSerialTest)
    wReturnValue = GetInfo (IDI_COM_RECORD, pPortStruct, FALSE, FALSE, FALSE);
  else
    wReturnValue = GetInfo (IDI_LPT_RECORD, pPortStruct, FALSE, FALSE, FALSE);

  if (wReturnValue)
    {
      free (pPortStruct);
      return (wReturnValue);
    }


  /* Is the port available */

  if (fSerialTest)
    {
      pCom = pPortStruct;

      if (pCom->ComxInfo[wPort].fComPortDetected == FALSE)
        {
          wReturnValue = MessageBox (szPort,
                                     "Was not detected.",
                                     "Do you wish to continue?",
                                     MB_YESNO | 0x8000 | MB_DEFBUTTON2);

          if (wReturnValue == IDNO)
            return (FALSE);
        }
    }
  else
    {
      pLpt = pPortStruct;

      if (pLpt->LptxInfo[wPort].fLptPortDetected == FALSE)
        {
          wReturnValue = MessageBox (szPort,
                                     "Was not detected.",
                                     "Do you wish to continue?",
                                     MB_YESNO | 0x8000 | MB_DEFBUTTON2);

          if (wReturnValue == IDNO)
            return (FALSE);
        }
    }


  /* Is the port ready?  Check while waiting about 0.5 seconds */

  if (fSerialTest == FALSE)
    {
      /* Point to the DOS timer click count */
      BYTE FAR * fpDosClick = (BYTE FAR *) 0x0040006C;
      WORD wClickCount   = 10;          /* Number of clicks to count    */
      BOOL fPrinterReady = FALSE;       /* TRUE when printer is ready   */
      BYTE bClickValue   = *fpDosClick; /* Current value of the counter */


      /* Port ready check */
      while (fPrinterReady == FALSE && wClickCount)
        {
          while (bClickValue == *fpDosClick &&
                 pLpt->LptxInfo[wPort].fLptPortDetected == FALSE)
            {
              GetInfo (IDI_LPT_RECORD, pLpt, FALSE, FALSE, FALSE);
            }

          /* Is the printer ready */
          if (pLpt->LptxInfo[wPort].fLptPortDetected == TRUE)
            {
              fPrinterReady = TRUE;
            }
          else
            {
              /* Reduce the number of click counts to check by 1 */
              --wClickCount;

              /* Set up to watch for the next click */
              bClickValue = *fpDosClick;
            }
        }


      /* Last chance */
      if (fPrinterReady == FALSE)
        {
          wReturnValue = MessageBox (szPort,
                                     "Does not appear to be ready",
                                     "Do you wish to continue?",
                                     MB_YESNO | 0x8000 | MB_DEFBUTTON2);

          if (wReturnValue == IDNO)
            return (FALSE);
        }
    }


  PrintTest (szPort, f8BitTest, fPostscript);

  return (FALSE);
}


/*********************************************************************
 * PrintTest - Prints the printer test to the specified port.
 *
 * pszPort - Filename of the printer port.
 * f8BitTest - TRUE if 8 bit test requested, FALSE for 7 bit test.
 * fPostscript - TRUE if Postscript codes required, FALSE for TTY.
 *
 * Returns:  TRUE if an error occured.
 *********************************************************************/

BOOL PrintTest (PSZ pszPort, BOOL f8BitTest, BOOL fPostscript)
{
  FILE *fpOut;        /* File handle for output                   */
  WORD i;             /* Looping variable                         */
  WORD wMaxChar;      /* Maximum character to print               */
  WORD wMaxCol;       /* Maximum character to print in column one */
  WORD wX;            /* X-Coordinate for postscript test         */
  WORD wY;            /* Y-Coordinate for postscript test         */
  static struct dosdate_t daDate;   /* Dos date structure         */
  static struct dostime_t tiTime;   /* Dos time structure         */
  BOOL fReturnValue;  /* Return value from various functions      */
  CHAR chBuffer1[80]; /* Buffer for printed line                  */
  CHAR chBuffer2[80]; /* Buffer for printed line                  */


  /* Open the file */
  fpOut = OpenFile (pszPort, "w", TRUE);
  if (fpOut == NULL)
    return (TRUE);


  /* Postscript Test */
  if (fPostscript)
    {
      /* Obtain the current date and time */
      _dos_getdate (&daDate);
      _dos_gettime (&tiTime);

      /* Output the header information */
      fReturnValue = _WriteLine (pszPostscriptTest1, fpOut);

      sprintf (chBuffer1, pszPostscriptTest2,
               daDate.month,
               daDate.day,
               daDate.year % 100,
               (tiTime.hour > 12) ? tiTime.hour-12 : tiTime.hour,
               tiTime.minute,
               (tiTime.hour > 12) ? "pm" : "am");

      fReturnValue = _WriteLine (chBuffer1, fpOut);

      fReturnValue = _WriteLine (pszPostscriptTest3, fpOut);

      /* Output the characters */
      wMaxChar = (f8BitTest) ? 255 : 127;
      wMaxCol  = ((wMaxChar - 32) / 6);

      wX = 100;
      wY = 600;

      for (i = 32; i <= wMaxChar && fReturnValue == FALSE; ++i)
        {
          sprintf (chBuffer1, "%d %d moveto (%d:) show %d %d moveto (\\%o) show\r\n",
                   wX, wY, i, wX + 30, wY, i);
          fReturnValue = _WriteLine (chBuffer1, fpOut);

          /* Move the Y value */
          wY -= 14;

          if (i >= wMaxCol + 32)
            {
              wMaxCol += ((wMaxChar - 32) / 6) + 1;
              wX      += 72;
              wY       = 600;
            }
        }

      _WriteLine ("showpage\r\n", fpOut);
    }
  else
    {
      /* Print the header */
      wLineCount   = 0;
      wColumnCount = 0;
      wPageCount   = 0;

      fReturnValue = WritePageBreak (fpOut);
      if (fReturnValue)
        return (fReturnValue);


      /* Output subheader information */
      for (i = 0; i < 2 && fReturnValue == FALSE; ++i)
        fReturnValue = WriteChar ('\n', fpOut);

      for (i = 0; i < 23 && fReturnValue == FALSE; ++i)
        fReturnValue = WriteChar (' ', fpOut);

      if (fReturnValue)
        return (fReturnValue);

      fReturnValue = WriteLine ("Standard Text Printer Test:\n", fpOut, TRUE);
      if (fReturnValue)
        return (fReturnValue);


      /* Output the characters */
      wMaxChar = (f8BitTest) ? 255 : 127;
      wMaxCol  = ((wMaxChar - 32) / 6) + 1;

      for (i = 32; i < wMaxCol + 32; ++i)
        {
          sprintf (chBuffer1, "           %3d: %c   %3d: %c   %3d: %c   %3d: %c   %3d: %c",
                   i,                 i,
                   i + wMaxCol,       i + wMaxCol,
                   i + (wMaxCol * 2), i + (wMaxCol * 2),
                   i + (wMaxCol * 3), i + (wMaxCol * 3),
                   i + (wMaxCol * 4), i + (wMaxCol * 4));

          if (i + (wMaxCol * 5) <= wMaxChar)
            {
              sprintf (chBuffer2, "   %3d: %c",
                       i + (wMaxCol * 5), i + (wMaxCol * 5));
            }
          else
            chBuffer2[0] = '\0';

          strcat (chBuffer1, chBuffer2);

          fReturnValue = WriteLine (chBuffer1, fpOut, TRUE);
          if (fReturnValue)
            return (fReturnValue);
        }

      fReturnValue = WriteChar ('\014', fpOut);
    }

  CloseFile (fpOut);

  return (fReturnValue);
}

#endif

⌨️ 快捷键说明

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