Slatexpr.c File Reference

#include <varargs.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include "../../modules/core/includes/machine.h"
#include "util.h"

Include dependency graph for Slatexpr.c:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * getenv ()
static int Sed __PARAMS ((int, char *, FILE *, char *, char *, char *, char *, char *, char *))
static void FileNameChange __PARAMS ((char *filein, char *fileout, char *, char *))
static void dos2win32 __PARAMS ((char *filename, char *filename1))
int ScilabPsToTeX __PARAMS ((char orientation, char *filenamein, char *filenameout, double xs, double ys))
int main (int argc, char **argv)
void sciprint (va_alist)
static void dos2win32 (char *filename, char *filename1)
int ScilabPsToTeX (char orientation, char *filein, char *fileout, double xs, double ys)
static void FileNameChange (char *filein, char *fileout, char *name, char *suf)
static int Sed (int flag, char *file, FILE *fileo, char *strin1, char *strout1, char *strin2, char *strout2, char *strin3, char *strout3)

Variables

char * UsageStr []
char file1 [256]
char file2 [256]
static char entete [256]
static char base [54]


Function Documentation

int ScilabPsToTeX __PARAMS ( (char orientation, char *filenamein, char *filenameout, double xs, double ys)   ) 

static void dos2win32 __PARAMS ( (char *filename, char *filename1  )  [static]

static void FileNameChange __PARAMS ( (char *filein, char *fileout, char *, char *)   )  [static]

static int Sed __PARAMS ( (int, char *, FILE *, char *, char *, char *, char *, char *, char *)   )  [static]

static void dos2win32 ( char *  filename,
char *  filename1 
) [static]

Definition at line 113 of file Slatexpr.c.

00114 {
00115 #ifdef CVT_PATH_BEG
00116   if ( filename[1] == ':' ) 
00117     {
00118       *filename1++ = '/';
00119       *filename1++ = '/';
00120       *filename1++ = *filename++;
00121       filename++;
00122     }
00123 #endif
00124   while ( *filename != '\0' ) 
00125     {
00126       *filename1++ = *filename++;
00127       if ( *(filename1-1) == '\\' ) *(filename1-1) = '/' ;
00128     }
00129   *filename1 = '\0';
00130 }

static void FileNameChange ( char *  filein,
char *  fileout,
char *  name,
char *  suf 
) [static]

Definition at line 289 of file Slatexpr.c.

References p, and strchr().

00290 {
00291   char *p=filein,*p1;
00292   p1=strchr(p,'/');
00293   while ( p1 != 0 ) 
00294     {
00295       p=p1+1;
00296       p1 = strchr(p,'/');
00297     }
00298   p1 = strchr(p,'.');
00299   if ( p1 != 0 ) 
00300     {
00301       *p1 = '\0';
00302       sprintf(fileout,"%s.%s",filein,suf);
00303       sprintf(base,"%s",p);
00304       *p1 = '.';
00305     }
00306   else 
00307     {
00308       sprintf(fileout,"%s.%s",filein,suf);
00309       sprintf(base,"%s",p);
00310     }
00311   /* 
00312      sciprint("[%s]=>[%s]\n",filein,fileout); 
00313      sciprint("real base %s\n",base);
00314      */
00315 }

Here is the call graph for this function:

char* getenv (  ) 

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file Slatexpr.c.

References dos2win32(), i, orientation, SciEnv(), and ScilabPsToTeX().

00043 {
00044   double xs=1.0,ys=1.0;
00045   char orientation='p';
00046 #ifdef _MSC_VER
00047   SciEnv();
00048 #endif 
00049   if (argc >= 6 || argc <= 3 )
00050     { int i=0;
00051       fprintf(stderr,"Usage  : %s [-orientation] xs ys filename.ps \n",argv[0]);
00052       while (strcmp(UsageStr[i],"fin")!=0)
00053           fprintf(stderr,"%s",UsageStr[i]),i++;
00054       return(1);
00055     }
00056   switch ( argc ) 
00057     {
00058     case 4 :
00059       if ( strncmp( argv[1] ,"-p",2) == 0 || ( strncmp( argv[1] ,"-l",2) == 0) )
00060         {
00061           fprintf(stderr,"Slatexpr: wrong number of arguments \n");
00062           return(1);
00063         }
00064       orientation = 'p';
00065       strcpy(file1,argv[3]);
00066       sscanf(argv[1],"%lf",&xs);
00067       sscanf(argv[2],"%lf",&ys);
00068       break;
00069     case 5:
00070       strcpy(file1,argv[4]);
00071       if ( strncmp( argv[1] ,"-p",2) == 0) 
00072         orientation = 'p';
00073       else if ( strncmp( argv[1] ,"-l",2) == 0) 
00074         orientation = 'l';
00075       else 
00076        fprintf(stderr,"Invalid first argument %s\n",argv[1]);
00077       sscanf(argv[2],"%lf",&xs);
00078       sscanf(argv[3],"%lf",&ys);
00079       break;
00080     }
00082   dos2win32(file1,file2);
00084   ScilabPsToTeX(orientation,file2,file1,xs,ys);
00085   return(0);
00086 }

Here is the call graph for this function:

int ScilabPsToTeX ( char  orientation,
char *  filein,
char *  fileout,
double  xs,
double  ys 
)

Definition at line 142 of file Slatexpr.c.

References env, FileNameChange(), getenv(), NULL, rep, sciprint(), and Sed().

Referenced by main(), and SavePs().

00143 {
00144   double wide,high,widecm,highcm,hscale,vscale;
00145   int flag = 0,rep;
00146   FILE *fo;
00147   char *env;
00148   env = getenv("SCI");
00149   if (env == NULL) 
00150     {
00151       sciprint("Environment variable SCI must be defined\n");
00152       return(1);
00153     }
00154 
00158   sprintf(entete,"%s/tools/printer/NperiPos.ps",env);
00159 
00160   FileNameChange(filein,fileout,base,"eps");
00161   if ( strcmp(fileout,filein) == 0 ) 
00162     {
00163       flag = 1;
00164       strcat(fileout,".temp");
00165     }
00166   
00167   if ( (fo = fopen(fileout,"w"))== 0 ) 
00168     {
00169       sciprint(" Can't open file %s\n",fileout);
00170       exit(1);
00171     }
00172 
00173   fprintf(fo,"%%!PS-Adobe-2.0 EPSF-2.0\n");
00174   if ( orientation == 'p' ) 
00175     fprintf(fo,"%%%%BoundingBox:  0 0 300 212\n");
00176   else 
00177     fprintf(fo,"%%%%BoundingBox:  0 0 212 300\n");
00178 
00179   Sed(0,entete,fo,"%!PS-ADOBE","%%",(char*) 0,(char *)0,(char*) 0,(char *)0);
00180 
00181   if ( orientation == 'p' )
00182         rep=Sed(1,filein,fo,(char*) 0,(char *)0,(char*) 0,(char *)0,
00183                 (char*) 0,(char *)0);
00184   else 
00185     
00186     rep=Sed(1,filein,fo,"[0.5 10 div 0 0 0.5 10 div neg  0 2120 10 div] concat",
00187         "90 rotate 0 600 neg translate [0.5 10 div 0 0 0.5 10 div neg  0 3000 5 div] concat",
00188         (char*) 0,(char *)0,(char*) 0,(char *)0);
00189   fclose(fo);
00190 
00191   if ( rep >= 1 ) 
00192     {
00193       if ( rep == 1) 
00194         sciprint("input file doesn't need to be converted to Epsf\n");
00195       remove(fileout);
00196       exit(0);
00197     }
00198   
00199   if ( flag == 1) 
00200     {
00202       fo = fopen(filein,"w");
00203       Sed(0,fileout,fo,(char*) 0,(char *)0,(char*) 0,(char *)0,(char*) 0,(char *)0);
00204       fclose(fo);
00205     }
00206   else
00207     {
00208       remove(filein);
00209     }
00210   
00213   if ( orientation == 'p' ) 
00214     {
00215       wide = 300 *xs;
00216       high = 212 *ys;
00217     }
00218   else 
00219     {
00220       wide = 212 *xs;
00221       high = 300 *ys;
00222     }
00223   widecm = wide *2.835;
00224   highcm = high *2.835;
00225   hscale = xs*100;
00226   vscale = ys*100;
00227 
00228   FileNameChange(filein,fileout,base,"tex");
00229   if ( (fo = fopen(fileout,"w"))== 0 ) 
00230     {
00231       sciprint(" Can't open file %s\n",fileout);
00232       exit(1);
00233     }
00234 #ifndef DOC
00235   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00236   fprintf(fo,"%% Usage: -To include a Figure with a caption, insert the TWO following lines\n");
00237   fprintf(fo,"%%        in your Latex file:\n");
00238   fprintf(fo,"%% \\input{This_file_name} \n");
00239   fprintf(fo,"%% \\dessin{The_caption}{The_label}\n");
00240   fprintf(fo,"%%         -To include just a picture, insert the lines \n");
00241   fprintf(fo,"%%         between \\fbox{\\begin{picture}...  and \\end{picture}} below \n");
00242   fprintf(fo,"%%          \n");
00243   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00244 
00245   fprintf(fo," \n");
00246 
00247   fprintf(fo," \\long\\def\\Checksifdef#1#2#3{%%\n");
00248   fprintf(fo,"\\expandafter\\ifx\\csname #1\\endcsname\\relax#2\\else#3\\fi}\n");
00249   fprintf(fo,"\\Checksifdef{Figdir}{\\gdef\\Figdir{}}{}\n");
00250   fprintf(fo,"\\def\\dessin#1#2{\n");
00251 #endif
00252   fprintf(fo,"\\begin{figure}[hbtp]\n");
00253   fprintf(fo,"\\begin{center}\n");
00254   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n");
00255   fprintf(fo,"%%If you prefer cm, uncomment the following two lines\n");
00256   fprintf(fo,"%%\\setlength{\\unitlength}{1mm}\n");
00257   fprintf(fo,"%%\\fbox{\\begin{picture}(%.2f,%.2f)\n",widecm,highcm);
00258   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n");
00259   fprintf(fo,"\\fbox{\\begin{picture}(%.2f,%.2f)\n",wide,high);
00260   FileNameChange(filein,fileout,base,"eps");
00261 #ifdef EPSFIG
00262   fprintf(fo,"\\epsfig{file=\\Figdir %s.eps,width=%.2fpt,height=%.2fpt}\n",
00263           base,wide,high);
00264 #else
00265   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00266   fprintf(fo,"%% If you want do not want to use epsfig ,comment the following line \n");
00267   fprintf(fo,"%% and uncomment the \\special line \n");
00268   fprintf(fo,"\\epsfig{file=\\Figdir %s.eps,width=%.2fpt,height=%.2fpt}\n",
00269           base,wide,high);
00270   fprintf(fo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00271   fprintf(fo,"%%\\special{psfile=\\Figdir %s.eps hscale=%.2f vscale=%.2f}\n",
00272           base,hscale,vscale);
00273 #endif
00274   fprintf(fo,"\\end{picture}}\n");
00275   fprintf(fo,"\\end{center}\n");
00276 #ifndef DOC 
00277   fprintf(fo,"\\caption{\\label{#2}#1}\n");
00278   fprintf(fo,"\\end{figure}}\n");
00279 #endif
00280   fclose(fo);
00281   return(0);
00282 }

Here is the call graph for this function:

Here is the caller graph for this function:

void sciprint ( va_alist   ) 

Definition at line 101 of file Slatexpr.c.

References void().

00102 {
00103   va_list ap;
00104   char *format;
00105   va_start(ap);
00106   format = va_arg(ap, char *);
00107   (void)  vfprintf(stdout, format, ap );
00108   va_end(ap);
00109 }

Here is the call graph for this function:

static int Sed ( int  flag,
char *  file,
FILE *  fileo,
char *  strin1,
char *  strout1,
char *  strin2,
char *  strout2,
char *  strin3,
char *  strout3 
) [static]

Definition at line 322 of file Slatexpr.c.

References buflen, fd, malloc(), NULL, read_one_line(), and sciprint().

00323 {
00324   FILE *fd;
00325 
00326   static char *buff = NULL;
00327   static int buflen = 512;
00328   if ( buff == NULL) 
00329     {
00330       buff = malloc(buflen*sizeof(char));
00331       if ( buff == NULL) 
00332         {
00333           fprintf(stderr,"Running out of space \n");
00334           exit(1);
00335         }
00336     }
00337 
00338   fd=fopen(file,"r");
00339   if (fd != 0)
00340     { int stop=0;
00341       while ( stop != 1)
00342         { 
00343            read_one_line (&buff,&stop,fd,&buflen); 
00344            if ( flag == 1 ) 
00345              {
00346                if ( strncmp(buff,"%!PS-Adobe-2.0 EPSF-2.0",
00347                             strlen("%!PS-Adobe-2.0 EPSF-2.0"))== 0)
00348                  {
00349                    fclose(fd);
00350                    return(1);
00351                  }
00352              }
00353            if ( strin1 != (char *) 0 && strncmp(buff,strin1,strlen(strin1))==0)
00354              fprintf(fileo,"%s\n",strout1);
00355            else
00356              {
00357                if (  strin2 != (char *) 0 && strncmp(buff,strin2,strlen(strin2))==0)
00358                  fprintf(fileo,"%s\n",strout2);
00359                else 
00360                  {
00361                    if ( strin3 != (char *) 0 && strncmp(buff,strin3,strlen(strin3))==0)
00362                      fprintf(fileo,"%s\n",strout3);
00363                    else
00364                      fprintf(fileo,"%s",buff);
00365                  }
00366              }
00367          }
00368       fclose(fd);
00369     }
00370   else 
00371     {
00372       sciprint("file %s not found \n",file);
00373       return(2);
00374     }
00375   return(0);
00376 }

Here is the call graph for this function:


Variable Documentation

char base[54] [static]

Definition at line 140 of file Slatexpr.c.

char entete[256] [static]

file wmtex.c in wsci ( should be gathered in a unique lib )

Definition at line 140 of file Slatexpr.c.

char file1[256]

Definition at line 36 of file Slatexpr.c.

char file2[256]

Definition at line 36 of file Slatexpr.c.

char* UsageStr[]

Initial value:

{
  "\tfilename.ps : Postscript file produced by Scilab\n",
  "\torientation : p[ortrait] or l[andscape]  \n",
  "fin"}

Definition at line 31 of file Slatexpr.c.


Generated on Sun Mar 4 16:14:22 2007 for Scilab [trunk] by  doxygen 1.5.1