mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
File Removed.
This commit is contained in:
parent
fab83a93ba
commit
a1191e197b
Binary file not shown.
@ -1,207 +0,0 @@
|
||||
(*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released March
|
||||
* 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1999
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*)
|
||||
|
||||
--// PUBLIC //--
|
||||
|
||||
property noErr : 0
|
||||
property unknownErr : -100
|
||||
property createErr : -101
|
||||
property rdErr : -102
|
||||
property replaceErr : -103
|
||||
property wrErr : -104
|
||||
|
||||
property kEmptyStream : ""
|
||||
property kDebug : false
|
||||
property kVersionToken : "$Version$"
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
-- genJSFile
|
||||
--
|
||||
-- Generates a JS file from a supplied template after replacing all
|
||||
-- predefined tokens with input parameters.
|
||||
--
|
||||
-- @param aSrcJSTFile the source JavaScript template file
|
||||
-- @param aDstJSFolder the destination folder into which to generate the install.js
|
||||
-- [NOTE: no ':' at path end]
|
||||
-- @param aVersion the version string with which to replace the $Version$ string
|
||||
-- @return err the error code as prescribed above
|
||||
------------------------------------------------------------------------------------------
|
||||
on genJSFile(aSrcJSTFile, aDstJSFolder, aVersion)
|
||||
|
||||
set err to unknownErr
|
||||
set dstJSFile to aDstJSFolder & ":install.js"
|
||||
|
||||
-- read in source file
|
||||
set inStream to readFileAsStream(aSrcJSTFile)
|
||||
if inStream = kEmptyStream then
|
||||
return rdErr
|
||||
end if
|
||||
|
||||
-- perform substiution in text stream
|
||||
set outStream to substitute(aVersion, inStream)
|
||||
if outStream = kEmptyStream then
|
||||
return replaceErr
|
||||
end if
|
||||
|
||||
-- write altered text stream to dest file
|
||||
set err to writeStreamToFile(dstJSFile, outStream)
|
||||
|
||||
-- return error val
|
||||
return err
|
||||
end genJSFile
|
||||
|
||||
|
||||
--// PRIVATE //--
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- createNewFile
|
||||
---------------------------------------------------------------------
|
||||
on createNewFile(aFile)
|
||||
|
||||
tell application "Finder"
|
||||
-- delete old dest file
|
||||
if file aFile exists then
|
||||
delete file aFile
|
||||
end if
|
||||
|
||||
-- create a new file
|
||||
return open for access file aFile with write permission
|
||||
end tell
|
||||
end createNewFile
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- readFileAsStream
|
||||
---------------------------------------------------------------------
|
||||
on readFileAsStream(aFile)
|
||||
|
||||
set inStream to kEmptyStream
|
||||
|
||||
tell application "Finder"
|
||||
if file aFile exists then
|
||||
set refnum to open for access file aFile without write permission
|
||||
else
|
||||
return inStream -- return empty stream if we couldn't read
|
||||
end if
|
||||
end tell
|
||||
|
||||
ASSERT(refnum > 0)
|
||||
set inStream to read refnum as text
|
||||
close access refnum
|
||||
|
||||
-- assert stream isn't empty
|
||||
ASSERT(kEmptyStream < (count inStream each character))
|
||||
|
||||
return inStream
|
||||
end readFileAsStream
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- substitute
|
||||
---------------------------------------------------------------------
|
||||
on substitute(aVersion, aInStream)
|
||||
|
||||
set outStream to kEmptyStream
|
||||
set currIndex to 1
|
||||
set currChar to ""
|
||||
set skipCount to 0
|
||||
set firstOffset to offset of kVersionToken in aInStream
|
||||
|
||||
repeat with currChar in (every text item of aInStream)
|
||||
if skipCount > 0 then
|
||||
set skipCount to skipCount - 1
|
||||
else
|
||||
|
||||
if currIndex = firstOffset then
|
||||
set outStream to outStream & aVersion
|
||||
set skipCount to strlen(kVersionToken) - 1
|
||||
else
|
||||
set outStream to outStream & currChar
|
||||
end if
|
||||
end if
|
||||
set currIndex to currIndex + 1
|
||||
end repeat
|
||||
|
||||
return outStream
|
||||
end substitute
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- writeStreamToFile
|
||||
---------------------------------------------------------------------
|
||||
on writeStreamToFile(aFile, aOutStream)
|
||||
|
||||
ASSERT(aOutStream kEmptyStream)
|
||||
set err to noErr
|
||||
|
||||
set refnum to createNewFile(aFile)
|
||||
ASSERT(refnum > 0)
|
||||
|
||||
write aOutStream to refnum
|
||||
|
||||
close access refnum
|
||||
return err
|
||||
end writeStreamToFile
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- strlen
|
||||
---------------------------------------------------------------------
|
||||
on strlen(aString)
|
||||
|
||||
return count aString each character
|
||||
end strlen
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- DEBUG
|
||||
---------------------------------------------------------------------
|
||||
on DEBUG(aMsg)
|
||||
|
||||
if kDebug then
|
||||
display dialog "GenJSLib DEBUG: " & aMsg
|
||||
end if
|
||||
end DEBUG
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- ASSERT
|
||||
---------------------------------------------------------------------
|
||||
on ASSERT(aCondition)
|
||||
|
||||
if kDebug then
|
||||
if not aCondition then
|
||||
DEBUG("Assertion failed!")
|
||||
quit -- come to a grinding halt
|
||||
end if
|
||||
end if
|
||||
end ASSERT
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- in place test harness for debugging
|
||||
---------------------------------------------------------------------
|
||||
on run
|
||||
|
||||
if kDebug then
|
||||
set zFolder to "HD:genJS"
|
||||
set src to zFolder & ":install.jst"
|
||||
set dst to zFolder
|
||||
set ver to "5.0.0.99288"
|
||||
|
||||
set err to genJSFile(src, dst, ver)
|
||||
display dialog "[TEST] genJSFile returned: " & err
|
||||
end if
|
||||
end run
|
Binary file not shown.
@ -1,44 +0,0 @@
|
||||
(*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released March
|
||||
* 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1999
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*)
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- GenJSLib TEST HARNESS
|
||||
--------------------------------------------------------------------
|
||||
|
||||
set zFolder to "HD:genJS"
|
||||
set src to zFolder & ":install.jst"
|
||||
set dst to zFolder
|
||||
set ver to "5.0.0.99288"
|
||||
|
||||
-- load lib
|
||||
tell application "Finder"
|
||||
load script file "GenJSLib" of folder "genJS" of startup disk
|
||||
set zGenJSLib to result
|
||||
end tell
|
||||
|
||||
-- call API
|
||||
tell zGenJSLib
|
||||
set err to genJSFile(src, dst, ver)
|
||||
display dialog "[TEST] genJSFile returned: " & err
|
||||
end tell
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user