home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 July / macformat-039.iso / DATABASE / SHARED.DIR / 01019.ls < prev    next >
Encoding:
Text File  |  1996-03-14  |  3.6 KB  |  118 lines

  1. on BatchIndex
  2.   global mpath, gWorld, gMakerNum
  3.   set the itemDelimiter to "."
  4.   set gWorld to item 1 of the movieName
  5.   set the itemDelimiter to ","
  6.   set mpath to the pathName & gWorld & ":"
  7.   set fileList to []
  8.   repeat with i = 1 to the maxinteger
  9.     set n to getNthFileNameInFolder(mpath, i)
  10.     if n = EMPTY then
  11.       exit repeat
  12.     end if
  13.     set num to the number of chars in n
  14.     if char num - 3 to num of n = ".txt" then
  15.       append(fileList, n)
  16.     end if
  17.   end repeat
  18.   put "filelist = " && fileList
  19.   set num to count(fileList)
  20.   repeat with i = 1 to num
  21.     set tmpname to getAt(fileList, i)
  22.     put "batch indexing " && tmpname
  23.     set the itemDelimiter to "."
  24.     set tmpname to item 1 of tmpname
  25.     set the itemDelimiter to ","
  26.     set gMakerNum to NameToNum(tmpname)
  27.     set err to MakeIndex(getAt(fileList, i))
  28.     if err = -1 then
  29.       set tmpnum to the number of lines in field "BatchErrors" + 1
  30.       put "Index Error: " && getAt(fileList, i) into line tmpnum of field "BatchErrors"
  31.     end if
  32.   end repeat
  33. end
  34.  
  35. on MakeIndex fname
  36.   global index, MainIndex, mpath, gMakerNum, gMakerName, gName, gWorld
  37.   put "indexing: " && fname
  38.   set the itemDelimiter to "."
  39.   set gWorld to item 1 of the movieName
  40.   set the itemDelimiter to ","
  41.   set gName to line gMakerNum of field "makernumlist"
  42.   set thenam to fname
  43.   if the paramCount = 1 then
  44.     set myObj to FileIO(mnew, "read", mpath & fname)
  45.   else
  46.     set myObj to FileIO(mnew, "?read", "TEXT")
  47.   end if
  48.   if not objectp(myObj) then
  49.     alert("problem opening " && fname)
  50.     abort()
  51.   else
  52.     set fname to myObj(mFileName)
  53.     set the itemDelimiter to ":"
  54.     set fname to item the number of items in fname of fname
  55.     set the itemDelimiter to "."
  56.     set fname to item 1 of fname
  57.     set the itemDelimiter to ","
  58.     put "Getting indexes for: " & fname
  59.     set tmpfile to myObj(mReadFile)
  60.     set tmpfilecopy to tmpfile
  61.     set the itemDelimiter to "@"
  62.     set inum to the number of items in tmpfile
  63.     set the itemDelimiter to ","
  64.     set offset to 0
  65.     set a to 0
  66.     set index to EMPTY
  67.     set first to 1
  68.     repeat with i = 1 to inum
  69.       set the itemDelimiter to "@"
  70.       set tmp to item i of tmpfile
  71.       set the itemDelimiter to ","
  72.       if (i = inum) and (the number of chars in tmp < 3) then
  73.         exit repeat
  74.       end if
  75.       if first then
  76.         set tmpart to line 1 of tmp
  77.         set first to 0
  78.       else
  79.         set tmpart to line 2 of tmp
  80.       end if
  81.       if the number of chars in tmpart > 4 then
  82.         put "error. article number is wrong."
  83.         return -1
  84.       else
  85.         set art to word 1 of tmpart
  86.       end if
  87.       set a to offset + a
  88.       if index = EMPTY then
  89.         put art & ":" & a into item 1 of index
  90.       else
  91.         put art & ":" & a into item the number of items in index + 1 of index
  92.       end if
  93.       set offset to the number of chars in tmp + 1
  94.     end repeat
  95.     myObj(mdispose)
  96.     set num to the number of lines in field ("CuttingIndex" & gWorld)
  97.     set fname to gName
  98.     put fname & ":" & index
  99.     set i to Bsearch(fname, "CuttingIndex" & gWorld)
  100.     if i then
  101.       delete line i of field ("CuttingIndex" & gWorld)
  102.     end if
  103.     set index to fname & "," & index
  104.     if line 1 of field ("CuttingIndex" & gWorld) = EMPTY then
  105.       put index into line 1 of field ("CuttingIndex" & gWorld)
  106.     else
  107.       put index into line the number of lines in field ("CuttingIndex" & gWorld) + 1 of field ("CuttingIndex" & gWorld)
  108.     end if
  109.     sortlines("CuttingIndex" & gWorld)
  110.     set fname to "CU" & gMakerNum & ".TXT"
  111.     set myObj to FileIO(mnew, "write", mpath & fname)
  112.     put "writing: " && fname
  113.     myObj(mWriteString, tmpfilecopy)
  114.     myObj(mdispose)
  115.     return 0
  116.   end if
  117. end
  118.