//gcc yrcmt.c -Wall -o yrcmt #include #include #include #define BUFSIZE 2048 FILE *fpin, *fpout; char buffer[BUFSIZE+1]; char *pstr1, *pstr2, *pstr3, *pstr4; short in_cmt_star, end; short in_string; int nbenrlus=0; //========================================================== int main(int argc, char *argv[]) { //pour virer les commentaires /* debut : verif arg, ouverture fichier ... */ if (argc<2 || argc>3) { printf ("syntaxe error: yrcmy file_in [file_out]}\n"); exit(-9); } if ((fpin = fopen(argv[1], "r")) <= 0) { printf ("problem when opening %s \n", argv[1]); exit(-9); } if (argc==3) { if ((fpout = fopen(argv[2], "w")) <= 0) { printf ("problem when opening %s \n", argv[2]); exit(-9); } } else fpout = stdout; while ( (fgets(buffer, BUFSIZE+1, fpin)) != NULL) { ++nbenrlus; pstr1 = buffer; end = 0; while (!end) { if (in_cmt_star) { //si on est dans un commentaire, on regarde //si on en trouve la fin pstr1 = strstr(pstr1, "*/"); if (pstr1 != NULL) { pstr1+=2; in_cmt_star = 0; } else end=1; } if (!in_cmt_star) { //si on est pas (ou plus) dans commentaire, on regarde si //y'en a pstr2 = pstr3 = pstr1; pstr2 = strstr(pstr1, "/*"); pstr3 = strstr(pstr1, "//"); pstr4 = strstr(pstr1, "\""); if (pstr4!=NULL) { //if ( (pstr4 yrcmt error a line %i: a string must end on the same line !!!?\n", nbenrlus); exit(-9); } //on va ecrire y compris jusqu'a la fin de la chaine de carateres pstr4[0]='\0'; printf("%s", pstr1); printf("\""); pstr1=pstr4+1; if (pstr1[0]=='\0') end=1; continue; } } if (pstr2!=NULL && pstr3!=NULL) { //c'est l'inf qui compte if (pstr2