65 lines
940 B
C++
65 lines
940 B
C++
#include <ctype.h>
|
||
#include <string.h>
|
||
#include <iostream>
|
||
#include <fstream>
|
||
using namespace std;
|
||
|
||
void patch(istream & i, ostream & o)
|
||
{
|
||
unsigned char lin[2048];
|
||
unsigned char * c;
|
||
|
||
while (i.good())
|
||
{
|
||
char instring = '\0';
|
||
bool full = false;
|
||
|
||
i.getline((char *) lin, 2048);
|
||
for(c = lin; isspace(*c); c++); // salta spazi iniziali
|
||
for (c ; *c; c++)
|
||
{
|
||
full = true;
|
||
if (*c == '!' && *(c + 1) == '!')
|
||
{
|
||
o << '#';
|
||
c++;
|
||
|
||
}
|
||
else
|
||
if (*c == '#')
|
||
{
|
||
o << *c;
|
||
while (isspace(*(++c)));
|
||
c--;
|
||
}
|
||
else
|
||
if (*c == ';')
|
||
o << '\n';
|
||
else
|
||
o << *c;
|
||
}
|
||
if (full)
|
||
o << '\n';
|
||
}
|
||
}
|
||
|
||
int main(int argc, char ** argv)
|
||
{
|
||
if (argc == 1)
|
||
patch(cin, cout);
|
||
else
|
||
{
|
||
ifstream fin(argv[1]);
|
||
|
||
if (argc == 2)
|
||
patch(fin, cout);
|
||
else
|
||
{
|
||
ofstream fout(argv[2]);
|
||
|
||
patch(fin, fout);
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|