Commit Diff


commit - 2e6b707359dc0f08cf7fcc054dedf926bafc168f
commit + 41ac9085dc74afb7030d4f0a9c786d14137f8843
blob - 2169a45cd1baf27dbb465447fbe6c5662a7a89e8
blob + 3acb5bcf3d5c13ffd92c2ac67979cf7b27660d31
--- src/main.rs
+++ src/main.rs
@@ -15,9 +15,11 @@
 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 //
 
-use std::{env, fs, path::{Path, PathBuf}, collections::HashMap};
+use std::{env, fs, path::{Path, PathBuf}, collections::HashMap, sync::OnceLock};
 
 fn main() {
+    LOG_ENABLED.set(env::var("KSSG_LOG").is_ok()).ok();
+
     let args: Vec<String> = env::args().collect();
 
     match args.get(1).map(|s| s.as_str()) {
@@ -27,6 +29,59 @@ fn main() {
 }
 
 //////////////////////////////////////////////////////////////////////////////
+// DateTime
+//////////////////////////////////////////////////////////////////////////////
+
+#[repr(C)]
+struct Tm {
+    tm_sec: i32,
+    tm_min: i32,
+    tm_hour: i32,
+    tm_mday: i32,
+    tm_mon: i32,
+    tm_year: i32,
+    tm_wday: i32,
+    tm_yday: i32,
+    tm_isdst: i32,
+}
+
+unsafe extern "C" {
+    fn time(t: *mut i64) -> i64;
+    fn gmtime(t: *const i64) -> *const Tm;
+}
+
+fn now_utc() -> String {
+    unsafe {
+        let mut t: i64 = 0;
+        time(&mut t);
+        let tm = &*gmtime(&t);
+        format!(
+            "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
+            tm.tm_year + 1900,
+            tm.tm_mon + 1,
+            tm.tm_mday,
+            tm.tm_hour,
+            tm.tm_min,
+            tm.tm_sec,
+        )
+    }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// Log
+//////////////////////////////////////////////////////////////////////////////
+
+static LOG_ENABLED: OnceLock<bool> = OnceLock::new();
+
+macro_rules! log {
+    ($($arg:tt)*) => {
+        if *LOG_ENABLED.get().unwrap_or(&false) {
+            eprintln!("[{}] {}", now_utc(), format_args!($($arg)*));
+        }
+    };
+}
+
+//////////////////////////////////////////////////////////////////////////////
 // Frontmatter
 //////////////////////////////////////////////////////////////////////////////
 
@@ -118,6 +173,7 @@ fn copy_dir(src: &Path, dst: &Path) {
 //////////////////////////////////////////////////////////////////////////////
 
 fn build() {
+    log!("starting build");
     let template = fs::read_to_string("templates/base.html")
         .expect("read templates/base.html");