Skip to content

Commit

Permalink
Add nio fromSV -d feature to cd pre-parse. Bump version pre-release.
Browse files Browse the repository at this point in the history
  • Loading branch information
c-blake committed Jul 11, 2021
1 parent 9d6d8fa commit 218e5e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions nio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ proc maybeAppend(path: string): FileMode = # modes maybe weird from Windows
result = if info.id.device == 0: fmWrite else: fmAppend

from cligen/argcvt import unescape
proc fromSV*(schema="", nameSep="", onlyOut=false, SVs: Strings): int =
proc fromSV*(schema="", nameSep="", dir="", onlyOut=false, SVs: Strings): int =
## parse *strict* separated values on stdin|SVs to NIO files via schemas.
##
## An example schema file (with default values but for `outSfx`):
Expand Down Expand Up @@ -922,7 +922,14 @@ proc fromSV*(schema="", nameSep="", onlyOut=false, SVs: Strings): int =
var doZip: bool
var xfm0: Transform = nil
var slno = 0
var didDir = false # Flag to only do mkdir/chdir once
var oldDir = getCurrentDir() # For restoring if called as a library
for line in lines(schema):
if dir.len > 0 and not didDir: # Done here so users need no special
discard existsOrCreateDir(dir) #..instructions Re: schema path.
try: setCurrentDir dir
except: erru &"Cannot cd to {dir}!\n"; return 1
didDir = true
inc slno
var c: Col # in loop re-inits each time
let line = line.commentStrip
Expand Down Expand Up @@ -986,7 +993,10 @@ proc fromSV*(schema="", nameSep="", onlyOut=false, SVs: Strings): int =
for c in cols:
if c.xfm != xfm0 and c.xfm != nil: c.xfm nil, "", 0 # close `Transform`s
if c.f != nil and c.f != stdout: c.f.close
if xfm0 != nil: xfm0(nil, "", 0) # close common `Transform`
if xfm0 != nil: xfm0(nil, "", 0) # close common `Transform`
if dir.len > 0: # Restore; if called as library API
try: setCurrentDir oldDir
except: erru &"Cannot revert cd back to {oldDir}!\n"; return 1

proc inferT*(ext=".sc", pre="", delim="\x00", nHdr=1, timeFmts: Strings = @[],
iType='i', fType='f', sType="i.Dn", guess="f\tf", SVs: Strings): int =
Expand Down Expand Up @@ -1125,6 +1135,7 @@ when isMainModule:
[fromSV, help={"SVs" : "[?SVs: input paths; empty|\"-\"=stdin]",
"onlyOut": "only parse schema & gen output name",
"nameSep": "string to separate schema col names",
"dir" : "maybe create&chdir here; SVs may need '..'",
"schema": "path to the parsing schema file"}],
[meta , help={"nios" : "paths to NIO files",
"format": """%[nrwzb]: name,rows,width,rowSize,lastBaseType
Expand Down
2 changes: 1 addition & 1 deletion nio.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package
version = "0.1.2"
version = "0.1.3"
author = "Charles Blake"
description = "Low Overhead Numerical/Native IO library & tools"
license = "MIT/ISC"
Expand Down

0 comments on commit 218e5e8

Please sign in to comment.