Commit 33f6041b408cc735c09753043fc7645ca1c434de

Authored by Andreas Rumpf
1 parent 06b0bbf2

make blimp compile with Nim version 0.11.2

Showing 2 changed files with 65 additions and 65 deletions
blimp.nim
... ... @@ -12,7 +12,7 @@ import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes, t
12 12 #
13 13 # Just run blimp --help for detailed help.
14 14  
15   -const
  15 +const
16 16 versionMajor* = 0
17 17 versionMinor* = 4
18 18 versionPatch* = 0
... ... @@ -88,7 +88,7 @@ proc cmd(cmd: string): string =
88 88 when defined(windows):
89 89 let tup = execCmdEx("cmd /c \"" & cmd & "\"")
90 90 else:
91   - let tup = execCmdEx(cmd)
  91 + let tup = execCmdEx(cmd)
92 92 #echo "cmd: " & $cmd & "err:" & $tup[1]
93 93 if tup[1] == 0:
94 94 result = strip(tup[0])
... ... @@ -124,7 +124,7 @@ proc expandDirs(templ: string): string =
124 124 result = templ.replace("%home%", homeDir)
125 125 result = result.replace("%cwd%", currentDir)
126 126 if result.contains("%gitroot%"):
127   - if gitRootDir.isNil: quit("Not in a git clone, can not expand %gitroot% in '" & templ & "'")
  127 + if gitRootDir.isNil: quit("Not in a git clone, can not expand %gitroot% in '" & templ & "'")
128 128 result = result.replace("%gitroot%", gitRootDir)
129 129  
130 130 # Copy of readAllBuffer from sysio.nim - we need to call it
... ... @@ -147,14 +147,14 @@ proc parseConfFile(filename: string) =
147 147 var f = newFileStream(filename, fmRead)
148 148 if f != nil:
149 149 if verbose: echo "Reading config: " & filename
150   - var p: CfgParser
  150 + var p: CfgParser
151 151 open(p, f, filename)
152 152 var section: string
153 153 var area: RemoteArea
154 154 while true:
155 155 var e = next(p)
156 156 case e.kind
157   - of cfgEof:
  157 + of cfgEof:
158 158 break
159 159 of cfgSectionStart:
160 160 section = e.section
... ... @@ -163,7 +163,7 @@ proc parseConfFile(filename: string) =
163 163 of "blimp":
164 164 case e.key
165 165 of "blimpstore":
166   - if blimpStore.isNil: blimpStore = expandDirs(e.value)
  166 + if blimpStore.isNil: blimpStore = expandDirs(e.value)
167 167 of "version":
168 168 if blimpVersion.isNil: blimpVersion = e.value
169 169 else:
... ... @@ -215,7 +215,7 @@ proc uploadFile(filename, fromDir: string) =
215 215 let errorCode = run(format(remoteArea.upload, filename, remoteArea.url, toUnixyPath(fromDir)))
216 216 if errorCode != 0:
217 217 quit("Something went wrong uploading " & filename & " to " & remoteArea.url, 2)
218   -
  218 +
219 219 # Download a file to the remote area
220 220 proc downloadFile(filename, toDir: string) =
221 221 if remoteArea.isNil:
... ... @@ -243,7 +243,7 @@ proc copyToBlimpStore(filename, blimpFilename: string) =
243 243 else:
244 244 copyFile(filename, blimpStore / blimpFilename)
245 245 uploadFile(blimpFilename, blimpStore)
246   -
  246 +
247 247  
248 248 # Copy content from blimpStore, and downloading first if needed
249 249 proc copyFromBlimpStore(blimpFilename, filename: string) =
... ... @@ -279,7 +279,7 @@ proc blimpFileName(filename: string): string =
279 279 var hashfile: File
280 280 if not open(hashfile, filename):
281 281 quit("Failed opening file: " & filename, 4)
282   - blimpFileNameFromString(string(readLine(hashfile)))
  282 + blimpFileNameFromString(string(readLine(hashfile)))
283 283  
284 284 # Get hash and compute blimpFilename
285 285 proc computeBlimpFilename(filename: string): string =
... ... @@ -290,7 +290,7 @@ proc computeBlimpFilename(filename: string): string =
290 290 quit("Failed opening file: " & filename, 1)
291 291 let hash = getMD5(content)
292 292 result = extractFilename(filename) & "-" & hash
293   -
  293 +
