diff --git a/.gitignore b/.gitignore index ddd9d5f..7832355 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ obj/ sha256_literal/ **/target/ test.txt +file.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..455ed51 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +sfexec-output: + g++ -Iinclude/ -w --std=c++17 main.cpp sha256_literal/sha256.cpp -o sfexec diff --git a/generator-native/file.h b/generator-native/file.h deleted file mode 100644 index 024af87..0000000 --- a/generator-native/file.h +++ /dev/null @@ -1,13 +0,0 @@ -constexpr const int DATA_COUNT = 1; -constexpr const char* const DATA_EXEC_AFTER = nullptr; -static constexpr auto DATA_EXEC_AFTER_HASH = "unbound"_sha256; -constexpr const unsigned char DATA[] = { - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x70, 0x6c, - 0x61, 0x6e, 0x65, 0x74, 0x21, 0x0a, -}; -constexpr const long DATA_LENGTHS[DATA_COUNT] = { - 14ll, -}; -constexpr const char* const DATA_NAMES[DATA_COUNT] = { - "test.txt", -}; diff --git a/generator-native/src/main.rs b/generator-native/src/main.rs index 4c8d665..27ea6ca 100644 --- a/generator-native/src/main.rs +++ b/generator-native/src/main.rs @@ -22,6 +22,12 @@ mod arg; use opt::Opt; +macro_rules! flush { + () => { + std::io::stdout().flush().ok().expect("fatal: could not flush stdout") + } +} + fn usage() -> ! { let prog = &arg::program_name(); println!("Usage: {} [-s] [-e ] [-o ] [-] ", prog); @@ -115,8 +121,8 @@ fn main() -> Result<(), Box>{ if let Some(exec) = exec { let exec = translate::c_escape(exec); - writeln!(fp, "constexpr const char* const DATA_EXEC_AFTER = {};", exec)?; - writeln!(fp, "static constexpr auto DATA_EXEC_AFTER_HASH = {}_sha256;", exec)?; + writeln!(fp, "constexpr const char* const DATA_EXEC_AFTER = \"{}\";", exec)?; + writeln!(fp, "static constexpr auto DATA_EXEC_AFTER_HASH = \"{}\"_sha256;", exec)?; } else { writeln!(fp, "constexpr const char* const DATA_EXEC_AFTER = nullptr;")?; writeln!(fp, "static constexpr auto DATA_EXEC_AFTER_HASH = \"unbound\"_sha256;")?; @@ -127,6 +133,7 @@ fn main() -> Result<(), Box>{ for file in files.iter() { print!(" + {}", file); + flush!(); let file = OpenOptions::new() .read(true) .open(file)?; @@ -158,6 +165,7 @@ fn main() -> Result<(), Box>{ for file in files.into_iter() { let file = Path::new(&file); print!(" - {:?}", file); + flush!(); let file = match attempt_get_name(&file) { Ok(file) => file, Err(error) => {