#!/bin/sh # # read a TAGS file created by etags and print the contents in ASCII # sep=`/bin/echo -n -e '\177'` eol=`/bin/echo -n -e '\001'` fil=`/bin/echo -n -e '\014'` cat "$1" | sed -n -e \ " # lines defining symbols have either of the following formats: # # 1: leader \177 symbolName \001 lineNumber , byteCount # 2: leader \177 lineNumber , byteCount # first, remove the trailing byte count s/,[0-9]\+$//1 # # The leader component will look like one of the following # # stuff name \177 ... # stuff name( \177 ... # # Convert the leaders to this format: # # name \177 ... # # Do this by remove "stuff", blanks, and the ( that optionally # follows the name /$sep/{ s/^.*\<\([a-zA-Z_0-9]\+\)[ =\t(;\[]*$sep/\1$sep/1; s/^ *//1 s/ *,/,/1 } # we now have one of the following formations: # # name \177 name \001 lineNumber # name \177 lineNumber # # Normalize this to # # name , lineNumber s/^\(.*\)$sep\(.*\)$eol/\2$sep/1 p;d; # stop processing and go to the next line s/$sep/,/1 " | sed -n -e \ " # # concatenate the whole file into 1 giant string # 1h; 1!H; \${ # on the last line of the file, swap the whole mess # back into pattern buffer # x; # unsplit the lines pairs that look like this # # ^L # filename # # and make them look like this: # # @filename s/$fil\n\([^\n]\+\)\n/@\1\n/g; # # print the whole mess out # p; } " | sed -n -e \ " # # We are expecting a sequence of groups with each group # looking like this: # # @filename # symbol,lineNumber # # And we are going to change it so that they look like this: # # filename:lineNumber: symbol # /^@/{ # just save file names for later use s/^@//1 h; d; # hold this line and stop processing } { # on lines that are not files, append the file name # to the current line like this: # # symbol $sep lineNumber \n filename G; s/\(.*\)$sep\(.*\)\n\(.*\)$/\3:\2: \1/1 # # At this point, we have a structure like this in the pattern space # # filename:lineNumber:STUFF # # Normally, STUFF is a symbol -- but it might also be a comma separated # list of symbols. Let us remove the first command the trailing text # just to get moving # s/^\([^,]\+\),.*/\1/1 p; } "