Patch level : 12.0 no-patch
Files correlati : Commento : rivisti patchdef e fastrip
This commit is contained in:
parent
907d3da0f8
commit
7c7b4def93
@ -1,73 +0,0 @@
|
||||
#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;
|
||||
}
|
77
src/utilities/fastrip.cpp
Normal file
77
src/utilities/fastrip.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#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;
|
||||
}
|
@ -1,51 +1,65 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <fstream.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
void patch(istream& i, ostream& o)
|
||||
void patch(istream & i, ostream & o)
|
||||
{
|
||||
char lin[513];
|
||||
unsigned char lin[2048];
|
||||
unsigned char * c;
|
||||
|
||||
while (i.good())
|
||||
{
|
||||
i.getline(lin, 512);
|
||||
|
||||
for(char* c = lin; isspace(*c); c++); // salta spazi iniziali
|
||||
|
||||
char instring = '\0';
|
||||
char wasspace = 0;
|
||||
|
||||
for (char* cur = lin; *c; c++)
|
||||
char instring = '\0';
|
||||
bool full = false;
|
||||
|
||||
i.getline((char *) lin, 2048);
|
||||
for(c = lin; isspace(*c); c++); // salta spazi iniziali
|
||||
for (c ; *c; c++)
|
||||
{
|
||||
if (*c == '!')
|
||||
full = true;
|
||||
if (*c == '!' && *(c + 1) == '!')
|
||||
{
|
||||
if (*(c + 1) == '!')
|
||||
{
|
||||
c++;
|
||||
*c = '#';
|
||||
}
|
||||
}
|
||||
if (*c == '#')
|
||||
{
|
||||
*cur++ = *c;
|
||||
while isspace(*(++c));
|
||||
}
|
||||
if (*c == ';')
|
||||
*cur++ = '\n';
|
||||
else
|
||||
*cur++ = *c;
|
||||
}
|
||||
*cur = '\0';
|
||||
o << '#';
|
||||
c++;
|
||||
|
||||
if (*lin) o << lin << endl;
|
||||
}
|
||||
else
|
||||
if (*c == '#')
|
||||
{
|
||||
o << *c;
|
||||
while (isspace(*(++c)));
|
||||
c--;
|
||||
}
|
||||
else
|
||||
if (*c == ';')
|
||||
o << '\n';
|
||||
else
|
||||
o << *c;
|
||||
}
|
||||
if (full)
|
||||
o << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
patch(cin, cout);
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user