From 1029f61d2301c424e32a6857176d55c7311a44aa Mon Sep 17 00:00:00 2001 From: nishi Date: Fri, 26 Jan 2024 04:41:53 +0000 Subject: [PATCH] fixing format git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@81 d27a3e52-49c5-7645-884c-6793ebffc270 --- Example/W3B/w3b.c | 70 +++++++++++++++++++++++------------------------ Library/URL.c | 34 +++++++++++------------ W3Version.h.p | 2 +- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/Example/W3B/w3b.c b/Example/W3B/w3b.c index d88ed83..e24c407 100644 --- a/Example/W3B/w3b.c +++ b/Example/W3B/w3b.c @@ -8,24 +8,22 @@ #include #include /* It has some useful functions, you know */ +#include +#include #include -#include #include -#include +#include #include -void status_handler(struct W3* w3, int status){ - printf("Response code: %d\n", status); -} +void status_handler(struct W3* w3, int status) { printf("Response code: %d\n", status); } -void data_handler(struct W3* w3, char* data, size_t size){ -} +void data_handler(struct W3* w3, char* data, size_t size) {} -void access_site(const char* url){ +void access_site(const char* url) { struct W3URL* u = W3_Parse_URL(url); - if(u != NULL){ + if(u != NULL) { struct W3* w3 = W3_Create(u->protocol, u->host, u->port); - if(w3 != NULL){ + if(w3 != NULL) { W3_Set_Method(w3, "GET"); W3_Set_Path(w3, u->path); W3_On(w3, "status", (void*)status_handler); @@ -40,15 +38,15 @@ void access_site(const char* url){ int main(int argc, char** argv) { int i; char* url = NULL; - for(i = 1; i < argc; i++){ - if(strcmp(argv[i], "--version") == 0){ + for(i = 1; i < argc; i++) { + if(strcmp(argv[i], "--version") == 0) { printf("LibW3 %s\n", LIBW3_VERSION); return 0; - }else if(argv[i][0] == '-'){ + } else if(argv[i][0] == '-') { fprintf(stderr, "%s: unknown option: %s\n", argv[0], argv[i]); return 1; - }else{ - if(url != NULL){ + } else { + if(url != NULL) { free(url); fprintf(stderr, "%s: garbage argument found\n", argv[0]); return 1; @@ -60,35 +58,35 @@ int main(int argc, char** argv) { int phase = 0; char c = 0; bool acc = false; - if(url != NULL){ + if(url != NULL) { access_site(url); acc = true; } - while(true){ /* Loop */ - if(c != '\n' && c != '\r'){ + while(true) { /* Loop */ + if(c != '\n' && c != '\r') { printf("(O)pen, (Q)uit? "); fflush(stdout); } if(scanf("%c", &c) < 0) break; - switch(tolower(c)){ - case 'q': - goto exitnow; - case 'o': - printf("URL: "); - fflush(stdout); - if(url != NULL) free(url); - url = malloc(2049); - scanf("%s", url); - acc = false; - break; - case '\n': - case '\r': - break; - default: - printf("What do you mean?\n"); - break; + switch(tolower(c)) { + case 'q': + goto exitnow; + case 'o': + printf("URL: "); + fflush(stdout); + if(url != NULL) free(url); + url = malloc(2049); + scanf("%s", url); + acc = false; + break; + case '\n': + case '\r': + break; + default: + printf("What do you mean?\n"); + break; } - if(!acc){ + if(!acc) { access_site(url); acc = true; } diff --git a/Library/URL.c b/Library/URL.c index 18e8da9..7f5d054 100644 --- a/Library/URL.c +++ b/Library/URL.c @@ -3,13 +3,13 @@ #include "W3Util.h" -#include -#include +#include #include +#include #include -#include +#include -struct W3URL* W3_Parse_URL(const char* _url){ +struct W3URL* W3_Parse_URL(const char* _url) { char* url = __W3_Strdup(_url); __W3_Debug("URL", "Parsing URL"); struct W3URL* r = malloc(sizeof(*r)); @@ -17,20 +17,20 @@ struct W3URL* W3_Parse_URL(const char* _url){ r->host = NULL; r->path = NULL; r->port = -1; - if(strlen(url) > 3){ + if(strlen(url) > 3) { int i; bool found = false; - for(i = 0; i < strlen(url) - 3; i++){ - if(url[i] == ':' && url[i + 1] == '/' && url[i + 2] == '/'){ + for(i = 0; i < strlen(url) - 3; i++) { + if(url[i] == ':' && url[i + 1] == '/' && url[i + 2] == '/') { found = true; break; } } - if(!found){ + if(!found) { __W3_Debug("URL", "Failed to parse"); W3_Free_URL(r); r = NULL; - }else{ + } else { url[i] = 0; char* str = malloc(strlen(url) + 64); sprintf(str, "Protocol is %s", url); @@ -40,23 +40,23 @@ struct W3URL* W3_Parse_URL(const char* _url){ i += 3; int start = i; int port_start = -1; - for(; url[i] != 0; i++){ - if(url[i] == '/'){ + for(; url[i] != 0; i++) { + if(url[i] == '/') { r->path = __W3_Strdup(url + i); url[i] = 0; break; - }else if(url[i] == ':'){ + } else if(url[i] == ':') { port_start = i + 1; url[i] = 0; } } - if(port_start != -1){ + if(port_start != -1) { r->port = atoi(url + port_start); } - if(r->port == -1){ - if(strcmp(r->protocol, "http") == 0){ + if(r->port == -1) { + if(strcmp(r->protocol, "http") == 0) { r->port = 80; - }else if(strcmp(r->protocol, "https") == 0){ + } else if(strcmp(r->protocol, "https") == 0) { r->port = 443; } } @@ -79,7 +79,7 @@ struct W3URL* W3_Parse_URL(const char* _url){ return r; } -void W3_Free_URL(struct W3URL* url){ +void W3_Free_URL(struct W3URL* url) { if(url == NULL) return; if(url->protocol != NULL) free(url->protocol); if(url->host != NULL) free(url->host); diff --git a/W3Version.h.p b/W3Version.h.p index 1ca713e..8be5efd 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "1.3D" \ +#define LIBW3_VERSION "1.4" \ SUFFIX #ifdef __cplusplus -- 2.43.0