home *** CD-ROM | disk | FTP | other *** search
/ Software Du Jour / SoftwareDuJour.iso / BUSINESS / DBASE / DBAPG.ARC / SOFT-CUT.PRG < prev    next >
Encoding:
Text File  |  1984-08-12  |  2.4 KB  |  76 lines

  1. * Program.: SOFT-CUT.PRG
  2. * Author..: Kevin Jay Shepherd & Luis A. Castro
  3. * Date....: 06/26/84
  4. * Notice..: Copyright 1984, Ashton-Tate, All Rights Reserved
  5. * Version.: dBASE II, version 2.4x
  6. * Notes...: Segments a sentence at word boundaries.
  7. *
  8. SET TALK OFF
  9. ERASE
  10. @ 2, 0 SAY "SEGMENT A SENTENCE AT WORD BOUNDARIES"
  11. @ 2,72 SAY DATE()
  12. @ 3, 0 SAY "========================================"
  13. @ 3,40 SAY "========================================"
  14. ACCEPT "Enter first word " TO firstword
  15. ACCEPT "Enter the sentence " TO sentence
  16. IF firstword = " " .OR. sentence = " "
  17.    SET TALK ON
  18.    RETURN
  19. ENDIF
  20. INPUT "Enter desired column width " TO maxwidth 
  21. IF maxwidth < 10
  22.    SET TALK ON
  23.    RETURN
  24. ENDIF
  25. *
  26. * ---Initialize memory variables.
  27. STORE 1 TO startpos
  28. STORE maxwidth TO maxpos, backpos
  29. STORE "  " TO spacing
  30. * ---Initialize the left margin spaces for
  31. * ---the second and any subsequent lines.
  32. STORE $( STR( 0, LEN( firstword ) + 1 ),;
  33.       1, LEN( firstword ) ) + spacing TO indent
  34. * ---Initialize the first macro string.
  35. STORE [? firstword + spacing + ] +;
  36.       [$( sentence, startpos, maxpos - 1 )] TO Macro
  37. STORE F TO finished
  38. ?
  39. * ---Now, segment the character string at word boundaries.
  40. DO WHILE .NOT. finished .AND. backpos >= startpos
  41.    IF $( sentence, backpos, 1 ) = " "
  42.       &Macro
  43.       * ---Re-initialize macro string to indent with blanks.
  44.       STORE [? indent + ] +;
  45.             [$( sentence, startpos, maxpos - 1 )] TO Macro
  46.       * ---Reset the pointers to the next segment.
  47.       STORE maxwidth TO maxpos
  48.       STORE backpos + 1 TO startpos
  49.       STORE backpos + maxwidth TO backpos
  50.       IF backpos > LEN( TRIM( sentence ) )
  51.          * ---The end of the sentence has been encountered.
  52.          * ---Reset back pointer to the length of the sentence.
  53.          STORE LEN( TRIM( sentence ) ) TO backpos
  54.          STORE T TO finished
  55.       ENDIF
  56.    ELSE
  57.       STORE maxpos - 1 TO maxpos
  58.       STORE backpos - 1 TO backpos
  59.    ENDIF
  60. ENDDO
  61. * ---Print the last segment.
  62. IF backpos < startpos
  63.    * ---A word in the sentence was longer than the width.
  64.    ? "THE FOLLOWING WORD IS TOO LONG FOR THE SELECTED WIDTH:"
  65.    ? $( sentence, startpos )
  66.    CANCEL
  67. ELSE
  68.    * ---Print the last portion of the sentence.
  69.    ? indent + $( sentence, startpos )
  70. ENDIF
  71. *
  72. CLEAR
  73. SET TALK ON
  74. RETURN
  75. * EOF: SOFT-CUT.PRG
  76.