Slpr.c

Go to the documentation of this file.
00001 /* Copyright ENPC/Chancelier Jean-Philippe */
00002 
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <ctype.h>
00006 #ifndef __STDC__
00007 #include <stdlib.h>
00008 #endif 
00009 #include <stdio.h>
00010 
00011 #if defined(netbsd)
00012 #include <ieeefp.h>
00013 #endif
00014 
00015 #if defined(freebsd)
00016 #include <floatingpoint.h>
00017 #endif
00018 
00019 #include "util.h" 
00020 
00021 static void Sed (char *,char *,char *,char *,char *,char *,char *);
00022 static void ComputeSize (int num,int i,double *,double *,double *,double *);
00023 
00024 #ifdef _MSC_VER
00025 extern void SciEnv(void);
00026 #endif 
00027 
00028 /*---------------------------------------------------------
00029 
00030   Blpr str file1 .... filen  | lpr 
00031                              >! foo.ps 
00032 
00033   fait une mise en page de n dessins scilab ou neoclo 
00034 
00035   avec un titre str et genere le fichier postscript associe
00036 -------------------------------------------------------------*/
00037 
00038 char * UsageStr[]={
00039   "Usage  : Blpr Title file1 ... filen | lpr   \n",
00040   "       : Blpr Title file1 ... filen > fileres  \n",
00041   "\tfile1, ... filen : are n Postscript files produced by Scilab\n",
00042   "\tfileres : a file name for the result \n",
00043   "\ttitle : a string for title\n",
00044   "\tThis command print n Postscript files produced by Scilab on a\n",
00045   "\tsingle page with a title Title\n",
00046   "fin"};
00047 
00048 char entete[160];
00049 
00050 int main(int argc, char **argv)
00051 {
00052   char *env;
00053   double x,y,w,h;
00054   char buf[256];
00055   int i ;
00056   FILE *fd;
00057 #if defined(freebsd) || defined(netbsd)
00058   fpsetmask(0);
00059 #endif
00060   if (argc <= 2) { int i=0;
00061                    while (strcmp(UsageStr[i],"fin")!=0)
00062                      { 
00063                        fprintf(stderr,"%s",UsageStr[i]),i++;
00064                      }
00065                    exit(0);
00066                  }
00067 #ifdef _MSC_VER
00068   SciEnv();
00069 #endif 
00070   env = getenv("SCI");
00071   if (env == NULL) {
00072     fprintf(stderr,"Environment variable SCI must be defined\n");
00073     exit(0);
00074   }
00075   sprintf(entete,"%s/tools/printer/NperiPos.ps",env);
00076   fd=fopen(entete,"r");
00077   if (fd != 0)
00078     { int c;
00079       while ( (c=getc(fd)) != EOF)  putc((char) c,stdout);
00080       fclose(fd);
00081     }
00082   else 
00083     {
00084       fprintf(stderr,"file %s not found ",entete);
00085       return(1);
00086     }
00087   fprintf(stdout,"/Times-Roman findfont 14 scf mul scalefont setfont\n");
00088   fprintf(stdout,"100 780 moveto ( %s ) show\n",argv[1]);
00089   for ( i = 2 ; i < argc-1 ; i++)
00090     { 
00091       ComputeSize(argc-2,i-1,&x,&y,&w,&h)      ;
00092       sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00093               ,x,y,w,h);
00094       Sed(argv[i],"[0.5 10 div 0 0 0.5 10 div neg  0 2120 10 div] concat",
00095           buf," showpage","grestore",
00096           " end saved restore","% end saved restore");
00097     }
00098   ComputeSize(argc-2,argc-2,&x,&y,&w,&h);      
00099   sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00100           ,x,y,w,h);
00101   Sed(argv[argc-1],"[0.5 10 div 0 0 0.5 10 div neg  0 2120 10 div] concat",
00102       buf, " showpage"," grestore showpage",
00103       " end saved restore"," end saved restore");
00104   return(0);
00105 }
00106 
00107 
00108 /*---------------------------------------------------
00109  remplace strin<i> par strout<i> en lisant le contenu de 
00110  file et en ecrivant sur stdout
00111 -------------------------------------------------------*/
00112 
00113 static void Sed(char *file, char *strin1, char *strout1, char *strin2, char *strout2, char *strin3, char *strout3)
00114 {
00115   FILE *fd;
00116 
00117   static char *buff = NULL;
00118   static int buflen = 512;
00119   if ( buff == NULL) 
00120     {
00121       buff = malloc(buflen*sizeof(char));
00122       if ( buff == NULL) 
00123         {
00124           fprintf(stderr,"Running out of space \n");
00125           exit(1);
00126         }
00127     }
00128 
00129   fd=fopen(file,"r");
00130   if (fd != 0)
00131     { int stop=0;
00132       while ( stop != 1)
00133         {  
00134           read_one_line (&buff,&stop,fd,&buflen); 
00135            if (strncmp(buff,strin1,strlen(strin1))==0)
00136              fprintf(stdout,"%s\n",strout1);
00137            else
00138              {
00139                if (strncmp(buff,strin2,strlen(strin2))==0)
00140                  fprintf(stdout,"%s\n",strout2);
00141                else 
00142                  {
00143                    if (strncmp(buff,strin3,strlen(strin3))==0)
00144                      fprintf(stdout,"%s\n",strout3);
00145                    else
00146                      fprintf(stdout,"%s",buff);
00147                  }
00148              }
00149          }
00150       fclose(fd);
00151     }
00152   else 
00153     {
00154       fprintf(stderr,"file %s not found ",file);
00155       return;
00156     }
00157 }
00158 
00159 
00160 
00161 /*-----------------------------------------------
00162   calcule la taille pour un dessin suivant le nombre de dessin a 
00163   placer dans la feuille 
00164   num est le nombre de dessins et i le numero du dessin 
00165   renvoit le point gauche dans (*x,*y) la largeur et le hauteur 
00166   dans (*w,*h)
00167 -----------------------------------------------------*/
00168 
00169 static void ComputeSize(int num, int i, double *x, double *y, double *w, double *h)
00170 {
00171   switch (num)
00172     {
00173     case 1 :
00174       *x=3.0;*y=24.0;*h=20.0;*w=15.0;
00175       break;
00176     case 2 :
00177       *x=3.0;*y=(24-(i-1)*11);*h=10.0;*w=15.0;
00178       break;
00179     case 3 :
00180       *x=3.0;*y=(26.5-(i-1)*8.5);*h=8.0;*w=15.0;
00181       break;
00182     case 4 :
00183       if (i <= 2) *y=24.0;else *y=24-11.0;
00184       if ( (i % 2 ) == 0 ) 
00185         { *x= 2+8.5;*h=8.0;*w=8.0;}
00186       else 
00187         {*x= 2.0;*h=8.0;*w=8.0;}
00188       break ;
00189     case 5 :
00190     case 6 :
00191       if (i <= 2) *y=26.0;else { if ( i <= 4) *y=26-8.5; else *y=26-2*8.5;}
00192       if ( (i % 2 ) == 0 ) 
00193         { *x= 2+8.5;*h=7.5;*w=8.0;}
00194       else 
00195         {*x= 2.0;*h=7.5;*w=8.0;}
00196       break ;
00197     case 7 :
00198     case 8 :
00199     case 9 :
00200       if (i <= 3) *y=26.0;else { if ( i <= 6) *y=26-8.5; else *y=26-2*8.5;}
00201       if ( (i % 3 ) == 0 ) 
00202         { *x= 1.5+2*6;*h=7.5;*w=5.5;}
00203       else 
00204         {
00205           if ( (i % 3 ) == 1 ) 
00206             { *x= 1.5;*h=7.5;*w=5.5;}
00207           else 
00208             {*x= 1.5+6 ;*h=7.5;*w=5.5;}
00209         }
00210       break ;
00211     case 10 :
00212     case 11 :
00213     case 12 :
00214     default :
00215       if (i <= 3) *y=27.0;
00216       else { 
00217         if ( i <= 6) *y=27-6.5;
00218         else {
00219           if (i <= 9 ) *y=27-2*6.5; else *y=27-3*6.5;}
00220       }
00221       if ( (i % 3 ) == 0 ) 
00222         { *x= 1.5+2*6;*h=6;*w=5.5;}
00223       else 
00224         {
00225           if ( (i % 3 ) == 1 ) 
00226             { *x= 1.5;*h=6.0;*w=5.5;}
00227           else 
00228             {*x= 1.5+6 ;*h=6.0;*w=5.5;}
00229         }
00230       break ;
00231     }
00232 }
00233 
00234 

Generated on Sun Mar 4 15:04:01 2007 for Scilab [trunk] by  doxygen 1.5.1