1998-12-14 02:27:52 +03:00
|
|
|
|
(*
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
|
1998-12-24 22:32:21 +03:00
|
|
|
|
on openProject(aProjectFile)
|
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
|
|
|
|
open aProjectFile
|
|
|
|
|
end tell
|
|
|
|
|
end openProject
|
|
|
|
|
|
|
|
|
|
on selectProject(aProjectFile)
|
|
|
|
|
set projectName to fileFromPath(aProjectFile as text)
|
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
|
|
|
|
if (name of window 1 is not projectName) then
|
|
|
|
|
select window projectName
|
|
|
|
|
end if
|
|
|
|
|
end tell
|
|
|
|
|
end selectProject
|
|
|
|
|
|
1998-12-14 02:27:52 +03:00
|
|
|
|
on getTargets()
|
|
|
|
|
set targetList to {}
|
|
|
|
|
set nameList to {}
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
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
|
|
|
|
|
|
1998-12-24 22:32:21 +03:00
|
|
|
|
(* uses "sort" scripting addition to sort a list of strings. *)
|
|
|
|
|
on sortList(aList)
|
|
|
|
|
if (aList <20> {}) then
|
|
|
|
|
return sort aList
|
|
|
|
|
else
|
|
|
|
|
return {}
|
|
|
|
|
end if
|
|
|
|
|
end sortList
|
|
|
|
|
|
|
|
|
|
(* uses "info for" scripting addition, to return the file type of a path. *)
|
|
|
|
|
on getFileType(aFilePath)
|
|
|
|
|
return file type of (info for alias aFilePath)
|
|
|
|
|
end getFileType
|
|
|
|
|
|
|
|
|
|
(* returns all "TEXT" files of the named target. *)
|
1998-12-14 02:27:52 +03:00
|
|
|
|
on getTargetFiles(targetKey)
|
|
|
|
|
set targetFiles to {}
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
set currentProject to project document 1
|
|
|
|
|
set currentTarget to (target targetKey of currentProject)
|
1998-12-24 22:32:21 +03:00
|
|
|
|
try
|
|
|
|
|
-- workaround for CW IDE 3.X bug, loop until error encountered.
|
|
|
|
|
set fileIndex to 1
|
|
|
|
|
repeat until false
|
|
|
|
|
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 (linked of targetFile) then
|
|
|
|
|
set targetFilePath to (Access Paths of targetFile)
|
|
|
|
|
tell me
|
|
|
|
|
if (getFileType(targetFilePath) = "TEXT") then
|
|
|
|
|
set targetFiles to targetFiles & {targetFilePath}
|
|
|
|
|
end if
|
|
|
|
|
end tell
|
|
|
|
|
end if
|
|
|
|
|
set fileIndex to (fileIndex + 1)
|
|
|
|
|
end repeat
|
|
|
|
|
on error msg
|
|
|
|
|
-- display dialog msg & " file count = " & fileIndex
|
|
|
|
|
end try
|
1998-12-14 02:27:52 +03:00
|
|
|
|
end tell
|
1998-12-24 22:32:21 +03:00
|
|
|
|
return sortList(targetFiles)
|
1998-12-14 02:27:52 +03:00
|
|
|
|
end getTargetFiles
|
|
|
|
|
|
|
|
|
|
on addTargetFile(targetFile, targetName)
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
add (project document 1) new target file with data {targetFile} to targets {targetName}
|
|
|
|
|
end tell
|
|
|
|
|
end addTargetFile
|
|
|
|
|
|
|
|
|
|
on setCurrentTarget(currentTargetName)
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
Set Current Target currentTargetName
|
|
|
|
|
end tell
|
|
|
|
|
end setCurrentTarget
|
|
|
|
|
|
|
|
|
|
on removeTargetFile(targetFile)
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
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")
|
|
|
|
|
|
1998-12-24 22:32:21 +03:00
|
|
|
|
openProject(theProjectFile)
|
|
|
|
|
selectProject(theProjectFile)
|
|
|
|
|
|
1998-12-14 02:27:52 +03:00
|
|
|
|
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.
|
1998-12-24 22:32:21 +03:00
|
|
|
|
tell application "CodeWarrior IDE 3.3"
|
1998-12-14 02:27:52 +03:00
|
|
|
|
activate
|
|
|
|
|
Close Project
|
|
|
|
|
open theManifestFile
|
|
|
|
|
end tell
|
|
|
|
|
|
|
|
|
|
setDelimiters(oldDelimiters)
|
|
|
|
|
end run
|