294 294 # Copy original file to blimpStore and replace with hash stub in git.
295 295 proc deflate(filename: string) =
296 296 if verbose: echo "Deflating " & filename
... ... @@ -312,7 +312,7 @@ iterator allDeflated() =
312 312 for fn in filenames:
313 313 if not blimpFilename(fn).isNil:
314 314 yield fn
315   -
  315 +
316 316 # Iterator over all files matching the blimp filter in the git clone
317 317 iterator allFiltered() =
318 318 let lines = cmd("git ls-files | git check-attr --stdin filter").split({'\l', '\c'})
... ... @@ -360,7 +360,7 @@ proc upload(filename: string) =
360 360 if verbose: echo "Uploading " & filename
361 361 uploadFile(filename, currentDir)
362 362 if verbose: echo("\t" & filename & " uploaded.")
363   -
  363 +
364 364 # Download a file from a remote area.
365 365 proc download(filename: string) =
366 366 if verbose: echo "Downloading " & filename
... ... @@ -421,17 +421,17 @@ let help = """
421 421 Use "blimp i mybigfile" to inflate it back to original content.
422 422  
423 423 When deflated the file only has this content:
424   -
  424 +
425 425 "blimphash:" <filename> "-" <md5sum>
426 426  
427 427 Deflate also copies the real content to your local blimpstore:
428   -
  428 +
429 429 <blimpstore>/<filename>-<md5sum>
430 430  
431 431 ...and if configured also uploads it to "remote", using rsync.
432 432  
433 433 Configuration is in these locations in order:
434   -
  434 +
435 435 ./.blimp.conf
436 436 <gitroot>/.blimp.conf
437 437 ~/<blimpstore>/.blimp.conf
... ... @@ -458,19 +458,19 @@ let help = &quot;&quot;&quot;
458 458 both from the local blimpstore and from the remote. This only removes
459 459 the current content version, not older versions. The file itself is first
460 460 inflated, if needed, and not deleted. This only "unblimps" the file.
461   -
  461 +
462 462 The push command (no single character shortcut) will force upload the given file
463 463 from the local blimpstore to the remote. This is normally done automatically,
464 464 but this way you can make sure they are synced onto the remote.
465   -
  465 +
466 466 The upload and download commands are used to distribute artifacts typically in a
467 467 build script. If no --area is given, they use the standard "remote" area.
468   -
  468 +
469 469 In order to have blimp work automatically you can:
470   -
  470 +
471 471 * Create a .gitattributes file with lines like:
472 472 *.png filter=blimp binary
473   -
  473 +
474 474 * Configure blimp as a filter by running:
475 475 git config filter.blimp.clean "blimp -s d %f"
476 476 git config filter.blimp.smudge "blimp -s i %f"
... ... @@ -479,13 +479,13 @@ let help = &quot;&quot;&quot;
479 479  
480 480 When the above is done (per clone) git will automatically run blimp deflate
481 481 just before committing and blimp inflate when operations are done.
482   -
  482 +
483 483 This means that if you clone a git repository that already has a .gitattributes
484 484 file in it that uses the blimp filter, then you should do:
485   -
  485 +
486 486 blimp init
487 487 blimp inflate --filter
488   -
  488 +
489 489 This will configure the blimp filter and then find and inflate all deflated
490 490 files throughout the clone.
491 491 """
... ... @@ -493,7 +493,7 @@ let help = &quot;&quot;&quot;
493 493 ################################ main #####################################
494 494 # Set some dirs
495 495 homeDir = getHomeDir()
496   -homeDir = homeDir[0.. -2] # Not sure why it keeps a trailing "/" on Linux
  496 +homeDir = homeDir[0..^2] # Not sure why it keeps a trailing "/" on Linux
497 497 currentDir = getCurrentDir()
498 498 gitRootDir = gitRoot()
499 499  
... ... @@ -545,7 +545,7 @@ if not blimpVersion.isNil and blimpVersion != versionAsString:
545 545 quit("Wrong version of blimp, configuration wants: " & blimpVersion)
546 546  
547 547  
548   -# Ok, let's see
  548 +# Ok, let's see
549 549 var filenames = initSet[string]()
550 550  
551 551 # Add upp all files to operate on in a Set
... ...
lapp.nim
... ... @@ -25,7 +25,7 @@ proc next(L: PLexer) = L.idx += 1
25 25  
26 26 proc skipws(L: PLexer) =
27 27 while thisChar(L) in Whitespace: next(L)
28   -
  28 +
