From 9ad3b1bbc06b43363d2983caa88896ef7eab330e Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 24 Apr 2021 17:17:10 -0400 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ Cargo.toml | 15 +++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 3 +++ src/lib.rs | 19 +++++++++++++++++++ src/version.rs | 9 +++++++++ 6 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/lib.rs create mode 100644 src/version.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2de3917 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +Cargo.lock +/.idea diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b9ea7c7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "filmscript" +version = "0.1.0" +authors = ["NGnius (Graham) "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = "0.2" +clap = "2" + +[lib] +name = "filmscript" +crate-type = ["rlib", "cdylib"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3237729 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 NGnius + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..526783e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# FilmScript + +The best Canadian camera technology since IMAX. diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ac9e4f9 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,19 @@ +use std::ffi::CString; +use std::os::raw::c_char; + +mod version; + +pub unsafe fn allocate_cstring(input: &str) -> *mut c_char { + let input_c = CString::new(input).expect("Rust &str -> CString conversion failed"); + let space = libc::malloc(libc::strlen(input_c.as_ptr()) + 1) as *mut c_char; + libc::strcpy(space, input_c.as_ptr()); + return space; +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/version.rs b/src/version.rs new file mode 100644 index 0000000..7ab4142 --- /dev/null +++ b/src/version.rs @@ -0,0 +1,9 @@ +//use libc; +use std::os::raw::c_char; +use crate::allocate_cstring; + +#[no_mangle] +pub unsafe extern "C" fn filmscript_version() -> *const c_char { + let crate_v = clap::crate_version!(); + allocate_cstring(crate_v) +} \ No newline at end of file