Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!qantel!lll-crg!seismo!brl-tgr!tgr!cottrell@nbs-vms.arpa From: cottrell@nbs-vms.arpa (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: Comments on your program Message-ID: <135@brl-tgr.ARPA> Date: Wed, 27-Nov-85 17:31:42 EST Article-I.D.: brl-tgr.135 Posted: Wed Nov 27 17:31:42 1985 Date-Received: Fri, 29-Nov-85 21:36:24 EST Sender: news@brl-tgr.ARPA Lines: 62 /* > Everybody I've shown this program to has *groaned* and complained > about what a nasssty program it was... This program was written > to help decode a bitnet routing table that I had been netcopy'd > to me and didn't get translated into ascii. So after running dd > over it, the line markers had disappeared into never never land. > But from looking real closely at the file I could see that each > line was supposed to start with ROUTE..... thus this program: It doesn't work. Suppose the sequence `ROUROUTE' occurs. The second `R' will not be recognized as the start of the sequence! > #include > > main() > { > register int r, o, u, t, e; > > while ((r = getchar()) != EOF) { > if (r == 'R') > if ((o = getchar()) == 'O') > if ((u = getchar()) == 'U') > if ((t = getchar()) == 'T') > if ((e = getchar()) == 'E') > printf("\nROUTE"); > else > printf("ROUT%c", e); > else > printf("ROU%c", t); > else > printf("RO%c", u); > else > printf("R%c", o); > else > putchar(r); > } > putchar('\n'); > } > -- > David Herron, cbosgd!ukma!david, david@UKMA.BITNET. I thought of ways to use existing tools to do the job. How about this: 1) run thru `tr' to change all `R's to newlines. This gives you all possible places where a line might start. Now run an `ex' script that chex (wheat, corn, rice) each line begins with OUTE. If it doesn't, then put back the R. Then for each line that begins with an R, join it with the previous line. Finally, put back an R on each line. So we have: v/^OUTE/s/^/R/ g/^R/.-1,.j g/^/s/^/R/ wq If you're clever you might be able to work out a sed script. > Experience is something you don't get until just after you need it. To quote what you once said to me:`Now why didn't you think before posting?' jim cottrell@nbs */ ------