29 29 proc get(L: PLexer; t: var TLexType): string =
30 30 skipws(L)
31 31 let c = thisChar(L)
... ... @@ -33,7 +33,7 @@ proc get(L: PLexer; t: var TLexType): string =
33 33 if c == '\0': return nil
34 34 result = ""
35 35 result.add(c)
36   - next(L)
  36 + next(L)
37 37 t = tchar
38 38 case c
39 39 of '-': # '-", "--"
... ... @@ -43,7 +43,7 @@ proc get(L: PLexer; t: var TLexType): string =
43 43 next(L)
44 44 if thisChar(L) == '-': # "---..."
45 45 t = tdivider
46   - result.add('-')
  46 + result.add('-')
47 47 while thisChar(L) == '-':
48 48 next(L)
49 49 of Letters: # word
... ... @@ -73,11 +73,11 @@ proc get(L: PLexer; t: var TLexType): string =
73 73 result.add('.')
74 74 next(L)
75 75 else: discard
76   -
77   -proc get(L: PLexer): string =
  76 +
  77 +proc get(L: PLexer): string =
78 78 var t: TLexType
79 79 get(L,t)
80   -
  80 +
81 81 proc reset(L: PLexer, s: string) =
82 82 L.str = s
83 83 L.idx = 0
... ... @@ -85,9 +85,9 @@ proc reset(L: PLexer, s: string) =
85 85 proc newLexer(s: string): PLexer =
86 86 new(result)
87 87 result.reset(s)
88   -
  88 +
89 89 ### a container for values ###
90   -
  90 +
91 91 type
92 92 TValueKind = enum
93 93 vInt,
... ... @@ -110,17 +110,17 @@ type
110 110 of vSeq: asSeq*: seq[PValue]
111 111  
112 112 proc boolValue(c: bool): PValue = PValue(kind: vBool, asBool: c)
113   -
  113 +
114 114 proc fileValue(f: File, name: string): PValue = PValue(kind: vFile, asFile: f, fileName: name)
115   -
116   -proc strValue(s: string): PValue = PValue(kind: vString, asString: s)
117   -
  115 +
  116 +proc strValue(s: string): PValue = PValue(kind: vString, asString: s)
  117 +
118 118 proc intValue(v: int): PValue = PValue(kind: vInt, asInt: v)
119   -
  119 +
120 120 proc floatValue(v: float): PValue = PValue(kind: vFloat, asFloat: v)
121   -
  121 +
122 122 proc seqValue(v: seq[PValue]): PValue = PValue(kind: vSeq, asSeq: v)
123   -
  123 +
124 124 type
125 125 PSpec = ref TSpec
126 126 TSpec = object
... ... @@ -137,18 +137,18 @@ proc fail(msg: string) =
137 137 stderr.writeln(progname & ": " & msg)
138 138 quit(usage)
139 139  
140   -proc parseSpec(u: string) =
  140 +proc parseSpec(u: string) =
141 141 var
142 142 L: PLexer
143 143 tok: string
144 144 groupCounter: int
145 145 k = 1
146   -
  146 +
147 147 let lines = u.splitLines
148 148 L = newLexer(lines[0])
149 149 progname = L.get
150 150 usage = u
151   - for line in lines[1..(-1)]:
  151 + for line in lines[1 .. ^1]:
152 152 var
153 153 isarg = false
154 154 multiple = false
... ... @@ -188,7 +188,7 @@ proc parseSpec(u: string) =
188 188 tok = L.get
189 189 if tok == nil: continue
190 190 # default types for flags and arguments
191   - var
  191 + var
192 192 ftype = if isarg: "string" else: "bool"
193 193 defValue = ""
194 194 if tok == "(": # typed flag/argument
... ... @@ -212,16 +212,16 @@ proc parseSpec(u: string) =
212 212 multiple = t == telipsis
213 213 elif ftype == "bool": # no type or default
214 214 defValue = "false"
215   -
  215 +
216 216 if name != nil:
217 217 #echo("Param: " & name & " type: " & $ftype & " group: " & $groupCounter & " needsvalue: " & $(ftype != "bool") & " default: " & $defValue & " multiple: " & $multiple)
218 218 let spec = PSpec(defVal:defValue, ptype: ftype, group: groupCounter, needsValue: ftype != "bool",multiple:multiple)
219   - aliases[alias] = name
  219 + aliases[alias] = name
