File:  [Local Repository] / rleda / rleda.c
Revision 1.1: download - view: text, annotated - select for diffs
Fri Dec 12 18:53:44 2003 UTC (20 years, 6 months ago) by brouard
Branches: MAIN
CVS tags: HEAD
Initial revision

/* $Id: rleda.c,v 1.1 2003/12/12 18:53:44 brouard Exp $
  $State: Exp $
  $Log: rleda.c,v $
  Revision 1.1  2003/12/12 18:53:44  brouard
  Initial revision


 rleda.c
 Programme pour lire une fichier d'index de LEDA qui a t  converti de l'EBCDIC vers l'ascii
 Nicolas Brouard (Institut national d'tudes d mographiques)
 Usage : rleda nom_d_index 
 Il y a plusieurs sorties, un log (pour le debug) un .txt pour le format et
 un .sas pour le sas.
 Je me suis inspir de la version sas d'Andr  Wielki (INED).
 Mardi 25 novembre 2003
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define MAXLINE 300
#define FILENAMELENGTH 300
#define FILENAMEEXTLEN 10
#define	GLOCK_ERROR_NOPATH		-1	/* empty path */
#define	GLOCK_ERROR_GETCWD		-2	/* cannot get cwd */

#ifdef unix
#define DIRSEPARATOR '/'
#define ODIRSEPARATOR '\\'
#else
#define DIRSEPARATOR '\\'
#define ODIRSEPARATOR '/'
#endif

char version[]="rleda-0.9 Programme de lecture de fichiers d'index au format LEDA convertis de l'EBCDIC en ASCII ";
char fullversion[]="$Revision: 1.1 $ $Date: 2003/12/12 18:53:44 $"; 
char line[MAXLINE];
char title[MAXLINE],namevar[MAXLINE], namevara[MAXLINE];

char fileres[FILENAMELENGTH], filereso[FILENAMELENGTH];
char filesas[FILENAMELENGTH]; /* SAS  file */
char filelog[FILENAMELENGTH]; /* Log file */

FILE *ficlog, *ficres, *ficpar, *ficparo, *ficparsas;


static unsigned char const ascii_to_ebcdic[] =
{
  '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',
  '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',
  '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',
  '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',
  '\100', '\117', '\177', '\173', '\133', '\154', '\120', '\175',
  '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',
  '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',
  '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',
  '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',
  '\347', '\350', '\351', '\112', '\340', '\132', '\137', '\155',
  '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',
  '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',
  '\247', '\250', '\251', '\300', '\152', '\320', '\241', '\007',
  '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',
  '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',
  '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',
  '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',
  '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',
  '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
  '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',
  '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',
  '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',
  '\216', '\217', '\220', '\232', '\233', '\234', '\235', '\236',
  '\237', '\240', '\252', '\253', '\254', '\255', '\256', '\257',
  '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',
  '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',
  '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'
};

static unsigned char const ascii_to_ibm[] =
{
  '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',
  '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',
  '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',
  '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',
  '\100', '\132', '\177', '\173', '\133', '\154', '\120', '\175',
  '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',
  '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',
  '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',
  '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',
  '\347', '\350', '\351', '\255', '\340', '\275', '\137', '\155',
  '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',
  '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',
  '\247', '\250', '\251', '\300', '\117', '\320', '\241', '\007',
  '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',
  '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',
  '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',
  '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',
  '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',
  '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
  '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',
  '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',
  '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',
  '\216', '\217', '\220', '\232', '\233', '\234', '\235', '\236',
  '\237', '\240', '\252', '\253', '\254', '\255', '\256', '\257',
  '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',
  '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',
  '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'
};

