home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / pascal / 7640 < prev    next >
Encoding:
Text File  |  1992-12-22  |  4.0 KB  |  101 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!usc!cs.utexas.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!bgsuvax!jzawodn
  3. From: jzawodn@bgsu.edu (jeremy zawodny)
  4. Subject: Help needed in writing a word-wrap function in a unit (BP 7.0)
  5. Message-ID: <BzowyE.FI6@andy.bgsu.edu>
  6. Summary: why doesn't this work?
  7. Keywords: pascal, word, bp7.0
  8. Sender: jzawodn@andy.bgsu.edu (jeremy zawodny)
  9. Organization: Bowling Green State Univ.
  10. Distribution: na
  11. Date: Wed, 23 Dec 1992 02:15:48 GMT
  12. Lines: 87
  13.  
  14. Hey Netters!  Now that all the crap has cleared up about my encryption
  15. problem, I have a new problem...
  16.  
  17. I'm using Borland Pascal w/ Objects 7.0 to write a function (in a unit so
  18. that other programs can use it) that takes a null-terminated string as a
  19. parameter and retuns a new-null terminated string that is formatted
  20. differently.  The new string should have returns stuck in the proper
  21. location so that when it is displayed on a screen of width x, none of the
  22. words will be split at the end of a line.  Basically, that's word-wrap.
  23.  
  24. I've made a few attempts at it, none of which have been successful.  I
  25. have appended my most recent trial.  I'd really appreciate it if somebody
  26. could look it over and tell me what's wrong with it.  Right now, if I pass
  27. it a string of length 90 or so to be formatted for a 80 column output, it
  28. sends crap.
  29.  
  30. Ideally, the formatted string should be able to display with just a
  31. writeln statement.
  32.  
  33. Thanks for any help or suggestions.
  34.  
  35. Jeremy
  36.  
  37. ----------------------------begin function here----------------------------
  38.  
  39. uses strings;
  40.  
  41. function WrapString(OldArray : PChar; MaxLine : integer) : PChar;
  42.          var
  43.             OldArrayPos, OldArrayLen, CWord, NewArrayPos, x : integer;
  44.             inchar : char;
  45.             NewArray : Array[0..8192] of char;
  46.  
  47.          begin
  48.               OldArrayLen := strlen(OldArray);
  49.               OldArrayPos := 0;  NewArrayPos := 0;  CWord := 0;
  50.               while (OldArrayPos <= OldArrayLen) do
  51.                     begin
  52.                          CWord := 0;
  53.                          inchar := OldArray[OldArrayPos];
  54.                          while (inchar <> ' ') and (inchar <> #00) do
  55.                                begin
  56.                                     CWord := CWord+1;
  57.                                     OldArrayPos := OldArrayPos+1;
  58.                                     inchar := OldArray[OldArrayPos];
  59.                                end;
  60.                          if (OldArrayPos) < MaxLine then
  61.                             begin
  62.                                  for x:=1 to CWord do
  63.                                      begin
  64.                                           NewArray[NewArrayPos] :=
  65. OldArray[(OldArrayPos - CWord - 1 + x)];
  66.                                           NewArrayPos := NewArrayPos + 1;
  67.                                      end;
  68.                                  NewArray[NewArrayPos] := ' '; 
  69. Inc(NewArrayPos);
  70.                                  Inc (OldArrayPos);
  71.                             end
  72.                          else
  73.                              begin
  74.                                   NewArray[NewArrayPos] := #10; 
  75. Inc(NewArrayPos);
  76.                                   NewArray[NewArrayPos] := #13; 
  77. Inc(NewArrayPos);
  78.                                   for x:=1 to CWord do
  79.                                      begin
  80.                                           NewArray[NewArrayPos] :=
  81. OldArray[(OldArrayPos - CWord - 1 + x)];
  82.                                           NewArrayPos := NewArrayPos + 1;
  83.                                      end;
  84.                                   NewArray[NewArrayPos] := ' '; 
  85. Inc(NewArrayPos);
  86.                                   Inc (OldArrayPos);
  87.                              end;
  88.                     end;
  89.               end;
  90.  
  91. -------------------------------end function here-------------------------
  92.  
  93.  
  94.  
  95.  
  96. -- 
  97. ------------------------------------------------------------------------------
  98. Jeremy Daniel Zawodny                           Computer Science Undergraduate
  99.                       Bowling Green State University
  100. ------------------------------------------------------------------------------
  101.