home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 7.1 KB | 298 lines | [TEXT/ToyS] |
- -- Preferences
- property kasVersion : "V1.53"
- property kasPrefix : "<!-- (c) 1998 AKUA interactive media AG - GLK OPO %v %d %n -->" -- Set to empty string to prevent prefixing
- property kasPrefName : "Unix Textify"
- property kasPrefixExt : {".html", ".htm"} -- Only prefix these files
-
- property kasWebStarSSI : "<!--#include virtual="
- property kasNetScapeSSI : "<!--#include file="
- property kasWebStarToNetScapeSSI : true -- Change the above two lines
-
- property kasLowerCaseNames : true
-
- property kasTypesToDo : {"TEXT"} -- Only run on these types
- property kasExtToDo : "" -- Use non-empty match string (e.g. "*.html") to limit to that extension
-
- property quote : "•"
- property cr : (ASCII character 13)
- property lf : (ASCII character 10)
- property crlf : cr & lf
-
- -- Globals
- global gasInfoWind -- Info window
- global gasInfoPos -- Position of info window
- global gasFoldersToDo -- The folders left to process
- global gasConverted -- Number gone!
- global gasChecked -- Number checked!
- global gasPrefix -- Adjusted kasPrefix (munge the % parms)
- global gasIndex -- Incremented # starting at 1
-
-
- on open fsObjs
- -- Load prefs, show window
- pfLoad()
-
- -- Set up prefix
- set gasPrefix to munge kasPrefix ¬
- searching for ¬
- "%d" replacing it with (the clock in extended sortable form)
-
- set gasPrefix to munge gasPrefix ¬
- searching for ¬
- "%v" replacing it with kasVersion
-
- set gasPrefix to munge gasPrefix ¬
- searching for ¬
- "%n" replacing it with (gasIndex as string)
-
- set gasConverted to 0
- set gasChecked to 0
-
- set gasInfoWind to display info titled kasPrefName ¬
- located at gasInfoPos ¬
- message "Scanning…"
-
- -- Do files
- set gasFoldersToDo to {}
-
- repeat with fsObj in fsObjs
- set myInfo to (basic info for fsObj)
-
- if (system type of myInfo is "fold") then
- set gasFoldersToDo to gasFoldersToDo & {fsObj}
- else if (system type of myInfo is in kasTypesToDo) then
- if (kasExtToDo is "") or ((collect lines of (catalog name of myInfo) that match kasExtToDo) is not "") then
- DoOne(fsObj)
- end if
- end if
- end repeat
-
- -- Do folders
- repeat while gasFoldersToDo is not {}
- -- Pop one off the end
- set n to the number of items of gasFoldersToDo
- set fsObj to item n of gasFoldersToDo
-
- if (n > 1) then
- set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
- else
- set gasFoldersToDo to {}
- end if
-
- display info gasInfoWind ¬
- message ("Folders to go: " & n) ¬
- at line 6 ¬
- using color (15 * 32)
-
- -- Process it
- GoDeep(fsObj)
- end repeat
-
- display info gasInfoWind message "DONE!"
-
- pause for 5 with seconds timing -- Let screen wait...
-
- set gasInfoPos to screen location of ¬
- (display info gasInfoWind with disposal)
-
- pfSave() -- Save window location
- end open
-
-
- on DoOne(fsObj)
- set aFileInfo to (alias info from fsObj)
-
- display info gasInfoWind ¬
- message "File: " & (original name of aFileInfo) ¬
- at line 2
-
- set gasChecked to gasChecked + 1
-
- display info gasInfoWind ¬
- message ("Checked: " & gasChecked) ¬
- at line 7 ¬
- using color 15
-
- ConvertFile(fsObj)
- end DoOne
-
-
- on ConvertFile(fsObj)
- try
- set fileRef to ¬
- open fork from fsObj ¬
- with write access
- on error errStr
- display info gasInfoWind ¬
- message ("Error: " & errStr) ¬
- at line 12 ¬
- using color (25 * 1024)
- return
- end try
-
- set fname to catalog name of (basic info for fsObj)
-
- set fileData to read data from fileRef
- set newData to fileData
-
- -- Convert DOS to Unix
- set newData to munge newData ¬
- searching for crlf ¬
- replacing it with lf
-
- -- Convert Mac to Unix
- set newData to munge newData ¬
- searching for cr ¬
- replacing it with lf
-
- -- Convert SSI?
- if (kasWebStarToNetScapeSSI) then ¬
- set newData to munge newData ¬
- searching for kasWebStarSSI ¬
- replacing it with kasNetScapeSSI
-
- -- Rename to lowercase?
- set changed to false
- if (kasLowerCaseNames) then
- set flow to transcribe fname with «class ñLow»
- considering case
- if flow is not fname then
- collate fsObj renaming it to flow
- set changed to (kasPrefix is not "") -- Prefix if this is a change
- end if
- end considering
- end if
-
- if changed or (newData is not fileData) then
- -- Check prefix
- if (kasPrefix is not "") then
- -- Does this file get prefixes?
- set doThis to (kasPrefixExt is {})
-
- repeat with suffix in kasPrefixExt
- display info gasInfoWind ¬
- message (the text from character -(length of suffix) to -1 of fname) ¬
- at line 15
-
- display info gasInfoWind ¬
- message suffix ¬
- at line 18
-
- set fext to (the text from character -(length of suffix) to -1 of fname)
- set os to offset of fext in suffix
-
- -- A check of equality fails here - I don't know why the hell?!?
- -- if (fext is suffix) then
- if ((offset of fext in suffix) is 1) then set doThis to true
- end repeat
-
- if (doThis) then
- display info gasInfoWind ¬
- message ("Prefix?") ¬
- at line 16
-
- -- Lop off current prefix
- if (the text from character 1 to 8 of kasPrefix) is (the text from character 1 to 8 of newData) then
- set n to offset of cr in newData
- if (n is 0) then set n to offset of lf in newData
- if n is not 0 then
- set newData to gasPrefix & (the text from character n to -1 of newData)
- display info gasInfoWind ¬
- message ("Updated prefix") ¬
- at line 17
- end if
- else
- set newData to gasPrefix & lf & newData
-
- display info gasInfoWind ¬
- message ("Adding prefix") ¬
- at line 17
- end if
- else
- display info gasInfoWind ¬
- message ("No Prefix") ¬
- at line 16
- end if
- end if
-
- -- Reset file to 0 long
- size fork fileRef ¬
- given «class len »:0
-
- -- Write data
- write data to fileRef ¬
- from buffer newData
-
- set gasConverted to gasConverted + 1
-
- display info gasInfoWind ¬
- message ("Converted: " & gasConverted) ¬
- at line 8 ¬
- using color (15 * 1024)
- display info gasInfoWind ¬
- message ("Last: " & fname) ¬
- at line 9 ¬
- using color (16 * 1024)
- end if
-
- close fork fileRef
- end ConvertFile
-
-
-
- on GoDeep(foldObj)
- display info gasInfoWind ¬
- message "Path: " & (foldObj as string)
-
- set daddy to foldObj as string
-
- -- Do kinds that match
- display info gasInfoWind ¬
- message "Scanning files" at line 5
-
- if (kasExtToDo is "") then
- set myItems to the entries in foldObj ¬
- whose types are in kasTypesToDo
- else
- set myItems to the entries in foldObj ¬
- whose types are in kasTypesToDo ¬
- whose names match kasExtToDo
- end if
-
- repeat with myItem in myItems
- DoOne((daddy & myItem) as alias)
- end repeat
-
- -- Do folders
- display info gasInfoWind ¬
- message "Scanning subfolders" at line 5
-
- set myItems to the entries in foldObj ¬
- whose kinds are a folder
-
- repeat with myItem in myItems
- set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
- end repeat
-
- -- Done
- display info gasInfoWind ¬
- message "…" at line 5
- end GoDeep
-
-
- on pfLoad()
- try
- set ourPrefs to (load preference named kasPrefName)
- set gasInfoPos to item 1 of ourPrefs
- set gasIndex to item 2 of ourPrefs
- on error
- set gasInfoPos to {-1, -1}
- set gasIndex to 1
- end try
- end pfLoad
-
-
- on pfSave()
- save preference {gasInfoPos, gasIndex + 1} named kasPrefName
- end pfSave
-