home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / d_ps.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  16KB  |  600 lines

  1. /*--------------------------------------------------------------*/
  2. /*    Post Script Driver, for GLE V3.0             */
  3. /*--------------------------------------------------------------*/
  4.  
  5. /*---------------------------------------------------------------------------*/
  6. #include "all.h"
  7.  
  8. #include <math.h>
  9. #include "core.h"
  10. #include "mygraph.h"
  11. #include "mydev.h"
  12. char *fontdir(char *s);
  13. extern int MAX_VECTOR; /* Cant send POSTSCRIPT too complex a path */
  14. static int ps_nvec;
  15.  
  16. extern int control_d;
  17. extern int dev_eps;
  18. extern struct gmodel g;
  19. /*---------------------------------------------------------------------------*/
  20. #define pi 3.141592653
  21. #define false 0
  22. #define true (!false)
  23. extern int BLACKANDWHITE;
  24. #define dbg if ((gle_debug & 64)>0)
  25. extern int gle_debug;
  26. char *font_getname(int i);
  27. /*---------------------------------------------------------------------------*/
  28. /* The global variables that CORE keeps track of */
  29. /*-----------------------------------------------*/
  30.  
  31.     FILE *psfile;
  32.     int i,l,j;
  33.  
  34. colortyp g_cur_fill,g_cur_color;
  35.  
  36. /*---------------------------------------------------------------------------*/
  37. d_dfont(char *c)
  38. {
  39.     /* only used for the DFONT driver which builds fonts */
  40. }
  41. /*---------------------------------------------------------------------------*/
  42. d_tidyup()
  43. {}
  44. d_message(char *s)
  45. {
  46. #ifdef unix
  47.     printw("%s\n",s);
  48. #else
  49.     printf("%s\n",s);
  50. #endif
  51. }
  52. /*---------------------------------------------------------------------------*/
  53. d_devcmd(char *s)
  54. {
  55.     fprintf(psfile,"%s",s);
  56. }
  57. d_source(char *s)
  58. {
  59.     dbg fprintf(psfile,"%% SOURCE, %s",s);
  60. }
  61. /*---------------------------------------------------------------------------*/
  62. d_get_type(char *t)
  63. {
  64.     strcpy(t,"HARDCOPY, PS, FILLPATH");
  65.     if (dev_eps) strcat(t,", EPS,");
  66. }
  67. /*---------------------------------------------------------------------------*/
  68. d_set_path(int onoff)
  69. {
  70. }
  71. /*---------------------------------------------------------------------------*/
  72. d_newpath()
  73. {
  74.     fprintf(psfile," newpath ");
  75.     ps_nvec = 0;
  76. }
  77. /*---------------------------------------------------------------------------*/
  78. extern char output_file[];
  79. extern char input_file[];
  80. d_open(double width, double height)
  81. {
  82.     char *outfile;
  83.     char *s;
  84.     char outfileb[90] = "out.ps";
  85.  
  86.     outfile = &outfileb[0];
  87.     s = strrchr(input_file,'.');
  88.     if (s!=NULL) {
  89.         strcpy(outfile,input_file);
  90.         s = strrchr(outfile,'.');
  91.         if (dev_eps) strcpy(s,".eps");
  92.         else strcpy(s,".ps");
  93.     }
  94.     if (output_file[0]!=0) outfile = &output_file[0];
  95.     psfile = fopen(outfile,"w");
  96.     if (psfile == NULL) { perror("PS open file GLE_OUTPUT: ") ; exit(2); }
  97.  
  98. #ifdef __TURBOC__
  99.     printf("\n Writing output to file (%s) \n",outfile);
  100. #endif
  101.     if (!dev_eps) {
  102.         if (control_d) fprintf(psfile,"\x04 \n");
  103.         fprintf(psfile,"%%!PS-Adobe-1.0 \n");
  104.     } else {
  105.         fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0 \n");
  106.     }
  107.     fprintf(psfile,"%%%%BoundingBox: -1 -1 %g %g \n",72*width/2.54+1,72*height/2.54+1);
  108.     fprintf(psfile,"%%%%EndComments \n");
  109.     fprintf(psfile,"%%%%EndProlog \n");
  110.     fprintf(psfile,"gsave \n");
  111.     fprintf(psfile," \n");
  112.     fprintf(psfile,"/f {findfont exch scalefont setfont} bind def \n");
  113.     fprintf(psfile,"/s {show} bind def \n");
  114.     fprintf(psfile,"/ps {true charpath} bind def \n");
  115.     fprintf(psfile,"/l {lineto} bind def \n");
  116.     fprintf(psfile,"/m {newpath moveto} bind def \n");
  117.     fprintf(psfile,"matrix currentmatrix /originmat exch def \n");
  118.     fprintf(psfile,"/umatrix {originmat matrix concatmatrix setmatrix} def \n");
  119.     fprintf(psfile," \n");
  120. }
  121. /*---------------------------------------------------------------------------*/
  122. d_close()
  123. {
  124.     g_flush();
  125.     fprintf(psfile,"showpage \n");
  126.     fprintf(psfile,"grestore \n");
  127.     fprintf(psfile,"%%%%Trailer \n");
  128.     if (!dev_eps) if (control_d) fprintf(psfile,"\x04 \n");
  129.     fclose(psfile);
  130. }
  131. /*---------------------------------------------------------------------------*/
  132. d_set_line_cap(int i)
  133. {
  134.     /*  lcap, 0= butt, 1=round, 2=projecting square */
  135.     if (!g.inpath) g_flush();
  136.     fprintf(psfile,"%d setlinecap \n",i);
  137. }
  138. /*---------------------------------------------------------------------------*/
  139. d_set_line_join(int i)
  140. {
  141.     if (!g.inpath) g_flush();
  142.     fprintf(psfile,"%d setlinejoin \n",i);
  143. }
  144. /*---------------------------------------------------------------------------*/
  145. d_set_line_miterlimit(double d)
  146. {
  147.     if (!g.inpath) g_flush();
  148.     fprintf(psfile,"%g setmiterlimit \n",d);
  149. }
  150. /*---------------------------------------------------------------------------*/
  151. d_set_line_width(double w)
  152. {
  153.     if (w==0) w = 0.02;
  154.     if (w<.0002) w = 0;
  155.     if (!g.inpath) g_flush();
  156.     fprintf(psfile,"%g setlinewidth \n",w);
  157. }
  158. /*---------------------------------------------------------------------------*/
  159. d_set_line_styled(double dd)
  160. {}
  161. d_set_line_style(char *s)
  162. {
  163.     /* should deal with [] for solid lines */
  164.     static char *defline[] = {"","","12","41","14","92","1282"
  165.     ,"9229","4114","54","73","7337","6261","2514"};
  166.     static char ob[200];
  167.     int l;
  168.  
  169.     if (!g.inpath) g_flush();
  170.     strcpy(ob,"[");
  171.     if (strlen(s)==1) s = defline[*s-'0'];
  172.     l = strlen(s);
  173.     for (i=0;i<l;i++)
  174.         sprintf(ob+strlen(ob),"%g ",(*(s+i)-'0')*g.lstyled);
  175.     strcat(ob,"]");
  176.     fprintf(psfile,"%s 0 setdash \n",ob);
  177. }
  178. /*---------------------------------------------------------------------------*/
  179. d_fill()
  180. {
  181.     fprintf(psfile,"gsave \n");
  182.     ddfill();
  183.     fprintf(psfile,"grestore \n");
  184. }
  185. ddfill()
  186. {
  187.     if (g_cur_fill.b[B_F] == 255) return; /* clear fill, do nothing */
  188.     if (g_cur_fill.b[B_F] == 2) {d_shade(); return;}
  189.     set_fill();            /*because color and fill are the same*/
  190.     fprintf(psfile,"fill \n");
  191.     set_color();
  192. }
  193. d_shade()
  194. {
  195.     double x,y,step1,step2;
  196.     fprintf(psfile,"gsave \n");
  197.     fprintf(psfile,"clip \n");
  198.     fprintf(psfile,"newpath  \n");
  199.     fprintf(psfile,"0 setgray \n");
  200.     step1 = g_cur_fill.b[B_B]/160.0;
  201.     step2 = g_cur_fill.b[B_G]/160.0;
  202.  
  203.     fprintf(psfile,"%g setlinewidth\n",(double) g_cur_fill.b[B_R]/160.0);
  204.     if (step1>0) {
  205.       fprintf(psfile,"%g %g %g { /x exch def \n",-40.0,step1,40.0);
  206.       fprintf(psfile,"x 0 moveto 40 x add 40 lineto stroke\n");
  207.       fprintf(psfile,"} for \n");
  208.     }
  209.     if (step2>0) {
  210.      fprintf(psfile,"%g %g %g { /x exch def \n",0.0,step2,80.0);
  211.      fprintf(psfile,"x 0 moveto -40 x add 40 lineto stroke\n");
  212.      fprintf(psfile,"} for \n");
  213.     }
  214.     fprintf(psfile,"grestore \n");
  215. /*    d_set_line_width(g.lwidth); */
  216. }
  217. /*---------------------------------------------------------------------------*/
  218. d_fill_ary(int nwk,double (*wkx)[],double (*wky)[])
  219. {
  220.     int i;
  221.     fprintf(psfile,"gsave \n");
  222.     fprintf(psfile,"newpath \n");
  223.     fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  224.     for (i=1;i<nwk;i++)
  225.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  226.     set_fill();
  227.     fprintf(psfile,"fill \n");
  228.     set_color();
  229.     fprintf(psfile,"grestore \n");
  230. }
  231. d_line_ary(int nwk,double (*wkx)[],double (*wky)[])
  232. {
  233.     int i;
  234.     fprintf(psfile,"gsave \n");
  235.     fprintf(psfile,"newpath \n");
  236.     fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  237.     for (i=1;i<nwk;i++)
  238.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  239.     fprintf(psfile,"stroke \n");
  240.     fprintf(psfile,"grestore \n");
  241. }
  242. /*---------------------------------------------------------------------------*/
  243. d_stroke()
  244. {
  245.     fprintf(psfile,"gsave \n");
  246.     fprintf(psfile,"stroke \n");
  247.     fprintf(psfile,"grestore \n");
  248. }
  249. /*---------------------------------------------------------------------------*/
  250. d_clip()
  251. {
  252.     fprintf(psfile,"clip \n");
  253. }
  254. /*---------------------------------------------------------------------------*/
  255. d_set_matrix(double newmat[3][3])
  256. {
  257.     fprintf(psfile," [%g %g %g %g %g %g] umatrix \n ",
  258.         newmat[0][0],newmat[1][0],newmat[0][1],
  259.         newmat[1][1],newmat[0][2],newmat[1][2]);
  260. }
  261. /*---------------------------------------------------------------------------*/
  262. d_move(double zx,double zy)
  263. {
  264.     if (g.inpath==true)
  265.         fprintf(psfile,"%g %g moveto \n",zx,zy);
  266.     else {
  267.         ps_nvec++;
  268.         fprintf(psfile,"%g %g m \n",zx,zy);
  269.     }
  270. }
  271. /*---------------------------------------------------------------------------*/
  272. d_reverse()     /* reverse the order of stuff in the current path */
  273. {
  274.     fprintf(psfile,"reversepath \n");
  275. }
  276. /*---------------------------------------------------------------------------*/
  277. d_closepath()
  278. {
  279.     fprintf(psfile,"closepath \n");
  280. }
  281. /*---------------------------------------------------------------------------*/
  282. d_line(double zx,double zy)
  283. {
  284.     dbg gprint("in d_line  g.curx,y  %g %g ",g.curx,g.cury);
  285.     if (g.xinline==false) {
  286.         d_move(g.curx,g.cury);
  287.     }
  288.     ps_nvec++;
  289.     if (ps_nvec>MAX_VECTOR) {
  290.         gprint("Warning, complex path, if filling fails then try /nomaxpath \n");
  291.         ps_nvec = 0; g_flush(); d_move(g.curx,g.cury);
  292.     }
  293.     if (fprintf(psfile,"%g %g l \n",zx,zy)==EOF) {
  294.         perror("=========Unable to write to output file ");
  295.     }
  296. }
  297. /*---------------------------------------------------------------------------*/
  298. d_clear()
  299. {
  300.     int flipit;
  301.     g_scale(72.0,72.0);
  302.     g_scale(.393701,.393701);
  303.     if (!dev_eps) g_translate(1.5,1.01);
  304.     if ((!dev_eps) && (g.userwidth>g.userheight)) {
  305.         fprintf(psfile,"%% Flipping coord system \n");
  306.         g_move(0.0,0.0);
  307.         g_rotate(90.0);
  308.         g_translate(0.0,-g.userheight);
  309.         g_move(0.0,0.0);
  310.     }
  311. }
  312. /*---------------------------------------------------------------------------*/
  313. d_flush()
  314. {
  315.     if (g.inpath) return;
  316.     if (g.xinline) {
  317.         fprintf(psfile,"stroke \n");
  318.         ps_nvec = 0;
  319.     }
  320. }
  321. /*---------------------------------------------------------------------------*/
  322. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  323. {
  324.     if (g.xinline==false)  d_move(g.curx,g.cury);
  325.     fprintf(psfile,"%g %g %g %g %g arcto %g %g l \n",x1,y1,x2,y2,rrr,x2,y2);
  326.     g.xinline = true;
  327. }
  328. /*---------------------------------------------------------------------------*/
  329. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  330. {
  331.     double dx,dy;
  332.     polar_xy(r,t1,&dx,&dy);
  333.     if (!g.inpath) g_move(cx+dx,cy+dy);
  334.     fprintf(psfile,"%g %g %g %g %g arc \n",cx,cy,r,t1,t2);
  335.     g.xinline = true;
  336.     if (!g.inpath) g_move(cx,cy);
  337. }
  338. /*---------------------------------------------------------------------------*/
  339. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  340. {
  341.     double dx,dy;
  342.     polar_xy(r,t1,&dx,&dy);
  343.     if (!g.inpath) g_move(cx+dx,cy+dy);
  344.     fprintf(psfile,"%g %g %g %g %g arcn \n",cx,cy,r,t1,t2);
  345.     g.xinline = true;
  346.     if (!g.inpath) g_move(cx,cy);
  347. }
  348. /*---------------------------------------------------------------------------*/
  349. d_box_fill(dbl x1, dbl y1, dbl x2, dbl y2)
  350. {
  351.     if (g.inpath==true) xdbox(x1,y1,x2,y2);
  352.     else {
  353.         g_flush();
  354.         fprintf(psfile," newpath ");
  355.         xdbox(x1,y1,x2,y2);
  356.         ddfill();
  357.         fprintf(psfile,"newpath \n");
  358. /*        set_fill();
  359.         fprintf(psfile,"fill \n");
  360.         set_color();
  361. */
  362.     }
  363. }
  364. d_box_stroke(dbl x1, dbl y1, dbl x2, dbl y2)
  365. {
  366.     if (g.inpath==true) xdbox(x1,y1,x2,y2);
  367.     else {
  368.         g_flush();
  369.         fprintf(psfile," newpath ");
  370.         xdbox(x1,y1,x2,y2);
  371.         fprintf(psfile,"stroke \n");
  372.         ps_nvec = 0;
  373.     }
  374. }
  375. /*---------------------------------------------------------------------------*/
  376. xdbox(double x1, double y1, double x2, double y2)
  377. {
  378.    fprintf(psfile," %g %g moveto %g %g l %g %g l %g %g l closepath \n"
  379.             ,x1,y1,x2,y1,x2,y2,x1,y2);
  380. }
  381. /*---------------------------------------------------------------------------*/
  382. d_circle_stroke(double zr)
  383. {
  384.     double x,y;
  385.     g_get_xy(&x,&y);
  386.     if (g.inpath==true)
  387.         fprintf(psfile," %g %g %g 0 360 arc \n",x,y,zr);
  388.     else {
  389.         g_flush();
  390.         fprintf(psfile," newpath ");
  391.         fprintf(psfile," %g %g %g 0 360 arc \n",x,y,zr);
  392.         fprintf(psfile,"stroke \n");
  393.     }
  394. }
  395. d_circle_fill(double zr)
  396. {
  397.     double x=g.curx,y=g.cury;
  398.     if (g.inpath==true)
  399.         fprintf(psfile," %g %g %g 0 360 arc \n",x,y,zr);
  400.     else {
  401.         g_flush();
  402.         fprintf(psfile,"newpath ");
  403.         fprintf(psfile,"%g %g %g 0 360 arc \n",x,y,zr);
  404.         ddfill();
  405.         fprintf(psfile,"newpath \n");
  406. /*
  407.  
  408.         set_fill();
  409.         fprintf(psfile,"fill \n");
  410.         set_color();
  411. */
  412.     }
  413. }
  414. /*---------------------------------------------------------------------------*/
  415. d_bezier(dbl x1,dbl y1,dbl x2,dbl y2,dbl x3,dbl y3)
  416. {
  417.     double x=g.curx,y=g.cury;
  418.     if (g.inpath==true)
  419.         fprintf(psfile,"%g %g %g %g %g %g curveto \n"
  420.             ,x1,y1,x2,y2,x3,y3);
  421.     else {
  422.         g_flush();
  423.         if (!g.xinline) fprintf(psfile,"%g %g moveto ",x,y);
  424.         fprintf(psfile,"%g %g %g %g %g %g curveto \n"
  425.             ,x1,y1,x2,y2,x3,y3);
  426.         g.xinline = true;
  427.     }
  428. }
  429. /*---------------------------------------------------------------------------*/
  430. /*---------------------------------------------------------------------------*/
  431. test_psfile()
  432. {
  433.     if (psfile==NULL) return;
  434.     set_color();
  435. }
  436. set_color()
  437. {
  438.     if (BLACKANDWHITE) {
  439.          fprintf(psfile,"%g setgray \n",((g_cur_color.b[B_R]*3.0/255.0
  440.         +g_cur_color.b[B_G]*2.0/255.0+g_cur_color.b[B_B]/255.0) / 6));
  441.     } else
  442.          fprintf(psfile,"%g %g %g setrgbcolor \n",g_cur_color.b[B_R]/255.0
  443.         ,g_cur_color.b[B_G]/255.0,g_cur_color.b[B_B]/255.0);
  444. }
  445. set_fill()
  446. {
  447.     if (BLACKANDWHITE) {
  448.          fprintf(psfile,"%g setgray \n",((g_cur_fill.b[B_R]*3.0/255.0
  449.         +g_cur_fill.b[B_G]*2.0/255.0+g_cur_fill.b[B_B]/255.0) / 6));
  450.     } else
  451.          fprintf(psfile,"%g %g %g setrgbcolor \n",g_cur_fill.b[B_R]/255.0
  452.         ,g_cur_fill.b[B_G]/255.0,g_cur_fill.b[B_B]/255.0);
  453. }
  454. /*---------------------------------------------------------------------------*/
  455. d_set_color(long f)
  456. {
  457.     g_flush();
  458.     g_cur_color.l = f;
  459.     set_color();
  460. }
  461. d_set_fill(long f)
  462. {
  463.     g_cur_fill.l = f;
  464. }
  465. /*---------------------------------------------------------------------------*/
  466. d_beginclip()
  467. {
  468.     fprintf(psfile,"gsave \n");
  469. }
  470. d_endclip()
  471. {
  472.     char *state;
  473.     g_flush();
  474.     fprintf(psfile,"grestore \n");
  475.     state = myallocz(300);
  476.     g_get_state(state);
  477.     g_set_state(state);
  478.     myfree(state);
  479. }
  480. /*---------------------------------------------------------------------------*/
  481. struct psfont_struct {char *sname; char *lname;} ;
  482. struct psfont_struct psf[70] = { /* leaves room for twenty more from PSFONT.DAT*/
  483.     "PSTR",        "Times-Roman",
  484.     "PSTI",        "Times-Italic",
  485.     "PSTB",        "Times-Bold",
  486.     "PSTBI",    "Times-BoldItalic",
  487.     "RM",        "Times-Roman",
  488.     "RMI",        "Times-Italic",
  489.     "RMB",        "Times-Bold",
  490.     "RMBI",        "Times-BoldItalic",
  491.     "SS",        "Helvetica",
  492.     "SSB",        "Helvetica-Bold",
  493.     "SSI",        "Helvetica-Oblique",
  494.     "SSBI",        "Helvetica-BoldOblique",
  495.     "PSH",        "Helvetica",
  496.     "PSHB",        "Helvetica-Bold",
  497.     "PSHBO",    "Helvetica-BoldOblique",
  498.     "PSHO",        "Helvetica-Oblique",
  499.     "PSAGB",    "AvantGarde-Book",
  500.     "PSAGBO",    "AvantGarde-BookOblique",
  501.     "PSAGD",    "AvantGarde-Demi",
  502.     "PSAGDO",    "AvantGarde-DemiOblique",
  503.     "PSBD",        "Bookman-Demi",
  504.     "PSBDI",    "Bookman-DemiItalic",
  505.     "PSBL",        "Bookman-Light",
  506.     "PSBLI",    "Bookman-LightItalic",
  507.     "PSC",        "Courier",
  508.     "PSCB",        "Courier-Bold",
  509.     "PSCBO",    "Courier-BoldOblique",
  510.     "PSCO",        "Courier-Oblique",
  511.     "TT",        "Courier",
  512.     "TTB",        "Courier-Bold",
  513.     "TTBI",        "Courier-BoldOblique",
  514.     "TTI",        "Courier-Oblique",
  515.     "PSNCSB",    "NewCenturySchlbk-Bold",
  516.     "PSNCSBI",    "NewCenturySchlbk-BoldItalic",
  517.     "PSNCSI",    "NewCenturySchlbk-Italic",
  518.     "PSNCSR",    "NewCenturySchlbk-Roman",
  519.     "PSPB",        "Palatino-Bold",
  520.     "PSPBI",    "Palatino-BoldItalic",
  521.     "PSPI",        "Palatino-Italic",
  522.     "PSPR",        "Palatino-Roman",
  523.     "PSZCMI",    "ZapfChancery-MediumItalic",
  524.     "PSZD",        "ZapfDingbats",
  525.     "PSSYM",    "Symbol",
  526.     NULL,NULL
  527. };
  528. /*---------------------------------------------------------------------------*/
  529. d_char(int font, int cc)
  530. {
  531.     double x,y;
  532.     char *s;
  533.     static int this_font;
  534.     static double this_size;
  535.  
  536.  
  537.     read_psfont();
  538.     if (font_get_encoding(font)>2) {
  539.         my_char(font,cc);
  540.         return;
  541.     }
  542.     if (this_font!=font || this_size!=g.fontsz) {
  543.         if (g.fontsz<0.00001) {
  544.             gprint("Font size is zero, error ********* \n");
  545.             return;
  546.         }
  547.         s = font_getname(font);
  548.         for (i=0;;i++) {
  549.             if (psf[i].sname==NULL) break;
  550.             dbg printf("font match  {%s} {%s} \n",s,psf[i].sname);
  551.             if (strcmp(psf[i].sname,s)==0) break;
  552.         }
  553.         if (psf[i].sname==NULL) {
  554.             my_char(font,cc);
  555.             return;
  556.         }
  557.         this_font = font;
  558.         this_size = g.fontsz;
  559.         fprintf(psfile," %f /%s f ",g.fontsz,psf[i].lname);
  560.     }
  561.     if (g.inpath==true) {
  562.         if (isalnum(cc) && cc<127) fprintf(psfile,"(%c) ps ",cc);
  563.         else  fprintf(psfile,"(\\%o) ps ",cc);
  564.     } else {
  565.         if (isalnum(cc) && cc<127) fprintf(psfile,"(%c) s ",cc);
  566.         else  fprintf(psfile,"(\\%o) s ",cc);
  567.     }
  568. }
  569. char *fontdir(char *s);
  570. read_psfont()  /* add aditional ps fonts,  e.g.  pstr = TimesRoman */
  571. {
  572.     static init_done;
  573.     FILE *fptr;
  574.     char fname[80],*s;
  575.     char inbuff[90];
  576.     if (init_done) return;
  577.     init_done = true;
  578.  
  579.     /* Find last used psf */
  580.     for (i=0;;i++) if (psf[i].sname==NULL) break;
  581.  
  582.     strcpy(fname,fontdir("psfont.dat"));
  583.     fptr = fopen(fname,"r");
  584.     if (fptr==0) return; /* if not exists then don't bother */
  585.  
  586.     for (fgets(inbuff,200,fptr);!feof(fptr);fgets(inbuff,200,fptr)) {
  587.         s = strchr(inbuff,'!');
  588.         if (s!=NULL) *s=0;
  589.         s = strtok(inbuff," \t,\n");
  590.         if (s!=NULL) if (*s!='\n') {
  591.             psf[i].sname = sdup(s);
  592.             s = strtok(0," \t,\n");
  593.             psf[i].lname = sdup(s);
  594.             i++;
  595.         }
  596.     }
  597.     psf[i].sname = NULL;
  598.     psf[i].lname = NULL;
  599. }
  600.