static unsigned char const ebcdic_to_ascii[] =
{
  '\000', '\001', '\002', '\003', '\234', '\011', '\206', '\177',
  '\227', '\215', '\216', '\013', '\014', '\015', '\016', '\017',
  '\020', '\021', '\022', '\023', '\235', '\205', '\010', '\207',
  '\030', '\031', '\222', '\217', '\034', '\035', '\036', '\037',
  '\200', '\201', '\202', '\203', '\204', '\012', '\027', '\033',
  '\210', '\211', '\212', '\213', '\214', '\005', '\006', '\007',
  '\220', '\221', '\026', '\223', '\224', '\225', '\226', '\004',
  '\230', '\231', '\232', '\233', '\024', '\025', '\236', '\032',
  '\040', '\240', '\241', '\242', '\243', '\244', '\245', '\246',
  '\247', '\250', '\133', '\056', '\074', '\050', '\053', '\041',
  '\046', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  '\260', '\261', '\135', '\044', '\052', '\051', '\073', '\136',
  '\055', '\057', '\262', '\263', '\264', '\265', '\266', '\267',
  '\270', '\271', '\174', '\054', '\045', '\137', '\076', '\077',
  '\272', '\273', '\274', '\275', '\276', '\277', '\300', '\301',
  '\302', '\140', '\072', '\043', '\100', '\047', '\075', '\042',
  '\303', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  '\150', '\151', '\304', '\305', '\306', '\307', '\310', '\311',
  '\312', '\152', '\153', '\154', '\155', '\156', '\157', '\160',
  '\161', '\162', '\313', '\314', '\315', '\316', '\317', '\320',
  '\321', '\176', '\163', '\164', '\165', '\166', '\167', '\170',
  '\171', '\172', '\322', '\323', '\324', '\325', '\326', '\327',
  '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  '\173', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
  '\110', '\111', '\350', '\351', '\352', '\353', '\354', '\355',
  '\175', '\112', '\113', '\114', '\115', '\116', '\117', '\120',
  '\121', '\122', '\356', '\357', '\360', '\361', '\362', '\363',
  '\134', '\237', '\123', '\124', '\125', '\126', '\127', '\130',
  '\131', '\132', '\364', '\365', '\366', '\367', '\370', '\371',
  '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  '\070', '\071', '\372', '\373', '\374', '\375', '\376', '\377'
};

/**************** split *************************/
static	int split( char *path, char *dirc, char *name, char *ext, char *finame )
{
  char	*ss;				/* pointer */
  int	l1, l2;				/* length counters */

  l1 = strlen(path );			/* length of path */
  if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
  ss= strrchr( path, DIRSEPARATOR );		/* find last / */
  if ( ss == NULL ) {			/* no directory, so use current */
    /*if(strrchr(path, ODIRSEPARATOR )==NULL)
      printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/
    /* get current working directory */
    /*    extern  char* getcwd ( char *buf , int len);*/
    if ( getcwd( dirc, FILENAME_MAX ) == NULL ) {
      return( GLOCK_ERROR_GETCWD );
    }
    strcpy( name, path );		/* we've got it */
  } else {				/* strip direcotry from path */
    ss++;				/* after this, the filename */
    l2 = strlen( ss );			/* length of filename */
    if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH );
    strcpy( name, ss );		/* save file name */
    strncpy( dirc, path, l1 - l2 );	/* now the directory */
    dirc[l1-l2] = 0;			/* add zero */
  }
  l1 = strlen( dirc );			/* length of directory */
  /*#ifdef windows
  if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }
#else
  if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; }
#endif
  */
  l1= strlen( name);
  ss = strrchr( name, '.' );		/* find last / */
  if (ss != '\0'){
    ss++;
    strcpy(ext,ss);			/* save extension */
    l2= strlen(ss)+1;
  }else{
    ext[0]='\0';
    l2 = 0;
  }
  strncpy( finame, name, l1-l2);
  finame[l1-l2]= 0;
  return( 0 );				/* we're done */
}

void trzb(char *z, char *in)
{
  /* Enlve les blancs en fin de cha ne et le caractre 0 qui se trouve
     au d but s'il y est */
  int i=0, j=0, k=0;
  int n;

  n =strlen(in);
/*   for(i=n;(i>=0) || (in[i]==' ');i--){ */
/*     printf ("i=%d in[i]=%s\n",i,in[i]); */
/*   } */
  k=0;
  if(in[0]== '0')
    k=1;
  for(j=k; j<=n;j++){
    if(in[j]==' '){
      z[j-k]='\0';
      break;
    }
    else
      z[j-k]=in[j];
  }
  z[j-k]='\0';
}

