home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / phreak_utils_pc / extras.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-04-01  |  21.0 KB  |  873 lines

  1. unit EXTRAS;
  2. interface
  3.  
  4. uses types,optimer,bbunit,grwins,mouseio,vgagraph,video,bbp_vars,ferror;
  5.  
  6. const just_clear   = 0;
  7.       pushoutleft  = 1;
  8.       pushoutright = 2;
  9.       pushoutdown  = 3;
  10.       pushoutup    = 4;
  11.  
  12. function  bytefilesize(fn:string):longint;
  13. function  charlot(lotchar:char;times:byte):string;
  14. function  colorselect(initial:byte):byte;
  15. function  date:string;
  16. function  exist(dateiname:string):boolean;
  17. function  getcursorsize :word;
  18. function  parameter(s:string):boolean;
  19. function  randomnr:string;
  20. function  scrambled(s:string):string;
  21. function  stg(w:word):string;
  22. function  stg2(r:real):string;
  23. function  striptrail(s:string):string;
  24. function  time(secs:boolean):string;
  25. function  uppercase(s:string):string;
  26. function  wvalue(s:string):word;
  27. function  yesnotoggle(default:boolean;choice1,choice2:string):boolean;
  28. procedure bottominfo(s:string);
  29. procedure center(y:integer;text:string);
  30. procedure chat(s:string);
  31. procedure clearscreen(method:byte);
  32. procedure cursoroff;
  33. procedure cursoron;
  34. procedure cwrite(s:string);
  35. procedure fadecenter(l:byte;s:string);
  36. procedure fadewrite(s:string);
  37. procedure fadewriteln(s:string);
  38. procedure fwrite(line:integer;eingabe:string);
  39. procedure iwrite(txt:string;itemize:boolean);
  40. procedure logo(x:integer;y:integer;wort:string);
  41. procedure run(prog:string);
  42. procedure scls(zeitraum:integer);
  43. procedure setcursorsize(custart, cuend :byte);
  44. procedure showansi(a:ansi;how:byte);
  45. procedure starten(programm:string);
  46. procedure swrite(input:string);
  47. procedure swriteln(input:string);
  48. procedure tapenter(line:byte);
  49. procedure twrite(input:string);
  50. procedure twritexy(x,y:shortint;input:string);
  51. procedure victorioustune;
  52. procedure vmemwrite(x,y:integer;blah:string;color:byte);
  53. procedure writevisbool(b:boolean;opt1,opt2:string);
  54.  
  55. implementation
  56.  
  57. uses dos,crt;
  58.  
  59. var regs        :Registers;
  60.     CursorSave  :Word;
  61.  
  62. function striptrail(s:string):string;
  63. var s2 :string;
  64. begin
  65.   s2:=s;
  66.   while s2[length(s2)]=#32 do s2:=copy(s2,1,length(s2)-1);
  67.   striptrail:=s2;
  68. end;
  69.  
  70. procedure clearscreen(method:byte);
  71. var lines :array[0..24] of array[0..159] of byte;
  72.     x,y,z :word;
  73. begin
  74.   if method = just_clear then begin
  75.     clrscr;
  76.     exit;
  77.   end;
  78.   if method = pushoutleft then begin
  79.     for x:=0 to 24 do move(mem[vadr:x*160],lines[x],160);
  80.     for x:=1 to 79 do begin
  81.       for y:=0 to 24 do move(lines[y][x*2],mem[vadr:160*y],160-(x*2));
  82.       vsync;
  83.     end;
  84.     clrscr;
  85.     exit;
  86.   end;
  87.   if method = pushoutright then begin
  88.     for x:=0 to 24 do move(mem[vadr:x*160],lines[x],160);
  89.     for x:=0 to 24 do for y:=158 downto 2 do lines[x][y]:=lines[x][y-2];
  90.     for x:=0 to 24 do lines[x][0]:=32;
  91.     for x:=0 to 24 do lines[x][1]:=0;
  92.     for x:=0 to 79 do begin
  93.       for y:=0 to 24 do move(lines[y],mem[vadr:160*y+(x*2)],160-(x*2));
  94.       vsync;
  95.     end;
  96.     clrscr;
  97.     exit;
  98.   end;
  99.   if method = pushoutdown then begin
  100.     gotoxy(1,1);
  101.     for x:=0 to 24 do begin
  102.       insline;
  103.       vsync;
  104.     end;
  105.     clrscr;
  106.     exit;
  107.   end;
  108.   if method = pushoutup then begin
  109.     gotoxy(1,1);
  110.     for x:=0 to 24 do begin
  111.       delline;
  112.       vsync;
  113.     end;
  114.     clrscr;
  115.     exit;
  116.   end;
  117. end;
  118.  
  119. function time(secs:boolean):string;
  120. var h,m,s,hs:word;
  121.     dummy:string;
  122. begin
  123.   dummy:='';
  124.   gettime(h,m,s,hs);
  125.   if h<10 then dummy:='0';
  126.   dummy:=dummy+stg(h)+':';
  127.   if m<10 then dummy:=dummy+'0';
  128.   dummy:=dummy+stg(m);
  129.   if secs then begin
  130.     dummy:=dummy+':';
  131.     if s<10 then dummy:=dummy+'0';
  132.     dummy:=dummy+stg(s);
  133.   end;
  134.   time:=dummy;
  135. end;
  136.  
  137. function date:string;
  138. var y,m,d,dum:word;
  139.     dummy:string;
  140. begin
  141.   getdate(y,m,d,dum);
  142.   dummy:='';
  143.   if m<10 then dummy:='0';
  144.   dummy:=dummy+stg(m)+'-';
  145.   if d<10 then dummy:=dummy+'0';
  146.   dummy:=dummy+stg(d)+'-'+copy(stg(y),3,2);
  147.   date:=dummy;
  148. end;
  149.  
  150. procedure chat(s:string);
  151. var x:byte;
  152. begin
  153.   textattr:=lightgray;
  154.   for x:=1 to length(s) do begin
  155.     write(s[x]);
  156.     delayms(random(140)+50);
  157.   end;
  158.   writeln;
  159.   writeln;
  160.   textattr:=cyan;
  161. end;
  162.  
  163. procedure run(prog:string);
  164. var s:string;
  165.     r:registers;
  166. begin
  167.   s:=prog+#00;
  168.   r.ax:=$4b00;
  169.   r.ds:=seg(s[1]);
  170.   r.dx:=ofs(s[1]);
  171.   intr($21,r);
  172. end;
  173.  
  174. procedure SCls(zeitraum:integer);
  175. var ox,oy,ux,uy :integer;
  176. const zeichen=' ';
  177. procedure wumm(olx,oly,urx,ury:integer);
  178. var wummx:integer;
  179. begin
  180.   gotoxy(olx,oly);
  181.   for wummx:=oly to ury do begin gotoxy(urx,wummx); write(zeichen); delayms(zeitraum); end;
  182.   for wummx:=urx downto olx do begin gotoxy(wummx,ury); write(zeichen); delayms(zeitraum); end;
  183.   for wummx:=ury downto oly do begin gotoxy(olx,wummx); write(zeichen); delayms(zeitraum); end;
  184.   gotoxy(olx,oly);
  185.   for wummx:=1 to urx-olx do begin write(zeichen); delayms(zeitraum); end;
  186. end;
  187. begin
  188.   ox:=1; oy:=1;
  189.   ux:=79; uy:=24;
  190.   while ox<13 do begin
  191.    wumm(ox,oy,ux,uy);
  192.    inc(ox); inc(oy);
  193.    dec(ux); dec(uy);
  194.   end;
  195.   clrscr;
  196. end;
  197.  
  198.  
  199. Procedure Starten(Programm:string);
  200. begin
  201. if Programm <> '' then
  202.     begin
  203.       SwapVectors;
  204.       Exec(GetEnv('COMSPEC'), '/C ' + Programm);
  205.       SwapVectors;
  206.       if DosError <> 0 then begin
  207.         normvideo;
  208.         clrscr;
  209.         WriteLn('Kommandointerpreter fehlt oder ist defekt !');
  210.         Halt(2);
  211.        End;
  212.     end;
  213. end;
  214.  
  215. procedure TWriteXY(x,y:shortint;input:string);
  216.  
  217. var l,a   :integer;
  218.     copied:string[1];
  219.  
  220. begin
  221.   gotoxy(x,y);
  222.   l:=length(input);
  223.     for a:=1 to l do
  224.       begin
  225.         copied:=copy(input,a,1);
  226.         if copied=' ' then
  227.           begin
  228.             write(' ');
  229.             delayms(75);
  230.           end
  231.             else
  232.               begin
  233.                 write(copied);
  234.                 sound(560);
  235.                 delayms(5);
  236.                 nosound;
  237.                 delayms(75);
  238.               end;
  239.       end;
  240. end;
  241.  
  242.  
  243. procedure TWrite(input:string);
  244.  
  245. var l,a   :integer;
  246.     copied:string[1];
  247.  
  248. begin
  249.   l:=length(input);
  250.     for a:=1 to l do
  251.       begin
  252.         copied:=copy(input,a,1);
  253.         if copied=' ' then
  254.           begin
  255.             write(' ');
  256.             delayms(75);
  257.           end
  258.             else
  259.               begin
  260.                 write(copied);
  261.                 sound(560); { Normal: 560 }
  262.                 delayms(5); { Normal: 5 }
  263.                 nosound;
  264.                 delayms(75); { Normal: 75 }
  265.               end;
  266.       end;
  267. end;
  268.  
  269. procedure box(ulx,uly,lrx,lry:integer;shadow:boolean);
  270. var hl,vl,x,xb,oc:integer;
  271. begin
  272.       oc:=textattr;
  273.       if ulx<1 then halt(1);
  274.       if uly<1 then halt(1);
  275.       if lrx>80 then halt(1);
  276.       if lry>25 then halt(1);
  277.       lry:=lry+1;
  278.       lrx:=lrx+1;
  279.       hl:=lrx-ulx-2;
  280.       vl:=lry-uly-2;
  281.       gotoxy(ulx,uly);
  282.       write(chr(201));
  283.       for x:=1 to hl do write(chr(205));
  284.       write(chr(187));
  285.         for x:=1 to vl do
  286.           begin
  287.             gotoxy(ulx,uly+x);
  288.             write(chr(186));
  289.             for xb:=1 to hl do write(' ');
  290.             write(chr(186));
  291.           end;
  292.       gotoxy(ulx,lry-1);
  293.       write(chr(200));
  294.       for x:=1 to hl do write(chr(205));
  295.       write(chr(188));
  296.       if shadow then
  297.         begin
  298.           textcolor(black);
  299.           gotoxy(ulx+2,lry);
  300.           for x:=1 to hl+2 do write(chr(219));
  301.             for x:=uly+1 to lry do
  302.               begin
  303.                 gotoxy(lrx,x);
  304.                 write('██');
  305.               end;
  306.         end;
  307.   textattr:=oc;
  308. end;
  309.  
  310. procedure Center(y:integer;text:string);
  311.  
  312. var laenge,x:integer;
  313.     a      :real;
  314.  
  315. begin
  316.   laenge:=length(text);
  317.   a:=40-(laenge/2);
  318.   x:=round(a);
  319.   gotoxy(x,y);
  320.   write(text);
  321. end;
  322.  
  323. procedure SWrite(input:string);
  324.  
  325. var l,a   :integer;
  326.     copied:string[1];
  327.  
  328. begin
  329.   l:=length(input);
  330.     for a:=1 to l do
  331.       begin
  332.         copied:=copy(input,a,1);
  333.         write(copied);
  334.         delayms(20);
  335.       end;
  336. end;
  337.  
  338. procedure SWriteLn(input:string);
  339. begin
  340.   SWrite(input);
  341.   WriteLn;
  342. end;
  343.  
  344. function GetCursorSize: word;
  345.   begin
  346.     with regs do
  347.       begin
  348.         ah:= 3;
  349.         bh:= 0;
  350.         intr($10, regs);
  351.         GetCursorsize:= cx;
  352.       end;
  353.   end;
  354.  
  355. procedure SetCursorSize(CuStart, CuEnd: Byte);
  356.   begin
  357.     with regs do
  358.       begin
  359.         ah:= 1;
  360.         ch:= CuStart;
  361.         cl:= CuEnd;
  362.         intr($10, regs);
  363.       end;
  364.   end;
  365.  
  366. procedure CursorOff;
  367.   begin
  368.     SetCursorSize($20, $20);
  369.   end;
  370.  
  371. procedure CursorOn;
  372.   begin
  373.     SetCursorSize(hi(CursorSave), lo(CursorSave));
  374.   end;
  375.  
  376. function Exist(Dateiname:string):boolean;
  377. var f:file;
  378. begin
  379.   assign(f,dateiname);
  380.   {$I-} Reset(f); {$I+}
  381.   if ioresult=0 then begin
  382.     close(f);
  383.     exist:=dateiname<>'';
  384.   end else
  385.     exist:=FALSE;
  386. end;
  387.  
  388. function Stg(w:word):String;
  389. var s:string;
  390. begin
  391.   str(w,s);
  392.   stg:=s;
  393. end;
  394.  
  395. function UpperCase(s:string):string;
  396. var Counter: Word;
  397. begin
  398.   if s='' then begin
  399.     uppercase:='';
  400.     exit;
  401.   end;
  402.   for Counter := 1 to Length(S) do
  403.     S[Counter] := UpCase(S[Counter]);
  404.   UpperCase := S;
  405. end;
  406.  
  407. procedure LogoChar(xp,yp:integer;c:char);
  408. var x,y,index,bits:integer;
  409. begin
  410.   for y:=0 to 7 do
  411.     begin
  412.       for x:=0 to 7 do
  413.         begin
  414.           bits:=Mem[$F000:$FB6E+(8*(ord(C)-32))+y];
  415.           gotoxy(xp+x,yp+y);
  416.           if (bits and (1 shl (7-x)))<>0 then write(chr(219));
  417.         end;
  418.       end;
  419.     writeln;
  420.   end;
  421.  
  422. procedure Logo(x,y:Integer;Wort:string);
  423. var i,xp,yp:integer;
  424. begin
  425.   xp:=0;yp:=0;
  426.   for i:=1 to length(wort) do
  427.     begin
  428.       LogoChar(x+xp,y,wort[I]);
  429.       xp:=xp+8
  430.     end;
  431.   yp:=yp+8;
  432. end;
  433.  
  434. procedure FWrite(line:integer;eingabe:string);
  435. type Zeichentyp=record Zeichen:char; Getippt:boolean; end;
  436. var z       :array[1..35] of zeichentyp;
  437.     x       :integer;
  438.     taste   :char;
  439.     geraten :boolean;
  440. begin
  441.   for x:=1 to length(eingabe) do z[x].zeichen:=eingabe[x];
  442.   for x:=length(eingabe)+1 to 35 do z[x].zeichen:=' ';
  443.   for x:=1 to 35 do z[x].getippt:=false;
  444.   taste:=chr(64);
  445.   repeat
  446.     delayms(40);
  447.     taste:=chr(ord(taste)+1);
  448.     for x:=1 to length(eingabe) do if taste=z[x].zeichen then z[x].getippt:=true;
  449.     gotoxy(40-(length(eingabe) div 2),line);
  450.     for x:=1 to length(eingabe) do if z[x].getippt then write(z[x].zeichen)
  451.       else write(' ');
  452.   until ord(taste)>91;
  453. end;
  454.  
  455. procedure fadewrite(s:string);
  456. var x:byte;
  457.     c:char;
  458. begin
  459.   for x:=1 to length(s) do begin
  460.     if x<=length(s) then begin textattr:=blue; write(s[x]); end;
  461.     if x<=length(s)-1 then begin textattr:=lightblue; write(s[x+1]); end;
  462.     if x<=length(s)-2 then begin textattr:=lightcyan; write(s[x+2]); end;
  463.     if x<=length(s)-3 then begin textattr:=white; write(s[x+3]); end;
  464.     delayms(50);
  465.     if x<=length(s)-3 then write(^H^H^H) else
  466.      if x<=length(s)-2 then write(^H^H) else
  467.      if x<=length(s)-1 then write(^H);
  468.   end;
  469. end;
  470.  
  471. procedure fadewriteln(s:string);
  472. begin
  473.   fadewrite(s);
  474.   writeln;
  475. end;
  476.  
  477. procedure fadecenter(L:byte;s:string);
  478. begin
  479.   gotoxy(40-(length(s) div 2),l);
  480.   fadewrite(s);
  481. end;
  482.  
  483. procedure tapenter(line:byte);
  484. const atts:array[1..20] of byte=(darkgray,green,lightgreen,white,lightgreen,
  485.                                 green,darkgray,blue,lightblue,lightcyan,
  486.                                 white,lightcyan,lightblue,blue,darkgray,
  487.                                 red,lightred,white,lightred,red);
  488. var ch:char;
  489.     x :byte;
  490. begin
  491.   repeat
  492.     for x:=1 to 20 do begin
  493.       if not keypressed then begin
  494.         gotoxy(35,line);
  495.         textattr:=atts[x];
  496.         write(' Tap ENTER ');
  497.         delayms(100);
  498.       end;
  499.     end;
  500.     if keypressed then ch:=readkey;
  501.   until ch=#13;
  502. end;
  503.  
  504. procedure showansi(a:ansi;how:byte);
  505. var tr      :array[1..2000] of boolean;
  506.     x,y,all :word;
  507.     sa      :ansi;
  508.  
  509. begin
  510.   move(mem[vadr:0],sa,4000);
  511.   case how of
  512.     1:begin
  513.         for x:=1 to 2000 do tr[x]:=false;
  514.         all:=2000;
  515.         repeat
  516.           repeat y:=random(2000) until tr[y]=false;
  517.           tr[y]:=true;
  518.           dec(all);
  519.           mem[vadr:y*2]:=ord(a[y*2]);
  520.           mem[vadr:y*2+1]:=ord(a[y*2+1]);
  521.           delayms(1);
  522.         until all<=2;
  523.         move(a,mem[vadr:0],4000);
  524.         tapenter(25);
  525.         for x:=1 to 2000 do tr[x]:=false;
  526.         all:=2000;
  527.         repeat
  528.           repeat y:=random(2000) until tr[y]=false;
  529.           tr[y]:=true;
  530.           dec(all);
  531.           mem[vadr:y*2]:=ord(sa[y*2]);
  532.           mem[vadr:y*2+1]:=ord(sa[y*2+1]);
  533.           delayms(1);
  534.         until all<=2;
  535.         move(sa,mem[vadr:0],4000);
  536.       end;
  537.     end;
  538. end;
  539.  
  540. procedure vmemwrite(x,y:integer;blah:string;color:byte);
  541. var i:word;
  542. begin
  543.   for i:=1 to length(blah) do mem[vadr:2*((y-1)*80+(x-2)+i)]:=ord(blah[i]);
  544.   for i:=1 to length(blah) do mem[vadr:2*((y-1)*80+(x-2)+i)+1]:=color;
  545. end;
  546.  
  547. function yesnotoggle(default:boolean;choice1,choice2:string):boolean;
  548. var b,decision   :boolean;
  549.     ch           :char;
  550.     x,saveattr   :byte;
  551. begin
  552.   decision:=false;
  553.   saveattr:=textattr;
  554.   b:=default;
  555.   if b then begin
  556.     textattr:=colors.knob_active;
  557.     write(' ',choice1,' ');
  558.     textattr:=colors.knob_inactive;
  559.     write('  ',choice2,' ');
  560.     for x:=1 to length(choice1)+length(choice2)+5 do write(^H);
  561.   end else begin
  562.     textattr:=colors.knob_inactive;
  563.     write(' ',choice1,'  ');
  564.     textattr:=colors.knob_active;
  565.     write(' ',choice2,' ');
  566.     for x:=1 to length(choice1)+length(choice2)+5 do write(^H);
  567.   end;
  568.   repeat
  569.     repeat ch:=upcase(readkey) until ch in [#13,#27,#0,'Y','N'];
  570.     if ch=#0 then ch:=readkey;
  571.     case ch of
  572.       CurLf,CurRt :b:=not(b);
  573.       'Y'         :begin b:=true; decision:=true; end;
  574.       'N',#27     :begin b:=false; decision:=true; exit; end;
  575.       #13         :decision:=true;
  576.     end;
  577.     if b then begin
  578.       textattr:=colors.knob_active;
  579.       write(' ',choice1,' ');
  580.       textattr:=colors.knob_inactive;
  581.       write('  ',choice2,' ');
  582.       for x:=1 to length(choice1)+length(choice2)+5 do write(^H);
  583.     end else begin
  584.       textattr:=colors.knob_inactive;
  585.       write(' ',choice1,'  ');
  586.       textattr:=colors.knob_active;
  587.       write(' ',choice2,' ');
  588.       for x:=1 to length(choice1)+length(choice2)+5 do write(^H);
  589.     end;
  590.   until decision;
  591.   yesnotoggle:=b;
  592.   textattr:=saveattr;
  593. end;
  594.  
  595. function stg2(r:real):string;
  596. var s:string;
  597. begin
  598.   str(r:0:2,s);
  599.   stg2:=s;
  600. end;
  601.  
  602. function scrambled(s:string):string;
  603. var x  :byte;
  604.     s2 :string;
  605. begin
  606.   if s='' then begin
  607.     scrambled:='';
  608.     exit;
  609.   end;
  610.   s2[0]:=s[0];
  611.   for x:=1 to length(s) do s2[x]:=chr(255-ord(s[x]));
  612.   scrambled:=s2;
  613. end;
  614.  
  615. function parameter(s:string):boolean;
  616. var x:byte;
  617.     b:boolean;
  618. begin
  619.   b:=false;
  620.   for x:=1 to paramcount do begin
  621.     if uppercase(s)=uppercase(paramstr(x)) then b:=true;
  622.   end;
  623.   parameter:=b;
  624. end;
  625.  
  626. procedure writevisbool(b:boolean;opt1,opt2:string);
  627. var saveattr :byte;
  628. begin
  629.   saveattr:=textattr;
  630.   if b then textattr:=colors.knob_active else textattr:=colors.knob_inactive;
  631.   write(' ',opt1,' ');
  632.   textattr:=colors.knob_inactive;
  633.   write(' ');
  634.   if b then textattr:=colors.knob_inactive else textattr:=colors.knob_active;
  635.   write(' ',opt2,' ');
  636.   textattr:=saveattr;
  637. end;
  638.  
  639. function randomnr:string;
  640. const areacodes : array[1..10] of string=('201','202','212','313','405','515',
  641.                                           '619','702','703','706');
  642. var s:string;
  643.     x:byte;
  644. begin
  645.   s:='XXXXXXX';
  646.   randomize;
  647.   for x:=1 to 7 do s[x]:=chr(random(10)+48);
  648.   s:=areacodes[random(10)+1]+s;
  649.   randomnr:=s;
  650. end;
  651.  
  652. procedure bottominfo(s:string);
  653. var save,x,y:byte;
  654. begin
  655.   save:=textattr;
  656.   x:=wherex; y:=wherey;
  657.   textattr:=colors.infoline;
  658.   gotoxy(1,25);
  659.   write(' ',s);
  660.   clreol;
  661.   textattr:=save;
  662.   gotoxy(x,y);
  663. end;
  664.  
  665. procedure victorioustune;
  666. var x:byte;
  667. begin
  668.   for x:=1 to 3 do begin
  669.     sound(1250);
  670.     delayms(50);
  671.     nosound;
  672.     delayms(50);
  673.   end;
  674.   sound(1660);
  675.   delayms(50);
  676.   nosound;
  677.   delayms(200);
  678.   sound(1250);
  679.   delayms(50);
  680.   nosound;
  681.   delayms(50);
  682.   sound(1660);
  683.   delayms(200);
  684.   nosound;
  685. end;
  686.  
  687. procedure cwrite(s:string);
  688. var saveattr,x,pos :byte;
  689. begin
  690.   saveattr:=textattr;
  691.   pos:=1;
  692.   while pos<=length(s) do begin
  693.     if s[pos]='|' then begin
  694.       inc(pos);
  695.       case s[pos] of
  696.         'b' :textcolor(blue);
  697.         'B' :textcolor(lightblue);
  698.         'g' :textcolor(green);
  699.         'G' :textcolor(lightgreen);
  700.         'c' :textcolor(cyan);
  701.         'C' :textcolor(lightcyan);
  702.         'r' :textcolor(red);
  703.         'R' :textcolor(lightred);
  704.         'm' :textcolor(magenta);
  705.         'M' :textcolor(lightmagenta);
  706.         'y' :textcolor(brown);
  707.         'Y' :textcolor(yellow);
  708.         'w' :textcolor(lightgray);
  709.         'W' :textcolor(white);
  710.         'd' :textcolor(darkgray);
  711.         '0' :textbackground(black);
  712.         '1' :textbackground(1);
  713.         '2' :textbackground(2);
  714.         '3' :textbackground(3);
  715.         '4' :textbackground(4);
  716.         '5' :textbackground(5);
  717.         '6' :textbackground(6);
  718.         '7' :textbackground(7);
  719.       else begin
  720.         clrscr;
  721.         writeln('Fatal Error in procedure cwrite() ! No colorcode after | !');
  722.         halt($FF);
  723.       end; end;
  724.     end else write(s[pos]);
  725.     inc(pos);
  726.   end;
  727.   textattr:=saveattr;
  728. end;
  729.  
  730. function wvalue(s:string):word;
  731. var v :word;
  732.     c :integer;
  733. begin
  734.   val(s,v,c);
  735.   if c<>0 then v:=0;
  736.   wvalue:=v;
  737. end;
  738.  
  739. function charlot(lotchar:char;times:byte):string;
  740. var tmp:string;
  741.     x  :byte;
  742. begin
  743.   tmp:='';
  744.   for x:=1 to times do tmp:=tmp+lotchar;
  745.   charlot:=tmp;
  746. end;
  747.  
  748. procedure iwrite(txt:string;itemize:boolean);
  749. var x:byte;
  750.     h,lh:boolean;
  751. begin
  752.   h:=false;
  753.   lh:=true;
  754.   for x:=1 to length(txt) do begin
  755.     if h<>lh then begin
  756.       lh:=h;
  757.       if itemize then if h then textattr:=colors.win_hilight_high
  758.         else textattr:=colors.win_hilight
  759.       else if h then textattr:=colors.win_text_high
  760.         else textattr:=colors.win_text;
  761.     end;
  762.     if txt[x]='~' then h:=not(h) else write(txt[x]);
  763.   end;
  764. end;
  765.  
  766. function bytefilesize(fn:string):longint;
  767. var f :file;
  768. begin
  769.   assign(f,fn);
  770.   {$I-} reset(f,1); {$I+}
  771.   if ioresult<>0 then begin
  772.     bytefilesize:=-1;
  773.     exit;
  774.   end;
  775.   bytefilesize:=filesize(f);
  776.   close(f);
  777. end;
  778.  
  779. function colorselect(initial:byte):byte;
  780. const xbase = 14;
  781.       ybase = 4;
  782.  
  783.       colorname :array[0..15] of string=('Black','Blue','Green','Cyan','Red',
  784.                                          'Magenta','Brown','Gray','Dark Gray',
  785.                                          'Light Blue','Light Green','Light Cyan',
  786.                                          'Light Red','Light Magenta','Yellow',
  787.                                          'White');
  788. var x,y,posx,posy,lposx,lposy :byte;
  789.     ch                        :char;
  790.  
  791. procedure reloc(x,y:byte);
  792. begin
  793.   gotoxy(x+xbase,y+ybase);
  794. end;
  795.  
  796. begin
  797.   openbox(111,xbase,ybase-1,xbase+50,ybase+19,true,true,true);
  798.   posx:=initial div 16;
  799.   posy:=initial mod 16;
  800.   for x:=0 to 7 do for y:=0 to 15 do begin
  801.     reloc((x+1)*5,y+1);
  802.     textattr:=x*16+y;
  803.     write(' ■ ');
  804.   end;
  805.   lposx:=0; lposy:=0;
  806.   repeat
  807.     if (posx=posy) then begin
  808.       textattr:=white;
  809.       reloc(1,18);
  810.       write('<invisible>         ');
  811.     end else begin
  812.       textattr:=posx*16+posy;
  813.       reloc(1,18);
  814.       write(' Yet Another Sample ');
  815.     end;
  816.     textattr:=white;
  817.     reloc(25,18); write(colorname[posy],' on ',colorname[posx]);
  818.     for x:=1 to 20-length(colorname[posx])-length(colorname[posy]) do write(' ');
  819.     reloc((lposx+1)*5-1,lposy); write(' ');
  820.     reloc((lposx+1)*5+3,lposy); write(' ');
  821.     reloc((lposx+1)*5-1,lposy+1); write(' ');
  822.     reloc((lposx+1)*5+3,lposy+1); write(' ');
  823.     reloc((lposx+1)*5-1,lposy+2); write(' ');
  824.     reloc((lposx+1)*5+3,lposy+2); write(' ');
  825.     if lposy>0 then begin
  826.       textattr:=lposx*16+lposy-1;
  827.       reloc((lposx+1)*5,lposy); write(' ■ ');
  828.     end else begin
  829.       textattr:=white;
  830.       reloc((lposx+1)*5,lposy); write('   ');
  831.     end;
  832.     textattr:=lposx*16+lposy;
  833.     reloc((lposx+1)*5,lposy+1); write(' ■ ');
  834.     if lposy<15 then begin
  835.       textattr:=lposx*16+lposy+1;
  836.       reloc((lposx+1)*5,lposy+2); write(' ■ ');
  837.     end else begin
  838.       textattr:=white;
  839.       reloc((lposx+1)*5,lposy+2); write('   ');
  840.     end;
  841.  
  842.     textattr:=white;
  843.     reloc((posx+1)*5-1,posy); write('┌───┐');
  844.     reloc((posx+1)*5-1,posy+1); write('│');
  845.     reloc((posx+1)*5+3,posy+1); write('│');
  846.     reloc((posx+1)*5-1,posy+2); write('└───┘');
  847.     textattr:=posx*16;
  848.     reloc((posx+1)*5,posy+1); write('▌');
  849.     reloc((posx+1)*5+2,posy+1); write('▐');
  850.     lposx:=posx; lposy:=posy;
  851.     colorselect:=posx*16+posy;
  852.     repeat ch:=readkey until ch in [#0,#27,#13];
  853.     if ch=#0 then ch:=readkey;
  854.     case ch of
  855.       CurUp :if posy>0 then dec(posy) else posy:=15;
  856.       CurDn :if posy<15 then inc(posy) else posy:=0;
  857.       CurLf :if posx>0 then dec(posx) else posx:=7;
  858.       CurRt :if posx<7 then inc(posx) else posx:=0;
  859.     end;
  860.   until ch in [#27,#13];
  861.   if ch=#27 then colorselect:=initial;
  862.   closebox(111);
  863. end;
  864.  
  865. begin
  866.   mousepresent:=false;
  867.   if paramstr(1)='/(C)' then begin
  868.     writeln('EXTRAS.PAS - v2.00 - (C) Onkel Dittmeyer / S.L.A.M.');
  869.     writeln('           General Purpose Pascal Utilities (TP 7.0)');
  870.     readln;
  871.   end;
  872. end.
  873.