220 220 parm_spec[name] = spec
221 221  
222   -proc tail(s: string): string = s[1..(-1)]
  222 +proc tail(s: string): string = s[1..^1]
223 223  
224   -var
  224 +var
225 225 files = newSeq[File]()
226 226  
227 227 proc closeFiles() {.noconv.} =
... ... @@ -234,16 +234,16 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
234 234 n = len(args) - 1
235 235 i = 1
236 236 k = 1
237   - flag,value, arg: string
  237 + flag,value, arg: string
238 238 info: PSpec
239 239 short: bool
240 240 flagvalues: seq[seq[string]]
241   -
  241 +
242 242 proc next(): string =
243 243 if i > n: fail("an option required a value!")
244 244 result = args[i]
245 245 i += 1
246   -
  246 +
247 247 proc get_alias(c: char): string =
248 248 result = aliases[c]
249 249 if result == nil:
... ... @@ -252,7 +252,7 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
252 252 fail("no such argument: " & $n)
253 253 else:
254 254 fail("no such option: " & c)
255   -
  255 +
256 256 proc get_spec(name: string): PSpec =
257 257 result = parm_spec[name]
258 258 if result == nil:
... ... @@ -264,7 +264,7 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
264 264  
265 265 # Collect failures
266 266 var failures = newSeq[string]()
267   -
  267 +
268 268 # parse the flags and arguments
269 269 while i <= n:
270 270 arg = next()
... ... @@ -299,26 +299,26 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
299 299 if not info.multiple: k += 1
300 300 flagvalues.add(@[flag,value])
301 301 info.used = true
302   -
  302 +
303 303 # Some options disables checking
304 304 var enableChecks = true
305 305 for flag,info in parm_spec:
306 306 if info.used:
307 307 if flag == "help" or flag == "version":
308 308 enableChecks = false
309   -
  309 +
310 310 # Check maximum group used
311 311 var maxGroup = 0
312 312 for item in flagvalues:
313 313 info = get_spec(item[0])
314 314 if maxGroup < info.group:
315 315 maxGroup = info.group
316   -
  316 +
317 317 # any flags not mentioned?
318 318 for flag,info in parm_spec:
319 319 if not info.used:
320 320 # Is there no default and we have used options in this group?
321   - if info.defVal == "" and info.group <= maxGroup:
  321 + if info.defVal == "" and info.group <= maxGroup:
322 322 failures.add("required option or argument missing: " & flag)
323 323 else:
324 324 flagvalues.add(@[flag,info.defVal])
... ... @@ -373,7 +373,7 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
373 373 fail("cannot open " & value)
374 374 pval = fileValue(f,value)
375 375 else: discard
376   -
  376 +
377 377 var oval = vars[flag]
378 378 if info.multiple: # multiple flags are sequence values
379 379 if oval == nil: # first value!
... ... @@ -388,13 +388,13 @@ proc parseArguments*(usage: string, args: seq[string]): Table[string,PValue] =
388 388 return vars
389 389  
390 390 proc parse*(usage: string): Table[string,PValue] =
391   - var
  391 + var
392 392 args: seq[string]
393 393 n = paramCount()
394 394 newSeq(args,n+1)
395 395 for i in 0..n:
396 396 args[i] = paramStr(i)
397   - return parseArguments(usage,args)
  397 + return parseArguments(usage,args)
398 398  
399 399 # Helper proc for verbosity level.
400 400 proc verbosityLevel*(args: Table[string,PValue]): int =
... ... @@ -432,19 +432,19 @@ when isMainModule:
432 432 # These two are special, they short out
433 433 if args.showHelp: quit(help)
434 434 if args.showVersion: quit("Version: 1.99")
435   -
  435 +
436 436 # Ok, so what did we get...
437 437 let n = args["n"].asInt
438   -
  438 +
439 439 # This one is a helper
440 440 let v = verbosityLevel(args)
441   -
  441 +
442 442 echo "Lines to show: " & $n
443 443 echo "Verbosity level: " & $verbosityLevel(args)
444   -
  444 +
445 445 let myfiles = args["files"].asSeq
446 446 var outFile = args["out"].asFile
447   -
  447 +
448 448 for f in myfiles:
449 449 for i in 1..n:
450 450 writeln(outFile, string(f.asFile.readLine()))
... ...