source: trunk/etc/src/yrcmt.c

Last change on this file was 610, checked in by grlod, 12 years ago

header replacements
uml diagrams updated
should have been committed 3 months ago ...

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1/*
2Copyright or © or Copr. MMSA team, LOCEAN Paris (2011)
3
4This software is a framework for variational data assimilation in
5numerical models.
6
7This software is governed by the CeCILL license under French law and
8abiding by the rules of distribution of free software.  You can  use,
9modify and/ or redistribute the software under the terms of the CeCILL
10license as circulated by CEA, CNRS and INRIA at the following URL
11"http://www.cecill.info".
12
13As a counterpart to the access to the source code and  rights to copy,
14modify and redistribute granted by the license, users are provided only
15with a limited warranty  and the software's author,  the holder of the
16economic rights,  and the successive licensors  have only  limited
17liability.
18
19In this respect, the user's attention is drawn to the risks associated
20with loading,  using,  modifying and/or developing or reproducing the
21software by the user in light of its specific status of free software,
22that may mean  that it is complicated to manipulate,  and  that  also
23therefore means  that it is reserved for developers  and  experienced
24professionals having in-depth computer knowledge. Users are therefore
25encouraged to load and test the software's suitability as regards their
26requirements in conditions enabling the security of their systems and/or
27data to be ensured and,  more generally, to use and operate it in the
28same conditions as regards security.
29
30The fact that you are presently reading this means that you have had
31knowledge of the CeCILL license and that you accept its terms.
32
33YAO website : http://www.locean-ipsl.upmc.fr/~yao/
34Contact : yao@locean-ipsl.upmc.fr
35*/
36// Contributor : Charles Sorror
37//gcc yrcmt.c -Wall -o yrcmt
38
39#include <stdlib.h>
40#include <stdio.h>
41#include <string.h>
42
43#define BUFSIZE       2048
44
45FILE    *fpin, *fpout;
46char    buffer[BUFSIZE+1];
47char    *pstr1, *pstr2, *pstr3, *pstr4;
48short   in_cmt_star, end;
49short   in_string;
50int     nbenrlus=0;
51
52//==========================================================
53int main(int argc, char *argv[])
54{   //pour virer les commentaires
55
56        /* debut : verif arg, ouverture fichier ... */
57        if (argc<2 || argc>3)
58        {               printf ("syntaxe error: yrcmy file_in [file_out]}\n");
59                  exit(-9);
60        }
61        if ((fpin = fopen(argv[1], "r")) <= 0)
62        {               printf ("problem when opening %s \n", argv[1]);
63                        exit(-9);
64        }
65        if (argc==3)
66        {  if ((fpout = fopen(argv[2], "w")) <= 0)
67           {  printf ("problem when opening %s \n", argv[2]);
68                          exit(-9);
69           }
70        }
71        else fpout = stdout;
72
73        while (  (fgets(buffer, BUFSIZE+1, fpin)) != NULL)
74  {    ++nbenrlus;
75       pstr1 = buffer;
76                         end = 0;
77       while (!end)
78       {
79           if (in_cmt_star)
80           {  //si on est dans un commentaire, on regarde
81              //si on en trouve la fin
82              pstr1 = strstr(pstr1, "*/");
83              if (pstr1 != NULL)
84              {  pstr1+=2;
85                 in_cmt_star = 0;
86              }
87                                                        else
88                                                           end=1;
89           }
90
91           if (!in_cmt_star)
92           {  //si on est pas (ou plus) dans commentaire, on regarde si
93              //y'en a
94              pstr2 = pstr3 = pstr1;
95              pstr2 = strstr(pstr1, "/*");
96              pstr3 = strstr(pstr1, "//");
97                                                        pstr4 = strstr(pstr1, "\"");
98
99                                                        if (pstr4!=NULL)
100                                                        {  //if ( (pstr4<pstr2 && pstr2!=NULL) && (pstr4<pstr3 && pstr3!=NULL) ) //"
101                                                           in_string=1;
102                                                                 if (pstr2<pstr4 && pstr2!=NULL) in_string=0;
103                                                                 if (pstr3<pstr4 && pstr3!=NULL) in_string=0;
104                                                                 if (in_string) //on a detected le debut d'une chaine de carateres
105                                                           {              //on doit en trouver la fin sur la meme ligne !!!
106                                                                                ++pstr4;
107                                                                                pstr4 = strstr(pstr4, "\"");
108                                                                                if (pstr4==NULL)
109                                                                                {  printf(" > yrcmt error a line %i: a string must end on the same line !!!?\n", nbenrlus);
110                                                                                   exit(-9);
111                                                                                }
112                                                                                //on va ecrire y compris jusqu'a la fin de la chaine de carateres
113                                                                                pstr4[0]='\0';
114                                                                                printf("%s", pstr1);
115                                                                                printf("\"");
116                                                                                pstr1=pstr4+1;
117                                                                                if (pstr1[0]=='\0')
118                                                                                   end=1;
119                                                                                continue;
120                                                                 }
121                                                        }
122
123                                                        if (pstr2!=NULL && pstr3!=NULL)
124                                                        {  //c'est l'inf qui compte
125                                                           if (pstr2<pstr3) //commentaire star (/*)
126                                                                 {  in_cmt_star=1;
127                                                                                //il faut écrire ce qu'il y a avant
128                                                                    pstr2[0]='\0';
129                                printf("%s", pstr1);
130                                                                    pstr1=pstr2+2; //pour avancer
131                                                                 }
132                                                                 if (pstr3<pstr2) //commentaire slash (//)
133                                                                 {  //il faut écrire ce qu'il y a avant
134                                                                          pstr3[0]='\0';
135                                printf("%s", pstr1);
136                                                                                end=1;
137                                                                 }
138                                                        }
139                                                        else if (pstr2!=NULL) //commentaire star (/*)
140                                                  {  in_cmt_star=1;
141                                                                 //il faut écrire ce qu'il y a avant
142                                                           pstr2[0]='\0';
143                 printf("%s", pstr1);
144                                                                 pstr1=pstr2+2; //pour avancer
145                                                        }
146                                                        else if (pstr3!=NULL) //commentaire slash (//)
147                                                  {  //il faut écrire ce qu'il y a avant
148                                                           pstr3[0]='\0';
149                 printf("%s", pstr1);
150                                                                 end=1;
151                                                        }
152                                                        else //pas de commentaire, on reconduit
153                                                        {  printf("%s", pstr1);
154                                                                 end=1;
155                                                        }
156                                         }
157       }
158  }
159
160   return(0);
161}
162//=========================================================
163
164
165
166
167
168
169
170
171
172
173
174
175
Note: See TracBrowser for help on using the repository browser.