]> Nishi Git Mirror - libw3.git/commitdiff
W3_Tag_Attr
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Tue, 30 Jan 2024 01:00:38 +0000 (01:00 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Tue, 30 Jan 2024 01:00:38 +0000 (01:00 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@135 d27a3e52-49c5-7645-884c-6793ebffc270

Example/w3b/w3b.c
Library/Tag.c
Library/W3Tag.h
W3Version.h.p

index e8e320b4d0a2af34d55097cffa0c33e380394e44..92f9092582d92f0e4b8458737bdcc0a4e59a6535 100644 (file)
@@ -176,7 +176,15 @@ void html_handler(char* tagname, char* attr) {
                if(nl >= start) printf("\n");
                nl++;
        } else if(strcasecmp(tagname, "img") == 0) {
-               if(nl >= start) printf("[IMG]");
+               if(nl >= start){
+                       char* alt = W3_Tag_Attr(attr, "alt");
+                       if(alt != NULL){
+                               printf("[%s]", alt);
+                               free(alt);
+                       }else{
+                               printf("[IMG]");
+                       }
+               }
        } else if(strcasecmp(tagname, "hr") == 0) {
                int i;
                if(nl >= start) printf("\n ");
@@ -325,7 +333,7 @@ int main(int argc, char** argv) {
                        printf("? ");
                        fflush(stdout);
                }
-               if(scanf("%c", &c) < 0) break;
+               if((c = getchar()) == EOF) break;
                switch(tolower(c)) {
                case 'q':
                        goto exitnow;
@@ -339,7 +347,7 @@ int main(int argc, char** argv) {
                        break;
                case 'd':
                        rendered = false;
-                       start++;
+                       start += termh;
                        break;
                case '\n':
                case '\r':
index 96658e3d0605f00a5aca31bc67af6a81017722b2..30226007e253204843f192a87d881991dd307b31 100644 (file)
@@ -70,3 +70,54 @@ void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char*
        free(tagn);
        free(cbuf);
 }
+
+char* W3_Tag_Attr(char* data, const char* name){
+       char* ret = NULL;
+       int i;
+       int phase = 0;
+       char* cbuf = malloc(2);
+       cbuf[1] = 0;
+       char* key = malloc(1);
+       key[0] = 0;
+       bool dq = false;
+       for(i = 0;; i++){
+               cbuf[0] = data[i];
+               if(phase == 0 && data[i] != 0 && data[i] != '='){
+                       char* tmp = key;
+                       key = __W3_Concat(tmp, cbuf);
+                       free(tmp);
+               }else if(phase == 0){
+                       phase = 2;
+                       if(strcasecmp(key, name) == 0) phase = 1;
+                       free(key);
+                       key = malloc(1);
+                       key[0] = 0;
+                       if(data[i] == 0) break;
+               }else if(phase == 1 && (dq ? dq : (data[i] != 0 && data[i] != ' '))){
+                       if(data[i] == '"'){
+                               dq = !dq;
+                       }else{
+                               if(ret == NULL){
+                                       ret = malloc(1);
+                                       ret[0] = 0;
+                               }
+                               char* tmp = ret;
+                               ret = __W3_Concat(tmp, cbuf);
+                               free(tmp);
+                       }
+               }else if(phase == 1){
+                       phase = 0;
+                       break;
+               }else if(phase == 2 && (dq ? dq : (data[i] != 0 && data[i] != ' '))){
+                       if(data[i] == '"'){
+                               dq = !dq;
+                       }
+               }else if(phase == 2){
+                       phase = 0;
+                       if(data[i] == 0) break;
+               }
+       }
+       free(key);
+       free(cbuf);
+       return ret;
+}
index 06035ba7966d85b0253b2041b78b4585a0865f0c..4c46fb041524ef46dc5fdc061d34ff7b7b1c132e 100644 (file)
@@ -5,5 +5,6 @@
 #include <stddef.h>
 
 void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char* attr), void (*textfunc)(char* data));
+char* W3_Tag_Attr(char* data, const char* name);
 
 #endif
index 7ebe7915a3ee7cb5aef1fd416ae21c238326abcb..67aab335b7d091a5954ed4ee7b95b60801d0a729 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "2.1B" \
+#define LIBW3_VERSION "2.2" \
 SUFFIX
 
 #ifdef __cplusplus