home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-05 | 8.6 KB | 259 lines | [TEXT/ttxt] |
- # RestoreFiles - use a Remember-generated backup file and compare it to the current version
- #
- # Usage:
- # RestoreFiles [-9 | -13 | -19 | -b x y | -Portrait | -TwoPage]
- # -9 use 9 inch screen (512 x 342)
- # -13 use 13 inch screen (640 x 480)
- # -19 use 19 inch screen (1024 x 768)
- # -Portrait use 15 inch screen (640 x 870)
- # -TwoPage use 21 inch screen (1152 x 870)
- # -b x y use screen dimensions given in x y
- # default is -13
- # NOTE:
- # Order of parameters is important
- # No error checking is done on x y coordinates
- #
- # Returns:
- # Status = 0 - files match
- # Status = 1 - syntax error
- # Status = 2 - files differ (this is the same status as the compare tool)
- #
- # RestoreFiles is a modified version of CompareFiles,
- # which compares two files, and if they don't match it will
- # bring them both up on the screen and put them side by side. A menu will be
- # appended to the menu bar to go through the changes. When all the changes
- # have been shown, the file windows will be restored and closed.
- #
- # The differences are shown from bottom to top so that if any changes are made
- # in the files, the line offsets are not messed up.
- #
- # The script creates two temporary files which are deleted on exit.
- #
- # Understanding the code…
- #
- # RestoreFiles is actually a few scripts rolled into one. The action
- # depends on the parameters. Here is what happens:
- #
- # RestoreFiles
- # Gets the files to be compared, and generates the difference script
- # If there are differences, it will
- # create a script to execute on quit
- # move the windows around next to each other
- # create the Restore Menu
- # call itself with -n
- # RestoreFiles -n - show next change
- # RestoreFiles -New - cut change from new to scrap
- # RestoreFiles -old - paste change from new into old
- # RestoreFiles -q - execute Quit script
- #
- # Portions copyright Apple Computer, Inc. 1988 - 1990
- # All rights reserved.
-
- Set ScriptName "{0}" # save the script's name
- Set Exit 0
- Set ErrorMessage "### {0} - Incorrect order, or missing or illegal option."
- Set Usage "# Usage - {0} [-9 | -13 | -19 | -b x y | -Portrait | -TwoPage]."
-
- If "{1}" == "-n" # find next change
- Find ¡1 "{ShellDirectory}"Restore_File # get past current Line
- Find \###\ "{ShellDirectory}"Restore_File
- If {Status} != 0 # end of change log
- Beep
- Confirm "No more changes. Are you done comparing these Files?"
- If {Status} == 0
- DeleteMenu Restore
- Close -n "{ShellDirectory}Restore_File" ≥ Dev:Null
- "{ShellDirectory}Restore_State" ≥ Dev:Null
- Delete "{ShellDirectory}Restore_File" ≥ Dev:Null
- Delete "{ShellDirectory}Restore_State" ≥ Dev:Null
- Set RememberActive 1 # re-enable Remember
- End # If {Status}
- Else
- Find !1 "{ShellDirectory}"Restore_File # select entire Line
- Mark -y § Current_Line "{ShellDirectory}"Restore_File
- Execute "{ShellDirectory}Restore_File.§"
- End # If {Status}
- Else If "{1}" == "-q" # Quit
- DeleteMenu Restore
- Close -n "{ShellDirectory}Restore_File" ≥ Dev:Null
- "{ShellDirectory}Restore_State" ≥ Dev:Null
- Delete "{ShellDirectory}Restore_File" ≥ Dev:Null
- Delete "{ShellDirectory}Restore_State" ≥ Dev:Null
- Set RememberActive 1 # re-enable Remember
- Else If "{1}" == "-New" # cut selection from new to scrap
- Find Current_Line "{ShellDirectory}"Restore_File ∑ Dev:Null # re-sync the two files
- Set MyStatus {Status}
- If {MyStatus} != 0
- Exit {MyStatus}
- End # If {MyStatus}
- Execute "{ShellDirectory}Compare_File.§" ∑ Dev:Null
- Set selChars `Position -C "{Target}" ≥ Dev:Null` # see if we need to copy/paste or just cut
- (Evaluate {selChars} =~ /([0-9]+)®1,([0-9]+)®2/ ) ∑ Dev:Null
- If {®1} == {®2}
- Cut § "{Active}" ∑ Dev:Null
- Else
- Copy § "{Target}" ∑ Dev:Null
- Mark -y § Compare_Mark "{Active}"
- Paste § "{Active}" ∑ Dev:Null
- Find Compare_Mark "{Active}" ∑ Dev:Null
- Unmark Compare_Mark "{Active}" ∑ Dev:Null
- End # If {®1}
- Else If "{1}" == "-old" # copy selection from old to new
- Find Current_Line "{ShellDirectory}"Restore_File ∑ Dev:Null # re-sync the two files
- Set MyStatus {Status}
- If {MyStatus} != 0
- Exit {MyStatus}
- End # If {MyStatus}
- Execute "{ShellDirectory}Restore_File.§" ∑ Dev:Null
- Set selChars `Position -C "{Active}" ≥ Dev:Null` # see if we need to copy/paste or just cut
- (Evaluate {selChars} =~ /([0-9]++)®1,([0-9]++)®2/ ) ∑ Dev:Null
- If {®1} == {®2}
- Cut § "{Target}" ∑ Dev:Null
- Else
- Copy § "{Active}" ∑ Dev:Null
- Mark -y § Restore_Mark "{Target}" ∑ Dev:Null
- Paste § "{Target}" ∑ Dev:Null
- Find Restore_Mark "{Target}" ∑ Dev:Null
- Unmark Restore_Mark "{Target}" ∑ Dev:Null
- End # If {®1}
- Else # restore the files and set up menu
- If "{1}" == "-b" || "{1}" == "-B" # user specified size
- If {#} != 5
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Evaluate Right = {2} - 5
- Evaluate Bottom = {3} - 140
- Set TileRectangle "0,5,{Bottom},{Right}"
- Evaluate Bottom = {Bottom} + 1
- Evaluate Right = {Right} - 9
- Shift 3
- Else If "{1}" == "-9" # MAC+ and MacSE screen
- If {#} != 1
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 234, 510"
- Set Bottom 235
- Set Right 500
- Shift 1
- Else If "{1}" == "-13" # MacII screen
- If {#} != 1
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 344, 635"
- Set Bottom 345
- Set Right 626
- Shift 1
- Else If "{1}" == "-19" # 19" screen (1024 x 768)
- If {#} != 1
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 647, 952"
- Set Bottom 648
- Set Right 945
- Shift 1
- Else If "{1}" =~ /-Portrait/ # Apple Macintosh Portrait Display
- If {#} != 1
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 749, 635"
- Set Bottom 750
- Set Right 626
- Shift 1
- Else If "{1}" =~ /-TwoPage/ # Apple Two-Page Monochrome Monitor
- If {#} != 1
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 749, 1148"
- Set Bottom 750
- Set Right 1138
- Shift 1
- Else # MacII screen (default)
- If {#} != 2
- Alert "{ErrorMessage}∂n∂n{Usage}"
- Exit 1
- End # If {#}
- Set TileRectangle "0, 5, 344, 635"
- Set Bottom 345
- Set Right 626
- End # If {1}
-
- # Make a list of the relevant remembered backup files
- Set OldDir "`Directory`"
- Directory "{Backup}"
- Set LeafName "`ParseFileName -l "{Active}"`" # Get the current file's leafname
- Set FileList "`Begin; Files "{LeafName}".[0-9]+; End ≥ Dev:Null`"
- Directory "{OldDir}"
-
- If ("{FileList}" != "")
- Set RemName "`GetListItem -m "Select remembered file:" -q -s {FileList}`"
- If ("{RemName}" != "")
- Set 1 "`Files -f -q "{Active}" ≥ Dev:Null`" # this is the current file
- Set 2 "`Files -f -q "{Backup}{RemName}" ≥ Dev:Null`" # this is the remembered Backup file name
- OpenStatus "{1}"
- Set openFile1 {Status}
- OpenStatus "{2}"
- Set openFile2 {Status}
- Compare -m "{1}" "{2}" > "{ShellDirectory}"Restore_File ≥ Dev:Null # do the comparison
-
- If {openFile1} == 0
- Open "{1}" ∑ Dev:Null
- End # If {openFile1}
- If {openFile2} == 0
- Open -r "{2}" ∑ Dev:Null
- End # If {openFile2}
- Begin # create end script
- MoveWindow "{1}" # get the current window states
- SizeWindow "{1}"
- MoveWindow "{2}"
- SizeWindow "{2}"
- If {openFile1} == 0
- Echo Close ∂""{1}"∂"
- End # If {openFile1}
- If {openFile2} == 0
- Echo Close ∂""{2}"∂"
- End # If {openFile2}
- End > "{ShellDirectory}"Restore_State
-
- Open "{ShellDirectory}"Restore_File
- Find ∞ "{ShellDirectory}"Restore_File
- TileWindows -v -r "{TileRectangle}" "{1}" "{2}"
- MoveWindow 7 {Bottom} "{ShellDirectory}"Restore_File
- SizeWindow {Right} 75 "{ShellDirectory}"Restore_File
- AddMenu Restore 'Find Next Change' 'Execute Begin; RestoreFiles "-n" ∑ Dev:Null; End'
- AddMenu Restore '(-' ''
- AddMenu Restore 'Copy Selection »»' 'Execute Begin; RestoreFiles "-New" ∑ Dev:Null; End'
- AddMenu Restore '«« Copy Selection' 'Execute Begin; RestoreFiles "-old" ∑ Dev:Null; End'
- AddMenu Restore '(-' ''
- AddMenu Restore 'Done' 'Execute Begin; RestoreFiles "-q" ∑ Dev:Null; End'
- Set RememberActive 0 # disable Remember
- Execute Begin; RestoreFiles "-n" ∑ Dev:Null; End
- End # If {RemName}
- Else
- Alert "{ScriptName}:∂nNo remembered files found for {Active}."
- End # If {FileList}
- End # If {1}
-
- Unset ErrorMessage
- Unset Usage
- Unset LeafName
- Unset FileList
- Unset OldDir
- Unset openFile1
- Unset openFile2
- Unset 1
- Unset 2
- Unset RemName
- Unset FileList
- Unset selChars
- Unset MyStatus
- Unset TileRectangle
- Unset Bottom
- Unset Right
-
- # end of RestoreFiles