diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/banned.h | 67 | ||||
| -rw-r--r-- | include/cla_parse.h | 26 | ||||
| -rw-r--r-- | include/pkgit_globals.h | 79 | ||||
| -rw-r--r-- | include/pkgit_string.h | 43 |
4 files changed, 205 insertions, 10 deletions
diff --git a/include/banned.h b/include/banned.h new file mode 100644 index 0000000..3ea7dd4 --- /dev/null +++ b/include/banned.h @@ -0,0 +1,67 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_BANNED_H +#define PKGIT_BANNED_H + +/* + * This header lists functions that have been banned from our code base, + * because they're too easy to misuse (and even if used correctly, + * complicate audits). Including this header turns them into compile-time + * errors. + */ + +#define BANNED(func) sorry_##func##_is_a_banned_function + +#undef strcpy +#define strcpy(x,y) BANNED(strcpy) +#undef strcat +#define strcat(x,y) BANNED(strcat) +#undef strncpy +#define strncpy(x,y,n) BANNED(strncpy) +#undef strncat +#define strncat(x,y,n) BANNED(strncat) +#undef strtok +#define strtok(x,y) BANNED(strtok) +#undef strtok_r +#define strtok_r(x,y,z) BANNED(strtok_r) + +#undef sprintf +#undef vsprintf +#define sprintf(...) BANNED(sprintf) +#define vsprintf(...) BANNED(vsprintf) + +#undef gmtime +#define gmtime(t) BANNED(gmtime) +#undef localtime +#define localtime(t) BANNED(localtime) +#undef ctime +#define ctime(t) BANNED(ctime) +#undef ctime_r +#define ctime_r(t, buf) BANNED(ctime_r) +#undef asctime +#define asctime(t) BANNED(asctime) +#undef asctime_r +#define asctime_r(t, buf) BANNED(asctime_r) + +#undef mktemp +#define mktemp(x) BANNED(mktemp) + +#endif /* BANNED_H */ diff --git a/include/cla_parse.h b/include/cla_parse.h new file mode 100644 index 0000000..eca1395 --- /dev/null +++ b/include/cla_parse.h @@ -0,0 +1,26 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_CLA_PARSE_H +#define PKGIT_CLA_PARSE_H + +void cla_parse(int argc, char **argv); + +#endif
\ No newline at end of file diff --git a/include/pkgit_globals.h b/include/pkgit_globals.h new file mode 100644 index 0000000..b1e76ed --- /dev/null +++ b/include/pkgit_globals.h @@ -0,0 +1,79 @@ +#ifndef PKGIT_GLOBALS_H +#define PKGIT_GLOBALS_H +#include "pkgit_string.h" + +typedef struct { + str_slc name; + str_slc url; + str_slc version; + str_slc target; + str_slc src; + int is_local; +} package; + +#define VERSION slc_from_cstr("1.4.0_INDEV") +#define RED slc_from_cstr("\x1b[0;31m") +#define GREEN slc_from_cstr("\x1b[0;32m") +#define YELLOW slc_from_cstr("\x1b[0;33m") +#define BLUE slc_from_cstr("\x1b[0;34m") +#define MAGENTA slc_from_cstr("\x1b[0;35m") +#define CYAN slc_from_cstr("\x1b[0;36m") +#define GRAY slc_from_cstr("\x1b[0;37m") +#define BRIGHT_RED slc_from_cstr("\x1b[0;91m") +#define BRIGHT_GREEN slc_from_cstr("\x1b[0;92m") +#define BRIGHT_YELLOW slc_from_cstr("\x1b[0;93m") +#define BRIGHT_BLUE slc_from_cstr("\x1b[0;94m") +#define BRIGHT_MAGENTA slc_from_cstr("\x1b[0;95m") +#define BRIGHT_CYAN slc_from_cstr("\x1b[0;96m") +#define BRIGHT_GRAY slc_from_cstr("\x1b[0;97m") +#define BOLD_RED slc_from_cstr("\x1b[1;31m") +#define BOLD_GREEN slc_from_cstr("\x1b[1;32m") +#define BOLD_YELLOW slc_from_cstr("\x1b[1;33m") +#define BOLD_BLUE slc_from_cstr("\x1b[1;34m") +#define BOLD_MAGENTA slc_from_cstr("\x1b[1;35m") +#define BOLD_CYAN slc_from_cstr("\x1b[1;36m") +#define BOLD_GRAY slc_from_cstr("\x1b[1;37m") +#define BOLD_WHITE slc_from_cstr("\x1b[1;38m") +#define BOLD_BRIGHT_RED slc_from_cstr("\x1b[1;91m") +#define BOLD_BRIGHT_GREEN slc_from_cstr("\x1b[1;92m") +#define BOLD_BRIGHT_YELLOW slc_from_cstr("\x1b[1;93m") +#define BOLD_BRIGHT_BLUE slc_from_cstr("\x1b[1;94m") +#define BOLD_BRIGHT_MAGENTA slc_from_cstr("\x1b[1;95m") +#define BOLD_BRIGHT_CYAN slc_from_cstr("\x1b[1;96m") +#define BOLD_BRIGHT_GRAY slc_from_cstr("\x1b[1;97m") +#define ITALIC slc_from_cstr("\x1b[3m") +#define COLOR_RESET slc_from_cstr("\x1b[0m") + +#define STR_BUFFER slc_from_cstr("") + +#define PRINT_PKGIT slc_cat( \ + slc_cat( \ + slc_cat(BOLD_YELLOW, slc_from_cstr("[")), \ + slc_cat(BOLD_MAGENTA, slc_from_cstr("pkgit")), \ + &STR_BUFFER \ + ), slc_cat( \ + slc_cat(BOLD_MAGENTA, slc_from_cstr("]")), \ + COLOR_RESET, &STR_BUFFER \ + ), &STR_BUFFER \ +) +#define PRINT_SUCCESS slc_cat( \ + slc_cat(PRINT_PKGIT, GREEN), \ + slc_cat(slc_from_cstr(" [SUCCESS]"), COLOR_RESET) \ +) +#define PRINT_SKIPPED slc_cat( \ + slc_cat(PRINT_PKGIT, BLUE), \ + slc_cat(slc_from_cstr(" [SKIPPED]"), COLOR_RESET) \ +) +#define PRINT_WARNING slc_cat( \ + slc_cat(PRINT_PKGIT, YELLOW), \ + slc_cat(slc_from_cstr(" [WARNING]"), COLOR_RESET) \ +) +#define PRINT_ERROR slc_cat( \ + slc_cat(PRINT_PKGIT, RED), \ + slc_cat(slc_from_cstr(" [ERROR]"), COLOR_RESET) \ +) + +extern int is_verbose; +extern int is_forced; + +#endif diff --git a/include/pkgit_string.h b/include/pkgit_string.h index ae6098c..c81bcbd 100644 --- a/include/pkgit_string.h +++ b/include/pkgit_string.h @@ -1,3 +1,23 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #ifndef PKGIT_STRING_H #define PKGIT_STRING_H #include <stddef.h> @@ -5,7 +25,7 @@ typedef struct { char* data; size_t len; -} str_s; +} str_slc; typedef struct { char* data; @@ -13,15 +33,18 @@ typedef struct { size_t len; } str; -#define format_string(s) (int)((s).len), (s).data -// Usage: printf("%.*s", format_string(ss)); +#define str_fmt(slice) (int)((slice).len), (slice).data +// Usage: printf("%.*s", format_string(slice)); -void print_slice(str_s s); -str_s slice_from_cstr(char* cstr); -int slice_eq(str_s a, str_s b); -int slice_starts_with(str_s slice, str_s prefix); -str_s slice_take(str_s slice, size_t n); -str_s slice_drop(str_s slice, size_t n); -str_s slice_trim(str_s slice); +void print_slice(str_slc s); +str_slc slc_from_cstr(char* cstr); +#define slc_from_cstr(cstr) slc_from_cstr(cstr) +int slc_eq(str_slc a, str_slc b); +int slc_starts_with(str_slc slice, str_slc prefix); +str_slc slc_take(str_slc slice, size_t n); +str_slc slc_drop(str_slc slice, size_t n); +str_slc slc_trim(str_slc slice); +void slc_cat(str_slc first, str_slc second, str_slc *new_slc); +//#define slc_cat(first, second, new_slc) slc_cat(first, second, *new_slc) #endif |
