/*
* =====================================================================================
*
* Copyright 2011 Ankur Sinha
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*
* Filename: freemedia.cpp
*
* Description:
*
* Version: 1.0
* Created: 19/04/11 12:32:41
* Revision: none
* Compiler: gcc
*
* Author: Ankur Sinha (FranciscoD), sanjay DOT ankur AT gmail DOT com
* Company:
*
* =====================================================================================
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
/*
* === FUNCTION ======================================================================
* Name: main
* Description:
* =====================================================================================
*/
int
main ( int argc, char *argv[] )
{
ifstream inFh;
string temp;
vector readFile;
vector::iterator fileIterator;
vector oneAddress;
string aMark = "=";
int outputNumber = 0;
int j;
inFh.open(argv[2]);
if(inFh)
{
while(getline(inFh,temp))
{
readFile.push_back(temp);
}
}
inFh.close();
for(fileIterator = readFile.begin(); fileIterator != readFile.end(); fileIterator++)
{
/* ignore empty lines */
if(fileIterator->length() == 0)
continue;
/* My sentinel between two addresses appears to be a single
* space. One might have to tweak this up depending on how
* the xml gets parsed */
if(fileIterator->compare(aMark) == 0)
{
int y = 360;
string commandLine = "convert -verbose -pointsize 19 ";
/* convert -pointsize 22 -draw 'text 270,360 "Songita
* Das"' -draw 'text 270,391 "C/o Ashok Stores"'
* Freemedia-mailer.png Freemedia-mailer1.png */
j = 0;
for(vector::iterator lineIterator = oneAddress.begin(); lineIterator != oneAddress.end(); lineIterator++, j+=2)
{
stringstream ss;
ss << y;
commandLine += (" -draw 'text 265," + ss.str() + " \"" + *lineIterator + "\"'");
y += (31 + j);
}
commandLine += (" " + string(argv[1]));
stringstream ss1;
ss1 << outputNumber++;
commandLine += (" Freemedia-mailer" + ss1.str() + ".png" );
/* /pidChild = fork();
if(pidChild == 0)
{
cout << "Running: " << commandLine << endl;
return 0;
}*/
cout << "Running: " << commandLine << endl;
if(system(commandLine.c_str()) == -1)
{
cout << "Something mucked up! \n";
};
oneAddress.clear();
continue;
}
string temp = string(fileIterator->c_str());
temp[0] = toupper(temp[0]);
for(j = 0; j < (int) temp.length() -1; j++)
{
if(ispunct(temp[j]) || isspace(temp[j]))
{
if(isalpha(temp[j+1]))
{
temp[j+1] = toupper(temp[j+1]);
}
}
}
oneAddress.push_back(temp);
}
} /* ---------- end of function main ---------- */