home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / hypercar / 3285 < prev    next >
Encoding:
Text File  |  1992-08-29  |  6.8 KB  |  199 lines

  1. Newsgroups: comp.sys.mac.hypercard
  2. Path: sparky!uunet!news.uiowa.edu!ffang
  3. From: ffang@newsuiowa.edu (Francis Fang)
  4. Subject: Re: First 80 chars?
  5. Sender: news@news.uiowa.edu (News)
  6. Message-ID: <1992Aug28.214418.3909@news.uiowa.edu>
  7. Date: Fri, 28 Aug 1992 21:44:18 GMT
  8. References: <1992Aug24.004837.1638@news.uiowa.edu>
  9. Nntp-Posting-Host: grover.printing.uiowa.edu
  10. Organization: University of Iowa, Iowa City, IA, USA
  11. X-Newsreader: Tin 1.1 PL3
  12. Lines: 185
  13.  
  14. SUMMARY:
  15.  
  16. First of all, I'd like to thanks all of those who helped by responding
  17. to my note regarding breaking up a block of text in a container to be
  18. sent to a host excepting 80 char lines of text. I have implemented it
  19. using a mixture of the responses.
  20.  
  21. The following is a summary of responses :
  22.  
  23. Initial message :
  24.  
  25. Hi all,
  26.  
  27. I've been designing a GUI interface for a piece of software that runs on
  28. our DEC mini in hypercard. I need to be able to break the contents of
  29. a field into 80 character lines so that I can send this information to
  30. fit a field on the mini (which unfortunately does not have word wrap).
  31. Is there some way I can do this without having to count the number of
  32. characters in words and adding them up and so on and so forth? Isn't
  33. there something that allows me to write the equivalent of :
  34.  
  35.    put the first 80 chars of cd fld "xxxyyyzzz" into <a container> ?
  36.  
  37. Or can I? I typed in the above (without the ?) and got a very computer
  38. like response of "Can't understand this."
  39.  
  40. Help!? Anyone?
  41.  
  42. Thanks in advance.
  43.  
  44. The responses
  45. --------------------------------------------------------------------------
  46. Ian Feldman (ianf@dada.uucp) gave this solution :
  47.  
  48.  on yourCommand ----------code not tested; may require some polishing
  49.    get field "myData" ------it now holds the data being operated upon
  50.    repeat with i= 1 to (length(it) div 80)---# of iterations required
  51.      put char (1+i*80)-80 to i*80 of it --redirect in right direction
  52.    end repeat --------------------------------------------------bingo
  53.  end yourCommand
  54.  
  55.  
  56.   I can assure you that this is by far the easiest solution.  Any
  57.   XCMD to break up the lines in fast-sized chunks that you might
  58.   find would be _negligibly_ faster, at best, if not outright
  59.   slower than this.
  60.  
  61. ------------------------------------------------------------------------
  62. Art Urban (urban@stout.atd.ucar.edu), 
  63. Jasper Kips (buurt1@rulfsw.leidenuniv.nl),
  64. and
  65. Tantek Celik (tron@apple.com) all suggested :
  66.  
  67. (Art's message follows)
  68. :
  69. :
  70.  
  71. you can simply say:
  72.  
  73.   put char 1 to 80 of cd fld "xyz" into <container>
  74.  
  75. I suppose a handler to do the whole shoot'n match would be:
  76.  
  77. on handler
  78.   repeat forever
  79.     if cd fld "xyz" is empty then exit repeat
  80.     put char 1 to 80 of cd fld "xyz" & return after <container>
  81.     delete char 1 to 80 of cd fld "xyz"
  82.   end repeat
  83. end handler
  84.  
  85. No, I haven't tried this, but I've done similar things in the past. Hope
  86. this helps!
  87. ------------------------------------------------------------------------
  88. Scott Bayes (bayes@hplvec.LVLD.HP.COM) optimized the above :
  89.  
  90. Neither have I tried it, but I think you first (before the repeat) want
  91. to copy the field to a container (get cd fld "xyz"), then use the
  92. container in the manipulation:
  93.  
  94. on handler
  95.   get cd fld "xyz"
  96.   repeat forever
  97.     if it is empty then exit repeat
  98.     put char 1 to 80 of it & return after <container>
  99.     delete char 1 to 80 of it
  100.   end repeat
  101. end handler
  102.  
  103. The reason being that operations that change fields always seem to hit
  104. the disk, causing your script to probably be very slow, and destructive
  105. of the orginal content of the field.
  106.  
  107. ------------------------------------------------------------------------
  108. Shawn O'Donnell (sro@media.mit.edu) offered a alternative solution :
  109.  
  110. :
  111.   If you want to go the route of munging the field in blocks of 80
  112. characters, you can do better than "char 1 to 80 of <container>".  You
  113. can make the line breaks on the screen of the minicomputer appear at
  114. word-boundaries-only by doing something like the following: (the
  115. source is in cd fld "source, the destination is cd fld "destination",
  116. and BufferContainer is a destructible buffer.)
  117.  
  118. on mouseUp
  119.   put empty into cd fld "destination"
  120.   put cd fld "source" into BufferContainer
  121.  
  122.   repeat until BufferContainer is empty
  123.     repeat with j = 5 to 20  -- some reasonable range for wds/line
  124.       if the length of BufferContainer < 80 then
  125.         put BufferContainer after cd fld "destination"
  126.         put empty into BufferContainer
  127.       else
  128.         if the length of (word 1 to j of BufferContainer) > 80 then
  129.           put word 1 to (j-1) of BufferContainer & return after [opt-return]
  130.           cd fld "destination"
  131.           delete word 1 to (j-1) of BufferContainer
  132.           exit repeat
  133.         end if
  134.       end if
  135.     end repeat
  136.   end repeat
  137. end mouseUp
  138.  
  139. ---
  140. The above would have been great except we both found that when you say
  141. line 1 of <a container>, Hypercard does not return the first line you
  142. see on the screen in your field but the line ending with a return.
  143.  
  144. ------------------------------------------------------------------------
  145. Finally N J Taber (NJTaber@mitre.org) writes :
  146.  
  147. :
  148. :
  149. The following code (based on a script in a HyperCard application by
  150. Harry Chesley at Apple) does the same job and may be easier to understand.
  151. The message in the example is in the local variable "m" and the output (80
  152. characters per line) is being written to card field "message".  Modify
  153. those parameters to fit your situation.
  154.  
  155.   repeat with i = 1 to the number of lines in m
  156.     get line i of m
  157.     repeat while the number of chars of it > 80
  158.       repeat with j = 80 down to 1
  159.         if char j of it is " " then exit repeat
  160.       end repeat
  161.       if j < 20 then put 80 into j
  162.       put char 1 to j of it & return after cd field "message"
  163.       delete char 1 to j of it
  164.     end repeat
  165.     put it & return after cd field "message"
  166.   end repeat
  167.  
  168.  
  169. ------------------------------------------------------------------------
  170. Shawn and I had also both tried the following :
  171.  
  172. (Shawn wrote) :
  173. You can create an invisible field, set its font to Monaco, 9 pt and
  174. set its width so that the maximum number of characters per line is 80.
  175. Then you put the text of the real field into the invisible field, and
  176. you
  177.  
  178. repeat with j = 1 to the number of lines in fld "invisible"
  179.   put line j of fld "invisible" into line j of <the mini's field>
  180. end repeat
  181.  
  182. The line breaks will be at word boundaries, and any empty lines will
  183. be transferred intact.   If you don't mind looking at Monaco, you
  184. could just set the source field to Monaco, 9 point, 80 characters
  185. wide and skip the invisible field.
  186.  
  187. ---
  188. The above would have been great except we both found that when you say
  189. line 1 of <a container>, Hypercard does not return the first line you
  190. see on the screen in your field but the line ending with a return.
  191.  
  192. ------------------------------------------------------------------------
  193.  
  194. Once again, thanks for all your responses. Hope somebody finds this
  195. summary somewhat helpful.
  196.  
  197. Frank.
  198.  
  199.