summaryrefslogtreecommitdiff
path: root/idlc
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:59 +0100
committerJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:59 +0100
commitad669b8d2356b1f53c11c33ccb51803fd3ea49fe (patch)
tree605a882022093cc2eb32e4af9c06cd75befea795 /idlc
parent5f3b360f26fb05b2c1b6666321359346f2ddb5a4 (diff)
parentc8b417d97c982736e9678264673a20d328cabd1f (diff)
Merge commit 'ooo/DEV300_m103'
Conflicts: codemaker/source/bonobowrappermaker/corbaoptions.cxx codemaker/source/cppumaker/cppuoptions.cxx codemaker/source/cunomaker/cunooptions.cxx codemaker/source/idlmaker/idloptions.cxx codemaker/source/javamaker/javaoptions.cxx cppu/source/typelib/typelib.cxx idlc/source/options.cxx offapi/com/sun/star/util/PathSubstitution.idl offapi/drafts/com/sun/star/form/ListEntryEvent.idl offapi/drafts/com/sun/star/form/XBindableValue.idl offapi/drafts/com/sun/star/form/XListEntryListener.idl offapi/drafts/com/sun/star/form/XListEntrySink.idl offapi/drafts/com/sun/star/form/XListEntrySource.idl offapi/drafts/com/sun/star/form/XValueBinding.idl registry/tools/checksingleton.cxx registry/tools/options.hxx registry/tools/regcompare.cxx registry/tools/regmerge.cxx sal/cppunittester/cppunittester.cxx sal/osl/unx/socket.c sal/osl/w32/diagnose.c sal/prj/d.lst sal/rtl/source/alloc_fini.cxx sal/rtl/source/alloc_global.c sal/rtl/source/makefile.mk
Diffstat (limited to 'idlc')
-rw-r--r--idlc/inc/idlc/idlctypes.hxx2
-rw-r--r--idlc/inc/idlc/options.hxx17
-rw-r--r--idlc/source/astexpression.cxx21
-rw-r--r--idlc/source/idlcmain.cxx19
-rw-r--r--idlc/source/options.cxx556
-rw-r--r--idlc/source/preproc/eval.c15
-rw-r--r--idlc/source/preproc/lex.c10
-rw-r--r--idlc/source/preproc/unix.c1
8 files changed, 343 insertions, 298 deletions
diff --git a/idlc/inc/idlc/idlctypes.hxx b/idlc/inc/idlc/idlctypes.hxx
index 834b8cc63..2bac20e3e 100644
--- a/idlc/inc/idlc/idlctypes.hxx
+++ b/idlc/inc/idlc/idlctypes.hxx
@@ -33,7 +33,9 @@
#include <boost/unordered_map.hpp>
#include <list>
#include <vector>
+#include <string>
#include <set>
+
#include <sal/types.h>
#include <rtl/ustring.hxx>
diff --git a/idlc/inc/idlc/options.hxx b/idlc/inc/idlc/options.hxx
index eda2a9274..df3d7e6a3 100644
--- a/idlc/inc/idlc/options.hxx
+++ b/idlc/inc/idlc/options.hxx
@@ -49,18 +49,29 @@ public:
class Options
{
public:
- Options();
+ explicit Options(char const * progname);
~Options();
+ static bool checkArgument(std::vector< std::string > & rArgs, char const * arg, size_t len);
+ static bool checkCommandFile(std::vector< std::string > & rArgs, char const * filename);
+
+ bool initOptions(std::vector< std::string > & rArgs)
+ throw(IllegalArgument);
+ bool badOption(char const * reason, std::string const & rArg)
+ throw(IllegalArgument);
+ bool setOption(char const * option, std::string const & rArg);
+
+#if 0 /* @@@ */
sal_Bool initOptions(int ac, char* av[], sal_Bool bCmdFile=sal_False)
throw( IllegalArgument );
+#endif /* @@@ */
::rtl::OString prepareHelp();
::rtl::OString prepareVersion();
const ::rtl::OString& getProgramName() const;
- sal_Bool isValid(const ::rtl::OString& option);
- const ::rtl::OString getOption(const ::rtl::OString& option)
+ bool isValid(const ::rtl::OString& option);
+ const ::rtl::OString& getOption(const ::rtl::OString& option)
throw( IllegalArgument );
const StringVector& getInputFiles() const { return m_inputFiles; }
diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx
index e4a5875c0..79f6c6288 100644
--- a/idlc/source/astexpression.cxx
+++ b/idlc/source/astexpression.cxx
@@ -28,6 +28,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_idlc.hxx"
+
#include <idlc/astexpression.hxx>
#include <idlc/astconstant.hxx>
#include <idlc/astscope.hxx>
@@ -35,6 +36,7 @@
#include <limits.h>
#include <float.h>
+#include <memory> // auto_ptr<>
#undef MAXCHAR
#define MAXCHAR 127
@@ -951,7 +953,6 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek)
AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
ExprType eType = ET_double;
if ( m_combOperator == EC_mod )
@@ -974,7 +975,7 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
if (m_subExpr2->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue();
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = eType;
switch (m_combOperator)
@@ -995,20 +996,18 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
break;
case EC_div:
if (m_subExpr2->getExprValue()->u.dval == 0.0)
- return NULL;
+ return NULL;
retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval;
break;
default:
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
-
if (ek != EK_const && ek != EK_positive_int)
return NULL;
if (m_subExpr1 == NULL || m_subExpr2 == NULL)
@@ -1026,7 +1025,7 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
if (m_subExpr2->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue;
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = ET_long;
switch (m_combOperator)
@@ -1050,13 +1049,11 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_un_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
-
if (m_exprValue != NULL)
return m_exprValue;
@@ -1071,7 +1068,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek)
if (m_subExpr1->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue();
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = ET_double;
switch (m_combOperator)
@@ -1092,7 +1089,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek)
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_symbol(EvalKind ek)
diff --git a/idlc/source/idlcmain.cxx b/idlc/source/idlcmain.cxx
index 21f8b89c3..d37b86d23 100644
--- a/idlc/source/idlcmain.cxx
+++ b/idlc/source/idlcmain.cxx
@@ -28,26 +28,35 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_idlc.hxx"
-#include <idlc/idlc.hxx>
+
+#include "idlc/idlc.hxx"
#include "sal/main.h"
+#include <string.h>
+
using namespace ::rtl;
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
{
- Options options;
+ std::vector< std::string > args;
+ for (int i = 1; i < argc; i++)
+ {
+ if (!Options::checkArgument (args, argv[i], strlen(argv[i])))
+ return (1);
+ }
+ Options options(argv[0]);
try
{
- if (!options.initOptions(argc, argv))
- exit(1);
+ if (!options.initOptions(args))
+ return (0);
}
catch( IllegalArgument& e)
{
fprintf(stderr, "Illegal argument: %s\n%s",
e.m_message.getStr(),
options.prepareVersion().getStr());
- exit(99);
+ return (99);
}
setIdlc(&options);
diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx
index b78afe80b..c17927e18 100644
--- a/idlc/source/options.cxx
+++ b/idlc/source/options.cxx
@@ -29,12 +29,25 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_idlc.hxx"
+#include "idlc/options.hxx"
+
+#include "osl/diagnose.h"
+#include "rtl/string.hxx"
+#include "rtl/strbuf.hxx"
+
#include <stdio.h>
-#include /*MSVC trouble: <cstring>*/ <string.h>
-#include <idlc/options.hxx>
+#include <string.h>
using ::rtl::OString;
-Options::Options(): m_stdin(false), m_verbose(false), m_quiet(false)
+using ::rtl::OStringBuffer;
+#ifdef SAL_UNX
+#define SEPARATOR '/'
+#else
+#define SEPARATOR '\\'
+#endif
+
+Options::Options(char const * progname)
+ : m_program(progname), m_stdin(false), m_verbose(false), m_quiet(false)
{
}
@@ -42,274 +55,283 @@ Options::~Options()
{
}
-sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
- throw( IllegalArgument )
+// static
+bool Options::checkArgument (std::vector< std::string > & rArgs, char const * arg, size_t len)
{
- sal_Bool ret = sal_True;
- sal_uInt16 j=0;
-
- if (!bCmdFile)
+ bool result = ((arg != 0) && (len > 0));
+ OSL_PRECOND(result, "idlc::Options::checkArgument(): invalid arguments");
+ if (result)
+ {
+ switch(arg[0])
{
- bCmdFile = sal_True;
-
- m_program = av[0];
-
- if (ac < 2)
+ case '@':
+ if ((result = (len > 1)) == true)
+ {
+ // "@<cmdfile>"
+ result = Options::checkCommandFile (rArgs, &(arg[1]));
+ }
+ break;
+ case '-':
+ if ((result = (len > 1)) == true)
+ {
+ // "-<option>"
+ switch (arg[1])
{
- fprintf(stderr, "%s", prepareHelp().getStr());
- ret = sal_False;
+ case 'O':
+ case 'I':
+ case 'D':
+ {
+ // "-<option>[<param>]
+ std::string option(&(arg[0]), 2);
+ rArgs.push_back(option);
+ if (len > 2)
+ {
+ // "-<option><param>"
+ std::string param(&(arg[2]), len - 2);
+ rArgs.push_back(param);
+ }
+ break;
+ }
+ default:
+ // "-<option>" ([long] option, w/o param)
+ rArgs.push_back(std::string(arg, len));
+ break;
}
-
- j = 1;
- } else
+ }
+ break;
+ default:
+ // "<param>"
+ rArgs.push_back(std::string(arg, len));
+ break;
+ }
+ }
+ return (result);
+}
+
+// static
+bool Options::checkCommandFile (std::vector< std::string > & rArgs, char const * filename)
+{
+ FILE * fp = fopen(filename, "r");
+ if (fp == 0)
{
- j = 0;
+ fprintf(stderr, "ERROR: can't open command file \"%s\"\n", filename);
+ return (false);
}
-
- char *s=NULL;
- for (; j < ac; j++)
+
+ std::string buffer;
+ buffer.reserve(256);
+
+ bool quoted = false;
+ int c = EOF;
+ while ((c = fgetc(fp)) != EOF)
{
- if (av[j][0] == '-')
- {
- switch (av[j][1])
- {
- case 'O':
- if (av[j][2] == '\0')
- {
- if (j < ac - 1 && av[j+1][0] != '-')
- {
- j++;
- s = av[j];
- } else
- {
- OString tmp("'-O', please check");
- if (j <= ac - 1)
- {
- tmp += " your input '" + OString(av[j+1]) + "'";
- }
-
- throw IllegalArgument(tmp);
- }
- } else
- {
- s = av[j] + 2;
- }
-
- m_options["-O"] = OString(s);
- break;
- case 'I':
- {
- if (av[j][2] == '\0')
- {
- if (j < ac - 1 && av[j+1][0] != '-')
- {
- j++;
- s = av[j];
- } else
- {
- OString tmp("'-I', please check");
- if (j <= ac - 1)
- {
- tmp += " your input '" + OString(av[j+1]) + "'";
- }
-
- throw IllegalArgument(tmp);
- }
- } else
- {
- s = av[j] + 2;
- }
-
- OString inc(s);
- if ( inc.indexOf(';') > 0 )
- {
- OString tmp(s);
- sal_Int32 nIndex = 0;
- inc = OString();
- do inc = inc + " -I\"" + tmp.getToken( 0, ';', nIndex ) +"\""; while( nIndex != -1 );
- } else
- inc = OString("-I\"") + s + "\"";
-
- if (m_options.count("-I") > 0)
- {
- OString tmp(m_options["-I"]);
- tmp = tmp + " " + inc;
- m_options["-I"] = tmp;
- } else
- {
- m_options["-I"] = inc;
- }
- }
- break;
- case 'D':
- if (av[j][2] == '\0')
- {
- if (j < ac - 1 && av[j+1][0] != '-')
- {
- j++;
- s = av[j];
- } else
- {
- OString tmp("'-D', please check");
- if (j <= ac - 1)
- {
- tmp += " your input '" + OString(av[j+1]) + "'";
- }
-
- throw IllegalArgument(tmp);
- }
- } else
- {
- s = av[j];
- }
-
- if (m_options.count("-D") > 0)
- {
- OString tmp(m_options["-D"]);
- tmp = tmp + " " + s;
- m_options["-D"] = tmp;
- } else
- m_options["-D"] = OString(s);
- break;
- case 'C':
- if (av[j][2] != '\0')
- {
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- }
- if (m_options.count("-C") == 0)
- m_options["-C"] = OString(av[j]);
- break;
- case 'c':
- if (av[j][2] == 'i' && av[j][3] == 'd' && av[j][4] == '\0')
- {
- if (m_options.count("-cid") == 0)
- m_options["-cid"] = OString(av[j]);
- } else
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- break;
- case 'v':
- if ( 0 == strcmp( &av[j][1], "verbose" ) )
- {
- m_verbose = true;
- }
- else
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- break;
- case 'q':
- if ( 0 == strcmp( &av[j][1], "quiet" ) )
- {
- m_quiet = true;
- }
- else
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- break;
- case 'w':
- if (av[j][2] == 'e' && av[j][3] == '\0') {
- if (m_options.count("-we") == 0)
- m_options["-we"] = OString(av[j]);
- } else {
- if (av[j][2] == '\0') {
- if (m_options.count("-w") == 0)
- m_options["-w"] = OString(av[j]);
- } else
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- }
- break;
- case 'h':
- case '?':
- if (av[j][2] != '\0')
- {
- throw IllegalArgument(OString(av[j]) + ", please check your input");
- } else
- {
- fprintf(stdout, "%s", prepareHelp().getStr());
- exit(0);
- }
- case 's':
- if (/*MSVC trouble: std::*/strcmp(&av[j][2], "tdin") == 0)
- {
- m_stdin = true;
- break;
- }
- // fall through
- default:
- throw IllegalArgument("the option is unknown" + OString(av[j]));
- }
- } else
+ switch(c)
{
- if (av[j][0] == '@')
- {
- FILE* cmdFile = fopen(av[j]+1, "r");
- if( cmdFile == NULL )
+ case '\"':
+ quoted = !quoted;
+ break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if (!quoted)
+ {
+ if (!buffer.empty())
+ {
+ // append current argument.
+ if (!Options::checkArgument(rArgs, buffer.c_str(), buffer.size()))
{
- fprintf(stderr, "%s", prepareHelp().getStr());
- ret = sal_False;
- } else
- {
- int rargc=0;
- char* rargv[512];
- char buffer[512]="";
+ (void) fclose(fp);
+ return (false);
+ }
+ buffer.clear();
+ }
+ break;
+ }
+ default:
+ // quoted white-space fall through
+ buffer.push_back(sal::static_int_cast<char>(c));
+ break;
+ }
+ }
+ if (!buffer.empty())
+ {
+ // append unterminated argument.
+ if (!Options::checkArgument(rArgs, buffer.c_str(), buffer.size()))
+ {
+ (void) fclose(fp);
+ return (false);
+ }
+ buffer.clear();
+ }
+ return (fclose(fp) == 0);
+}
- int i=0;
- int found = 0;
- char c;
- while ( fscanf(cmdFile, "%c", &c) != EOF )
- {
- if (c=='\"') {
- if (found) {
- found=0;
- } else {
- found=1;
- continue;
- }
- } else {
- if (c!=13 && c!=10) {
- if (found || c!=' ') {
- buffer[i++]=c;
- continue;
- }
- }
- if (i==0)
- continue;
- }
- buffer[i]='\0';
- found=0;
- i=0;
- rargv[rargc]= strdup(buffer);
- rargc++;
- buffer[0]='\0';
- }
- if (buffer[0] != '\0') {
- buffer[i]='\0';
- rargv[rargc]= strdup(buffer);
- rargc++;
- }
- fclose(cmdFile);
-
- ret = initOptions(rargc, rargv, bCmdFile);
-
- long ii = 0;
- for (ii=0; ii < rargc; ii++)
- {
- free(rargv[ii]);
- }
- }
- } else
- {
- OString name(av[j]);
- name = name.toAsciiLowerCase();
- if ( name.lastIndexOf(".idl") != (name.getLength() - 4) )
- {
- throw IllegalArgument("'" + OString(av[j]) +
- "' is not a valid input file, only '*.idl' files will be accepted");
- }
- m_inputFiles.push_back(av[j]);
- }
+bool Options::badOption(char const * reason, std::string const & rArg) throw(IllegalArgument)
+{
+ OStringBuffer message;
+ if (reason != 0)
+ {
+ message.append(reason); message.append(" option '"); message.append(rArg.c_str()); message.append("'");
+ throw IllegalArgument(message.makeStringAndClear());
+ }
+ return false;
+}
+
+bool Options::setOption(char const * option, std::string const & rArg)
+{
+ bool result = (0 == strcmp(option, rArg.c_str()));
+ if (result)
+ m_options[rArg.c_str()] = OString(rArg.c_str(), rArg.size());
+ return (result);
+}
+
+bool Options::initOptions(std::vector< std::string > & rArgs) throw(IllegalArgument)
+{
+ std::vector< std::string >::const_iterator first = rArgs.begin(), last = rArgs.end();
+ for (; first != last; ++first)
+ {
+ if ((*first)[0] != '-')
+ {
+ OString filename((*first).c_str(), (*first).size());
+ OString tmp(filename.toAsciiLowerCase());
+ if (tmp.lastIndexOf(".idl") != (tmp.getLength() - 4))
+ {
+ throw IllegalArgument("'" + filename + "' is not a valid input file, only '*.idl' files will be accepted");
+ }
+ m_inputFiles.push_back(filename);
+ continue;
+ }
+
+ std::string const option(*first);
+ switch((*first)[1])
+ {
+ case 'O':
+ {
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", option);
+ }
+ OString param((*first).c_str(), (*first).size());
+ m_options["-O"] = param;
+ break;
+ }
+ case 'I':
+ {
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", option);
+ }
+ OString param((*first).c_str(), (*first).size());
+ {
+ // quote param token(s).
+ OStringBuffer buffer;
+ sal_Int32 k = 0;
+ do
+ {
+ OStringBuffer token; token.append("-I\""); token.append(param.getToken(0, ';', k)); token.append("\"");
+ if (buffer.getLength() > 0)
+ buffer.append(' ');
+ buffer.append(token);
+ } while (k != -1);
+ param = buffer.makeStringAndClear();
+ }
+ if (m_options.count("-I") > 0)
+ {
+ // append param.
+ OStringBuffer buffer(m_options["-I"]);
+ buffer.append(' '); buffer.append(param);
+ param = buffer.makeStringAndClear();
+ }
+ m_options["-I"] = param;
+ break;
+ }
+ case 'D':
+ {
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", option);
+ }
+ OString param("-D"); param += OString((*first).c_str(), (*first).size());
+ if (m_options.count("-D") > 0)
+ {
+ OStringBuffer buffer(m_options["-D"]);
+ buffer.append(' '); buffer.append(param);
+ param = buffer.makeStringAndClear();
+ }
+ m_options["-D"] = param;
+ break;
+ }
+ case 'C':
+ {
+ if (!setOption("-C", option))
+ {
+ return badOption("invalid", option);
}
+ break;
+ }
+ case 'c':
+ {
+ if (!setOption("-cid", option))
+ {
+ return badOption("invalid", option);
+ }
+ break;
+ }
+ case 'q':
+ {
+ if (!setOption("-quiet", option))
+ {
+ return badOption("invalid", option);
+ }
+ m_quiet = true;
+ break;
+ }
+ case 'v':
+ {
+ if (!setOption("-verbose", option))
+ {
+ return badOption("invalid", option);
+ }
+ m_verbose = true;
+ break;
+ }
+ case 'w':
+ {
+ if (!(setOption("-w", option) || setOption("-we", option)))
+ {
+ return badOption("invalid", option);
+ }
+ break;
+ }
+ case 'h':
+ case '?':
+ {
+ if (!(setOption("-h", option) || setOption("-?", option)))
+ {
+ return badOption("invalid", option);
+ }
+ {
+ (void) fprintf(stdout, "%s", prepareHelp().getStr());
+ return (false);
+ }
+ // break; // Unreachable
+ }
+ case 's':
+ {
+ if (!setOption("-stdin", option))
+ {
+ return badOption("invalid", option);
+ }
+ m_stdin = true;
+ break;
+ }
+ default:
+ return badOption("unknown", option);
}
-
- return ret;
-}
+ }
+ return (true);
+}
OString Options::prepareHelp()
{
@@ -335,7 +357,7 @@ OString Options::prepareHelp()
help += " requirements.\n";
help += " -w = display warning messages.\n";
help += " -we = treat warnings as errors.\n";
- help += " -h|-? = print this help message and exit.\n";
+ help += " -h|-? = print this help message and exit.\n\n";
help += prepareVersion();
return help;
@@ -343,8 +365,8 @@ OString Options::prepareHelp()
OString Options::prepareVersion()
{
- OString version("\nSun Microsystems (R) ");
- version += m_program + " Version 1.1\n\n";
+ OString version(m_program);
+ version += " Version 1.1\n\n";
return version;
}
@@ -353,21 +375,19 @@ const OString& Options::getProgramName() const
return m_program;
}
-sal_Bool Options::isValid(const OString& option)
+bool Options::isValid(const OString& option)
{
return (m_options.count(option) > 0);
}
-const OString Options::getOption(const OString& option)
+const OString& Options::getOption(const OString& option)
throw( IllegalArgument )
{
- if (m_options.count(option) > 0)
- {
- return m_options[option];
- } else
+ if (!isValid(option))
{
throw IllegalArgument("Option is not valid or currently not set.");
}
+ return m_options[option];
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/idlc/source/preproc/eval.c b/idlc/source/preproc/eval.c
index e908d19cb..782469924 100644
--- a/idlc/source/preproc/eval.c
+++ b/idlc/source/preproc/eval.c
@@ -25,9 +25,11 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
+
+#include "cpp.h"
+
#include <stdlib.h>
#include <string.h>
-#include "cpp.h"
#define NSTAK 32
#define SGN 0
@@ -737,10 +739,10 @@ struct value
}
else
{
- static char cvcon[]
- = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
+ static char cvcon[] = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
+ static int cvlen = sizeof(cvcon) - 1;
- for (i = 0; i < (int)sizeof(cvcon); i += 2)
+ for (i = 0; i < cvlen; i += 2)
{
if (*p == cvcon[i])
{
@@ -749,9 +751,8 @@ struct value
}
}
p += 1;
- if (i >= (int)sizeof(cvcon))
- error(WARNING,
- "Undefined escape in character constant");
+ if (i >= cvlen)
+ error(WARNING,"Undefined escape in character constant");
}
}
else
diff --git a/idlc/source/preproc/lex.c b/idlc/source/preproc/lex.c
index 2ca70e94d..6f9d27b23 100644
--- a/idlc/source/preproc/lex.c
+++ b/idlc/source/preproc/lex.c
@@ -291,7 +291,7 @@ void
bigfsm[j][fp->state] = (short) nstate;
continue;
case C_ALPH:
- for (j = 0; j <= 256; j++)
+ for (j = 0; j < 256; j++)
if (('a' <= j && j <= 'z') || ('A' <= j && j <= 'Z')
|| j == '_')
bigfsm[j][fp->state] = (short) nstate;
@@ -688,9 +688,13 @@ void
if (s->fd >= 0)
{
- close(s->fd);
- dofree(s->inb);
+ (void) close(s->fd);
+ dofree(s->filename);
}
+
+ if (s->inb)
+ dofree(s->inb);
+
cursource = s->next;
dofree(s);
}
diff --git a/idlc/source/preproc/unix.c b/idlc/source/preproc/unix.c
index 8b39cdd88..3bfb67cef 100644
--- a/idlc/source/preproc/unix.c
+++ b/idlc/source/preproc/unix.c
@@ -92,6 +92,7 @@ void
maketokenrow(3, &tr);
gettokens(&tr, 1);
doadefine(&tr, c);
+ dofree(tr.bp); tr.bp = 0;
unsetsource();
break;