MODULE file_tidy; ! peruses sets of wildcarded file specifications ! and reduces strings of multiple blanks to one blank, ! eliminates trailing blanks, and rewraps lines to a ! new right margin (if specified). INCLUDE FILE 'sysdeflib$scn:lib$find_file.scndef'; INCLUDE FILE 'sysdeflib$scn:$rmsdef.scndef'; DECLARE lastcol, wrap_point : INTEGER; TOKEN spaces { ' ' ' ' ... }; TOKEN eol { [ ' ' ] S'EOL' }; TOKEN space { ' ' }; MACRO find_spaces TRIGGER { spaces }; ANSWER TRIGGER ' '; END MACRO; /* find_spaces MACRO find_end_of_line TRIGGER { eol }; ANSWER S'EOL'; lastcol = 0; END MACRO /* find_end_of_line */; MACRO find_space TRIGGER { *,*,col: space }; IF wrap_point > 0 THEN IF col - lastcol > wrap_point THEN ANSWER S'EOL'; lastcol = col; RETURN; END IF; END IF; ANSWER ' '; END MACRO; /* find_spaces PROCEDURE tidy MAIN OF INTEGER; DECLARE oc: FIXED STRING(1); DECLARE file_spec, file_name : STRING; DECLARE context,status: INTEGER; READ PROMPT ('Enter column number to rewrap lines at, or 0 to inhibit rewrapping: ') wrap_point; next_file_spec: READ PROMPT ('Enter files to process: ') file_spec; IF file_spec = '' THEN GOTO no_more_files; END IF; context = 0; status=lib$find_file(file_spec,file_name,context,*,*); IF status = rms$_fnf THEN WRITE ('no files found'); GOTO next_file_spec; END IF; IF status <> rms$_normal THEN RETURN status; END IF; WHILE status <> rms$_nmf; file_name = file_name[ 1 .. INDEX(file_name,';')-1 ]; WRITE 'DOING: ', file_name; lastcol = 0; START SCAN DATA STACK 10000 INPUT FILE file_name INPUT WIDTH 6000 OUTPUT FILE file_name OUTPUT WIDTH 255; status=lib$find_file(file_spec,file_name,context,*,*); END WHILE; /* find_file status=lib$find_file_end(context); GOTO next_file_spec; no_more_files: RETURN rms$_normal; END PROCEDURE; /* tidy END MODULE; /* file_tidy