#include "../rospell/utils.h" static bool get_line(char *ptr) { ASSERT(ptr != 0); while (*ptr != '\0' && *ptr != '\n') ptr++; if (*ptr == '\0') return false; *ptr = '\0'; return true; } static void usage() { printf("Usage: rohtml file\n"); } // scan the line for http links and include the links // if no link found just print the line static void process_http(const char *ptrin) { char *ptr = strstr(ptrin, "http://"); if (ptr == 0) printf("%s\n", ptrin); else { *ptr = '\0'; printf("%s", ptrin); fflush(0); *ptr = 'h'; char *ptr2 = ptr + strlen("http://"); char *ptr3 = ptr2; while (*ptr3 != '\0') { if (*ptr3 == ' ' || *ptr3 == ')' || *ptr3 == '\t') break; ptr3++; } char tmp = *ptr3; *ptr3 = '\0'; printf("%s", ptr, ptr2); fflush(0); *ptr3 = tmp; printf("%s\n", ptr3); } } // process one line of input: // - add blockquotes if the line statrs with ' ' // - add line break if empty line // - add h1 section if line starts wiht '=' // - add h2 section if line starts with '==' static void process_line(const char *ptr) { static bool incode = false; if (incode && *ptr != ' ') { printf("\n"); incode = false; } if (!incode && *ptr == ' ') { printf("
\n%s\n", ptr);
		incode = true;
		return;
	}
	
	if (*ptr == '\0') { // insert 

printf("

\n"); return; } // check for section if (*ptr == '=' && *(ptr + 1) != '=') { // look for the second = sign const char *ptr1 = ptr + 1; while (*ptr1 != '=' && *ptr1 != '\0') ptr1++; if (*ptr1 == '=') { unsigned long len = (unsigned long) ptr1 - (unsigned long) (ptr + 1); char *ptrprint = new char[len + 1]; strncpy(ptrprint, ptr + 1, len); ptrprint[len] = '\0'; printf("

%s

\n", ptrprint); delete[] ptrprint; // process(ptr1 + 1); return; } } // check for sub-section if (*ptr == '=' && *(ptr + 1) == '=' && *(ptr + 2) != '=') { // look for the second = sign const char *ptr1 = ptr + 2; while (*ptr1 != '=' && *ptr1 != '\0') ptr1++; if (*ptr1 == '=' && *(ptr1 + 1) == '=') { unsigned long len = (unsigned long) ptr1 - (unsigned long) (ptr + 2); char *ptrprint = new char[len + 1]; strncpy(ptrprint, ptr + 2, len); ptrprint[len] = '\0'; printf("

%s

\n", ptrprint); delete[] ptrprint; process_line(ptr1 + 2); return; } } process_http(ptr); } int main(int argc, char **argv) { if (argc != 2) { usage(); return 1; } char *strin = UTILS::read_file_malloc(argv[1]); if (strin == 0) { printf("Error: cannot open file %s\n", argv[1]); usage(); return 1; } char *ptr = strin; bool notdone = true; do { notdone = get_line(ptr); process_line(ptr); ptr += strlen(ptr) + 1; } while (notdone); delete[] strin; }