1 | //gcc ylmodf.c -Wall -o ylmodf |
---|
2 | |
---|
3 | #include <stdlib.h> |
---|
4 | #include <stdio.h> |
---|
5 | #include <string.h> |
---|
6 | |
---|
7 | #define BUFSIZE 2048 |
---|
8 | #define LG_MAX_NAME 24 |
---|
9 | #define LG_STR80 80 |
---|
10 | |
---|
11 | FILE *fpin, *fpout; |
---|
12 | char buffer[BUFSIZE+1]; |
---|
13 | int nbenrlus; |
---|
14 | int nbitem; |
---|
15 | char modname[LG_MAX_NAME+1]; |
---|
16 | int nbi, nbo, mode, prodlev; |
---|
17 | int wi; |
---|
18 | char cdesys[LG_STR80+1]; |
---|
19 | |
---|
20 | //========================================================== |
---|
21 | int main(int argc, char *argv[]) |
---|
22 | { //syntaxe: ylmodf filein fileout [mode] |
---|
23 | // mode determine le mode d'ecriture du fichier filout : |
---|
24 | // avec mode = 1, >> dans filout |
---|
25 | // mode = 0, raz de filout |
---|
26 | // mais attention, ce mode est positionne selon en priorite : |
---|
27 | // - le 2eme caratere du 1er enregistrement de filin a condition |
---|
28 | // qu'il commence par un diese et qu'il valle 0 ou 1 |
---|
29 | // - le mode passe en parametre qui doit valoir 0 ou 1, |
---|
30 | // - et par defaut, mode = 1 |
---|
31 | printf("\n"); |
---|
32 | |
---|
33 | /* debut : verif arg, ouverture fichier ... */ |
---|
34 | if (argc<3 || argc>4) |
---|
35 | { printf (" > ylmodf: syntaxe error: ylmodf file_in file_out [mode]\n"); |
---|
36 | exit(-9); |
---|
37 | } |
---|
38 | if ((fpin = fopen(argv[1], "r")) <= 0) |
---|
39 | { printf (" > ylmodf: problem when opening %s \n", argv[1]); |
---|
40 | exit(-9); |
---|
41 | } |
---|
42 | if (argc==3) mode = 1; |
---|
43 | if (argc==4) mode = atoi(argv[3]); |
---|
44 | if (mode!=0 && mode!=1) |
---|
45 | { printf(" > ylmodf: error on mode value (%i), must 0 to RAZ or 1 to CONCAT\n", mode); |
---|
46 | } |
---|
47 | /*-------------------------- |
---|
48 | if (mode==0) |
---|
49 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
50 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
51 | exit(-9); |
---|
52 | } |
---|
53 | } |
---|
54 | else //=>mode==1 |
---|
55 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
56 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
57 | exit(-9); |
---|
58 | } |
---|
59 | } |
---|
60 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
61 | */ |
---|
62 | |
---|
63 | //------------------------------------------------------------------- |
---|
64 | nbenrlus=0; |
---|
65 | while ( (fgets(buffer, BUFSIZE+1, fpin)) != NULL) |
---|
66 | { ++nbenrlus; |
---|
67 | |
---|
68 | nbitem=sscanf(buffer, "%s %i %i %i", modname, &nbi, &nbo, &prodlev); |
---|
69 | //printf(" %i> %s %i %i [%i] \n", nbitem, modname, nbi, nbo, prodlev); |
---|
70 | |
---|
71 | if (nbenrlus==1) |
---|
72 | { //si dans l'entete (i.e 1er enreg) du fichier on trouve que le |
---|
73 | // 1er caractere du 1er token est un '#' (indication de commentaire), |
---|
74 | // et que le 2eme token correspond a O ou 1, alors c'est |
---|
75 | // ca qui prime pour determiner le mode 'w' ou 'r' |
---|
76 | if (nbitem >=2 && modname[0]=='#' && (nbi==0 || nbi==1)) |
---|
77 | { mode=nbi; |
---|
78 | //-------------------------- |
---|
79 | if (mode==0) |
---|
80 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
81 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
82 | exit(-9); |
---|
83 | } |
---|
84 | } |
---|
85 | else //=>mode==1 |
---|
86 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
87 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
88 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
89 | exit(-9); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
94 | //-------------------------- |
---|
95 | continue; |
---|
96 | } |
---|
97 | else //alors seulement le mode passed en parametre ou par defaut est utilise |
---|
98 | { //-------------------------- |
---|
99 | if (mode==0) |
---|
100 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
101 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
102 | exit(-9); |
---|
103 | } |
---|
104 | } |
---|
105 | else //=>mode==1 |
---|
106 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
107 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
108 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
109 | exit(-9); |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | if (nbitem<=0) continue; //ligne vide |
---|
118 | if (modname[0]=='#') continue; //commentaire |
---|
119 | |
---|
120 | //dans un enregistrement, on doit au moins trouver modname nbi nbo |
---|
121 | if (nbitem<3) |
---|
122 | { printf(" < %s", buffer); |
---|
123 | printf(" > ylmodf: uncomplete ligne; skeep to the next\n"); |
---|
124 | continue; |
---|
125 | } |
---|
126 | |
---|
127 | //on verifie que le module existe bien |
---|
128 | if ((fpout = fopen(modname, "r")) <= 0) //on essaye avec le nom tel quel |
---|
129 | { //sinon on essaye en rajoutant .h |
---|
130 | strcat(modname, ".h"); |
---|
131 | if ((fpout = fopen(modname, "r")) <= 0) |
---|
132 | { printf (" > ylmodf: problem when opening %s \n", modname); |
---|
133 | printf (" skeep to next module\n\n"); |
---|
134 | continue; |
---|
135 | } |
---|
136 | } |
---|
137 | fclose(fpout); //c'etait juste pour verifier |
---|
138 | |
---|
139 | //on cree la commande d'appel a la procedure de derivation automatique |
---|
140 | //pour le module: YdfA fileout modname nbi nbo prodlev |
---|
141 | sprintf(cdesys, "YdfA %s %s %i %i %i\n", argv[2], modname, nbi, nbo, prodlev); |
---|
142 | system (cdesys); |
---|
143 | } |
---|
144 | |
---|
145 | fclose(fpin); |
---|
146 | printf("\n"); |
---|
147 | return(0); |
---|
148 | } |
---|
149 | //========================================================= |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | |
---|