// main.c // Jedi Academy Server Log Converter - Version 1.1 // // Created By Steven Mattera on August 30th 2010. // Copyright (c) 2010 Steven Mattera // // Jedi Academy Server Log Converter is free software; you can // redistribute it and/or modify it under the terms of the GNU General // Public License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // Jedi Academy Server Log Converter is distributed in the hope that it // will be useful, but WITHOUT ANY WARRENTY; without even the implied // warrenty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more deails. // // You should have received a copy of the GNU General Public License // along with Jedi Academy Server Log Converter; if not, write to the Free // Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 // USA // #include #include #include #include #include FILE * openLogFile(char *path); FILE * openConvFile(char *argv[]); int main(int argc, char *argv[]) { FILE * logFile; FILE * convFile; printf("Jedi Academy Server Log Converter\n"); printf("Copyright (c) 2010 Steven Mattera \n\n"); printf("Jedi Academy Server Log Converter is free software; you can redistribute it\n"); printf("and/or modify it under the terms of the GNU General Public License as published\n"); printf("by the Free Software Foundation; either version 2 of the License, or (at your\n"); printf("option) any later version.\n\n"); printf("Jedi Academy Server Log Converter is distributed in the hope that it will be\n"); printf("useful, but WITHOUT ANY WARRENTY; without even the implied warrenty of \n"); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n"); printf("License for more deails.\n\n"); printf("You should have received a copy of the GNU General Public License along with\n"); printf("Jedi Academy Server Log Converter; if not, write to the Free Software\n"); printf("Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\n"); if(argc != 2) { printf("Usage: JALOG_CONV.EXE \n"); system("pause"); return -1; } logFile = openLogFile(argv[1]); if (logFile == NULL) return -1; convFile = openConvFile(argv); if (convFile == NULL) return -1; fputs("", convFile); char * line; char * lineProcessing; char * convLine; size_t currentPosition; int color = 7; while(!feof(logFile)) { line = (char *)malloc(sizeof(char)*512); memset(line, '\0', sizeof(char)*512); fgets(line, 512, logFile); if(color != 7) { fputs("", convFile); color = 7; } int n; for (n = 0; n < strlen(line); n++) { if(line[n] == '^') { switch (atoi(&line[n+1])) { case 1: if(color != 1) { color = 1; fputs("", convFile); } break; case 2: if(color != 2) { color = 2; fputs("", convFile); } break; case 3: if(color != 3) { color = 3; fputs("", convFile); } break; case 4: if(color != 4) { color = 4; fputs("", convFile); } break; case 5: if(color != 5) { color = 5; fputs("", convFile); } break; case 6: if(color != 6) { color = 6; fputs("", convFile); } break; case 7: if(color != 7) { color = 7; fputs("", convFile); } break; case 0: if(color != 8) { color = 8; fputs("", convFile); } break; default: fputc('^', convFile); fputc(line[n+1], convFile); break; } n++; } else if (line[n] == ':' && color != 7) { fputs("", convFile); fputc(':', convFile); } else if (line[n] == '\\' && color != 7) { fputs("", convFile); fputc('\\', convFile); } else if (line[n] == ' ' && line[n+1] == 'k' && line[n+2] == 'i' && line[n+3] == 'l' && line[n+4] == 'l' && line[n+5] == 'e' && line[n+6] == 'd' && line[n+7] == ' ' && color != 7) { fputs("", convFile); fputc(' ', convFile); } else if (line[n] == ' ' && line[n+1] == 'b' && line[n+2] == 'y' && line[n+3] == ' ' && color != 7) { fputs("", convFile); fputc(' ', convFile); } else if (line[n] == '<') { fputs("<", convFile); } else if (line[n] == '>') { fputs(">", convFile); } else if (line[n] == '&') { fputs("&", convFile); } else if (line[n] != '\n' || line[n] != '\r') { fputc(line[n], convFile); } } fputs("
", convFile); free(line); } fputs("", convFile); fclose(convFile); fclose(logFile); return 0; } FILE * openLogFile(char *path) { FILE * logFile = fopen(path, "r"); if(logFile == NULL) { printf("Error: Opening reading stream.\n\n"); system("pause"); return NULL; } return logFile; } FILE * openConvFile(char *argv[]) { char abs_exe_path[MAX_PATH]; char * pch = strrchr(argv[0],'\\'); strncpy(abs_exe_path, argv[0], pch-argv[0]+1); free(pch); char convPath[PATH_MAX]; sprintf(convPath, "%sJALOG_CONV.HTML", abs_exe_path); FILE * convFile = fopen(convPath, "w+"); if(convFile == NULL) { printf("Error: Opening writing stream.\n\n"); system("pause"); return NULL; } return convFile; }