#include <stdio.h>
void delNote(FILE *fp,FILE *fp2);
int main(int argc, const char *argv[])
{
FILE *fp,*fp2;
fp=fopen(argv[1],"r");
fp2=fopen(argv[2],"w");
delNote(fp,fp2);
fcloseall();
return 0;
}
void delNote(FILE *fp,FILE *fp2)
{
enum
{
normal,
single,
multiple,
string,
}mode=normal;
char lead,follow=0;
while((lead=fgetc(fp))!=EOF)
{
switch(mode)
{
case normal:
{
if (follow == '/')
{
if (lead == '/')
{
mode = single;
}
else if (lead == '*')
{
mode = multiple;
}
else
{
fputc(follow,fp2);
fputc(lead,fp2);
}
}
else if (lead != '/')
{
fputc(lead,fp2);
if (lead == '"')
{
mode = string;
}
}
}break;
case single:
{
if (follow != '\\' && (lead == '\n' || lead == '\r'))
{
fputc(lead,fp2);
lead = 0;
mode = normal;
}
} break;
case multiple:
{
if (follow == '*' && lead == '/')
{
lead = 0;
mode = normal;
}
} break;
case string:
{
if (follow == '\\')
{
fputc(follow,fp2);
fputc(lead,fp2);
}
else if (lead != '\\')
{
fputc(lead,fp2);
if (lead == '"')
{
mode = normal;
}
}
} break;
}
follow = lead;
}
}
void delNote(FILE *fp,FILE *fp2);
int main(int argc, const char *argv[])
{
FILE *fp,*fp2;
fp=fopen(argv[1],"r");
fp2=fopen(argv[2],"w");
delNote(fp,fp2);
fcloseall();
return 0;
}
void delNote(FILE *fp,FILE *fp2)
{
enum
{
normal,
single,
multiple,
string,
}mode=normal;
char lead,follow=0;
while((lead=fgetc(fp))!=EOF)
{
switch(mode)
{
case normal:
{
if (follow == '/')
{
if (lead == '/')
{
mode = single;
}
else if (lead == '*')
{
mode = multiple;
}
else
{
fputc(follow,fp2);
fputc(lead,fp2);
}
}
else if (lead != '/')
{
fputc(lead,fp2);
if (lead == '"')
{
mode = string;
}
}
}break;
case single:
{
if (follow != '\\' && (lead == '\n' || lead == '\r'))
{
fputc(lead,fp2);
lead = 0;
mode = normal;
}
} break;
case multiple:
{
if (follow == '*' && lead == '/')
{
lead = 0;
mode = normal;
}
} break;
case string:
{
if (follow == '\\')
{
fputc(follow,fp2);
fputc(lead,fp2);
}
else if (lead != '\\')
{
fputc(lead,fp2);
if (lead == '"')
{
mode = normal;
}
}
} break;
}
follow = lead;
}
}