home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8809.arc
/
STITT.LIS
< prev
Wrap
File List
|
1988-08-22
|
4KB
|
116 lines
_USING ACTION CHARTS_
by
Martin Stitt
Listing One
{ Read each line of an action chart file and filter out the bracket }
{ charactors. Format the remaining text with regards to the left }
{ margin and indentation. }
{ NOTE - comments ending with a ** denote areas of this program which were }
{ left incomplete for the sake of brevity. }
{ You should customize the following constants to suit your particular }
{ tastes as far as indentation. You may wish to use variables instead }
{ and obtain their values from command line switches or a configuration }
{ file. }
const
margin_spaces : integer = 0; { customize these variables per }
margin_tabs : integer = 0; { your particular taste. }
spaces_per_level : integer = 2; { Better yet, prompt for them at }
skip_null_lines : boolean = false; { run time or read from a
{ These character sets are the block graphics characters which }
{ this program filters out. }
top_set : set of char = ['Z','U']; { alt-218, alt-213 }
bot_set : set of char = ['@','T']; { alt-192, alt-212 }
else_set : set of char = ['C']; { alt-195 }
pass_set : set of char = [' ','D','M','3'];
{ space, alt-196, alt-205, alt-179 }
type
str_type = string[80];
chset = set of char;
var
source,dest : text;
total_spaces,c_index,
indent_adj,indent_level : integer;
indent_str,work_str : str_type;
procedure advance_index(w_str : str_type; var ix : integer; test_set : chset);
{ accept a string, an index and a set of characters to the string test for. }
{ advance the index past all charactors in the specified set, returning an }
{ updated value of the index to the calling program. }
var
w_str_len : integer;
begin
w_str_len := ord(w_str[0]);
while(true) do begin
if ix > w_str_len then exit;
if not (w_str[ix] in test_set) then exit;
ix := ix + 1
end
end;
begin { MAIN PROGRAM LOGIC}
indent_level := 0;
{ validate command line parameters and manage file open errors ** }
assign(source,paramstr(1));
reset(source);
assign(dest,paramstr(2));
rewrite(dest);
{ read each line from the source file and filter out the characters which }
{ are used to produce the action chart brackets. Write the resulting line }
{ to the destination file. }
while(not eof(source)) do begin
readln(source,work_str);
c_index := 1;
indent_adj := 0;
advance_index(work_str,c_index,pass_set);
if c_index <= ord(work_str[0]) then
if work_str[c_index] in top_set + bot_set + else_set then begin
if work_str[c_index] in top_set then indent_adj := 1
else
if work_str[c_index] in bot_set then
indent_level := indent_level - 1
else begin { must be in the else set }
indent_level := indent_level - 1;
indent_adj := 1
end;
advance_index(work_str,c_index,top_set + bot_set + else_set + pass_set);
end;
if c_index <= ord(work_str[0]) then begin
total_spaces := margin_spaces + (indent_level * spaces_per_level);
indent_str[0] := chr(margin_tabs + total_spaces);
fillchar(indent_str[1],margin_tabs,#9);
fillchar(indent_str[margin_tabs+1],total_spaces,' ');
writeln(dest,concat(indent_str,copy(work_str,c_index,999)))
end
else
if not skip_null_lines then writeln(dest);
indent_level := indent_level + indent_adj
end;
close(dest);
close(source);
{ manage file errors ** }
end.