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

  1. on removeDuplicates
  2.   global aList, newList
  3.   set aList to fileToList()
  4.   set newList to []
  5.   repeat with i in aList
  6.     if getPos(newList, i) then
  7.       nothing()
  8.       next repeat
  9.     end if
  10.     add(newList, i & RETURN)
  11.   end repeat
  12.   listToFile(newList)
  13. end
  14.  
  15. on removeDuplicatesString string
  16.   global aList, newList
  17.   set aList to stringToList(string)
  18.   sort(aList)
  19.   set newList to []
  20.   repeat with i in aList
  21.     if getPos(newList, i) then
  22.       nothing()
  23.       next repeat
  24.     end if
  25.     add(newList, i)
  26.   end repeat
  27.   listToFile(newList)
  28. end
  29.  
  30. on removeSortedDuplicates
  31.   global aList, formatted
  32.   set aList to fileToList()
  33.   set formatted to []
  34.   set lastOne to EMPTY
  35.   repeat with i in aList
  36.     if not (i = lastOne) then
  37.       set lastOne to i
  38.       add(formatted, i)
  39.     end if
  40.   end repeat
  41.   listToFile(formatted)
  42. end
  43.  
  44. on interlace
  45.   global aList, list1, list2, interlaced
  46.   set list1 to fileToList()
  47.   set list2 to fileToList()
  48.   set lineNum to 0
  49.   set interlaced to []
  50.   repeat with i in list1
  51.     set lineNum to lineNum + 1
  52.     set aLine to line 1 of i
  53.     repeat with j in list2
  54.       if j = EMPTY then
  55.         exit repeat
  56.       end if
  57.       set anIngredient to line 1 of j
  58.       if aLine contains anIngredient then
  59.         add(interlaced, lineNum & "@" & j)
  60.       end if
  61.     end repeat
  62.   end repeat
  63.   listToFile(interlaced)
  64. end
  65.  
  66. on idize
  67.   global aList, list1, list2, interlaced
  68.   set list1 to fileToList()
  69.   set list2 to fileToList()
  70.   set lineNum1 to 0
  71.   set lineNum2 to 1
  72.   set interlaced to []
  73.   repeat with i in list1
  74.     set lineNum1 to lineNum1 + 1
  75.     set anID to line 1 of i
  76.     repeat while 1
  77.       set aLine to getAt(list2, lineNum2)
  78.       set aLineNum to the number of words in aLine
  79.       if word 1 of aLine = lineNum1 then
  80.         add(interlaced, anID & word 2 to aLineNum of aLine & RETURN)
  81.         set lineNum2 to lineNum2 + 1
  82.         next repeat
  83.       end if
  84.       exit repeat
  85.     end repeat
  86.   end repeat
  87.   listToFile(interlaced)
  88. end
  89.  
  90. on separateFile
  91.   global aList, formatted
  92.   fileToList()
  93.   sort(aList)
  94.   set lastOne to "A"
  95.   repeat with i in aList
  96.     if not (char 1 of i = lastOne) then
  97.       set lastOne to char 1 of i
  98.       next repeat
  99.     end if
  100.     put i after field ("ingredients-" & lastOne)
  101.   end repeat
  102. end
  103.  
  104. on fracToFloatPars
  105.   global aList, formatted
  106.   set formatted to []
  107.   set lineNum to 0
  108.   repeat with aLine in aList
  109.     set lineNum to lineNum + 1
  110.     set first to offset("@", aLine) + 1
  111.     set second to offset("@", char first to length(aLine) of aLine) + first - 2
  112.     set quantity to char first to second of aLine
  113.     set word1 to word 1 of quantity
  114.     if word1 contains "-" then
  115.       set dash to offset("-", word1)
  116.       set quan1 to char 1 to dash - 1 of word1
  117.       set quan2 to char dash + 1 to length(word1) of word1
  118.       put ".0" after quan1
  119.       put ".0" after quan2
  120.       set floatQuantity to value(quan1) + value(quan2)
  121.     else
  122.       put ".0" after word1
  123.       set floatQuantity to value(word1)
  124.     end if
  125.     add(formatted, lineNum & "@" & floatQuantity & RETURN)
  126.   end repeat
  127.   listToFile(formatted)
  128. end
  129.  
  130. on singleify
  131.   global aList, formatted
  132.   set i to 0
  133.   set iNum to count(aList)
  134.   set lastNumber to 0
  135.   set checkNumber to 1
  136.   set formatted to []
  137.   repeat while i <= iNum
  138.     set i to i + 1
  139.     set aLine to getAt(aList, i)
  140.     if aLine = EMPTY then
  141.       exit
  142.     end if
  143.     set number to char 1 to offset("@", aLine) - 1 of aLine
  144.     if (number <> lastNumber) and (number = checkNumber) then
  145.       add(formatted, aLine)
  146.       set checkNumber to checkNumber + 1
  147.       set lastNumber to number
  148.       next repeat
  149.     end if
  150.     if number <> lastNumber then
  151.       add(formatted, checkNumber & "@" & RETURN)
  152.       set checkNumber to checkNumber + 1
  153.       set i to i - 1
  154.     end if
  155.   end repeat
  156.   listToFile(formatted)
  157. end
  158.  
  159. on numberFile
  160.   set aList to fileToList()
  161.   set lineNum to 0
  162.   set numbered to EMPTY
  163.   repeat with anItem in aList
  164.     set lineNum to lineNum + 1
  165.     put lineNum & "@" & anItem after numbered
  166.   end repeat
  167.   writeFile(numbered)
  168. end
  169.  
  170. on changeIngredients
  171.   global newIngredients
  172.   set ingredients to fileToList()
  173.   set newIngredients to EMPTY
  174.   repeat with aLine in ingredients
  175.     if aLine contains "(" then
  176.       set part1 to char 1 to offset("(", aLine) - 2 of aLine
  177.       set part2 to char offset(")", aLine) + 1 to length(aLine) of aLine
  178.       put part1 & part2 after newIngredients
  179.       next repeat
  180.     end if
  181.     put aLine after newIngredients
  182.   end repeat
  183.   writeFile(newIngredients)
  184. end
  185.  
  186. on lineToline
  187.   global newText, list1, list2
  188.   set list1 to fileToList()
  189.   set list2 to fileToList()
  190.   set newText to EMPTY
  191.   set lineCount to count(list1)
  192.   set lineNum to 0
  193.   repeat with i = 1 to lineCount
  194.     set standard to line 1 of getAt(list1, i)
  195.     set id to line 1 of getAt(list2, i)
  196.     put id & "@" & standard & RETURN after newText
  197.   end repeat
  198.   writeFile(newText)
  199. end
  200.  
  201. on checkMeta aWord
  202.   global newText, list1
  203.   set newText to EMPTY
  204.   repeat with i in list1
  205.     set at to offset("@", i)
  206.     set id to char 1 to at - 1 of i
  207.     set match to id & "@" & aWord & RETURN
  208.     if (match <> i) and (i contains aWord) then
  209.       put match after newText
  210.     end if
  211.   end repeat
  212.   put newText after field "foo"
  213.   beep()
  214. end
  215.  
  216. on checkMetaList aList
  217.   global newText, list1
  218.   set newText to EMPTY
  219.   repeat with i in list1
  220.     set at to offset("@", i)
  221.     set id to char 1 to at - 1 of i
  222.     set food to char at + 1 to length(i) of i
  223.     repeat with aWord in aList
  224.       if food = (aWord & RETURN) then
  225.         set match1 to id & "@" & "shellfish" & RETURN
  226.         put match1 after newText
  227.       end if
  228.     end repeat
  229.   end repeat
  230.   put newText after field "foo"
  231.   beep()
  232. end
  233.  
  234. on replaceStandard
  235.   global newText, list1, gStandardIDDB, standards
  236.   set list1 to fileToList()
  237.   set standards to value(field "standardIDDB")
  238.   set newText to EMPTY
  239.   repeat with i in list1
  240.     set at to offset("@", i)
  241.     set recipe to char 1 to at of i
  242.     set standard to char at + 1 to length(i) - 1 of i
  243.     set id to getaProp(gStandardIDDB, standard)
  244.     if id > 0 then
  245.       put recipe & id & RETURN after newText
  246.     else
  247.       put standard, id
  248.     end if
  249.     setaProp(standards, standard, "gone")
  250.   end repeat
  251.   writeFile(newText)
  252. end
  253.  
  254. on standardsNotUsed
  255.   global standards, newText
  256.   set num to count(standards)
  257.   set newText to EMPTY
  258.   repeat with i = 1 to num
  259.     set id to getAt(standards, i)
  260.     set ingredient to getOne(standards, id)
  261.     if id <> "gone" then
  262.       put id && ingredient & RETURN after newText
  263.     end if
  264.   end repeat
  265.   writeFile(newText)
  266. end
  267.  
  268. on removeStandards
  269.   global list1, list2, newText
  270.   set list1 to fileToList()
  271.   set list2 to fileToList()
  272.   repeat with i in list1
  273.     set id to integer(word 1 of i)
  274.     if id > 0 then
  275.       setAt(list2, id, "removed")
  276.     end if
  277.   end repeat
  278.   writeFile(listToString(list2))
  279. end
  280.  
  281. on standardToCollate
  282.   global newText, list1, gStandardIDDB, standards
  283.   set list1 to fileToList()
  284.   set categories to value(field "categoryIDDB")
  285.   set newText to EMPTY
  286.   repeat with i in list1
  287.     set at to offset("@", i)
  288.     set recipe to char 1 to at of i
  289.     set standard to char at + 1 to length(i) - 1 of i
  290.     set standardID to getaProp(gStandardIDDB, standard)
  291.     set category to getaProp(categories, standardID)
  292.     put recipe & category & RETURN after newText
  293.   end repeat
  294.   writeFile(newText)
  295. end
  296.