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