MODULE nonprint_ascii; LIST TITLE 'find non-printable ASCII characters'; !++ ! ! ABSTRACT: ! ! peruses wildcarded files looking for ASCII non-printable characters ! and reports same ! ! AUTHORS: ! ! DKR ! ! CREATION DATE: 3/24/88 ! ! MODIFICATION HISTORY: ! ! [-tbs-] !-- INCLUDE FILE 'comp_include:lib$find_file.scndef'; INCLUDE FILE 'comp_include:$rmsdef.scndef'; CONSTANT tab = S'HT'; CONSTANT formfeed = S'FF'; DECLARE output_filename : BOOLEAN; DECLARE file_name: STRING; DECLARE character_count, tab_count, formfeed_count : INTEGER; SET printable_ascii ( ' ' .. '~' ); SET scanning_literals ( S'SOS' OR S'EOL' OR S'EOS' ); SET non_printable_char ( NOT ( printable_ascii OR scanning_literals ) ); TOKEN np_string { non_printable_char ... }; MACRO find_nps TRIGGER { s,l,c: np_string }; DECLARE i : INTEGER; IF output_filename THEN output_filename = FALSE; WRITE ' '; WRITE file_name; END IF; IF LENGTH(s) > 1 THEN WRITE 'line,column: ', l, ',', c, ' for ', LENGTH( s ); ELSE WRITE 'line,column: ', l, ',', c; END IF; character_count = character_count + LENGTH( s ); FOR i = 1 TO LENGTH( s ); IF s[ i ] = tab THEN tab_count = tab_count + 1; ELSE IF s[ i ] = formfeed THEN formfeed_count = formfeed_count + 1; END IF; END IF; END FOR; END MACRO; /* find_nps PROCEDURE nonprintables MAIN OF INTEGER; DECLARE file_spec: STRING; DECLARE context, status: INTEGER; ! ! prompt for a file specification with/out wildcards and ! read through the specified file(s) ! 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 ]; output_filename = TRUE; START SCAN INPUT FILE file_name OUTPUT FILE 'nl:'; 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: WRITE ' '; WRITE tab_count, ' Tabs'; WRITE formfeed_count, ' Formfeeds'; WRITE tab_count + formfeed_count, ' Tabs & Formfeeds'; WRITE ' '; WRITE character_count, ' Total non-printable ASCII characters'; WRITE ' '; RETURN rms$_normal; END PROCEDURE; /* nonprintables END MODULE /* nonprint_ascii */;