tw2109.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. { Source provided for Free Pascal Bug Report 2109 }
  2. { Submitted by "Layton Davis" on 2002-09-05 }
  3. { e-mail: [email protected] }
  4. unit tw2109;
  5. interface
  6. { warning!!! -- pascal re-generates every result in an operator statement }
  7. { attributes of the results have to be carried forward from the old value }
  8. { as a work arround we have to ask the user to assign the original destination variable to OldBCD }
  9. { or OldZoned before doing any assignments or arithmetic }
  10. { fixme!!! -- assignment statements are used automatically to provide data }
  11. { type conversion. I need to provide a safety net so that this doesn't create bad behavior }
  12. { from this library }
  13. type
  14. flint = record
  15. data : longint;
  16. dec : byte;
  17. end;
  18. bcddata = array[1..18] of char;
  19. bcd = record
  20. data : ^bcddata;
  21. bcdlen : byte;
  22. bcddec : byte;
  23. end;
  24. zoneddata = array[1..9] of char;
  25. zoned = record
  26. data : ^zoneddata;
  27. zonelen : byte;
  28. zonedec : byte;
  29. end;
  30. operator := (a:bcd) b:Integer;
  31. operator := (a:bcd) b:Longint;
  32. operator := (a:bcd) b:FLInt;
  33. function initbcd(blen, bdec:byte; bcdptr:pointer):bcd;
  34. operator := (a:integer) b:bcd;
  35. operator := (a:longint) b:bcd;
  36. operator := (a:FLInt) b:bcd;
  37. function initzoned(zlen, zdec:byte; zptr:pointer):zoned;
  38. var
  39. OldBCD : bcd;
  40. implementation
  41. operator := (a:bcd) b:Integer;
  42. var
  43. knt : integer;
  44. begin
  45. b := 0;
  46. for knt := 1 to a.bcdlen - a.bcddec do
  47. begin
  48. b := b * 10;
  49. b := b + ord(a.data^[knt]) - ord('0');
  50. end;
  51. end;
  52. operator := (a:bcd) b: LongInt;
  53. var
  54. test : FLInt;
  55. knt : byte;
  56. begin
  57. test := a;
  58. b := test.data;
  59. knt := test.dec;
  60. while knt > 0 do
  61. begin
  62. b := b div 10;
  63. knt := knt - 1;
  64. end;
  65. end;
  66. operator := (a:bcd) b:FLInt;
  67. var
  68. knt : byte;
  69. begin
  70. b.data := 0;
  71. for knt := 1 to a.bcdlen do
  72. b.data := (b.data * 10) + ord(a.data^[knt]) - ord('0');
  73. b.dec := a.bcddec;
  74. end;
  75. operator := (a:FLInt) b:bcd;
  76. var
  77. tmp : FLInt;
  78. knt : byte;
  79. tmpl : longint;
  80. begin
  81. b := oldbcd;
  82. tmp := a;
  83. while tmp.dec < b.bcddec do
  84. begin
  85. tmp.data := tmp.data * 10;
  86. tmp.dec := tmp.dec + 1;
  87. end;
  88. while tmp.dec > b.bcddec do
  89. begin
  90. tmp.data := tmp.data div 10;
  91. tmp.dec := tmp.dec - 1;
  92. end;
  93. for knt := 1 to b.bcdlen do
  94. b.data^[knt] := '0';
  95. knt := b.bcdlen;
  96. while (knt > 0) and (tmp.data > 0) do
  97. begin
  98. tmpl := tmp.data div 10;
  99. tmpl := tmp.data - (tmpl * 10);
  100. b.data^[knt] := char(ord('0') + tmpl);
  101. tmp.data := tmp.data div 10;
  102. knt := knt - 1;
  103. end;
  104. end;
  105. function initbcd(blen, bdec:byte; bcdptr:pointer):bcd;
  106. var
  107. temp : bcd;
  108. knt : integer;
  109. begin
  110. if bcdptr <> NIL then
  111. temp.data := bcdptr
  112. else
  113. new(temp.data);
  114. temp.bcdlen := blen;
  115. temp.bcddec := bdec;
  116. for knt := 1 to blen do {only fill out the space allocated to us -- as we may be part of a data structure}
  117. temp.data^[knt] := '0';
  118. initbcd := temp;
  119. end;
  120. operator := (a:integer) b:bcd;
  121. var
  122. knt : integer;
  123. temp : integer;
  124. temp2 : integer;
  125. begin
  126. b := oldbcd;
  127. for knt := 1 to b.bcdlen do
  128. b.data^[knt] := '0';
  129. knt := b.bcdlen-b.bcddec;
  130. temp := a;
  131. while (knt > 0 ) and (temp > 0) do
  132. begin
  133. temp2 := temp div 10;
  134. temp2 := temp - (temp2 * 10);
  135. temp := temp div 10;
  136. b.data^[knt] := char(ord('0') + temp2);
  137. knt := knt - 1;
  138. end;
  139. end;
  140. operator := (a:longint) b:bcd;
  141. var
  142. knt : integer;
  143. temp : longint;
  144. temp2 : longint;
  145. begin
  146. b := oldbcd;
  147. for knt := 1 to b.bcdlen do
  148. b.data^[knt] := '0';
  149. knt := b.bcdlen-b.bcddec;
  150. temp := a;
  151. while (knt > 0 ) and (temp > 0) do
  152. begin
  153. temp2 := temp div 10;
  154. temp2 := temp - (temp2 * 10);
  155. temp := temp div 10;
  156. b.data^[knt] := char(ord('0') + temp2);
  157. knt := knt - 1;
  158. end;
  159. end;
  160. function initzoned(zlen, zdec:byte; zptr:pointer):zoned;
  161. begin
  162. end;
  163. end.