diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-11 18:13:26 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-11 18:13:26 -0400 |
| commit | 9ca7c88d7c56b4bdbf2380ffeb663d700404ea35 (patch) | |
| tree | c7d10efab48e325c5d007a1017cfaad24de721e6 /ws2a | |
| parent | b9976f40a6a13b0dd8462183ff40a21634789cb8 (diff) | |
| download | webpage-9ca7c88d7c56b4bdbf2380ffeb663d700404ea35.tar.gz webpage-9ca7c88d7c56b4bdbf2380ffeb663d700404ea35.tar.bz2 webpage-9ca7c88d7c56b4bdbf2380ffeb663d700404ea35.zip | |
Modifications to butcomment so it can accept newlines
Diffstat (limited to 'ws2a')
| -rw-r--r-- | ws2a/bugcomment.c | 8 | ||||
| -rw-r--r-- | ws2a/testhtmlreplace.c | 37 |
2 files changed, 35 insertions, 10 deletions
diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c index eeba8fe..6464314 100644 --- a/ws2a/bugcomment.c +++ b/ws2a/bugcomment.c @@ -24,6 +24,14 @@ char* replaceHTML(char* str){ int hex; sscanf(str+strp,"%%%x",&hex); //printf("Was:%c\n",(char)hex); + if(hex == 0x0D) continue; + if(hex == 0x0A){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; + continue; + } nstr[nstrp] = (char)hex; nstrp++; strp+=3; diff --git a/ws2a/testhtmlreplace.c b/ws2a/testhtmlreplace.c index 56bd5cd..6ac6f90 100644 --- a/ws2a/testhtmlreplace.c +++ b/ws2a/testhtmlreplace.c @@ -3,29 +3,43 @@ #include <stdlib.h> #include <stdint.h> -void replaceHTML(char* str){ - printf("Replaceing:%s\n",str); +char* replaceHTML(char* str){ + //printf("Replaceing:%s\n",str); char* nstr = malloc((sizeof(char)*strlen(str)) + 1); if(nstr == NULL){ + printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); printf("Failed to allocate memory!\n"); } int strp = 0; int nstrp = 0; while(str[strp] != '\0'){ - printf("Strp=%d nstrp=%d\n",strp,nstrp); + //printf("Strp=%d nstrp=%d\n",strp,nstrp); if(str[strp] == '+'){ nstr[nstrp] = ' '; strp++; nstrp++; }else if(str[strp] == '%'){ - printf("Hit encodeing!\n"); + //printf("Hit encodeing!\n"); int hex; sscanf(str+strp,"%%%x",&hex); - printf("Was:%c\n",(char)hex); + //printf("Was:%c\n",(char)hex); + if(hex == 0x0D) continue; + if(hex == 0x0A){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; + continue; + } nstr[nstrp] = (char)hex; nstrp++; strp+=3; + }else if(str[strp] == '\n'){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; }else{ nstr[nstrp] = str[strp]; nstrp++; @@ -33,7 +47,8 @@ void replaceHTML(char* str){ } } nstr[nstrp] = '\0'; - printf("Done, str is now:%s\n",nstr); + //printf("Done, str is now:%s\n",nstr); + return nstr; } char* useridhash(char* str){ @@ -67,9 +82,11 @@ char* useridhash(char* str){ } int main(){ - char teststring[] = "This+is+a+test"; - useridhash(teststring); - char teststring2[] = "This+is+a+tost"; - useridhash(teststring2); + char teststring[] = "This+is+a+test\nWith\nSome\nNewlines"; + char* parsed = replaceHTML(teststring); + printf("%s\n",parsed); + char teststring2[] = "This+is+another+test"; + char* parsed2 = replaceHTML(teststring2); + printf("%s\n",parsed2); return 0; } |
