💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › C › lffix.… captured on 2024-07-09 at 01:42:13.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Newsgroups: comp.sys.apple2 Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!panix!MathWorks.Com!yeshua.marcam.com!zip.eecs.umich.edu!newsxfer.itd.umich.edu!nntp.cs.ubc.ca!unixg.ubc.ca!quartz.ucs.ualberta.ca!acs.ucalgary.ca!cpsc.ucalgary.ca!debug!griffin!dockery From: dockery@griffin.cuc.ab.ca (Sean Dockery) Subject: Re: Warp Six BBS 2.5 (description) Message-ID: <CrM85q.77A@griffin.cuc.ab.ca> Organization: Griffin Software Development References: <2tpqal$8fb@netaxs.com> <2tschj$jck@blue.weeg.uiowa.edu> Date: Sat, 18 Jun 1994 23:05:49 GMT Lines: 79 snelson@blue.weeg.uiowa.edu wrote the following article: | I know how to make this change with the Davex 'tr' command after dnloading, | but evidently the Unix 'tr' command works differently. Can someone tell | me how to change \012\040\040\040\040\012 to \040\040\040\040\040\040 | in unix? Not all \012, just the ones in that pattern. Then I can | correct the ones on grind.isca.uiowa.edu:apple2/apple8/bbs/Warp6.v25 | without having to dn/up load all of them with Kermit [SLOW......] :) tr is a character translator, not a pattern replacement utility. It is probably easier to handle the conversion with either awk or sed, but I am not sure how to handle control characters in regular expressions with either. Anyways, I hacked this together in about ten minutes. --------------------------------------------------------------------------- /* filter.c */ #include <stdio.h> /* sprintf, fprintf, putchar, getchar, EOF */ #include <stdlib.h> /* malloc, free */ #define NIL(tag) ((tag) 0) /* remove dependency on "NULL" macro */ int main (int argc, char **argv) { int ch = 0, i, index = 0; char *token; if ((token = (char *) malloc (7)) == NIL (char *)) { fprintf (stderr, "main: malloc failure\n"); exit (1); } sprintf (token, "%c%c%c%c%c%c", 012, 040, 040, 040, 040, 012); ch = getchar (); /* prime while loop */ while (ch != EOF) { if (ch == token[index]) /* character matches next space in token? */ index++; else if (index > 0) /* abstract buffer non-empty? */ { for (i = 0; i < index; i++) /* flush matched-so-far */ putchar (token[i]); putchar (ch); /* and first mis-match */ index = 0; } else /* only single character mis-match */ putchar (ch); if (index == 6) /* complete match? */ { printf ("%c%c%c%c%c%c", 040, 040, 040, 040, 040, 040); index = 0; } ch = getchar (); if (ch == EOF && index > 0) /* if EOF, flush matched-so-far */ for (i = 0; i < index; i++) putchar (token[i]); } free (token); /* no memory leaks here */ return 0; } /* main */ --------------------------------------------------------------------------- It compiles with `gcc -ansi -Wall -g filter.c' without no warnings. From my quick tests (from stdin,) it seems to be working properly. Invoke it using `./a.out < infile.bxy > outfile.bxy'. | --Steve (steven-nelson@uiowa.edu) -- Sean Dockery | Tickle us, do we not laugh? Griffin Software Development Group | Prick us, do we not bleed? dockery@griffin.cuc.ab.ca | Wrong us, shall we not revenge?