add my .clang-format

This commit is contained in:
Iris Lightshard 2021-04-15 14:44:07 -04:00
parent 836e861d99
commit ff4700df5a
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 58 additions and 28 deletions

23
.clang-format Normal file
View file

@ -0,0 +1,23 @@
TabWidth: 2
IndentWidth: 2
ContinuationIndentWidth: 2
UseTab: Never
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
PenaltyReturnTypeOnItsOwnLine: 255
IndentCaseLabels: true
SpaceBeforeParens: ControlStatements
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false
BinPackArguments: false
PointerAlignment: Left
BreakBeforeBraces: Attach
SortIncludes: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignEscapedNewlines: Left

63
main.c
View file

@ -33,7 +33,7 @@ WITH REGARD TO THIS SOFTWARE.
/* clang-format on */ /* clang-format on */
struct dirent *dir; struct dirent* dir;
typedef struct Lexicon { typedef struct Lexicon {
int len, refs[512]; int len, refs[512];
@ -57,16 +57,16 @@ char *ccat(char *dst, char c) { int len = slen(dst); dst[len] = c; dst[len + 1]
/* clang-format on */ /* clang-format on */
int fpinject(FILE *f, Lexicon *l, char *filepath); int fpinject(FILE* f, Lexicon* l, char* filepath);
int error(char *msg, char *val) { int error(char* msg, char* val) {
printf("Error: %s(%s)\n", msg, val); printf("Error: %s(%s)\n", msg, val);
return 0; return 0;
} }
int ismetanav(char *name) { return scmp(name, "meta.nav"); } int ismetanav(char* name) { return scmp(name, "meta.nav"); }
int findf(Lexicon *l, char *f) { int findf(Lexicon* l, char* f) {
int i; int i;
char filename[64]; char filename[64];
scat(scsw(stlc(scpy(f, filename, 64)), ' ', '_'), ".htm"); scat(scsw(stlc(scpy(f, filename, 64)), ' ', '_'), ".htm");
@ -76,7 +76,7 @@ int findf(Lexicon *l, char *f) {
return -1; return -1;
} }
void fpedited(FILE *f, char *path) { void fpedited(FILE* f, char* path) {
struct stat attr; struct stat attr;
stat(path, &attr); stat(path, &attr);
fputs("<span style='float:right'>", f); fputs("<span style='float:right'>", f);
@ -84,7 +84,7 @@ void fpedited(FILE *f, char *path) {
fputs("</span>", f); fputs("</span>", f);
} }
int fpportal(FILE *f, Lexicon *l, char *s, int head) { int fpportal(FILE* f, Lexicon* l, char* s, int head) {
int target; int target;
char srcpath[64], filename[64]; char srcpath[64], filename[64];
target = findf(l, s); target = findf(l, s);
@ -94,14 +94,18 @@ int fpportal(FILE *f, Lexicon *l, char *s, int head) {
filename[0] = 0; filename[0] = 0;
scat(scat(scat(srcpath, "inc/"), scpy(s, filename, 64)), ".htm"); scat(scat(scat(srcpath, "inc/"), scpy(s, filename, 64)), ".htm");
if (head) if (head)
fprintf(f, "<h2 id='%s'><a href='%s.html'>%s</a></h2>", fprintf(
scsw(filename, ' ', '_'), filename, s); f,
"<h2 id='%s'><a href='%s.html'>%s</a></h2>",
scsw(filename, ' ', '_'),
filename,
s);
fpinject(f, l, srcpath); fpinject(f, l, srcpath);
l->refs[target]++; l->refs[target]++;
return 1; return 1;
} }
int fptemplate(FILE *f, Lexicon *l, char *s) { int fptemplate(FILE* f, Lexicon* l, char* s) {
int target; int target;
if (s[0] == '/') if (s[0] == '/')
return fpportal(f, l, s + 1, 1); return fpportal(f, l, s + 1, 1);
@ -114,8 +118,8 @@ int fptemplate(FILE *f, Lexicon *l, char *s) {
return 1; return 1;
} }
int fpinject(FILE *f, Lexicon *l, char *filepath) { int fpinject(FILE* f, Lexicon* l, char* filepath) {
FILE *inc; FILE* inc;
char c, s[1024]; char c, s[1024];
unsigned char t = 0; unsigned char t = 0;
scsw(filepath, ' ', '_'); scsw(filepath, ' ', '_');
@ -145,26 +149,28 @@ int fpinject(FILE *f, Lexicon *l, char *filepath) {
return 1; return 1;
} }
FILE *build(FILE *f, Lexicon *l, char *name, char *srcpath) { FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
if (!f) if (!f)
return f; return f;
/* begin */ /* begin */
fputs("<!DOCTYPE html><html lang='en'>", f); fputs("<!DOCTYPE html><html lang='en'>", f);
fputs("<head>", f); fputs("<head>", f);
fprintf(f, fprintf(
"<meta charset='utf-8'>" f,
"<meta name='description' content='%s'/>" "<meta charset='utf-8'>"
"<meta name='viewport' content='width=device-width,initial-scale=1'>", "<meta name='description' content='%s'/>"
"lair of drkste aka nilix: programmer, artist, philosopher"); "<meta name='viewport' content='width=device-width,initial-scale=1'>",
"lair of drkste aka nilix: programmer, artist, philosopher");
if (ismetanav(name)) { if (ismetanav(name)) {
fputs("<link rel='stylesheet' type='text/css' href='" FRONTCSS "'>", f); fputs("<link rel='stylesheet' type='text/css' href='" FRONTCSS "'>", f);
} else { } else {
fputs("<link rel='stylesheet' type='text/css' href='" MAINCSS "'>", f); fputs("<link rel='stylesheet' type='text/css' href='" MAINCSS "'>", f);
} }
fprintf(f, fprintf(
"<link rel='shortcut icon' href='/favicon.ico'>" f,
"<title>" NAME " &mdash; %s</title>", "<link rel='shortcut icon' href='/favicon.ico'>"
name); "<title>" NAME " &mdash; %s</title>",
name);
fputs("</head>", f); fputs("</head>", f);
fputs("<body>", f); fputs("<body>", f);
/* header */ /* header */
@ -196,8 +202,9 @@ FILE *build(FILE *f, Lexicon *l, char *name, char *srcpath) {
/* footer */ /* footer */
fputs("<footer>", f); fputs("<footer>", f);
fpedited(f, srcpath); fpedited(f, srcpath);
fputs("contact: <a href='mailto://drkste@zoho.com'>drkste@zoho.com</a> ", fputs(
f); "contact: <a href='mailto://drkste@zoho.com'>drkste@zoho.com</a> ",
f);
fputs("(<a href='keys.html'>keys</a>)", f); fputs("(<a href='keys.html'>keys</a>)", f);
/* fputs("<a href='" LICENSE "' target='_blank'>BY-NC-SA 4.0</a>", f) */; /* fputs("<a href='" LICENSE "' target='_blank'>BY-NC-SA 4.0</a>", f) */;
fputs("</footer>", f); fputs("</footer>", f);
@ -207,7 +214,7 @@ FILE *build(FILE *f, Lexicon *l, char *name, char *srcpath) {
return f; return f;
} }
int generate(Lexicon *l) { int generate(Lexicon* l) {
int i = 0; int i = 0;
char srcpath[64], dstpath[64], filename[64]; char srcpath[64], dstpath[64], filename[64];
for (i = 0; i < l->len; ++i) { for (i = 0; i < l->len; ++i) {
@ -234,7 +241,7 @@ int generate(Lexicon *l) {
return 1; return 1;
} }
int index(Lexicon *l, DIR *d) { int index(Lexicon* l, DIR* d) {
while ((dir = readdir(d))) while ((dir = readdir(d)))
if (ssin(dir->d_name, ".htm") > 0) { if (ssin(dir->d_name, ".htm") > 0) {
l->refs[l->len] = 0; l->refs[l->len] = 0;
@ -245,7 +252,7 @@ int index(Lexicon *l, DIR *d) {
return 1; return 1;
} }
void inspect(Lexicon *l) { void inspect(Lexicon* l) {
int i; int i;
for (i = 0; i < l->len; ++i) for (i = 0; i < l->len; ++i)
if (!l->refs[i]) if (!l->refs[i])
@ -254,7 +261,7 @@ void inspect(Lexicon *l) {
int main(void) { int main(void) {
Lexicon lex; Lexicon lex;
DIR *d; DIR* d;
lex.len = 0; lex.len = 0;
if (!(d = opendir("inc"))) if (!(d = opendir("inc")))
return error("Open", "Missing inc/ folder. "); return error("Open", "Missing inc/ folder. ");