home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / strings.swg / 0113_BASIC String Functions.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-05-27  |  44.2 KB  |  1,160 lines

  1.  
  2. {  File:  Basics.Pas }
  3. {+------------------------------------------------------------------+}
  4. {: Unit  : Basics   ( BASIC functions in Turbo Pascal )             :}
  5. {+------------------------------------------------------------------+}
  6. {: Author : Joseph L. Cousins                                       :}
  7. {:                                                                  :}
  8. {:    for : Sierra Consultants                                      :}
  9. {:          3500 Hawthorne Road                                     :}
  10. {:          Fredericksburg, Virginia 22407-6819                     :}
  11. {:          (703) 785-9472, (703) 786-2316                          :}
  12. {:          CompuServe ID = [70245,374]                             :}
  13. {:          Internet      = jcousins@ix.netcom.com                  :}
  14. {:                                                                  :}
  15. {: Copyright (c) 1992-95 by Sierra Consultants  All Rights Reserved :}
  16. {:                                                                  :}
  17. {+------------------------------------------------------------------+}
  18. Unit Basics;
  19.  
  20. Interface
  21.  
  22. Uses
  23.     Dos,
  24.     CRT,
  25.     Printer;
  26. {.pa}
  27. {+------------------------------------------------------------------+}
  28. {: The following are the descriptions of the Functions and Procedures}
  29. {+------------------------------------------------------------------+}
  30. Function Left(inString : String; numChars : Byte) : String;
  31. Function Right(inString : String; numChars : Byte) : String;
  32. Function Len(inString : String) : Byte;
  33. Function LTrim(inString : String) : String;
  34. Function RTrim(inString : String) : String;
  35. Function Trim(inString : String) : String;
  36. Function Empty(inString : String) : Boolean;
  37. Function SubStr(inString : String; numChars, strSize : Byte) : String;
  38. Function PutStr(inString,putString: String; where: Byte) : String;
  39. Function Stuff(putString, inString: String; where: Integer) : String;
  40. Function Lower(inString : String) : String;
  41. Function Upper(inString : String) : String;
  42. Function Instr(Temp_Item: String; From, Size: Byte): String;
  43. Function NoTrailZeros(tempStr : String) : String;
  44. Function MkStr(I,W:Integer) : String;
  45. Function Spaces(i:Byte):String;
  46. Function LeadZeros(inString :String) : String;
  47. Function Str2Bin(inString :String) : Real;
  48. Function IfStr( Text, Pattern : String) : Integer;
  49. Function PrnOk : Boolean;
  50. Procedure LPrint(PrnString : String);
  51. Procedure Eject;
  52. Procedure Beep;
  53. Function Time : String;
  54. Function Date : String;
  55. Function Month : String;
  56. Function WeekDay : String;
  57. Function DayOfWeek( Day : Integer ): String;
  58. Function DateStr : String;
  59. Function Fix(x : Real): Real;
  60. Function Int(x : Real): Real;
  61. Function OCT( Value : Longint ): String;
  62. Function Hex( Value : Longint ): String;
  63. Function ASC( inString : String ): Byte;
  64. Function RAD( Degrees : Real ): Real;
  65. Function DEG( Radians : Real ): Real;
  66. Function LOG( x : Real ): Real;
  67. Function SGN( x : Integer ): Integer;
  68. Procedure DefSeg( SegValue : Integer );
  69. Function Peek( Offset : Word ): Byte;
  70. Function PeekW( Offset : Word ): Word;
  71. Function PeekL( Offset : Word ): Longint;
  72. Procedure Poke( Offset: Word; Value : Byte );
  73. Function TAN( x : Real ): Real;  { input must be in radians }
  74. Function Input( prompt : String): String;
  75. Function InputS( prompt : String): String;
  76. Function InputI( prompt : String): Integer;
  77. Function InputR( prompt : String): Real;
  78. Procedure PrintAT(Row, Col : Word; Tex : string);
  79. Procedure Print(Tex : String);
  80. Procedure CursorOn;
  81. Procedure CursorOff;
  82. {.pa}
  83. const
  84.  
  85.   WeekDays : Array[1..7] of String =
  86.                          ('Sunday','Monday','Tuesday','Wednesday',
  87.                           'Thursday','Friday','Saturday');
  88.  
  89.   Months   : Array[1..12] of String =
  90.                           ('January','February','March','April','May',
  91.                            'June','July','August','September','October',
  92.                            'November','December');
  93.   CR = Chr(13);
  94.   LF = Chr(10);
  95.   FF = Chr(12);
  96.   ESC = Chr(27);
  97.   BS = Chr(08);
  98.   Space = ' ';
  99.   Yes = True;
  100.   No = False;
  101.  
  102. Var
  103.    Segment  : Word;         { Preset to zero }
  104.    GMT      : Boolean;
  105.    Suppress : Boolean;
  106.  
  107. Implementation
  108.  
  109. {+-------------------------------------------------------+}
  110. {: Function :  PrnOk ( checks status of printer )        :}
  111. {+-------------------------------------------------------+}
  112. {:    Syntax : PrnOk                                     :}
  113. {:                                                       :}
  114. {:    Action : Test printer status through MSDOS and     :}
  115. {:             returns TRUE if printer is available.     :}
  116. {:                                                       :}
  117. {: Result Type :  Boolean                                :}
  118. {+-------------------------------------------------------+}
  119. Function PrnOk: Boolean;
  120. Var
  121.   Rg : Registers;
  122. Begin
  123.   Rg.AH    := $02;  { Get Status }
  124.   Rg.DX    := $0000; { Use printer 0 }
  125.   Intr($17,Rg);  { MsDos Service request    }
  126.   PrnOk := True;
  127.   If Rg.AH <> $90 then
  128.     PrnOk := False
  129. End;
  130. {.pa}
  131.  
  132. {+-------------------------------------------------------+}
  133. {: Procedure : LPrint ( Print string to printer )        :}
  134. {+-------------------------------------------------------+}
  135. {:    Syntax : LPrint ( <expS1> )                        :}
  136. {:                                                       :}
  137. {:     Where : <expS1> = String expression               :}
  138. {:                                                       :}
  139. {:    Action : Sends the string expression to the printer:}
  140. {:             using the MSDOS interrupt 17h.            :}
  141. {:                                                       :}
  142. {+-------------------------------------------------------+}
  143. Procedure LPrint(PrnString : String);
  144. Var
  145.   Pi,Pj : Integer;
  146.   Rg : Registers;
  147. Begin
  148.   If PrnOk then
  149.     Begin
  150.       PrnString := PrnString+CR+LF;
  151.       Pj := Ord(PrnString[0]);
  152.       For Pi := 1 To Pj Do
  153.         Begin
  154.           Rg.AL := Ord(PrnString[Pi]);
  155.           Rg.AH := $00;
  156.           Rg.DX := $0000;
  157.           Intr($17,Rg);
  158.         End;
  159.     End;
  160. End;
  161. {.pa}
  162.  
  163. Procedure Eject;
  164. Begin
  165.   LPrint(FF);   { do an eject on printer}
  166. End;
  167.  
  168. Procedure Beep;
  169. Begin
  170.   Write(Chr(07));
  171. End;
  172. {.pa}
  173. {+---------------------------------------------------------------------+}
  174. {: Function FIX   -    Truncates x to an integer                       :}
  175. {+---------------------------------------------------------------------+}
  176. {: format :    v = FIX(x)                                              :}
  177. {:                         FIX strips all  digits to the right of the  :}
  178. {:                         decimal point and returns the value of the  :}
  179. {:                         digits to the left of the decimal point.    :}
  180. {:                                                                     :}
  181. {:  The difference between FIX and INT is that FIX does not return the :}
  182. {:  next lower number when x is negative.                              :}
  183. {+---------------------------------------------------------------------+}
  184. FUNCTION Fix(x : Real): Real;
  185. Begin
  186.   Fix := x - Frac(x);
  187. End;
  188.  
  189. {+---------------------------------------------------------------------+}
  190. {: Function INT   -    Truncates x to an integer                       :}
  191. {+---------------------------------------------------------------------+}
  192. {: format :    v = INT(x)                                              :}
  193. {:                         INT strips all  digits to the right of the  :}
  194. {:                         decimal point and returns the value of the  :}
  195. {:                         digits to the left of the decimal point.    :}
  196. {:                                                                     :}
  197. {:  The difference between FIX and INT is that FIX does not return the :}
  198. {:  next lower number when x is negative.                              :}
  199. {+---------------------------------------------------------------------+}
  200. FUNCTION Int(x : Real): Real;
  201. Begin
  202.   If x < 0 Then
  203.     If Frac(x) >= 0.5 Then
  204.       Int := (x+1) - Frac(x)
  205.     Else
  206.       Int := Fix(x)
  207.   Else
  208.     Int := Fix(x)
  209. End;
  210. {.pa}
  211. {+-----------------------------------------------------------+}
  212. {: Procedure:    T i m e  ( convert system time to string )  :}
  213. {+-----------------------------------------------------------+}
  214. {:   This Procedure Builds the current time of day by getting:}
  215. {: the time from DOS and converting it To ascii.             :}
  216. {+-----------------------------------------------------------+}
  217. Function Time: String;
  218. Var
  219.    AmPm : Char;
  220.    Hr, Mn, Sc, Sc100 : Word;
  221.    t1, t2, t3 : String;
  222. Begin
  223.   GetTime(Hr,Mn,Sc,Sc100);
  224.   AmPm := 'a';
  225.   If Hr >= 12 Then
  226.     Begin
  227.       AmPm := 'p';
  228.       If GMT = False then
  229.         Begin
  230.           If Hr > 12 Then
  231.             Hr := Hr - 12;
  232.         End;
  233.     End;
  234.   Str(Hr:2,t1);
  235.   If GMT then
  236.     If Hr < 10 Then
  237.       t1[1] := Chr(48);
  238.   Str(Mn:2,t2);
  239.   If Mn < 10 Then
  240.     t2[1] := Chr(48);
  241.   Str(Sc:2,t3);
  242.   If Sc < 10 Then
  243.     t3[1] := Chr(48);
  244.   If GMT Then
  245.     AmPm := ' ';
  246.   Time := t1+':'+t2+':'+t3+AmPm;
  247. End;
  248. {.pa}
  249. {+-----------------------------------------------------------+}
  250. {: Procedure:    D a t e   ( convert system date to ascii )  :}
  251. {+-----------------------------------------------------------+}
  252. {:   This Procedure Builds the current Date by getting the   :}
  253. {: date from DOS and converting it To an ascii string.       :}
  254. {+-----------------------------------------------------------+}
  255. Function Date : String;
  256. Var
  257.    Y,M,D,Week  : Word;
  258.    t1, t2, t3 : String;
  259. Begin
  260.   GetDate(Y,M,D,Week);
  261.   Str(M:2,t1);
  262.   If M < 10  Then
  263.     t1[1] := '0';
  264.   Str(D:2,t2);
  265.   If D < 10 Then
  266.     t2[1] := '0';
  267.   Str(Y:4,t3);
  268.   Date := t1+'/'+t2+'/'+t3;
  269. End;
  270. {.pa}
  271.  
  272. {+-------------------------------------------------------+}
  273. {: Function :  Month   ( get name of month )             :}
  274. {+-------------------------------------------------------+}
  275. {:    Syntax : Month                                     :}
  276. {:                                                       :}
  277. {:    Action : Obtains date from MSDOS and returns the   :}
  278. {:             ASCII string containing the Name of the   :}
  279. {:             current Month.                            :}
  280. {:                                                       :}
  281. {: Result Type :  String                                 :}
  282. {+-------------------------------------------------------+}
  283. Function Month : String;
  284. Var
  285.    Y,M,D,Week  : Word;
  286. Begin
  287.   GetDate(Y,M,D,Week);
  288.   Month := Months[M];
  289. End;
  290. {.pa}
  291. {+-------------------------------------------------------+}
  292. {: Function :  WeekDay ( get day of week )               :}
  293. {+-------------------------------------------------------+}
  294. {:    Syntax : WeekDay                                   :}
  295. {:                                                       :}
  296. {:    Action : Obtains date from MSDOS and returns the   :}
  297. {:             ASCII string containing the Name of the   :}
  298. {:             current Day of the Week.                  :}
  299. {:                                                       :}
  300. {: Result Type :  String                                 :}
  301. {+-------------------------------------------------------+}
  302. Function WeekDay : String;
  303. Var
  304.    Y,M,D,Week  : Word;
  305. Begin
  306.   GetDate(Y,M,D,Week);
  307.   WeekDay := WeekDays[Week+1];
  308. End;
  309. {.pa}
  310. {+-------------------------------------------------------+}
  311. {: Function :  DayOfWeek  ( Get Day of the Week )        :}
  312. {+-------------------------------------------------------+}
  313. {:    Syntax : DayOfWeek ( <expN1> )                     :}
  314. {:                                                       :}
  315. {:    Action : Uses Day input value to obtain Weekday    :}
  316. {:             ASCII string from constant array.         :}
  317. {:                                                       :}
  318. {: Result Type :  String                                 :}
  319. {+-------------------------------------------------------+}
  320. Function DayOfWeek( Day : Integer ): String;
  321. Begin
  322.   DayOfWeek := WeekDays[Day+1];
  323. End;
  324.  
  325. {+-------------------------------------------------------+}
  326. {: Function :  DateStr  ( return date string )           :}
  327. {+-------------------------------------------------------+}
  328. {:    Syntax : DateStr                                   :}
  329. {:                                                       :}
  330. {:    Action : Obtains date from MSDOS and returns the   :}
  331. {:             ASCII string containing the Month, the    :}
  332. {:             Day, the Year and the Day-of-Week         :}
  333. {:                                                       :}
  334. {: Result Type :  String                                 :}
  335. {+-------------------------------------------------------+}
  336. Function DateStr : String;
  337. Var
  338.    Y,M,D,Week  : Word;
  339.    t1, t2, t3 : String;
  340. Begin
  341.   GetDate(Y,M,D,Week);
  342.   Str(M:2,t1);
  343.   If M < 10  Then
  344.     t1[1] := '0';
  345.   Str(D:2,t2);
  346.   If D < 10 Then
  347.     t2[1] := '0';
  348.   Str(Y:4,t3);
  349.   DateStr := Months[M]+' '+t2+', '+t3+' - '+WeekDay;
  350. End;
  351. {.pa}
  352. {+-------------------------------------------------------+}
  353. {: Function :  LEFT                                      :}
  354. {+-------------------------------------------------------+}
  355. {:    Syntax : LEFT ( <expC> , <expN> )                  :}
  356. {:                                                       :}
  357. {:     where : <expC> = character string                 :}
  358. {:             <expN> = number of characters to return   :}
  359. {:                      Integer value                    :}
  360. {:                                                       :}
  361. {:    Action : Returns a specified number of characters  :}
  362. {:             in the character string <expC>, starting  :}
  363. {:             from the leftmost character.              :}
  364. {:                                                       :}
  365. {: Result Type :  String                                 :}
  366. {+-------------------------------------------------------+}
  367. Function Left;
  368. Begin
  369.   Left := Copy(inString,1,numChars)
  370. End;
  371.  
  372. {+-------------------------------------------------------+}
  373. {: Function :  RIGHT                                     :}
  374. {+-------------------------------------------------------+}
  375. {:    Syntax : RIGHT ( <expC> , <expN> )                 :}
  376. {:                                                       :}
  377. {:     where : <expC> = character string                 :}
  378. {:             <expN> = number of characters to return   :}
  379. {:                      Integer value                    :}
  380. {:                                                       :}
  381. {:    Action : Returns the rightmost <expN> portion of a :}
  382. {:             character string <expC>                   :}
  383. {:                                                       :}
  384. {: Result Type :  String                                 :}
  385. {+-------------------------------------------------------+}
  386. Function Right;
  387. Var
  388.   index : Byte;
  389. Begin
  390.   If numChars >= Length(inString) Then
  391.     Right := inString
  392.   Else
  393.     Begin
  394.       index := Length(inString) - numChars+1;
  395.       Right := Copy(inString,index,numChars)
  396.     End
  397. End;
  398. {.pa}
  399. {+-------------------------------------------------------+}
  400. {: Function :  LEN                                       :}
  401. {+-------------------------------------------------------+}
  402. {:    Syntax : LEN ( <expC> )                            :}
  403. {:                                                       :}
  404. {:     where : <expC> = character string                 :}
  405. {:                                                       :}
  406. {:    Action : Returns the dynamic length of character   :}
  407. {:             string <expC>.  Nonprinting characters    :}
  408. {:             and blanks are counted.                   :}
  409. {:                                                       :}
  410. {: Result Type :  Integer                                :}
  411. {+-------------------------------------------------------+}
  412. Function Len;
  413. Begin
  414.   Len :=  Ord(inString[0]);
  415. End;
  416.  
  417. {+-------------------------------------------------------+}
  418. {: Function :  LTRIM                                     :}
  419. {+-------------------------------------------------------+}
  420. {:    Syntax : LTRIM ( <expC1> )                         :}
  421. {:                                                       :}
  422. {:     where : <expC1> = character string                :}
  423. {:                                                       :}
  424. {:    Action : Returns <expC1> with all leading SPACES   :}
  425. {:             (blanks) removed.                         :}
  426. {:                                                       :}
  427. {: Result Type :  String                                 :}
  428. {+-------------------------------------------------------+}
  429. Function LTrim;
  430. Var
  431.   p : Integer;
  432. Begin
  433.   p := 1;
  434.   While (inString[p] = '') and (p <= Length(inString)) Do
  435.     inc( p );
  436.   If p > 1 Then
  437.     Begin
  438.       Move( inString[p], inString[1], Succ(Length(inString)) - p);
  439.       dec(inString[0], pred(p));
  440.     End;
  441.    LTrim := inString;
  442. End;
  443. {.pa}
  444. {+-------------------------------------------------------+}
  445. {: Function :  RTRIM                                     :}
  446. {+-------------------------------------------------------+}
  447. {:    Syntax : RTRIM ( <expC1> )                         :}
  448. {:                                                       :}
  449. {:     where : <expC1> = character string                :}
  450. {:                                                       :}
  451. {:    Action : Returns <expC1> with all trailing SPACES  :}
  452. {:             (blanks) removed.                         :}
  453. {:                                                       :}
  454. {: Result Type :  String                                 :}
  455. {+-------------------------------------------------------+}
  456. Function RTrim;
  457. Begin
  458.   While inString[Length(inString)] = ' ' Do
  459.     dec( inString[0] );
  460.   RTrim := inString;
  461. End;
  462.  
  463. {+-------------------------------------------------------+}
  464. {: Function :  Trim                                      :}
  465. {+-------------------------------------------------------+}
  466. {:    Syntax :  Trim ( <expC1> )                         :}
  467. {:                                                       :}
  468. {:     where : <expC1> = character string                :}
  469. {:                                                       :}
  470. {:    Action : Returns <expC1> with all trailing SPACES  :}
  471. {:             (blanks) removed.                         :}
  472. {:                                                       :}
  473. {: Result Type :  String                                 :}
  474. {+-------------------------------------------------------+}
  475. Function Trim( inString : String ): String;
  476. Begin
  477.   Trim := RTrim( inString );
  478. End;
  479. {.pa}
  480. {+-------------------------------------------------------+}
  481. {: Function :  EMPTY                                     :}
  482. {+-------------------------------------------------------+}
  483. {:    Syntax : EMPTY ( <expC1> )                         :}
  484. {:                                                       :}
  485. {:     where : <expC1> = character string                :}
  486. {:                                                       :}
  487. {:    Action : Returns TRUE if <expC1> contains only     :}
  488. {:             SPACES (blanks).                          :}
  489. {:                                                       :}
  490. {: Result Type :  Boolean                                :}
  491. {+-------------------------------------------------------+}
  492. Function Empty;
  493. Var
  494.   index : Byte;
  495. Begin
  496.   index := 1;
  497.   Empty := True;
  498.   While (index <= Length(inString))and (index <> 0) do
  499.     Begin
  500.       If inString[index] = ' ' Then
  501.     inc(index)
  502.       Else
  503.     Begin
  504.       Empty := False;
  505.       index := 0
  506.     End;
  507.     End;
  508. End;
  509.  
  510. {.pa}
  511. {+-------------------------------------------------------+}
  512. {: Function :  SUBSTR                                    :}
  513. {+-------------------------------------------------------+}
  514. {:    Syntax : SUBSTR ( <expC>, <expN1>[, <expN2>] )     :}
  515. {:                                                       :}
  516. {:     where : <expC> = character string                 :}
  517. {:             <expN1>,<expN2> = numeric value (Byte)    :}
  518. {:                                                       :}
  519. {:    Action : Returns a string of length <expN2> from   :}
  520. {:             <expC>, beginning with the <expN1>th      :}
  521. {:             character.  The <expN1> and <expN2> must  :}
  522. {:             be in the range 1 to 255.  If <expN2> is  :}
  523. {:             omitted or if there is fewer than <expN2> :}
  524. {:             characters to the right of the <expN1>th  :}
  525. {:             character, all rightmost characters       :}
  526. {:             beginning with the <expN1>th character are:}
  527. {:             returned.  If <expN1> is greater than the :}
  528. {:             number of characters in <expC>, SUBSTR    :}
  529. {:             returns a null string.                    :}
  530. {:                                                       :}
  531. {: Result Type :  String                                 :}
  532. {+-------------------------------------------------------+}
  533. Function SubStr;
  534. Begin
  535.   SubStr := Copy(inString, numChars, StrSize );
  536. End;
  537. {.pa}
  538. {+-------------------------------------------------------+}
  539. {: Function :  PUTSTR                                    :}
  540. {+-------------------------------------------------------+}
  541. {:    Syntax : PUTSTR ( <expC1>, <expC2>, <expN1> )      :}
  542. {:                                                       :}
  543. {:     where : <expC1>,<expC2> = character string        :}
  544. {:             <expN1> = numeric value (Byte)            :}
  545. {:                                                       :}
  546. {:    Action : Replaces a portion of one string <expC1>  :}
  547. {:             with another string <expC2>.  The         :}
  548. {:             characters in <expC1> beginning at        :}
  549. {:             position <expN1> are replaced by the      :}
  550. {:             characters in <expC2>.  The number of     :}
  551. {:             characters replaced is equal to the length:}
  552. {:             of string <expC2>.  However, the          :}
  553. {:             replacement of characters never goes      :}
  554. {:             beyond the original length of <expC1>.    :}
  555. {:                                                       :}
  556. {: Result Type :  String                                 :}
  557. {+-------------------------------------------------------+}
  558. Function PutStr;
  559. Var
  560.   index, j : Byte;
  561. Begin
  562.   index := Ord(putString[0]);    { get size of input string}
  563.   For j := where to where + (index-1) do
  564.     inString[j] := putString[(j+1)-where];
  565.   PutStr := inString;
  566. End;
  567. {.pa}
  568. {+-------------------------------------------------------+}
  569. {: Function :  Stuff                                     :}
  570. {+-------------------------------------------------------+}
  571. {:    Syntax : Stuff  ( <expC1>, <expC2>, <expN1> )      :}
  572. {:                                                       :}
  573. {:     where : <expC1>,<expC2> = character string        :}
  574. {:             <expN1> = numeric value (Byte)            :}
  575. {:                                                       :}
  576. {:    Action : Replaces a portion of one string <expC2>  :}
  577. {:             with another string <expC1>.  The         :}
  578. {:             characters in <expC2> beginning at        :}
  579. {:             position <expN1> are replaced by the      :}
  580. {:             characters in <expC1>.  The number of     :}
  581. {:             characters replaced is equal to the length:}
  582. {:             of string <expC1>.  However, the          :}
  583. {:             replacement of characters never goes      :}
  584. {:             beyond the original length of <expC2>.    :}
  585. {:                                                       :}
  586. {: Result Type :  String                                 :}
  587. {+-------------------------------------------------------+}
  588. Function Stuff;
  589. Begin
  590.   Insert(putString, inString, where);
  591.   Stuff := inString;
  592. End;
  593. {.pa}
  594. {+-------------------------------------------------------+}
  595. {: Function :  LOWER                                     :}
  596. {+-------------------------------------------------------+}
  597. {:    Syntax : LOWER ( <expC1> )                         :}
  598. {:                                                       :}
  599. {:     where : <expC1> = character string                :}
  600. {:                                                       :}
  601. {:    Action : Returns the specified character           :}
  602. {:             expression <expC1> in lowercase.          :}
  603. {:                                                       :}
  604. {: Result Type :  String                                 :}
  605. {+-------------------------------------------------------+}
  606. Function Lower;
  607. Var
  608.   index : Byte;  tempString : String;
  609. Const
  610.     Upset = ['A'..'Z'];
  611.     LowSet = ['a'..'z'];
  612. Begin
  613.   For index := 1 to Length(inString) do
  614.     Begin
  615.       If inString[index] in UpSet Then
  616.     tempString[index] := Chr(Ord(inString[index])+32)
  617.       Else
  618.     TempString[index] := inString[index];
  619.     End;
  620.   Lower := tempString;
  621. End;
  622. {.pa}
  623. {+-------------------------------------------------------+}
  624. {: Function :  UPPER                                     :}
  625. {+-------------------------------------------------------+}
  626. {:    Syntax : UPPER ( <expC1> )                         :}
  627. {:                                                       :}
  628. {:     where : <expC1> = character string                :}
  629. {:                                                       :}
  630. {:    Action : Returns the specified character           :}
  631. {:             expression <expC1> in uppercase.          :}
  632. {:                                                       :}
  633. {: Result Type :  String                                 :}
  634. {+-------------------------------------------------------+}
  635. Function Upper;
  636. Var
  637.   index : Byte;
  638.   tempString : String;
  639. Begin
  640.   For index := 1 to Length(inString) do
  641.      tempString[index] := UpCase(inString[index]);
  642.   tempString[0] := inString[0];
  643.   Upper := tempString;
  644. End;
  645.  
  646. {+-----------------------------------------------------------+}
  647. {: Function:    I n s t r  ( Instring )                      :}
  648. {+-----------------------------------------------------------+}
  649. {:   This function extracts a string beginning at pointer    :}
  650. {: From in string Temp_Item for Size chars and returns Value.:}
  651. {+-----------------------------------------------------------+}
  652. Function Instr;
  653. Begin
  654.   Instr := Copy(Temp_Item, From, Size);
  655. End;
  656. {.pa}
  657. {+-------------------------------------------------------+}
  658. {: Function :  NoTrailZeros                              :}
  659. {+-------------------------------------------------------+}
  660. {:    Syntax : NoTrailZeros ( <expC1> )                  :}
  661. {:                                                       :}
  662. {:     where : <expC1> = character string                :}
  663. {:                                                       :}
  664. {:    Action : Removes trailing Zeros from the specified :}
  665. {:             expression <expC1>.                       :}
  666. {:                                                       :}
  667. {: Result Type :  String                                 :}
  668. {+-------------------------------------------------------+}
  669. Function NoTrailZeros;
  670. Var
  671.   index : Integer;
  672.   tempString : String;
  673. Begin
  674.   While tempStr[Length(tempStr)] = '0' Do
  675.     tempStr[0] := Chr(Length(tempStr)-1);
  676.   NoTrailZeros := tempStr;
  677. End;
  678.  
  679.  
  680. {+-------------------------------------------------------+}
  681. {: Function :  MkStr        ( Make String )              :}
  682. {+-------------------------------------------------------+}
  683. {:    Syntax : MkStr ( <expN1>, <expN2> )                :}
  684. {:                                                       :}
  685. {:     where : <expN1>,<expN2> = numeric values (integer):}
  686. {:                                                       :}
  687. {:    Action : Makes a string of length <expN2> from     :}
  688. {:             Integer expression <expN1>.               :}
  689. {:                                                       :}
  690. {: Result Type :  String                                 :}
  691. {+-------------------------------------------------------+}
  692. Function MkStr;
  693. Var
  694.   temp1 : String;
  695. Begin
  696.   Str(I:W,temp1);
  697.   MKStr := temp1;
  698. End;
  699. {.pa}
  700. {+-------------------------------------------------------+}
  701. {: Function :  Spaces                                    :}
  702. {+-------------------------------------------------------+}
  703. {:    Syntax : Spaces ( <expN1> )                        :}
  704. {:                                                       :}
  705. {:     where : <expN1> = numeric value ( Byte )          :}
  706. {:                                                       :}
  707. {:    Action : Makes a string of length <expN1> which    :}
  708. {:             contains Space characters.                :}
  709. {:                                                       :}
  710. {: Result Type :  String                                 :}
  711. {+-------------------------------------------------------+}
  712. Function Spaces;
  713. Var
  714.   zip : String[255];
  715. Begin
  716.   FillChar(zip,i+1,' ');
  717.   zip[0] := Chr(i);
  718.   Spaces := Zip;
  719. End;
  720.  
  721. {+-------------------------------------------------------+}
  722. {: Function :  LeadZeros                                 :}
  723. {+-------------------------------------------------------+}
  724. {:    Syntax : LeadZeros ( <expC1> )                     :}
  725. {:                                                       :}
  726. {:     where : <expC1> = character string input          :}
  727. {:                                                       :}
  728. {:    Action : replace the leading spaces in a string    :}
  729. {:             with ASCII Zeros.                         :}
  730. {:                                                       :}
  731. {: Result Type :  String                                 :}
  732. {+-------------------------------------------------------+}
  733. Function LeadZeros;
  734. Var i : Integer;
  735. Begin
  736.   i := 1;
  737.   While inString[i] = ' ' do
  738.     Begin
  739.       inString[i] := Chr(48);
  740.       inc(i);
  741.     End;
  742.   LeadZeros := inString;
  743. End;
  744. {.pa}
  745. {+-------------------------------------------------------+}
  746. {: Function :  Str2Bin ( String to Binary )              :}
  747. {+-------------------------------------------------------+}
  748. {:    Syntax : Str2Bin ( <expC1> )                       :}
  749. {:                                                       :}
  750. {:     where : <expC1> = Character string                :}
  751. {:                                                       :}
  752. {:    Action : converts a string containing an ASCII     :}
  753. {:             numeric value to an number.               :}
  754. {:                                                       :}
  755. {: Result Type :  Real                                   :}
  756. {+-------------------------------------------------------+}
  757. Function Str2Bin;
  758. Var
  759.   i : Real;
  760.   k : Integer;
  761. Begin
  762.   Val(inString,i,k);
  763.   Str2Bin := i;
  764. End;
  765.  
  766.  
  767. {+-------------------------------------------------------+}
  768. {: Function :  IfStr ( If StringB in StringA )           :}
  769. {+-------------------------------------------------------+}
  770. {:    Syntax : IfStr (<expC1>,<expC2>)                   :}
  771. {:                                                       :}
  772. {:     where : <expC1> = Character string                :}
  773. {:             <expC2> = Character string                :}
  774. {:                                                       :}
  775. {:    Action : Determines if <expC2> exists within       :}
  776. {:             <expC1>.                                  :}
  777. {:                                                       :}
  778. {: Result Type :  Integer                                :}
  779. {: Result Values :  0 = char not in stringA              :}
  780. {:                  1-n = position of <expC2> within     :}
  781. {:                        <expC1>                        :}
  782. {:                                                       :}
  783. {+-------------------------------------------------------+}
  784. Function IfStr( Text, Pattern  : String) : Integer;
  785. Begin
  786.   IfStr := Pos( Pattern, Text );
  787. End;
  788. {.pa}
  789. {+-------------------------------------------------------+}
  790. {: Function :  Oct   Binary to Octal                     :}
  791. {+-------------------------------------------------------+}
  792. {:    Syntax : Oct ( <expN1> )                           :}
  793. {:                                                       :}
  794. {:     where : <expN1> = Binary number of type Longint   :}
  795. {:                                                       :}
  796. {:    Action : Converts a binary number of type Longint  :}
  797. {:             to a String containing 11 octal Digits.   :}
  798. {:                                                       :}
  799. {: Result Type :  String                                 :}
  800. {+-------------------------------------------------------+}
  801. Function OCT( Value : Longint ) : String;
  802. Var
  803.   i : Integer;
  804.   j : Word;
  805.   t1   : String;
  806.   f : Boolean;
  807. Begin
  808.   If Value < 0 Then
  809.     Begin
  810.       Value := Value - $80000000;
  811.       F := True;
  812.     End
  813.   Else
  814.     F := False;
  815.   For i := 11 DownTo 2 Do
  816.     Begin
  817.       j := Value Mod 8;
  818.       Value := Value Div 8;
  819.       t1[i] := Chr( j+48 );
  820.     End;
  821.   If f Then
  822.     Value := Value + $2;
  823.   j := Value Mod 8;
  824.   t1[1] := Chr( j+48 );
  825.   t1[0] := Chr(11);
  826.   i := 1;
  827.   If Suppress Then
  828.     While t1[i] = '0' Do
  829.       Begin
  830.         t1[i] := ' ';
  831.         inc( i );
  832.       End;
  833.   OCT := LTrim( t1 );
  834. End;
  835. {.pa}
  836. {+-------------------------------------------------------+}
  837. {: Function :  Hex   Binary to Hex                       :}
  838. {+-------------------------------------------------------+}
  839. {:    Syntax : Hex ( <expN1> )                           :}
  840. {:                                                       :}
  841. {:     where : <expN1> = Binary number of type Longint   :}
  842. {:                                                       :}
  843. {:    Action : Converts a binary number of type Longint  :}
  844. {:             to a String containing 8 Hex Digits.      :}
  845. {:                                                       :}
  846. {: Result Type :  String                                 :}
  847. {+-------------------------------------------------------+}
  848. Function Hex( Value : Longint ):String;
  849. Var
  850.    t1 : String;
  851.    i : Integer;
  852.    j : Word;
  853.    f : Boolean;
  854.  
  855.   Function HexChr( HexNibble : Byte ): Char;
  856.   Begin
  857.     If HexNibble < 10 then
  858.       HexChr := Chr(HexNibble+48)
  859.     Else
  860.       HexChr := Chr(HexNibble+55);
  861.   End;
  862. begin
  863.   If Value < 0 Then
  864.     Begin
  865.       Value := Value - $80000000;
  866.       F := True;
  867.     End
  868.   Else
  869.     F := False;
  870.   For i := 8 DownTo 2 Do
  871.     Begin
  872.       j := Value Mod 16;
  873.       Value := Value Div 16;
  874.       t1[i] := HexChr( j );
  875.     End;
  876.   If f Then
  877.     Value := Value + $8;
  878.   j := Value Mod 16;
  879.   t1[1] := HexChr( j );
  880.   t1[0] := Chr(8);
  881.   i := 1;
  882.   If Suppress Then
  883.     While t1[i] = '0' Do
  884.       Begin
  885.         t1[i] := ' ';
  886.         inc( i );
  887.       End;
  888.   HEX := LTrim( t1 );
  889. End;
  890. {.pa}
  891. {+-------------------------------------------------------+}
  892. {: Function :  ASC   Get ASCII code from String          :}
  893. {+-------------------------------------------------------+}
  894. {:    Syntax : ASC ( <expS1> )                           :}
  895. {:                                                       :}
  896. {:     where : <expS1> = ASCII String                    :}
  897. {:                                                       :}
  898. {:    Action : Returns the numeric value of the first    :}
  899. {:             character of the String expression.       :}
  900. {:                                                       :}
  901. {: Result Type :  Byte                                   :}
  902. {+-------------------------------------------------------+}
  903. Function ASC( inString : String ) : Byte;
  904. Begin
  905.   If Length( inString ) > 0 Then
  906.     ASC := Ord( inString[1] )
  907.   Else
  908.     ASC := 0;
  909. End;
  910.  
  911. {+-------------------------------------------------------+}
  912. {: Function :  RAD   Convert from Degrees to Radians     :}
  913. {+-------------------------------------------------------+}
  914. {:    Syntax : RAD ( <expR1> )                           :}
  915. {:                                                       :}
  916. {:     where : <expR1> = Degrees of type Real            :}
  917. {:                                                       :}
  918. {:    Action : Converts a number (REAL) containing       :}
  919. {:             Degrees to one expressed as Radians.      :}
  920. {:                                                       :}
  921. {: Result Type :  Real                                   :}
  922. {+-------------------------------------------------------+}
  923. Function RAD( Degrees : Real ) : Real;
  924. Begin
  925.   RAD := Degrees * ( Pi / 180 );
  926. End;
  927.  
  928. {+-------------------------------------------------------+}
  929. {: Function :  DEG   Convert from Radians to Degrees     :}
  930. {+-------------------------------------------------------+}
  931. {:    Syntax : DEG ( <expR1> )                           :}
  932. {:                                                       :}
  933. {:     where : <expR1> = Radians of type Real            :}
  934. {:                                                       :}
  935. {:    Action : Converts a number (REAL) containing       :}
  936. {:             Radians to one expressed as Degrees.      :}
  937. {:                                                       :}
  938. {: Result Type :  Real                                   :}
  939. {+-------------------------------------------------------+}
  940. Function DEG( Radians : Real ) : Real;
  941. Begin
  942.   DEG := Radians * ( 180 / Pi );
  943. End;
  944. {.pa}
  945. {+-------------------------------------------------------+}
  946. {: Function :  LOG   Returns the Log                     :}
  947. {+-------------------------------------------------------+}
  948. {:    Syntax : DEG ( <expR1> )                           :}
  949. {:                                                       :}
  950. {:     where : <expR1> = number to obtain Log of         :}
  951. {:                                                       :}
  952. {:    Action : Returns the natural Logarithm of the      :}
  953. {:             argument.                                 :}
  954. {:                                                       :}
  955. {: Result Type :  Real                                   :}
  956. {+-------------------------------------------------------+}
  957. Function LOG( x : Real ) : Real;
  958. Begin
  959.   LOG := LN( x );
  960. End;
  961.  
  962. {+-------------------------------------------------------+}
  963. {: Function :  SGN   Returns the Sign of argument        :}
  964. {+-------------------------------------------------------+}
  965. {:    Syntax : DEG ( <expI1> )                           :}
  966. {:                                                       :}
  967. {:     where : <expI1> = number to obtain Sign of        :}
  968. {:                                                       :}
  969. {:    Action : If <expI1> is positive SGN returns 1      :}
  970. {:             If <expI1> is zero     SGN returns 0      :}
  971. {:             If <expI1> is negative SGN returns -1     :}
  972. {:                                                       :}
  973. {: Result Type :  Integer                                :}
  974. {+-------------------------------------------------------+}
  975. Function SGN( x : Integer ): Integer;
  976. Begin
  977.   If x = 0 Then
  978.     SGN := 0
  979.   Else
  980.     If x < 0 Then
  981.       SGN := -1
  982.     Else
  983.       SGN := 1;
  984. End;
  985. {.pa}
  986. {+-------------------------------------------------------+}
  987. {:Procedure :  DEFSEG  (assign current segment register) :}
  988. {+-------------------------------------------------------+}
  989. {:    Syntax : DEFSEG ( <expI1> )                        :}
  990. {:                                                       :}
  991. {:     where : <expI1> = Integer value of Segment Reg    :}
  992. {:                       Segment = Global Variable       :}
  993. {:    Action : Assigns <expI1> to the Segment Register   :}
  994. {+-------------------------------------------------------+}
  995. Procedure DefSeg( SegValue : Integer);
  996. Begin
  997.   Segment := SegValue;
  998. End;
  999.  
  1000. {+-------------------------------------------------------+}
  1001. {: Function :  Peek  Get contents of memory address      :}
  1002. {+-------------------------------------------------------+}
  1003. {:    Syntax : Peek ( <expW1> )                          :}
  1004. {:                                                       :}
  1005. {:     where : <expW1> = Offset of memory address of     :}
  1006. {:                       type Word                       :}
  1007. {:                                                       :}
  1008. {:    Action : Gets contents of memory address as        :}
  1009. {:             Segment:Offset.                           :}
  1010. {:                                                       :}
  1011. {: Result Type :  Byte                                   :}
  1012. {+-------------------------------------------------------+}
  1013. Function Peek( Offset : Word ): Byte;
  1014. Begin
  1015.   Peek := Mem[Segment:Offset];
  1016. End;
  1017.  
  1018. {+-------------------------------------------------------+}
  1019. {: Function :  PeekW  Get contents of memory address     :}
  1020. {+-------------------------------------------------------+}
  1021. {:    Syntax : PeekW  ( <expW1> )                        :}
  1022. {:                                                       :}
  1023. {:     where : <expW1> = Offset of memory address of     :}
  1024. {:                       type Word                       :}
  1025. {:                                                       :}
  1026. {:    Action : Gets contents of memory address as        :}
  1027. {:             Segment:Offset.                           :}
  1028. {:                                                       :}
  1029. {: Result Type :  Word                                   :}
  1030. {+-------------------------------------------------------+}
  1031. Function PeekW( Offset : Word ): Word;
  1032. Begin
  1033.   PeekW := MemW[Segment:Offset];
  1034. End;
  1035. {.pa}
  1036. {+-------------------------------------------------------+}
  1037. {: Function :  PeekL  Get contents of memory address     :}
  1038. {+-------------------------------------------------------+}
  1039. {:    Syntax : PeekL ( <expW1> )                         :}
  1040. {:                                                       :}
  1041. {:     where : <expW1> = Offset of memory address of     :}
  1042. {:                       type Word                       :}
  1043. {:                                                       :}
  1044. {:    Action : Gets contents of memory address as        :}
  1045. {:             Segment:Offset.                           :}
  1046. {:                                                       :}
  1047. {: Result Type :  Longint                                :}
  1048. {+-------------------------------------------------------+}
  1049. Function PeekL( Offset : Word ): Longint;
  1050. Begin
  1051.   PeekL := MemL[Segment:Offset];
  1052. End;
  1053.  
  1054. {+-------------------------------------------------------+}
  1055. {: Procedure : Poke  Put contents of memory address      :}
  1056. {+-------------------------------------------------------+}
  1057. {:    Syntax : Poke ( <expW1>, <expB1> )                 :}
  1058. {:                                                       :}
  1059. {:     where : <expW1> = Offset of memory address of     :}
  1060. {:                       type Word                       :}
  1061. {:                                                       :}
  1062. {:             <expB1> = Byte of data to poke            :}
  1063. {:                                                       :}
  1064. {:    Action : Pokes contents of memory address.         :}
  1065. {:                                                       :}
  1066. {+-------------------------------------------------------+}
  1067. Procedure Poke( Offset: Word; Value : Byte );
  1068. Begin
  1069.   Mem[Segment:Offset] := Value;
  1070. End;
  1071.  
  1072. {+-------------------------------------------------------+}
  1073. {: Function :  TAN   Computes Tangent of Angle           :}
  1074. {+-------------------------------------------------------+}
  1075. {:    Syntax : TAN ( <expR1> )                           :}
  1076. {:                                                       :}
  1077. {:     where : <expR1> = number to obtain TAN of         :}
  1078. {:                                                       :}
  1079. {:    Action : Returns the Tangent of angle in radians   :}
  1080. {:                                                       :}
  1081. {: Result Type :  Real                                   :}
  1082. {+-------------------------------------------------------+}
  1083. Function TAN( x : Real ) : Real;  { input must be in radians }
  1084. Begin
  1085.   TAN := Sin(x)*(1/Cos(x));
  1086. End;
  1087. {.pa}
  1088. Function Input( prompt : String): String;
  1089. Var
  1090.   t1 : String;
  1091. Begin
  1092.   Write(prompt);
  1093.   ReadLn(t1);
  1094.   Input := t1;
  1095. End;
  1096.  
  1097. Function InputS( prompt : String): String;
  1098. Var
  1099.   t1 : String;
  1100. Begin
  1101.   Write(prompt);
  1102.   ReadLn(t1);
  1103.   InputS := t1;
  1104. End;
  1105.  
  1106. Function InputI( prompt : String): Integer;
  1107. Var
  1108.   t1 : String;
  1109. Begin
  1110.   Write(Prompt);
  1111.   ReadLn(t1);
  1112.   InputI := Trunc( Str2Bin( t1 ) );
  1113. End;
  1114.  
  1115. Function InputR( prompt : String): Real;
  1116. Var
  1117.   t1 : String;
  1118. Begin
  1119.   Write(Prompt);
  1120.   ReadLn(t1);
  1121.   InputR := Str2Bin( t1 );
  1122. End;
  1123.  
  1124. Procedure PrintAT(Row, Col : word; Tex : String);
  1125. Begin
  1126.   GotoXY(Row,col);
  1127.   Write(Tex);
  1128. End;
  1129.  
  1130. Procedure Print(Tex : String);
  1131. Begin
  1132.   WriteLn(Tex);
  1133. End;
  1134.  
  1135. {.pa}
  1136. Procedure CursorOn;
  1137. Var
  1138.   Rg : Registers;
  1139. Begin
  1140.   Rg.AH := 1;
  1141.   Rg.CH := 1;
  1142.   Rg.CL := 7;
  1143.   Intr($10,Rg);
  1144. End;
  1145.  
  1146. Procedure CursorOff;
  1147. Var
  1148.   Rg : Registers;
  1149. Begin
  1150.   Rg.AH := 1;
  1151.   Rg.CH := $20;
  1152.   Intr($10,Rg);
  1153. End;
  1154.  
  1155. Begin
  1156.   Segment := 0;
  1157.   GMT := False;
  1158.   Suppress := False;
  1159. End.
  1160.