universe@55: /* universe@55: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@55: * universe@55: * Copyright 2016 Mike Becker. All rights reserved. universe@55: * universe@55: * Redistribution and use in source and binary forms, with or without universe@55: * modification, are permitted provided that the following conditions are met: universe@55: * universe@55: * 1. Redistributions of source code must retain the above copyright universe@55: * notice, this list of conditions and the following disclaimer. universe@55: * universe@55: * 2. Redistributions in binary form must reproduce the above copyright universe@55: * notice, this list of conditions and the following disclaimer in the universe@55: * documentation and/or other materials provided with the distribution. universe@55: * universe@55: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@55: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@55: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@55: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@55: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@55: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@55: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@55: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@55: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@55: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@55: * POSSIBILITY OF SUCH DAMAGE. universe@55: * universe@55: */ universe@55: universe@55: #include universe@55: #include universe@55: #include universe@55: #include universe@55: universe@55: #include "c2html.h" universe@61: #include universe@55: universe@55: #define FILEBUF_SIZE 4096 universe@55: universe@55: typedef struct { universe@55: char* outfilename; universe@55: char* headerfile; universe@55: char* footerfile; universe@55: char* infilename; universe@55: int showlinenumbers; universe@55: } Settings; universe@55: universe@55: static int appendfile(const char *filename, FILE *fout, universe@55: char *copybuf, size_t copybuflen, const char *errmsg) { universe@55: FILE *headerfile = fopen(filename, "r"); universe@55: if (!headerfile) { universe@55: perror(errmsg); universe@55: if (fout != stdout) { universe@55: fclose(fout); universe@55: } universe@55: return 1; universe@55: } universe@61: ucx_stream_bncopy(headerfile, fout, universe@55: (read_func) fread, (write_func) fwrite, universe@55: copybuf, copybuflen, (size_t)-1); universe@55: fclose(headerfile); universe@55: return 0; universe@55: } universe@55: universe@55: static void printhelp() { universe@55: printf("Formats source code using HTML.\n\nUsage:\n" universe@55: " c2html [Options] FILE\n\n" universe@55: " Options:\n" universe@55: " -h Prints this help message\n" universe@55: " -j Highlight Java instead of C source code\n" universe@55: " -o Output file (stdout, if not specified)\n" universe@55: " -H
Prepend header file\n" universe@55: " -F