home | blog | art | now | git gpg | email | rss

sopen

Suckless mimeopen alternative
git clone git://pollux.codes/git/sopen.git
Log | Files | Refs | README | LICENSE
commit 661bbceeea493ddca8d2d549bd60ee85cd064363
parent cb38a512f2d901e827d452b75d497307dae3907d
Author: Pollux <pollux@pollux.codes>
Date:   Mon, 10 Feb 2025 22:17:26 -0600

style: Format code

Signed-off-by: Pollux <pollux@pollux.codes>

Diffstat:
Msopen.c | 76+++++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/sopen.c b/sopen.c @@ -13,17 +13,17 @@ #define REGEX_URL "^(([a-z]*)://(.*)/)?(.*)$" typedef struct { - const char* protocol_regex; - const char* url_regex; - const char* mime_regex; - const char* file_regex; - const char* program; + const char *protocol_regex; + const char *url_regex; + const char *mime_regex; + const char *file_regex; + const char *program; } Rule; #include "config.h" int -main(int argc, const char** argv) { +main(int argc, const char **argv) { int res; @@ -32,17 +32,17 @@ main(int argc, const char** argv) { regex_t has_protocol; regex_t regex_url; - regex_t protocol_regex; - regex_t url_regex; - regex_t mime_regex; - regex_t file_regex; + regex_t protocol_regex; + regex_t url_regex; + regex_t mime_regex; + regex_t file_regex; - regmatch_t match[8]; + regmatch_t match[8]; - const char *url; - const char *mime_type; + const char *url; + const char *mime_type; - char* child_args[3]; + char *child_args[3]; char fragment[128]; @@ -56,47 +56,56 @@ main(int argc, const char** argv) { url = argv[1]; res = regcomp(&has_protocol, REGEX_PROTOCOL, REG_EXTENDED); - if(res > 0) goto error; + if(res > 0) + goto error; res = regcomp(&regex_url, REGEX_URL, REG_EXTENDED); - if(res > 0) goto error; + if(res > 0) + goto error; mime_type = ""; res = regexec(&has_protocol, url, 0, NULL, 0); - if(res > 0) mime_type = magic_file(cookie, url); + if(res > 0) + mime_type = magic_file(cookie, url); - for(int n = 0; n < sizeof(rules)/sizeof(Rule); n++) { + for(int n = 0; n < sizeof(rules) / sizeof(Rule); n++) { - res = regcomp(&protocol_regex, rules[n].protocol_regex, REG_EXTENDED); + res = regcomp(&protocol_regex, rules[n].protocol_regex, + REG_EXTENDED); if(res > 0) { - printf("Failed to compile protocol regex: %s\n", rules[n].protocol_regex); + printf("Failed to compile protocol regex: %s\n", + rules[n].protocol_regex); goto error; } res = regcomp(&url_regex, rules[n].url_regex, REG_EXTENDED); if(res > 0) { - printf("Failed to compile url regex: %s\n", rules[n].url_regex); + printf("Failed to compile url regex: %s\n", + rules[n].url_regex); goto error; } res = regcomp(&mime_regex, rules[n].mime_regex, REG_EXTENDED); if(res > 0) { - printf("Failed to compile mime regex: %s\n", rules[n].mime_regex); + printf("Failed to compile mime regex: %s\n", + rules[n].mime_regex); goto error; } res = regcomp(&file_regex, rules[n].file_regex, REG_EXTENDED); if(res > 0) { - printf("Failed to compile file regex: %s\n", rules[n].file_regex); + printf("Failed to compile file regex: %s\n", + rules[n].file_regex); goto error; } - res = regexec(&regex_url, url, regex_url.re_nsub+1, match, 0); - if (res > 0) { + res = regexec(&regex_url, url, regex_url.re_nsub + 1, match, 0); + if(res > 0) { printf("Wat..."); goto error; } - memcpy(fragment, &url[match[2].rm_so], match[2].rm_eo-match[2].rm_so); - fragment[match[2].rm_eo-match[2].rm_so] = '\0'; + memcpy(fragment, &url[match[2].rm_so], + match[2].rm_eo - match[2].rm_so); + fragment[match[2].rm_eo - match[2].rm_so] = '\0'; res = regexec(&protocol_regex, fragment, 0, NULL, 0); if(res > 0) { @@ -107,15 +116,16 @@ main(int argc, const char** argv) { if(res > 0) { continue; } - + res = regexec(&mime_regex, mime_type, 0, NULL, 0); if(res > 0) { continue; } - memcpy(fragment, &url[match[4].rm_so], match[4].rm_eo-match[4].rm_so); - fragment[match[4].rm_eo-match[4].rm_so] = '\0'; - + memcpy(fragment, &url[match[4].rm_so], + match[4].rm_eo - match[4].rm_so); + fragment[match[4].rm_eo - match[4].rm_so] = '\0'; + res = regexec(&file_regex, fragment, 0, NULL, 0); if(res > 0) { continue; @@ -123,8 +133,8 @@ main(int argc, const char** argv) { printf("Match: %s\n", rules[n].program); - child_args[0] = (char*)rules[n].program; - child_args[1] = (char*)url; + child_args[0] = (char *)rules[n].program; + child_args[1] = (char *)url; child_args[2] = NULL; execvp(rules[n].program, child_args);