home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / DSUTIL11 / LPRINT / LPRINT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-25  |  85KB  |  2,234 lines

  1. {-----------------------------------------------------------------------}
  2. { PROJECT        NON-PROFIT HIGH QUALITY PROFESSIONAL SOFTWARE,  }
  3. {            AVAILABLE FOR ALL WORLD                }
  4. { LIBRARY        SYSTEM UTILITIES                                }
  5. { MODULE        TEXT_LINE_PRINT                                 }
  6. { FILE NAME        LPRINT.PAS                    }
  7. { PURPOSE               Text Formatter For Printing                     }
  8. { VERSION        1.30                        }
  9. { DATE            25-Oct-93                    }
  10. { DESIGN        Dmitry Stefankov                }
  11. { IMPLEMENTATION    Dmitry Stefankov                 }
  12. { COMPANY        Freelance Software Engineer            }
  13. { ADDRESS        Isakowskogo str, 4-2-30                }
  14. {            Moscow, 123181                    }
  15. {            USSR                        }
  16. {            Tel. 007 (095) 944-6304                }
  17. { COPYRIGHT NOTICE    Copyright (C) 1987-1992, Dmitry Stefankov    }
  18. { RESTRICTED RIGHTS    AVAILABLE ONLY FOR FREE DISTRIBUTION,           }
  19. {            NOT FOR COMMERCIAL PURPOSE            }
  20. { COMPUTER        IBM PC or compatible                }
  21. { OPERATING SYSTEM    MS/PC-DOS Version 3.30 or higher        }
  22. { COMPILER        Turbo Pascal Version 7.0            }
  23. {                       (Borland International Inc.), or compatible     }
  24. { ASSEMBLY LANGUAGE    Microsoft MASM 5.10 or compatible               }
  25. { LINKER        Turbo Pascal internal                           }
  26. { ARGUMENTS             See command line syntax description             }
  27. { RETURN        See error return codes definitions        }
  28. { REQUIRES        Source Code Files                               }
  29. {                       MESSAGES.INC    (text messages)                 }
  30. {                       External Object Files                           }
  31. {                       NONE                                            }
  32. { NATURAL LANGUAGE      A. English Language                             }
  33. {                       B. Russian Language                             }
  34. {                       C. Germany Language                             }
  35. { SPECIAL        None                        }
  36. { DESCRIPTION        1.Read   input  stream                          }
  37. {                       2.Format output stream                          }
  38. {                       3.Write  output stream                          }
  39. { REVISION HISTORY    Dima Stefankov (DS)                }
  40. {               1.00  21-Feb-92  DS  initilal release        }
  41. {                       1.01  12-Mar-92  DS  fixed some bugs            }
  42. {                       1.02  17-Mar-92  DS  added documentation        }
  43. {                       1.03  07-Apr-92  DS  added some print options,  }
  44. {                         fixed errors at printing    }
  45. {                       1.04  19-Apr-92  DS  added user break of print  }
  46. {                       1.05  28-Apr-92  DS  some corrections of syntax }
  47. {                       1.06  08-May-92  DS  added UNIX text convert    }
  48. {                       1.07  14-May-92  DS  added command file option  }
  49. {                       1.10  15-Jun-92  DS  international support and  }
  50. {                                            new user interface         }
  51. {                       1.11  02-Jul-92  DS  fixed a bug for inputstream}
  52. {                       1.12  16-Jul-92  DS  added PC parameter         }
  53. {                       1.13  31-Aug-92  DS  added international help   }
  54. {                       1.14  04-Sep-92  DS  some corrections           }
  55. {                       1.15  18-Sep-92  DS  fixed a bug with page count}
  56. {                                            calculation                }
  57. {                       1.20  27-Oct-92  DS  some corrections           }
  58. {                       1.21  08-Nov-92  DS  some updates and added true}
  59. {                                            Germany writing            }
  60. {                       1.22  14-May-93  DS  some style updates         }
  61. {            1.23  04-Jul-93  DS  updated documentation    }
  62. {            1.24  19-Aug-93  DS  fixed problem character map}
  63. {                         translation        }
  64. {            1.30  25-Oct-93  DS  added large string options,}
  65. {                         automatic adjusting    }
  66. {-----------------------------------------------------------------------}
  67.  
  68.  
  69. {*======================= PROGRAM HEADER PART ==========================*}
  70.  
  71. PROGRAM   LinePrintUtility;
  72.  
  73.  
  74.  
  75. {** switches for compilation **}
  76. {$S-}                 {*  stack checking   *}
  77. {$R-}                    {*  range checking   *}
  78. {$X+}                    {*  extended syntax  *}
  79. {$M 32768,65536,65536}   {*  stack/heap sizes *}
  80.  
  81.  
  82. {** switches for international support **}
  83. {$DEFINE EnglishVersion}
  84. {$DEFINE RussianVersion}
  85. {$DEFINE GermanyVersion}
  86.  
  87.  
  88. {*** other modules ***}
  89. USES
  90.      Strings, Dos;
  91.  
  92.  
  93. {*========================== CONSTANTS PART ============================*}
  94.  
  95. CONST
  96.  
  97.    { std definitions }
  98.      asVersion                  =       '1.30';
  99.      asYears                    =       ' 1987, 1993  ';
  100.      asMsgHyphen                =       ' - ';
  101.  
  102.    { character constants }
  103.      achNULL                    =     #0;
  104.      achBS                      =     #8;
  105.      achHTAB                    =     #9;
  106.      achLF                      =     #10;
  107.      achFF                      =     #12;
  108.      achCR                      =     #13;
  109.      achEOF                     =     #26;
  110.      achESC                     =     #27;
  111.      achComma                   =     ',';
  112.      achBlank                   =     ' ';
  113.      achColon                   =     ':';
  114.      achComment                 =     '#';
  115.      achZERO                    =     '0';
  116.      ach255                     =     #255;
  117.  
  118.    { string constants }
  119.      asPcTextLF                 =     achCR + achLF;
  120.      asBlankStr                 =     '';
  121.      asSpaces2                  =     achBlank+achBlank;
  122.      asSpaces4                  =     asSpaces2+asSpaces2;
  123.      aMaxSymInStr               =     4096;     { lentgth = 4K !!}
  124.  
  125.    { Dos standard devices }
  126.      asStdDosConsoleDevice      =     'CON';
  127.      asStdDosPrintDevice        =     'PRN';
  128.  
  129.    { Dos miscellaneous }
  130.      achDosSwitch               =     '/';
  131.      achUnixSwitch              =     '-';
  132.  
  133.    { character values for boolean switch }
  134.      achSwitchON                =    '+';
  135.      achSwitchOFF               =    '-';
  136.  
  137.    { string constants }
  138.     asHelpIndent                =     asSpaces4+achBlank+achDosSwitch;
  139.  
  140.    { print settings constants }
  141.      aFileSwitch                =       'F';
  142.      aControlSwitch             =       'C';
  143.      aPageSwitch                =       'P';
  144.      aHeaderSwitch              =       'H';
  145.      aLineSwitch                =       'L';
  146.      aMarginSwitch              =       'M';
  147.  
  148.    { <file> switches }
  149.      aConfigCmd                 =       'C';
  150.      aSourceCmd                 =       'S';
  151.      aDestinationCmd            =       'D';
  152.      aWordStarCmd               =       'W';
  153.      aFirstBinaryCmd            =       'F';
  154.      aLastBinaryCmd             =       'L';
  155.      aTransCodesCmd             =       'T';
  156.  
  157.    { <control> switches > }
  158.      aStatisticsCmd             =       'S';
  159.      aAdvancedCtrlCmd           =       'A';
  160.      aBatchCmd                  =       'B';
  161.      aCtrlCodesCmd              =       'C';
  162.      aTabCmd                    =       'T';
  163.      aCtrlCharCodeCmd           =       'N';
  164.      aLanguageCmd               =       'L';
  165.  
  166.    { <page> switches }
  167.      aHeightCmd                 =       'H';
  168.      aWidthCmd                  =       'W';
  169.      aPageNumberCmd             =       'N';
  170.      aSkipPagesCmd              =       'S';
  171.      aCountPagesCmd              =      'C';
  172.      aPrintEvenCmd              =       'E';
  173.      aPrintOddCmd               =       'O';
  174.  
  175.    { <header> switches }
  176.      aHdrLevelCmd               =       'L';
  177.      aHdrTextCmd                =       'T';
  178.  
  179.    { <line> switches }
  180.      aLineNumCmd                =       'N';
  181.      aLineSpacingCmd            =       'S';
  182.  
  183.    { <margin> switches }
  184.      aLeftMarginCmd             =       'L';
  185.      aRightMarginCmd            =       'R';
  186.      aTopMarginCmd              =       'T';
  187.      aBottomMarginCmd           =       'B';
  188.  
  189.    { user confirm }
  190.      asExitKey                  =     'ESC';
  191.      asStopKey                  =     'SPACE BAR';
  192.      adwUserStopPrint           =     $3920;   { System BIOS  SPACE BAR key }
  193.      adwUserBreakPrint          =     $011B;   { System BIOS  ESCAPE    key }
  194.  
  195.    { human languages }
  196.      aEnglishLanguage           =       0;
  197.      aRussianLanguage           =       1;
  198.      aGermanyLanguage           =       2;
  199.      aBadLanguage               =       3;
  200.  
  201.  {$IFDEF EnglishVersion}
  202.      aDefLang                   =       aEnglishLanguage;
  203.  {$ELSE}
  204.     {$IFDEF RussianVersion}
  205.           aDefLang              =       aRussianLanguage;
  206.     {$ELSE}
  207.        {$IFDEF GermanyVersion}
  208.              aDefLang           =       aGermanyLanguage;
  209.        {$ELSE}
  210.              aDefLang           =       aBadLanguage;
  211.        {$ENDIF}
  212.     {$ENDIF}
  213.  {$ENDIF}
  214.  
  215.      aMinLangNum                =       aEnglishLanguage;
  216.      aMaxLangNum                =       aGermanyLanguage;
  217.  
  218.    { some help }
  219.      asLongLine                 =      ' ----------------+-------------------------------+-----------------------------';
  220.      asShortExample             =       ': -FSa:\my.doc /pw80 -pN2 /bfc:\bin\lptfont.bin';
  221.  
  222. { include files }
  223. {$I MESSAGES.INC}
  224.  
  225.  
  226. {*========================== CONSTANTS PART ============================*}
  227.  
  228.    { program exit codes }
  229.      errTerminateOK             =     0;
  230.      errBadParmsNumber          =     1;
  231.      errSourceNotFound          =     2;
  232.      errDestDontWrite           =     3;
  233.      errSameNames               =     4;
  234.      errInvalidSwtchCharFound   =     5;
  235.      errSrcOpenFailed           =     6;
  236.      errDestCreateFailed        =     7;
  237.      errBinOpenFailed           =     8;
  238.      errUserBreakOfPrint        =     9;
  239.      errBadFormatForNumberFound =     10;
  240.      errDestWriteFault          =     11;
  241.      errBadBooleanValueFound    =     12;
  242.      errNoSourceFileName        =     13;
  243.      errNoActiveLanguageFound   =     14;
  244.  
  245.    { Dos miscellaneous }
  246.      achDosEndFile              =     achEOF;
  247.      aDosFileNameLength         =     13;
  248.      aWSHBitOff                 =     $7F;
  249.  
  250.    { TP error codes }
  251.      errOK                      =     0;
  252.  
  253.    { time/date miscellaneous }
  254.      aHalfDay                   =     12;
  255.  
  256.    { defaults }
  257.      aDefPageWidth              =       85;
  258.      aDefPageHeight             =       66;
  259.  
  260.      aDefMarginTop              =       3;
  261.      aDefMarginBottom           =       5;
  262.      aDefMarginLeft             =       5;
  263.      aDefMarginRight            =       5;
  264.  
  265.      aDefPageNumber             =       1;
  266.      aDefPagesSkipCount         =       0;
  267.      aDefPagesPrintCount        =       0;
  268.      aDefOutPageNumber          =       1;
  269.  
  270.      aDefLineNumber             =       0;
  271.      aDefCurrentLineOnPage      =       1;
  272.      aDefOutLineNum             =       1;
  273.  
  274.      achDefEoln                 =       achLF;
  275.  
  276.      aDefLineSpacing            =       0;
  277.      aNoHTabSpaces              =       0;
  278.      aDefTabCols                =       8;
  279.      aDefHeaderLevel            =       1;
  280.  
  281.  
  282. {*==================== TYPE DECLARATIONS PART ==========================*}
  283.  
  284. TYPE
  285.     STR2                =       STRING[2];
  286.     STR4                =       STRING[4];
  287.     STR6                =       STRING[6];
  288.     STR8                =       STRING[8];
  289.     STR9                =       STRING[9];
  290.     STR10               =       STRING[10];
  291.     STR80               =       STRING[80];
  292.  
  293.     fBinFileType        =       FILE  OF  System.Byte;
  294.  
  295.  
  296. {*====================== TYPED CONSTANTS PART ==========================*}
  297.  
  298. CONST
  299.  
  300.    { command script file }
  301.      gsCmdFileName         :      STR80               =   asBlankStr;
  302.  
  303.    { input stream assignment }
  304.      gsInFileName          :       STR80             =    asBlankStr;
  305.  
  306.    { output stream assignment }
  307.      gsOutFileName         :       STR80              =   asStdDosPrintDevice;
  308.  
  309.    { binary files misc. info }
  310.      gsStartBinaryFileName :      STR80               =   asBlankStr;
  311.      gsEndBinaryFileName   :      STR80               =   asBlankStr;
  312.      gsTranslBinFileName   :      STR80               =   asBlankStr;
  313.  
  314.    { page linear sizes }
  315.      gdwPageWidth         :       System.Word         =   aDefPageWidth;
  316.      gdwPageHeight        :       System.Word         =   aDefPageHeight;
  317.  
  318.    { page indentation }
  319.      gdwMarginTop         :       System.Word         =   aDefMarginTop;
  320.      gdwMarginBottom      :       System.Word         =   aDefMarginBottom;
  321.      gdwMarginLeft        :       System.Word         =   aDefMarginLeft;
  322.      gdwMarginRight       :       System.Word         =   aDefMarginRight;
  323.  
  324.    { number of printing page }
  325.      gdwPageNumber        :       System.Word         =   aDefPageNumber;
  326.      gdwFirstPageNumber   :       System.Word         =   aDefPageNumber;
  327.      gdwSkipPagesCount    :       System.Word         =   aDefPagesSkipCount;
  328.      gdwPrintPagesCount   :       System.Word         =   aDefPagesPrintCount;
  329.      gdwOutPageNumber     :       System.Word         =   aDefOutPageNumber;
  330.  
  331.    { page line number }
  332.      gdwLineNumber        :       System.Longint      =   aDefLineNumber;
  333.      gdwCurrentLineOnPage :       System.Longint      =   aDefCurrentLineOnPage;
  334.      gdwOutLineNum        :       System.Word         =   aDefOutLineNum;
  335.  
  336.    { line spacing on page }
  337.      gdwLineSpacing       :       System.Word         =   aDefLineSpacing;
  338.  
  339.    { tab size }
  340.      gdbTabCols           :       System.Byte         =   aDefTabCols;
  341.  
  342.    { page header control }
  343.      gdwHeaderLevel       :       System.Word         =   aDefHeaderLevel;
  344.      gsHeaderText         :       STRING              =   asBlankStr;
  345.  
  346.    { print control miscellaneous switches }
  347.      gbAdvancePrintControlOK    :     System.Boolean  =   System.False;
  348.      gbBatchModeOK              :     System.Boolean  =   System.False;
  349.      gbPrintStatisticsOK        :     System.Boolean  =   System.True;
  350.      gbAsciiControlCharsOff     :     System.Boolean  =   System.False;
  351.      gbWordStarModeOK           :     System.Boolean  =   System.False;
  352.      gbTransModeOK              :     System.Boolean  =   System.False;
  353.      gbPrintOK                  :     System.Boolean  =   System.True;
  354.      gbOddPagesPrintOK          :     System.Boolean  =   System.True;
  355.      gbEvenPagesPrintOK         :     System.Boolean  =   System.True;
  356.      gbPrintNotAllPages         :     System.Boolean  =   System.False;
  357.      gchEOLN                    :     System.Char     =   achDefEoln;
  358.  
  359.  { international support }
  360.      gdbCurLanguage             :      System.Byte    =   aDefLang;
  361.  
  362.  { support for enhanced keyboard }
  363.    gbEnhancedKeyboardFound      :     System.Boolean  =   System.False;
  364.  
  365.  { file open mode control byte, default=read/write }
  366.    gdbOpenFileMode              :     System.Byte     =   2;
  367.  
  368.  { end of printing flag }
  369.    gbPrintDone                  :     System.Boolean  =   System.False;
  370.  
  371.  { standard codes translation table }
  372.    aNumOfCodes                  =    256;
  373.    gchCodeTranslateTable        :     ARRAY[0..aNumOfCodes-1]  OF  System.Char =
  374.                                     (#$00,#$01,#$02,#$03,#$04,#$05,#$06,#$07,
  375.                                      #$08,#$09,#$0A,#$0B,#$0C,#$0D,#$0E,#$0F,
  376.                                      #$10,#$11,#$12,#$13,#$14,#$15,#$16,#$17,
  377.                                      #$18,#$19,#$1A,#$1B,#$1C,#$1D,#$1E,#$1F,
  378.                                      #$20,#$21,#$22,#$23,#$24,#$25,#$26,#$27,
  379.                                      #$28,#$29,#$2A,#$2B,#$2C,#$2D,#$2E,#$2F,
  380.                                      #$30,#$31,#$32,#$33,#$34,#$35,#$36,#$37,
  381.                                      #$38,#$39,#$3A,#$3B,#$3C,#$3D,#$3E,#$3F,
  382.                                      #$40,#$41,#$42,#$43,#$44,#$45,#$46,#$47,
  383.                                      #$48,#$49,#$4A,#$4B,#$4C,#$4D,#$4E,#$4F,
  384.                                      #$50,#$51,#$52,#$53,#$54,#$55,#$56,#$57,
  385.                                      #$58,#$59,#$5A,#$5B,#$5C,#$5D,#$5E,#$5F,
  386.                                      #$60,#$61,#$62,#$63,#$64,#$65,#$66,#$67,
  387.                                      #$68,#$69,#$6A,#$6B,#$6C,#$6D,#$6E,#$6F,
  388.                                      #$70,#$71,#$72,#$73,#$74,#$75,#$76,#$77,
  389.                                      #$78,#$79,#$7A,#$7B,#$7C,#$7D,#$7E,#$7F,
  390.                                      #$80,#$81,#$82,#$83,#$84,#$85,#$86,#$87,
  391.                                      #$88,#$89,#$8A,#$8B,#$8C,#$8D,#$8E,#$8F,
  392.                                      #$90,#$91,#$92,#$93,#$94,#$95,#$96,#$97,
  393.                                      #$98,#$99,#$9A,#$9B,#$9C,#$9D,#$9E,#$9F,
  394.                                      #$A0,#$A1,#$A2,#$A3,#$A4,#$A5,#$A6,#$A7,
  395.                                      #$A8,#$A9,#$AA,#$AB,#$AC,#$AD,#$AE,#$AF,
  396.                                      #$B0,#$B1,#$B2,#$B3,#$B4,#$B5,#$B6,#$B7,
  397.                                      #$B8,#$B9,#$BA,#$BB,#$BC,#$BD,#$BE,#$BF,
  398.                                      #$C0,#$C1,#$C2,#$C3,#$C4,#$C5,#$C6,#$C7,
  399.                                      #$C8,#$C9,#$CA,#$CB,#$CC,#$CD,#$CE,#$CF,
  400.                                      #$D0,#$D1,#$D2,#$D3,#$D4,#$D5,#$D6,#$D7,
  401.                                      #$D8,#$D9,#$DA,#$DB,#$DC,#$DD,#$DE,#$DF,
  402.                                      #$E0,#$E1,#$E2,#$E3,#$E4,#$E5,#$E6,#$E7,
  403.                                      #$E8,#$E9,#$EA,#$EB,#$EC,#$ED,#$EE,#$EF,
  404.                                      #$F0,#$F1,#$F2,#$F3,#$F4,#$F5,#$F6,#$F7,
  405.                                      #$F8,#$F9,#$FA,#$FB,#$FC,#$FD,#$FE,#$FF);
  406.  
  407.    { filter for ASCII control codes }
  408.      aMinCtrlCodeChar       =     0;
  409.      aMaxCtrlCodeChar       =     31;
  410.      gbAvailAsciiCtrlCodesTable :     ARRAY[aMinCtrlCodeChar..aMaxCtrlCodeChar]  OF  System.Boolean  =
  411.                      (System.False,System.False,System.False,System.False,  {0-3}
  412.                       System.False,System.False,System.True, System.False,  {4-7}
  413.                       System.True, System.True, System.False,System.False,  {8-11}
  414.                       System.False,System.True, System.False,System.False,  {12-15}
  415.                       System.False,System.False,System.False,System.False,  {16-19}
  416.                       System.False,System.False,System.False,System.False,  {20-23}
  417.                       System.False,System.False,System.False,System.False,  {24-27}
  418.                       System.False,System.False,System.False,System.False); {28-31}
  419.  
  420.    { filter for ASCII codes }
  421.      aMinCodeChar           =     0;
  422.      aHalfTableCodeChar     =     127;
  423.      aMaxCodeChar           =     255;
  424.      gbAvailAsciiCodesTable :     ARRAY[aMinCodeChar..aMaxCodeChar]  OF  System.Boolean  =
  425.         (System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {00-07}
  426.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {08-0F}
  427.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {10-17}
  428.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {18-1F}
  429.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {20-27}
  430.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {28-2F}
  431.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {30-37}
  432.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {38-3F}
  433.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {40-47}
  434.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {48-4F}
  435.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {50-57}
  436.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {58-5F}
  437.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {60-67}
  438.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {68-6F}
  439.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {70-77}
  440.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {78-7F}
  441.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {80-87}
  442.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {88-8F}
  443.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {90-97}
  444.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {98-9F}
  445.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {A0-A7}
  446.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {A8-AF}
  447.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {B0-B7}
  448.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {B8-BF}
  449.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {C0-C7}
  450.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {C8-CF}
  451.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {D0-D7}
  452.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {D8-DF}
  453.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {E0-E7}
  454.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {E8-EF}
  455.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True,  {F0-F7}
  456.          System.True,System.True,System.True,System.True,System.True,System.True,System.True,System.True); {F8-FF}
  457.  
  458.    { character sets }
  459.      setAscii8NoCtrl            :     SET OF System.Char = [achBlank..ach255];
  460.      setUnusedLeadChars         :     SET OF System.Char = [achHTAB,achBlank];
  461.  
  462.  
  463. {*=========================== VARIABLES PART ===========================*}
  464.  
  465. VAR
  466.  
  467.  { input stream description }
  468.    gfInputStream        :       fBinFileType;
  469.    gfInputFileRecord    :       Dos.FileRec  ABSOLUTE  gfInputStream;
  470.  
  471.  { output stream description }
  472.    gfOutputStream       :       System.Text;
  473.    gfOutputFileRecord   :       Dos.TextRec  ABSOLUTE  gfOutputStream;
  474.  
  475.  { DOS info for input stream }
  476.    gsInFileDirStr       :       Dos.DirStr;
  477.    gsInFileNameStr      :       Dos.NameStr;
  478.    gsInFileExtStr       :       Dos.ExtStr;
  479.  
  480.  { DOS info for output stream }
  481.    gsOutFileDirStr      :      Dos.DirStr;
  482.    gsOutFileNameStr     :      Dos.NameStr;
  483.    gsOutFileExtStr      :      Dos.ExtStr;
  484.  
  485.  { current date }
  486.    gdwCurrentYear       :       System.Word;
  487.    gdwCurrentMonth      :       System.Word;
  488.    gdwCurrentDay        :       System.Word;
  489.    gdwCurrentWeekDay    :       System.Word;
  490.  
  491.  { current time }
  492.    gdwCurrentHour       :       System.Word;
  493.    gdwCurrentMinute     :       System.Word;
  494.    gdwCurrentSec        :       System.Word;
  495.    gdwCurrentSec100     :       System.Word;
  496.  
  497.  { DOS miscellaneous info for input stream }
  498.    gliFileTime          :       System.Longint;
  499.    grecFileDateTime     :       Dos.DateTime;
  500.    gdwFileDayOfWeek     :       System.Word;
  501.  
  502.  { text stamp for date/time }
  503.    gsPrintDateStamp     :       STRING;
  504.    gsFileDateStamp      :       STRING;
  505.  
  506.  { current printing page info }
  507.    gdwOutLineWidth      :       System.Word;
  508.    gdwOutLineHeight     :       System.Word;
  509.    gdwOutLinesOnPage    :       System.Word;
  510.  
  511.  { large buffer for input string }
  512.    gszLargeInBuf        :       ARRAY[0..aMaxSymInStr]  OF System.Char;
  513.    gpszLargeInBuf       :       System.PChar;
  514.  
  515. {*=========================== FORWARD REFERENCES =======================*}
  516.  
  517. PROCEDURE  _OutputTextStrLn(sMessage : STRING);      FORWARD;
  518. PROCEDURE  _ProcessOneCommand(sCommand : STRING);  FORWARD;
  519. PROCEDURE  _ErrorHalt(sMessage : STRING; dbReturnCode : System.Byte); FORWARD;
  520. PROCEDURE  _UserErrorReport(sMessage : STRING; bAddRetryAsk,bYesNo : System.Boolean); FORWARD;
  521.  
  522.  
  523. {*=========================== FUNCTIONAL PART ==========================*}
  524.  
  525. FUNCTION  _bDeviceReadyForOutput(dwDeviceHandle : System.Word) : System.Boolean; assembler;
  526. {* get output device status * }
  527. asm
  528.      mov        bx, dwDeviceHandle    { BX = handle }
  529.      mov        ax, $4407        { IOCTL, get file/device output status }
  530.      int        21h            { Dos services }
  531.      mov        ah, System.True        { AH = 1 }
  532.      cmp        al,0FFh            { 0FFh = ready, 00h = not ready }
  533.      je         @ExitFunc
  534.      mov        ah, System.False    { AH = 0 }
  535.   @ExitFunc:
  536.      mov        al, ah                    { return value of function }
  537. END;
  538.   {end-asm}
  539. { _bDeviceReadyForOutput }
  540.  
  541.  
  542.  
  543. FUNCTION  _fnbIsDevice(dwDeviceHandle : System.Word) : System.Boolean; assembler;
  544. {* get output device status * }
  545.   asm
  546.      mov        bx, dwDeviceHandle    { BX = handle }
  547.      mov        ax, $4400        { IOCTL, get file/device info }
  548.      int        21h            { Dos services }
  549.      jc         @FileFound              { may be error }
  550.      mov        ah, System.True            { AH = 1 }
  551.      test       dx,080h                 { test DEV bit }
  552.      jnz        @ExitFunc               { if ZR then we have disk file }
  553.   @FileFound:
  554.      mov        ah, System.False    { AH = 0 }
  555.   @ExitFunc:
  556.      mov        al, ah              { return value of function }
  557. END;
  558.   {end-asm}
  559. { _fnbIsDevice }
  560.  
  561.  
  562. FUNCTION  _fndwCalcDayOfWeek(dwInitYear,dwInitMonth,dwInitDay,
  563.                              dwCurYear,dwCurMonth : System.Word) : System.Word;
  564. VAR
  565.   ddTotal, ddInitDays, ddCurDays  :  System.Longint;
  566.  
  567. FUNCTION  _fndwTotalDays(dwDayFn,dwMonthFn,dwYearFn : System.Word) : System.Word;
  568. {* internal *}
  569. VAR
  570.   ddTemp  :  System.Longint;
  571.  
  572. BEGIN
  573.   {* magic formula *}
  574.      ddTemp := System.Trunc((22-dwMonthFn)/10);
  575.  
  576.   _fndwTotalDays := System.Trunc((dwYearFn-1899-ddTemp)*365.25)+
  577.                  System.Trunc((12*ddTemp+dwMonthFn-14)*30.59)+29+dwDayFn;
  578. END;  { _fndwAllDays }
  579.  
  580. BEGIN   { _fndwCalcDayOfWeek }
  581.   {* magic calculations *}
  582.       ddInitDays := _fndwTotalDays(dwInitDay,dwInitMonth,dwInitYear);
  583.       ddCurDays  := _fndwTotalDays(1,dwCurMonth,dwCurYear);
  584.       ddTotal := ddCurDays - ddInitDays;
  585.  
  586.     _fndwCalcDayOfWeek := System.Trunc((ddInitDays/7-System.Trunc(ddInitDays/7))*7+0.5);
  587. END;    { _fndwCalcDayOfWeek }
  588.  
  589.  
  590. FUNCTION  _fnsCurrentLanguage(dbDefLang : System.Byte)  :  STRING;
  591. {* Get the current language in string form. *}
  592. VAR
  593.   sLang  :  STRING;
  594. BEGIN
  595.    CASE  dbDefLang  OF
  596.        aEnglishLanguage    :   sLang := Strings.StrPas(gszEnglishLanguage[gdbCurLanguage]);
  597.        aRussianLanguage    :   sLang := Strings.StrPas(gszRussianLanguage[gdbCurLanguage]);
  598.        aGermanyLanguage    :   sLang := Strings.StrPas(gszGermanyLanguage[gdbCurLanguage]);
  599.    ELSE
  600.        sLang := 'Unknown';
  601.    END;
  602.    {case-of}
  603.  
  604.   _fnsCurrentLanguage := sLang;
  605. END; { _fnsCurrentLanguage }
  606.  
  607.  
  608. FUNCTION  _fnsUpcaseStr(sInput : STRING) : STRING;
  609. {* Make all in uppercase. *}
  610. VAR
  611.   dbIndex  :  System.Byte;
  612.   dbCount  :  System.Byte  ABSOLUTE sInput;
  613.  
  614. BEGIN
  615.   IF  (dbCount <> 0)
  616.   THEN  FOR dbIndex :=  1  TO  dbCount  DO
  617.             sInput[dbIndex] := System.Upcase(sInput[dbIndex]);
  618.         {for-to-do}
  619.   {if-then}
  620.  
  621.    _fnsUpcaseStr := sInput;
  622. END; { _fnsUpcaseStr }
  623.  
  624.  
  625. FUNCTION  _fnszWordStar(szInput : System.PChar) : System.PChar;
  626. {* Strip high bit off for all characters. *}
  627. VAR
  628.   dwIndex  :  System.Word;
  629.   dwCount  :  System.Word;
  630.  
  631. BEGIN
  632.   dwCount := Strings.StrLen(szInput);
  633.   IF (dwCount <> 0)
  634.     THEN   FOR dwIndex :=  0  TO  dwCount-1  DO
  635.               szInput[dwIndex] := System.Char(System.Byte(szInput[dwIndex]) AND aWSHBitOff);
  636.            {for-to-do}
  637.   {if-then}
  638.  
  639.    _fnszWordStar := szInput;
  640. END; { _fnszWordStar }
  641.  
  642.  
  643. FUNCTION  _fnszTranslateCodes(szInput : System.PChar) : System.PChar;
  644. {* Translate from one code table to another. *}
  645. VAR
  646.   dwIndex  :  System.Word;
  647.   dwCount  :  System.Word;
  648.  
  649. BEGIN
  650.   dwCount := Strings.StrLen(szInput);
  651.   IF (dwCount <> 0)
  652.     THEN   FOR dwIndex :=  0  TO  dwCount-1  DO
  653.               szInput[dwIndex] := gchCodeTranslateTable[System.Byte((szInput[dwIndex]))];
  654.            {for-to-do}
  655.   {if-then}
  656.  
  657.    _fnszTranslateCodes := szInput;
  658. END; { _fnszTranslateCodes }
  659.  
  660.  
  661. FUNCTION  _fnszRemoveUnusedAsciiCodes(szInput : System.PChar) : System.PChar;
  662. {* Strip all unwanted character codes. *}
  663. VAR
  664.   dwFetchIndex  :  System.Word;
  665.   dwPutIndex    :  System.Word;
  666.   dwCount       :  System.Word;
  667.   chNext        :  System.Char;
  668.  
  669. BEGIN
  670.   dwCount := Strings.StrLen(szInput);
  671.   dwFetchIndex := 0;
  672.   dwPutIndex := 0;
  673.  
  674.   WHILE  (dwCount <> 0) DO
  675.   BEGIN
  676.     chNext := szInput[dwFetchIndex];
  677.     IF ((gbAvailAsciiCodesTable[System.Byte(chNext)]))
  678.        THEN  BEGIN
  679.                 szInput[dwPutIndex] := chNext;
  680.                 System.Inc(dwPutIndex);
  681.              END;
  682.     {if-then}
  683.     {* total count/pointer *}
  684.       System.Inc(dwFetchIndex);
  685.       System.Dec(dwCount);
  686.   END;
  687.   {while-do}
  688.  
  689.   {* make final str *}
  690.     szInput[dwPutIndex] := achNULL;
  691.  
  692.   _fnszRemoveUnusedAsciiCodes := szInput;
  693. END; { _fnszRemoveUnusedAsciiCodes }
  694.  
  695.  
  696. FUNCTION _fnchUpperCase(chSym : System.Char) : System.Char;
  697. {* Translates from lowercase to uppercase. *}
  698. BEGIN
  699.    CASE  gdbCurLanguage OF
  700.       aEnglishLanguage  :  chSym := System.UpCase(chSym);
  701.       aRussianLanguage  :  {** Attention!!! Hard-Coded Values! **}
  702.                            CASE  chSym OF
  703.                                  #$F1  : chSym := #$F1;
  704.                                  #$A0..#$AF : System.Dec(System.Byte(chSym),$A0-$80);
  705.                                  #$E0..#$EF : System.Dec(System.Byte(chSym),$E0-$90);
  706.                              ELSE
  707.                                {nothing};
  708.                            END;
  709.                            {case-of}
  710.       aGermanyLanguage  :  chSym := System.UpCase(chSym);
  711.    END;
  712.    {case-of}
  713.  
  714.   _fnchUpperCase := chSym;
  715. END; { _fnchUpperCase }
  716.  
  717.  
  718. FUNCTION  _fnbGetValue(sInput : STRING) : System.Boolean;
  719. {* Convert string to an integer number. *}
  720. VAR
  721.   bReturnValue    :  System.Boolean;
  722.   chBooleanValue  :  System.Char;
  723.   dbCount         :  System.Byte  ABSOLUTE  sInput;
  724.  
  725. BEGIN
  726.     {* get a first char *}
  727.       IF  (dbCount <> 0)
  728.         THEN    chBooleanValue := sInput[1]
  729.         ELSE    chBooleanValue := #0;
  730.       {if-then-else}
  731.  
  732.     CASE  chBooleanValue  OF
  733.             achSwitchON  : bReturnValue := System.True;
  734.             achSwitchOFF : bReturnValue := System.False;
  735.     ELSE
  736.         _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  737.                    Strings.StrPas(gszMsgBadBooleanSwitch[gdbCurLanguage]),
  738.                      errBadBooleanValueFound);
  739.     END;
  740.     {case-of}
  741.  
  742.    _fnbGetValue := bReturnValue;
  743. END; { _fnbGetValue }
  744.  
  745.  
  746. FUNCTION  _fndwGetNum(sInput : STRING) : System.Word;
  747. {* Convert string to an integer number. *}
  748. VAR
  749.   iErrorCode :  System.Integer;
  750.   dwNumber   :  System.Word;
  751.  
  752. BEGIN
  753.     System.Val(sInput,dwNumber,iErrorCode);
  754.     IF  (iErrorCode <> errOK)
  755.        THEN _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  756.                        Strings.StrPas(gszMsgBadNumericFound[gdbCurLanguage]),
  757.                         errBadFormatForNumberFound);
  758.     {if-then}
  759.  
  760.    _fndwGetNum := dwNumber;
  761. END; { _fndwGetNum }
  762.  
  763.  
  764. FUNCTION  _fnsNumToStr(dwNum,dwWidth : System.Word) : STRING;
  765. {* Returns a numeric format string for a given number. *}
  766. VAR
  767.   sNumStr   :  STRING;
  768.  
  769. BEGIN
  770.   IF (dwWidth = 0)
  771.     THEN  System.Str(dwNum,sNumStr)
  772.     ELSE  System.Str(dwNum:dwWidth,sNumStr);
  773.   {if-then-else}
  774.   _fnsNumToStr := sNumStr;
  775. END; { _fnsNumToStr }
  776.  
  777.  
  778. FUNCTION  _fnsAddSpaces(dbSpaceNum : System.Byte) : STRING;
  779. {* String must be contain only spaces. *}
  780. VAR
  781.   sTemp : STRING;
  782.  
  783. BEGIN
  784.     IF (dbSpaceNum <> 0)
  785.        THEN  System.FillChar(sTemp[1],System.Word(dbSpaceNum),achBlank);
  786.     {if-then}
  787.  
  788.     sTemp[0] := System.Char(dbSpaceNum);
  789.    _fnsAddSpaces := sTemp;
  790. END; { _fnsAddSpaces }
  791.  
  792.  
  793. FUNCTION  _fnsLeadingZeroSpace(sInput : STRING; bReplace : System.Boolean; chOld,chNew : System.Char) : STRING;
  794. {* Remove or replace the leading character *}
  795. VAR
  796.   dbCount  :  System.Byte  ABSOLUTE  sInput;
  797.  
  798. BEGIN
  799.   IF  (dbCount <> 0)  THEN
  800.   BEGIN
  801.      IF  (bReplace)
  802.        THEN
  803.           BEGIN  IF  (sInput[1] = chOld)
  804.                    THEN sInput[1] := chNew;
  805.                  {if-then}
  806.           END
  807.        ELSE
  808.           IF  (sInput[1] = chOld) THEN System.Delete(sInput,1,1);
  809.           {if-then}
  810.       {if-then-else}
  811.   END;
  812.   {if-then}
  813.   _fnsLeadingZeroSpace := sInput;
  814. END; { _fnsLeadingZeroSpace }
  815.  
  816.  
  817. FUNCTION  _fnsRemoveLeadChars(sInput : STRING) : STRING;
  818. {* Remove all occurrences of leading char from left side. *}
  819. BEGIN
  820.    WHILE ((sInput <> asBlankStr) AND (sInput[1] IN setUnusedLeadChars))
  821.    DO  System.Delete(sInput,1,1);
  822.    {while-do}
  823.    _fnsRemoveLeadChars := sInput;
  824. END; { _fnsRemoveLeadChars }
  825.  
  826.  
  827. FUNCTION  _fnsDateTimeStamp(dwYear,dwMonth,dwDay,dwWeekDay,dwHour,dwMinute : System.Word) : STRING;
  828. {* Make the date/time stamp string. *}
  829. VAR
  830.   sStamp        :  STRING;
  831.   sMeridian     :  STR2;
  832.  
  833. BEGIN
  834.   {* add day of week *}
  835.     sStamp := Strings.StrPas(gstrucDaysOfWeek[gdbCurLanguage,dwWeekDay]) + achComma + achBlank;
  836.  
  837.   {* add month/day *}
  838.     sStamp := sStamp + Strings.StrPas(gstrucMonthsOfYear[gdbCurLanguage,dwMonth]) + achBlank;
  839.     sStamp := sStamp +
  840.               _fnsLeadingZeroSpace(_fnsNumToStr(dwDay,2),System.False,achBlank,achBlank) +
  841.               achComma +
  842.               achBlank;
  843.  
  844.   {* add year *}
  845.     sStamp := sStamp + _fnsNumToStr(dwYear,4) + achComma + achBlank;
  846.  
  847.   {* add am/pm mark *}
  848.      sMeridian := Strings.StrPas(gszMsgAM[gdbCurLanguage]);
  849.      IF (dwHour  > (aHalfDay-1)) THEN
  850.        BEGIN
  851.          sMeridian := Strings.StrPas(gszMsgPM[gdbCurLanguage]);
  852.          System.Dec(dwHour,aHalfDay);
  853.        END;
  854.      {if-then}
  855.      IF (dwHour = aHalfDay) THEN
  856.        BEGIN
  857.          dwHour := 0;
  858.          sMeridian := Strings.StrPas(gszMsgAM[gdbCurLanguage]);
  859.        END;
  860.      {if-then}
  861.  
  862.   {* add hour *}
  863.     sStamp := sStamp +
  864.               _fnsLeadingZeroSpace(_fnsNumToStr(dwHour,2),System.False,achBlank,achBlank) +
  865.               achColon;
  866.  
  867.   {* add minute *}
  868.     sStamp := sStamp +
  869.               _fnsLeadingZeroSpace(_fnsNumToStr(dwMinute,2),System.True,achBlank,achZERO) +
  870.               sMeridian;
  871.  
  872.    _fnsDateTimeStamp := sStamp;
  873. END; { _fnsDateTimeStamp }
  874.  
  875.  
  876. FUNCTION  _fnbTextFileExist(VAR fStruc : System.Text; sFileName : STRING) : System.Boolean;
  877. {* Check that file exits. *}
  878. VAR
  879.   dwFileHandle   :  System.Word;
  880.   bResult        :  System.Boolean;
  881.  
  882. BEGIN
  883.   {** attempt to open the file **}
  884.     System.Assign(fStruc,sFileName);
  885.  
  886.   {** turn I/O check off at file opening **}
  887.     {$I-}  System.Reset(fStruc);  {$I+}
  888.  
  889.   {** get open handle **}
  890.   {* Attention!! Access of TP internal structures *}
  891.     asm
  892.       les  di, fStruc            { ES:DI -> file struc }
  893.       mov  ax, es:[di+0]         { AX = file handle !!!!}
  894.       mov  dwFileHandle, ax      { save it }
  895.     END;
  896.     {asm}
  897.  
  898.   IF (_fnbIsDevice(dwFileHandle))
  899.     THEN  BEGIN
  900.              bResult := System.False;
  901.              System.InOutRes := errOK;  { fix a TP run-time error }
  902.           END
  903.     ELSE  bResult := (System.IOResult = errOK);
  904.   {if-then-else}
  905.  
  906.   {** if open successful then close this file **}
  907.     IF (bResult)
  908.       THEN  System.Close(fStruc);
  909.     {if-then}
  910.  
  911.   _fnbTextFileExist := bResult;
  912. END; { _fnbTextFileExist }
  913.  
  914.  
  915. FUNCTION  _fnbBinFileExist(VAR fStruc : fBinFileType; sFileName : STRING) : System.Boolean;
  916. {* Check that file exits. *}
  917. VAR
  918.   dwFileHandle   :  System.Word;
  919.   bResult        :  System.Boolean;
  920.  
  921. BEGIN
  922.   {** attempt to open the file **}
  923.     System.Assign(fStruc,sFileName);
  924.  
  925.   {** turn I/O check off at file opening **}
  926.     {$I-}  System.Reset(fStruc);  {$I+}
  927.  
  928.   {** get open handle **}
  929.   {* Attention!!! Access of TP internal structures. *}
  930.     asm
  931.       les  di, fStruc            { ES:DI -> file struc }
  932.       mov  ax, es:[di+0]         { AX = file handle, just DOS index !!!!}
  933.       mov  dwFileHandle, ax      { save it }
  934.     END;
  935.     {end-asm}
  936.  
  937.   IF (_fnbIsDevice(dwFileHandle))
  938.     THEN  BEGIN
  939.              bResult := System.False;
  940.              System.InOutRes := errOK;  { fix a TP run-time error!! }
  941.           END
  942.     ELSE  bResult := (System.IOResult = errOK);
  943.   {if-then-else}
  944.  
  945.   {** if open successful then close this file **}
  946.     IF (bResult)
  947.       THEN  System.Close(fStruc);
  948.     {if-then}
  949.  
  950.   _fnbBinFileExist := bResult;
  951. END; { _fnbBinFileExist }
  952.  
  953.  
  954. FUNCTION  _fnszDeTabString(szInput: System.PChar) : System.PChar;
  955. {* Replaces the horizontal tabulation char with wanted # of spaces. *}
  956. CONST
  957.   aszHTAB     :  System.PChar    =  (achHTAB);
  958.  
  959. VAR
  960.   szUnTabStr  :  System.PChar;
  961.   pszIndex    :  System.PChar;
  962.   sTemp       :  STRING;
  963.   dwIndex     :  System.Word;
  964.   dwStrSize   :  System.Word;
  965.   dbPStrLen   :  System.Byte;
  966.  
  967. BEGIN
  968.   { works also if empty string found }
  969.     szUnTabStr := Strings.StrNew(szInput);
  970.     dwStrSize := Strings.StrLen(szInput);
  971.     pszIndex := Strings.StrPos(szInput,aszHTAB);
  972.  
  973.  
  974.     {** replace all occurrences of tab mark to wanted # of spaces **}
  975.       WHILE  (pszIndex <> NIL) DO
  976.       BEGIN
  977.           dwIndex := pszIndex - szInput;
  978.           sTemp := _fnsAddSpaces(gdbTabCols-((dwIndex) MOD gdbTabCols));
  979.           System.Move(szInput[dwIndex+1],szUnTabStr[0],dwStrSize-dwIndex+1);
  980.           dbPStrLen := System.Length(sTemp);
  981.           System.Move(sTemp[1],szInput[dwIndex],dbPStrLen);
  982.           System.Move(szUnTabStr[0],szInput[dwIndex+dbPStrLen],dwStrSize-dwIndex+1);
  983.           dwStrSize := Strings.StrLen(szInput);
  984.           pszIndex := Strings.StrPos(szInput,aszHTAB);
  985.       END;
  986.       {while-do}
  987.  
  988.       Strings.StrDispose(szUnTabStr);
  989.      _fnszDeTabString := szInput;
  990. END; { _fnszDeTabString }
  991.  
  992.  
  993. FUNCTION  _fnsFormatLineFromLeftSide(sInput : STRING) : STRING;
  994. {* adjust the string from left side. *}
  995. BEGIN
  996.    _fnsFormatLineFromLeftSide := _fnsAddSpaces(gdwMarginLeft) + sInput;
  997. END; { _fnsFormatLineFromLeftSide }
  998.  
  999.  
  1000. FUNCTION _fnsRemoveLastColon(sInput : STRING) : STRING;
  1001. {* remove the colon if found at the end of string *}
  1002. VAR
  1003.   dbIndex  :  System.Byte  ABSOLUTE sInput;
  1004.  
  1005. BEGIN
  1006.   IF (dbIndex <> 0)
  1007.   THEN  IF (sInput[dbIndex] = achColon)
  1008.            THEN  System.Delete(sInput,dbIndex,1);
  1009.         {if-then}
  1010.   {if-then}
  1011.   _fnsRemoveLastColon := sInput;
  1012. END; { _fnsRemoveLastColon }
  1013.  
  1014.  
  1015. FUNCTION  _fnszFileRead(VAR fStruc : fBinFileType; pszSInputBuf : System.PChar) : System.PChar;
  1016. {* Read one line from UNIX-formatted text *}
  1017. VAR
  1018.   dwCount       :       System.Word;
  1019.   szOutLine     :       System.PChar;
  1020.   bLineEnd      :       System.Boolean;
  1021.   chNextByte    :       System.Byte;
  1022.   bReadOk       :       System.Boolean;
  1023.  
  1024. BEGIN
  1025.   {* set defaults *}
  1026.     bLineEnd  :=  System.False;
  1027.     szOutLine := pszSInputBuf;
  1028.     dwCount   :=  0;
  1029.  
  1030.   {*****************************************************
  1031.     read char-by-char
  1032.         while linefeed not meeting
  1033.           or
  1034.         # of pushed symbols don't exceed maximum number
  1035.    *****************************************************}
  1036.   REPEAT
  1037.     bReadOk := System.False;
  1038.     REPEAT
  1039.       {$I-}  System.Read(fStruc,chNextByte);  {$I+}
  1040.  
  1041.        IF  (System.IoResult = errOK)
  1042.          THEN  bReadOk := System.True
  1043.          ELSE _UserErrorReport(Strings.StrPas(gszMsgReadFail[gdbCurLanguage]),
  1044.                                System.True,System.True);
  1045.        {if-then-else}
  1046.     UNTIL (bReadOk);
  1047.     {repeat-until}
  1048.  
  1049.     IF  (System.Char(chNextByte) = gchEOLN)
  1050.       THEN  bLineEnd := System.True
  1051.       ELSE
  1052.         IF (System.Char(chNextByte) <> achCR)
  1053.           THEN  BEGIN
  1054.             szOutLine[dwCount] := System.Char(chNextByte);
  1055.             System.Inc(dwCount);
  1056.                 END;
  1057.         {if-then}
  1058.     {if-then-else}
  1059.   UNTIL ((bLineEnd) OR (System.Eof(fStruc)) OR (dwCount >= aMaxSymInStr));
  1060.   {repeat-until}
  1061.  
  1062.   {* we now have the DOS std text string *}
  1063.     szOutLine[dwCount] := achNULL;
  1064.     _fnszFileRead:= szOutLine;
  1065. END; { _fnszFileRead }
  1066.  
  1067.  
  1068. FUNCTION  _fnchUserAsk  :  System.Char;
  1069. {* ask user and display his option *}
  1070. VAR
  1071.   sUserInput :  STRING;
  1072.  
  1073. BEGIN
  1074.     {$I-} System.ReadLn(System.Input,sUserInput); {$I+}
  1075.     IF  (sUserInput <> asBlankStr)
  1076.       THEN  _fnchUserAsk := sUserInput[1]
  1077.       ELSE  _fnchUserAsk := achNULL;
  1078.     {if-then-else}
  1079. END; { _fnchUserAsk }
  1080.  
  1081.  
  1082. FUNCTION  _fnpszInsertString(DestTo,SrcFrom : System.PChar; dwMaxDestLen : System.Word) : System.PChar;
  1083. {* Insert function for zero-terminated strings. *}
  1084. VAR
  1085.    dwSrcCount,
  1086.    dwDestCount  :  System.Word;
  1087.  
  1088. BEGIN
  1089.  
  1090.    dwSrcCount := Strings.StrLen(SrcFrom);
  1091.    dwDestCount := Strings.StrLen(DestTo);
  1092.  
  1093.    IF ((dwSrcCount+dwDestCount) > dwMaxDestLen)
  1094.      THEN  dwSrcCount := dwMaxDestLen - dwDestCount;
  1095.    {if-then}
  1096.  
  1097.    IF (dwSrcCount <> 0)
  1098.      THEN  BEGIN
  1099.         System.Move(DestTo[0],DestTo[dwSrcCount],dwDestCount+1);
  1100.         System.Move(SrcFrom[0],DestTo[0],dwSrcCount);
  1101.            END;
  1102.    {if-then}
  1103.  
  1104.   _fnpszInsertString := DestTo;
  1105.  
  1106. END;
  1107. { _fnpszInsertString }
  1108.  
  1109.  
  1110.  
  1111. {*=========================== PROCEDURAL PART ==========================*}
  1112.  
  1113. PROCEDURE    _CopyrightDisplay;
  1114. {* Outputs the copyright notice. *}
  1115. BEGIN
  1116.      _OutputTextStrLn(Strings.StrPas(gszPurpose[gdbCurLanguage])+
  1117.                       Strings.StrPas(gszMsgVersion[gdbCurLanguage])+
  1118.                       asVersion+
  1119.                       achComma+achBlank +
  1120.                       Strings.StrPas(gszCopyright[gdbCurLanguage])+
  1121.                       asYears+
  1122.                       Strings.StrPas(gszAuthor[gdbCurLanguage]));
  1123. END;  { _CopyrightDisplay }
  1124.  
  1125.  
  1126. PROCEDURE  _ErrorHalt(sMessage : STRING; dbReturnCode : System.Byte);
  1127. {* Display message about error and exit to DOS. *}
  1128. BEGIN
  1129.     IF (sMessage <> asBlankStr)
  1130.       THEN  _OutputTextStrLn(sMessage);
  1131.     {if-then}
  1132.     System.Halt(dbReturnCode);
  1133. END; { _ErrorHalt }
  1134.  
  1135.  
  1136. PROCEDURE  _OutputTextStr(sMessage : STRING);
  1137. {* Display a message. }
  1138. BEGIN
  1139.     {$I-} System.Write(System.Output,sMessage); {$I+}
  1140. END; { _OutputTextStr }
  1141.  
  1142.  
  1143. PROCEDURE  _OutputTextStrLn(sMessage : STRING);
  1144. {* Display a message. }
  1145. BEGIN
  1146.     {$I-} System.WriteLn(System.Output,sMessage); {$I+}
  1147. END; { _OutputTextStrLn }
  1148.  
  1149.  
  1150. PROCEDURE  _BadSwitchFound(sErrorMessage : STRING);
  1151. {* Display message about error and stop program. *}
  1152. BEGIN
  1153.   _CopyrightDisplay;
  1154.   _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1155.               sErrorMessage +
  1156.               Strings.StrPas(gszMsgsMisMatchSwitch[gdbCurLanguage]),
  1157.                 errInvalidSwtchCharFound);
  1158. END; { _BadSwitchFound }
  1159.  
  1160.  
  1161. PROCEDURE  _LoadBinaryFile(sBinFileName : STR80);
  1162. VAR
  1163.   fBinaryStream  :   FILE OF System.Byte;
  1164.   ddBytesCount   :   System.Longint;
  1165.   dbBufForByte   :   System.Byte;
  1166.   bReadOk        :   System.Boolean;
  1167.   bWriteOk       :   System.Boolean;
  1168.  
  1169. BEGIN
  1170.     {** debug message **}
  1171.       _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage])+
  1172.                        Strings.StrPas(gszMsgLoadBinFile[gdbCurLanguage])+
  1173.                        sBinFileName);
  1174.  
  1175.     {** attempt to open the file **}
  1176.       System.Assign(fBinaryStream,sBinFileName);
  1177.  
  1178.     {** turn I/O check off at file opening **}
  1179.       {$I-}  System.Reset(fBinaryStream);  {$I+}
  1180.  
  1181.     {** check if the file successfull opened **}
  1182.       IF  (System.IoResult <> errOK)
  1183.         THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1184.                          Strings.StrPas(gszMsgFileNotFound[gdbCurLanguage]) +
  1185.                          sBinFileName,
  1186.                            errBinOpenFailed);
  1187.       {if-then}
  1188.  
  1189.     {* get total count of bytes in file *}
  1190.       ddBytesCount := System.FileSize(fBinaryStream);
  1191.  
  1192.     {** we are used one-by-one byte algorithm to copy **}
  1193.     WHILE  (ddBytesCount <> 0) DO
  1194.     BEGIN
  1195.       {* read only one byte *}
  1196.         bReadOk := System.False;
  1197.         REPEAT
  1198.            {$I-}  System.Read(fBinaryStream,dbBufForByte);  {$I+}
  1199.  
  1200.            IF  (System.IoResult = errOK)
  1201.              THEN  bReadOk := System.True
  1202.              ELSE  _UserErrorReport(Strings.StrPas(gszMsgReadFail[gdbCurLanguage]),
  1203.                                     System.True,System.True);
  1204.            {if-then}
  1205.         UNTIL (bReadOk);
  1206.         {repeat-until}
  1207.  
  1208.       {** write all bytes except EOF **}
  1209.         IF (dbBufForByte <> System.Byte(achDosEndFile))
  1210.           THEN  BEGIN
  1211.              bWriteOk := System.False;
  1212.              REPEAT
  1213.                 {$I-} System.Write(gfOutputStream,System.Char(dbBufForByte)); {$I+}
  1214.                 IF  (System.IoResult = errOK)
  1215.                   THEN   bWriteOk := System.True
  1216.                   ELSE  _UserErrorReport(Strings.StrPas(gszMsgWriteFail[gdbCurLanguage]),
  1217.                                          System.True,System.True);
  1218.                 {if-then}
  1219.              UNTIL (bWriteOk); {
  1220.              repeat-until}
  1221.                 END;
  1222.          {if-then}
  1223.       {* total count down *}
  1224.         System.Dec(ddBytesCount);
  1225.     END;
  1226.     {while-do}
  1227.  
  1228.     {* close this file if no need more *}
  1229.       System.Close(fBinaryStream);
  1230. END;  { _LoadBinaryFile }
  1231.  
  1232.  
  1233. PROCEDURE  _LoadCodeTranslFile(sTransBinFileName : STR80);
  1234. VAR
  1235.   fBinaryStream  :   FILE OF System.Byte;
  1236.   dwCount        :   System.Word;
  1237.   dbInitOfs      :   System.Byte;
  1238.   dbIndex        :   System.Byte;
  1239.  
  1240. FUNCTION _fndbGetByteFromFile : System.Byte;
  1241. {* Get one byte from binary stream. *}
  1242. VAR
  1243.   dbBufForByte   :   System.Byte;
  1244.   bReadOk        :   System.Boolean;
  1245.  
  1246. BEGIN
  1247.       bReadOk := System.False;
  1248.  
  1249.       REPEAT
  1250.          {$I-}  System.Read(fBinaryStream,dbBufForByte);  {$I+}
  1251.          IF  (System.IoResult = errOK)
  1252.            THEN   bReadOk := System.True
  1253.            ELSE  _UserErrorReport(Strings.StrPas(gszMsgReadFail[gdbCurLanguage]),
  1254.                                   System.True,System.True);
  1255.          {if-then-else}
  1256.       UNTIL (bReadOk);
  1257.       {repeat-until}
  1258.  
  1259.   _fndbGetByteFromFile := dbBufForByte;
  1260. END; { _fndbGetByteFromFile }
  1261.  
  1262. BEGIN
  1263.     {** debug message **}
  1264.       _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage])+
  1265.                        Strings.StrPas(gszMsgLoadTransFile[gdbCurLanguage])+
  1266.                        sTransBinFileName);
  1267.  
  1268.     {** attempt to open the file **}
  1269.        System.Assign(fBinaryStream,sTransBinFileName);
  1270.  
  1271.     {** turn I/O check off at file opening **}
  1272.       {$I-}  System.Reset(fBinaryStream);  {$I+}
  1273.  
  1274.     {** check if the file successfull opened **}
  1275.       IF  (System.IoResult <> errOK)
  1276.         THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1277.                          Strings.StrPas(gszMsgFileNotFound[gdbCurLanguage]) +
  1278.                          sTransBinFileName,
  1279.                            errBinOpenFailed);
  1280.       {if-then}
  1281.  
  1282.     {* setup vars: total bytes in files, offset into table and # to copy *}
  1283.       dbInitOfs    := _fndbGetByteFromFile;
  1284.       dwCount      := _fndbGetByteFromFile;
  1285.       IF (dwCount = 0)
  1286.         THEN  dwCount := aNumOfCodes;
  1287.       {if-then}
  1288.  
  1289.     {* check user numbers *}
  1290.       IF ((System.Word(dbInitOfs)+dwCount) > aNumOfCodes)
  1291.         THEN  dwCount := aNumOfCodes - dbInitOfs;
  1292.       {if-then}
  1293.  
  1294.     FOR  dbIndex := 0 to (dwCount-1) DO
  1295.        gchCodeTranslateTable[dbInitOfs+dbIndex] := System.Char(_fndbGetByteFromFile);
  1296.     {for-to-do}
  1297.  
  1298.     {* close this file if no need more *}
  1299.       System.Close(fBinaryStream);
  1300.  
  1301.     {* enable global translation *}
  1302.       gbTransModeOK := System.True;
  1303. END;  { _LoadCodeTranslFile }
  1304.  
  1305.  
  1306. PROCEDURE  _UserErrorReport(sMessage : STRING; bAddRetryAsk,bYesNo : System.Boolean);
  1307. {* ask user to recover a error condition. }
  1308. VAR
  1309.  chUserExit  :  System.Char;
  1310.  chOtherKey  :  System.Char;
  1311.  
  1312. BEGIN
  1313.           _OutputTextStrLn(asBlankStr);
  1314.           _OutputTextStr(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) + sMessage);
  1315.  
  1316.           IF (bAddRetryAsk)
  1317.             THEN  _OutputTextStr(Strings.StrPas(gszMsgRetryAction[gdbCurLanguage]));
  1318.           {if-then}
  1319.  
  1320.           IF (bYesNo)
  1321.             THEN  BEGIN
  1322.                 chUserExit  := gchUserDontWant[gdbCurLanguage];
  1323.                 chOtherKey  := gchUserWant[gdbCurLanguage];
  1324.                   END
  1325.             ELSE  BEGIN
  1326.                 chUserExit  := gchUserWant[gdbCurLanguage];
  1327.                 chOtherKey  := gchUserDontWant[gdbCurLanguage];
  1328.                   END;
  1329.           {if-then-else}
  1330.  
  1331.           IF (gbBatchModeOK)
  1332.             THEN  _OutputTextStrLn(chOtherKey)
  1333.             ELSE
  1334.               IF (_fnchUpperCase(_fnchUserAsk) = chUserExit)
  1335.                   THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1336.                                    Strings.StrPas(gszMsgAbortOfPrint[gdbCurLanguage]),
  1337.                                      errUserBreakOfPrint);
  1338.               {if-then}
  1339.           {if-then-else}
  1340. END; {  UserErrorReport }
  1341.  
  1342.  
  1343. PROCEDURE    _PrintLine(sOutStr : STRING; bIncLineNum,bAddLineFeed : System.Boolean);
  1344. {* Writes a text line to user specified output device. *}
  1345. VAR
  1346.   dbIndex    :  System.Byte;
  1347.   dbCount    :  System.Byte;
  1348.   bBadOutput :  System.Boolean;
  1349.  
  1350. PROCEDURE  _UserBreakOfPrint;
  1351. {* see what user want *}
  1352. VAR
  1353.   dwUserKey     :  System.Word;
  1354.   chUserKey     :  System.Char;
  1355.  
  1356. BEGIN
  1357.   {** NOTE: Access to low-level system ROM BIOS routines! **}
  1358.   asm
  1359.      mov    dwUserKey, 0     { assume that no key was pressed by user }
  1360.      cmp    gbEnhancedKeyboardFound,System.True
  1361.      je     @EnhancedKbd
  1362.      mov    ah, 01h          { keystroke in buffer? }
  1363.      int    16h              { system BIOS call }
  1364.      jz     @NoKey           { exit if no available user keystroke }
  1365.      mov    ah, 0            { get ready key }
  1366.      int    16h              { system BIOS call }
  1367.      jmp    @SaveKey         { exit from inline }
  1368.    @EnhancedKbd:
  1369.      mov    ah, 11h          { extended key in buffer? }
  1370.      int    16h              { system BIOS call }
  1371.      jz     @NoKey           { exit if no available user keystroke }
  1372.      mov    ah, 10h          { get ready extended key }
  1373.      int    16h              { system BIOS call }
  1374.    @SaveKey:
  1375.      mov    dwUserKey, ax    { save to TP variable }
  1376.    @NoKey:
  1377.   END;
  1378.   {end-asm}
  1379.  
  1380.    CASE dwUserKey OF
  1381.       adwUserStopPrint   :  BEGIN
  1382.                               _UserErrorReport(Strings.StrPas(gszMsgStopPrintByUser[gdbCurLanguage]),
  1383.                                                System.True, System.True);
  1384.                             END;
  1385.       adwUserBreakPrint :   BEGIN
  1386.                               _UserErrorReport(Strings.StrPas(gszMsgUserWantBreak[gdbCurLanguage]),
  1387.                                                System.False, System.False);
  1388.                             END;
  1389.    END;
  1390.    {case-of}
  1391. END; { _UserBreakOfPrint }
  1392.  
  1393. BEGIN
  1394.    {* check if user want to stop print *}
  1395.      _UserBreakOfPrint;
  1396.  
  1397.    {* add CR/LF if need }
  1398.      IF  (bAddLineFeed)
  1399.        THEN  sOutStr := sOutStr + asPcTextLF;
  1400.      {if-then}
  1401.  
  1402.    {* find the # of characters in string *}
  1403.      dbCount := System.Length(sOutStr);
  1404.  
  1405.    {* check if print enabled **}
  1406.     IF  (System.Odd(gdwOutPageNumber))
  1407.       THEN  gbPrintOK := gbOddPagesPrintOK
  1408.       ELSE  gbPrintOK := gbEvenPagesPrintOK;
  1409.     {if-then-else}
  1410.  
  1411.    {** skip these pages **}
  1412.      IF (gdwSkipPagesCount <> 0)
  1413.        THEN gbPrintOK := System.False;
  1414.      {if-then}
  1415.  
  1416.    IF  (gbPrintOK)
  1417.    THEN
  1418.      {** output char-by-char **}
  1419.      {* Note: each string has at least two chars: CR+LF }
  1420.      FOR  dbIndex := 1  TO  dbCount  DO
  1421.      BEGIN
  1422.         {** assume that print failed **}
  1423.         bBadOutput := System.True;
  1424.  
  1425.         {* repeat until output successful and/or user abort the printing **}
  1426.         WHILE  (bBadOutput) DO
  1427.         BEGIN
  1428.  
  1429.          {**** advanced printer control if enabled ****}
  1430.            IF (gbAdvancePrintControlOK)
  1431.            THEN  WHILE NOT(_bDeviceReadyForOutput(gfOutputFileRecord.Handle))
  1432.                  DO  _UserErrorReport(Strings.StrPas(gszMsgDeviceNotReady[gdbCurLanguage]),
  1433.                                       System.True,System.True);
  1434.                  {while-do}
  1435.            {if-then}
  1436.  
  1437.          {** no check for errors during TP operations **}
  1438.             {$I-} System.Write(gfOutputStream,sOutStr[dbIndex]); {$I+}
  1439.  
  1440.          {** our solution is based on error return code **}
  1441.            IF (System.IOResult <> errOK)
  1442.              THEN
  1443.                 _UserErrorReport(Strings.StrPas(gszMsgWriteFault[gdbCurLanguage]),
  1444.                                  System.True,System.True)
  1445.              ELSE
  1446.                 bBadOutput := System.False;
  1447.            {if-then-else}
  1448.         END;
  1449.         {while-do}
  1450.      END;
  1451.      {for-to-do}
  1452.  
  1453.    {** display print info: page,line **}
  1454.      IF (bIncLineNum) THEN
  1455.      BEGIN
  1456.        System.Inc(gdwCurrentLineOnPage);
  1457.        IF  ((gbPrintOK) AND (gbPrintStatisticsOK)) THEN
  1458.          BEGIN
  1459.             _OutputTextStr(achCR);
  1460.             _OutputTextStr(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1461.                            Strings.StrPas(gszMsgPrintPageNum[gdbCurLanguage]) +
  1462.                            _fnsNumToStr(gdwOutPageNumber,0) +
  1463.                            Strings.StrPas(gszMsgPrintLineNum[gdbCurLanguage]) +
  1464.                            _fnsNumToStr(gdwCurrentLineOnPage,0) +
  1465.                            asSpaces4);
  1466.          END;
  1467.          {if-then}
  1468.      END;
  1469.      {if-then}
  1470.  
  1471. END;  { _PrintLine }
  1472.  
  1473.  
  1474. PROCEDURE    _FormFeed;
  1475. {* Output a form feed code. *}
  1476. BEGIN
  1477.    _PrintLine(achFF,System.False,System.False);
  1478. END;  { _FormFeed }
  1479.  
  1480.  
  1481. PROCEDURE    _SkipLinesOnPrint(dwCount : System.Word;bIncLineNum : System.Boolean);
  1482. {* Output empty lines. *}
  1483. VAR
  1484.   dwIndex : System.Word;
  1485.  
  1486. BEGIN
  1487.    IF  (dwCount <> 0)  THEN
  1488.       FOR dwIndex := 1 TO  dwCount  DO _PrintLine(asBlankStr,bIncLineNum,System.True);
  1489.       {for-to-do}
  1490.    {if-then}
  1491. END;  { _FormFeed }
  1492.  
  1493.  
  1494. PROCEDURE    _PrintPageHeader(dwPageNum : System.Word);
  1495. {* Output a page header. }
  1496. VAR
  1497.   sHeaderStr            :  STRING;
  1498.   sTemp                 :  STRING;
  1499.   dbFillLength          :  System.Byte;
  1500.   dbHeaderHeight        :  System.Byte;
  1501.  
  1502. BEGIN
  1503.   IF  (gdwHeaderLevel > 0)  THEN
  1504.     BEGIN
  1505.       {* put a file name in N-char field for DOS *}
  1506.         dbFillLength := aDosFileNameLength;
  1507.         sHeaderStr := gsInFileNameStr+gsInFileExtStr;
  1508.  
  1509.       {** fill the remainder with spaces **}
  1510.         WHILE  ( System.Length(sHeaderStr) < dbFillLength ) DO
  1511.            System.Insert(achBlank,sHeaderStr,System.Length(sHeaderStr)+1);
  1512.         {while-do}
  1513.  
  1514.       {* put a current date/time at center of line *}
  1515.         sTemp := gsPrintDateStamp;
  1516.         dbFillLength := (gdwOutLineWidth -(System.Length(sTemp)+System.Length(sHeaderStr))) DIV 2;
  1517.         sHeaderStr := sHeaderStr + _fnsAddSpaces(dbFillLength);
  1518.         sHeaderStr := sHeaderStr + sTemp;
  1519.  
  1520.       {* add page number at end of line *}
  1521.         sTemp := Strings.StrPas(gszMsgPage[gdbCurLanguage]) + _fnsNumToStr(dwPageNum,0);
  1522.         dbFillLength := gdwOutLineWidth - (System.Length(sTemp));
  1523.           WHILE  ( System.Length(sHeaderStr) < dbFillLength ) DO
  1524.               System.Insert(achBlank,sHeaderStr,System.Length(sHeaderStr)+1);
  1525.           {while-do}
  1526.         sHeaderStr := sHeaderStr + sTemp;
  1527.  
  1528.       {** output a header **}
  1529.         _PrintLine(_fnsFormatLineFromLeftSide(sHeaderStr),System.True,System.True);
  1530.     END;
  1531.     {if-then}
  1532.  
  1533.   {** output the file time/date at the creating moment**}
  1534.     IF  (gdwHeaderLevel > 1)  THEN
  1535.       BEGIN
  1536.          sTemp := Strings.StrPas(gszMsgTimeOfFileCreate[gdbCurLanguage]) + gsFileDateStamp;
  1537.         _PrintLine(_fnsFormatLineFromLeftSide(sTemp),System.True,System.True);
  1538.       END;
  1539.     {if-then}
  1540.  
  1541.   {** output user additional information **}
  1542.     IF  (gdwHeaderLevel > 2)  THEN
  1543.       BEGIN
  1544.         dbHeaderHeight := gdwHeaderLevel-2;
  1545.  
  1546.         IF  (gsHeaderText <> asBlankStr)
  1547.           THEN  BEGIN
  1548.            _PrintLine(_fnsFormatLineFromLeftSide(gsHeaderText),System.True,System.True);
  1549.             System.Dec(dbHeaderHeight);
  1550.                END;
  1551.         {if-then}
  1552.  
  1553.           WHILE (dbHeaderHeight <> 0) DO
  1554.           BEGIN
  1555.             _SkipLinesOnPrint(1,System.True);
  1556.              System.Dec(dbHeaderHeight);
  1557.           END;
  1558.           {while-do}
  1559.  
  1560.       END;
  1561.       {if-then}
  1562. END; { _PrintPageHeader }
  1563.  
  1564.  
  1565. PROCEDURE    _WriteLineToOutputStream(sInputStr : STRING;bIncLineCount : System.Boolean);
  1566. {* Writes only one string to stream. *}
  1567. BEGIN
  1568.     {** move to top of next page **}
  1569.     IF (gdwCurrentLineOnPage > gdwOutLinesOnPage)
  1570.               THEN
  1571.     BEGIN
  1572.        _FormFeed;
  1573.  
  1574.         {* check for total enabled pages to print *}
  1575.           IF (gbPrintNotAllPages) AND (gdwSkipPagesCount = 0)
  1576.             THEN  System.Dec(gdwPrintPagesCount);
  1577.           {if-then}
  1578.  
  1579.         IF (gbPrintNotAllPages) AND ((gdwPrintPagesCount) = 0)
  1580.           THEN  BEGIN
  1581.                    gbPrintDone := System.True;
  1582.                  {* terminates a current proc immediately *}
  1583.                    System.Exit;
  1584.                 END;
  1585.         {if-then}
  1586.  
  1587.       {* start a new page *}
  1588.         System.Inc(gdwOutPageNumber);
  1589.         gdwCurrentLineOnPage := 1;
  1590.  
  1591.         {** decrement by one **}
  1592.           IF (gdwSkipPagesCount <> 0)
  1593.             THEN  System.Dec(gdwSkipPagesCount);
  1594.           {if-then}
  1595.     END;
  1596.     {if-then}
  1597.  
  1598.     {** skip top lines **}
  1599.       IF   (gdwCurrentLineOnPage = 1)   THEN
  1600.         BEGIN
  1601.           _SkipLinesOnPrint(gdwMarginTop,System.False);
  1602.         END;
  1603.       {if-then}
  1604.  
  1605.     {** output the header information **}
  1606.       IF  (gdwHeaderLevel <> 0) AND (gdwCurrentLineOnPage = 1)  THEN
  1607.         BEGIN
  1608.               _PrintPageHeader(gdwOutPageNumber);
  1609.               _SkipLinesOnPrint(1,System.True);
  1610.         END;
  1611.       {if-then}
  1612.  
  1613.    {* output the line from the input stream **}
  1614.       _PrintLine(sInputStr,bIncLineCount,System.True);
  1615. END; { _WriteLineToOutputStream }
  1616.  
  1617.  
  1618. PROCEDURE    _ProcessLine(szInput : System.PChar);
  1619. {* Output the formatting text line. *}
  1620. VAR
  1621.   sTemp       :  STRING;
  1622.   szAdjust    :  ARRAY[0..SizeOf(STRING)]  OF  System.Char;
  1623.   sNumTemp    :  STR10;
  1624.   szNumTemp   :  ARRAY[0..SizeOf(STR10)+1] OF  System.Char;
  1625.   dwIndex     :  System.Word;
  1626.   dwCount     :  System.Word;
  1627.   dwStrSize   :  System.Word;
  1628.  
  1629. BEGIN
  1630.    {* at first call code-translation proc *}
  1631.      IF (gbTransModeOK)
  1632.        THEN  szInput := _fnszTranslateCodes(szInput);
  1633.      {if-then}
  1634.  
  1635.    {* strip off unwanted char codes *}
  1636.      szInput :=_fnszRemoveUnusedAsciiCodes(szInput);
  1637.  
  1638.    {** high bit off if need **}
  1639.      IF (gbWordStarModeOK)
  1640.        THEN  szInput := _fnszWordStar(szInput);
  1641.      {if-then}
  1642.  
  1643.    {** de-tabulation process **}
  1644.      IF (gdbTabCols <> aNoHTabSpaces)
  1645.        THEN  szInput := _fnszDeTabString(szInput);
  1646.      {if-then}
  1647.  
  1648.    {* add line number if need *}
  1649.     IF  (gdwLineNumber <> 0)
  1650.       THEN  sNumTemp := _fnsNumToStr(gdwOutLineNum,6) + asSpaces4
  1651.       ELSE  sNumTemp := asBlankStr;
  1652.     {if-then-else}
  1653.  
  1654.   {* automatical adjusting *}
  1655.  
  1656.     dwIndex := 0;
  1657.     WHILE  (szInput[dwIndex] = achBlank)  DO
  1658.     BEGIN
  1659.        System.Inc(dwIndex);
  1660.     END;
  1661.     {while-do}
  1662.     dwCount := dwIndex;
  1663.  
  1664.     szInput := _fnpszInsertString(szInput,Strings.StrPCopy(szNumTemp,sNumTemp),aMaxSymInStr);
  1665.  
  1666.  
  1667.    IF (sNumTemp <> asBlankStr)
  1668.      THEN  BEGIN
  1669.          System.Inc(dwCount,SizeOf(STR10)-1);
  1670.            END;
  1671.    {if-then}
  1672.    System.FillChar(szAdjust[0],dwCount,achBlank);
  1673.    szAdjust[dwCount] := achNULL;
  1674.  
  1675.    {** main algorithm to print one line **}
  1676.      dwStrSize := Strings.StrLen(szInput);
  1677.      REPEAT
  1678.      IF (dwStrSize >= gdwOutLineWidth)
  1679.        THEN  {* output main line *}
  1680.              BEGIN
  1681.            System.Move(szInput[0],sTemp[1],gdwOutLineWidth);
  1682.            sTemp[0] := System.Char(System.Lo(gdwOutLineWidth));
  1683.            _WriteLineToOutputStream(_fnsFormatLineFromLeftSide(sTemp),System.True);
  1684.            System.Move(szInput[gdwOutLineWidth],szInput[0],dwStrSize-gdwOutLineWidth+1+1);
  1685.        szInput := _fnpszInsertString(szInput,szAdjust,aMaxSymInStr);
  1686.              END
  1687.        ELSE  {* output a remainder and/or empty line *}
  1688.             BEGIN
  1689.           _WriteLineToOutputStream(_fnsFormatLineFromLeftSide(Strings.StrPas(szInput)),System.True);
  1690.           System.Inc(gdwOutLineNum);
  1691.           szInput := asBlankStr;  {* force empty string *}
  1692.              END;
  1693.      {if-then-else}
  1694.      dwStrSize := Strings.StrLen(szInput);
  1695.      UNTIL (dwStrSize = 0);
  1696.      {repeat-until}
  1697.  
  1698.    {* add line spacing *}
  1699.       dwCount := gdwLineSpacing;
  1700.  
  1701.     WHILE (dwCount <> 0) DO
  1702.       BEGIN
  1703.           _SkipLinesOnPrint(1,System.True);
  1704.           System.Dec(dwCount);
  1705.       END;
  1706.       { while-do }
  1707. END; { _ProcessLine }
  1708.  
  1709.  
  1710. PROCEDURE  _ParseScriptFile(sScriptName : STR80);
  1711. {* Processing of the script file that must contain settings for printing. *}
  1712. VAR
  1713.   fStruc       :          System.Text;
  1714.   sInputLine   :          STRING;
  1715.   bReadOk      :          System.Boolean;
  1716.  
  1717. BEGIN
  1718.     {** debug message **}
  1719.       _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1720.                        Strings.StrPas(gszMsgScriptFile[gdbCurLanguage]) +
  1721.                        sScriptName);
  1722.  
  1723.   {** attempt to open the file **}
  1724.     System.Assign(fStruc,sScriptName);
  1725.  
  1726.   {** turn I/O check off at file opening **}
  1727.     {$I-}  System.Reset(fStruc);  {$I+}
  1728.  
  1729.   {** check if the file successfull opened **}
  1730.     IF  (System.IoResult <> errOK)
  1731.         THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1732.                          Strings.StrPas(gszMsgFileNotFound[gdbCurLanguage]) +
  1733.                          sScriptName,
  1734.                            errBinOpenFailed);
  1735.     {if-then}
  1736.  
  1737.     WHILE  NOT(System.Eof(fStruc)) DO
  1738.     BEGIN
  1739.         bReadOk := System.False;
  1740.         REPEAT
  1741.           {$I-} System.ReadLn(fStruc,sInputLine); {$I+}
  1742.           IF  (System.IoResult = errOK)
  1743.              THEN  bReadOk := System.True
  1744.              ELSE  _UserErrorReport(Strings.StrPas(gszMsgReadFail[gdbCurLanguage]),
  1745.                                     System.True,System.True);
  1746.           {if-then-else}
  1747.         UNTIL (bReadOk);
  1748.         {repeat-until}
  1749.  
  1750.         IF ((sInputLine <> asBlankStr) AND (sInputLine[1] <> achComment))
  1751.            THEN  _ProcessOneCommand(_fnsRemoveLeadChars(sInputLine));
  1752.         {if-then}
  1753.     END;
  1754.     { while-do }
  1755.  
  1756.   {** if reading was successful then close this file **}
  1757.     System.Close(fStruc);
  1758. END; { _ParseScriptFile }
  1759.  
  1760.  
  1761. PROCEDURE  _ProcessOneCommand(sCommand : STRING);
  1762. {* table-driven parse algorithm. *}
  1763. VAR
  1764.   sParameter       :  STRING;
  1765.   chSwitch         :  System.Char;
  1766.   chSubSwitch      :  System.Char;
  1767.   dbTemp           :  System.Byte;
  1768.   bSwitchVal       :  System.Boolean;
  1769.  
  1770. BEGIN
  1771.       {* initial parsing *}
  1772.       chSwitch := System.Upcase(sCommand[2]);
  1773.       chSubSwitch := System.Upcase(sCommand[3]);
  1774.       System.Delete(sCommand,1,3);
  1775.  
  1776.       {** go through the multiple tests **}
  1777.       CASE  chSwitch  OF
  1778.              aFileSwitch  :
  1779.                      CASE  chSubSwitch  OF
  1780.                              aConfigCmd  :
  1781.                                          BEGIN
  1782.                   gsCmdFileName := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1783.                               IF  (gsCmdFileName <> asBlankStr)
  1784.                                 THEN  _ParseScriptFile(gsCmdFileName);
  1785.                               {if-then}
  1786.                                          END;
  1787.                              aSourceCmd  :
  1788.                   gsInFileName  := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1789.                              aDestinationCmd  :
  1790.                   gsOutFileName := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1791.                               aWordStarCmd  :
  1792.                   gbWordStarModeOK := _fnbGetValue(sCommand);
  1793.                               aFirstBinaryCmd  :
  1794.                   gsStartBinaryFileName := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1795.                                aLastBinaryCmd  :
  1796.                   gsEndBinaryFileName := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1797.                                  aTransCodesCmd  :
  1798.                   gsTranslBinFileName := _fnsRemoveLastColon(_fnsUpcaseStr(sCommand));
  1799.                      ELSE
  1800.                            _BadSwitchFound(Strings.StrPas(gszMsgBadFileSwitch[gdbCurLanguage]));
  1801.                      END;
  1802.                      {case-of}
  1803.              aControlSwitch  :
  1804.                      CASE  chSubSwitch  OF
  1805.                               aStatisticsCmd  :
  1806.                                      gbPrintStatisticsOK := _fnbGetValue(sCommand);
  1807.                                aAdvancedCtrlCmd  :
  1808.                                      gbAdvancePrintControlOK := _fnbGetValue(sCommand);
  1809.                                aBatchCmd  :
  1810.                                      gbBatchModeOK := _fnbGetValue(sCommand);
  1811.                                aCtrlCodesCmd  :   BEGIN
  1812.                                      gbAsciiControlCharsOff  := _fnbGetValue(sCommand);
  1813.                                      IF (gbAsciiControlCharsOff)
  1814.                                        THEN  System.Move(gbAvailAsciiCtrlCodesTable[aMinCtrlCodeChar],
  1815.                                                          gbAvailAsciiCodesTable[aMinCodeChar],
  1816.                                                          aMaxCtrlCodeChar+1);
  1817.                                      {if-then}
  1818.                                                    END;
  1819.                                aTabCmd  :
  1820.                                      gdbTabCols := _fndwGetNum(sCommand);
  1821.                                aCtrlCharCodeCmd  :
  1822.                                           BEGIN
  1823.                                      dbTemp := System.Length(sCommand);
  1824.                                      bSwitchVal := _fnbGetValue(sCommand[dbTemp]);
  1825.                                      System.Delete(sCommand,dbTemp,1);
  1826.                                      dbTemp := _fndwGetNum(sCommand);
  1827.                                      IF ((aMinCodeChar <= dbTemp) AND (dbTemp <= aMaxCodeChar))
  1828.                                        THEN  gbAvailAsciiCodesTable[dbTemp] := bSwitchVal
  1829.                                        ELSE  _BadSwitchFound(Strings.StrPas(gszMsgBadCtrlCode[gdbCurLanguage]));
  1830.                                      {if-then-else}
  1831.                                           END;
  1832.                                aLanguageCmd  :
  1833.                                           BEGIN
  1834.                                      dbTemp := _fndwGetNum(sCommand);
  1835.                                      IF (dbTemp <= aMaxLangNum) AND (gbLanguagesArray[dbTemp])
  1836.                                        THEN   gdbCurLanguage := dbTemp
  1837.                                        ELSE   _BadSwitchFound(Strings.StrPas(gszMsgBadLangSwitch[gdbCurLanguage]));
  1838.                                      {if-then-else}
  1839.                                            END;
  1840.                         ELSE
  1841.                            _BadSwitchFound(Strings.StrPas(gszMsgPrintCtrlSwitch[gdbCurLanguage]));
  1842.                         END;
  1843.                         {case-of}
  1844.              aPageSwitch  :
  1845.                      CASE  chSubSwitch  OF
  1846.                               aHeightCmd  :
  1847.                                      gdwPageHeight := _fndwGetNum(sCommand);
  1848.                                aWidthCmd  :
  1849.                                      gdwPageWidth := _fndwGetNum(sCommand);
  1850.                                aPageNumberCmd  :
  1851.                                      gdwPageNumber := _fndwGetNum(sCommand);
  1852.                                aSkipPagesCmd  :
  1853.                                      gdwSkipPagesCount := _fndwGetNum(sCommand);
  1854.                                aCountPagesCmd  :  BEGIN
  1855.                                      gdwPrintPagesCount := _fndwGetNum(sCommand);
  1856.                                      gbPrintNotAllPages := System.True;
  1857.                                                   END;
  1858.                                aPrintEvenCmd  :
  1859.                                      gbEvenPagesPrintOK := _fnbGetValue(sCommand);
  1860.                                aPrintOddCmd  :
  1861.                                      gbOddPagesPrintOK := _fnbGetValue(sCommand);
  1862.                         ELSE
  1863.                            _BadSwitchFound(Strings.StrPas(gszMsgBadPageSwitch[gdbCurLanguage]));
  1864.                         END;
  1865.                         {case-of}
  1866.              aHeaderSwitch  :
  1867.                      CASE  chSubSwitch  OF
  1868.                               aHdrLevelCmd  :
  1869.                                     gdwHeaderLevel := _fndwGetNum(sCommand);
  1870.                               aHdrTextCmd  :
  1871.                                        BEGIN
  1872.                                           IF (sCommand = asBlankStr) THEN
  1873.                                            BEGIN
  1874.                                              _OutputTextStr(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  1875.                                                             Strings.StrPas(gszMsgUserHeader[gdbCurLanguage]));
  1876.                                              System.ReadLn(sCommand);
  1877.                                            END;
  1878.                                            {if-then}
  1879.                                           gsHeaderText := sCommand;
  1880.                                        END;
  1881.                         ELSE
  1882.                            _BadSwitchFound(Strings.StrPas(gszMsgBadHeaderSwitch[gdbCurLanguage]));
  1883.                         END;
  1884.                         {case-of}
  1885.              aLineSwitch  :
  1886.                      CASE  chSubSwitch  OF
  1887.                              aLineNumCmd  :
  1888.                                     gdwLineNumber := _fndwGetNum(sCommand);
  1889.                              aLineSpacingCmd  :
  1890.                                     gdwLineSpacing := _fndwGetNum(sCommand);
  1891.                         ELSE
  1892.                            _BadSwitchFound(Strings.StrPas(gszMsgBadLineSwitch[gdbCurLanguage]));
  1893.                         END;
  1894.                         {case-of}
  1895.              aMarginSwitch  :
  1896.                      CASE  chSubSwitch  OF
  1897.                              aLeftMarginCmd  :
  1898.                                     gdwMarginLeft := _fndwGetNum(sCommand);
  1899.                              aRightMarginCmd  :
  1900.                                     gdwMarginRight := _fndwGetNum(sCommand);
  1901.                              aTopMarginCmd  :
  1902.                                     gdwMarginTop := _fndwGetNum(sCommand);
  1903.                              aBottomMarginCmd  :
  1904.                                     gdwMarginBottom := _fndwGetNum(sCommand);
  1905.                          ELSE
  1906.                             _BadSwitchFound(Strings.StrPas(gszMsgBadMarginSwitch[gdbCurLanguage]));
  1907.                          END;
  1908.                          {case-of}
  1909.       ELSE
  1910.           _BadSwitchFound(Strings.StrPas(gszMsgBadSwitchFound[gdbCurLanguage]));
  1911.       END;
  1912.       {case-of}
  1913. END;  { _ProcessOneCommand }
  1914.  
  1915.  
  1916. PROCEDURE    _ParseCommandLine(dbFirstParmIndex,dbLastParmIndex : System.Byte);
  1917. {* Read the user suggested settings for text formatting. *}
  1918. VAR
  1919.   sParameter       :  STRING;
  1920.   chSwitch         :  System.Char;
  1921.   dbIndex          :  System.Byte;
  1922.  
  1923. BEGIN
  1924.    {** parse all parameters **}
  1925.    FOR dbIndex := dbFirstParmIndex TO dbLastParmIndex DO
  1926.    BEGIN
  1927.       {** !!ATTENTION!! This algorithm is based on two-char keyword for each switch **}
  1928.       sParameter := System.ParamStr(dbIndex);
  1929.       chSwitch := sParameter[1];
  1930.  
  1931.       {** test for switch present **}
  1932.       IF  ((chSwitch <> achDosSwitch) AND (chSwitch <> achUnixSwitch))
  1933.         THEN  _BadSwitchFound(Strings.StrPas(gszMsgBadPrefixSwitch[gdbCurLanguage]));
  1934.       {if-then}
  1935.  
  1936.       _ProcessOneCommand(sParameter);
  1937.  
  1938.    END;
  1939.    {for-to-do}
  1940. END;  { _ParseCommandLine }
  1941.  
  1942.  
  1943. PROCEDURE _ProgramHelp;
  1944. {* Output help screen for user *}
  1945. BEGIN
  1946.   {* copyright notice *}
  1947.   _CopyrightDisplay;
  1948.  
  1949.   {* small help *}
  1950.    _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage])+
  1951.                     Strings.StrPas(gszMsgHelp00A[gdbCurLanguage]));
  1952.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp01A[gdbCurLanguage])+
  1953.                     Strings.StrPas(gszUProgram[gdbCurLanguage])+
  1954.                     Strings.StrPas(gszMsgHelp01B[gdbCurLanguage]));
  1955.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp02A[gdbCurLanguage]));
  1956.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp03A[gdbCurLanguage]));
  1957.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp04A[gdbCurLanguage]));
  1958.    _OutputTextStrLn(asLongLine);
  1959.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp05A[gdbCurLanguage]));
  1960.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp06A[gdbCurLanguage]));
  1961.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp07A[gdbCurLanguage]));
  1962.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp08A[gdbCurLanguage]));
  1963.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp09A[gdbCurLanguage]));
  1964.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp10A[gdbCurLanguage]));
  1965.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp11A[gdbCurLanguage]));
  1966.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp12A[gdbCurLanguage]));
  1967.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp13A[gdbCurLanguage]));
  1968.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp14A[gdbCurLanguage]));
  1969.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp15A[gdbCurLanguage]));
  1970.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp16A[gdbCurLanguage])+
  1971.                     _fnsNumToStr(aDefLang,0)+
  1972.                     ' (='+
  1973.                     _fnsCurrentLanguage(aDefLang)+
  1974.                     ')');
  1975.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp17A[gdbCurLanguage])+
  1976.                     _fnsNumToStr(aDefTabCols,0)+
  1977.                     Strings.StrPas(gszMsgHelp17B[gdbCurLanguage]));
  1978.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp18A[gdbCurLanguage]));
  1979.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp19A[gdbCurLanguage])+
  1980.                     _fnsNumToStr(aDefLineNumber,0)+
  1981.                     Strings.StrPas(gszMsgHelp19B[gdbCurLanguage]));
  1982.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp20A[gdbCurLanguage])+
  1983.                     +_fnsNumToStr(aDefLineSpacing,0)+
  1984.                     Strings.StrPas(gszMsgHelp20B[gdbCurLanguage]));
  1985.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp21A[gdbCurLanguage])+
  1986.                     _fnsNumToStr(aDefPageHeight,0)+
  1987.                     Strings.StrPas(gszMsgHelp21B[gdbCurLanguage]));
  1988.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp22A[gdbCurLanguage])+
  1989.                     _fnsNumToStr(aDefPageWidth,0)+
  1990.                     Strings.StrPas(gszMsgHelp22B[gdbCurLanguage]));
  1991.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp23A[gdbCurLanguage])+
  1992.                     _fnsNumToStr(aDefPageNumber,0));
  1993.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp24A[gdbCurLanguage]));
  1994.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp25A[gdbCurLanguage]));
  1995.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp26A[gdbCurLanguage])+
  1996.                     _fnsNumToStr(aDefPagesSkipCount,0)+
  1997.                     Strings.StrPas(gszMsgHelp26B[gdbCurLanguage]));
  1998.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp27A[gdbCurLanguage])+
  1999.                     _fnsNumToStr(aDefPagesPrintCount,0)+
  2000.                     Strings.StrPas(gszMsgHelp27B[gdbCurLanguage]));
  2001.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp28A[gdbCurLanguage])+
  2002.                     _fnsNumToStr(aDefMarginTop,0));
  2003.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp29A[gdbCurLanguage])+
  2004.                     _fnsNumToStr(aDefMarginBottom,0));
  2005.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp30A[gdbCurLanguage])+
  2006.                     _fnsNumToStr(aDefMarginLeft,0));
  2007.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp31A[gdbCurLanguage])+
  2008.                     _fnsNumToStr(aDefMarginRight,0));
  2009.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp32A[gdbCurLanguage])+
  2010.                    _fnsNumToStr(aDefHeaderLevel,0));
  2011.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp33A[gdbCurLanguage]));
  2012.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp33B[gdbCurLanguage]));
  2013.    _OutputTextStrLn(Strings.StrPas(gszMsgHelp34A[gdbCurLanguage])+
  2014.                     asShortExample);
  2015. END; { _ProgramHelp }
  2016.  
  2017.  
  2018. PROCEDURE  _InitInternals;
  2019. {* initialize some internal variables. *}
  2020. BEGIN
  2021.    {* access to System BIOS variable *}
  2022.    IF ((System.Mem[$40:$96] AND $10) <> 0)
  2023.      THEN  gbEnhancedKeyboardFound := System.True;
  2024.    {if-then}
  2025. END; { _InitInternals }
  2026.  
  2027.  
  2028. {*============================== MAIN PART =============================*}
  2029.  
  2030. BEGIN
  2031.  
  2032.   {* some housekeeping *}
  2033.     _InitInternals;
  2034.  
  2035.   {* do user want something? *}
  2036.      IF (System.ParamCount = 0) THEN
  2037.        BEGIN
  2038.           _ProgramHelp;
  2039.           _ErrorHalt(asBlankStr,errBadParmsNumber);
  2040.        END;
  2041.      {if-then}
  2042.  
  2043.  
  2044.   {** read all user parameters **}
  2045.      _ParseCommandLine(1,System.LO(System.ParamCount)); { if-then }
  2046.  
  2047.  
  2048.   {* exit if no source file for print *}
  2049.     IF (gsInFileName = asBlankStr)
  2050.       THEN BEGIN
  2051.               _ProgramHelp;
  2052.               _ErrorHalt(asBlankStr,errNoSourceFileName);
  2053.            END;
  2054.     {if-then}
  2055.  
  2056.  
  2057.   {* copyright notice *}
  2058.     _CopyrightDisplay;
  2059.  
  2060.  
  2061.   {** recalculate the print settings **}
  2062.      gdwOutLineWidth    := gdwPageWidth - (gdwMarginLeft+gdwMarginRight);
  2063.      gdwOutPageNumber   := gdwPageNumber;
  2064.      gdwOutLinesOnPage  := gdwPageHeight - (gdwMarginTop+gdwMarginBottom);
  2065.      gdwFirstPageNumber := gdwPageNumber + gdwSkipPagesCount;
  2066.  
  2067.  
  2068.   {* same names? *}
  2069.     IF (gsInFileName = gsOutFileName)
  2070.       THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2071.                        Strings.StrPas(gszMsgSameFilesNotAllowed[gdbCurLanguage]),
  2072.                          errSameNames);
  2073.     {if-then}
  2074.  
  2075.   {** source file exists? **}
  2076.     IF  NOT(_fnbBinFileExist(gfInputStream,gsInFileName))
  2077.       THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2078.                        Strings.StrPas(gszMsgFileNotFound[gdbCurLanguage]) +
  2079.                        gsInFileName,
  2080.                          errSourceNotFound);
  2081.     {if-then}
  2082.  
  2083.   {** may be destination file present? **}
  2084.     IF (_fnbTextFileExist(gfOutputStream,gsOutFileName))  THEN
  2085.     BEGIN
  2086.       _OutputTextStr(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2087.                                    Strings.StrPas(gszMsgOutFile[gdbCurLanguage]) +
  2088.                                    gsOutFileName +
  2089.                                    Strings.StrPas(gszMsgAlreadyExists[gdbCurLanguage]));
  2090.       IF (gbBatchModeOK)
  2091.         THEN  _OutputTextStrLn(gchUserWant[gdbCurLanguage])
  2092.         ELSE  IF (_fnchUpperCase(_fnchUserAsk) <> gchUserWant[gdbCurLanguage])
  2093.                        THEN  _ErrorHalt(asBlankStr,errDestDontWrite);
  2094.       {if-then-else}
  2095.     END;
  2096.     {if-then}
  2097.  
  2098.  
  2099.   {** open the source file **}
  2100.     System.Assign(gfInputStream,gsInFileName);
  2101.     System.InOutRes := errOK;                 { fix an errata in TP-RTL }
  2102.     gdbOpenFileMode := System.FileMode;       { access to TP internal var }
  2103.     System.FileMode := $20;                   { read, deny write on sharing }
  2104.     {$I-} System.Reset(gfInputStream); {$I+}
  2105.     System.FileMode := gdbOpenFileMode;       { restore TP internal var }
  2106.  
  2107.  
  2108.   {** stop if open failed **}
  2109.     IF  (System.IOResult <> errOK)
  2110.       THEN  _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2111.                        Strings.StrPas(gszMsgFileNotFound[gdbCurLanguage]) +
  2112.                        gsInFileName,
  2113.                         errSrcOpenFailed);
  2114.     {if-then}
  2115.  
  2116.   {** create the destination file **}
  2117.     System.Assign(gfOutputStream,gsOutFileName);
  2118.     {$I-} System.Rewrite(gfOutputStream); {$I+}
  2119.  
  2120.   {** creation failed? **}
  2121.     IF  (System.IOResult <> errOK)
  2122.       THEN   _ErrorHalt(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2123.                         Strings.StrPas(gszMsgFileNotCreated[gdbCurLanguage]) +
  2124.                         gsOutFileName,
  2125.                          errDestCreateFailed);
  2126.     {if-then}
  2127.  
  2128.   {** load binary file if need **}
  2129.     IF  (gsStartBinaryFileName <> asBlankStr)
  2130.       THEN  _LoadBinaryFile(gsStartBinaryFileName);
  2131.     {if-then}
  2132.  
  2133.  
  2134.   {** load code translation file if need **}
  2135.     IF  (gsTranslBinFileName <> asBlankStr)
  2136.       THEN  _LoadCodeTranslFile(gsTranslBinFileName);
  2137.     {if-then}
  2138.  
  2139.  
  2140.   {** splite a input/output filenames **}
  2141.     Dos.FSplit(gsInFileName,gsInFileDirStr,gsInFileNameStr,gsInFileExtStr);
  2142.     Dos.FSplit(gsOutFileName,gsOutFileDirStr,gsOutFileNameStr,gsOutFileExtStr);
  2143.  
  2144.  
  2145.   {** get current date/time **}
  2146.     Dos.GetDate(gdwCurrentYear,gdwCurrentMonth,gdwCurrentDay,gdwCurrentWeekDay);
  2147.     Dos.GetTime(gdwCurrentHour,gdwCurrentMinute,gdwCurrentSec,gdwCurrentSec100);
  2148.  
  2149.  
  2150.   {** get input file date/time **}
  2151.     Dos.GetFTime(gfInputStream,gliFileTime);
  2152.     Dos.UnpackTime(gliFileTime,grecFileDateTime);
  2153.     WITH grecFileDateTime DO
  2154.            gdwFileDayOfWeek := _fndwCalcDayOfWeek(Year,
  2155.                                                   Month,
  2156.                                                   Day,
  2157.                                                   gdwCurrentYear,
  2158.                                                   gdwCurrentMonth);
  2159.     {with-do}
  2160.  
  2161.   {** user message: source -> destination **}
  2162.     _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2163.                      Strings.StrPas(gszMsgPrintStart[gdbCurLanguage]) +
  2164.                      gsInFileNameStr +
  2165.                      gsInFileExtStr +
  2166.                      Strings.StrPas(gszMsgTo[gdbCurLanguage]) +
  2167.                      gsOutFileNameStr +
  2168.                      gsOutFileExtStr);
  2169.  
  2170.   {** get file date/time **}
  2171.     WITH grecFileDateTime  DO
  2172.             gsFileDateStamp  := _fnsDateTimeStamp(Year,
  2173.                                                   Month,
  2174.                                                   Day,
  2175.                                                   gdwFileDayOfWeek,
  2176.                                                   Hour,
  2177.                                                   Min);
  2178.     {with-do}
  2179.  
  2180.   {** get print date/time **}
  2181.      gsPrintDateStamp := _fnsDateTimeStamp(gdwCurrentYear,
  2182.                                            gdwCurrentMonth,
  2183.                                            gdwCurrentDay,
  2184.                                            gdwCurrentWeekDay,
  2185.                                             gdwCurrentHour,
  2186.                                             gdwCurrentMinute);
  2187.  
  2188.   {** user message: valid keys during the printing **}
  2189.     _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage]) +
  2190.                      Strings.StrPas(gszMsgUserAvailableKeys[gdbCurLanguage]));
  2191.  
  2192.   {** set a pointer **}
  2193.   gpszLargeInBuf := @gszLargeInBuf;
  2194.  
  2195.   {** main loop: read_line/process_line **}
  2196.   WHILE  (NOT(gbPrintDone)) AND NOT(System.Eof(gfInputStream)) DO
  2197.   BEGIN
  2198.     _ProcessLine(_fnszFileRead(gfInputStream,gpszLargeInBuf));
  2199.   END;
  2200.   { while-do }
  2201.  
  2202.  
  2203.   {** output last line **}
  2204.     _FormFeed;
  2205.  
  2206.   {** load binary file if need **}
  2207.     IF  (gsEndBinaryFileName <> asBlankStr)
  2208.       THEN  BEGIN
  2209.          _OutputTextStrLn(asBlankStr);
  2210.      _LoadBinaryFile(gsEndBinaryFileName);
  2211.        END;
  2212.     {if-then}
  2213.  
  2214.   {** write End-Of-File **}
  2215.     _PrintLine(achDosEndFile,System.False,System.False);
  2216.  
  2217.   {** close all files **}
  2218.     System.Close(gfInputStream);
  2219.     System.Close(gfOutputStream);
  2220.  
  2221.   {** put newline char and write report**}
  2222.     _OutputTextStrLn(asBlankStr);
  2223.     IF (gbPrintStatisticsOK)
  2224.        THEN  _OutputTextStrLn(Strings.StrPas(gszProgramPrompt[gdbCurLanguage])+
  2225.                               Strings.StrPas(gszMsgPrintDone[gdbCurLanguage])+
  2226.                               _fnsNumToStr(gdwFirstPageNumber,0)+
  2227.                               asMsgHyphen+
  2228.                               _fnsNumToStr(gdwOutPageNumber,0));
  2229.     {if-then}
  2230.  
  2231.   {* System.Halt(errTerminateOk); *}
  2232.  
  2233. END.
  2234.