home *** CD-ROM | disk | FTP | other *** search
- {$I-} {IO checking off}
- {$R-} {Range checking off}
- {$S-} {Stack checking off}
- {$V-} {Bounds checking off}
- { = faster}
- {
-
- -------------------------------------------------------------------
-
- Mike Bailey
- Madison, WI
- March 1988
-
- The purpose of this program is to convert a text file
- into all uppercase alphabetic characters. Input is in
- the form of a command line, with wild cards allowed. A
- temporary file is made then deleted during the conversion
- process.
-
- -------------------------------------------------------------------
-
- }
-
- program UC;
-
- Uses
- Crt,
- Dos;
-
- type
- Fstring = string[12];
- Fnames = string[12];
-
- const
- OffBar = $07; {normal video}
- OnBar = $70; {reverse video highlight}
-
- var
- DatFile : array[1..400] of Fnames;
- FileIn,FileOut,F1,F2 : file;
- words,bufferin,bufferout : string[255];
- NextFile : Fstring;
- Buf : array[0..32767] of char;
- FileN1,FileN2 : string[128];
- DInfo : SearchRec; {record for directory info}
- Ndx : word; {index for array}
- DMax : word; {maximum file number}
- Regs : registers;
- RealCurs : integer;
-
- procedure LightBar(WStr : Fnames;Attr: byte);
- { WStr = string to write to screen.
- Attr = $07 if normal video
- $70 if reverse video
- $FF if blinking reverse video
- $F0 if blinking reverse video line
- Uses BIOS calls $03 : get current cursor location
- $09 : write char & attribute
- $02 : move cursor to new position
- Column must be incremented before call to move cursor.}
- var
- Index : integer;
- Column, Row : byte;
- begin
- for Index := 1 to length(WStr) do {write each character}
- begin
- with Regs do {use Regs set}
- begin
- AX := $0300; {function to save current cursor pos.}
- BX := 0; {page 0}
- Intr($10,Regs); {BIOS call}
- Row := DX shr 8; {row return*ed in DH}
- Column := (DX mod 256) + 1; {column returned in DL,inc and store}
- AX := $0900 + ord(WStr[Index]);{function to write char & attribute}
- BX := Attr; {BL gets attribute}
- CX := $01; {do only one character}
- Intr($10,Regs); {BIOS call}
- AX := $0200; {function to set cursor position}
- DX := Row shl 8 + Column; {DH gets row, DL gets column}
- Intr($10,Regs); {BIOS call}
- end;
- end;
- end;
-
- procedure OrgCursor;
- { Capture the original value of the cursor upon entry.}
- begin
- Regs.AX := $0300; {read cursor function}
- Regs.BX := $00; {assume page 0}
- Intr($10,Regs); {call BIOS int 10h}
- RealCurs := Regs.CX; {cursor val returned in CX}
- end;
-
- procedure Cursor;
- { Turns the cursor on using BIOS int 10h.
- The cursor captured upon program initiation is used.}
- begin
- Regs.AX := $0100;
- Regs.CX := RealCurs;
- Intr($10,Regs);
- end;
-
- procedure NoCursor;
- { Turns the cursor off using BIOS int 10h.
- Bit 5 of CH when high turns off the cursor.}
- begin
- Regs.AX := $0100;
- Regs.CX := $2000; {turn off original cursor}
- Intr($10,Regs);
- end;
-
- procedure DoDwn(RFile : Fstring);
- { Inputs file name to open, read and convert all upper case
- characters to lower case.}
- var
- ReadIn,WroteOut,Ndx : word;
- FileOk : boolean;
- begin
- FileOk := true;
- FileN2 := RFile; {get file name}
- FileN1 := FileN2; {store in another string}
- if Pos('.',FileN2) <> 0 then {look for extension}
- FileN2 := Copy(FileN2,1,Pos('.',FileN2) - 1) + '.BAK'
- else FileN2 := FileN2 + '.BAK'; {delete if any, add 'bak'}
- Assign(FileIn,FileN1); {try to open file}
- Reset(FileIn,1);
- If IOResult <> 0 then {if unsuccessful give err msg}
- begin
- LowVideo;
- Write('Unable to access ---> ');
- HighVideo;
- Write(FileN1);
- FileOk := false; {error, exit procedure}
- end;
- LowVideo;
- if FileOk then
- begin
- Write('Upper case conversion ---> ');
- LightBar(FileN1,OnBar);
- Assign(FileOut,FileN2); {open file to write}
- Rewrite(FileOut,1);
- repeat {read until EOF}
- BlockRead(FileIn,Buf,SizeOf(Buf),ReadIn); {read up to buffer size}
- for Ndx := 0 to Readin do
- if ((Buf[Ndx] <= 'z') and (Buf[Ndx] >= 'a')) then
- ord(Buf[Ndx]) := ord(Buf[Ndx]) - $20;
- BlockWrite(FileOut,Buf,ReadIn,WroteOut); {write it to other file}
- until (ReadIn = 0) or (WroteOut <> ReadIn); {until EOF}
- close(FileIn); {close both files}
- close(FileOut);
- Assign(F1,FileN2); {get file named *.bak}
- Rename(F1,'TMPADZ'); {temporarily rename}
- Assign(F2,FileN1); {get original file}
- Erase(F2); {delete it}
- Assign(F1,'TMPADZ'); {get altered file}
- Rename(F1,FileN1); {rename it original name}
- end;
- end;
-
- procedure ReadDat;
- { Uses the command line with the DOS file name(s)
- to alter.}
- var
- FileOk : boolean;
- begin
- Ndx := 1; {start real info}
- FindFirst(ParamStr(1),AnyFile,DInfo); {use DOS file records}
- while DosError = 0 do {while not no more files}
- begin
- DatFile[Ndx] := DInfo.Name; {file the array}
- FindNext(DInfo); {get next file name}
- Inc(Ndx); {increment array pointer}
- end;
- DMax := Ndx - 1; {get number of files}
- for Ndx := 1 to DMax do
- begin
- DoDWn(DatFile[Ndx]);{make lower case}
- if Ndx < DMax then Writeln;
- end;
- end;
-
- begin
- OrgCursor; {get original cursor}
- NoCursor; {turn cursor off}
- if paramcount <> 1 then
- begin
- lowvideo;
- write('Usage: UC [Filenames] - wildcards * and ? acceptable ');
- end
- else
- ReadDat;
- HighVideo;
- Cursor; {restore cursor}
- end.