home *** CD-ROM | disk | FTP | other *** search
/ Better Homes & Gardens: …oking for Today - Chicken / Image.iso / pc / shared.dxr / 01010_tools.ls < prev    next >
Encoding:
Text File  |  1995-11-21  |  5.6 KB  |  231 lines

  1. on writeFile text
  2.   set myObj to FileIO(mnew, "?write", "fileName")
  3.   if objectp(myObj) then
  4.     myObj(mWriteString, text)
  5.     myObj(mdispose)
  6.   end if
  7. end
  8.  
  9. on readFile
  10.   set myObj to FileIO(mnew, "?read", "TEXT")
  11.   if objectp(myObj) then
  12.     return myObj(mReadToken, EMPTY, EMPTY)
  13.     myObj(mdispose)
  14.   end if
  15. end
  16.  
  17. on readLine aFileName
  18.   set myObj to FileIO(mnew, "read", the pathName & aFileName)
  19.   if objectp(myObj) then
  20.     return myObj(mReadLine)
  21.     myObj(mdispose)
  22.   end if
  23. end
  24.  
  25. on fileToList
  26.   global aList
  27.   set aList to []
  28.   set content to "dummy"
  29.   if objectp(myObj) then
  30.     myObj(mdispose)
  31.   end if
  32.   set myObj to FileIO(mnew, "?read", "TEXT")
  33.   if objectp(myObj) then
  34.     repeat while content <> EMPTY
  35.       set content to myObj(mReadLine)
  36.       add(aList, content)
  37.     end repeat
  38.   end if
  39.   if objectp(myObj) then
  40.     myObj(mdispose)
  41.   end if
  42.   put "file to list complete"
  43.   return aList
  44. end
  45.  
  46. on listToFile aList
  47.   set file to EMPTY
  48.   repeat with i in aList
  49.     put i & RETURN after file
  50.   end repeat
  51.   writeFile(file)
  52. end
  53.  
  54. on stringToList theString
  55.   global aList
  56.   set aString to theString
  57.   set aList to []
  58.   set num to the number of lines in aString
  59.   repeat with i = 1 to num
  60.     set anItem to line i of aString
  61.     add(aList, anItem)
  62.   end repeat
  63.   return aList
  64. end
  65.  
  66. on listToString aList
  67.   global newList
  68.   set newList to EMPTY
  69.   repeat with i in aList
  70.     put i & RETURN after newList
  71.   end repeat
  72.   return newList
  73. end
  74.  
  75. on listToString3 aList
  76.   global newList
  77.   set newList to EMPTY
  78.   repeat with i in aList
  79.     put i & RETURN after newList
  80.   end repeat
  81.   return newList
  82. end
  83.  
  84. on listToString2 aList
  85.   global newLista
  86.   set newList to EMPTY
  87.   repeat with i in aList
  88.     put i & RETURN & RETURN after newList
  89.   end repeat
  90.   return newList
  91. end
  92.  
  93. on removeReturns fieldName
  94.   set num to the number of lines in field fieldName
  95.   set it to field fieldName
  96.   repeat with i = num down to 1
  97.     if line i of it = EMPTY then
  98.       delete line i of it
  99.     end if
  100.   end repeat
  101.   put it into field fieldName
  102.   return it
  103. end
  104.  
  105. on removeReturns2 aString
  106.   set num to the number of lines in aString
  107.   repeat with i = num down to 1
  108.     if line i of aString = EMPTY then
  109.       delete line i of aString
  110.     end if
  111.   end repeat
  112.   return aString
  113. end
  114.  
  115. on removeCarrots aString
  116.   repeat while 1
  117.     set Carrot to offset("^", aString)
  118.     if Carrot then
  119.       delete char Carrot of aString
  120.       return removeCarrots(aString)
  121.       next repeat
  122.     end if
  123.     exit repeat
  124.   end repeat
  125.   return aString
  126. end
  127.  
  128. on removeSpace aString
  129.   repeat while 1
  130.     set space to offset(" ", aString)
  131.     if space then
  132.       delete char space of aString
  133.       return removeSpace(aString)
  134.       next repeat
  135.     end if
  136.     exit repeat
  137.   end repeat
  138.   return aString
  139. end
  140.  
  141. on floatToFrac float
  142.   set whole to 0
  143.   set fraction to 0
  144.   if float > 1.0 then
  145.     set floatString to string(float)
  146.     set point to offset(".", floatString)
  147.     set whole to integer(char 1 to point - 1 of floatString)
  148.     set float to float - whole
  149.   end if
  150.   if float > 0.0 then
  151.     if float <= 0.0625 then
  152.       set fraction to "1/16"
  153.     else
  154.       if float <= 0.125 then
  155.         set fraction to "1/8"
  156.       else
  157.         if float <= 0.1875 then
  158.           set fraction to "3/16"
  159.         else
  160.           if float <= 0.25 then
  161.             set fraction to "1/4"
  162.           else
  163.             if float <= 0.3125 then
  164.               set fraction to "5/16"
  165.             else
  166.               if float <= 0.33400000000000002 then
  167.                 set fraction to "1/3"
  168.               else
  169.                 if float <= 0.375 then
  170.                   set fraction to "3/8"
  171.                 else
  172.                   if float <= 0.4375 then
  173.                     set fraction to "7/16"
  174.                   else
  175.                     if float <= 0.5 then
  176.                       set fraction to "1/2"
  177.                     else
  178.                       if float <= 0.5625 then
  179.                         set fraction to "9/16"
  180.                       else
  181.                         if float <= 0.625 then
  182.                           set fraction to "5/8"
  183.                         else
  184.                           if float <= 0.66700000000000004 then
  185.                             set fraction to "2/3"
  186.                           else
  187.                             if float <= 0.6875 then
  188.                               set fraction to "11/16"
  189.                             else
  190.                               if float <= 0.75 then
  191.                                 set fraction to "3/4"
  192.                               else
  193.                                 if float <= 0.8125 then
  194.                                   set fraction to "13/16"
  195.                                 else
  196.                                   if float <= 0.875 then
  197.                                     set fraction to "7/8"
  198.                                   else
  199.                                     if float <= 0.9375 then
  200.                                       set fraction to "15/16"
  201.                                     else
  202.                                       set whole to whole + 1
  203.                                     end if
  204.                                   end if
  205.                                 end if
  206.                               end if
  207.                             end if
  208.                           end if
  209.                         end if
  210.                       end if
  211.                     end if
  212.                   end if
  213.                 end if
  214.               end if
  215.             end if
  216.           end if
  217.         end if
  218.       end if
  219.     end if
  220.   end if
  221.   if (fraction <> 0) and (whole <> 0) then
  222.     return whole & "-" & fraction
  223.   else
  224.     if fraction <> 0 then
  225.       return fraction
  226.     else
  227.       return whole
  228.     end if
  229.   end if
  230. end
  231.