summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/Client.cpp87
-rw-r--r--cpp/src/IceGrid/Parser.cpp87
-rw-r--r--cpp/src/IceGrid/Parser.h14
-rw-r--r--cpp/src/IceGrid/Scanner.l48
-rw-r--r--cpp/src/IceStorm/Admin.cpp101
-rw-r--r--cpp/src/IceStorm/Parser.cpp87
-rw-r--r--cpp/src/IceStorm/Parser.h14
-rw-r--r--cpp/src/IceStorm/Scanner.l48
8 files changed, 32 insertions, 454 deletions
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp
index f421c781af2..55adf95850d 100644
--- a/cpp/src/IceGrid/Client.cpp
+++ b/cpp/src/IceGrid/Client.cpp
@@ -129,15 +129,11 @@ main(int argc, char* argv[])
void
Client::usage()
{
- cerr << "Usage: " << appName() << " [options] [file...]\n";
+ cerr << "Usage: " << appName() << " [options]\n";
cerr <<
"Options:\n"
"-h, --help Show this message.\n"
"-v, --version Display the Ice version.\n"
- "-DNAME Define NAME as 1.\n"
- "-DNAME=DEF Define NAME as DEF.\n"
- "-UNAME Remove any definition for NAME.\n"
- "-IDIR Put DIR in the include file search path.\n"
"-e COMMANDS Execute COMMANDS.\n"
"-d, --debug Print debug messages.\n"
"-s, --server Start icegridadmin as a server (to parse XML files).\n"
@@ -252,16 +248,12 @@ Client::interrupted()
int
Client::run(int argc, char* argv[])
{
- string cpp("cpp");
string commands;
bool debug;
IceUtil::Options opts;
opts.addOpt("h", "help");
opts.addOpt("v", "version");
- opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
- opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
- opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("e", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("u", "username", IceUtil::Options::NeedArg, "", IceUtil::Options::NoRepeat);
opts.addOpt("p", "password", IceUtil::Options::NeedArg, "", IceUtil::Options::NoRepeat);
@@ -281,6 +273,11 @@ Client::run(int argc, char* argv[])
usage();
return EXIT_FAILURE;
}
+ if(!args.empty())
+ {
+ usage();
+ return EXIT_FAILURE;
+ }
if(opts.isSet("help"))
{
@@ -305,30 +302,6 @@ Client::run(int argc, char* argv[])
return EXIT_SUCCESS;
}
- if(opts.isSet("D"))
- {
- vector<string> optargs = opts.argVec("D");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -D" + *i;
- }
- }
- if(opts.isSet("U"))
- {
- vector<string> optargs = opts.argVec("U");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -U" + *i;
- }
- }
- if(opts.isSet("I"))
- {
- vector<string> optargs = opts.argVec("I");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -I" + *i;
- }
- }
if(opts.isSet("e"))
{
vector<string> optargs = opts.argVec("e");
@@ -339,13 +312,6 @@ Client::run(int argc, char* argv[])
}
debug = opts.isSet("debug");
- if(!args.empty() && !commands.empty())
- {
- cerr << appName() << ": `-e' option cannot be used if input files are given" << endl;
- usage();
- return EXIT_FAILURE;
- }
-
bool ssl = communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.AuthenticateUsingSSL");
if(opts.isSet("ssl"))
{
@@ -586,46 +552,7 @@ Client::run(int argc, char* argv[])
_parser = Parser::createParser(communicator(), session, admin, args.empty() && commands.empty());
}
- if(!args.empty()) // Files given
- {
- // Process files given on the command line
- for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i)
- {
- ifstream test(i->c_str());
- if(!test)
- {
- cerr << appName() << ": can't open `" << *i << "' for reading: " << strerror(errno) << endl;
- return EXIT_FAILURE;
- }
- test.close();
-
- string cmd = cpp + " " + *i;
-#ifdef _WIN32
- FILE* cppHandle = _popen(cmd.c_str(), "r");
-#else
- FILE* cppHandle = popen(cmd.c_str(), "r");
-#endif
- if(cppHandle == NULL)
- {
- cerr << appName() << ": can't run C++ preprocessor: " << strerror(errno) << endl;
- return EXIT_FAILURE;
- }
-
- int parseStatus = _parser->parse(cppHandle, debug);
-
-#ifdef _WIN32
- _pclose(cppHandle);
-#else
- pclose(cppHandle);
-#endif
-
- if(parseStatus == EXIT_FAILURE)
- {
- status = EXIT_FAILURE;
- }
- }
- }
- else if(!commands.empty()) // Commands were given
+ if(!commands.empty()) // Commands were given
{
int parseStatus = _parser->parse(commands, debug);
if(parseStatus == EXIT_FAILURE)
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index 25c67564f93..35ab0cbf548 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -1702,7 +1702,7 @@ Parser::getInput(char* buf, int& result, int maxSize)
}
}
}
- else if(isatty(fileno(yyin)))
+ else
{
#ifdef HAVE_READLINE
@@ -1772,21 +1772,6 @@ Parser::getInput(char* buf, int& result, int maxSize)
#endif
}
- else
- {
- if(((result = (int) fread(buf, 1, maxSize, yyin)) == 0) && ferror(yyin))
- {
- error("input in flex scanner failed");
- buf[0] = EOF;
- result = 1;
- }
- }
-}
-
-void
-Parser::nextLine()
-{
- _currentLine++;
}
void
@@ -1798,7 +1783,7 @@ Parser::continueLine()
const char*
Parser::getPrompt()
{
- assert(_commands.empty() && isatty(fileno(yyin)));
+ assert(_commands.empty());
if(_continue)
{
@@ -1812,50 +1797,6 @@ Parser::getPrompt()
}
void
-Parser::scanPosition(const char* s)
-{
- string line(s);
- string::size_type idx;
-
- idx = line.find("line");
- if(idx != string::npos)
- {
- line.erase(0, idx + 4);
- }
-
- idx = line.find_first_not_of(" \t\r#");
- if(idx != string::npos)
- {
- line.erase(0, idx);
- }
-
- _currentLine = atoi(line.c_str()) - 1;
-
- idx = line.find_first_of(" \t\r");
- if(idx != string::npos)
- {
- line.erase(0, idx);
- }
-
- idx = line.find_first_not_of(" \t\r\"");
- if(idx != string::npos)
- {
- line.erase(0, idx);
-
- idx = line.find_first_of(" \t\r\"");
- if(idx != string::npos)
- {
- _currentFile = line.substr(0, idx);
- line.erase(0, idx + 1);
- }
- else
- {
- _currentFile = line;
- }
- }
-}
-
-void
Parser::invalidCommand(const char* s)
{
error(s);
@@ -1956,14 +1897,7 @@ Parser::patchFailed(const Ice::StringSeq& reasons)
void
Parser::error(const char* s)
{
- if(_commands.empty() && !isatty(fileno(yyin)))
- {
- cerr << _currentFile << ':' << _currentLine << ": " << s << endl;
- }
- else
- {
- cerr << "error: " << s << endl;
- }
+ cerr << "error: " << s << endl;
_errors++;
}
@@ -1976,14 +1910,7 @@ Parser::error(const string& s)
void
Parser::warning(const char* s)
{
- if(_commands.empty() && !isatty(fileno(yyin)))
- {
- cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl;
- }
- else
- {
- cerr << "warning: " << s << endl;
- }
+ cerr << "warning: " << s << endl;
}
void
@@ -2005,10 +1932,7 @@ Parser::parse(FILE* file, bool debug)
yyin = file;
assert(yyin);
- _currentFile = "";
- _currentLine = 0;
_continue = false;
- nextLine();
int status = yyparse();
if(_errors)
@@ -2033,10 +1957,7 @@ Parser::parse(const std::string& commands, bool debug)
assert(!_commands.empty());
yyin = 0;
- _currentFile = "";
- _currentLine = 0;
_continue = false;
- nextLine();
int status = yyparse();
if(_errors)
diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h
index 12f42a75bb5..a57de7b589a 100644
--- a/cpp/src/IceGrid/Parser.h
+++ b/cpp/src/IceGrid/Parser.h
@@ -16,16 +16,6 @@
#include <list>
#include <stdio.h>
-#ifdef _WIN32
-# include <io.h>
-# ifdef _MSC_VER
-# define isatty _isatty
-# define fileno _fileno
-// '_isatty' : inconsistent dll linkage. dllexport assumed.
-# pragma warning( disable : 4273 )
-# endif
-#endif
-
//
// Stuff for flex and bison
//
@@ -129,10 +119,8 @@ public:
void showWarranty();
void getInput(char*, int&, int);
- void nextLine();
void continueLine();
const char* getPrompt();
- void scanPosition(const char*);
void invalidCommand(const char*);
void invalidCommand(const std::string&);
@@ -162,8 +150,6 @@ private:
bool _continue;
bool _interrupted;
int _errors;
- int _currentLine;
- std::string _currentFile;
bool _interactive;
std::map< std::string, std::map<std::string, std::string> > _helpCommands;
};
diff --git a/cpp/src/IceGrid/Scanner.l b/cpp/src/IceGrid/Scanner.l
index e21f5541275..8c67888bdcb 100644
--- a/cpp/src/IceGrid/Scanner.l
+++ b/cpp/src/IceGrid/Scanner.l
@@ -50,32 +50,12 @@ keyword [[:alpha:]]*
%%
-^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ {
- parser->scanPosition(yytext);
-}
-
"//" {
// C++-style comment
int c;
do
{
c = yyinput();
- if(c == '\n')
- {
- parser->nextLine();
- }
}
while(c != '\n' && c != EOF);
}
@@ -85,11 +65,7 @@ keyword [[:alpha:]]*
while(true)
{
int c = yyinput();
- if(c == '\n')
- {
- parser->nextLine();
- }
- else if(c == '*')
+ if(c == '*')
{
int next = yyinput();
if(next == '/')
@@ -117,22 +93,10 @@ keyword [[:alpha:]]*
{
parser->continueLine();
}
- else if(yytext[i] == '\n')
- {
- parser->nextLine();
- }
}
}
{NL}|; {
- size_t len = strlen(yytext);
- for(size_t i = 0; i < len; ++i)
- {
- if(yytext[i] == '\n')
- {
- parser->nextLine();
- }
- }
return ';';
}
@@ -151,11 +115,6 @@ keyword [[:alpha:]]*
parser->warning("EOF in string");
break;
}
- else if(c == '\n')
- {
- s += c;
- parser->nextLine();
- }
else if(c == '\\')
{
char next = static_cast<char>(yyinput());
@@ -230,11 +189,6 @@ keyword [[:alpha:]]*
parser->warning("EOF in string");
break;
}
- else if(c == '\n')
- {
- s += c;
- parser->nextLine();
- }
else
{
s += c;
diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp
index db7d90eb292..9cf383482f5 100644
--- a/cpp/src/IceStorm/Admin.cpp
+++ b/cpp/src/IceStorm/Admin.cpp
@@ -55,16 +55,12 @@ Client::usage()
int
Client::run(int argc, char* argv[])
{
- string cpp("cpp");
string commands;
bool debug;
IceUtil::Options opts;
opts.addOpt("h", "help");
opts.addOpt("v", "version");
- opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
- opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
- opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("e", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("d", "debug");
@@ -79,6 +75,11 @@ Client::run(int argc, char* argv[])
usage();
return EXIT_FAILURE;
}
+ if(!args.empty())
+ {
+ usage();
+ return EXIT_FAILURE;
+ }
if(opts.isSet("help"))
{
@@ -90,30 +91,6 @@ Client::run(int argc, char* argv[])
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
- if(opts.isSet("D"))
- {
- vector<string> optargs = opts.argVec("D");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -D" + *i;
- }
- }
- if(opts.isSet("U"))
- {
- vector<string> optargs = opts.argVec("U");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -U" + *i;
- }
- }
- if(opts.isSet("I"))
- {
- vector<string> optargs = opts.argVec("I");
- for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i)
- {
- cpp += " -I" + *i;
- }
- }
if(opts.isSet("e"))
{
vector<string> optargs = opts.argVec("e");
@@ -124,13 +101,6 @@ Client::run(int argc, char* argv[])
}
debug = opts.isSet("debug");
- if(!args.empty() && !commands.empty())
- {
- cerr << appName() << ": `-e' option cannot be used if input files are given" << endl;
- usage();
- return EXIT_FAILURE;
- }
-
// The complete set of Ice::Identity -> manager proxies.
map<Ice::Identity, IceStorm::TopicManagerPrx> managers;
@@ -232,63 +202,22 @@ Client::run(int argc, char* argv[])
ParserPtr p = Parser::createParser(communicator(), defaultManager, managers);
int status = EXIT_SUCCESS;
- if(args.empty()) // No files given
+ if(!commands.empty()) // Commands were given
{
- if(!commands.empty()) // Commands were given
+ int parseStatus = p->parse(commands, debug);
+ if(parseStatus == EXIT_FAILURE)
{
- int parseStatus = p->parse(commands, debug);
- if(parseStatus == EXIT_FAILURE)
- {
- status = EXIT_FAILURE;
- }
- }
- else // No commands, let's use standard input
- {
- p->showBanner();
-
- int parseStatus = p->parse(stdin, debug);
- if(parseStatus == EXIT_FAILURE)
- {
- status = EXIT_FAILURE;
- }
+ status = EXIT_FAILURE;
}
}
- else // Process files given on the command line
+ else // No commands, let's use standard input
{
- for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i)
- {
- ifstream test(i->c_str());
- if(!test)
- {
- cerr << appName() << ": can't open `" << *i << "' for reading: " << strerror(errno) << endl;
- return EXIT_FAILURE;
- }
- test.close();
-
- string cmd = cpp + " " + *i;
-#ifdef _WIN32
- FILE* cppHandle = _popen(cmd.c_str(), "r");
-#else
- FILE* cppHandle = popen(cmd.c_str(), "r");
-#endif
- if(cppHandle == NULL)
- {
- cerr << appName() << ": can't run C++ preprocessor: " << strerror(errno) << endl;
- return EXIT_FAILURE;
- }
-
- int parseStatus = p->parse(cppHandle, debug);
-
-#ifdef _WIN32
- _pclose(cppHandle);
-#else
- pclose(cppHandle);
-#endif
+ p->showBanner();
- if(parseStatus == EXIT_FAILURE)
- {
- status = EXIT_FAILURE;
- }
+ int parseStatus = p->parse(stdin, debug);
+ if(parseStatus == EXIT_FAILURE)
+ {
+ status = EXIT_FAILURE;
}
}
diff --git a/cpp/src/IceStorm/Parser.cpp b/cpp/src/IceStorm/Parser.cpp
index 7cc0404f574..e98abe3d8dd 100644
--- a/cpp/src/IceStorm/Parser.cpp
+++ b/cpp/src/IceStorm/Parser.cpp
@@ -319,7 +319,7 @@ Parser::getInput(char* buf, int& result, int maxSize)
}
}
}
- else if(isatty(fileno(yyin)))
+ else
{
#ifdef HAVE_READLINE
@@ -390,21 +390,6 @@ Parser::getInput(char* buf, int& result, int maxSize)
#endif
}
- else
- {
- if(((result = (int) fread(buf, 1, maxSize, yyin)) == 0) && ferror(yyin))
- {
- error("input in flex scanner failed");
- buf[0] = EOF;
- result = 1;
- }
- }
-}
-
-void
-Parser::nextLine()
-{
- _currentLine++;
}
void
@@ -416,7 +401,7 @@ Parser::continueLine()
const char*
Parser::getPrompt()
{
- assert(_commands.empty() && isatty(fileno(yyin)));
+ assert(_commands.empty());
if(_continue)
{
@@ -430,60 +415,9 @@ Parser::getPrompt()
}
void
-Parser::scanPosition(const char* s)
-{
- string line(s);
- string::size_type idx;
-
- idx = line.find("line");
- if(idx != string::npos)
- {
- line.erase(0, idx + 4);
- }
-
- idx = line.find_first_not_of(" \t\r#");
- if(idx != string::npos)
- {
- line.erase(0, idx);
- }
-
- _currentLine = atoi(line.c_str()) - 1;
-
- idx = line.find_first_of(" \t\r");
- if(idx != string::npos)
- {
- line.erase(0, idx);
- }
-
- idx = line.find_first_not_of(" \t\r\"");
- if(idx != string::npos)
- {
- line.erase(0, idx);
-
- idx = line.find_first_of(" \t\r\"");
- if(idx != string::npos)
- {
- _currentFile = line.substr(0, idx);
- line.erase(0, idx + 1);
- }
- else
- {
- _currentFile = line;
- }
- }
-}
-
-void
Parser::error(const char* s)
{
- if(_commands.empty() && !isatty(fileno(yyin)))
- {
- cerr << _currentFile << ':' << _currentLine << ": " << s << endl;
- }
- else
- {
- cerr << "error: " << s << endl;
- }
+ cerr << "error: " << s << endl;
_errors++;
}
@@ -496,14 +430,7 @@ Parser::error(const string& s)
void
Parser::warning(const char* s)
{
- if(_commands.empty() && !isatty(fileno(yyin)))
- {
- cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl;
- }
- else
- {
- cerr << "warning: " << s << endl;
- }
+ cerr << "warning: " << s << endl;
}
void
@@ -531,10 +458,7 @@ Parser::parse(FILE* file, bool debug)
yyin = file;
assert(yyin);
- _currentFile = "";
- _currentLine = 0;
_continue = false;
- nextLine();
int status = yyparse();
if(_errors)
@@ -559,10 +483,7 @@ Parser::parse(const std::string& commands, bool debug)
assert(!_commands.empty());
yyin = 0;
- _currentFile = "";
- _currentLine = 0;
_continue = false;
- nextLine();
int status = yyparse();
if(_errors)
diff --git a/cpp/src/IceStorm/Parser.h b/cpp/src/IceStorm/Parser.h
index 1497d906980..81efeba4672 100644
--- a/cpp/src/IceStorm/Parser.h
+++ b/cpp/src/IceStorm/Parser.h
@@ -15,16 +15,6 @@
#include <list>
#include <stdio.h>
-#ifdef _WIN32
-# include <io.h>
-# ifdef _MSC_VER
-# define isatty _isatty
-# define fileno _fileno
-// '_isatty' : inconsistent dll linkage. dllexport assumed.
-# pragma warning( disable : 4273 )
-# endif
-#endif
-
//
// Stuff for flex and bison
//
@@ -79,10 +69,8 @@ public:
void showBanner();
void getInput(char*, int&, int);
- void nextLine();
void continueLine();
const char* getPrompt();
- void scanPosition(const char*);
void error(const char*);
void error(const std::string&);
@@ -111,8 +99,6 @@ private:
std::string _commands;
bool _continue;
int _errors;
- int _currentLine;
- std::string _currentFile;
};
extern Parser* parser; // The current parser for bison/flex
diff --git a/cpp/src/IceStorm/Scanner.l b/cpp/src/IceStorm/Scanner.l
index 3f1fc20dbb3..c33c5a8ac54 100644
--- a/cpp/src/IceStorm/Scanner.l
+++ b/cpp/src/IceStorm/Scanner.l
@@ -49,32 +49,12 @@ keyword [[:alpha:]]*
%%
-^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]*$ {
- parser->scanPosition(yytext);
-}
-
-^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ {
- parser->scanPosition(yytext);
-}
-
"//" {
// C++-style comment
int c;
do
{
c = yyinput();
- if(c == '\n')
- {
- parser->nextLine();
- }
}
while(c != '\n' && c != EOF);
}
@@ -84,11 +64,7 @@ keyword [[:alpha:]]*
while(true)
{
int c = yyinput();
- if(c == '\n')
- {
- parser->nextLine();
- }
- else if(c == '*')
+ if(c == '*')
{
int next = yyinput();
if(next == '/')
@@ -116,22 +92,10 @@ keyword [[:alpha:]]*
{
parser->continueLine();
}
- else if(yytext[i] == '\n')
- {
- parser->nextLine();
- }
}
}
{NL}|; {
- size_t len = strlen(yytext);
- for(size_t i = 0; i < len; ++i)
- {
- if(yytext[i] == '\n')
- {
- parser->nextLine();
- }
- }
return ';';
}
@@ -150,11 +114,6 @@ keyword [[:alpha:]]*
parser->warning("EOF in string");
break;
}
- else if(c == '\n')
- {
- s += c;
- parser->nextLine();
- }
else if(c == '\\')
{
char next = static_cast<char>(yyinput());
@@ -229,11 +188,6 @@ keyword [[:alpha:]]*
parser->warning("EOF in string");
break;
}
- else if(c == '\n')
- {
- s += c;
- parser->nextLine();
- }
else
{
s += c;