Created
January 14, 2012 18:20
-
-
Save mcfiredrill/1612335 to your computer and use it in GitHub Desktop.
frowneyface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
char *tag(char *dest, char* tag, char* closing_tag){ | |
char *out = malloc(1024); | |
printf("dest:%s\n",dest); | |
out = strncat(out, tag, strlen(tag)); | |
out = strncat(out, dest, strlen(dest)); | |
out = strncat(out, closing_tag, strlen(closing_tag)); | |
printf("out:%s\n",out); | |
return out; | |
} | |
char *do_wakabamark(char *input){ | |
char *output = malloc(1024); | |
char *temp = malloc(1024); | |
int i = 0; | |
int em_flag = 0, bold_flag = 0; | |
while(input[i] != '\0'){ | |
if(bold_flag){ | |
if(input[i] == '*'){ | |
if(input[i+1] == '*'){ | |
i++; | |
//bold tag was closed | |
char *s = tag(temp, "<strong>", "</strong>"); | |
strncat(output, s, strlen(s)); | |
bold_flag = 0; | |
}else{ | |
//might be another em_tag | |
em_flag = 1; | |
} | |
}else{ | |
printf("input[i]:%c\n",input[i]); | |
strncat(temp, &input[i], sizeof(input[i])); | |
} | |
}else if(em_flag){ | |
if(input[i] == '*' && input[i+1] != '*'){ | |
char *s = tag(temp, "<em>", "</em>"); | |
strncat(output, s, strlen(s)); | |
em_flag = 0; | |
}else{ | |
printf("input[i]:%c\n",input[i]); | |
strncat(temp, &input[i], sizeof(input[i])); | |
} | |
}else if(input[i] == '*'){ | |
if(input[i+1] == '*'){ | |
bold_flag = 1; | |
i++; | |
}else{ | |
em_flag = 1; | |
} | |
}else{ | |
strncat(output, &input[i], sizeof(input[i])); | |
} | |
i++; | |
} | |
return output; | |
} | |
int main(){ | |
char *string = malloc(1024); | |
char *html; | |
while((string = fgets(string, 1024, stdin))){ | |
printf("hhhhhhhh:%s\n", string); | |
html = do_wakabamark(string); | |
printf("%s\n", html); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment