home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
turbopas
/
turbscr.lbr
/
SCREEN.PQS
/
SCREEN.PAS
Wrap
Pascal/Delphi Source File
|
1986-06-21
|
9KB
|
388 lines
program screen_gen;
type
anystring = string[255];
Scr = array[1..79] of array[1..23] of char;
var
S : Scr;
x,y,col,row : integer;
ch,FileType,ProgCode: char;
Filename : string[8];
OutFile : text;
SaveFile : file of Scr;
FileSaved : boolean;
{ *** FUNCTION TO CHECK FOR EXISTING FILE RETURNS TRUE OR FALSE ***}
function Exist(FileN: Anystring): boolean;
var F: file;
begin
{$I-}
assign(F,FileN);
reset(F);
{$I+}
if IOResult <> 0 then Exist:=false
else Exist:=true;
end;
procedure status_line;
begin
gotoXY(1,24);
ClrEOL;
end;
procedure GetFileName;
begin
Filename:='';
repeat
read(kbd,ch);
if Upcase(ch) in ['A'..'Z','0'..'9',^M] then
begin
write(Upcase(ch));
Filename:=Filename+upcase(ch);
end;
UNTIL(Ch=^M) or (length(Filename)=8);
if Ch=^M then Delete(Filename,Length(Filename),1);
end;
procedure display_screen;
begin
ClrScr;
for y:=1 to 23 do
begin
for x:=1 to 79 do write(s[x,y]);
if y < 23 then writeln;
end;
end; {display_screen}
procedure alpha_in;
begin
write(ch);
S[col,row]:=ch;
col:=col+1;
if col > 79 then
begin
row:=row+1;
if row > 23 then row:=1;
col:=1;
end;
gotoXY(col,row);
end;
procedure carriage_return;
begin
if col > 1 then
begin
col:=1;
repeat
if s[col,row]=' ' then col:= col+1;
until s[col,row] <> ' ';
end;
row:=row+1;
gotoXY(col,row);
end;
procedure up_arrow;
begin
if row > 1 then row:=row-1;
gotoXY(col,row);
end;
procedure right_arrow;
begin
col:=col+1;
if col > 79 then
begin
row:=row+1;
if row > 23 then row:=1;
col:=1;
end;
gotoXY(col,row);
end; (* right_arrow *)
procedure down_arrow;
begin
row:=row+1;
if row > 23 then row:=1;
gotoXY(col,row);
end; (* down_arrow *)
procedure back_space;
begin
col:=col-1;
if (col < 1) and (row > 1) then
begin
col:=79;
row:=row-1;
end
else
if (col < 1) and (row = 1) then
begin
col:=1;
row:=1;
end;
gotoXY(col,row);
end; (* back_space *)
procedure delete_char;
begin
col:=col-1;
if (col < 1) and (row > 1) then
begin
col:=79;
row:=row-1;
end
else
if (col < 1) and (row = 1) then
begin
col:=1;
row:=1;
end;
gotoXY(col,row);
s[col,row]:=' ';
write(s[col,row]);
end;
procedure Prog_Code_in;
begin
status_line;
write('<H>orz line <V>ert line <Q>uit drawing screen ');
read(kbd,ProgCode);
ProgCode:=UpCase(ProgCode);
write(ProgCode);
case ProgCode of
'H' : begin (* Horz Line *)
for x:=col to 79 do
begin
gotoXY(x,row);
if S[x,row]='|' then S[x,row]:='+' else S[x,row]:='-';
write(S[x,row]);
end;
row:=row+1;
if row > 23 then row:=1;
col:=1;
gotoXY(col,row);
end; (* case H *)
'V' : begin (*Vert Line *)
for x:=row to 23 do
begin
gotoXY(col,x);
if S[col,x]='-' then S[col,x]:='+' else S[col,x]:='|';
write(S[col,x]);
end;
row:=1;
col:=col+1;
gotoXY(col,row);
end; (* case V *)
end; (* case *)
gotoXY(1,24);
ClrEOL;
write('Press \ for options');
gotoXY(col,row);
end; (* Prog_code_in *)
Procedure draw_screen;
begin
FileSaved:=false;
Progcode:=' ';
if FileType='O' then display_screen;
status_line; write('Press \ for options');
col:=1;
row:=1;
gotoXY(col,row);
repeat
gotoXY(66,24); write('Col ',col:2,' Row ',row:2); gotoXY(col,row);
read(kbd,ch);
case ch of
#32..#91,#93..#126 : alpha_in;
^M : carriage_return;
^K : up_arrow;
^L : right_arrow;
^J : down_arrow;
^H : back_space;
'\' : Prog_Code_in;
#127 : delete_char;
end; {case}
until ProgCode ='Q';
end; {draw_screen}
procedure old_new;
label stop;
begin
status_line;
write('<O>ld or <N>ew file : ');
repeat
read(kbd,ch);
until ch in ['O','o','N','n'];
FileType:=Upcase(ch);
status_line;
write('Enter file name (no ext) :');
GetFileName;
case FileType of
'N':begin
if not exist(filename+'.SCR') then
begin
assign(outfile,filename+'.INC');
assign(savefile,filename+'.SCR');
end
else
begin
status_line;
write('File ',FileName,' exists. Erase Y/N ? ');
read(kbd,ch);
if ch in['Y','y'] then
begin
assign(outfile,filename+'.INC');
assign(savefile,filename+'.SCR');
rewrite(outfile);
rewrite(savefile);
end;
end;
end;
'O':begin
if exist(Filename+'.SCR') then
begin
reset(savefile);
read(savefile,S);
end
else
begin
status_line;
write(Filename+'.SCR does not exist. Press <RETURN> ');
read(kbd,ch);
end;
end;
end;(* case *)
end;
procedure save_outfile;
var
varout:boolean;
begin
FileSaved:=true;
varout:=false;
status_line;
write('saving file ',FileName+'.INC');
rewrite(outfile);
writeln(outfile,'Procedure ',FileName,';');
writeln(outfile,'begin');
for y:=1 to 23 do
begin
x:=1;
write(outfile,' gotoXY(',x:2,',',y:2,'); '); (*start position*)
write(outfile,' write(''');
for x:=1 to 40 do (* eliminate var from print screen *)
begin
if (s[x,y]='@') or (s[x,y]='#') then varout:=true;
if varout then write(outfile,' ') else write(outfile,s[x,y]);
if (varout) and (s[x,y]=' ') then varout:=false;
end;
writeln(outfile,''');');
x:=41;
write(outfile,' gotoXY(',x:2,',',y:2,'); '); (*start position*)
write(outfile,' write(''');
(* note if we were in the middle of a variable then the next *)
(* for x loop will continue to write spaces i.e. varout true *)
for x:=41 to 79 do (* eliminate var from print screen *)
begin
if (s[x,y]='@') or (s[x,y]='#') then varout:=true;
if varout then write(outfile,' ') else write(outfile,s[x,y]);
if (varout) and (s[x,y]=' ') then varout:=false;
end;
writeln(outfile,''');');
end;
(* write var*)
varout:=false;
for y:= 1 to 23 do
begin
for x:=1 to 79 do
begin
if (varout) and (s[x,y]=' ') then
begin
varout:=false;
writeln(outfile,');');
end;
if (varout) and (s[x,y]<>' ') then write(outfile,s[x,y]);
if s[x,y]='@' then
begin
varout:=true;
write(outfile,' gotoXY(',x:2,',',y:2,'); '); (*start position*)
write(outfile,' write(')
end;
end;
end;
(* read var *)
varout:=false;
for y:= 1 to 23 do
begin
for x:=1 to 79 do
begin
if (varout) and (s[x,y]=' ') then
begin
varout:=false;
writeln(outfile,');');
end;
if (varout) and (s[x,y]<>' ') then write(outfile,s[x,y]);
if s[x,y]='#' then
begin
varout:=true;
write(outfile,' gotoXY(',x:2,',',y:2,'); '); (*start position*)
write(outfile,' read(');
end;
end;
end;
writeln(outfile,'end;');
close(outfile);
status_line;
write('saving file ',FileName+'.SCR');
rewrite(savefile);
write(savefile,S);
close(savefile);
end; {save_outfile}
begin
FileSaved:=true;
ClrScr;
(* initialize array *)
FillChar(S,79*23,' ');
repeat
status_line;
LowVideo;
write('<1>Select file <2>Draw screen <3>Display screen ');
write('<4>Save screen <5>Quit :');
HighVideo;
read(kbd,ch);
case ch of
'1': old_new;
'2': draw_screen;
'3': display_screen;
'4': save_outfile;
end; {case}
until ch = '5';
if not FileSaved then
begin
status_line;
write('You have not saved the edited file ',FileName,' Save now ?');
read(kbd,ch);
if ch in['Y','y'] then save_outfile;
end;
end.