campo-sirio/src/utilities/patchdef.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

65 lines
940 B
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}