Last active
October 12, 2022 16:06
-
-
Save hello-smile6/8d253230bb00077ea519d44d185ae797 to your computer and use it in GitHub Desktop.
errno markdown generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include "startswith.h" | |
int main() { | |
// Start the markdown table | |
printf("|Number|description|\n|----|----|\n"); | |
int i; | |
for (i = -1000; i < 1000; ++i) | |
{ | |
char *errdesc = strerror(i); | |
// Don't log unknown errors | |
if(startsWith(errdesc, "Unknown error ")) { | |
continue; | |
} | |
// Log as a table, so you can send the output to a .md file and open it | |
printf("|%d|%s|\n", i, errdesc); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: default run clean | |
default: generate | |
generate: generate.o | |
gcc -o generate generate.o | |
generate.o: generate.c startswith.h | |
gcc -c -o generate.o generate.c | |
run: generate | |
./generate | |
clean: | |
rm *.o generate test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://stackoverflow.com/a/15515276/14639867 | |
bool startsWith(const char *a, const char *b) | |
{ | |
if(strncmp(a, b, strlen(b)) == 0) return 1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment