- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <iterator>
- #include <cstring>
- #include <vector>
- #include <sstream>
-
-
- void Dip_Help();
-
- using namespace std;
- bool isNumeric(const string &atester);
- vector<string> dec( string str);
-
-
- int main(int argc, char *argv[])
- {
-
- /**on va convertir des fichier ps - couleur en noir et blanc.
- Comment sa marche ?
- Dans les postScript, les coleurs des lignes (pas des images, pour ces dernieres sa ne fait rien) sont définie par :
- # # # rgb
- ou # # # correspond au code RGB (rouge par ex : 1 0 0 rgb)...
- donc on recherche les rgb, on fait gaffe à ce que sa soit bien un code couleur (preceder de trois chiffres, pas de chr)
- et on remplace par "0 0 0 rgb"
- y a t'il des argc?
- */
- if ( argc == 1)
- {
- Dip_Help() ;
- return 1;
- }
- //1° boucle sur les args :
- int i;
- for(i=1 ; i<argc ; i++)
- {
- cout << "Traitement de : " << argv[i] << endl;
- //verification que le fichier existe :
- ifstream file( argv[i] );
- string line;
-
- string te = "c:\\temp\\convert_.ps";
- ofstream fp(te.c_str() , ios::out|ios::binary);
-
- //fp = fopen(, "w") ;
-
- while ( getline( file, line ))
- {
- if ( line.find("rgb") < line.size())
- {
-
- vector<string> temp = dec(line);
-
- vector<string>::reverse_iterator c1_Iter;
-
- c1_Iter = temp.rbegin();
- bool modif = false;
- int max0 = 0;
- for (; c1_Iter != temp.rend(); c1_Iter++)
- {
- if (*c1_Iter == "rgb")
- {
- max0 = 0;
- modif = true;
- }else{
- if (!isNumeric(*c1_Iter) || max0 == 3)
- modif = false;
- }
-
- if (modif == true && *c1_Iter != "rgb" )
- {
- *c1_Iter = "0";
- max0 +=1;
- //cout << *c1_Iter << endl;
- }
-
- //la on met à jour la ligne
-
- }
- ostringstream oss;
- copy(
- temp.begin(),
- temp.end(),
- ostream_iterator<string>( oss, " " ) );
- line = oss.str();
- //cout << line << endl;
-
- }
- //la on ajoute la ligne au nouveaux fichier :
- //cout << line << endl;
- fp << line;
- fp << "\n";
- }
- fp.close();
- file.close();
- //copy du fichier à la place du deuxieme :
- ofstream file_ecr( argv[i] , ios::in|ios::binary );
- ifstream fp_re(te.c_str() , ios::out|ios::binary);
-
- while ( getline( fp_re, line ))
- file_ecr << line << "\n";
-
- file_ecr.close();
-
- //effacement fichier temp :
- cout << remove(te.c_str()) << endl;
-
- }
-
-
- system("PAUSE");
- return EXIT_SUCCESS;
- }
-
- void Dip_Help()
- {
- cout << "Utlisation du logiciel : " << endl;
- cout << "PS_NB.exe \"Nom_du_prmier_fichier\" \"Nom_du_deuxieme_fichier\" \"...\" " << endl;
-
-
- }
-
- vector<string> dec(string str)
- {
-
- vector<string> str_list; // liste de mots
-
- // remplir la liste de mots
- istringstream iss( str );
- copy(
- istream_iterator<string>( iss ),
- istream_iterator<string>(),
- back_inserter( str_list ) );
-
- return str_list;
- }
-
- bool isNumeric(const string &atester) {
- const char *c = atester.c_str();
- while(*c) {
- if ((*c<'0' || *c>'9') && *c!='.') return 0;
- c++;
- }
- return 1;
- }
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iterator>
#include <cstring>
#include <vector>
#include <sstream>
void Dip_Help();
using namespace std;
bool isNumeric(const string &atester);
vector<string> dec( string str);
int main(int argc, char *argv[])
{
/**on va convertir des fichier ps - couleur en noir et blanc.
Comment sa marche ?
Dans les postScript, les coleurs des lignes (pas des images, pour ces dernieres sa ne fait rien) sont définie par :
# # # rgb
ou # # # correspond au code RGB (rouge par ex : 1 0 0 rgb)...
donc on recherche les rgb, on fait gaffe à ce que sa soit bien un code couleur (preceder de trois chiffres, pas de chr)
et on remplace par "0 0 0 rgb"
y a t'il des argc?
*/
if ( argc == 1)
{
Dip_Help() ;
return 1;
}
//1° boucle sur les args :
int i;
for(i=1 ; i<argc ; i++)
{
cout << "Traitement de : " << argv[i] << endl;
//verification que le fichier existe :
ifstream file( argv[i] );
string line;
string te = "c:\\temp\\convert_.ps";
ofstream fp(te.c_str() , ios::out|ios::binary);
//fp = fopen(, "w") ;
while ( getline( file, line ))
{
if ( line.find("rgb") < line.size())
{
vector<string> temp = dec(line);
vector<string>::reverse_iterator c1_Iter;
c1_Iter = temp.rbegin();
bool modif = false;
int max0 = 0;
for (; c1_Iter != temp.rend(); c1_Iter++)
{
if (*c1_Iter == "rgb")
{
max0 = 0;
modif = true;
}else{
if (!isNumeric(*c1_Iter) || max0 == 3)
modif = false;
}
if (modif == true && *c1_Iter != "rgb" )
{
*c1_Iter = "0";
max0 +=1;
//cout << *c1_Iter << endl;
}
//la on met à jour la ligne
}
ostringstream oss;
copy(
temp.begin(),
temp.end(),
ostream_iterator<string>( oss, " " ) );
line = oss.str();
//cout << line << endl;
}
//la on ajoute la ligne au nouveaux fichier :
//cout << line << endl;
fp << line;
fp << "\n";
}
fp.close();
file.close();
//copy du fichier à la place du deuxieme :
ofstream file_ecr( argv[i] , ios::in|ios::binary );
ifstream fp_re(te.c_str() , ios::out|ios::binary);
while ( getline( fp_re, line ))
file_ecr << line << "\n";
file_ecr.close();
//effacement fichier temp :
cout << remove(te.c_str()) << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
void Dip_Help()
{
cout << "Utlisation du logiciel : " << endl;
cout << "PS_NB.exe \"Nom_du_prmier_fichier\" \"Nom_du_deuxieme_fichier\" \"...\" " << endl;
}
vector<string> dec(string str)
{
vector<string> str_list; // liste de mots
// remplir la liste de mots
istringstream iss( str );
copy(
istream_iterator<string>( iss ),
istream_iterator<string>(),
back_inserter( str_list ) );
return str_list;
}
bool isNumeric(const string &atester) {
const char *c = atester.c_str();
while(*c) {
if ((*c<'0' || *c>'9') && *c!='.') return 0;
c++;
}
return 1;
}