/* * DVISVG section */ #include #include #include #include "xmlsvg.h" #include "dstypes.h" #include "version.h" /* used in dvipage.c */ int sel_page = 1; int main(int argc, char **argv) { FILE *dvi_inp, *svg_out, *log_out; char log_out_name[MAXFILENAME]; char svg_out_name[MAXFILENAME]; char svgfontfile[MAXFILENAME]; char cnf_dir[MAXPATH]; int opt_c; int opt_ind = 0; struct option long_options[] = { {"version", 0, 0, 0}, {"help", 0, 0, 1}, {0, 0, 0, 0} }; const char *help_str = "Usage: dvisvg [OPTIONS] file[.dvi]\n\n" " -o FILE\tFILE name for SVG output, default out.svg\n" " -O FILE\tFILE name for LOG output, default out.log\n" " -f FILE\tFILE name for SVG Fonts output, default fonts.svg\n" " -t\t\ttry generate new TFM files by mktextfm, default\n" " -d LEVEL\tset debug level\n" " -p PAGE\tselects page in DVI for output, default first\n\n" " -c DIR\tconfig files directory DIR,\n\t\tdefault %s\n\n" " --help\tdisplay help and exit\n" " --version\toutput version and exit\n\n"; const char *vers_str = "DVISVG version %s\n" "http://dvisvg.sourceforge.net\n" "Copyright (c) 2004, 2005 Rudolf Sabo\n"; int debug = 0; strcpy(log_out_name, "out.log"); strcpy(svg_out_name, "out.svg"); strcpy(cnf_dir, CNFDIR); strcpy(svgfontfile, "fonts.svg"); /* * ARGUMENTS */ while ((opt_c = getopt_long(argc, argv, "p:o:O:d:f:c:", long_options, &opt_ind)) != EOF) { switch (opt_c) { case 0: printf(vers_str, DVISVGVER); return 201; break; case 1: printf(help_str, CNFDIR); return 202; break; case 'p': printf("Page: %s\n", optarg); sel_page = atoi(optarg); break; case 'o': printf("SVG output is now: %s\n", optarg); strcpy(svg_out_name, optarg); break; case 'O': printf("LOG output is now: %s\n", optarg); strcpy(log_out_name, optarg); break; case 'c': printf("CNF DIR is now: %s\n", optarg); strcpy(cnf_dir, optarg); break; case 'f': printf("SVG Font is now: %s\n", optarg); strcpy(svgfontfile, optarg); break; case 'd': printf("DEBUG on level:\n", optarg); debug = atoi(optarg); break; case '?': return 204; break; } } printf("This is DVISVG version %s\n", DVISVGVER); if (optind < argc) { if(strstr(argv[optind], ".dvi") == NULL) strcat(argv[optind], ".dvi"); } else { printf(help_str, CNFDIR); return 205; } /* * INPUT & OUTPUT */ if((dvi_inp = fopen(argv[optind],"r")) == NULL) { printf("%s: File %s doesn't exists.\n", argv[0], argv[optind]); return 10; } if((log_out = fopen(log_out_name,"w")) == NULL) { printf("%s: Can not open %s as output file.\n", argv[0], log_out_name); return 30; } if((svg_out = fopen(svg_out_name,"w")) == NULL) { printf("%s: Can not open %s as output file.\n", argv[0], svg_out_name); return 50; } printf("Opening files: %s (r) %s %s (w).\n", argv[optind], log_out_name, svg_out_name); /* * SVG OUTPUT */ fprintf(svg_out, xml_pro, XMLVER, XMLENC); fprintf(svg_out, svg_gen, DVISVGVER); /* * DVI base */ if(fseek(dvi_inp, 0, SEEK_SET) != 0) { printf("\nCan not seek dvi file\n"); return 11; } switch(dvibase(svgfontfile, dvi_inp, svg_out, log_out)) { case 12: printf("\nCan not find DVI_POST_POST.\n"); return 12; break; case 13: printf("\nCan not find DVI_POST.\n"); return 13; break; case 14: printf("\nError in DVI: FNT_DEF_i.\n"); return 14; break; case 15: printf("\nCan not find DVI_PRE.\n"); return 15; break; case 16: printf("Error in DVI: DVI_BOP.\n"); return 16; break; } /* * DVI page */ dvipage(dvi_inp, cnf_dir, svgfontfile, svg_out, log_out); /* * INPUT & OUTPUT */ fclose(dvi_inp); fclose(svg_out); fclose(log_out); return 0; } /* * DVISVG section * vim:ts=4: */