Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: Want a way to strip comments from a Message-ID: <983@philmds.UUCP> Date: 20 Mar 89 12:52:15 GMT References: <7150@siemens.UUCP> <9900010@bradley> <4896@cbnews.ATT.COM> <978@philmds.UUCP> <3114@nunki.usc.edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 34 In article <3114@nunki.usc.edu> jeenglis@nunki.usc.edu (Joe English) writes: | |leo@philmds.UUCP (Leo de Wit) writes: |> |> puts(" A comment /* in here */"); |> |>And you can give more examples showing it isn't that trivial; a challenge |>for the sed adept, perhaps ... | |Does it *have* to be done in sed/awk/other text processor? |This problem is fairly difficult to solve using regexp/editor |commands, but it's a piece of cake to do in C: Piece of cake? Your program can't even strip its own comments (try it)! Reason: | case '"' : | instring = !instring; | break; This is both a defect in your program, and the cause that subsequent comments aren't detected when using the source as input. After the sequence '"' instring is 1. Besides it doesn't handle multiple character char constants (e.g. '/*', though one could perhaps argue whether it should). |This hasn't been tested thoroughly; it's mostly |from memory. If your memory was ok, the program wasn't tested thoroughly 8-). Though the problem isn't difficult, it isn't so trivial as you thought it was. Leo.