home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mpbeta-2.zip / fmtdesc.cmd < prev    next >
OS/2 REXX Batch file  |  1994-07-12  |  3KB  |  73 lines

  1. /*                                                                           */
  2. /* FMTDESC.CMD                                                               */
  3. /*                                                                           */
  4. /* Craig Morrison, 10 July 1994, inspired and requested by Elliott Goodman,  */
  5. /* who can be credited for quite a few things in MaxFile/PM.                 */
  6. /*                                                                           */
  7. /* An example REXX script that will take a given string and perform simple   */
  8. /* word wrapping to 'format' a line of text. This roughly approximates the   */
  9. /* 'Format Description' option included in MaxFile/PM.                       */
  10. /*                                                                           */
  11. /* Use, abuse, fold, spindle or mutilate freely.                             */
  12. /*                                                                           */
  13.  
  14. text = ' This is a long 'x2c('0d')' 'x2c('0a')' string > that is going to get '
  15. text = text||'formatted for Elliott. '
  16. text = text||Copies('01234567890123456', 4)||text
  17.  
  18. lmargin = 16         /* how far from the left margin the ED Marker should be */
  19. llength = 45                 /* this is how long each line segment should be */
  20. EDMarker = '>'        /* Set EDMarker to your extended description character */
  21.  
  22. spaces = SubStr(Copies(' ', 80), 1, lmargin)||EDMarker||' '
  23.  
  24. /* Translate all CRs, LFs and Extended Description Markers into spaces       */
  25. ntext = Translate(text, '   ', x2c('0d')||x2c('0a')||EDMarker)
  26.  
  27. ntext = Space(ntext, 1)                       /* remove all the extra spaces */
  28.  
  29. Say 'Before:'
  30. Say
  31. Say Text
  32.  
  33. text = GetOneLine(llength, ntext)
  34. ntext = Space(DelWord(ntext, 1, Words(text)), 1)
  35. Do While Length(ntext) \= 0
  36.     wText = GetOneLine(llength, ntext)
  37.     text = text||x2c('0d')||x2c('0a')||spaces||wText
  38.     ntext = Space(DelWord(ntext, 1, Words(wText)), 1)
  39. End
  40.  
  41. Say
  42. Say 'After:'
  43. Say
  44. Say text
  45.  
  46. Exit
  47.  
  48. /*
  49.     GetOneLine takes a variable length string and returns a blank delimited
  50.     string that is a substring of inText and is no longer than llen
  51.     characters.
  52.  
  53.     A single word that is longer than llen is simply truncated at llen when it
  54.     would be the only word in a line segment and not wrappable. Its cheesy and
  55.     cheap, but hey, it works.. ;-)
  56. */
  57. GetOneLine:
  58.  
  59.     Parse Arg llen, inText
  60.  
  61.     cText = ''
  62.     Do While Length(cText' 'Word(inText, 1)) < llen
  63.         cText = cText' 'Word(inText, 1)
  64.         inText = DelWord(inText, 1, 1)
  65.         If inText = '' Then Leave
  66.     End
  67.  
  68.     if cText = '' Then Do
  69.         cText = Left(inText, llen)
  70.     End
  71.  
  72. Return Space(cText, 1)
  73.