aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneauoire <aliceffekt@gmail.com>2020-11-29 14:31:22 -0800
committerneauoire <aliceffekt@gmail.com>2020-11-29 14:31:22 -0800
commit40615974cc12dd055c664339c8d782dbcab723dc (patch)
tree4bf1f89beedbef0f9cb2a18d7362dc19f3829f6e
parentc1cc3205ce63ecb44082f8f14d83ad0bf95e3fd3 (diff)
Improved C tool
-rw-r--r--.gitignore2
-rw-r--r--tools/.clang-format76
-rwxr-xr-xtools/build.sh4
-rw-r--r--tools/themes.c84
4 files changed, 54 insertions, 112 deletions
diff --git a/.gitignore b/.gitignore
index 5ca0973..8a8a657 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
.DS_Store
-
+tools/themes
diff --git a/tools/.clang-format b/tools/.clang-format
index 5ca25b8..67c9a1b 100644
--- a/tools/.clang-format
+++ b/tools/.clang-format
@@ -1,65 +1,19 @@
----
-Language: Cpp
-# BasedOnStyle: LLVM
-AccessModifierOffset: -2
-AlignAfterOpenBracket: true
-AlignEscapedNewlinesLeft: false
-AlignOperands: true
-AlignTrailingComments: false
-AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
-AllowShortCaseLabelsOnASingleLine: false
+AlignAfterOpenBracket: DontAlign
+AlignEscapedNewlines: DontAlign
+AllowShortBlocksOnASingleLine: Empty
+AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
-AlwaysBreakAfterDefinitionReturnType: true
-AlwaysBreakTemplateDeclarations: false
-AlwaysBreakBeforeMultilineStrings: false
-BreakBeforeBinaryOperators: None
-BreakBeforeTernaryOperators: true
-BreakConstructorInitializersBeforeComma: false
-BinPackParameters: true
-BinPackArguments: true
-ColumnLimit: 0
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
-ConstructorInitializerIndentWidth: 4
-DerivePointerAlignment: false
-ExperimentalAutoDetectBinPacking: false
+AlwaysBreakAfterDefinitionReturnType: TopLevel
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBraces: WebKit
IndentCaseLabels: false
-IndentWrappedFunctionNames: false
-IndentFunctionDeclarationAfterType: false
-MaxEmptyLinesToKeep: 1
-KeepEmptyLinesAtTheStartOfBlocks: true
-NamespaceIndentation: None
-ObjCBlockIndentWidth: 2
-ObjCSpaceAfterProperty: false
-ObjCSpaceBeforeProtocolList: true
-PenaltyBreakBeforeFirstCallParameter: 19
-PenaltyBreakComment: 300
-PenaltyBreakString: 1000
-PenaltyBreakFirstLessLess: 120
-PenaltyExcessCharacter: 1000000
-PenaltyReturnTypeOnItsOwnLine: 60
-PointerAlignment: Left
-SpacesBeforeTrailingComments: 1
-Cpp11BracedListStyle: true
-Standard: Cpp11
-IndentWidth: 8
-TabWidth: 8
-UseTab: ForIndentation
-BreakBeforeBraces: Linux
-SortIncludes: false
-SpacesInParentheses: false
-SpacesInSquareBrackets: false
-SpacesInAngles: false
-SpaceInEmptyParentheses: false
-SpacesInCStyleCastParentheses: false
-SpaceAfterCStyleCast: false
-SpacesInContainerLiterals: true
-SpaceBeforeAssignmentOperators: true
+TabWidth: 4
+IndentWidth: 4
ContinuationIndentWidth: 4
-CommentPragmas: '^ IWYU pragma:'
-ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
-SpaceBeforeParens: Never
-DisableFormat: false
-...
+UseTab: ForContinuationAndIndentation
+ColumnLimit: 0
+ReflowComments: false
+SortIncludes: false
+SpaceBeforeParens: false \ No newline at end of file
diff --git a/tools/build.sh b/tools/build.sh
index a9ed3bc..2c73ddf 100755
--- a/tools/build.sh
+++ b/tools/build.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+rm -f ./themes
+
clang-format -i themes.c
# Linux
@@ -8,5 +10,3 @@ cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werr
# ./themes ../themes/apollo.svg
cat ../themes/apollo.svg | ./themes
-
-rm ./themes
diff --git a/tools/themes.c b/tools/themes.c
index 69145c3..0c5ba73 100644
--- a/tools/themes.c
+++ b/tools/themes.c
@@ -1,37 +1,15 @@
#include <stdio.h>
-#define BUFLEN 256
-
-int
-slen(char* s)
-{
- int n = 0;
- while(s[n] != '\0' && s[++n])
- ;
- return n;
-}
-
int
-cpos(char* s, char c)
+cpos(char *s, char c)
{
- int i;
- for(i = 0; i < slen(s); i++)
- if(s[i] == c)
- return i;
+ int i = 0;
+ while(s[i])
+ if(s[i++] == c)
+ return i - 1;
return -1;
}
-char*
-sstr(char* src, char* dest, int from, int to)
-{
- int i;
- char *a = (char*)src + from, *b = (char*)dest;
- for(i = 0; i < to; i++)
- b[i] = a[i];
- dest[to] = '\0';
- return dest;
-}
-
unsigned char
chex(char c)
{
@@ -42,49 +20,59 @@ chex(char c)
return (c - '0') & 0xF;
}
-unsigned long
-shex(char* s)
+int
+shex(char *s, int len)
{
- int i, n = 0, l = slen(s);
- for(i = 0; i < l; ++i)
- n |= (chex(s[i]) << ((l - i - 1) * 4));
+ int i, n = 0;
+ for(i = 0; i < len; ++i)
+ n |= (chex(s[i]) << ((len - i - 1) * 4));
return n;
}
+char *
+sstr(char *src, char *dst, int from, int to)
+{
+ int i;
+ char *a = (char *)src + from, *b = (char *)dst;
+ for(i = 0; i < to; i++)
+ b[i] = a[i];
+ dst[to] = '\0';
+ return dst;
+}
+
int
-error(char* name)
+error(char *name)
{
printf("Error: %s\n", name);
return 0;
}
int
-parse(FILE* f)
+parse(FILE *f)
{
int i, id = 0;
long theme[9];
- char line[BUFLEN], hexs[BUFLEN];
- while(fgets(line, BUFLEN, f)) {
+ char line[256], hexs[9][7];
+ while(fgets(line, 256, f)) {
int split = cpos(line, '#');
- if(split < 0 || id > 9)
- continue;
- sstr(line, hexs, split, 7);
- printf("%s ", hexs);
- theme[id] = shex(hexs + 1);
- id++;
+ if(split >= 0) {
+ sstr(line + split + 1, hexs[id], 0, 6);
+ theme[id++] = shex(line + split + 1, 6);
+ }
+ if(id >= 9)
+ break;
}
if(id != 9)
return error("Invalid theme");
- for(i = 0; i < 9; ++i) {
- printf("%ld ", theme[i]);
- }
+ for(i = 0; i < 9; ++i)
+ printf("#%s = %ld\n", hexs[i], theme[i]);
return 1;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- FILE* input;
+ FILE *input;
if(argc == 2) {
input = fopen(argv[1], "rb");
if(input == NULL)
@@ -92,4 +80,4 @@ main(int argc, char* argv[])
} else
input = stdin;
return parse(input);
-} \ No newline at end of file
+}