home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/pvcs.pev 1.50 26 Sep 1990 17:09:28 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: pvcs.pel $: PVCS support
-
-
- ### global variables
-
- global PVCS_DISABLED = 0x00
- global PVCS_ENABLE_GETS = 0x01
- global PVCS_ENABLE_EMPTY_GETS = 0x02
-
- ### local variables
-
- global pvcsEnabled
- local pvcsPutEnabled
- local pvcsEmptyEnabled
- local pvcsPutId
- local pvcsGetId
- local pvcsGetEmptyId
- local pvcsBuffersGot
- local pvcsRevision = ""
-
-
- ## pvcs() and
- ## toggle_pvcs()
- #
- # Enable PVCS get and put. The "on" argument can be set to one of
- # four values depending on the desired configuration:
- #
- # PVCS_DISABLED = 0 - disable PVCS
- # PVCS_ENABLE_GETS = 1 - enable get and put via existing file edits
- # PVCS_ENABLE_EMPTY_GETS = 2 - enable get and put via non-existant
- # file reads
- # PVCS_ENABLE_GETS +
- # PVCS_ENABLE_EMPTY_GETS = 3 - enable get and put via existing and
- # non-existant files
- #
- global function pvcs( on ){
- if (argcount())
- toggle_pvcs( on )
- else
- toggle_pvcs()
- }
-
- global function toggle_pvcs( on ){
-
- if ( !argcount()) {
- on = !pvcsEnabled
- message( "PVCS " (on ? "Enabled." : "Disabled." ))
- } else {
- on = 0+on
- }
-
- #
- # enable puts for all files
- #
- if (on && !pvcsPutEnabled) {
- pvcsPutEnabled = 1
- attach_event_handler( EVENT_EDIT_FILE_SAVE, \
- pvcsPutId = function_id( "pvcs_put_buffer" ))
- } else if (!on && pvcsPutEnabled) {
- pvcsPutEnabled = 0
- delete_event( EVENT_EDIT_FILE_SAVE, pvcsPutId )
- }
-
- #
- # enable gets for existing files
- #
- if (and( on, PVCS_ENABLE_GETS ) && !pvcsEnabled) {
- pvcsEnabled = 1
- attach_event_handler( EVENT_FIRST_MOD, \
- pvcsGetId = function_id( "pvcs_get_existing_buffer" ))
- } else if (!and( on, PVCS_ENABLE_GETS ) && pvcsEnabled) {
- pvcsEnabled = 0
- delete_event( EVENT_FIRST_MOD, pvcsGetId )
- }
-
- #
- # enable gets for non-existing files
- #
- if (and( on, PVCS_ENABLE_EMPTY_GETS ) && !pvcsEmptyEnabled) {
- pvcsEmptyEnabled = 1
- attach_event_handler( EVENT_NEW_EDIT_FILE, \
- pvcsGetEmptyId = function_id( "pvcs_get_empty" ))
- } else if (!and( on, PVCS_ENABLE_EMPTY_GETS ) && (pvcsEmptyEnabled)) {
- pvcsEmptyEnabled = 0
- delete_event( EVENT_NEW_EDIT_FILE, pvcsGetEmptyId )
- }
- }
-
-
- ###
- ### put up a menu of PVCS system commands
- ###
-
- global function pvcs_menu(){
- local priorPvcsEnabled
- local cmd
- local options = ""
- local str = " Get\n Put\n Ident\n Regen\n VCS\n Vcompress\n Vdel\n Vdiff\n VJournal\n Vlog\n Vlogin\n Vmrg\n Vname"
-
- cmd = list_vertical( str, 10, display_height - 22, 15, 18 )
- cmd = tolower( ltrim( cmd ))
-
- if (cmd != "") {
-
- # default actions for selected commands
- if (cmd == "get") {
- pvcs_get_existing_buffer( 1 )
- return
- } else if (cmd == "put") {
- pvcs_put_buffer( 1 )
- return
- } else if (cmd == "vdiff") {
- options = "-r " buffer_filename
- }
-
- str = prompt_history( "PVCS" toupper( cmd ), \
- "PVCS Command:" cmd " ", \
- options )
-
- if ( str != "" ) {
-
- # write the buffer; prevent conflicts with
- # pvcs "put" events
- priorPvcsEnabled = pvcsEnabled
- pvcsEnabled = 0
- write_buffer_key()
- pvcsEnabled = priorPvcsEnabled
-
- push_dir( path_path( buffer_filename ))
-
- if ( cmd == "vdiff" || \
- cmd == "vjournal" || \
- cmd == "vlog" ) {
- dos_buffer( cmd " " str )
- } else {
- system_window_command( cmd " " str )
- }
-
- pop_dir()
-
- return
- }
- }
- }
-
-
- ###
- ### event handlers for PVCS
- ###
-
- ### event handler invoked when attempting to edit a non-exisiting file
-
- global function pvcs_get_empty(){
- if ( pvcsEnabled && filemode( buffer_filename ) < 0) {
- # file doesn't exist
- pvcs_get_existing_buffer( 1 )
- }
- }
-
-
- ### event handler invoked when attempting to edit a read-only buffer
-
- ## pvcs_get_existing_buffer()
- #
- # forceget instructs not to delete the buffer and reload, just perform
- # the PVCS command.
- #
- global function pvcs_get_existing_buffer( forceget ){
- local fmode = filemode( buffer_filename )
- local cmd
-
- # check the file's read-only status
-
- if ( (pvcsEnabled && ((fmode > 0) && and( fmode, _READ_ONLY ))) \
- || forceget ) {
-
- cmd = factory_prompt( \
- "Read-only buffer : enter a PVCS \"get\" command (<Esc> to cancel)",
- "PVCSGET",
- "cmd: ",
- "get -L " pvcsRevision buffer_filename )
-
- if ( cmd ) {
- # perform the GET command
- pvcsSystemCommand( cmd, forceget )
-
- # add this buffer to the list if we have it locked
- if ( !and( buffer_flags, BUFFER_READ_ONLY )) {
- pvcsBuffersGot[ current_buffer ] = \
- (cmd ~ /<-[Ll]/)
- }
- }
- }
- }
-
-
- ### event handler invoked when attempting to write a buffer
-
- global function pvcs_put_buffer( forceput ){
- local priorPvcsEnabled
- local cmd
-
- # see if the current buffer originated from a PVCS get
-
- if ( (pvcsEnabled && \
- current_buffer in pvcsBuffersGot && \
- pvcsBuffersGot[current_buffer] ) \
- || forceput ) {
-
- cmd = factory_prompt( \
- "Enter a PVCS \"put\" command (<Esc> to cancel)",
- "PVCSPUT",
- "cmd: ",
- "put " pvcsRevision buffer_filename )
-
- if ( cmd ) {
-
- # write the current buffer to disk if necessary,
- priorPvcsEnabled = pvcsEnabled
- pvcsEnabled = 0 # prevent recursion
- write_buffer_key()
- pvcsEnabled = priorPvcsEnabled
-
- # perform the put command
- pvcsSystemCommand( cmd )
- }
- }
- }
-
-
- ## support functions for pvcs commands
-
- local bufferSavedState
-
- local function pvcsSystemCommand( cmd, forceget ) {
-
- # save the current state of the current buffer
- saveBufferState()
-
- # change to the directory where the file is
- push_dir( path_path( buffer_filename ))
-
- # do the shell-in-a-box command
- system_window_command( cmd )
-
- # restore the prior working directory
- pop_dir()
-
- # re-edit the file and restore the state of the
- # buffer to what it was, depending on the file's
- # new read-write/read-only status, etc.
- if (!forceget)
- rereadNewBuffer()
-
- # if a wildcard GET or PUT was performed, check all buffers
- # for conflicts
- if ( cmd ~ /[*?][^ \t]*$/ ) {
- checkAllFilemodes();
- }
- }
-
- local function checkAllFilemodes(){
- #
- # PVCS GET and PUT commands can result in changes to the filemodes
- # of one or more files. This function synchronizes the read-write/
- # read-only status of all buffers currently in the editor with their
- # corresponding disk files.
- #
- local priorBuffer = current_buffer
- local sentinel = next_buffer()
- local fmode
-
- do {
- fmode = filemode( buffer_filename )
- if ( fmode >= 0 ) {
- if ( !and( fmode, _READ_ONLY ) != \
- !and( buffer_flags, BUFFER_READ_ONLY ) ) {
- # read only status differs:
- saveBufferState()
- bufferSavedState[ "filetime" ] = 0
- rereadNewBuffer()
- }
- }
- } while( next_buffer() != sentinel )
-
- current_buffer = priorBuffer
- }
-
- local function saveBufferState(){
- #
- # save salient info about the current buffer in an array
- #
- bufferSavedState[ "filename" ] = buffer_filename
- bufferSavedState[ "filetime" ] = filetime( buffer_filename )
- bufferSavedState[ "name" ] = buffer_name
- bufferSavedState[ "flags" ] = buffer_flags
- bufferSavedState[ "line" ] = current_line
- bufferSavedState[ "column" ] = current_column
- bufferSavedState[ "keymap" ] = buffer_keymap
- bufferSavedState[ "tabs" ] = buffer_tabs
- }
-
- local function rereadNewBuffer(){
- local fmode
-
- #
- # re-read a buffer which has possibly been changed by a system
- # command, using the attributes saved by function saveBufferState()
- #
- if ( bufferSavedState ) {
-
- # has the disk file changed?
- if ( bufferSavedState[ "filetime" ] \
- != filetime( buffer_filename )) {
-
- # delete the current buffer without asking
- #
- buffer_flags = and( buffer_flags, \
- not( BUFFER_MODIFIED ))
- delete_buffer()
-
- # create a new buffer with the same attributes
- # as before
- #
- current_buffer = create_buffer( \
- bufferSavedState[ "name" ], \
- bufferSavedState[ "filename" ], \
- bufferSavedState[ "flags" ] )
-
- current_line = bufferSavedState[ "line" ]
- current_column = bufferSavedState[ "column" ]
- buffer_keymap = bufferSavedState[ "keymap" ]
- buffer_tabs = bufferSavedState[ "tabs" ]
-
- center_cursor()
- }
-
- delete bufferSavedState
- }
-
- # update the read-only bit of the buffer to match the disk file
- #
- fmode = filemode( buffer_filename )
- if ( fmode >= 0 ) {
- set_buffer_flag( \
- BUFFER_READ_ONLY, \
- and( fmode, _READ_ONLY ) )
- }
-
- return fmode
- }
-