1: /* $Id: rleda.c,v 1.2 2003/12/12 19:08:17 brouard Exp $
2: $State: Exp $
3: $Log: rleda.c,v $
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:
8: Revision 1.1.1.1 2003/12/12 18:53:44 brouard
9: Import de rleda
10:
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:
39: char version[]="rleda-0.9.1 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 $";
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:
48: FILE *ficlog, *ficres, *ficpar, *ficparo, *ficparsas;
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: {
234: int numlinepar=0;
235: long nobs, ncar,ncara, ncartes, nn, nvaris=0;
236: long c;
237: long d;
238: long numlis, ntype;
239: long n, pos;
240: int level, olevel;
241: char scar;
242: char s;
243:
244: char pathtot[MAXLINE], path[MAXLINE], optionfile[FILENAMELENGTH], optionfilext[FILENAMEEXTLEN];
245: char optionfilefiname[FILENAMELENGTH];
246:
247: numlinepar=0;
248: if(argc <=1){
249: printf("\nEntrez le nom du fichier index binaire : ");
250: scanf("%s",pathtot);
251: }
252: else{
253: strcpy(pathtot,argv[1]);
254: }
255: split(pathtot,path,optionfile,optionfilext,optionfilefiname);
256: printf("pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
257: chdir(path);
258:
259:
260: /* Log file */
261: strcat(filelog, optionfilefiname);
262: strcat(filelog,".log"); /* */
263: if((ficlog=fopen(filelog,"w"))==NULL) {
264: printf("Problem with logfile %s\n",filelog);
265: goto end;
266: }
267: fprintf(ficlog,"Log filename:%s\n",filelog);
268: fprintf(ficlog,"\n%s\n%s",version,fullversion);
269: fprintf(ficlog,"\nEntrez le nom du fichier d'index: ");
270: fprintf(ficlog,"pathtot=%s\n\
271: path=%s \n\
272: optionfile=%s\n\
273: optionfilext=%s\n\
274: optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
275: fflush(ficlog);
276:
277:
278: if((ficpar=fopen(optionfile,"rb"))==NULL) {
279: printf("Problem with optionfile %s\n",optionfile);
280: fprintf(ficlog,"Problem with optionfile %s\n",optionfile);
281: fflush(ficlog);
282: goto end;
283: }
284:
285: strcpy(filereso,"o");
286: strcat(filereso,optionfilefiname);
287: strcat(filereso,".txt");
288: if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
289: printf("Problem with Output resultfile: %s\n", filereso);
290: fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso);
291: fflush(ficlog);
292: goto end;
293: }
294: fprintf(ficparo,"Log filename:%s\n",filelog);
295: fprintf(ficparo,"\n%s\n%s",version,fullversion);
296: fprintf(ficparo,"\nEntrez le nom du fichier d'index: ");
297: fprintf(ficparo,"pathtot=%s\n\
298: path=%s \n\
299: optionfile=%s\n\
300: optionfilext=%s\n\
301: optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
302: fflush(ficparo);
303:
304: strcpy(filesas,"s");
305: strcat(filesas,optionfilefiname);
306: strcat(filesas,".sas");
307: if((ficparsas=fopen(filesas,"w"))==NULL) { /* opened on subdirectory */
308: printf("Problem with Output resultfile: %s\n", filesas);
309: fprintf(ficlog,"Problem with Output resultfile: %s\n", filesas);
310: fflush(ficlog);
311: goto end;
312: }
313: fprintf(ficparsas,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion);
314: fprintf(ficparsas,"libname %s \"%s\";\n",optionfilefiname,path);
315: fprintf(ficparsas,"filename a \"%s.dat\";\n",optionfilefiname );
316: fprintf(ficparsas,"* Ci dessous a modifier *;\n");
317: fprintf(ficparsas,"data %s.u?? (keep=??);\n",optionfilefiname);
318: fprintf(ficparsas,"infile a lrecl=500 ;\n");
319: fprintf(ficparsas,"input id 1. @; retain numero 0;\n");
320: fprintf(ficparsas,"");
321: fprintf(ficparsas,"");
322:
323: printf("Le nom du fichier de sortie est %s\n",filereso);
324: printf("Le nom du fichier SAS de sortie est %s\n",filesas);
325:
326: pos=9;nvaris=0 ;
327: level=0;
328: while((c=getc(ficpar)) != EOF){
329: ungetc(c,ficpar);
330: ntype=0;for(n=0;n<2;n++){ c=getc(ficpar); ntype+=(n+(1-n)*256)*ascii_to_ebcdic[c];}
331: fprintf(ficlog,"ntype=%d ",ntype);
332: /* printf("ntype=%d ",ntype); */
333: switch(ntype){
334: case 11 : /* 11*/
335: nobs=0;
336: for(n=0;n<2;n++){
337: c=getc(ficpar);
338: d=(n+(1-n)*256)*ascii_to_ebcdic[c];
339: nobs+=d;
340: }
341: fprintf(ficlog,"nobs=%d ",nobs);
342: 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);
343: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
344: printf(" %s\n", title);
345: 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);
346: 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);
347: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
348: 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);
349: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
350: 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);
351: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
352: 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);
353: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
354: 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);
355: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
356: break;
357: case 12: /* 12 */
358: 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);
359: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
360: printf(" %s\n", title);
361: 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);
362: 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);
363: for(n=0;n<8;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
364: olevel=level;
365: level=title[0]-48;
366: printf(" Niveau = %d Colonnes 1 8 = %s\n",level,title);
367: fprintf(ficlog," Niveau = %d Colonnes 1 8 = %s\n",level,title);
368: fprintf(ficparo," Niveau = %d Colonnes 1 8 = %s\n",level,title);
369: if(level ==0) fprintf(ficparsas,"if id=%d then do;\n",level);
370: /* fprintf(ficparsas," input @9 "); */
371: 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);
372: 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);
373: 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);
374: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
375: 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);
376: for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title);
377: 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);
378: break;
379: case 10: /* 10 = 142 ascii*/
380: 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);
381: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
382: printf(" %s\n", title);
383: trzb(namevar,title);
384: 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);
385: 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);
386: 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);
387: 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);
388: printf(" %s %d\n",namevar,ncara);
389: fprintf(ficparo," %s %d\n",namevar,ncara);
390: 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);
391: break;
392: case 14: /* 14 */
393: 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);
394: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
395: trzb(namevar,title);
396: printf("%d %20s ",level, namevar);
397: fprintf(ficparo,"%d %20s ",level, namevar);
398: fprintf(ficlog,"Variable \"%s\" \n",namevar);
399: 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);
400: 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);
401: 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);
402: printf(" %6d",ncara); /* Nombre de caractres */
403: fprintf(ficparo," %6d",ncara); /* Nombre de caract res */
404: 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);
405: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
406: trzb(namevara,title);
407: printf("%10s ", namevara); /* Association */
408: fprintf(ficparo,"%10s ", namevara); /* Association */
409: 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);
410: 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);
411: for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"\"%s\"",title);
412: printf("%3s", title); /* Brute C ou Calcule R */
413: fprintf(ficparo,"%3s", title); /* Brute C ou Calcul e R */
414: if(strrchr(title,'C')!= 0 || strrchr(title,'G')!=0){
415: if(level!=olevel){
416: pos=9;
417: fprintf(ficparsas,";\n output %s.u%d;\n",optionfilefiname,olevel);
418: fprintf(ficparsas," end\n");
419: if(level !=0) fprintf(ficparsas,";\n else if id=%d then do;\n",level);
420: fprintf(ficparsas," input @9 ");
421: olevel=level;
422: }
423: printf(" %d-%d", pos, pos+(ncara-1));
424: fprintf(ficparo," %d-%d", pos, pos+(ncara-1));
425: for(n=0;n<strlen(namevar);n++){
426: if(namevar[n]=='-')
427: break;
428: }
429: namevar[n]='\0';
430: fprintf(ficparsas, " %s $%d.", namevar, ncara);
431: pos+=ncara;nvaris++ ;
432: if (nvaris>=5) {
433: fprintf(ficparsas,"\n ") ;
434: nvaris=0 ;
435: }
436: }
437: 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);
438: 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);
439: 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);
440: 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);
441: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
442: trzb(namevar,title);
443: printf(" %10s\n", namevar); /* format */
444: fprintf(ficparo," %10s", namevar); /* format */
445: 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);
446: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title);
447: 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);
448: break;
449: default: fprintf(ficlog,"Warning ntype=%d cas non prvu, voir les fichiers sources",ntype);
450: 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);
451: for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title);
452: printf(" %s\n", title);
453: }
454: n=0;
455: while((c=getc(ficpar)) !='\r'){
456: nn= n % ncara;
457: title[nn]=c;
458: if(nn==ncara-1){
459: title[nn+1]='\0';
460: fprintf(ficlog," \"%s\"",title);
461: printf(" \"%s\"",title);
462: fprintf(ficparo," \"%s\"",title);
463: n=n+1;
464: }else{
465: n=n+1;
466: }
467: }
468: if(c=='\r')
469: if((c=getc(ficpar))=='\n');
470: else ungetc(c,ficpar);
471: fprintf(ficlog,"\n");
472: fprintf(ficparo,"\n");
473: }
474: fprintf(ficparsas,";\n output %s.u%d;\n end;\n else input;\n run;",optionfilefiname,level);
475: fclose(ficparsas);
476: printf("Le nom du fichier de debug est %s\n",filelog);
477: printf("Le nom du fichier du format de sortie est %s\n",filereso);
478: printf("Le nom du fichier SAS de sortie est %s\n",filesas);
479: fclose(ficpar);
480: fclose(ficparo);
481: fclose(ficlog);
482: exit(0);
483: end:
484: fclose(ficlog);
485: exit(1);
486:
487: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>