################################################################################ # # Program: level_break.pl # Author: Peter R. Schmidt # Description: print a new-line between level-breaks # Date: 04/19/95 # # Usage: level_break.pl [From-position] [To-position] # # Note: If no run-time arguments are provided, the from-to # positions are calculated from 1 to # the first record's first blank character # ################################################################################ # ENABLE THIS PERL SHRIPT TO RUN AS A SHELL SCRIPT eval 'exec perl -S $0 ${1+"$@"}' if 0; ################################################################################ # WHERE TO FIND PERL FUNCTIONS push (@INC,"/usr/local/src/lib/perl"); # WHERE TO FIND LOCAL PERL FUNCTIONS push (@INC,"/usr/local/perl4/lib"); # WHERE TO FIND STANDARD PERL FUNCTIONS require "perl_lib1.pl"; ################################################################################ # INITIALIZE SOME VARIABLES $FALSE = 0; $TRUE = 1; $last = ""; $flagfirst = $TRUE; ################################################################################ # GET FROM/TO POSITIONS OF AREA TO CHECK FOR LEVEL BREAK $from = @ARGV[0]; $to = @ARGV[1]; if ($from) { $flag_args = $TRUE; $from--; # CONVERT TO RELATIVE OFFSET $to--; # CONVERT TO RELATIVE OFFSET $len = (($to - $from) + 1); # GET LENGTH } else { $flag_args = $FALSE; } ################################################################################ while () { ###################################################################### # IF NO RUN-TIME ARGS ARE PROVIDED, CALCULATE FROM-TO # FROM POSITION1 UNTIL THE FIRST NON-BLANK POSITION OF THE # FIRST RECORD IN THE FILE if ($flag_args == $FALSE) { $len = length($_); for ($i=0;$i<$len;$i++) { if (substr($_,$i,1) eq " ") { last; } } $from = 1; $to = $i; $len = (($to - $from) + 1); # GET LENGTH $flag_args = $TRUE; } ###################################################################### $str = substr($_,$from,$len); if ($flagfirst == $TRUE) { $flagfirst = $FALSE; } else { if ($str ne $last) { print "\n"; } } $last = $str; print $_; } ################################################################################