aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-08-28 16:05:30 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-08-28 16:05:30 -0700
commitf8860c385ee35e50c716e2119131103fdb6fd70e (patch)
tree3f45681dbf519285680c421cdf14ee13d7059100 /utils.c
parentd44806f746b22311a04e45a80a9281d4f4f3a71d (diff)
Style change: added cino=:0 (i.e. case statements on same indentation as
switch). Also fixed issue where $$ would fail to match with trailing newline on file
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/utils.c b/utils.c
index cb0719c..47958f7 100644
--- a/utils.c
+++ b/utils.c
@@ -20,18 +20,18 @@ const char *after_spaces(const char *str, bool skip_nl)
// Skip whitespace and comments:
skip_whitespace:
switch (*str) {
- case '\r': case '\n':
- if (!skip_nl) break;
- __attribute__ ((fallthrough));
- case ' ': case '\t': {
- ++str;
- goto skip_whitespace;
- }
- case '#': {
- while (*str && *str != '\n') ++str;
- goto skip_whitespace;
- }
- default: break;
+ case '\r': case '\n':
+ if (!skip_nl) break;
+ __attribute__ ((fallthrough));
+ case ' ': case '\t': {
+ ++str;
+ goto skip_whitespace;
+ }
+ case '#': {
+ while (*str && *str != '\n') ++str;
+ goto skip_whitespace;
+ }
+ default: break;
}
return str;
}
@@ -90,39 +90,38 @@ char unescapechar(const char *escaped, const char **end)
size_t len = 1;
unsigned char ret = (unsigned char)*escaped;
switch (*escaped) {
- case 'a': ret = '\a'; break; case 'b': ret = '\b'; break;
- case 'n': ret = '\n'; break; case 'r': ret = '\r'; break;
- case 't': ret = '\t'; break; case 'v': ret = '\v'; break;
- case 'e': ret = '\033'; break; case '\\': ret = '\\'; break;
- case 'x': { // Hex
- static const unsigned char hextable[255] = {
- ['0']=0x10, ['1']=0x1, ['2']=0x2, ['3']=0x3, ['4']=0x4,
- ['5']=0x5, ['6']=0x6, ['7']=0x7, ['8']=0x8, ['9']=0x9,
- ['a']=0xa, ['b']=0xb, ['c']=0xc, ['d']=0xd, ['e']=0xe, ['f']=0xf,
- ['A']=0xa, ['B']=0xb, ['C']=0xc, ['D']=0xd, ['E']=0xe, ['F']=0xf,
- };
- if (hextable[(int)escaped[1]] && hextable[(int)escaped[2]]) {
- ret = (hextable[(int)escaped[1]] << 4) | (hextable[(int)escaped[2]] & 0xF);
- len = 3;
- }
- break;
+ case 'a': ret = '\a'; break; case 'b': ret = '\b'; break;
+ case 'n': ret = '\n'; break; case 'r': ret = '\r'; break;
+ case 't': ret = '\t'; break; case 'v': ret = '\v'; break;
+ case 'e': ret = '\033'; break; case '\\': ret = '\\'; break;
+ case 'x': { // Hex
+ static const unsigned char hextable[255] = {
+ ['0']=0x10, ['1']=0x1, ['2']=0x2, ['3']=0x3, ['4']=0x4,
+ ['5']=0x5, ['6']=0x6, ['7']=0x7, ['8']=0x8, ['9']=0x9,
+ ['a']=0xa, ['b']=0xb, ['c']=0xc, ['d']=0xd, ['e']=0xe, ['f']=0xf,
+ ['A']=0xa, ['B']=0xb, ['C']=0xc, ['D']=0xd, ['E']=0xe, ['F']=0xf,
+ };
+ if (hextable[(int)escaped[1]] && hextable[(int)escaped[2]]) {
+ ret = (hextable[(int)escaped[1]] << 4) | (hextable[(int)escaped[2]] & 0xF);
+ len = 3;
}
- case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { // Octal
- ret = (unsigned char)(escaped[0] - '0');
- if ('0' <= escaped[1] && escaped[1] <= '7') {
+ break;
+ }
+ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { // Octal
+ ret = (unsigned char)(escaped[0] - '0');
+ if ('0' <= escaped[1] && escaped[1] <= '7') {
+ ++len;
+ ret = (ret << 3) | (escaped[1] - '0');
+ if ('0' <= escaped[2] && escaped[2] <= '7') {
++len;
- ret = (ret << 3) | (escaped[1] - '0');
- if ('0' <= escaped[2] && escaped[2] <= '7') {
- ++len;
- ret = (ret << 3) | (escaped[2] - '0');
- }
+ ret = (ret << 3) | (escaped[2] - '0');
}
- break;
- }
- default: {
- if (end) *end = escaped;
- return (char)0;
}
+ break;
+ }
+ default:
+ if (end) *end = escaped;
+ return (char)0;
}
if (end) *end = &escaped[len];
return (char)ret;
@@ -151,4 +150,4 @@ void delete(void *p)
*((void**)p) = NULL;
}
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0