// main.cc - Don Yang (uguu.org) // // 05/26/11 #include #include #include #include"load_events.h" #include"write_events.h" #include"util.h" #ifdef _WIN32 #include #define BINMODE(x) setmode(fileno(x), O_BINARY) #else #define BINMODE(x) /* no-op */ #endif // Maximum amount of idle time between events (seconds). This is so that // viewers don't get bored staring at the screen when there is nothing // happening. Empirically, 3 seconds is about as much patience as I got, but // this constant can be changed to an arbitrarily high value if the user wants // the output timestamps to be more faithful to the original recording. static const int kMaxIdleTime = 3; int main(int argc, char **argv) { if( argc == 1 && isatty(fileno(stdin)) ) { printf("%s [input_log.txt] [output.html]\n", *argv); return 1; } // Open input FILE *input; if( argc > 1 && strcmp(argv[1], "-") != 0 ) { if( (input = fopen(argv[1], "rb")) == NULL ) { printf("Error opening %s for reading\n", argv[1]); return 1; } } else { input = stdin; BINMODE(stdin); } // Open output FILE *output; if( argc > 2 ) { if( (output = fopen(argv[2], "wb+")) == NULL ) { printf("Error opening %s for writing\n", argv[2]); return 1; } } else { output = stdout; BINMODE(stdout); } // Translate events AllEvents events; events.Load(input); if( input != stdin ) fclose(input); events.CompressIdleTime(kMaxIdleTime); events.CompileEvents(); // Write output const Animation animation(events.compiled_events(), events.max_file_size(), events.GetSlotCount()); animation.Write(output); // Cleanup if( output != stdout ) fclose(output); return 0; }