#!/usr/bin/awk -f # Extracts the first comment in program source. # Pipe it to firstsentence.awk to extract just the first sentence. BEGIN { sh = "#[^!] *(.*)$"; printing = 0; shstripper = "^ *#"; cstripper = "^[ \t]*\\*"; } printing && /\*\// { if ( cstripper == stripper ) { exit; } } printing && /^ *[^#]/ { if ( shstripper == stripper ) { exit; } } /#[^!] *(.*)$/ { # Shell, AWK, Ruby, or Perl (Python?) stripper = shstripper; printing = 1; } /^ *\/\*\*/ { # Java stripper = cstripper; printing = 1; # Note that RSTART and RLENGTH are not set. # Hence the redundant re below. sub( /^ *\/\*\*/, "" ); } /^ *\/\*([^*]|$)/ { # C stripper = cstripper; printing = 1; # Note that RSTART and RLENGTH are not set. # Hence the redundant re below. sub( /^ *\/\*([^*]|$)/, "" ); } /