From ac027069c0dcf06bd58f4b6870d5af385e7134b7 Mon Sep 17 00:00:00 2001 From: ruglory Date: Tue, 10 Mar 2009 03:41:54 +0000 Subject: [PATCH] Added parameter --file - to process file with KEY=VALUE lines git-svn-id: https://svn.code.sf.net/p/qlscribe/svn/trunk@120 cac9541e-1b8d-4bfa-827e-589bba606050 --- src/main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 99527e1..8150ee0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "mainwindow.h" #include "qcdscene.h" #include "qlightscribe.h" @@ -46,6 +48,7 @@ void usage() << "\t\t--size | -s size - image size, 400 by default\n" << "\t\t--drive | -d NUMBER - use this drive, starts from 0, 0 is default\n" << "\t\t--replace | -r KEY=VALUE - replace text from KEY to VALUE\n" + << "\t\t--file | -f filename - read replacements in format KEY=VALUE from file\n" << std::endl; } @@ -61,6 +64,7 @@ int main( int argc, char **argv ) int driveIndex = 0; int imageSize = 400; QString imageName; + QString replacementsFile; PrintParameters params; bool labelModeOverriden = false; @@ -90,6 +94,29 @@ int main( int argc, char **argv ) replacements[ param.left( pos ) ] = param.right( param.size() - pos - 1 ); continue; } + if( arg == "--file" || arg == "-f" ) { + if( i == arguments.size() - 1 ) { + std::cerr << "Error: arg#" << i + << " argument expected for \"" << arg << "\" not enough parameters" << std::endl; + return 1; + } + QFile data( arguments[ ++i ] ); + if( !data.open( QIODevice::ReadOnly ) ) { + std::cerr << "cannot open file \"" << arguments[ i ] << "\" for reading" << std::endl; + return 2; + } + QTextStream stream( &data ); + while( true ) { + QString line = stream.readLine(); + if( line.isNull() ) + break; + int pos = line.indexOf( '=' ); + if( pos == -1 ) + continue; + replacements[ line.left( pos ) ] = line.right( line.size() - pos - 1 ); + } + continue; + } if( arg == "--drive" || arg == "-d" ) { if( i == arguments.size() - 1 ) { std::cerr << "Error: arg#" << i