home *** CD-ROM | disk | FTP | other *** search
- { ===================================================================== }
- { INPFLD.INC - Get a field of characters. All attributes concerning }
- { the field are user-definable. InpFld was concieved from a routine }
- { contained in the Borland International Turbo Database Toolbox. }
- { }
- { The following procedures are also contained in the package }
- { WINDOxx.ARC and are duplicated here for ease of use: }
- { DispLine Set_Cursor }
- { }
- { Author: Michael Burton }
- { 15540 Boot Hill Rd. }
- { Hayden Lake, ID 83835 }
- { (208) 772-9347 (after 1800 PST) }
- { Revision: 1.1 }
- { Date: 02 July 1987 }
- { }
- { Copyright (C) 1987 by Michael Burton }
- { }
- { This is a 'Shareware' program. If you find it to be of significant }
- { use to you, a $10 donation to the above address would be greatly }
- { appreciated. This would also place you on our mailing list to keep }
- { you informed of upgrades to InpFld and of new programs. }
- { }
- { Modifications: }
- { DATE Rev Description }
- { 16 Jun 87 1.0 Initial release }
- { 02 Jul 87 1.1 Add right justified field option }
- { ===================================================================== }
- Type
- option_type = set of 0..7;
- strg80 = string[80];
- strg255 = string[255];
- ifrec = record case integer of
- 1: (ax,bx,cx,dx,bp,si,di,ds,es,flags: integer);
- 2: (al,ah,bl,bh,cl,ch,dl,dh: byte);
- end;
-
- Const
- IFCR = 13;
- IFESC = 27;
- IFCTLS = 19;
- IFCTLD = 4;
- IFCTLA = 1;
- IFCTLF = 6;
- IFCTLG = 7;
- IFBKSP = 8;
- IFCTBS = 127;
- IFINS = 338;
- IFLARW = 331;
- IFRARW = 333;
- IFHOME = 327;
- IFEND = 335;
- IFDEL = 339;
- IFTAB = 9;
- IFBTAB = 271;
- IFUARW = 328;
- IFDARW = 336;
- IFCRAR = 372;
- IFCLAR = 371;
- IFCEND = 373;
-
- { ===================================================================== }
- { DISPLINE - Display a string of characters on the CRT (with the same }
- { attributes) }
- { The row and column inputs are relative to zero and are }
- { also relative to the entire screen, not any open window. }
- { }
- { Inputs: }
- { colb : byte; Starting column (0 - 79) }
- { rowb : byte; Starting row (0 - 24) }
- { attrib : byte; Line attributes }
- { fromstrng : string[80]; String to display }
- { ===================================================================== }
- Procedure DispLine(colb,rowb,attrib : byte; VAR fromstrng : strg80);
- Begin
- Inline(
- $1E/ { PUSH DS }
- $8A/$86/rowb/ { MOV AL,rowb[BP] }
- $B3/$50/ { MOV BL,80 }
- $F6/$E3/ { MUL BL }
- $2B/$DB/ { SUB BX,BX }
- $8A/$9E/colb/ { MOV BL,colb[BP] }
- $03/$C3/ { ADD AX,BX }
- $03/$C0/ { ADD AX,AX }
- $8B/$F8/ { MOV DI,AX }
- $8A/$BE/attrib/ { MOV BH,attrib[BP] }
- $C4/$B6/fromstrng/ { LES SI,fromstrng[BP] }
- $2B/$C9/ { SUB CX,CX }
- $26/$8A/$0C/ { MOV CL,ES:[SI] }
- $2B/$C0/ { ADD AX,AX }
- $8E/$D8/ { MOV DS,AX }
- $A0/$49/$04/ { MOV AL,DS:[0449H] }
- $22/$C9/ { AND CL,CL }
- $74/$34/ { JZ DONE }
- $2C/$07/ { SUB AL,7 }
- $74/$21/ { JZ MONO }
- $BA/$00/$B8/ { MOV DX,0B800H }
- $8E/$DA/ { MOV DS,DX }
- $BA/$DA/$03/ { MOV DX,03DAH }
- $46/ { GETCHAR: INC SI }
- $26/$8A/$1C/ { MOV BL,ES:[SI] }
- $EC/ { TESTLOW: IN AL,DX }
- $A8/$01/ { TEST AL,1 }
- $75/$FB/ { JNZ TESTLOW }
- $FA/ { CLI }
- $EC/ { TESTHI: IN AL,DX }
- $A8/$01/ { TEST AL,1 }
- $74/$FB/ { JZ TESTHI }
- $89/$1D/ { MOV DS:[DI],BX }
- $47/ { INC DI }
- $47/ { INC DI }
- $E2/$EB/ { LOOP GETCHAR }
- $2A/$C0/ { SUB AL,AL }
- $74/$0F/ { JZ DONE }
- $BA/$00/$B0/ { MONO: MOV DX,0B000H }
- $8E/$DA/ { MOV DS,DX }
- $46/ { MONO1: INC SI }
- $26/$8A/$1C/ { MOV BL,ES:[SI] }
- $89/$1D/ { MOV DS:[DI],BX }
- $47/ { INC DI }
- $47/ { INC DI }
- $E2/$F6/ { LOOP MONO1 }
- $1F); { DONE: POP DS }
- End;
-
- { ======================================================================== }
- { NAME: Set_Cursor VERSION: 1.0 DATE: 27 January 1986 }
- { AUTHOR: }
- { DESCRIPTION: Set the cursor size }
- { INPUTS: The number of cursor lines to display (0 -7, 0-14) }
- { }
- { ======================================================================== }
- Procedure Set_Cursor (n: byte);
- Var regpak : ifrec;
- top, bottom : byte;
- Begin
- If Mem[$0040:$0049] = 7 Then bottom := 13
- Else bottom := 7;
- regpak.ax:= $100;
- If n <= bottom Then top := bottom - n + 1
- Else top := 0;
- regpak.cx := top shl 8 or bottom;
- Intr($10,regpak)
- End;
-
- { --------------------------------------------------------- }
- { ReadChar - Get a character from the keyboard. Returns an }
- { integer from 0 to 512. Double keys have 256 added to }
- { them, e.g., F1 (27 59) returns 315 (59 + 256) }
- { --------------------------------------------------------- }
- function ReadChar: integer;
- Var
- ch : char;
-
- begin
- Read(kbd,ch);
- if ch = Chr(IFESC) then
- if KeyPressed then
- begin
- Read(kbd,ch);
- ReadChar := Ord(ch) + 256;
- Exit;
- end;
- ReadChar := Ord(ch);
- end;
-
- { --------------------------------------------------------- }
- { FindPos - find the next occurrence of a character with- }
- { in a string. Returns 0 if character not found. }
- { --------------------------------------------------------- }
- Function FindPos(s : strg255; startpos : integer; direction : boolean): integer;
- Const
- delimiters : set of char = [' ','/','\',':','-','.',',','_','='];
-
- Var i : integer;
- found : boolean;
-
- begin
- i := startpos;
- found := False;
- if (((startpos = 0) and (direction = False)) or
- ((startpos = length(s)) and (direction = True))) then
- begin
- FindPos := startpos;
- Exit;
- end;
- repeat
- if direction then i := Succ(i)
- else i := Pred(i);
- if ((i = 0) or (i = length(s))) then found := True
- else
- if (s[i] in delimiters) then found := True;
- until found;
- FindPos := i;
- end;
-
- { --------------------------------------------------------- }
- { StrConst - Return a string of length n filled with char- }
- { acter c. }
- { --------------------------------------------------------- }
- function StrConst(c : char; n : integer) : strg80;
- Var
- s : strg80;
- begin
- if n < 0 then n := 0;
- s[0] := Chr(n);
- FillChar(s[1],n,c);
- StrConst := s;
- end;
-
- { --------------------------------------------------------- }
- { DispField - Display the field and position the cursor. }
- { --------------------------------------------------------- }
- Procedure DispField(x,y,size,attr,pcol : integer; ibuf : strg255);
- Const
- fieldfiller = ' '; { fill the rest of the field with this character }
- var
- s : strg80;
- regpack : ifrec;
-
- begin
- s := ibuf + StrConst(fieldfiller,size - Length(ibuf));
- DispLine(x - 1,y - 1,attr,s); { Display the field }
- regpack.ah := 2;
- regpack.bx := 0;
- regpack.dh := y - 1;
- regpack.dl := x + pcol - 1;
- Intr($10,regpack); { Position the cursor }
- Gotoxy(wherex,wherey); { adjust for turbo windos }
- end;
-
- { --------------------------------------------------------- }
- { InpFld - Get a field of characters. Upon return, keyval }
- { has the last character entered. Legal contains all the }
- { legal characters. If legal is empty, all characters }
- { are legal. Ibuf is the string returned. Attr is the }
- { screen attributes to use for the field. x and y are }
- { the position on the display to get input. Size is the }
- { maximum size of the field. Option are the input }
- { options. Options are: }
- { [] = No options chosen }
- { [1] = Perform uppercase translation }
- { [5] = Exit from field if field is full. }
- { [6] = Right justify field upon exit }
- { [7] = Display and use initial value of ibuf. }
- { Otherwise ibuf will be emptied before use. }
- { Field Editing Keys are: }
- { Left arrow, }
- { Ctl-S - Move one character left. }
- { }
- { Right arrow, }
- { Ctl-D - Move one character right. }
- { }
- { Home, }
- { Ctl-A - Move to the start of the field. }
- { }
- { End, }
- { Ctl-F - Move to the current end of the field. }
- { }
- { Del, }
- { Ctl-G - Delete the char under the cursor. }
- { }
- { BackSpace - Delete the char to the left of cursor.}
- { }
- { Ctl-BackSpace- Delete the entire field. }
- { }
- { Ins - Toggle insert/overwrite mode. }
- { }
- { Ctl-End - Delete to the end of the line. }
- { }
- { Ctl-Left arw - Move left one word. }
- { }
- { Ctl-Right arw- Move right one word. }
- { }
- { To end field editing, use one of Enter, Esc, Tab, }
- { BackTab, Up arrow or Down arrow; or fill the field }
- { if option 5 is selected. }
- { --------------------------------------------------------- }
- procedure InpFld(var keyval: integer;
- var Legal : strg255;
- var ibuf : strg255;
- attr : Integer;
- x,y,size : Integer;
- option: option_type);
- Var
- pcol : integer;
- ich : integer;
- s : strg80;
- insmode : boolean;
-
- begin
- insmode := False;
- if option >= [7] then else ibuf := '';
- pcol := 0;
- repeat
- DispField(x,y,size,attr,pcol,ibuf);
- ich := ReadChar;
- case ich of
- 32..126 : begin
- if option >= [1] then ich := Ord(Upcase(Chr(ich)));
- if ((Length(legal) = 0) or (Pos(Chr(ich),legal) <> 0)) then
- begin
- if pcol < size then
- begin
- if ((insmode) and (Length(ibuf) < size)) then
- begin
- pcol := Succ(pcol);
- Insert(Chr(ich),ibuf,pcol);
- end
- else
- if ((pcol < size) and (insmode = False)) then
- begin
- pcol := Succ(pcol);
- ibuf[pcol] := Chr(ich);
- if length(ibuf) < pcol then ibuf[0] := Chr(pcol);
- end;
- end;
- end;
- end;
- IFCTLS,IFLARW : if pcol > 0 then { left arrow }
- pcol := Pred(pcol);
- IFCTLD,IFRARW : if pcol < Length(ibuf) then { right arrow }
- pcol := Succ(pcol);
- IFCTLA,IFHOME : pcol := 0; { home }
- IFCTLF,IFEND : pcol := Length(ibuf); { end }
- IFCTLG,IFDEL : if pcol < Length(ibuf) then { del }
- begin
- Delete(ibuf,pcol + 1,1);
- end;
- IFBKSP : if pcol > 0 then { backspace }
- begin
- Delete(ibuf,pcol,1);
- pcol := Pred(pcol);
- end;
- IFCTBS : begin { delete line }
- ibuf := '';
- pcol := 0;
- end;
- IFINS : begin
- insmode := not insmode;
- if insmode then Set_Cursor(5)
- else Set_Cursor(2);
- end;
- IFCEND : Delete(ibuf,pcol+1,(length(ibuf)-pcol));
- IFCRAR : pcol := FindPos(ibuf,pcol,True);
- IFCLAR : pcol := FindPos(ibuf,pcol,False);
- end; {of case}
- until ((ich = IFCR) or (ich = IFESC) or (ich = IFTAB) or (ich = IFBTAB) or
- (ich = IFUARW) or (ich = IFDARW) or
- ((option >= [5]) and (Length(ibuf) = size)));
- pcol := Length(ibuf);
- if option >= [6] then
- s := StrConst(' ',size - Length(ibuf)) + ibuf
- else
- s := ibuf + StrConst(' ',size - Length(ibuf));
- DispLine(x-1,y-1,attr,s);
- keyval := ich;
- Set_Cursor(2);
- end;