home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / sccs / text0000.txt < prev   
Encoding:
Text File  |  1990-07-22  |  29.7 KB  |  1,271 lines

  1. Here's the latest version. Also I wrote up some info nodes for it so
  2. you can put it in the documentation tree -- I suggest under `Major Modes'.
  3. I haven't tested this info file as I don't really understand how to integrate
  4. it into the existing tree.
  5.  
  6. Here's the info file:
  7.  
  8. -------------------------------------CUT HERE----------------------------------
  9. This file documents the SCCS front-end features.  -*-Text-*-
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. File: sccs    Node: Top    Up: (DIR)    Next: SCCS Operations
  71.  
  72.    If your environment supports SCCS (the Source Code Control System) Emacs
  73. includes facilities for version control of files direct from the editor. You
  74. can load the SCCS support facilities by invoking `M-x sccs'; thereafter,
  75. keystroke bindings are available.
  76.  
  77.    This library assumes that you are one of a group maintaining a project which
  78. has a single `current version', but for which you need to maintain a
  79. modification history so that you can reconcile diffs made by each other against
  80. old versions.
  81.  
  82.    The major function assists you in checking in a file to SCCS and registering
  83. successive sets of changes to it as SCCS deltas. Other entry points allow you
  84. to retrieve change histories, examine differences between versions, and examine
  85. the overall SCCS status of the project (which files are registered to SCCS,
  86. which are currently locked, etc).
  87.  
  88.    A function is provided to generate diff sets that express all differences
  89. between a given delta pair. This can be used to automatically generate
  90. patch sets corresponding to releases. A function for marking out major
  91. releases is also provided.
  92.  
  93.    It is not necessary to pre-register the project files into SCCS to use
  94. these facilities; this will be done automatically when you first invoke the
  95. major entry point on each file. Thus you only pay minimum disk space overhead
  96. for using SCCS.
  97.  
  98.    Finally, note that this major mode adds entries to the global C-c keymap
  99. when first loaded. Given that the sccs code has to coexist with things like
  100. c-mode that define their own keymaps, this is at least better than hogging
  101. each buffer's local one.
  102.  
  103. * Menu::
  104.  
  105. * SCCS Operations::     Describes the major `smart' entry points.
  106. * Difference Reports::  How to compare saved deltas and look at file histories.
  107. * Status Functions::    Functions for examining SCCS project directories.
  108. * Release Generation::  Functions for generating releases from delta sets.
  109. * Variables::           Ways to customize SCCS's behavior through Emacs.
  110.  
  111. This library was designed and implemented by Eric Raymond (eric@snark.uu.net).
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. File: sccs    Node: SCCS Operations    Up: Top        Next: Difference Reports
  174.  
  175.    The main function that assists with this is SCCS use is `sccs', which tries
  176. to do the next logical SCCS operation on the file associated with the current
  177. buffer.
  178.  
  179. `C-c n, M-x sccs'
  180.    Perform the next logical operation on the SCCS file corresponding to
  181.    the current buffer, either an admin(1) or get(1) or delta(1).
  182.  
  183.    If the file is not already registered with SCCS, this does an admin -i
  184. followed by a get -e. This checks the file in to SCCS and gets an editable
  185. copy. The base version will be 1.1 unless you have done a previous
  186. sccs-delta-release in this directory, in which case the saved version number
  187. will be used.
  188.  
  189.    Note that you must have an SCCS subdirectory in the same directory
  190. as the file being operated on for the check-in to work. 
  191.  
  192.    If the file is registered and not locked by anyone, sccs does a get -e. This
  193. gets an editable copy.
  194.  
  195.    If the file is registered and locked by the calling user, sccs pops up a
  196. buffer for creation of a log message, then does a delta -n on the file. The
  197. presumption is that you're done with a set of changes and want to register
  198. them as a delta. A read-only copy of the changed file is left in place
  199. afterwards.
  200.  
  201.    If the file is registered and locked by someone else, an error message is
  202. returned indicating who has locked it.
  203.  
  204.    When entering the log entry for a delta, you may use `sccs-insert-last-log'
  205. to insert the last change log message you composed. You do this with:
  206.  
  207. `C-c i, C-c C-i, M-x insert-last-log'
  208.    Insert a copy of the last change message you composed. Useful when entering
  209.    a change log message.
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. File: sccs    Node: Difference Reports    Up: Top        Next: Status Functions
  272.  
  273.    Sometimes it is useful to compare the current version of a file with
  274. previous versions, or get reports on changes that have been made to a file
  275. or group of files. Functions are provided to do this.
  276.  
  277. `C-c d, M-x sccs-diff'
  278.    Compare the current version in the buffer with the last checked in
  279.    revision (delta) of the file, or, if given a prefix argument, with a
  280.    previous delta.
  281.  
  282. The comparison will be the output of a diff(1) using the flags specified in
  283. the variable sccs-diff-default-flags. *Note Cross: SCCS Variables:: You may
  284. add flags by specifying string arguments to sccs-diff.
  285.  
  286. `C-c v, M-x sccs-version-diff'
  287.    Compare two past deltas of the current file. You will be prompted for
  288.    the SIDs of the versions to compare.
  289.  
  290. Comparisons will be done with diff(1) as above.
  291.  
  292. `C-c p, M-x sccs-prs'
  293.    Run a prs(1) on the SCCS s.* file corresponding to the file in the current
  294.    buffer. This yields a history of changes to the file.
  295.  
  296. The results of all of these go to a compilation buffer name *SCCS* which is
  297. popped to.
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. File: sccs    Node: Status Functions        Up: Top        Next: Release Generation
  360.  
  361.    Some functions exist to allow you to check on which files of a project
  362. are SCCS-registered or locked. These functions assume that the files for your
  363. current project or subproject occupy the current directory and all its
  364. subdirectories.
  365.  
  366. `C-cC-p, M-x sccs-pending'
  367.    List all files at or below current directory that are currently locked
  368. for edit by any user.
  369.  
  370. `C-c r, M-x sccs-registered'
  371.    List all files at or below current directory that are SCCS-registered.
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433. File: sccs    Node: Release Generation    Up: Top        Next: Variables
  434.  
  435.    The following functions assist in defining releases and generating patch
  436. sets for them. They are not bound to keystrokes, as they will be used
  437. relatively infrequently.
  438.  
  439. `M-x sccs-delta-release'
  440.    Insert a dummy delta (to mark a major release) in all SCCS-registered files
  441.    at or below the current directory. The log message for all deltas is simply
  442.    `Release <sid>' where <sid> is an SID for which you will be prompted. This
  443.    SID is saved to be used in subsequent check-ins of new files.
  444.  
  445.    The SID of the new major release level is stored in ./SCCS/emacs-vars.el and
  446. used as the base SID for all subsequent new admins done from the current
  447. directory. It is good practice to register all current changes to their
  448. individual files with their own explanatory log messages before invoking
  449. sccs-delta-release, so that each real delta will carry real change info.
  450.  
  451. `M-x sccs-release-diff'
  452.    Generate a complete report on diffs between given versions for all
  453.    SCCS files at or below default-directory. You will be prompted for the
  454.    SIDs of versions to be compared. If the newer SID is omitted or nil, the
  455.    comparison is done against the most recent version saved.
  456.  
  457. This report is generated into a buffer in the format of a context diff set
  458. suitable for use with patch(1).
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520. File: sccs    Node: Variables            Up: Top
  521.  
  522.    You can customize the behavior of the Emacs interface by setting 
  523.  
  524. sccs-max-log-size
  525.   Maximum allowable size of an sccs log message.
  526.  
  527. sccs-default-diff-flags
  528.   Default the diff in sccsdiff to use the flags given in this list.
  529.  
  530. sccs-headers-wanted
  531.   A list of SCCS header keywords inserted into comments when the 
  532.   sccs-insert-header function is executed. Defaults to insert %W% only.
  533.  
  534. sccs-insert-static
  535.   If non-nil, use a static character string when inserting SCCS headers in
  536.   C mode. This permits what(1) to find SCCS version info in the compiled
  537.   object file.
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599. -------------------------------------CUT HERE----------------------------------
  600.  
  601. Here's the revised mode. Changes from the one you've seen already are:
  602.  
  603. 1) Global-keymap bindings for the entry points.
  604.  
  605. 2) The code now maintains a major-version variable associated with each 
  606.    directory where sccs.el is run; it is used as the base version when
  607.    checking in new files, and is incremented by sccs-delta-release.
  608.  
  609. -------------------------------------CUT HERE----------------------------------
  610. ;; sccs.el -- front-end code for using SCCS from GNU Emacs.
  611. ;;     by Eric S. Raymond (eric@snark.uu.net) v2.0 March 4 1990
  612.  
  613. ;; This file is part of GNU Emacs.
  614.  
  615. ;; GNU Emacs is distributed in the hope that it will be useful,
  616. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  617. ;; accepts responsibility to anyone for the consequences of using it
  618. ;; or for whether it serves any particular purpose or works at all,
  619. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  620. ;; License for full details.
  621.  
  622. ;; Everyone is granted permission to copy, modify and redistribute
  623. ;; GNU Emacs, but only under the conditions described in the
  624. ;; GNU Emacs General Public License.   A copy of this license is
  625. ;; supposed to have been given to you along with GNU Emacs so you
  626. ;; can know your rights and responsibilities.  It should be in a
  627. ;; file named COPYING.  Among other things, the copyright notice
  628. ;; and this notice must be preserved on all copies.
  629. ;;;
  630. ;;; You can blame this one on Eric S. Raymond (eric@snark.uu.net).
  631. ;;; It is loosely derived from an rcs mode written by Ed Simpson
  632. ;;; ({decvax, seismo}!mcnc!duke!dukecdu!evs) in years gone by
  633. ;;; and revised at MIT's Project Athena.
  634.  
  635. ;; User options
  636.  
  637. (defvar sccs-max-log-size 510
  638.   "*Maximum allowable size (chars) + 1 of an sccs log message.")
  639. (defvar sccs-default-diff-flags '("-c")
  640.   "*If non-nil, default the diff in sccsdiff to use these flags.")
  641. (defvar sccs-headers-wanted '("%W%")
  642.   "*SCCS header keywords inserted into comments when sccs-insert-header
  643. is executed")
  644. (defvar sccs-insert-static t
  645.   "*Insert a static character string when inserting SCCS headers in C mode.")
  646.  
  647. ;; Vars the user doesn't need to know about.
  648.  
  649. (defvar sccs-log-entry-mode nil)
  650. (defvar sccs-current-major-version nil)
  651.  
  652. ;; Some helper functions
  653.  
  654. (defun sccs-name (file &optional letter)
  655.   "Return the sccs-file name corresponding to a given file"
  656.   (format "%sSCCS/%s.%s"
  657.       (concat (file-name-directory file))
  658.       (or letter "s")
  659.       (concat (file-name-nondirectory file))))
  660.  
  661. (defun sccs-lock-info (file index)
  662.    "Return the nth token in a file's SCCS-lock information"
  663.    (let
  664.        ((pfile (sccs-name file "p")))
  665.      (and (file-exists-p pfile)
  666.       (save-excursion
  667.         (find-file pfile)
  668.         (auto-save-mode nil)
  669.         (replace-string " " "\n")
  670.         (goto-char (point-min))
  671.         (forward-line index)
  672.         (prog1
  673.         (buffer-substring (point) (progn (end-of-line) (point)))
  674.           (set-buffer-modified-p nil)
  675.           (kill-buffer (current-buffer)))
  676.         )
  677.       )
  678.      )
  679.    )
  680.  
  681. (defun sccs-locking-user (file)
  682.   "Return the name of the person currently holding a lock on FILE, nil if
  683. there is no such person."
  684.   (sccs-lock-info file 2)
  685.   )
  686.  
  687. (defun sccs-locked-revision (file)
  688.   "Return the revision number currently locked for FILE, nil if none such."
  689.   (sccs-lock-info file 1)
  690.   )
  691.  
  692. (defmacro error-occurred (&rest body)
  693.   (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
  694.  
  695. ;; There has *got* to be a better way to do this...
  696. (defmacro chmod (perms file)
  697.   (list 'call-process "chmod" nil nil nil perms file))
  698.  
  699. (defun sccs-save-vars (sid)
  700.   (save-excursion
  701.     (find-file "SCCS/emacs-vars.el")
  702.     (erase-buffer)
  703.     (insert "(setq sccs-current-major-version \"" sid "\")")
  704.     (basic-save-buffer)
  705.     )
  706.   )
  707.  
  708. (defun sccs-load-vars ()
  709.   (if (error-occurred (load-file "SCCS/emacs-vars.el"))
  710.       (setq sccs-current-major-version "1.1"))
  711. )
  712.  
  713. ;; The following functions do most of the real work
  714.  
  715. (defun sccs-get-version (file sid)
  716.    "For the given FILE, retrieve a copy of the version with given SID in
  717. a tempfile. Return the tempfile name, or nil if no such version exists."
  718.   (let (oldversion vbuf)
  719.     (setq oldversion (sccs-name file (or sid "new")))
  720.     (setq vbuf (create-file-buffer oldversion))
  721.     (prog1
  722.     (if (not (error-occurred
  723.          (sccs-do-command vbuf "get" file
  724.                   (and sid (concat "-r" sid))
  725.                   "-p" "-s")))
  726.         (save-excursion
  727.           (set-buffer vbuf)
  728.           (write-region (point-min) (point-max) oldversion t 0)
  729.           oldversion)
  730.       )
  731.       (kill-buffer vbuf)
  732.       )
  733.     )
  734.   )
  735.  
  736. (defun sccs-mode-line (file)
  737.   "Set the mode line for an sccs buffer. FILE is the file being visited to
  738. put in the modeline."
  739.   (setq mode-line-process
  740.     (if (file-exists-p (sccs-name file "p"))
  741.         (format " <SCCS: %s>" (sccs-locked-revision file))
  742.       ""))
  743.  
  744.     ; force update of screen
  745.     (save-excursion (set-buffer (other-buffer)))
  746.     (sit-for 0)
  747.     )
  748.  
  749. (defun sccs-do-command (buffer command file &rest flags)
  750. "  Execute an sccs command, notifying the user and checking for errors."
  751.   (message (format "Running %s on %s..." command file))
  752.   (save-window-excursion
  753.     (set-buffer (get-buffer-create buffer))
  754.     (erase-buffer)
  755.     (while (and flags (not (car flags)))
  756.       (setq flags (cdr flags)))
  757.     (let
  758.       ((default-directory (file-name-directory (or file "./"))))
  759.       (apply 'call-process command nil t nil
  760.          (append flags (and file (list (sccs-name file)))))
  761.     )
  762.     (goto-char (point-max))
  763.     (previous-line 1)
  764.     (if (looking-at "ERROR")
  765.       (error (format "Running %s on %s...failed" command file))
  766.       (message (format "Running %s on %s...done" command file))
  767.       )
  768.     )
  769.   (if file (sccs-mode-line file))
  770.   )
  771.  
  772. (defun sccs-tree-walk (func &rest optargs)
  773.   "Apply FUNC to each SCCS file under the default directory. If present,
  774. OPTARGS are also passed."
  775.   (shell-command (concat
  776.           "find " default-directory " -print | grep 'SCCS/s\\.'"))
  777.   (set-buffer "*Shell Command Output*")
  778.   (goto-char (point-min))
  779.   (replace-string "SCCS/s." "")
  780.   (goto-char (point-min))
  781.   (if (eobp)
  782.       (error "No SCCS files under %s" default-directory))
  783.   (while (not (eobp))
  784.     (let ((file (buffer-substring (point) (progn (end-of-line) (point)))))
  785.       (apply func file optargs)
  786.       )
  787.     (forward-line 1)
  788.     )
  789.   )
  790.  
  791. (defun sccs-init ()
  792.   (sccs-load-vars)
  793.   (define-key (current-global-map) "\C-c?" 'describe-mode)
  794.   (define-key (current-global-map) "\C-cn" 'sccs)
  795.   (define-key (current-global-map) "\C-ch" 'sccs-insert-headers)
  796.   (define-key (current-global-map) "\C-cd" 'sccs-diff)
  797.   (define-key (current-global-map) "\C-cp" 'sccs-prs)
  798.   (define-key (current-global-map) "\C-cC-p" 'sccs-pending)
  799.   (define-key (current-global-map) "\C-cr" 'sccs-registered)
  800.   )
  801.  
  802. ;; Here's the major entry point
  803.  
  804. (defun sccs (verbose)
  805.   "*Tries to do the next logical SCCS operation on the file associated with the
  806. current buffer. You must have an SCCS subdirectory in the same directory
  807. as the file being operated on.
  808.    If the file is not already registered with SCCS, this does an admin -i
  809. followed by a get -e.
  810.    If the file is registered and not locked by anyone, this does a get -e.
  811.    If the file is registered and locked by the calling user, this pops up a
  812. buffer for creation of a log message, then does a delta -n on the file.
  813. A read-only copy of the changed file is left in place afterwards.
  814.    If the file is registered and locked by someone else, an error message is
  815. returned indicating who has locked it."
  816.   (interactive "P")
  817.   (sccs-init)
  818.   (if (buffer-file-name)
  819.       (let
  820.       (do-update revision owner
  821.              (file (buffer-file-name))
  822.              (sccs-file (sccs-name (buffer-file-name)))
  823.              (sccs-log-buf (get-buffer-create "*SCCS-Log*"))
  824.              (err-msg nil))
  825.  
  826.     ;; if there is no SCCS file corresponding, create one
  827.     (if (not (file-exists-p sccs-file))
  828.           (sccs-admin file sccs-current-major-version))
  829.  
  830.     (cond
  831.  
  832.      ;; if there is no lock on the file, assert one and get it
  833.      ((not (file-exists-p (sccs-name file "p")))
  834.       (progn
  835.         (sccs-get file t)
  836.         (revert-buffer nil t)
  837.         (sccs-mode-line file)
  838.         ))
  839.  
  840.      ;; a checked-out version exists, but the user may not own the lock
  841.      ((not (string-equal
  842.         (setq owner (sccs-locking-user file)) (user-login-name)))
  843.       (error "Sorry, %s has that file checked out", owner))
  844.  
  845.      ;; OK, user owns the lock on the file 
  846.      (t (progn
  847.  
  848.           ;; if so, give luser a chance to save before delta-ing.
  849.           (if (and (buffer-modified-p)
  850.                (y-or-n-p (format "%s has been modified. Write it out? "
  851.                      (buffer-name))))
  852.           (save-buffer))
  853.  
  854.           (setq revision (sccs-locked-revision file))
  855.  
  856.           ;; user may want to set nonstandard parameters
  857.           (if verbose
  858.           (if (y-or-n-p 
  859.                (format "Rev: %s  Change revision level? " revision))
  860.               (setq revision (read-string "New revision level: "))))
  861.  
  862.           ;; OK, let's do the delta
  863.           (if
  864.           ;; this excursion returns t if the new version was saved OK
  865.           (save-window-excursion
  866.             (pop-to-buffer (get-buffer-create "*SCCS*"))
  867.             (erase-buffer)
  868.             (set-buffer-modified-p nil)
  869.             (sccs-mode)
  870.             (message 
  871.              "Enter log message. Type C-c C-c when done, C-c ? for help.")
  872.             (prog1
  873.             (and (not (error-occurred (recursive-edit)))
  874.                  (not (error-occurred (sccs-delta file revision))))
  875.               (setq buffer-file-name nil)
  876.               (bury-buffer "*SCCS*")))
  877.  
  878.           ;; if the save went OK do some post-checking
  879.           (if (buffer-modified-p)
  880.               (error
  881.                "Delta-ed version of file does not match buffer!")
  882.             (progn
  883.               ;; sccs-delta already turned off write-privileges on the
  884.               ;; file, let's not re-fetch it unless there's something
  885.               ;; in it that get would expand
  886.               (if (sccs-check-headers)
  887.               (sccs-get file nil))
  888.               (revert-buffer nil t)
  889.               (sccs-mode-line file)
  890.               )
  891.             ))))))
  892.     (error "There is no file associated with buffer %s" (buffer-name))))
  893.  
  894. (defun sccs-insert-last-log ()
  895.   "*Insert the log message of the last sccs check in at point."
  896.   (interactive)
  897.   (insert-buffer sccs-log-buf))
  898.  
  899. ;;; These functions help the sccs entry point
  900.  
  901. (defun sccs-admin (file sid)
  902.   "Checks a file into sccs. FILE is the unmodified name of the file. SID
  903. should be the base-level sid to check it in under."
  904.   (sccs-do-command "*SCCS*" "admin" file
  905.            (concat "-i" file) (concat "-r" sid))
  906.   (chmod "-w" file)
  907. )
  908.  
  909. (defun sccs-get (file writeable)
  910.   "Retrieve a locked copy of the latest delta of the given file."
  911.     (sccs-do-command "*SCCS*" "get" file (if writeable "-e")))
  912.  
  913. (defun sccs-delta (file &optional rev comment)
  914.    "Delta the file specified by FILE.  REV is a string specifying the
  915. new revision level (if nil increment the current level). The file is retained
  916. with write permissions zeroed. COMMENT is a comment string; if omitted, the
  917. contents of the current buffer up to point becomes the comment for this delta."
  918.   (if (not comment)
  919.       (progn
  920.     (goto-char (point-max))
  921.     (if (not (bolp)) (newline))
  922.     (newline)
  923.     (setq comment (buffer-substring (point-min) (1- (point)))))
  924.     )
  925.   (sccs-do-command "*SCCS*" "delta" file "-n"
  926.        (if rev (format "-r%s" rev))
  927.        (format "-y%s" comment))
  928.   (chmod "-w" file)
  929. )
  930.  
  931. (defun sccs-abort ()
  932.   "Abort an sccs command."
  933.   (interactive)
  934.   (if (y-or-n-p "Abort the delta? ") (error "Delta aborted")))
  935.  
  936. (defun sccs-exit ()
  937.   "Leave the recursive edit of an sccs log message."
  938.   (interactive)
  939.   (if (< (buffer-size) sccs-max-log-size)
  940.      (progn
  941.        (copy-to-buffer sccs-log-buf (point-min) (point-max))
  942.        (exit-recursive-edit))
  943.      (progn
  944.        (goto-char sccs-max-log-size)
  945.        (error
  946.         "Log must be less than %d characters. Point is now at char %d."
  947.         sccs-max-log-size sccs-max-log-size)))
  948. )
  949.  
  950. ;; Additional entry points for examining version histories
  951.  
  952. (defun sccs-diff (&optional revno &rest flags)
  953.   "*Compare the current version of the buffer with the last checked in
  954. revision of the file, or, if given a prefix argument, with another revision."
  955.   (interactive (if current-prefix-arg 
  956.            (list current-prefix-arg
  957.              (read-string "Revision to compare against: "))))
  958. (let (old file)
  959.   (if
  960.       (setq old (sccs-get-version (buffer-file-name) revno))
  961.       (progn
  962.     (if (and (buffer-modified-p)
  963.          (y-or-n-p (format "%s has been modified. Write it out? "
  964.                    (buffer-name))))
  965.         (save-buffer))
  966.  
  967.     (setq file (buffer-file-name))
  968.     (pop-to-buffer (get-buffer-create "*SCCS*"))
  969.     (erase-buffer)
  970.     (apply 'call-process "diff" nil t nil
  971.            (append sccs-default-diff-flags flags (list old) (list file)))
  972.     (set-buffer-modified-p nil)
  973.     (goto-char (point-min))
  974.     (delete-file old)
  975.     )
  976.     )
  977.   )
  978. )
  979.  
  980. (defun sccs-prs ()
  981.   "*List the SCCS log of the current buffer in an emacs window"
  982.   (interactive)
  983.   (sccs-do-command "*SCCS*" "prs" buffer-file-name)
  984.   (pop-to-buffer (get-buffer-create "*SCCS*")))
  985.  
  986. (defun sccs-version-diff (file rel1 rel2)
  987.   "*Given a FILE registered under SCCS, report diffs between two stored deltas
  988. REL1 and REL2 of it."
  989.   (interactive "sOlder version: \nsNewer version: ")
  990.   (if (string-equal rel1 "") (setq rel1 nil))
  991.   (if (string-equal rel2 "") (setq rel2 nil))
  992.   (pop-to-buffer (get-buffer-create "*SCCS*"))
  993.   (erase-buffer)
  994.   (sccs-vdiff file rel1 rel2)
  995.   (set-buffer-modified-p nil)
  996.   (goto-char (point-min))
  997.   )
  998.  
  999. (defun sccs-vdiff (file rel1 rel2 &optional flags)
  1000.   "Compare two deltas into the current buffer"
  1001.   (let (vers1 vers2)
  1002.     (and
  1003.      (setq vers1 (sccs-get-version file rel1))
  1004.      (setq vers2 (sccs-get-version file rel2))
  1005. ;     (prog1
  1006. ;     (save-excursion
  1007. ;       (not (error-occurred
  1008. ;         (call-process "prs" nil t t
  1009. ;                   (sccs-name file))))
  1010. ;     )
  1011. ;       )
  1012.      (unwind-protect
  1013.      (apply 'call-process "diff" nil t t
  1014.         (append sccs-default-diff-flags flags (list vers1) (list vers2)))
  1015.        (condition-case () (delete-file vers1) (error nil))
  1016.        (condition-case () (delete-file vers2) (error nil))
  1017.        )
  1018.      )
  1019.     )
  1020.   )
  1021.  
  1022. ;; SCCS header insertion code
  1023.  
  1024. (defun sccs-insert-headers ()
  1025.   "*Insert headers for use with the Source Code Control System
  1026. Headers desired are inserted at the start of the buffer, and are pulled from 
  1027. the variable sccs-headers-wanted"
  1028.   (interactive)
  1029.   (save-excursion
  1030.     (save-restriction
  1031.       (widen)
  1032.       (if (or (not (sccs-check-headers))
  1033.           (y-or-n-p "SCCS headers already exist.  Insert another set?"))
  1034.       (progn
  1035.          (goto-char (point-min))
  1036.          (run-hooks 'sccs-insert-headers-hook)
  1037.          (cond ((eq major-mode 'c-mode) (sccs-insert-c-header))
  1038.            ((eq major-mode 'lisp-mode) (sccs-insert-lisp-header))
  1039.            ((eq major-mode 'emacs-lisp-mode) (sccs-insert-lisp-header))
  1040.            ((eq major-mode 'scheme-mode) (sccs-insert-lisp-header))
  1041.            (t (sccs-insert-generic-header))))))))
  1042.  
  1043. (defun sccs-insert-c-header ()
  1044.   (let (st en)
  1045.     (insert "/*\n")
  1046.     (mapcar '(lambda (s)
  1047.            (insert " *\t" s "\n"))
  1048.         sccs-headers-wanted)
  1049.     (insert " */\n\n")
  1050.     (if (and sccs-insert-static 
  1051.          (not (string-match "\\.h$" (buffer-file-name))))
  1052.     (progn
  1053.       (insert "#ifndef lint\n"
  1054.           "static char *sccsid")
  1055. ;;      (setq st (point))
  1056. ;;      (insert (file-name-nondirectory (buffer-file-name)))
  1057. ;;      (setq en (point))
  1058. ;;      (subst-char-in-region st en ?. ?_)
  1059.       (insert " = \"%W%\";\n"
  1060.           "#endif /* lint */\n\n")))
  1061.     (run-hooks 'sccs-insert-c-header-hook)))
  1062.  
  1063. (defun sccs-insert-lisp-header ()
  1064.   (mapcar '(lambda (s) 
  1065.           (insert ";;;\t" s "\n"))
  1066.       sccs-headers-wanted)
  1067.   (insert "\n")
  1068.   (run-hooks 'sccs-insert-lisp-header-hook))
  1069.  
  1070. (defun sccs-insert-generic-header ()
  1071.   (let* ((comment-start-sccs (or comment-start "#"))
  1072.      (comment-end-sccs (or comment-end ""))
  1073.      (dont-insert-nl-p (string-match "\n" comment-end-sccs)))
  1074.     (mapcar '(lambda (s)
  1075.            (insert comment-start-sccs "\t" s ""
  1076.                comment-end-sccs (if dont-insert-nl-p "" "\n")))
  1077.       sccs-headers-wanted)
  1078.   (insert comment-start-sccs comment-end-sccs (if dont-insert-nl-p "" "\n"))))
  1079.  
  1080. (defun sccs-check-headers ()
  1081.   "Check if the current file has any SCCS headers in it."
  1082.   (interactive)
  1083.   (save-excursion
  1084.     (goto-char (point-min))
  1085.     (re-search-forward  "%[MIRLBSDHTEGUYFPQCZWA]%" (point-max) t)))
  1086.  
  1087. ;; Status-checking functions
  1088.  
  1089. (defun sccs-status (prefix legend)
  1090.    "List all files underneath the current directory matching a prefix type"
  1091.    (shell-command
  1092.     (format "find . -print | grep 'SCCS/%s\\.'" prefix))
  1093.    (if
  1094.        (save-excursion
  1095.      (set-buffer "*Shell Command Output*")
  1096.      (if (= (point-max) (point-min))
  1097.          (not (message
  1098.            "No files are currently %s under %s"
  1099.            legend default-directory))
  1100.        (progn
  1101.          (goto-char (point-min))
  1102.          (insert
  1103.           "The following files are currently " legend
  1104.           " under " default-directory ":\n")
  1105.          (replace-string (format "SCCS/%s." prefix) "")
  1106.          )
  1107.        )
  1108.      )
  1109.        (pop-to-buffer "*Shell Command Output*")
  1110.        )
  1111.      )
  1112.  
  1113. (defun sccs-pending ()
  1114.   "*List all files currently SCCS locked"
  1115.   (interactive)
  1116.   (sccs-status "p" "locked"))
  1117.  
  1118. (defun sccs-registered ()
  1119.   "*List all files currently SCCS registered"
  1120.   (interactive)
  1121.   (sccs-status "s" "registered"))
  1122.        
  1123. ;; Major functions for release-tracking and generation.
  1124.  
  1125. (defun sccs-release-diff (rel1 rel2)
  1126.   "*Generate a complete report on diffs between versions REL1 and REL2 for all
  1127. SCCS files at or below default-directory. If REL2 is omitted or nil, the
  1128. comparison is done against the most recent version."
  1129.   (interactive "sOlder version: \nsNewer version: ")
  1130.   (if (string-equal rel1 "") (setq rel1 nil))
  1131.   (if (string-equal rel2 "") (setq rel2 nil))
  1132.   (shell-command (concat
  1133.           "find " default-directory " -print | grep 'SCCS/s\\.'"))
  1134.   (set-buffer "*Shell Command Output*")
  1135.   (goto-char (point-min))
  1136.   (replace-string "SCCS/s." "")
  1137.   (goto-char (point-min))
  1138.   (if (eobp)
  1139.       (error "No SCCS files under %s" default-directory))
  1140.   (let
  1141.       ((sccsbuf (get-buffer-create "*SCCS*")))
  1142.     (save-excursion
  1143.       (set-buffer sccsbuf)
  1144.       (erase-buffer)
  1145.       (insert (format "Diffs from %s to %s.\n\n"
  1146.               (or rel1 "current") (or rel2 "current"))))
  1147.     (while (not (eobp))
  1148.      (let ((file (buffer-substring (point) (progn (end-of-line) (point)))))
  1149.        (save-excursion
  1150.          (set-buffer sccsbuf)
  1151.          (set-buffer-modified-p nil)
  1152.          (sccs-vdiff file rel1 rel2)
  1153.          (if (buffer-modified-p)
  1154.          (insert "\n"))
  1155.          )
  1156.        (forward-line 1)
  1157.        )
  1158.      )
  1159.     (kill-buffer "*Shell Command Output*")
  1160.     (pop-to-buffer sccsbuf)
  1161.     (insert "\nEnd of diffs.\n")
  1162.     (goto-char (point-min))
  1163.     (replace-string (format "/SCCS/%s." rel1) "/")
  1164.     (goto-char (point-min))
  1165.     (replace-string (format "/SCCS/%s." rel2) "/new/")
  1166.     (goto-char (point-min))
  1167.     (replace-string "/SCCS/new." "/new/")
  1168.     (goto-char (point-min))
  1169.     (replace-regexp (concat "^*** " default-directory) "*** ")
  1170.     (goto-char (point-min))
  1171.     (replace-regexp (concat "^--- " default-directory) "--- ")
  1172.     (goto-char (point-min))
  1173.     (set-buffer-modified-p nil)
  1174.     )
  1175.   )
  1176.  
  1177. (defun sccs-dummy-delta (file sid)
  1178.   "Make a dummy delta to the given FILE with the given SID"
  1179.   (interactive "sFile: \nsRelease ID: ")
  1180.   (if (not (sccs-locked-revision file))
  1181.       (sccs-get file t))
  1182.   ;; Grottiness alert -- to get around SCCS's obsessive second-guessing we
  1183.   ;; have to mung the p-file
  1184.   (save-excursion
  1185.     (let ((pfile (sccs-name file "p")))
  1186.       (chmod "u+w" pfile)
  1187.       (find-file pfile)
  1188.       (auto-save-mode nil)
  1189.       (replace-regexp "^\\([0-9.]+\\) \\([0-9.]+\\)" (concat "\\1 " sid) t)
  1190.       (write-region (point-min) (point-max) pfile t 0)
  1191.       (chmod "u-w" pfile)
  1192.       (set-buffer-modified-p nil)
  1193.       (kill-buffer (current-buffer))
  1194.       )
  1195.     )
  1196.   (sccs-delta file sid (concat "Release " sid))
  1197.   (sccs-get file nil)
  1198.   (sccs-save-vars sid)
  1199.   )
  1200.  
  1201. (defun sccs-delta-release (sid)
  1202.   "*Delta everything underneath the current directory to mark it as a release."
  1203.   (interactive "sRelease: ")
  1204.   (sccs-tree-walk 'sccs-dummy-delta sid)
  1205.   (kill-buffer "*SCCS*")
  1206.   )
  1207.  
  1208. ;; Set up key bindings for SCCS use, e.g. while editing log messages
  1209.  
  1210. (defun sccs-mode ()
  1211.   "Major mode for doing an sccs check in.
  1212. Calls the value of text-mode-hook then sccs-mode-hook.
  1213. Like Text Mode but with these additional comands:
  1214. C-c n        perform next logical SCCS operation (`sccs') on current file
  1215. C-c h        insert SCCS headers in current file
  1216. C-c d        show difference between buffer and last saved delta
  1217. C-c p        display change history of current file
  1218. C-c C-p        show all files currently locked by any user at or below .
  1219. C-c r        show all files registered into SCCS at or below .
  1220. C-c ?        show this message
  1221.  
  1222. While you are entering a change log message for a delta, the following
  1223. additional bindings will be in effect.
  1224.  
  1225. C-c C-c        proceed with check in, ending log message entry
  1226. C-x C-s        same as C-c C-c
  1227. C-c i        insert log message from last check-in
  1228. C-c a        abort this delta check-in
  1229.  
  1230. Global user options:
  1231.     sccs-max-log-size    specifies the maximum allowable size
  1232.                 of a log message plus one.
  1233.     sccs-default-diff-flags    flags to pass to diff(1) when doing
  1234.                 sccs-prs commands, useful if you have
  1235.                 a context differ
  1236.     sccs-headers-wanted    which %-keywords to insert when adding
  1237.                 SCCS headers with C-c h
  1238.     sccs-insert-static    if non-nil, SCCS keywords inserted in C files
  1239.                 get stuffed in a static string area so that
  1240.                 what(1) can see them in the compiled object
  1241.                 code.
  1242. "
  1243.   (interactive)
  1244.   (set-syntax-table text-mode-syntax-table)
  1245.   (use-local-map sccs-log-entry-mode)
  1246.   (setq local-abbrev-table text-mode-abbrev-table)
  1247.   (setq major-mode 'sccs-mode)
  1248.   (setq mode-name "SCCS")
  1249.   (run-hooks 'text-mode-hook 'sccs-mode-hook)
  1250. )
  1251.  
  1252. ;; Initialization code, to be done just once at load-time
  1253. (if sccs-log-entry-mode
  1254.     nil
  1255.   (setq sccs-log-entry-mode (make-sparse-keymap))
  1256.   (define-key sccs-log-entry-mode "\C-ci" 'sccs-insert-last-log)
  1257.   (define-key sccs-log-entry-mode "\C-c\C-i" 'sccs-insert-last-log)
  1258.   (define-key sccs-log-entry-mode "\C-ca" 'sccs-abort)
  1259.   (define-key sccs-log-entry-mode "\C-c\C-a" 'sccs-abort)
  1260.   (define-key sccs-log-entry-mode "\C-c\C-c" 'sccs-exit)
  1261.   (define-key sccs-log-entry-mode "\C-x\C-s" 'sccs-exit)
  1262. )
  1263.  
  1264. ;; sccs.el ends here
  1265. ;-------------------------------------CUT HERE----------------------------------
  1266. ;
  1267. ;Please acknowledge receipt of this code. I have sent the requested assignment
  1268. ;of copyright via paper mail.
  1269. ;
  1270. ;                                >>eric>>
  1271.