home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / s5 / extend.pas < prev    next >
Pascal/Delphi Source File  |  1990-12-27  |  28KB  |  1,130 lines

  1. unit extend;
  2. {$D+,I-,R-,S-,F-,V-,B-,L-}
  3. {$M 4096,0,65535}
  4.  
  5. interface
  6.  
  7. uses
  8. crt,dos;
  9.  
  10.  
  11. type
  12. range              =  set of char;
  13. str12              =  string[12];
  14. str20              =  string[20];
  15. filename           =  str12;
  16. screenptr          =  ^screentype;
  17. screentype         =  record
  18.                         pos  :  array[1..25,1..80] of record
  19.                                                         ch :  char;
  20.                                                         at :  byte;
  21.                                                       end;
  22.                       end;
  23.  
  24.  
  25. const
  26. _spmax             :  byte  = 80;
  27. _zmax              :  byte  = 25;
  28. _inpwinsp          :  byte  = 20;
  29. _inpwinz           :  byte  = 11;
  30. _inpwinlen         :  byte  = 40;
  31. _dirwinmax         :  byte  = 60;
  32. _dirwinsp          :  byte  = 15;
  33. _dirwinz           :  byte  = 7;
  34. _dirwinfwide       :  byte  = 13;
  35. _dirwinanzsp       :  byte  = 4;
  36. _auswahl_chpos     :  byte  = 1;
  37.  
  38. terminator         :  range = [#13,#27];
  39. extterminator      :  range = [#1..#27];
  40. csrterm            :  range = [#73,#81];
  41. jn                 :  range = ['J','j','Y','y','N','n'];
  42. buchstaben         :  range = ['A'..'Z','a'..'z'];
  43. filechar           :  range = ['A'..'Z','a'..'z','_','.','\',':'];
  44. wildcards          :  range = ['*','?'];
  45. umlaute            :  range = ['Ü','ü','Ö','ö','Ä','ä','ß'];
  46. grossbuchstaben    :  range = ['A'..'Z','Ä','Ö','Ü'];
  47. kleinbuchstaben    :  range = ['a'..'z','ä','ö','ü','ß'];
  48. ziffern            :  range = ['0'..'9'];
  49. vorzeichen         :  range = ['+','-'];
  50. punkt              :  range = ['.'];
  51. binchar            :  range = ['0','1'];
  52. hexchar            :  range = ['0'..'9','A'..'F'];
  53. backspace          =  #8;
  54. space              =  #32;
  55. esc                =  #27;
  56. cr                 =  #13;
  57. lf                 =  #10;
  58. ff                 =  #12;
  59. f1                 =  #59;
  60. f2                 =  #60;
  61. f3                 =  #61;
  62. f4                 =  #62;
  63. f5                 =  #63;
  64. f6                 =  #64;
  65. f7                 =  #65;
  66. f8                 =  #66;
  67. f9                 =  #67;
  68. f10                =  #68;
  69. sf1                =  #84;
  70. sf2                =  #85;
  71. sf3                =  #86;
  72. sf4                =  #87;
  73. sf5                =  #88;
  74. sf6                =  #89;
  75. sf7                =  #90;
  76. sf8                =  #91;
  77. sf9                =  #92;
  78. sf10               =  #93;
  79. cf1                =  #94;
  80. cf2                =  #95;
  81. cf3                =  #96;
  82. cf4                =  #97;
  83. cf5                =  #98;
  84. cf6                =  #99;
  85. cf7                =  #100;
  86. cf8                =  #101;
  87. cf9                =  #102;
  88. cf10               =  #103;
  89. af1                =  #104;
  90. af2                =  #105;
  91. af3                =  #106;
  92. af4                =  #107;
  93. af5                =  #108;
  94. af6                =  #109;
  95. af7                =  #110;
  96. af8                =  #111;
  97. af9                =  #112;
  98. af10               =  #113;
  99. csr_up             =  #72;
  100. csr_dn             =  #80;
  101. csr_l              =  #75;
  102. csr_r              =  #77;
  103. pgup               =  #73;
  104. pgdn               =  #81;
  105. home               =  #71;
  106. ende               =  #79;
  107. initdrucker        =  #27'@'#24;
  108. schmalschriftein   =  #15;
  109. schmalschriftaus   =  #18;
  110. normalschriftein   =  #27'T';
  111. fettdruckein       =  #27'E';
  112. fettdruckaus       =  #27'F';
  113. elite              =  #27'M';
  114. pica               =  #27'P';
  115. doppeldruckein     =  #27'G';
  116. doppeldruckaus     =  #27'H';
  117. tiefstellenein     =  #27'S1';
  118. hochstellenein     =  #27'S0';
  119. breitschriftein    =  #27'W1';
  120. breitschriftaus    =  #27'W0';
  121. unterstreichenein  =  #27'-1';
  122. unterstreichenaus  =  #27'-0';
  123. kursivein          =  #27'4';
  124. kursivaus          =  #27'5';
  125.  
  126. messageattr        :  byte = $F0;
  127. frageattr          :  byte = $F0;
  128. inputattr          :  byte = $F0;
  129. fensterattr        :  byte = $70;
  130. auswahlattr        :  byte = $17;
  131. normalattr         :  byte = $07;
  132. highlightattr      :  byte = $F0;
  133. askmask            :  boolean = true;
  134. extterm            :  boolean = false;
  135. _80x87             :  boolean = false;
  136. _game              :  boolean = false;
  137. _dma               :  boolean = false;
  138. screenadr          :  word = $B800;
  139. screen_init        :  boolean = false;
  140.  
  141. var
  142. com1               :  word    absolute $0040:$0000;
  143. com2               :  word    absolute $0040:$0002;
  144. com3               :  word    absolute $0040:$0004;
  145. com4               :  word    absolute $0040:$0006;
  146. lpt1               :  word    absolute $0040:$0008;
  147. lpt2               :  word    absolute $0040:$000A;
  148. lpt3               :  word    absolute $0040:$000C;
  149. lpt4               :  word    absolute $0040:$000E;
  150. equipment          :  word    absolute $0040:$0010;
  151. ram                :  word    absolute $0040:$0013;
  152. kbdstat            :  byte    absolute $0040:$0017;
  153. videomode          :  byte    absolute $0040:$0049;
  154. cursor_form        :  word    absolute $0040:$0060;
  155. doszeit            :  longint absolute $0040:$006C;
  156. anz_hd             :  byte    absolute $0040:$0075;
  157. last_fd            :  byte    absolute $0050:$0004;
  158. computer           :  byte    absolute $F000:$FFFE;
  159. anz_fd             :  byte;
  160. anz_com            :  byte;
  161. anz_lpt            :  byte;
  162. regs               :  registers;
  163. fkey,ja            :  boolean;
  164. ch,key             :  char;
  165. mask               :  string;
  166. screen             :  screenptr;
  167. screenbuffer       :  array[1..6] of screenptr;
  168. value              :  range;
  169. errnum             :  word;
  170. wahlterm           :  byte;
  171. _wherex,_wherey    :  byte;
  172. _windmin,_windmax  :  word;
  173. _textattr          :  word;
  174. max_screen         :  word;
  175. dira               :  array[1..100] of str12;
  176.  
  177. function  tstbit (zahl : word; bitnr : byte) : boolean;
  178. function  setbit (zahl : word; bitnr : byte) : word;
  179. function  clrbit (zahl : word; bitnr : byte) : word;
  180. function  bytehex (b : byte) : string;
  181. function  bytebin (b : byte) : string;
  182. function  wordhex (w : word) : string;
  183. function  wordbin (w : word) : string;
  184. procedure save_cursor;
  185. procedure restore_cursor;
  186. procedure save_window;
  187. procedure restore_window;
  188. procedure save_textattr;
  189. procedure restore_textattr;
  190. procedure cursor_block;
  191. procedure cursor_ein;
  192. procedure cursor_aus;
  193. procedure write_screen( s,z : integer; str : string);
  194. procedure screen_attr(nr,ss,es,sz,ez : integer; attr : byte);
  195. procedure init_screen( max : integer );
  196. procedure save_screen( i : integer );
  197. procedure restore_screen( i : integer);
  198. procedure getkey;
  199. procedure std_inout;
  200. procedure crt_inout;
  201. function  upstring(s : string) : string;
  202. function  lostring(s : string) : string;
  203. function  exist(n : string) : boolean;
  204. function  load_screen(i : integer; n : string) : boolean;
  205. procedure rahmen(s,z,b,h : integer);
  206. procedure fenster(s,z,b,h : integer);
  207. procedure wait(s : word);
  208. procedure p1(attr : byte);
  209. procedure message(s : string);
  210. function  frage_jn(s : string) : boolean;
  211. procedure input_str(msg : string;VAR s : string; l : integer; valid : range);
  212. function  input_int(s : string;a : boolean;l : integer; i, min, max : longint) : longint;
  213. function  input_real(s : string;a : boolean;l, d : integer; i, min, max : real) : real;
  214. procedure read_str(VAR s : string; l : integer; valid : range);
  215. function  read_int(a : boolean;l : integer; i, min, max : longint) : longint;
  216. function  read_real(a : boolean;l, d : integer; i, min, max : real) : real;
  217. function  int_to_str(i : longint; w : integer) : string;
  218. function  real_to_str(r : real; w,d : integer) : string;
  219. function  int_from_str(z : string; von,len : integer) : longint;
  220. function  real_from_str(z : string; von,len : integer) : real;
  221. function  int_from_cmdline(nr,von,bis : integer) : longint;
  222. function  real_from_cmdline(nr : integer;von,bis : real) : real;
  223. procedure Auswahl(xPos,yPos,Breite,Spalten : INTEGER;
  224.                   UmRahmung : BOOLEAN; AnzahlBytes : INTEGER;
  225.                   VAR Menue; Anzahl : INTEGER; VAR Wahl : INTEGER);
  226. function  dirwin : string;
  227.  
  228. implementation
  229.  
  230. const
  231. spaces             =  '                                                                                ';
  232. line               =  '════════════════════════════════════════════════════════════════════════════════';
  233.  
  234. var
  235. i,j,max            :  integer;
  236. path               :  string;
  237. srec               :  searchrec;
  238.  
  239.  
  240. function  tstbit (zahl : word; bitnr : byte) : boolean;
  241.  
  242. begin
  243.   tstbit           := (((zahl shr bitnr) and 1) = 1);
  244. end;
  245.  
  246.  
  247. function  setbit (zahl : word; bitnr : byte) : word;
  248.  
  249. begin
  250.   setbit           := zahl or (1 shl bitnr);
  251. end;
  252.  
  253.  
  254. function  clrbit (zahl : word; bitnr : byte) : word;
  255.  
  256. begin
  257.   clrbit           := zahl and not (1 shl bitnr);
  258. end;
  259.  
  260.  
  261. function  bytehex (b : byte) : string;
  262.  
  263. var
  264. nl,nh              :  byte;
  265.  
  266. begin
  267.   nh               := b div 16;
  268.   if (nh > 9) then inc(nh,7);
  269.   nl               := b mod 16;
  270.   if (nl > 9) then inc(nl,7);
  271.   bytehex          := chr(nh+48) + chr(nl+48);
  272. end;
  273.  
  274.  
  275. function  bytebin (b : byte) : string;
  276.  
  277. const
  278. c                  :  array[1..8] of byte = (128,64,32,16,8,4,2,1);
  279.  
  280. var
  281. n                  :  integer;
  282. s                  :  str20;
  283.  
  284. begin
  285.   s                := '';
  286.   for n            := 1 to 8 do
  287.     if (c[n] > b) then
  288.       s            := s + '0'
  289.     else
  290.     begin
  291.       s            := s + '1';
  292.       b            := b - c[n];
  293.     end;
  294.   bytebin          := s;
  295. end;
  296.  
  297.  
  298. function  wordhex (w : word) : string;
  299.  
  300. begin
  301.   wordhex          := bytehex(hi(w)) + bytehex(lo(w));
  302. end;
  303.  
  304.  
  305. function  wordbin (w : word) : string;
  306.  
  307. begin
  308.   wordbin          := bytebin(hi(w)) + bytebin(lo(w));
  309. end;
  310.  
  311.  
  312. procedure save_cursor;
  313.  
  314. begin
  315.   _wherex          := wherex;
  316.   _wherey          := wherey;
  317. end;
  318.  
  319.  
  320. procedure restore_cursor;
  321.  
  322. begin
  323.   gotoxy(_wherex,_wherey);
  324. end;
  325.  
  326.  
  327. procedure save_window;
  328.  
  329. begin
  330.   _windmin         := windmin;
  331.   _windmax         := windmax;
  332. end;
  333.  
  334.  
  335. procedure restore_window;
  336.  
  337. begin
  338.   windmin          := _windmin;
  339.   windmax          := _windmax;
  340. end;
  341.  
  342.  
  343. procedure save_textattr;
  344.  
  345. begin
  346.   _textattr        := textattr;
  347. end;
  348.  
  349.  
  350. procedure restore_textattr;
  351.  
  352. begin
  353.   textattr         := _textattr;
  354. end;
  355.  
  356.  
  357. procedure cursor( l,h : byte );
  358.  
  359.  
  360. begin
  361.   regs.ah          := 1;
  362.   regs.cl          := l;
  363.   regs.ch          := h;
  364.   intr   (16,regs);
  365. end;
  366.  
  367.  
  368. procedure cursor_block;
  369.  
  370. begin
  371.   if (videomode = 7) then
  372.     cursor (13, 0)
  373.   else
  374.     cursor ( 7, 0);
  375. end;
  376.  
  377.  
  378. procedure cursor_ein;
  379.  
  380. begin
  381.   if (videomode = 7) then
  382.     cursor (13,12)
  383.   else
  384.     cursor ( 7, 6);
  385. end;
  386.  
  387.  
  388. procedure cursor_aus;
  389.  
  390. begin
  391.   if (videomode = 7) then
  392.     cursor ( 0,14)
  393.   else
  394.     cursor ( 0, 1);
  395. end;
  396.  
  397.  
  398. procedure write_screen( s,z : integer; str : string);
  399.  
  400. var
  401. i                  :  integer;
  402.  
  403. begin
  404.     if ((s in [1.._spmax]) and (z in [1.._zmax])) then
  405.     begin
  406.       dec(s);
  407.       if ((length(str) +  s)  <= _spmax) then
  408.         for i      := 1 to length(str) do
  409.           screen^.pos[z,s+i].ch := str[i];
  410.     end;
  411. end;
  412.  
  413.  
  414. procedure screen_attr(nr,ss,es,sz,ez : integer; attr : byte);
  415.  
  416. var
  417. i                  :  integer;
  418.  
  419. begin
  420.   if (screen_init and (nr <= max_screen)) then
  421.   begin
  422.     if ((ss in [1.._spmax]) and (es in [1.._spmax])  and
  423.         (sz in [1.._zmax ]) and (ez in [1.._zmax])) then
  424.     begin
  425.       for j        := sz to ez do
  426.         for i      := ss to es do
  427.           screenbuffer[nr]^.pos[j,i].at := attr;
  428.     end;
  429.   end;
  430. end;
  431.  
  432.  
  433. procedure save_screen( i : integer );
  434.  
  435. begin
  436.   if (screen_init and (i <= max_screen)) then
  437.     screenbuffer[i]^         := screen^;
  438. end;
  439.  
  440.  
  441. procedure restore_screen( i : integer );
  442.  
  443. begin
  444.   if (screen_init and (i <= max_screen)) then
  445.     screen^        := screenbuffer[i]^;
  446. end;
  447.  
  448.  
  449. procedure getkey;
  450.  
  451. begin
  452.   while keypressed do key := readkey;
  453.  
  454.   repeat
  455.   until keypressed;
  456.  
  457.   key              := readkey;
  458.   if (key = #0) then
  459.   begin
  460.     key            := readkey;
  461.     fkey           := true;
  462.     ja             := false;
  463.   end
  464.   else
  465.   begin
  466.     fkey           := false;
  467.     ja             := (upcase(key) in ['Y','J']);
  468.   end;
  469. end;
  470.  
  471.  
  472. procedure std_inout;
  473.  
  474. begin
  475.   assign (input,''); Reset (input);
  476.   assign (output,''); Rewrite (output);
  477. end;
  478.  
  479.  
  480. procedure crt_inout;
  481.  
  482. begin
  483.   close(input); assignCrt (input); Reset (input);
  484.   close(output); assignCrt (output); Rewrite (output);
  485. end;
  486.  
  487.  
  488. function upstring(s : string) : string;
  489.  
  490. var
  491. i                  :  integer;
  492.  
  493. begin
  494.   for i            := 1 to length(s) do s[i] := upcase(s[i]);
  495.   upstring         := s;
  496. end;
  497.  
  498.  
  499. function lostring(s : string) : string;
  500.  
  501. var
  502. i                  :  integer;
  503.  
  504. begin
  505.   for i            := 1 to length(s) do
  506.   if (s[i] in ['A'..'Z']) then
  507.     s[i]           := char(byte(s[i])+32);
  508.   lostring         := s;
  509. end;
  510.  
  511.  
  512. function exist(n : string) : boolean;
  513.  
  514. var
  515. f                  : file;
  516.  
  517. begin
  518.   assign (f,n);
  519.   (*$I-*)
  520.   reset (f);
  521.   errnum           := ioresult;
  522.   (*$I+*)
  523.   if errnum = 0 then close (f);
  524.   exist            := (errnum = 0);
  525. end;
  526.  
  527.  
  528. function load_screen(i : integer; n : string) : boolean;
  529.  
  530. var
  531. f                  :  file;
  532. ids                :  word;
  533.  
  534. begin
  535.   if ((screen_init and (i <= max_screen)) or (i = 0)) then
  536.   begin
  537.   if exist(n) then
  538.   begin
  539.     assign (f,n);
  540.     reset (f,1);
  541.     if (filesize(f) = (_spmax*_zmax*2)) then
  542.     begin
  543.       if i=0 then
  544.         blockread(f,screen^,(_spmax*_zmax*2),ids)
  545.       else
  546.         blockread(f,screenbuffer[i]^,(_spmax*_zmax*2),ids);
  547.       load_screen  := true;
  548.     end
  549.     else
  550.       load_screen  := false;
  551.     close (f);
  552.   end
  553.   else
  554.     load_screen    := false;
  555.   end;
  556. end;
  557.  
  558.  
  559. procedure rahmen(s,z,b,h : integer);
  560.  
  561. var
  562. i                  :  integer;
  563.  
  564. begin
  565.   gotoxy (s, z);
  566.   write  ('╒',copy(line,1,b),'╕');
  567.   gotoxy (s,z+h+1);
  568.   write  ('╘',copy(line,1,b),'╛');
  569.   for i            := z+1 to z+h do
  570.   begin
  571.     gotoxy (s, i);
  572.     write  ('│',copy(spaces,1,b),'│');
  573.   end;
  574. end;
  575.  
  576.  
  577. procedure fenster(s,z,b,h : integer);
  578.  
  579. begin
  580.   textattr         := fensterattr;
  581.   rahmen(s,z,b,h);
  582.   window(s+1,z+1,s+b,z+h);
  583.   clrscr;
  584. end;
  585.  
  586.  
  587. procedure wait(s : word);
  588.  
  589. begin
  590.   for i            := 1 to s * 1000 do
  591.   begin
  592.     delay(1);
  593.     if keypressed then
  594.     begin
  595.       ch           := readkey;
  596.       exit;
  597.     end;
  598.   end;
  599. end;
  600.  
  601.  
  602.  
  603. procedure Auswahl(xPos,yPos,Breite,Spalten : INTEGER;
  604.                   UmRahmung : BOOLEAN; AnzahlBytes : INTEGER;
  605.                   VAR Menue; Anzahl : INTEGER; VAR Wahl : INTEGER);
  606. (*                                                                          *)
  607. (*   p Auswahl(xPos,yPos,Breite,Spalten,UmRahmung,                          *)
  608. (*             AnzahlBytes,Menue,Anzahl,Wahl                                *)
  609. (*      xPos, yPos : Bildschirm-Koordinaten des ersten Menüpunktes          *)
  610. (*      Breite     : (INTEGER) Breite des Leuchtbalkens                     *)
  611. (*      Spalten    : (INTEGER) Anzahl der Tabellen-Spalten                  *)
  612. (*      UmRahmung  : (BOOLEAN) Rahmen zeichnen oder nicht                   *)
  613. (*      AnzahlBytes: (INTEGER) = SizeOf(Menue[1])                           *)
  614. (*      Menue      : (ARRAY[1..Anzahl] OF STRING[X]) das Menü               *)
  615. (*      Anzahl     : (INTEGER) Anzahl der angezeigten Menüpunkte            *)
  616. (*      Wahl       : (VAR INTEGER)                                          *)
  617. (*                     >0 Der gewählte Punkt                                *)
  618. (*                     =0 Auswahl wurde über <ESC> verlassen                *)
  619.  
  620.    TYPE StrPtr = ^String;
  621.    VAR  MenueStr : ARRAY[1..255] OF StrPtr;
  622.         Zeilen, i,j : INTEGER;
  623.         term : range;
  624.  
  625.  
  626.    PROCEDURE Locate(Nr : INTEGER);
  627.      BEGIN
  628.        gotoxy(xPos+(pred(Nr) DIV Zeilen)*Breite,yPos+(pred(Nr) MOD Zeilen))
  629.      END (* Locate *);
  630.  
  631.    PROCEDURE Print(Nr : INTEGER);
  632.      VAR i : INTEGER;
  633.      BEGIN
  634.        Write(copy(MenueStr[Nr]^,1,Breite));
  635.        FOR i:=succ(length(MenueStr[Nr]^)) TO Breite DO Write(' ')
  636.      END (* Print *);
  637.  
  638.    PROCEDURE ChangeHighLight(VAR alt, neu : INTEGER);
  639.      BEGIN
  640.        Locate(alt); textattr := auswahlattr; Print(alt);
  641.        Locate(neu); textattr := highlightattr; Print(neu);
  642.        Locate(neu); textattr := auswahlattr; alt:=neu;
  643.      END (* ChangeHighLight *);
  644.  
  645.    BEGIN
  646.      cursor_aus;
  647.      save_textattr;
  648.      textattr      := auswahlattr;
  649.      term          := terminator;
  650.      if extterm then term := extterminator;
  651.      Zeilen:=pred(Anzahl+Spalten) DIV Spalten; Wahl:=Wahl AND 255;
  652.      IF UmRahmung THEN Rahmen(xPos-1,yPos-1,Breite*Spalten,Zeilen);
  653.      IF (Wahl>Anzahl) OR (Wahl<1) THEN Wahl:=1;
  654.      FOR i:=1 TO Anzahl DO BEGIN
  655.        MenueStr[i]:=Ptr(Seg(Menue),Ofs(Menue)+pred(i)*AnzahlBytes);
  656.        Locate(i); IF i=Wahl THEN textattr := highlightattr ELSE textattr := auswahlattr;
  657.        Print(i)
  658.      END; (* FOR *)
  659.      Locate(Wahl); i:=Wahl;
  660.      REPEAT
  661.        IF i<>Wahl THEN ChangeHighLight(i,Wahl);
  662.        getkey;
  663.        if fkey then
  664.        begin
  665.          CASE key OF
  666.          csr_l : IF Wahl>Zeilen THEN Wahl:=Wahl-Zeilen ELSE
  667.                  IF Wahl>1 THEN Wahl:=Wahl+pred(Spalten)*Zeilen-1 ELSE
  668.                  WAHL:=Anzahl;
  669.          csr_r : IF Wahl<=Anzahl-Zeilen THEN Wahl:=Wahl+Zeilen ELSE
  670.                  IF (Wahl>pred(Spalten)*Zeilen) AND (Wahl<Anzahl)
  671.                  THEN Wahl:=Wahl-pred(Spalten)*Zeilen+1 ELSE
  672.                  Wahl:=1;
  673.          csr_up: IF Wahl>1 THEN Wahl:=Wahl-1
  674.                  ELSE Wahl:=Anzahl;
  675.          csr_dn: IF Wahl<Anzahl THEN Wahl:=Wahl+1
  676.                  ELSE Wahl:=1;
  677.          home  : Wahl:=1;
  678.          ende  : Wahl:=Anzahl;
  679.          END (* CASE *)
  680.        end
  681.        else
  682.        begin
  683.          if (upcase(key) in buchstaben) then
  684.          begin
  685.            if (upcase(key) = copy(MenueStr[Wahl]^,_auswahl_chpos,1)) then
  686.              j := Wahl
  687.            else
  688.              j := 0;
  689.            repeat
  690.              inc(j);
  691.            until (j >= Anzahl) or (upcase(key) = copy(MenueStr[j]^,_auswahl_chpos,1));
  692.            if (upcase(key) = copy(MenueStr[j]^,_auswahl_chpos,1)) then
  693.              Wahl := j;
  694.          end;
  695.          if ((key in ziffern) and ((ord(key)-48) <= Anzahl)) then
  696.          begin
  697.            Wahl := ord(key)-48;
  698.          end;
  699.        end;
  700.        if (key = esc) then wahl := 0;
  701.      UNTIL ((key in term) and not fkey) or (fkey and (key in csrterm));
  702.    wahlterm := byte(key);
  703.    restore_textattr;
  704.    cursor_ein;
  705.    END (* Auswahl *);
  706.  
  707.  
  708. procedure p9;
  709.  
  710. begin
  711.   delay(500);
  712.   restore_textattr;
  713.   if screen_init then restore_screen(max_screen);
  714. end;
  715.  
  716.  
  717. function dirwin : string;
  718.  
  719. var
  720. marked             :  integer;
  721. ende               :  boolean;
  722.  
  723.  
  724. procedure sortdira(von,bis : integer);
  725.  
  726. var
  727. i,j                :  integer;
  728. s                  :  str12;
  729.  
  730. begin
  731.   for i            := von to bis do
  732.     for j          := von to bis do
  733.       if dira[j] > dira[i] then
  734.       begin
  735.         s          := dira[i];
  736.         dira[i]    := dira[j];
  737.         dira[j]    := s;
  738.       end;
  739. end;
  740.  
  741. procedure dir;
  742.  
  743. begin
  744.   srec.name        := '*.*';
  745.   i                := 0;
  746.   findfirst(copy(path,1,length(path)-length(mask))+'*.*',$20+$10,srec);
  747.   while not (doserror = 18) and (i <= _dirwinmax) do
  748.   begin
  749.     if srec.attr = Directory then
  750.     begin
  751.       if srec.name <> '.' then
  752.       begin
  753.         inc(i);
  754.         dira[i]    := srec.name + '\';
  755.       end;
  756.     end;
  757.     findnext(srec);
  758.   end;
  759.   max              := i;
  760.   if (i > 1) then sortdira(1,i);
  761.  
  762.   srec.name        := path;
  763.   findfirst(path,Archive or Hidden,srec);
  764.   while not (doserror = 18) and (i <= _dirwinmax) do
  765.   begin
  766.       inc(i);
  767.       if ((srec.attr and Hidden) = Hidden) then
  768.         dira[i]    := lostring(srec.name)
  769.       else
  770.         dira[i]    := srec.name;
  771.     findnext(srec);
  772.   end;
  773.   if dira[1] = (copy(path,1,3) + mask) then dec(i);
  774.  
  775.   if (i > max+1) then sortdira(max+1,i);
  776.   max              := i;
  777. end;
  778.  
  779. begin
  780.   if screen_init then save_screen(max_screen);
  781.   save_textattr;
  782.   if askmask then input_str('Suchmaske',mask,12,filechar + wildcards);
  783.   if (key <> esc) then
  784.   begin
  785.   getdir(0,path);
  786.   if length(path) > 3 then path := path + '\';
  787.   path             := path + mask;
  788.   repeat
  789.   clrscr;
  790.   dir;
  791.   if max < 1 then
  792.   begin
  793.     max            := 1;
  794.     dira[max]      := 'No files!';
  795.   end;
  796.   marked           := 1;
  797.   ende             := true;
  798.   auswahl(_dirwinsp,_dirwinz,_dirwinfwide,_dirwinanzsp,true,sizeof(dira[1]),dira,max,marked);
  799.   if (marked > 0) then
  800.   begin
  801.     if (dira[marked][length(dira[marked])] = '\') then
  802.     begin
  803.       ende         := false;
  804.         if dira[marked] = '..\' then
  805.         begin
  806.           if path <> mask then
  807.           begin
  808.             i      := length(path)-length(mask)-1;
  809.             while (path[i] <> '\') do dec(i);
  810.             delete(path,i,length(path)-length(mask)-i);
  811.           end;
  812.         end
  813.         else
  814.         begin
  815.           delete(dira[marked],length(dira[marked]),1);
  816.           dira[marked] := '\' + dira[marked];
  817.           insert(dira[marked],path,length(path)-length(mask));
  818.         end;
  819.     end
  820.     else
  821.       dirwin       := copy(path,1,length(path)-length(mask)) + dira[marked];
  822.   end;
  823.   if (marked < 1) or (dira[1] = 'No files!') then
  824.     dirwin         := '<ESC>';
  825.   until ende;
  826.   if (length(path)-length(mask)) > 3 then
  827.     chdir(copy(path,1,length(path)-length(mask)-1))
  828.   else
  829.     chdir(copy(path,1,length(path)-length(mask)));
  830.   end
  831.   else
  832.     dirwin         := '<ESC>';
  833.   p9;
  834. end;
  835.  
  836.  
  837. procedure p1(attr : byte);
  838.  
  839. begin
  840.   if screen_init then save_screen(max_screen);
  841.   save_textattr;
  842.   textattr         := attr;
  843.   rahmen(_inpwinsp-1,_inpwinz-1,_inpwinlen,1);
  844.   gotoxy(_inpwinsp,_inpwinz);
  845. end;
  846.  
  847.  
  848. procedure message(s : string);
  849.  
  850. begin
  851.   p1(messageattr);
  852.   write (s);
  853.   wait(4);
  854.   p9;
  855. end;
  856.  
  857.  
  858. function frage_jn(s : string) : boolean;
  859.  
  860. begin
  861.   p1(frageattr);
  862.   if length(s) > (_inpwinlen-14) then delete(s,(_inpwinlen-14),255);
  863.   write  (s + ' (J/N): ');
  864.   repeat
  865.     getkey;
  866.   until (key in jn);
  867.  
  868.   if ja then
  869.     writeln('Ja')
  870.   else
  871.     writeln('Nein');
  872.  
  873.   frage_jn         := ja;
  874.   p9;
  875. end;
  876.  
  877.  
  878. procedure read_str(VAR s : string; l : integer; valid : range);
  879.  
  880. var
  881. i, j, x, y         :  integer;
  882.  
  883. begin
  884.   i                := length(s);
  885.   x                := wherex;
  886.   y                := wherey;
  887.   gotoxy (x,y);
  888.   write  (s);
  889.   for j            := i + 1 to l do write  ('_');
  890.   repeat
  891.     repeat
  892.       gotoxy (x + i,y);
  893.       key          := readkey;
  894.     until (key in terminator) or (key in valid) or (key = backspace);
  895.     if ((key in valid) and (i < l)) then
  896.     begin
  897.       inc(i);
  898.       s            := s + key;
  899.       write  (key);
  900.     end
  901.     else
  902.     begin
  903.       if (key = backspace) and (i > 0) then
  904.       begin
  905.         dec(i);
  906.         delete(s,length(s),1);
  907.         gotoxy (x + i,y);
  908.         write  ('_');
  909.       end;
  910.     end;
  911.   until (key in terminator);
  912. end;
  913.  
  914.  
  915. function read_int(a : boolean;l : integer; i, min, max : longint) : longint;
  916.  
  917. var
  918. j                  :  integer;
  919. s                  :  string;
  920.  
  921. begin
  922.   save_cursor;
  923.   repeat
  924.     if a then
  925.       str(i, s)
  926.     else
  927.       s            := '';
  928.     restore_cursor;
  929.     read_str(s, l, vorzeichen + ziffern);
  930.     val(s, i, j);
  931.   until (j = 0) and ((i >= min) and (i <= max));
  932.   read_int         := i;
  933. end;
  934.  
  935.  
  936. function read_real(a : boolean;l, d : integer; i, min, max : real) : real;
  937.  
  938. var
  939. j                  :  integer;
  940. s                  :  string;
  941.  
  942. begin
  943.   save_cursor;
  944.   repeat
  945.     if a then
  946.       str(i:0:d, s)
  947.     else
  948.       s            := '';
  949.     restore_cursor;
  950.     read_str(s, l, vorzeichen + punkt + ziffern + [',']);
  951.     for j          := 1 to length(s) do
  952.       if s[j] = ',' then s[j] := '.';
  953.     val(s, i, j);
  954.   until (j = 0) and ((i >= min) and (i <= max));
  955.   read_real        := i;
  956. end;
  957.  
  958.  
  959. procedure p3(VAR msg : string;l : integer);
  960.  
  961. begin
  962.   if (length(msg)+l) > 35 then delete(msg,35-l,255);
  963.   write  (msg + ': ');
  964. end;
  965.  
  966.  
  967. procedure input_str(msg : string;VAR s : string; l : integer; valid : range);
  968.  
  969. begin
  970.   p1(inputattr);
  971.   p3(msg,l);
  972.   read_str(s,l,valid);
  973.   p9;
  974. end;
  975.  
  976.  
  977. function input_int(s : string;a : boolean;l : integer; i, min, max : longint) : longint;
  978.  
  979. begin
  980.   p1(inputattr);
  981.   p3(s,l);
  982.   input_int        := read_int(a,l,i,min,max);
  983.   p9;
  984. end;
  985.  
  986.  
  987. function input_real(s : string;a : boolean;l, d : integer; i, min, max : real) : real;
  988.  
  989. begin
  990.   p1(inputattr);
  991.   p3(s,l);
  992.   input_real       := read_real(a,l,d,i,min,max);
  993.   p9;
  994. end;
  995.  
  996.  
  997. function  int_to_str(i : longint; w : integer) : string;
  998.  
  999. var
  1000. s                  :  string;
  1001.  
  1002. begin
  1003.   str(i:w,s);
  1004.   int_to_str       := s;
  1005. end;
  1006.  
  1007.  
  1008.  
  1009. function  real_to_str(r : real; w,d : integer) : string;
  1010.  
  1011. var
  1012. s                  :  string;
  1013.  
  1014. begin
  1015.   str(r:w:d,s);
  1016.   real_to_str      := s;
  1017. end;
  1018.  
  1019.  
  1020. function int_from_str(z : string; von,len : integer) : longint;
  1021.  
  1022. var
  1023. i,j                :  integer;
  1024. r                  :  longint;
  1025. s                  :  string;
  1026.  
  1027. begin
  1028.   s                := copy(z,von,len);
  1029.   for i            := 1 to length(s) do
  1030.     if not (s[i] in (vorzeichen + ziffern)) then s[i] := '0';
  1031.  
  1032.   val(s,r,j);
  1033.   if j = 0 then
  1034.     int_from_str   := r
  1035.   else
  1036.     int_from_str   := 0;
  1037. end;
  1038.  
  1039.  
  1040. function real_from_str(z : string; von,len : integer) : real;
  1041.  
  1042. var
  1043. i,j                :  integer;
  1044. r                  :  real;
  1045. s                  :  string;
  1046. begin
  1047.   s                := copy(z,von,len);
  1048.   for i            := 1 to length(s) do
  1049.     if not (s[i] in (vorzeichen + ziffern + punkt)) then s[i] := '0';
  1050.  
  1051.   val(s,r,j);
  1052.   if j = 0 then
  1053.     real_from_str  := r
  1054.   else
  1055.     real_from_str  := 0.0;
  1056. end;
  1057.  
  1058.  
  1059. function int_from_cmdline(nr,von,bis : integer) : longint;
  1060.  
  1061. var
  1062. i,j                :  integer;
  1063. r                  :  longint;
  1064.  
  1065. begin
  1066.   val(paramstr(nr),r,i);
  1067.   if ((i <> 0) or (r < von) or (r > bis)) then
  1068.   begin
  1069.     writeln('Parameter ',paramstr(nr),' ungültig.');
  1070.     halt(nr);
  1071.   end;
  1072.   int_from_cmdline := r;
  1073. end;
  1074.  
  1075.  
  1076. function real_from_cmdline(nr : integer;von,bis : real) : real;
  1077.  
  1078. var
  1079. i                  :  integer;
  1080. r                  :  real;
  1081.  
  1082. begin
  1083.   val(paramstr(nr),r,i);
  1084.   if ((i <> 0) or (r < von) or (r > bis)) then
  1085.   begin
  1086.     writeln('Parameter ',paramstr(nr),' ungültig.');
  1087.     halt(nr);
  1088.   end;
  1089.   real_from_cmdline:= r;
  1090. end;
  1091.  
  1092.  
  1093. procedure init_screen( max : integer );
  1094.  
  1095. begin
  1096.   if screen_init then exit;
  1097.   if max > 6 then max := 6;
  1098.   for i            := 1 to max do
  1099.     new(screenbuffer[i]);
  1100.  
  1101.   screen_init      := true;
  1102.   max_screen       := max;
  1103. end;
  1104.  
  1105.  
  1106. (* Initialisierung der UNIT *)
  1107.  
  1108. begin
  1109.   _wherex          := 1;
  1110.   _wherey          := 1;
  1111.   mask             := '*.*';
  1112.  
  1113.   if (videomode = 7) then
  1114.     screenadr      := $B000;
  1115.  
  1116.   new(screen);
  1117.   screen           := ptr(screenadr,$0000);
  1118.  
  1119.   _dma             := (equipment and $0100) = $0100;
  1120.   _game            := (equipment and $1000) = $1000;
  1121.   _80x87           := (equipment and $0002) = $0002;
  1122.   anz_lpt          := hi(equipment) shr 6;
  1123.   anz_com          := hi(equipment) and $0F shr 1;
  1124.   if (equipment and $0001) = 1 then
  1125.     anz_fd         := lo(equipment) shr 6 + 1
  1126.   else
  1127.     anz_fd         := 0;
  1128.  
  1129. end.
  1130.