-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension for loading SPICE files from julia package manager
This adds the following extension to ngspice (when loaded from Julia): In statements that load additional files from the filesystem (e.g. `.lib` and `.include`), a path preceded by `jlpkg:`, e.g. `jlpkg:my_pkg/models/my_model.sp` will be resolved by the julia package manager (taking the first path component to be a package name in the currently active project). The idea here is to manage libraries of SPICE files as julia packages.
- Loading branch information
Showing
6 changed files
with
85 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const JLPATH_PREFIX = "jlpkg:" | ||
|
||
function c_strdup(str) | ||
ptr = @ccall libngspice.tmalloc((sizeof(str)+1)::Cint)::Ptr{UInt8} | ||
@GC.preserve str Base.unsafe_copyto!(ptr, pointer(str), sizeof(str)) | ||
unsafe_store!(ptr, UInt8(0), sizeof(str) + 1) | ||
ptr | ||
end | ||
|
||
function path_resolve(name::Cstring, dir::Cstring)::Cstring | ||
name = unsafe_string(name) | ||
dir = unsafe_string(dir) | ||
|
||
if startswith(name, JLPATH_PREFIX) | ||
path = name[sizeof(JLPATH_PREFIX)+1:end] | ||
components = splitpath(path) | ||
|
||
@assert components[1] != "/" | ||
|
||
pkg_path = Base.locate_package(Base.PkgId(components[1])) | ||
if pkg_path !== nothing | ||
pkg_path = realpath(joinpath(dirname(pkg_path), "..")) | ||
file_path = joinpath(pkg_path, components[2:end]...) | ||
return c_strdup(file_path) | ||
end | ||
|
||
return Ptr{Cchar}(-1) | ||
end | ||
return C_NULL | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters