gecko-dev/build/mac/GenToc.script
beard%netscape.com c3173abbd8 First Checked In.
1998-12-13 23:27:52 +00:00

219 lines
6.2 KiB
Plaintext

(*
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*)
(*
GenToc - Generates a .toc file from the current contents of a project.
by Patrick C. Beard <beard@netscape.com>
*)
on swapDelimiters(newDelimiters)
set oldDelimiters to get AppleScript's text item delimiters
set AppleScript's text item delimiters to newDelimiters
return oldDelimiters
end swapDelimiters
on setDelimiters(newDelimiters)
set AppleScript's text item delimiters to newDelimiters
end setDelimiters
on setExtension(fileName, newExtension)
set oldDelimiters to swapDelimiters(".")
set newFileName to (text item 1 of fileName) & newExtension
setDelimiters(oldDelimiters)
return newFileName
end setExtension
on folderFromPath(filePath)
set folderPath to ((filePath's text items 1 thru ((count of filePath's text items) - 1)) as string) & ":"
return folderPath
end folderFromPath
on fileFromPath(filePath)
return last text item of filePath
end fileFromPath
on getTargets()
set targetList to {}
set nameList to {}
tell application "CodeWarrior IDE 3.2"
set currentProject to project document 1
repeat with targetIndex from 1 to (count of targets of currentProject)
set currentTarget to (target targetIndex of currentProject)
set targetList to targetList & {currentTarget}
set nameList to nameList & {name of currentTarget}
end repeat
return {target:targetList, names:nameList}
end tell
end getTargets
on getTargetFiles(targetKey)
set targetFiles to {}
tell application "CodeWarrior IDE 3.2"
set currentProject to project document 1
set currentTarget to (target targetKey of currentProject)
repeat with fileIndex from 1 to (count of target files of currentTarget)
set targetFile to (target file fileIndex of currentTarget)
-- only consider text files, since other platforms won't be managing binaries.
-- also, only consider if target file is directly linked.
if (type of targetFile is text file) and (linked of targetFile) then
set targetFiles to targetFiles & {Access Paths of targetFile}
end if
end repeat
return sort targetFiles
end tell
end getTargetFiles
on addTargetFile(targetFile, targetName)
tell application "CodeWarrior IDE 3.2"
add (project document 1) new target file with data {targetFile} to targets {targetName}
end tell
end addTargetFile
on setCurrentTarget(currentTargetName)
tell application "CodeWarrior IDE 3.2"
Set Current Target currentTargetName
end tell
end setCurrentTarget
on removeTargetFile(targetFile)
tell application "CodeWarrior IDE 3.2"
Remove Files {targetFile}
end tell
end removeTargetFile
on quote(aString)
return "'" & aString & "'"
end quote
on listContains(aList, anItem)
repeat with listItem in aList
if (listItem contains anItem) then
return true
end if
end repeat
return false
end listContains
on showList(listToShow)
choose from list listToShow with prompt "List:" with empty selection allowed
end showList
on replace(aString, oldChar, newChar)
set newString to ""
repeat with aChar in (every character of aString)
if (contents of aChar = oldChar) then
set newString to newString & newChar
else
set newString to newString & aChar
end if
end repeat
return newString
end replace
on substring(aString, anOffset)
set aSubString to ""
repeat with charIndex from anOffset to (count aString)
set aSubString to aSubString & (character charIndex of aString)
end repeat
return aSubString
end substring
on setFileInfo(aFile, aCreator, aType)
tell application "Finder"
set creator type of aFile to aCreator
set file type of aFile to aType
end tell
end setFileInfo
on closeFile(fileRef)
try
-- make sure it's not currently open.
close access fileRef
on error
-- ignore error closing.
end try
end closeFile
on mroFile(aFile)
try
-- make sure it's modifiable.
mro aFile
on error
-- ignore error MROing.
end try
end mroFile
on run
-- so we can easily strip off file names from paths.
set oldDelimiters to swapDelimiters(":")
set theProjectFile to (choose file with prompt "Choose a CW Project file." of type {"MMPr"})
set theManifestFile to (new file with prompt "Create MANIFEST where?" default name setExtension(fileFromPath(theProjectFile as text), ".toc"))
set manifestRef to false
try
-- make sure the file is closed & is modifiable.
closeFile(theManifestFile)
mroFile(theManifestFile)
-- open the new MANIFEST file.
set manifestRef to (open for access theManifestFile with write permission)
set eof manifestRef to 0
-- give it CodeWarrior look and feel.
setFileInfo(theManifestFile, "CWIE", "TEXT")
tell application "CodeWarrior IDE 3.2"
open theProjectFile
end tell
set targetsList to getTargets()
set targetNames to names of targetsList
set targetCount to count items of targetNames
set mozillaTreePathOffset to (offset of "mozilla" in (theManifestFile as text))
-- dump all targets into the new MANIFEST file.
repeat with targetName in targetNames
write ("# target: " & targetName & return) to manifestRef
setCurrentTarget(targetName)
set targetFiles to getTargetFiles(contents of targetName)
repeat with targetFile in targetFiles
-- only store the path name relative to the source tree itself.
set targetFilePath to substring(contents of targetFile, mozillaTreePathOffset)
write (replace(targetFilePath, ":", "/") & return) to manifestRef
end repeat
end repeat
on error msg
display dialog msg
end try
if (manifestRef is not false) then
closeFile(manifestRef)
end if
-- shut the project down, and display the result.
tell application "CodeWarrior IDE 3.2"
activate
Close Project
open theManifestFile
end tell
setDelimiters(oldDelimiters)
end run