home *** CD-ROM | disk | FTP | other *** search
- Path: wupost!m.cs.uiuc.edu!vela!umich!umeecs!msi.umn.edu!noc.MR.NET!uc!apctrc!voyager!zjdg11
- From: zjdg11@eddie.chi.amoco.com (Jim Graham)
- Newsgroups: alt.sources
- Subject: alternate breakstrings() for ulp (micro lp)
- Message-ID: <1991Aug19.144325.29804@hou.amoco.com>
- Date: 19 Aug 91 14:43:25 GMT
- Sender: news@hou.amoco.com
- Organization: Amoco Corporation, Telecommunications Network Design
- Lines: 135
- Originator: zjdg11@eddie
-
- saturday morning, while waiting for a UPS package to arrive, I decided to
- use ulp to print a long thread of articles from rec.pets.cats, which is among
- the types of things I wrote it for. well, I quickly realized that, due to the
- length of some of the From:, Path:, and References: fields, and the fact that
- (with the exception of References:) the items are not delineated by spaces,
- but by !s, which breakstrings() wouldn't know what to do with. therefore, I
- needed to either edit the file or add some smarts to breakstrings. knowing
- that this would come up again, can you guess which one I chose?
-
- (btw, the main problem that concerns me is that in double column mode, it
- would just go ahead and print the line, and then that would get written over
- later on --- that also has been taken care of...this version of the function
- will try to split at a space or at a ! in a bang-path, but if it can't, it
- will split at linelength-1, regardless.)
-
- this breakstrings() function basically replaces the old one in string.c.
- the rest of the code need not be changed to support this. I strongly
- suggest that you keep a copy of the old version handy, just in case your
- system doesn't like this one.
-
- the output of this will look something like the following (w/o the '>'s):
-
- > From foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
- > !gargleblaster!whatever
-
- > Path: foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
- > !gargleblaster!whatever
-
- > From: foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
- > !gargleblaster!whatever
-
- > References: <reference> <reference> <reference> <reference> <reference>
- > <reference> <reference>
-
-
- neat, eh?
- --jim
-
- Standard disclaimer....Ever since my cat learned to type, there's no telling
- whose thoughts these really are....but they are not my employer's (are they?).
- 73 DE N5IAL (/9)
- ------------------------------------------------------------------------------
- "Oh dear, I think you'll find reality's on the blink again."
- -- Marvin The Paranoid Android
- INTERNET: || AMATEUR RADIO (Packet):
- zjdg11@hou.amoco.com (pref.) || TCP/IP: jim@n5ial.ampr.org (44.72.47.193)
- j.graham@ieee.org || AX.25: n5ial@wb9yae (Chicago, IL, US)
- grahj@gagme.chi.il.us ||
- ------------------------------------------------------------------------------
-
- -------------------------------- CUT HERE --------------------------------
-
- breakstrings (string1,string2)
- char string1[],string2[];
- {
- int i,tmp=0,foo=0,infrom=0,inpath=0,inrefs=0;
- static int wasinfrom=0,wasinpath=0,wasinrefs=0;
- int len;
-
- len = strlen(string1);
-
- /* handle headers for mail/news, where lines may be exceptionally long, */
- /* and items aren't broken up by spaces, but by ! (i.e., a bang-path) */
- /* OR the references line --- we'll just format this one a bit if we */
- /* break it. */
-
- if (!strncmp(string1,"From:",5)) /* ^From: */
- {
- infrom=1;
- wasinfrom=1;
- }
- else if (!strncmp(string1,"From",4)) /* ^From */
- {
- infrom=2;
- wasinfrom=2;
- }
- else if (!strncmp(string1,"Path:",5)) /* ^Path: */
- {
- inpath=1;
- wasinpath=1;
- }
- else if (!strncmp(string1,"References:",11)) /* ^References: */
- {
- inrefs=1;
- wasinrefs=1;
- }
- else if (wasinfrom && !strncmp(string1," ",4)) infrom = wasinfrom;
- else if (wasinpath && !strncmp(string1," ",5)) inpath = 1;
- else if (wasinrefs && !strncmp(string1," ",5)) inrefs = 1;
- else
- {
- wasinfrom = 0;
- wasinpath = 0;
- wasinrefs = 0;
- } /* reset these in case needed */
-
- for (i=linelength;!foo && i;--i)
- if (string1[i] == 32) foo = i;
- if (!foo && !infrom && !inpath && !inrefs) foo = linelength-1;
-
- if ((infrom || inpath) && foo < 10) /* really is From: or Path: */
- {
- foo = 0;
- for (i=linelength;!foo && i;--i)
- if (string1[i] == 33) foo = i-1;
- if (!foo) foo = linelength-1;
- }
-
- if (inrefs || inpath || infrom)
- {
- if (inrefs) tmp = 12;
- else if (inpath || infrom == 1) tmp = 6;
- else if (infrom == 2) tmp = 5;
- for (i=0;i<tmp;++i) string2[i] = 32;
- }
- else tmp = 0; /* just for safety..... anti-careless, etc. */
-
- for (i=foo+1;i<len;++i)
- {
- string2[tmp] = string1[i];
- ++tmp;
- }
- string2[tmp] = '\0';
- if (inpath || infrom) string1[foo+1] = '\0';
- else string1[foo] = '\0';
-
- len = strlen(string2); /* in case we won't be coming back.... */
- if (len <= linelength) /* reset these in case we need to */
- {
- wasinfrom = 0;
- wasinpath = 0;
- wasinrefs = 0;
- }
- return 1;
- }
-