Annotation of rleda/rleda.c, revision 1.3
1.3 ! brouard 1: /* $Id: rleda.c,v 1.2 2003/12/12 19:08:17 brouard Exp $
1.2 brouard 2: $State: Exp $
3: $Log: rleda.c,v $
1.3 ! brouard 4: Revision 1.2 2003/12/12 19:08:17 brouard
! 5: Les variables ne sont plus toutes écrites en ligne mais avec un retour
! 6: à la ligne toutes les 5 variables.
! 7:
1.2 brouard 8: Revision 1.1.1.1 2003/12/12 18:53:44 brouard
9: Import de rleda
10:
1.1 brouard 11:
12: rleda.c
13: Programme pour lire une fichier d'index de LEDA qui a t converti de l'EBCDIC vers l'ascii
14: Nicolas Brouard (Institut national d'tudes d mographiques)
15: Usage : rleda nom_d_index
16: Il y a plusieurs sorties, un log (pour le debug) un .txt pour le format et
17: un .sas pour le sas.
18: Je me suis inspir de la version sas d'Andr Wielki (INED).
19: Mardi 25 novembre 2003
20: */
21: #include <stdio.h>
22: #include <string.h>
23: #include <unistd.h>
24:
25: #define MAXLINE 300
26: #define FILENAMELENGTH 300
27: #define FILENAMEEXTLEN 10
28: #define GLOCK_ERROR_NOPATH -1 /* empty path */
29: #define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */
30:
31: #ifdef unix
32: #define DIRSEPARATOR '/'
33: #define ODIRSEPARATOR '\\'
34: #else
35: #define DIRSEPARATOR '\\'
36: #define ODIRSEPARATOR '/'
37: #endif
38:
1.3 ! brouard 39: char version[]="rleda-0.9.2 Programme de lecture de fichiers d'index au format LEDA convertis de l'EBCDIC en ASCII ";
! 40: char fullversion[]="$Revision: 1.2 $ $Date: 2003/12/12 19:08:17 $";
1.1 brouard 41: char line[MAXLINE];
42: char title[MAXLINE],namevar[MAXLINE], namevara[MAXLINE];
43:
44: char fileres[FILENAMELENGTH], filereso[FILENAMELENGTH];
45: char filesas[FILENAMELENGTH]; /* SAS file */
46: char filelog[FILENAMELENGTH]; /* Log file */
47:
1.3 ! brouard 48: FILE *ficlog, *ficres, *ficdat, *ficreso, *ficsas;
1.1 brouard 49:
50:
51: static unsigned char const ascii_to_ebcdic[] =
52: {
53: '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',
54: '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',
55: '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',
56: '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',
57: '\100', '\117', '\177', '\173', '\133', '\154', '\120', '\175',
58: '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',
59: '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
60: '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',
61: '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
62: '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',
63: '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',
64: '\347', '\350', '\351', '\112', '\340', '\132', '\137', '\155',
65: '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
66: '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',
67: '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',
68: '\247', '\250', '\251', '\300', '\152', '\320', '\241', '\007',
69: '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',
70: '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',
71: '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',
72: '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',
73: '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',
74: '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
75: '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',
76: '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',
77: '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',
78: '\216', '\217', '\220', '\232', '\233', '\234', '\235', '\236',
79: '\237', '\240', '\252', '\253', '\254', '\255', '\256', '\257',
80: '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
81: '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
82: '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',
83: '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',
84: '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'
85: };
86:
87: static unsigned char const ascii_to_ibm[] =
88: {
89: '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',
90: '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',
91: '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',
92: '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',
93: '\100', '\132', '\177', '\173', '\133', '\154', '\120', '\175',
94: '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',
95: '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
96: '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',
97: '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
98: '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',
99: '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',
100: '\347', '\350', '\351', '\255', '\340', '\275', '\137', '\155',
101: '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
102: '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',
103: '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',
104: '\247', '\250', '\251', '\300', '\117', '\320', '\241', '\007',
105: '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',
106: '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',
107: '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',
108: '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',
109: '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',
110: '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
111: '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',
112: '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',
113: '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',
114: '\216', '\217', '\220', '\232', '\233', '\234', '\235', '\236',
115: '\237', '\240', '\252', '\253', '\254', '\255', '\256', '\257',
116: '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
117: '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
118: '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',
119: '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',
120: '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'
121: };
122:
123: static unsigned char const ebcdic_to_ascii[] =
124: {
125: '\000', '\001', '\002', '\003', '\234', '\011', '\206', '\177',
126: '\227', '\215', '\216', '\013', '\014', '\015', '\016', '\017',
127: '\020', '\021', '\022', '\023', '\235', '\205', '\010', '\207',
128: '\030', '\031', '\222', '\217', '\034', '\035', '\036', '\037',
129: '\200', '\201', '\202', '\203', '\204', '\012', '\027', '\033',
130: '\210', '\211', '\212', '\213', '\214', '\005', '\006', '\007',
131: '\220', '\221', '\026', '\223', '\224', '\225', '\226', '\004',
132: '\230', '\231', '\232', '\233', '\024', '\025', '\236', '\032',
133: '\040', '\240', '\241', '\242', '\243', '\244', '\245', '\246',
134: '\247', '\250', '\133', '\056', '\074', '\050', '\053', '\041',
135: '\046', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
136: '\260', '\261', '\135', '\044', '\052', '\051', '\073', '\136',
137: '\055', '\057', '\262', '\263', '\264', '\265', '\266', '\267',
138: '\270', '\271', '\174', '\054', '\045', '\137', '\076', '\077',
139: '\272', '\273', '\274', '\275', '\276', '\277', '\300', '\301',
140: '\302', '\140', '\072', '\043', '\100', '\047', '\075', '\042',
141: '\303', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
142: '\150', '\151', '\304', '\305', '\306', '\307', '\310', '\311',
143: '\312', '\152', '\153', '\154', '\155', '\156', '\157', '\160',
144: '\161', '\162', '\313', '\314', '\315', '\316', '\317', '\320',
145: '\321', '\176', '\163', '\164', '\165', '\166', '\167', '\170',
146: '\171', '\172', '\322', '\323', '\324', '\325', '\326', '\327',
147: '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
148: '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
149: '\173', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
150: '\110', '\111', '\350', '\351', '\352', '\353', '\354', '\355',
151: '\175', '\112', '\113', '\114', '\115', '\116', '\117', '\120',
152: '\121', '\122', '\356', '\357', '\360', '\361', '\362', '\363',
153: '\134', '\237', '\123', '\124', '\125', '\126', '\127', '\130',
154: '\131', '\132', '\364', '\365', '\366', '\367', '\370', '\371',
155: '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
156: '\070', '\071', '\372', '\373', '\374', '\375', '\376', '\377'
157: };
158:
159: /**************** split *************************/
160: static int split( char *path, char *dirc, char *name, char *ext, char *finame )
161: {
162: char *ss; /* pointer */
163: int l1, l2; /* length counters */
164:
165: l1 = strlen(path ); /* length of path */
166: if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
167: ss= strrchr( path, DIRSEPARATOR ); /* find last / */
168: if ( ss == NULL ) { /* no directory, so use current */
169: /*if(strrchr(path, ODIRSEPARATOR )==NULL)
170: printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/
171: /* get current working directory */
172: /* extern char* getcwd ( char *buf , int len);*/
173: if ( getcwd( dirc, FILENAME_MAX ) == NULL ) {
174: return( GLOCK_ERROR_GETCWD );
175: }
176: strcpy( name, path ); /* we've got it */
177: } else { /* strip direcotry from path */
178: ss++; /* after this, the filename */
179: l2 = strlen( ss ); /* length of filename */
180: if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH );
181: strcpy( name, ss ); /* save file name */
182: strncpy( dirc, path, l1 - l2 ); /* now the directory */
183: dirc[l1-l2] = 0; /* add zero */
184: }
185: l1 = strlen( dirc ); /* length of directory */
186: /*#ifdef windows
187: if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }
188: #else
189: if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; }
190: #endif
191: */
192: l1= strlen( name);
193: ss = strrchr( name, '.' ); /* find last / */
194: if (ss != '\0'){
195: ss++;
196: strcpy(ext,ss); /* save extension */
197: l2= strlen(ss)+1;
198: }else{
199: ext[0]='\0';
200: l2 = 0;
201: }
202: strncpy( finame, name, l1-l2);
203: finame[l1-l2]= 0;
204: return( 0 ); /* we're done */
205: }
206:
207: void trzb(char *z, char *in)
208: {
209: /* Enlve les blancs en fin de cha ne et le caractre 0 qui se trouve
210: au d but s'il y est */
211: int i=0, j=0, k=0;
212: int n;
213:
214: n =strlen(in);
215: /* for(i=n;(i>=0) || (in[i]==' ');i--){ */
216: /* printf ("i=%d in[i]=%s\n",i,in[i]); */
217: /* } */
218: k=0;
219: if(in[0]== '0')
220: k=1;
221: for(j=k; j<=n;j++){
222: if(in[j]==' '){
223: z[j-k]='\0';
224: break;
225: }
226: else
227: z[j-k]=in[j];
228: }
229: z[j-k]='\0';
230: }
231:
232: main(int argc, char *argv[])
233: {
1.3 ! brouard 234: int numlinepar=0, ilect=0, firstpass=0;
! 235: long nobs=0, ncar=0,ncara=0, ncartes=0, nn=0, nvaris=0;
1.1 brouard 236: long c;
237: long d;
238: long numlis, ntype;
239: long n, pos;
1.3 ! brouard 240: int level, olevel, levelmax;
1.1 brouard 241: char scar;
242: char s;
1.3 ! brouard 243: char var1[4][10], varn[4][10];
1.1 brouard 244:
1.3 ! brouard 245: char pathtot[MAXLINE], path[MAXLINE], indexfile[FILENAMELENGTH], indexfilext[FILENAMEEXTLEN];
! 246: char indexfilefiname[FILENAMELENGTH];
1.1 brouard 247:
248: numlinepar=0;
249: if(argc <=1){
1.3 ! brouard 250: printf("\nEntrez le nom du fichier index binaire (dtrirdex) : ");
1.1 brouard 251: scanf("%s",pathtot);
252: }
253: else{
254: strcpy(pathtot,argv[1]);
255: }
1.3 ! brouard 256: split(pathtot,path,indexfile,indexfilext,indexfilefiname);
! 257: printf("pathtot=%s,\npath=%s,\nindexfile=%s \nindexfilext=%s \nindexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname);
1.1 brouard 258: chdir(path);
259:
260:
261: /* Log file */
1.3 ! brouard 262: strcat(filelog, indexfilefiname);
1.1 brouard 263: strcat(filelog,".log"); /* */
264: if((ficlog=fopen(filelog,"w"))==NULL) {
265: printf("Problem with logfile %s\n",filelog);
266: goto end;
267: }
268: fprintf(ficlog,"Log filename:%s\n",filelog);
269: fprintf(ficlog,"\n%s\n%s",version,fullversion);
270: fprintf(ficlog,"\nEntrez le nom du fichier d'index: ");
271: fprintf(ficlog,"pathtot=%s\n\
272: path=%s \n\
1.3 ! brouard 273: indexfile=%s\n\
! 274: indexfilext=%s\n\
! 275: indexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname);
1.1 brouard 276: fflush(ficlog);
277:
278:
279:
280: strcpy(filereso,"o");
1.3 ! brouard 281: strcat(filereso,indexfilefiname);
1.1 brouard 282: strcat(filereso,".txt");
1.3 ! brouard 283: if((ficreso=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
1.1 brouard 284: printf("Problem with Output resultfile: %s\n", filereso);
285: fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso);
286: fflush(ficlog);
287: goto end;
288: }
1.3 ! brouard 289: fprintf(ficreso,"Log filename:%s\n",filelog);
! 290: fprintf(ficreso,"\n%s\n%s",version,fullversion);
! 291: fprintf(ficreso,"\nEntrez le nom du fichier d'index: ");
! 292: fprintf(ficreso,"pathtot=%s\n\
1.1 brouard 293: path=%s \n\
1.3 ! brouard 294: indexfile=%s\n\
! 295: indexfilext=%s\n\
! 296: indexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname);
! 297: fflush(ficreso);
1.1 brouard 298:
299: strcpy(filesas,"s");
1.3 ! brouard 300: strcat(filesas,indexfilefiname);
1.1 brouard 301: strcat(filesas,".sas");
302:
303: printf("Le nom du fichier de sortie est %s\n",filereso);
304: printf("Le nom du fichier SAS de sortie est %s\n",filesas);
305:
1.3 ! brouard 306: for(ilect=1;ilect<=2;ilect++){
! 307: pos=9;nvaris=0 ;
! 308: level=0;
! 309: printf("Lecture du fichier d index pour la %d fois\n",ilect);
! 310: if((ficdat=fopen(indexfile,"rb"))==NULL) {
! 311: printf("Problem with binary file %s\n",indexfile);
! 312: fprintf(ficlog,"Problem with binary file %s\n",indexfile);
! 313: fflush(ficlog);
! 314: goto end;
! 315: }
! 316: if(ilect==2){
! 317: if((ficsas=fopen(filesas,"w"))==NULL) { /* opened on subdirectory */
! 318: printf("Problem with Output resultfile: %s\n", filesas);
! 319: fprintf(ficlog,"Problem with Output resultfile: %s\n", filesas);
! 320: fflush(ficlog);
! 321: goto end;
! 322: }
! 323: fprintf(ficsas,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion);
! 324: fprintf(ficsas,"libname %s \"%s\";\n",indexfilefiname,path);
! 325: fprintf(ficsas,"filename a \"%s.dat\";\n",indexfilefiname );
! 326: fprintf(ficsas,"* Ci dessous a modifier eventuellement *;\n");
! 327: fprintf(ficsas,"data %s.%s0 (keep=ID)\n",indexfilefiname,indexfilefiname);
! 328: for(level=1; level <=levelmax; level++){
! 329: fprintf(ficsas," %s.%s%d (keep=%s--%s)\n",indexfilefiname,indexfilefiname,level,var1[level],varn[level]);
1.1 brouard 330: }
1.3 ! brouard 331: fprintf(ficsas," ;\n");
! 332: fprintf(ficsas," infile a lrecl=500 ;\n");
! 333: fprintf(ficsas," input id 1. @; \n");
! 334: fprintf(ficsas,"");
! 335: fprintf(ficsas,"");
! 336: }
! 337: while((c=getc(ficdat)) != EOF){
! 338: ungetc(c,ficdat);
! 339: ntype=0;for(n=0;n<2;n++){ c=getc(ficdat); ntype+=(n+(1-n)*256)*ascii_to_ebcdic[c];}
! 340: fprintf(ficlog,"ntype=%d ",ntype);
! 341: /* printf("ntype=%d ",ntype); */
! 342: switch(ntype){
! 343: case 11 : /* 11*/
! 344: nobs=0;
! 345: for(n=0;n<2;n++){
! 346: c=getc(ficdat);
! 347: d=(n+(1-n)*256)*ascii_to_ebcdic[c];
! 348: nobs+=d;
1.1 brouard 349: }
1.3 ! brouard 350: fprintf(ficlog,"nobs=%d ",nobs);
! 351: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 352: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 353: printf(" %s\n", title);
! 354: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 355: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 356: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 357: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 358: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 359: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 360: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 361: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 362: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 363: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 364: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 365: break;
! 366: case 12: /* 12 */
! 367: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 368: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 369: printf(" %s\n", title);
! 370: ncartes=0;for(n=0;n<2;n++){ c=getc(ficdat); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
! 371: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 372: for(n=0;n<8;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 373: olevel=level;
! 374: level=title[0]-48;
! 375: printf(" Niveau = %d Colonnes 1 8 = %s\n",level,title);
! 376: fprintf(ficlog," Niveau = %d Colonnes 1 8 = %s\n",level,title);
! 377: fprintf(ficreso," Niveau = %d Colonnes 1 8 = %s\n",level,title);
! 378: if(level ==0){
! 379: if(ilect==2){
! 380: fprintf(ficsas," if id=%d then do;\n",level);
! 381: /* fprintf(ficsas," input @9 "); */
! 382: }
1.1 brouard 383: }
1.3 ! brouard 384: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 385: ncara=0;for(n=0;n<2;n++){ c=getc(ficdat); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
! 386: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 387: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 388: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 389: for(n=0;n<2;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
! 390: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 391: break;
! 392: case 10: /* 10 = 142 ascii*/
! 393: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 394: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
! 395: printf(" %s\n", title);
! 396: trzb(namevar,title);
! 397: ncartes=0;for(n=0;n<2;n++){ c=getc(ficdat); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
! 398: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 399: ncara=0;for(n=0;n<2;n++){ c=getc(ficdat); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
! 400: ncar=0;for(n=0;n<2;n++){ c=getc(ficdat); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
! 401: printf(" %s %d\n",namevar,ncara);
! 402: fprintf(ficreso," %s %d\n",namevar,ncara);
! 403: ncar=0;for(n=0;n<2;n++){ c=getc(ficdat); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
! 404: break;
! 405: case 14: /* 14 */
! 406: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 407: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
! 408: trzb(namevar,title);
! 409: printf("%d %20s ", level, namevar);
! 410: fprintf(ficreso,"%d %20s ",level, namevar);
! 411: fprintf(ficlog,"Variable \"%s\" \n",namevar);
! 412: ncartes=0;for(n=0;n<2;n++){ c=getc(ficdat); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes);
! 413: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 414: ncara=0;for(n=0;n<2;n++){ c=getc(ficdat); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara);
! 415: printf(" %6d",ncara); /* Nombre de caractres */
! 416: fprintf(ficreso," %6d",ncara); /* Nombre de caract res */
! 417: ncar=0;for(n=0;n<2;n++){ c=getc(ficdat); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar);
! 418: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
! 419: trzb(namevara,title);
! 420: printf("%10s ", namevara); /* Association */
! 421: fprintf(ficreso,"%10s ", namevara); /* Association */
! 422: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 423: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 424: for(n=0;n<2;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0';fprintf(ficlog,"\"%s\"",title);
! 425: printf("%3s", title); /* Brute C ou Calcule R */
! 426: fprintf(ficreso,"%3s", title); /* Brute C ou Calcul e R */
! 427: if(strrchr(title,'C')!= 0 || strrchr(title,'G')!=0){
! 428: if(level!=olevel){
! 429: pos=9;
! 430: firstpass=0;
! 431: if(ilect==2){
! 432: fprintf(ficsas," ;\n output %s.%s%d;\n",indexfilefiname,indexfilefiname,olevel);
! 433: fprintf(ficsas," end\n");
! 434: }
! 435: if(level !=0)
! 436: if(ilect==2){
! 437: fprintf(ficsas," ;\n else if id=%d then do;\n",level);
! 438: }
! 439: if(ilect==2){
! 440: fprintf(ficsas," input @9 ");
! 441: printf(" input @9 ");
! 442: }
! 443: if(ilect==1){
! 444: levelmax=level;
! 445: }
! 446: olevel=level;
! 447: }
! 448: printf(" %d-%d", pos, pos+(ncara-1));
! 449: fprintf(ficreso," %d-%d", pos, pos+(ncara-1));
! 450: for(n=0;n<strlen(namevar);n++){
! 451: if(namevar[n]=='-')
! 452: break;
! 453: }
! 454: namevar[n]='\0';
! 455: if(ilect==1){
! 456: if(firstpass==0){
! 457: strcpy(var1[level],namevar);
! 458: printf(" Variable premiere %s, niveau %d namevar=%s\n",var1[level],level, namevar);
! 459: firstpass=1;
! 460: }
! 461: else{
! 462: strcpy(varn[level],namevar);
! 463: printf(" Variable N %s, niveau %d namevar=%s\n",varn[level],level, namevar);
! 464: }
! 465: }
! 466: if(ilect==2){
! 467: fprintf(ficsas, " %s $%d.", namevar, ncara);
! 468: }
! 469: pos+=ncara;nvaris++ ;
! 470: if (nvaris>=5) {
! 471: if(ilect==2){
! 472: fprintf(ficsas,"\n ") ;
! 473: }
! 474: nvaris=0 ;
! 475: }
1.2 brouard 476: }
1.3 ! brouard 477: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 478: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 479: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 480: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 481: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
! 482: trzb(namevar,title);
! 483: printf(" %10s\n", namevar); /* format */
! 484: fprintf(ficreso," %10s", namevar); /* format */
! 485: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 486: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
! 487: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 488: break;
! 489: default: fprintf(ficlog,"Warning ntype=%d cas non prvu, voir les fichiers sources",ntype);
! 490: nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs);
! 491: for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
! 492: printf(" %s\n", title);
1.1 brouard 493: }
1.3 ! brouard 494: n=0;
! 495: while((c=getc(ficdat)) !='\r'){
! 496: if(ncara != 0)
! 497: nn= n % ncara;
! 498: else
! 499: nn=0;
! 500: title[nn]=c;
! 501: if(nn==ncara-1){
! 502: title[nn+1]='\0';
! 503: fprintf(ficlog," \"%s\"",title);
! 504: printf(" \"%s\"",title);
! 505: fprintf(ficreso," \"%s\"",title);
! 506: n=n+1;
! 507: }else{
! 508: n=n+1;
! 509: }
1.1 brouard 510: }
1.3 ! brouard 511: if(c=='\r')
! 512: if((c=getc(ficdat))=='\n');
! 513: else ungetc(c,ficdat);
! 514: fprintf(ficlog,"\n");
! 515: fprintf(ficreso,"\n");
! 516: } /* End of read loop */
! 517: fclose(ficdat);
! 518: } /* End loop ilect */
! 519:
! 520: fprintf(ficsas," ;\n output %s.%s%d;\n end;\n else input;\nrun;\n",indexfilefiname,indexfilefiname,level);
! 521: for(level=0; level <=levelmax; level++){
! 522: fprintf(ficsas,"proc contents data=%s.%s%d;run;\n",indexfilefiname,indexfilefiname,level);
! 523: }
! 524: fclose(ficsas);
1.1 brouard 525: printf("Le nom du fichier de debug est %s\n",filelog);
526: printf("Le nom du fichier du format de sortie est %s\n",filereso);
527: printf("Le nom du fichier SAS de sortie est %s\n",filesas);
1.3 ! brouard 528: fclose(ficreso);
1.1 brouard 529: fclose(ficlog);
530: exit(0);
531: end:
532: fclose(ficlog);
533: exit(1);
534:
535: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>