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