Made non MSVC include files conditional.

* Made unistd.h include conditional by cmake HAVE_UNISTD_H flag.
* Made dirent.h include conditional by cmake HAVE_DIRENT_H flag.
* Made sys/params.h include conditional by cmake HAVE_SYS_PARAMS_H flag.
* Made stdbool.h include conditinal by cmake HAVE_STDBOOL_H flag.
* Added scl_stdbool.h as an alternative for stdbool.h.
* Added xgetopt.cc/xgetopt.h to be included when HAVE_GETOPT flag false.
This commit is contained in:
davyw 2011-12-01 21:25:08 +01:00 committed by Mark Pictor
parent 48dff49299
commit 71bd7b235a
17 changed files with 377 additions and 17 deletions

View file

@ -204,12 +204,16 @@ INCLUDE(${SCL_CMAKE_DIR}/FindYACC.cmake)
CHECK_INCLUDE_FILE(ndir.h HAVE_NDIR_H)
CHECK_INCLUDE_FILE(stdarg.h HAVE_STDARG_H)
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE(sys/params.h HAVE_SYS_PARAMS_H)
CHECK_INCLUDE_FILE(sysent.h HAVE_SYSENT_H)
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
CHECK_FUNCTION_EXISTS(abs HAVE_ABS)
CHECK_FUNCTION_EXISTS(memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS(getopt HAVE_GETOPT)
CHECK_TYPE_SIZE("ssize_t" SSIZE_T)

View file

@ -72,14 +72,18 @@
*
*/
#include <scl_cf.h>
#include <stdio.h>
/******************************/
/* type Boolean and constants */
/******************************/
#include <stdbool.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# include <scl_stdbool.h>
#endif
/************************/
/* Generic pointer type */

View file

@ -1,11 +1,20 @@
#ifndef SCL_CF_H
#define SCL_CF_H
/**** Define statements for CMake ****/
#cmakedefine HAVE_NDIR_H 1
#cmakedefine HAVE_STDARG_H 1
#cmakedefine HAVE_SYS_STAT_H 1
#cmakedefine HAVE_SYSENT_H 1
#cmakedefine HAVE_UNISTD_H 1
#cmakedefine HAVE_DIRENT_H 1
#cmakedefine HAVE_STDBOOL_H 1
#cmakedefine HAVE_ABS 1
#cmakedefine HAVE_MEMCPY 1
#cmakedefine HAVE_MEMMOVE 1
#cmakedefine HAVE_GETOPT 1
#cmakedefine HAVE_SSIZE_T 1
#endif /* SCL_CF_H */

54
include/scl_stdbool.h Normal file
View file

@ -0,0 +1,54 @@
#ifndef STDBOOL_H_
#define STDBOOL_H_
/**
* stdbool.h - ISO C99 Boolean type
* Author - Bill Chatfield
* E-mail - bill underscore chatfield at yahoo dot com
* Copyright - You are free to use for any purpose except illegal acts
* Warrenty - None: don't blame me if it breaks something
*
* In ISO C99, stdbool.h is a standard header and _Bool is a keyword, but
* some compilers don't offer these yet. This header file is an
* implementation of the standard ISO C99 stdbool.h header file. It checks
* for various compiler versions and defines things that are missing in
* those versions.
*
* The GNU and Watcom compilers include a stdbool.h, but the Borland
* C/C++ 5.5.1 compiler and the Microsoft compilers do not.
*
* See http://predef.sourceforge.net/precomp.html for compile macros.
*/
#ifndef __cplusplus
/**
* Borland C++ 5.5.1 does not define _Bool.
*/
#ifdef __BORLANDC__
typedef int _Bool;
#endif
/**
* Microsoft C/C++ version 14.00.50727.762, which comes with Visual C++ 2005,
* and version 15.00.30729.01, which comes with Visual C++ 2008, do not
* define _Bool.
*/
#if defined(_MSC_VER)
typedef int _Bool;
#endif
/**
* Define the Boolean macros only if they are not already defined.
*/
#ifndef __bool_true_false_are_defined
#define bool _Bool
#define Boolean _Bool
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif
#endif /* __cplusplus */
#endif /*STDBOOL_H_*/

View file

@ -39,10 +39,11 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <scl_cf.h>
#include <dirobj.h>
#include <dirent.h>
# include <scl_cf.h>
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
/* for stat() file status */
#ifdef HAVE_SYS_STAT_H

View file

@ -33,10 +33,13 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <scl_cf.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#ifdef HAVE_SYS_PARAMS_H
# include <sys/param.h>
#endif
#include <string>

View file

@ -1,10 +1,17 @@
#include <scl_cf.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdbool.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# include <scl_stdbool.h>
#endif
#ifdef __STDC__
#include <stdarg.h>

View file

@ -64,6 +64,10 @@ include_directories(
add_definitions( -DFLEX )
if(MSVC)
add_definitions( -DYY_NO_UNISTD_H )
endif(MSVC)
SCL_ADDLIB(express "${EXPRESS_SOURCES}" "")
if(APPLE)

View file

@ -51,10 +51,13 @@
* prettied up interface to print_objects_when_running
*/
#include <scl_cf.h>
#include <stdlib.h>
#include "conf.h"
#include <setjmp.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#define ERROR_C
#include "signal.h"

View file

@ -70,8 +70,11 @@
*
*/
#include <scl_cf.h>
#define EXPRESSION_C
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "express/expr.h"
#include "express/resolve.h"

View file

@ -67,6 +67,7 @@
*
*/
#include <scl_cf.h>
#define EXPRESS_C
#include "conf.h"
#include "express/basic.h"
@ -74,7 +75,9 @@
#include <stdlib.h>
#include <setjmp.h>
#include <errno.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "express/express.h"
#include "express/resolve.h"

View file

@ -71,11 +71,16 @@
*
*/
#include "scl_cf.h"
#include <scl_cf.h>
#include "scl_version_string.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifndef HAVE_GETOPT
# include <xgetopt.h>
#endif
#include "express/error.h"
#include "express/express.h"
#include "express/resolve.h"

View file

@ -55,9 +55,12 @@
*
*/
#include <scl_cf.h>
#define RESOLVE_C
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "express/resolve.h"
#include "stack.h"
#include "express/schema.h"

View file

@ -45,8 +45,11 @@
* prettied up interface to print_objects_when_running
*/
#include <scl_cf.h>
#define SCHEMA_C
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "express/expbasic.h"
#include "express/schema.h"
#include "express/object.h"

216
src/express/xgetopt.cc Normal file
View file

@ -0,0 +1,216 @@
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are using precompiled headers then include this line:
//#include "stdafx.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
#include <windows.h>
#include <stdio.h>
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
//
// extern TCHAR *optarg;
// extern int optind;
//
// DESCRIPTION
// The getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. optarg
// is set to point to the start of the option argument on return from
// getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// getopt places in the external variable optind the argv index
// of the next argument to be processed. optind is initialized
// to 0 before the first call to getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), getopt returns EOF, optarg will point
// to the argument, and optind will be set to the argv index of
// the argument. If there are no non-option arguments, optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, getopt
// will return the option letter. getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// {
// int c;
//
// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;
if (optind == 0)
next = NULL;
optarg = NULL;
if (next == NULL || *next == _T('\0'))
{
if (optind == 0)
optind++;
if (optind >= argc || argv[optind][0] != _T('-') || argv[optind][1] == _T('\0'))
{
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
if (_tcscmp(argv[optind], _T("--")) == 0)
{
optind++;
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
next = argv[optind];
next++; // skip past -
optind++;
}
TCHAR c = *next++;
TCHAR *cp = _tcschr(optstring, c);
if (cp == NULL || c == _T(':'))
return _T('?');
cp++;
if (*cp == _T(':'))
{
if (*next != _T('\0'))
{
optarg = next;
next = NULL;
}
else if (optind < argc)
{
optarg = argv[optind];
optind++;
}
else
{
return _T('?');
}
}
return c;
}

33
src/express/xgetopt.h Normal file
View file

@ -0,0 +1,33 @@
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XGETOPT_H
#define XGETOPT_H
#include <tchar.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int optind, opterr;
extern TCHAR *optarg;
int getopt(int argc, TCHAR *argv[], TCHAR *optstring);
#ifdef __cplusplus
}
#endif
#endif //XGETOPT_H

View file

@ -11,7 +11,7 @@
** name of the file to be output may also be provided, if no name is
** provided the file written out is called file.out
*/
#include <scl_cf.h>
extern void SchemaInit( class Registry & );
#include "scl_version_string.h"
#include <STEPfile.h>
@ -22,7 +22,12 @@ extern void SchemaInit( class Registry & );
#include <errordesc.h>
#include <algorithm>
#include <string>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifndef HAVE_GETOPT
# include <xgetopt.h>
#endif
/**
* Compare the schema names from the lib (generated by fedex_plus) and