From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:52:39 +0200 Subject: format files --- src/quote.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/quote.c') diff --git a/src/quote.c b/src/quote.c index ef1bf45..0a3efc3 100644 --- a/src/quote.c +++ b/src/quote.c @@ -1,7 +1,8 @@ -#include "stralloc.h" -#include "str.h" #include "quote.h" +#include "str.h" +#include "stralloc.h" + /* quote() encodes a box as per rfc 821 and rfc 822, while trying to do as little quoting as possible. @@ -10,26 +11,24 @@ no special encoding here for bytes above 127. */ static char ok[128] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -,0,7,0,7,7,7,7,7,0,0,7,7,0,7,7,7 ,7,7,7,7,7,7,7,7,7,7,0,0,0,7,0,7 -,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 ,7,7,7,7,7,7,7,7,7,7,7,0,0,0,7,7 -,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 ,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0 -} ; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 7, 0, 7, 7, 7, 7, 7, 0, 0, 7, 7, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 7, 0, 7, + 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0}; -static int doit(stralloc *saout,stralloc *sain) +static int doit(stralloc *saout, stralloc *sain) { char ch; int i; int j; - if (!stralloc_ready(saout,sain->len * 2 + 2)) return 0; + if (!stralloc_ready(saout, sain->len * 2 + 2)) return 0; j = 0; saout->s[j++] = '"'; for (i = 0; i < sain->len; ++i) { ch = sain->s[i]; - if ((ch == '\r') || (ch == '\n') || (ch == '"') || (ch == '\\')) - saout->s[j++] = '\\'; + if ((ch == '\r') || (ch == '\n') || (ch == '"') || (ch == '\\')) saout->s[j++] = '\\'; saout->s[j++] = ch; } saout->s[j++] = '"'; @@ -38,7 +37,7 @@ static int doit(stralloc *saout,stralloc *sain) return 1; } -int quote_need(char *s,unsigned int n) +int quote_need(char *s, unsigned int n) { unsigned char uch; int i; @@ -52,30 +51,30 @@ int quote_need(char *s,unsigned int n) if (s[0] == '.') return 1; if (s[n - 1] == '.') return 1; - for (i = 0; i < n - 1; ++i) - if (s[i] == '.') + for (i = 0; i < n - 1; ++i) + if (s[i] == '.') if (s[i + 1] == '.') return 1; return 0; } -int quote(stralloc *saout,stralloc *sain) +int quote(stralloc *saout, stralloc *sain) { - if (quote_need(sain->s,sain->len)) return doit(saout,sain); - return stralloc_copy(saout,sain); + if (quote_need(sain->s, sain->len)) return doit(saout, sain); + return stralloc_copy(saout, sain); } static stralloc foo = {0}; -int quote2(stralloc *sa,char *s) +int quote2(stralloc *sa, char *s) { int j; - if (!*s) return stralloc_copys(sa,s); - j = str_rchr(s,'@'); - if (!stralloc_copys(&foo,s)) return 0; - if (!s[j]) return quote(sa,&foo); + if (!*s) return stralloc_copys(sa, s); + j = str_rchr(s, '@'); + if (!stralloc_copys(&foo, s)) return 0; + if (!s[j]) return quote(sa, &foo); foo.len = j; - if (!quote(sa,&foo)) return 0; + if (!quote(sa, &foo)) return 0; - return stralloc_cats(sa,s + j); + return stralloc_cats(sa, s + j); } -- cgit v1.2.3