| | @@ -13,19 +13,19 @@ |
| 13 | 13 | |
| 14 | 14 | package require Tcl 8.4 |
| 15 | 15 | package require fileutil ; # Tcllib (cat) |
| 16 | 16 | package require vc::tools::log ; # User feedback |
| 17 | 17 | |
| 18 | | -namespace eval ::rcsparser { |
| 18 | +namespace eval ::vc::rcs::parser { |
| 19 | 19 | vc::tools::log::system rcs |
| 20 | 20 | namespace import ::vc::tools::log::progress |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | # ----------------------------------------------------------------------------- |
| 24 | 24 | # API |
| 25 | 25 | |
| 26 | | -# rcsparser::process file |
| 26 | +# vc::rcs::parser::process file |
| 27 | 27 | # |
| 28 | 28 | # Parses the rcs file and returns a dictionary containing the meta |
| 29 | 29 | # data. The following keys are used |
| 30 | 30 | # |
| 31 | 31 | # Key Meaning |
| | @@ -45,11 +45,11 @@ |
| 45 | 45 | # The state 'dead' has special meaning, the user should know that. |
| 46 | 46 | |
| 47 | 47 | # ----------------------------------------------------------------------------- |
| 48 | 48 | # API Implementation |
| 49 | 49 | |
| 50 | | -proc ::rcsparser::process {path} { |
| 50 | +proc ::vc::rcs::parser::process {path} { |
| 51 | 51 | set data [fileutil::cat -encoding binary $path] |
| 52 | 52 | array set res {} |
| 53 | 53 | set res(size) [file size $path] |
| 54 | 54 | set res(done) 0 |
| 55 | 55 | set res(nsize) [string length $res(size)] |
| | @@ -70,97 +70,97 @@ |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | # ----------------------------------------------------------------------------- |
| 73 | 73 | # Internal - Recursive Descent functions implementing the syntax. |
| 74 | 74 | |
| 75 | | -proc ::rcsparser::Admin {} { |
| 75 | +proc ::vc::rcs::parser::Admin {} { |
| 76 | 76 | upvar 1 data data res res |
| 77 | 77 | Head ; Branch ; Access ; Symbols ; Locks ; Strict ; Comment ; Expand |
| 78 | 78 | return |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | | -proc ::rcsparser::Deltas {} { |
| 81 | +proc ::vc::rcs::parser::Deltas {} { |
| 82 | 82 | upvar 1 data data res res |
| 83 | 83 | while {[Num 0]} { IsIdent ; Date ; Author ; State ; Branches ; NextRev } |
| 84 | 84 | return |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | | -proc ::rcsparser::Description {} { |
| 87 | +proc ::vc::rcs::parser::Description {} { |
| 88 | 88 | upvar 1 data data res res |
| 89 | 89 | Literal desc |
| 90 | 90 | String 1 |
| 91 | 91 | Def desc |
| 92 | 92 | return |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | | -proc ::rcsparser::DeltaTexts {} { |
| 95 | +proc ::vc::rcs::parser::DeltaTexts {} { |
| 96 | 96 | upvar 1 data data res res |
| 97 | 97 | while {[Num 0]} { IsIdent ; Log ; Text } |
| 98 | 98 | return |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | | -proc ::rcsparser::Head {} { |
| 101 | +proc ::vc::rcs::parser::Head {} { |
| 102 | 102 | upvar 1 data data res res |
| 103 | 103 | Literal head ; Num 1 ; Literal \; |
| 104 | 104 | Def head |
| 105 | 105 | return |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | | -proc ::rcsparser::Branch {} { |
| 108 | +proc ::vc::rcs::parser::Branch {} { |
| 109 | 109 | upvar 1 data data res res |
| 110 | 110 | if {![Literal branch 0]} return ; Num 1 ; Literal \; |
| 111 | 111 | Def branch |
| 112 | 112 | return |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | | -proc ::rcsparser::Access {} { |
| 115 | +proc ::vc::rcs::parser::Access {} { |
| 116 | 116 | upvar 1 data data res res |
| 117 | 117 | Literal access ; Literal \; |
| 118 | 118 | return |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | | -proc ::rcsparser::Symbols {} { |
| 121 | +proc ::vc::rcs::parser::Symbols {} { |
| 122 | 122 | upvar 1 data data res res |
| 123 | 123 | Literal symbols |
| 124 | 124 | while {[Ident]} { Num 1 ; Map symbol } |
| 125 | 125 | Literal \; |
| 126 | 126 | return |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | | -proc ::rcsparser::Locks {} { |
| 129 | +proc ::vc::rcs::parser::Locks {} { |
| 130 | 130 | upvar 1 data data res res |
| 131 | 131 | Literal locks |
| 132 | 132 | while {[Ident]} { Num 1 ; Map lock } |
| 133 | 133 | Literal \; |
| 134 | 134 | return |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | | -proc ::rcsparser::Strict {} { |
| 137 | +proc ::vc::rcs::parser::Strict {} { |
| 138 | 138 | upvar 1 data data res res |
| 139 | 139 | if {![Literal strict 0]} return ; Literal \; |
| 140 | 140 | return |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | | -proc ::rcsparser::Comment {} { |
| 143 | +proc ::vc::rcs::parser::Comment {} { |
| 144 | 144 | upvar 1 data data res res |
| 145 | 145 | if {![Literal comment 0]} return ; |
| 146 | 146 | if {![String 0]} return ; |
| 147 | 147 | Literal \; |
| 148 | 148 | Def comment |
| 149 | 149 | return |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | | -proc ::rcsparser::Expand {} { |
| 152 | +proc ::vc::rcs::parser::Expand {} { |
| 153 | 153 | upvar 1 data data res res |
| 154 | 154 | if {![Literal expand 0]} return ; |
| 155 | 155 | if {![String 0]} return ; |
| 156 | 156 | Literal \; |
| 157 | 157 | Def expand |
| 158 | 158 | return |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | | -proc ::rcsparser::Date {} { |
| 161 | +proc ::vc::rcs::parser::Date {} { |
| 162 | 162 | upvar 1 data data res res |
| 163 | 163 | Literal date ; Num 1 ; Literal \; |
| 164 | 164 | |
| 165 | 165 | foreach {yr mo dy h m s} [split $res(lastval) .] break |
| 166 | 166 | if {$yr < 100} {incr yr 1900} |
| | @@ -167,50 +167,50 @@ |
| 167 | 167 | set res(lastval) [join [list $yr $mo $dy $h $m $s] .] |
| 168 | 168 | Map date |
| 169 | 169 | return |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | | -proc ::rcsparser::Author {} { |
| 172 | +proc ::vc::rcs::parser::Author {} { |
| 173 | 173 | upvar 1 data data res res |
| 174 | 174 | Literal author ; Skip ; Literal \; ; Map author |
| 175 | 175 | return |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | | -proc ::rcsparser::State {} { |
| 178 | +proc ::vc::rcs::parser::State {} { |
| 179 | 179 | upvar 1 data data res res |
| 180 | 180 | Literal state ; Skip ; Literal \; ; Map state |
| 181 | 181 | return |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | | -proc ::rcsparser::Branches {} { |
| 184 | +proc ::vc::rcs::parser::Branches {} { |
| 185 | 185 | upvar 1 data data res res |
| 186 | 186 | Literal branches ; Skip ; Literal \; |
| 187 | 187 | return |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | | -proc ::rcsparser::NextRev {} { |
| 190 | +proc ::vc::rcs::parser::NextRev {} { |
| 191 | 191 | upvar 1 data data res res |
| 192 | 192 | Literal next ; Skip ; Literal \; ; Map parent |
| 193 | 193 | return |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | | -proc ::rcsparser::Log {} { |
| 196 | +proc ::vc::rcs::parser::Log {} { |
| 197 | 197 | upvar 1 data data res res |
| 198 | 198 | Literal log ; String 1 ; Map commit |
| 199 | 199 | return |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | | -proc ::rcsparser::Text {} { |
| 202 | +proc ::vc::rcs::parser::Text {} { |
| 203 | 203 | upvar 1 data data res res |
| 204 | 204 | Literal text ; String 1 |
| 205 | 205 | return |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | # ----------------------------------------------------------------------------- |
| 209 | 209 | # Internal - Lexicographical commands and data aquisition preparation |
| 210 | 210 | |
| 211 | | -proc ::rcsparser::Ident {} { |
| 211 | +proc ::vc::rcs::parser::Ident {} { |
| 212 | 212 | upvar 1 data data res res |
| 213 | 213 | |
| 214 | 214 | #puts I@?<[string range $data 0 10]...> |
| 215 | 215 | |
| 216 | 216 | if {[regexp -indices -- {^\s*;\s*} $data]} { |
| | @@ -222,11 +222,11 @@ |
| 222 | 222 | Get $val ; IsIdent |
| 223 | 223 | Next |
| 224 | 224 | return 1 |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | | -proc ::rcsparser::Literal {name {required 1}} { |
| 227 | +proc ::vc::rcs::parser::Literal {name {required 1}} { |
| 228 | 228 | upvar 1 data data res res |
| 229 | 229 | if {![regexp -indices -- "^\\s*$name\\s*" $data match]} { |
| 230 | 230 | if {$required} { |
| 231 | 231 | return -code error "Expected '$name' @ '[string range $data 0 30]...'" |
| 232 | 232 | } |
| | @@ -235,11 +235,11 @@ |
| 235 | 235 | |
| 236 | 236 | Next |
| 237 | 237 | return 1 |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | | -proc ::rcsparser::String {{required 1}} { |
| 240 | +proc ::vc::rcs::parser::String {{required 1}} { |
| 241 | 241 | upvar 1 data data res res |
| 242 | 242 | |
| 243 | 243 | if {![regexp -indices -- {^\s*@(([^@]*(@@)*)*)@\s*} $data match val]} { |
| 244 | 244 | if {$required} { |
| 245 | 245 | return -code error "Expected string @ '[string range $data 0 30]...'" |
| | @@ -250,11 +250,11 @@ |
| 250 | 250 | Get $val |
| 251 | 251 | Next |
| 252 | 252 | return 1 |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | | -proc ::rcsparser::Num {required} { |
| 255 | +proc ::vc::rcs::parser::Num {required} { |
| 256 | 256 | upvar 1 data data res res |
| 257 | 257 | if {![regexp -indices -- {^\s*((\d|\.)+)\s*} $data match val]} { |
| 258 | 258 | if {$required} { |
| 259 | 259 | return -code error "Expected id @ '[string range $data 0 30]...'" |
| 260 | 260 | } |
| | @@ -264,11 +264,11 @@ |
| 264 | 264 | Get $val |
| 265 | 265 | Next |
| 266 | 266 | return 1 |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | | -proc ::rcsparser::Skip {} { |
| 269 | +proc ::vc::rcs::parser::Skip {} { |
| 270 | 270 | upvar 1 data data res res |
| 271 | 271 | regexp -indices -- {^\s*([^;]*)\s*} $data match val |
| 272 | 272 | Get $val |
| 273 | 273 | Next |
| 274 | 274 | return |
| | @@ -275,51 +275,55 @@ |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | # ----------------------------------------------------------------------------- |
| 278 | 278 | # Internal - Data aquisition |
| 279 | 279 | |
| 280 | | -proc ::rcsparser::Def {key} { |
| 280 | +proc ::vc::rcs::parser::Def {key} { |
| 281 | 281 | upvar 1 data data res res |
| 282 | 282 | set res($key) $res(lastval) |
| 283 | 283 | unset res(lastval) |
| 284 | 284 | return |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | | -proc ::rcsparser::Map {key} { |
| 287 | +proc ::vc::rcs::parser::Map {key} { |
| 288 | 288 | upvar 1 data data res res |
| 289 | 289 | lappend res($key) $res(id) $res(lastval) |
| 290 | 290 | #puts Map($res(id))=($res(lastval)) |
| 291 | 291 | unset res(lastval) |
| 292 | 292 | #unset res(id);#Keep id for additional mappings. |
| 293 | 293 | return |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | | -proc ::rcsparser::IsIdent {} { |
| 296 | +proc ::vc::rcs::parser::IsIdent {} { |
| 297 | 297 | upvar 1 data data res res |
| 298 | 298 | set res(id) $res(lastval) |
| 299 | 299 | unset res(lastval) |
| 300 | 300 | return |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | | -proc ::rcsparser::Get {val} { |
| 303 | +proc ::vc::rcs::parser::Get {val} { |
| 304 | 304 | upvar 1 data data res res |
| 305 | 305 | foreach {s e} $val break |
| 306 | 306 | set res(lastval) [string range $data $s $e] |
| 307 | 307 | #puts G|$res(lastval) |
| 308 | 308 | return |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | | -proc ::rcsparser::Next {} { |
| 311 | +proc ::vc::rcs::parser::Next {} { |
| 312 | 312 | upvar 1 match match data data res res |
| 313 | 313 | foreach {s e} $match break ; incr e |
| 314 | 314 | set data [string range $data $e end] |
| 315 | 315 | set res(done) [expr {$res(size) - [string length $data]}] |
| 316 | 316 | |
| 317 | 317 | progress 2 rcs $res(done) $res(size) |
| 318 | 318 | return |
| 319 | 319 | } |
| 320 | + |
| 321 | +namespace eval ::vc::rcs::parser { |
| 322 | + namespace export process |
| 323 | +} |
| 320 | 324 | |
| 321 | 325 | # ----------------------------------------------------------------------------- |
| 322 | 326 | # Ready |
| 323 | 327 | |
| 324 | | -package provide rcsparser 1.0 |
| 328 | +package provide vc::rcs::parser 1.0 |
| 325 | 329 | return |
| 326 | 330 | |