campo-sirio/src/utilities/fastrip.cpp
Alessandro Bonazzi 7c7b4def93 Patch level : 12.0 no-patch
Files correlati     :
Commento            :

rivisti patchdef e fastrip
2020-06-24 18:30:35 +02:00

78 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#include <ctype.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void strip(istream & i, ostream & o)
{
unsigned char lin[2048];
unsigned char* c;
while (i.good())
{
bool instring = false;
bool wasspace = false;
bool full = false;
i.getline((char *)lin, 2048);
for (c = lin; isspace(*c); c++); // salta spazi iniziali
for (; *c; c++)
{
full = true;
if (*c == '/' && *(c+1) == '/')
{
o << '\n';
break;
}
if (*c == '#')
{
o << *c;
while (isspace(*(++c)));
// c--;
}
else
if (*c == '"' || *c == '\'')
instring = !instring;
if (isspace(*c))
{
if (!instring)
{
if (wasspace && *c != '\n')
continue;
wasspace = true;
}
}
else
wasspace = false;
o << *c;
}
if (full)
o << '\n';
}
}
int main(int argc, char ** argv)
{
// cerr << "Strip 1.2 - White spaces filter by Guy 2012" << endl;
if (argc == 1)
strip(cin, cout);
else
{
ifstream fin(argv[1]);
if (argc == 2)
strip(fin, cout);
else
{
ofstream fout(argv[2]);
strip(fin, fout);
}
}
return 0;
}