]> Nishi Git Mirror - libw3.git/commitdiff
fixing format
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 26 Jan 2024 04:41:53 +0000 (04:41 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 26 Jan 2024 04:41:53 +0000 (04:41 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@81 d27a3e52-49c5-7645-884c-6793ebffc270

Example/W3B/w3b.c
Library/URL.c
W3Version.h.p

index d88ed8389948d74fccbeaa31763b04c5938d1207..e24c407a6598ea6eaa75b26b6d42ef3bc13bbd64 100644 (file)
@@ -8,24 +8,22 @@
 #include <W3URL.h>
 #include <W3Util.h> /* It has some useful functions, you know */
 
+#include <ctype.h>
+#include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <stdbool.h>
+#include <string.h>
 #include <unistd.h>
 
-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;
                }
index 18e8da9645c7003ac87d1aeda45965ffbb650c3c..7f5d054d14ac53d8d1a8c9c2868db186aa6d8730 100644 (file)
@@ -3,13 +3,13 @@
 
 #include "W3Util.h"
 
-#include <string.h>
-#include <stdio.h>
+#include <stdbool.h>
 #include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
+#include <string.h>
 
-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);
index 1ca713ecd72d67136aa630f378aeecfd122dbc5b..8be5efdfb13f42a0c4ccb3925c7036c4d546a600 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "1.3D" \
+#define LIBW3_VERSION "1.4" \
 SUFFIX
 
 #ifdef __cplusplus