#define PROGRAM "mkhtml" #define VERSION "0.0.1-2" #include #include char filename[256] = "mkhtml.html"; char *filenames[256] = { "mkhtml.html" }; int files = 1; /* getopt Section */ struct option mkhtml_options[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'v' }, { "nocss", 0, NULL, 0 }, { "noscr", 0, NULL, 0 }, { "emptytags", 0, NULL, 'e' }, { "notitle", 0, NULL, 0 }, { "nometa", 0, NULL, 0 }, { "output", 1, NULL, 'o' }, { "ofile", 1, NULL, 'o' } }; int o_help=0, o_version=0, o_nocss=0, o_noscr=0, o_emptytags=0, o_nometa=0, o_notitle=0; int option, option_idx; int parse_options(int argc, char *argv[]) { option_idx = 0; opterr = 0; /* getopt.h */ while (1) { option = getopt_long(argc, argv, "hveo", mkhtml_options, &option_idx); if (option == EOF) break; switch(option) { case 'e' : o_emptytags=1; break; case 'v' : o_version=1; break; case 'h' : o_help=1; break; case 'o' : if (optarg) strcpy(filename, optarg); break; case 0 : if (!strcmp(mkhtml_options[option_idx].name, "nocss")) o_nocss=1; else if (!strcmp(mkhtml_options[option_idx].name, "noscr")) o_noscr=1; else if (!strcmp(mkhtml_options[option_idx].name, "nometa")) o_nometa=1; else if (!strcmp(mkhtml_options[option_idx].name, "notitle")) o_notitle=1; break; case '?': fprintf(stdout, "unknown option"); break; case ':': fprintf(stdout, "invalid option"); break; default: break; } } return 1; } /* helper Section */ int version() { fprintf(stdout, "%s\n", VERSION); return 0; } int help(char *arg0) { fprintf(stdout, "\n" PROGRAM " " VERSION "\n" "usage: %s [options] filenames\n" "where options are some of the following\n" "\n" "--help -h show help\n" "--version -v show version number\n" "--nocss - no css\n" "--noscr - no javascript\n" "--emptytags -e with all tags, but without their contents...\n" "--nometa - to turn of meta tag explicit\n" "--notitle - to leave out title tag\n" "\n" "--output filename - output to filename (default mkhtml.html)\n" "\n", arg0 ); return 0; } /* mkhtml Section */ FILE *document; char *HTML_OPEN = "\n"; char *HTML_CLOSE = "\n"; char *HEAD_OPEN = "\t\n"; char *HEAD_CLOSE = "\t\n"; char *SCRIPT_OPEN = "\t\n"; char *CSS_OPEN = "\t\n"; char *BODY_OPEN = "\t\n"; char *BODY_CLOSE = "\t\n"; char *TITLE = "\t\t\n"; char *META = "\t\t\n"; char *CSS_CONTENT = "\t\tbody {\n" "\t\t\tbackground:\n" "\t\t\tcolor:\n" "\t\t\tfont-size:\n" "\t\t\tfont-family:\n" "\t\t\tmargin:\n" "\t\t\tpadding:\n" "\t\t\t\n" "\t\t\t\n" "\t\t\t\n" "\t\t}\n" "\t\ta:hover {\n" "\t\t\tbackground:\n" "\t\t\tcolor:\n" "\t\t\t\n" "\t\t}\n" "\t\ta:active, link, visited {\n" "\t\t\tbackground:\n" "\t\t\tcolor:\n" "\t\t\t\n" "\t\t}\n" "\t\t/* temp {\n" "\t\t\tbackground:\n" "\t\t\tcolor:\n" "\t\t\tfont-size:\n" "\t\t\tfont-family:\n" "\t\t\tmargin:\n" "\t\t\tpadding:\n" "\t\t\tborder-style:\n" "\t\t\tborder-width:\n" "\t\t} */\n"; /* "\t\t \n" "\t\t\t\n" "\t\t\t\n" "\t\t\t\n" "\t\t \n" */ char *CSS_CONTENT_B = "\n"; char *BODY_CONTENT = "\n"; char *BODY_CONTENT_B = "\t\t
zurück
\n"; char *SCRIPT_CONTENT = "\t\twindow.status=\"empty page generated with mkhtml\";\n"; char *SCRIPT_CONTENT_B = "\n"; int write_string_to_disk(char *str) { fputs(str,document); } int write_document(char *doc) { /* generate the html document */ fprintf(stdout, "wrting: %s...", doc); document=fopen(doc, "w"); write_string_to_disk(HTML_OPEN); write_string_to_disk(HEAD_OPEN); if (!o_notitle) write_string_to_disk(TITLE); if (!o_nometa) write_string_to_disk(META); write_string_to_disk(HEAD_CLOSE); if (!o_nocss) { write_string_to_disk(CSS_OPEN); if (!o_emptytags) write_string_to_disk(CSS_CONTENT); write_string_to_disk(CSS_CLOSE); } if (!o_noscr) { write_string_to_disk(SCRIPT_OPEN); if (!o_emptytags) write_string_to_disk(SCRIPT_CONTENT); write_string_to_disk(SCRIPT_CLOSE); } write_string_to_disk(BODY_OPEN); if (!o_emptytags) write_string_to_disk(BODY_CONTENT); if (!o_emptytags) write_string_to_disk(BODY_CONTENT_B); write_string_to_disk(BODY_CLOSE); write_string_to_disk(HTML_CLOSE); fclose(document); fprintf(stdout, "written!\n"); } /* Main */ int main(int argc, char *argv[]) { int i; parse_options(argc,argv); if (o_help) { return help(argv[0]); } else if (o_version) { return version(); } else write_document(filename); return 1; }