MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 73 lines 2.0 kB view raw
1#include "utils.h" 2 3#include <string.h> 4#include <argtable3.h> 5#include <pthread.h> 6 7static char ant_semver_buf[32]; 8static pthread_once_t ant_semver_once = PTHREAD_ONCE_INIT; 9 10static void ant_semver_init(void) { 11 const char *s = ANT_VERSION; 12 int d = 0, i = 0; 13 while (s[i] && d < 3 && i < 31) { 14 if (s[i] == '.') d++; 15 ant_semver_buf[i] = s[i]; i++; 16 } 17 ant_semver_buf[i - (d == 3)] = '\0'; 18} 19 20const char *ant_semver(void) { 21 pthread_once(&ant_semver_once, ant_semver_init); 22 return ant_semver_buf; 23} 24 25int ant_version(void *argtable[]) { 26 time_t build_time = (time_t)ANT_BUILD_TIMESTAMP; 27 time_t now = time(NULL); 28 long diff = (long)difftime(now, build_time); 29 30 struct { long secs; const char *suffix; } units[] = { 31 {86400, "d"}, {3600, "h"}, {60, "m"}, {1, "s"} 32 }; 33 34 const char *suffix = "s"; 35 long value = diff; 36 37 for (size_t i = 0; i < sizeof(units) / sizeof(units[0]); i++) { 38 if (diff >= units[i].secs) { 39 value = diff / units[i].secs; 40 suffix = units[i].suffix; break; 41 } 42 } 43 44 struct tm *tm = gmtime(&build_time); 45 char date_buf[32]; 46 strftime(date_buf, sizeof(date_buf), "%Y-%m-%d", tm); 47 48 #define RED "\033[38;5;197m" 49 #define RESET "\033[0m" 50 51 const char *logo = 52 RED 53 " ___ __ __ _____ _ __\n" 54 " / | ____ / /_ / /___ __ ______ _/ ___/__________(_)___ / /_\n" 55 " / /| | / __ \\/ __/ __ / / __ `/ | / / __ `/\\__ \\/ ___/ ___/ / __ \\/ __/\n" 56 " / ___ |/ / / / /_ / /_/ / /_/ /| |/ / /_/ /___/ / /__/ / / / /_/ / /_\n" 57 "/_/ |_/_/ /_/\\__/ \\____/\\__,_/ |___/\\__,_//____/\\___/_/ /_/ .___/\\__/\n" 58 " /_/" RESET " by @themackabu\n" 59 RESET; 60 61 fputs(logo, stdout); 62 63 printf("%s (released %s, %ld%s ago)\n", 64 ANT_VERSION, 65 date_buf, 66 value, suffix 67 ); 68 69 printf("built for %s\n", ANT_TARGET_TRIPLE); 70 arg_freetable(argtable, ARGTABLE_COUNT); 71 72 return EXIT_SUCCESS; 73}