CmdLineApp.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1996 James Clark
// See the file COPYING for copying permission.
#pragma ident "%Z%%M% %I% %E% SMI"
// Need option registration method that allows derived class to change
// option names.
#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "CmdLineApp.h"
#include "CmdLineAppMessages.h"
#include "MessageArg.h"
#include "ErrnoMessageArg.h"
#include "Options.h"
#include "version.h"
#include "xnew.h"
#include "macros.h"
#include "sptchar.h"
#include "MessageTable.h"
#include "CodingSystemKit.h"
#include "ConsoleOutput.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef SP_HAVE_LOCALE
#include <locale.h>
#endif
#ifdef SP_HAVE_SETMODE
#include <fcntl.h>
#include <io.h>
#endif
#ifdef SP_INCLUDE_UNISTD_H
#include <unistd.h>
#endif
#ifdef SP_INCLUDE_IO_H
#include <io.h>
#endif
#ifdef _MSC_VER
#include <crtdbg.h>
#endif
#ifndef SP_DEFAULT_ENCODING
#ifdef WIN32
#else
#endif
#endif /* not SP_DEFAULT_ENCODING */
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
: errorFile_(0),
// Colon at beginning is Posix.2ism that says to return : rather than ? for
// missing option argument.
MessageReporter(0),
{
registerOption('v');
}
void CmdLineApp::resetCodingSystemKit()
{
}
{
optstr_ += c;
if (argName) {
}
}
{
if (progName)
for (int i = 0; i < 128; i++)
hadOption[i] = 0;
Boolean hadNoArgOption = 0;
if (optstr_[i] == 0)
break;
i++;
if (!hadNoArgOption) {
hadNoArgOption = 1;
}
}
}
if (hadNoArgOption)
size_t j = 0;
}
i++;
j++;
}
}
result += 0;
}
static
void ewrite(const char *s)
{
int n = (int)strlen(s);
while (n > 0) {
if (nw < 0)
break;
n -= nw;
s += nw;
}
}
static
#ifdef SP_FANCY_NEW_HANDLER
int outOfMemory(size_t)
#else
void outOfMemory()
#endif
{
ewrite("SP library: out of memory\n");
exit(1);
#ifdef SP_FANCY_NEW_HANDLER
return 0;
#endif
}
{
#ifndef SP_ANSI_LIB
#endif
#ifdef SP_HAVE_LOCALE
#endif
#ifdef SP_HAVE_SETMODE
#endif
if (progName)
return 0;
}
{
#ifdef _MSC_VER
#endif
#ifdef SP_ANSI_LIB
try {
#endif
if (ret)
return ret;
int firstArg;
if (ret)
return ret;
progName = 0;
return ret;
#ifdef SP_ANSI_LIB
}
catch (
#ifndef SP_NO_STD_NAMESPACE
std::
#endif
bad_alloc) {
#ifdef SP_FANCY_NEW_HANDLER
outOfMemory(0);
#else
outOfMemory();
#endif
}
return 1;
#endif /* SP_ANSI_LIB */
}
{
switch (opt) {
case ':':
return 1;
case '?':
return 1;
default:
break;
}
}
if (errorFile_) {
static FileOutputByteStream file;
return 1;
}
}
if (!outputCodingSystem_)
return 0;
}
{
switch (opt) {
case 'b':
if (!outputCodingSystem_)
break;
case 'f':
errorFile_ = arg;
break;
case 'v':
// print the version number
break;
default:
}
}
{
return 0;
#ifdef SP_WIDE_SYSTEM
#else
str += 0;
#endif
return 1;
}
{
return 0;
}
return *s == '\0';
}
{
const char *name = requiredInternalCode;
#ifdef SP_MULTI_BYTE
char buf[256];
if (!name) {
if (internalCode) {
for (size_t i = 0; i < 255; i++) {
buf[i] = internalCode[i];
if (buf[i] == '\0')
break;
}
}
}
if (requiredInternalCode)
else {
if (useInternal
}
#endif /* SP_MULTI_BYTE */
? SP_T("SP_BCTF")
: SP_T("SP_ENCODING"));
if (codingName)
#ifdef SP_MULTI_BYTE
if (!codingSystem_ && !internalCharsetIsDocCharset_)
#endif
if (!codingSystem_
#ifndef SP_WIDE_SYSTEM
#endif
)
}
const CodingSystem *
{
#define MAX_CS_NAME 50
char buf[MAX_CS_NAME];
int i;
SP_TUCHAR c = codingName[i];
#ifdef SP_WIDE_SYSTEM
if (c > (unsigned char)-1)
return 0;
#endif
buf[i] = char(c);
}
buf[i] = '\0';
}
return 0;
}
{
#ifdef SP_WIDE_SYSTEM
#else
#endif
if (str[i] == '\n')
str[i] = '\r';
return str;
}
{
if (os)
return os;
}
{
if (os)
return os;
}
{
return CmdLineAppMessages::openFileError;
}
{
return CmdLineAppMessages::closeFileError;
}
#ifdef SP_NAMESPACE
}
#endif