/* * Copyright (c) 2004 Chirok Han * * This file is part of fig2pstricks. * * Fig2pstricks 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. * * Fig2pstricks is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with fig2pstricks; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact: beanerjo@yahoo.com */ #include "version.h" #include "fig2pstricks.h" #include "helpmsgs.h" #include "chars.h" int going = -1, ndots = 0; int math_label=0; int resolution=1200; int y_boundary; STYLE prev_style; int custom_color_equiv[MAXCOLOR]; int global_depth; int math_mode = 0; int latex_symbols = 0; int pkgs_needed[4] = {0,0,0,0}; double def_unit = 1.0; double def_scale = 0.8; void print_depth_help(FILE *fp, char *appname) { fprintf(fp, depth_help, appname, appname, XFIG_SPECIAL, appname, XFIG_DEPTH); } void print_help(FILE *fp, char *appname) { fprintf(fp, general_help, appname, appname); } void print_version(FILE *fp, char *appname, char *version) { fprintf(fp, "%s %s\n", appname, version); } void error_exit(char *fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); exit(-1); } void proc_spec(FILE *fp, char *p) { fprintf(stderr, "proc_spec( , %s)\n", p); } void check_next_arg1(char *opt, int i, int argc, char *next_arg, char **ptr) { if (i0 && strcmp(p,"cm")){ error = 1; } return error; } int get_unit(double *xunit, double *yunit, char *ptr) { double ux, uy; char *p, *where_comma; int ncomma; int error = 0; if (!ptr) { ux=def_unit; uy=def_unit; } else { p = ptr; ncomma = 0; while (*p) { if (*p==',') { ncomma++; where_comma=p; } p++; } if (ncomma==0) { error = get_one_unit(&ux, ptr); if (!error) { if (ux<=0.0) { fprintf(stderr, "Invalid unit in %s. Use default (%g) instead.\n", ptr, def_unit); ux = def_unit; } uy = ux; } } else if (ncomma==1) { *where_comma='\0'; error = get_one_unit(&ux, ptr); *where_comma=','; if (!error) { if (ux<=0.0) { fprintf(stderr, "Invalid x unit in %s. Use default (%g) instead.\n", ptr, def_unit); ux = def_unit; } if (!(error=get_one_unit(&uy, where_comma+1))) { if (uy<=0.0) { fprintf(stderr, "Invalid y unit in %s. Use default (%g) instead.\n", ptr, def_unit); uy = def_unit; } } } } else { error = 1; } } *xunit = ux; *yunit = uy; return error; } int get_scale(double *xscale, double *yscale, char *ptr) { double sx, sy; char *p, *where_comma; int ncomma; int error; if (!ptr) { sx=def_scale; sy=def_scale; } else { p = ptr; ncomma = 0; while (*p) { if (*p==',') { ncomma++; where_comma=p; } p++; } if (ncomma==0) { error = get_one_scale(&sx, ptr); if (!error) { if (sx<=0.0) { fprintf(stderr, "Invalid scale in %s. Use default (%g) instead.\n", ptr, def_scale); sx = def_scale; } sy = sx; } } else if (ncomma==1) { *where_comma='\0'; error = get_one_scale(&sx, ptr); *where_comma=','; if (!error) { if (sx<=0.0) { fprintf(stderr, "Invalid x scale in %s. Use default (%g) instead.\n", ptr, def_scale); sx = def_scale; } if (!(error=get_one_scale(&sy, where_comma+1))) { if (sy<=0.0) { fprintf(stderr, "Invalid y scale in %s. Use default (%g) instead.\n", ptr, def_scale); sy = def_scale; } } } } else { error = 1; } } *xscale = sx; *yscale = sy; return error; } int _debug = 0; int main(int argc, char *argv[]) { char *pszFileIn=NULL, *pszFileOut=NULL, *pszUnit=NULL, *pszScale=NULL, *pszPadding=NULL, *pszTitle=NULL, *pszFormat=NULL; char *src; FILE *fin, *fout; char *p, *q, *endptr; char buf[MAXSIZE+1], tok1[MAXSIZE+1], tok2[MAXSIZE+1]; int i, id, pageno=0, coord=1, end_flag; int complete = 0, usedot = 0, prosper=0, obey_specials=1; int depth, prev_depth, ndepths, empty_page=0; long fpos, tmpl; double xunit, yunit, xscale=-1.0, yscale=-1.0; double padding=0.5; double mag; int ctbl[MAXCOLOR]; int xmin=100000, xmax=-100000, ymin=100000, ymax=-100000; STREAM *sp; NODE node; global_depth = -1; // command line options for (i=1; i=0 && obey_specials) depth=global_depth; prev_depth = depth; if (*(sp->curpos)) { *(sp->curpos)='\0'; sp->curpos++; } else { end_flag = 1; } if (node) append_node(node, depth, p); else node = create_node(depth, p); } if (_debug) fprintf(fout, "%%%% global_depth: %d\n", global_depth); proc_colortbl(fout, ctbl); if (pkgs_needed[1] || pkgs_needed[2] || pkgs_needed[3]) { if (complete) { fprintf(fout, "\n%%%% Extra packages to handle texts:\n"); for (i=1; i<4; i++) if (pkgs_needed[i]) fprintf(fout, "%s\n", _pkg_needed[i]); } else { fprintf(fout, "%%%% Include the following in the preamble:\n"); for (i=1; i<4; i++) if (pkgs_needed[i]) fprintf(fout, "%%%% %s\n", _pkg_needed[i]); fprintf(fout, "%%%% End\n"); } } if (complete) fprintf(fout, "\n\\begin{document}\n"); y_boundary = ymin+ymax; ndepths = sort_by_depth(&node); //print_node(node); if (prosper) { if (ndepths>1 && global_depth>-1) fprintf(fout, "\n\\overlays{%d}{\n", ndepths); fprintf(fout, "\\begin{slide}{%s}", pszTitle?pszTitle:""); } //printf("padding: %f -> ", padding); padding *= (double)resolution/2.45; //printf("%f\n", padding); fprintf(fout, "\n\\begin{pspicture}"); fprint_xy_cm4(fout, (int)((xmin-padding)*xunit), (int)((ymax+padding)*yunit), (int)((y_boundary+0*padding)*yunit)); fprint_xy_cm4(fout, (int)((xmax+padding)*xunit), (int)((ymin-padding)*yunit), (int)((y_boundary+0*padding)*yunit)); fputc('\n', fout); if (xunit==yunit) fprintf(fout, "\\psset{unit=%gcm}", xunit); else fprintf(fout, "\\psset{xunit=%gcm,yunit=%gcm}", xunit, yunit); trewind(sp); init_style(&prev_style); prev_depth = -1; depth = 0; while (1) { trelink(sp, node->ptr, 0); if (prev_depth!=node->depth) { fprintf(fout, "\n%%%%\n%%%% Depth: %d\n%%%%", node->depth); prev_depth=node->depth; if (node->depth!=INT_MAX) depth++; if (prosper && global_depth>-1 && depth>1) fprintf(fout, "\n\\FromSlide{%d}", depth); } id = tscani(sp); switch(id) { case OBJ_COLOR: if (_debug) fprintf(fout, "%%%% COLOR\n"); proc_color(fout, sp); break; case OBJ_ELLIPSE: if (_debug) fprintf(fout, "%%%% ELLIPSE\n"); if (usedot) proc_ellipse_dot(fout, sp); else proc_ellipse(fout, sp); break; case OBJ_POLYLINE: if (_debug) fprintf(fout, "%%%% POLYLINE\n"); proc_polyline(fout, sp); break; case OBJ_SPLINE: if (_debug) fprintf(fout, "%%%% SPLINE\n"); proc_spline(fout, sp); break; case OBJ_TEXT: if (_debug) fprintf(fout, "%%%% TEXT\n"); proc_text(fout, sp); break; case OBJ_ARC: if (_debug) fprintf(fout, "%%%% ARC\n"); proc_arc(fout, sp); break; case OBJ_COMPOUND: if (_debug) fprintf(fout, "%%%% COMPOUND\n"); proc_compound(fout, sp); break; default: twindup(sp); break; } going = id; if (node==node->next) break; else node=node->next; } tclose(sp); free(src); fprintf(fout, "\n\\end{pspicture}\n"); texcomment(fout, "End"); if (prosper) { fprintf(fout, "\\end{slide}"); if (ndepths>1 && global_depth>-1) fputc('}', fout); fputc('\n', fout); } if (empty_page) { if (complete) { fprintf(fout, "\\thispagestyle{empty}\n"); } else { fprintf(fout, "%%%% \\thispagestyle{empty}\n"); } } if (complete) { fprintf(fout, "\\end{document}\n"); } // Close files delete_node(node); if (fout!=stdout) fclose(fout); if (!complete) { if (pkgs_needed[1] || pkgs_needed[2] || pkgs_needed[3]) { printf("%%%% Include the following in the preamble (before \\begin{document}):\n"); for (i=1; i<4; i++) if (pkgs_needed[i]) printf("%%%% %s\n", _pkg_needed[i]); } } return 0; }