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

  1. on BatchReadCaptions world
  2.   global gMakerNum, gWorld
  3.   set gWorld to world
  4.   set mpath to the pathName & world & ":"
  5.   set fileList to []
  6.   repeat with i = 1 to the maxinteger
  7.     set n to getNthFileNameInFolder(mpath, i)
  8.     if n = EMPTY then
  9.       exit repeat
  10.     end if
  11.     set num to the number of chars in n
  12.     if char num - 3 to num of n = ".CAP" then
  13.       append(fileList, n)
  14.     end if
  15.   end repeat
  16.   set num to count(fileList)
  17.   set tmperrlist to []
  18.   repeat with i = 1 to num
  19.     set fname to getAt(fileList, i)
  20.     set the itemDelimiter to "."
  21.     set gMakerNum to item 1 of fname
  22.     set the itemDelimiter to ","
  23.     put "batch reading captions " && fname
  24.     set gMakerName to char 1 to the number of chars in fname - 4 of fname
  25.     set err to ReadCaptions(world & ":" & fname)
  26.     if err = -1 then
  27.       add(tmperrlist, fname)
  28.     end if
  29.   end repeat
  30. end
  31.  
  32. on ReadNewCaptions
  33.   global gMakerName, mpath, gWorld
  34.   puppetSound("click")
  35.   updateStage()
  36.   set fname to gWorld & ":" & NameToNum(gMakerName) & ".CAP"
  37.   set err to ReadCaptions(fname)
  38.   if err = -1 then
  39.     alert("problem loading caption for:" & fname)
  40.     go(2)
  41.   end if
  42.   go("database")
  43. end
  44.  
  45. on ReadCaptions fname
  46.   global myObj, gMakerNum
  47.   set mypath to the pathName & fname
  48.   set myObj to FileIO(mnew, "read", mypath)
  49.   if not objectp(myObj) then
  50.     alert("couldnt open " && mypath)
  51.     return -1
  52.   end if
  53.   put "gmakernum  = " & gMakerNum
  54.   set scast to the number of cast (gMakerNum & ".cap")
  55.   set the text of field scast to myObj(mReadFile)
  56.   set the name of cast scast to gMakerNum & ".cap"
  57.   put "done " && fname
  58.   myObj(mdispose)
  59.   return 0
  60. end
  61.  
  62. on saveNewParse
  63.   global gChapters, gArticles, gCaptions, gTitles, gDates, gName, gMakerName, gnuggets, mpath, gMakerNum
  64.   set tmptxt to EMPTY
  65.   put "set gChapters = " && gChapters into line 1 of tmptxt
  66.   put "set gArticles = " && gArticles into line 2 of tmptxt
  67.   put "set gDates = " && gDates into line 3 of tmptxt
  68.   set tmplist to []
  69.   add(tmplist, gName)
  70.   put "set gName = getat(" & tmplist & ",1)" into line 4 of tmptxt
  71.   put gTitles into line 5 of tmptxt
  72.   put gnuggets into line 6 of tmptxt
  73.   put "saving: " && gMakerNum && gName
  74.   if gMakerNum = 0 then
  75.     alert("Error finding number of " && gName)
  76.     abort()
  77.   else
  78.     set mypath to mpath & gMakerNum & ".CAP"
  79.     set myObj to FileIO(mnew, "write", mypath)
  80.     if not objectp(myObj) then
  81.       alert("problem writing to " && mypath)
  82.       abort()
  83.     end if
  84.     set i to the number of cast gMakerNum && "script"
  85.     if i > 0 then
  86.       set captiontxt to EMPTY
  87.       set the text of field i to tmptxt
  88.       set the itemDelimiter to "@"
  89.       set numchap to the number of items in gCaptions
  90.       set the itemDelimiter to ","
  91.       repeat with j = 1 to numchap
  92.         set the itemDelimiter to "@"
  93.         set tmpcap to item j of gCaptions
  94.         set the itemDelimiter to "#"
  95.         set numart to the number of items in tmpcap
  96.         set the itemDelimiter to ","
  97.         repeat with k = 1 to numart
  98.           set the itemDelimiter to "#"
  99.           set it to item k of tmpcap
  100.           set the itemDelimiter to ","
  101.           if k = numart then
  102.             put it & RETURN & "@" & RETURN after captiontxt
  103.           else
  104.             put it & RETURN & "#" & RETURN after captiontxt
  105.           end if
  106.           set the itemDelimiter to ","
  107.         end repeat
  108.       end repeat
  109.       if 0 then
  110.         put captiontxt into field (i + 1)
  111.         set the name of cast (i + 1) to gMakerName
  112.       end if
  113.       myObj(mWriteString, captiontxt)
  114.     end if
  115.   end if
  116.   set tmptxt to EMPTY
  117.   set txt to EMPTY
  118.   myObj(mdispose)
  119. end
  120.  
  121. on cleancast s, e
  122.   repeat with i = s to e
  123.     set the name of cast i to "a"
  124.     set the text of field i to EMPTY
  125.   end repeat
  126. end
  127.  
  128. on ReadScript
  129.   global gChapters, gArticles, gCaptions, gTitles, gDates, gName, gMakerName, gnuggets, gTotalChapters, tmpfile, mpath, gMakerNum
  130.   set forcd to 0
  131.   set fname to gMakerNum && "script"
  132.   set cnum to the number of cast fname
  133.   if not (cnum > 0) then
  134.     alert("Problem loading" && fname && ". This means this persons script file must be re-indexed")
  135.     unpuppet()
  136.     if forcd = 1 then
  137.       ReturnToWorld()
  138.     else
  139.       go(2)
  140.       abort()
  141.     end if
  142.   else
  143.     set tmptxt to the text of field cnum
  144.     set tmpfile to tmptxt
  145.     repeat with i = 1 to 4
  146.       do(line i of tmptxt)
  147.     end repeat
  148.     set gTitles to line 5 of tmptxt
  149.     set gCaptions to the text of cast (gMakerNum & ".CAP")
  150.     set gnuggets to line 6 of tmptxt
  151.     set gTotalChapters to count(gArticles)
  152.   end if
  153. end
  154.  
  155. on PrepareCasts next
  156.   global tmplist
  157.   set tmplist to []
  158.   set flist to "Filenames"
  159.   set num to the number of lines in field flist
  160.   repeat with i = 1 to num
  161.     set tmp to line i of field flist
  162.     if notEmpty(tmp) then
  163.       set mnum to NameToNum(tmp)
  164.       add(tmplist, mnum)
  165.     end if
  166.   end repeat
  167.   set flist to "Filenames2"
  168.   set num to the number of lines in field flist
  169.   repeat with i = 1 to num
  170.     set tmp to line i of field flist
  171.     if notEmpty(tmp) then
  172.       set mnum to NameToNum(tmp)
  173.       add(tmplist, mnum)
  174.     end if
  175.   end repeat
  176.   put tmplist
  177.   set num to count(tmplist)
  178.   repeat with i = 1 to num
  179.     set the name of cast next to getAt(tmplist, i) && "script"
  180.     set next to next + 1
  181.   end repeat
  182.   repeat with i = 1 to num
  183.     set the name of cast next to getAt(tmplist, i) & ".CAP"
  184.     set next to next + 1
  185.   end repeat
  186. end
  187.