#!/bin/sed -f # # Will Hall # Remove C++ comments :FindCplusplusComm /\/\//{ s/[ ]*\/\/.*$// N # delete the newline if there's nothing to it's left s/^\n// bFindCplusplusComm } # Remove C comments :FindBeginComm # find lines with begin-comment /\/\*/{ # look for (the left-most) end-comment on same line tz0;:z0 :SrchEndCommOnSameLine s/\*\//XoXendcommentXoX/ tEndCommOnSameLine bNoEndCommOnSameLine :EndCommOnSameLine # delete first comment within this line s/\/\*.*XoXendcommentXoX//;tz1;:z1 # look for another begin comment on same line s/\/\*/&/ tSrchEndCommOnSameLine bExhaustedBeginComms :NoEndCommOnSameLine # append next line to current buffer (strip newline) N;s/\n//;tz2;:z2 tSrchEndCommOnSameLine :ExhaustedBeginComms N # delete the newline if there's nothing to it's left s/^\n// # check for another begin-comment; if none, we're done w/ this line bFindBeginComm }