cvs.tcl

Go to the documentation of this file.
00001 /*  cvs.tcl --*/
00002 /* */
00003 /*  Handling of various cvs output formats.*/
00004 /* */
00005 /*  Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net>*/
00006 /* */
00007 /*  See the file "license.terms" for information on usage and redistribution*/
00008 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00009 /*  */
00010 /*  RCS: @(#) $Id: cvs.tcl,v 1.7 2005/09/28 04:51:19 andreas_kupries Exp $*/
00011 
00012 package require Tcl 8.2
00013 package require textutil
00014 
00015 namespace ::doctools {}
00016 namespace ::doctools::cvs {
00017     namespace export scanLog toChangeLog
00018 }
00019 
00020 /*  ::doctools::cvs::scanLog --*/
00021 /* */
00022 /*  Scan a log generated by 'cvs log' and extract the relevant information.*/
00023 /* */
00024 /*  Arguments:*/
00025 /*  text    The text to scan*/
00026 /* */
00027 /*  Results:*/
00028 /*  None.*/
00029 /* */
00030 /*  Sideeffects:*/
00031 /*  None.*/
00032 /* */
00033 /*  Notes:*/
00034 /*  Original location of code:  http://wiki.tcl.tk/3638*/
00035 /*              aka http://wiki.tcl.tk/log2changelog*/
00036 /*  Original author unknown.*/
00037 /*  Bugfix by TR / Torsten Reincke*/
00038 
00039 ret  ::doctools::cvs::scanLog (type text , type evar , type cvar , type fvar) {
00040 
00041     set text [split $text \n]
00042     set n    [llength $text]
00043 
00044     upvar $evar entries  ;    #set       entries  [list]
00045     upvar $cvar comments ;    #array set comments {}
00046     upvar $fvar files    ;    #array set files    {}
00047 
00048     for {set i 0} {$i < $n} {incr i} {
00049     set line [lindex $text $i]
00050     switch -glob -- $line {
00051         "*Working file:*" {
00052         regexp {Working file: (.*)} $line -> filename
00053         }
00054         "date:*" {
00055         scan $line "date: %s %s author: %s" date time author
00056         set author [string trim $author ";"]
00057 
00058         # read the comment lines following date
00059         set comment ""
00060         incr i
00061         set line [lindex $text $i]
00062         # [TR]: use regexp here to see if log ends:
00063         while {(![regexp "(-----*)|(=====*)" $line]) && ($i < $n)} {
00064             append comment $line "\n"
00065             incr i
00066             set line [lindex $text $i]
00067         }
00068 
00069         #  Store this date/author/comment
00070         lappend entries [list $date $author]
00071         lappend comments($date,$author) $comment
00072         lappend files($date,$author,$comment) $filename
00073         }
00074     }
00075     }
00076 
00077     return
00078 }
00079 
00080 
00081 /*  ::doctools::cvs::toChangeLog --*/
00082 
00083 /*  Convert a preprocessed cvs log (see scanLog) into a Changelog*/
00084 /*  suitable for emacs.*/
00085 /* */
00086 /*  Arguments:*/
00087 /*  evar, cvar, fvar: Name of the variables containing the preprocessed log.*/
00088 /* */
00089 /*  Results:*/
00090 /*  A string containing a properly formatted ChangeLog.*/
00091 /* */
00092 /*  Sideeffects:*/
00093 /*  None.*/
00094 /* */
00095 /*  Notes:*/
00096 /*  Original location of code:  http://wiki.tcl.tk/3638*/
00097 /*              aka http://wiki.tcl.tk/log2changelog*/
00098 /*  Original author unknown.*/
00099 
00100 ret  ::doctools::cvs::toChangeLog (type evar , type cvar , type fvar) {
00101     upvar $evar entries
00102     upvar $cvar comments
00103     upvar $fvar files
00104 
00105     set linebuffer [list]
00106 
00107     foreach e [lsort -unique -decreasing $entries] {
00108 
00109     #  print the date/author
00110     foreach {date author} $e {break}
00111     lappend linebuffer "$date $author"
00112     lappend linebuffer ""
00113 
00114     #  Find all the comments submitted this date/author
00115 
00116     set clist [lsort -unique $comments($date,$author)]
00117 
00118     foreach c $clist {
00119         #  Print all files for a given comment
00120         foreach f [lsort -unique $files($date,$author,$c)] {
00121         lappend linebuffer "\t* $f:"
00122         }
00123 
00124         #  Format and print the comment
00125 
00126         lappend linebuffer [textutil::indent [textutil::undent $c] "\t  "]
00127         lappend linebuffer ""
00128         continue
00129     }
00130     }
00131 
00132     return [join $linebuffer \n]
00133 }
00134 
00135 /* ------------------------------------*/
00136 /*  Module initialization*/
00137 
00138 package provide doctools::cvs 0.1.1
00139 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1