home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3870 < prev    next >
Encoding:
Internet Message Format  |  1991-08-22  |  4.9 KB

  1. Path: wupost!m.cs.uiuc.edu!vela!umich!umeecs!msi.umn.edu!noc.MR.NET!uc!apctrc!voyager!zjdg11
  2. From: zjdg11@eddie.chi.amoco.com (Jim Graham)
  3. Newsgroups: alt.sources
  4. Subject: alternate breakstrings() for ulp (micro lp)
  5. Message-ID: <1991Aug19.144325.29804@hou.amoco.com>
  6. Date: 19 Aug 91 14:43:25 GMT
  7. Sender: news@hou.amoco.com
  8. Organization: Amoco Corporation, Telecommunications Network Design
  9. Lines: 135
  10. Originator: zjdg11@eddie
  11.  
  12. saturday morning, while waiting for a UPS package to arrive, I decided to
  13. use ulp to print a long thread of articles from rec.pets.cats, which is among
  14. the types of things I wrote it for.  well, I quickly realized that, due to the
  15. length of some of the From:, Path:, and References: fields, and the fact that
  16. (with the exception of References:) the items are not delineated by spaces,
  17. but by !s, which breakstrings() wouldn't know what to do with.  therefore, I
  18. needed to either edit the file or add some smarts to breakstrings.  knowing
  19. that this would come up again, can you guess which one I chose?
  20.  
  21. (btw, the main problem that concerns me is that in double column mode, it
  22. would just go ahead and print the line, and then that would get written over
  23. later on --- that also has been taken care of...this version of the function
  24. will try to split at a space or at a ! in a bang-path, but if it can't, it
  25. will split at linelength-1, regardless.)
  26.  
  27. this breakstrings() function basically replaces the old one in string.c.
  28. the rest of the code need not be changed to support this.  I strongly
  29. suggest that you keep a copy of the old version handy, just in case your
  30. system doesn't like this one.
  31.  
  32. the output of this will look something like the following (w/o the '>'s):
  33.  
  34. > From foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
  35. >      !gargleblaster!whatever
  36.  
  37. > Path: foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
  38. >       !gargleblaster!whatever
  39.  
  40. > From: foobar!foo!bar!baz!zaphod!beeblebrox!ford!prefect!pangalactic
  41. >       !gargleblaster!whatever
  42.  
  43. > References: <reference> <reference> <reference> <reference> <reference>
  44. >             <reference> <reference>
  45.  
  46.  
  47. neat, eh?
  48.    --jim
  49.  
  50. Standard disclaimer....Ever since my cat learned to type, there's no telling
  51. whose thoughts these really are....but they are not my employer's (are they?).
  52. 73 DE N5IAL (/9)
  53. ------------------------------------------------------------------------------
  54. "Oh dear, I think you'll find reality's on the blink again."
  55.    -- Marvin The Paranoid Android
  56.          INTERNET:               ||              AMATEUR RADIO (Packet):
  57.    zjdg11@hou.amoco.com (pref.)  || TCP/IP: jim@n5ial.ampr.org (44.72.47.193)
  58.    j.graham@ieee.org             || AX.25:  n5ial@wb9yae    (Chicago, IL, US)
  59.    grahj@gagme.chi.il.us         ||
  60. ------------------------------------------------------------------------------
  61.  
  62.  --------------------------------  CUT HERE  --------------------------------
  63.  
  64. breakstrings (string1,string2)
  65. char string1[],string2[];
  66. {
  67. int i,tmp=0,foo=0,infrom=0,inpath=0,inrefs=0;
  68. static int wasinfrom=0,wasinpath=0,wasinrefs=0;
  69. int len;
  70.  
  71. len = strlen(string1);
  72.  
  73. /* handle headers for mail/news, where lines may be exceptionally  long, */
  74. /* and items aren't broken up by spaces, but by ! (i.e., a bang-path)    */
  75. /* OR the references line --- we'll just format this one a bit if we     */
  76. /* break it. */
  77.  
  78. if (!strncmp(string1,"From:",5))              /* ^From: */
  79.    {
  80.    infrom=1;
  81.    wasinfrom=1;
  82.    }
  83. else if (!strncmp(string1,"From",4))          /* ^From */
  84.    {
  85.    infrom=2;
  86.    wasinfrom=2;
  87.    }
  88. else if (!strncmp(string1,"Path:",5))         /* ^Path:  */
  89.    {
  90.    inpath=1;
  91.    wasinpath=1;
  92.    }
  93. else if (!strncmp(string1,"References:",11))  /* ^References: */
  94.    {
  95.    inrefs=1;
  96.    wasinrefs=1;
  97.    }
  98. else if (wasinfrom && !strncmp(string1,"    ",4)) infrom = wasinfrom;
  99. else if (wasinpath && !strncmp(string1,"     ",5)) inpath = 1;
  100. else if (wasinrefs && !strncmp(string1,"     ",5)) inrefs = 1;
  101. else
  102.    {
  103.    wasinfrom = 0;
  104.    wasinpath = 0;
  105.    wasinrefs = 0;
  106.    }  /* reset these in case needed */
  107.  
  108. for (i=linelength;!foo && i;--i)
  109.    if (string1[i] == 32) foo = i;
  110. if (!foo && !infrom && !inpath && !inrefs) foo = linelength-1;
  111.  
  112. if ((infrom || inpath) && foo < 10)  /* really is From: or Path: */
  113.    {
  114.    foo = 0;
  115.    for (i=linelength;!foo && i;--i)
  116.       if (string1[i] == 33) foo = i-1;
  117.    if (!foo) foo = linelength-1;
  118.    }
  119.  
  120. if (inrefs || inpath || infrom)
  121.    {
  122.    if (inrefs) tmp = 12;
  123.    else if (inpath || infrom == 1) tmp = 6;
  124.    else if (infrom == 2) tmp = 5;
  125.    for (i=0;i<tmp;++i) string2[i] = 32;
  126.    }
  127. else tmp = 0;   /* just for safety..... anti-careless, etc. */
  128.  
  129. for (i=foo+1;i<len;++i)
  130.    {
  131.    string2[tmp] = string1[i];
  132.    ++tmp;
  133.    }
  134. string2[tmp] = '\0';
  135. if (inpath || infrom) string1[foo+1] = '\0';
  136. else string1[foo] = '\0';
  137.  
  138. len = strlen(string2);    /* in case we won't be coming back.... */
  139. if (len <= linelength)    /* reset these in case we need to */
  140.    {
  141.    wasinfrom = 0;
  142.    wasinpath = 0;
  143.    wasinrefs = 0;
  144.    }
  145. return 1;
  146. }
  147.