git-svn-id: svn://10.65.10.50/branches/R_10_00@23159 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
e7ca697691
commit
5a6ba3428f
73
fastrip/fastrip.c
Normal file
73
fastrip/fastrip.c
Normal file
@ -0,0 +1,73 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void strip(FILE * i, FILE * o)
|
||||
{
|
||||
char lin[513];
|
||||
|
||||
while (fgets(lin, 512, i) != NULL)
|
||||
{
|
||||
char instring = '\0';
|
||||
char wasspace = 0;
|
||||
|
||||
char* c = lin;
|
||||
for(; isspace(*c); c++); // salta spazi iniziali
|
||||
|
||||
for (; *c; c++)
|
||||
{
|
||||
if (*c == '/' && *(c+1) == '/')
|
||||
{
|
||||
fputc('\n', o);
|
||||
break;
|
||||
}
|
||||
|
||||
if (*c == '#')
|
||||
{
|
||||
fputc(*c, o);
|
||||
while (isspace(*(++c)));
|
||||
}
|
||||
if (*c == '"' || *c == '\'')
|
||||
{
|
||||
if (instring == *c)
|
||||
instring = '\0';
|
||||
else
|
||||
{
|
||||
if (instring == '\0')
|
||||
instring = *c;
|
||||
}
|
||||
}
|
||||
|
||||
if (isspace(*c))
|
||||
{
|
||||
if (!instring)
|
||||
{
|
||||
if (wasspace && *c != '\n')
|
||||
continue;
|
||||
wasspace = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
wasspace = 0;
|
||||
|
||||
fputc(*c, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
// cerr << "Strip 1.2 - White spaces filter by Guy 2012" << endl;
|
||||
FILE* i = argc > 1 ? fopen(argv[1], "r") : stdin;
|
||||
FILE* o = argc > 2 ? fopen(argv[2], "w") : stdout;
|
||||
if (i && o)
|
||||
strip(i, o);
|
||||
if (o)
|
||||
fclose(o);
|
||||
if (i)
|
||||
fclose(i);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user