main(int argc, char *argv[])
{
  int numlinepar=0;
  long nobs, ncar,ncara, ncartes, nn;
  long c;
  long d;
  long numlis, ntype;
  long n, pos;
  int level, olevel;
  char scar;
  char s;

  char pathtot[MAXLINE], path[MAXLINE], optionfile[FILENAMELENGTH], optionfilext[FILENAMEEXTLEN];
  char optionfilefiname[FILENAMELENGTH];

  numlinepar=0;
  if(argc <=1){
    printf("\nEntrez le nom du fichier index binaire : ");
    scanf("%s",pathtot);
  }
  else{
    strcpy(pathtot,argv[1]);
  }
  split(pathtot,path,optionfile,optionfilext,optionfilefiname);
  printf("pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
  chdir(path);


  /* Log file */
  strcat(filelog, optionfilefiname);
  strcat(filelog,".log");    /* */
  if((ficlog=fopen(filelog,"w"))==NULL)    {
    printf("Problem with logfile %s\n",filelog);
    goto end;
  }
  fprintf(ficlog,"Log filename:%s\n",filelog);
  fprintf(ficlog,"\n%s\n%s",version,fullversion);
  fprintf(ficlog,"\nEntrez le nom du fichier d'index: ");
  fprintf(ficlog,"pathtot=%s\n\
 path=%s \n\
 optionfile=%s\n\
 optionfilext=%s\n\
 optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
  fflush(ficlog);


  if((ficpar=fopen(optionfile,"rb"))==NULL)    {
    printf("Problem with optionfile %s\n",optionfile);
    fprintf(ficlog,"Problem with optionfile %s\n",optionfile);
    fflush(ficlog);
    goto end;
  }

  strcpy(filereso,"o");
  strcat(filereso,optionfilefiname);
  strcat(filereso,".txt");
  if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
    printf("Problem with Output resultfile: %s\n", filereso);
    fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso);
    fflush(ficlog);
    goto end;
  }
  fprintf(ficparo,"Log filename:%s\n",filelog);
  fprintf(ficparo,"\n%s\n%s",version,fullversion);
  fprintf(ficparo,"\nEntrez le nom du fichier d'index: ");
  fprintf(ficparo,"pathtot=%s\n\
 path=%s \n\
 optionfile=%s\n\
 optionfilext=%s\n\
 optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
  fflush(ficparo);

  strcpy(filesas,"s");
  strcat(filesas,optionfilefiname);
  strcat(filesas,".sas");
  if((ficparsas=fopen(filesas,"w"))==NULL) { /* opened on subdirectory */
    printf("Problem with Output resultfile: %s\n", filesas);
    fprintf(ficlog,"Problem with Output resultfile: %s\n", filesas);
    fflush(ficlog);
    goto end;
  }
  fprintf(ficparsas,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion);
  fprintf(ficparsas,"libname optionfilefiname \"%s\";\n",path);
  fprintf(ficparsas,"filename a \"%s\";\n", filesas);
  fprintf(ficparsas,"* Ci dessous à modifier *;\n");
  fprintf(ficparsas,"data %s.?? (keep=??);\n",optionfilefiname);
  fprintf(ficparsas,"infile a lrecl=500 ;\n");
  fprintf(ficparsas,"input id 1. @; retain numero 0;\n");
  fprintf(ficparsas,"");
  fprintf(ficparsas,"");

  printf("Le nom du fichier de sortie est %s\n",filereso);
  printf("Le nom du fichier SAS de sortie est %s\n",filesas);

  pos=9;
  level=0;
  while((c=getc(ficpar)) != EOF){  
    ungetc(c,ficpar); 
    ntype=0;for(n=0;n<2;n++){ c=getc(ficpar); ntype+=(n+(1-n)*256)*ascii_to_ebcdic[c];} 
    fprintf(ficlog,"ntype=%d ",ntype); 
/*     printf("ntype=%d ",ntype); */
    switch(ntype){
    case 11 : /* 11*/
      nobs=0;
      for(n=0;n<2;n++){
	c=getc(ficpar);
	d=(n+(1-n)*256)*ascii_to_ebcdic[c];
	nobs+=d;
      }
      fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      printf(" %s\n", title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      break;
    case 12: /* 12 */
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      printf(" %s\n", title);
      ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<8;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      olevel=level;
      level=title[0]-48;
      printf(" Niveau = %d Colonnes 1  8 = %s\n",level,title);
      fprintf(ficparo," Niveau = %d Colonnes 1   8 = %s\n",level,title);
      if(level !=0) fprintf(ficparsas,"if id=%d then do;\n",level); 
	 /*       fprintf(ficparsas,"  input @9 "); */
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      break;
    case 10:  /* 10 = 142 ascii*/
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
      printf(" %s\n", title);
      trzb(namevar,title); 
      ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
      ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
      printf(" %s %d\n",namevar,ncara);
      fprintf(ficparo," %s %d\n",namevar,ncara);
      ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
      break;
    case 14: /* 14 */
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
      trzb(namevar,title); 
      printf("%d %20s ",level, namevar);
      fprintf(ficparo,"%d %20s ",level, namevar);
      fprintf(ficlog,"Variable \"%s\" \n",namevar);
      ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
      printf(" %6d",ncara); /* Nombre de caractres */
      fprintf(ficparo," %6d",ncara); /* Nombre de caract res */
      ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';  fprintf(ficlog,"%s ",title);
      trzb(namevara,title); 
      printf("%10s ", namevara); /* Association */
      fprintf(ficparo,"%10s ", namevara); /* Association */
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"\"%s\"",title);
      printf("%3s", title); /* Brute C ou Calcule R */
      fprintf(ficparo,"%3s", title); /* Brute C ou Calcul e R */
      if(strrchr(title,'C')!= 0 || strrchr(title,'G')!=0){
	if(level!=olevel){
	  pos=9;
	  if(olevel !=0){
	    fprintf(ficparsas,"  output %s.%d;\n",optionfilefiname,olevel);
	    fprintf(ficparsas,"  end\n");
	  }
	  if(level !=1) fprintf(ficparsas,";\n else if id=%d then do;\n",level);
	  fprintf(ficparsas,"  input @9 ");
	  olevel=level;
	}
	printf(" %d-%d", pos, pos+(ncara-1));
	fprintf(ficparo," %d-%d", pos, pos+(ncara-1));
	for(n=0;n<strlen(namevar);n++){
	  if(namevar[n]=='-')
	    break;
	}
	namevar[n]='\0';
	fprintf(ficparsas, " %s $%d.", namevar, ncara);
	pos+=ncara;
      }
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
      trzb(namevar,title); 
      printf(" %10s\n", namevar); /* format */
      fprintf(ficparo," %10s", namevar); /* format */
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      break;
    default: fprintf(ficlog,"Warning ntype=%d cas non prvu, voir les fichiers sources",ntype);
      nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
      for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
      printf(" %s\n", title);
    }
    n=0;
    while((c=getc(ficpar)) !='\r'){
      nn= n % ncara;
      title[nn]=c; 
      if(nn==ncara-1){
	title[nn+1]='\0';
	fprintf(ficlog," \"%s\"",title);
	printf(" \"%s\"",title);
	fprintf(ficparo," \"%s\"",title);
	n=n+1;
      }else{
	n=n+1;
      }
    }
    if(c=='\r')
      if((c=getc(ficpar))=='\n');
      else ungetc(c,ficpar);
    fprintf(ficlog,"\n");
    fprintf(ficparo,"\n");
  } 
  fprintf(ficparsas,";\n  output %s%d;\n end;\n else input;\n run;",optionfilefiname,level);
  fclose(ficparsas);
  printf("Le nom du fichier de debug est %s\n",filelog);
  printf("Le nom du fichier du format de sortie est %s\n",filereso);
  printf("Le nom du fichier SAS de sortie est %s\n",filesas);
  fclose(ficpar);
  fclose(ficparo);
  fclose(ficlog);
  exit(0);
 end: 
    fclose(ficlog);
    exit(1);

}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>