Changed xgetopt module to remove unicode support.

* Since the unicode support (TCHAR, _T, ...) did not build with borland
  makefiles target I removed unicode support temporarily since most scl
  code does not support unicode yet.
This commit is contained in:
davyw 2011-12-21 21:31:49 +01:00
parent c0c423c625
commit 2d26da7d24
4 changed files with 38 additions and 71 deletions

View file

@ -15,16 +15,14 @@
#ifndef XGETOPT_H
#define XGETOPT_H
#include <tchar.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int optind, opterr;
extern TCHAR * optarg;
extern char * optarg;
int getopt( int argc, TCHAR * argv[], TCHAR * optstring );
int getopt( int argc, char * argv[], char * optstring );
#ifdef __cplusplus
}

View file

@ -31,8 +31,9 @@
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
#include <windows.h>
//#include <windows.h>
#include <stdio.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
@ -46,9 +47,9 @@
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
// int getopt(int argc, char *argv[], char *optstring)
//
// extern TCHAR *optarg;
// extern char *optarg;
// extern int optind;
//
// DESCRIPTION
@ -101,7 +102,7 @@
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[])
// {
// int c;
//
@ -149,23 +150,23 @@
//
///////////////////////////////////////////////////////////////////////////////
TCHAR * optarg; // global argument pointer
char * optarg; // global argument pointer
int optind = 0; // global argv index
int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
static TCHAR * next = NULL;
int getopt( int argc, char * argv[], char * optstring ) {
static char * next = NULL;
if( optind == 0 ) {
next = NULL;
}
optarg = NULL;
if( next == NULL || *next == _T( '\0' ) ) {
if( next == NULL || *next == '\0' ) {
if( optind == 0 ) {
optind++;
}
if( optind >= argc || argv[optind][0] != _T( '-' ) || argv[optind][1] == _T( '\0' ) ) {
if( optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0' ) {
optarg = NULL;
if( optind < argc ) {
optarg = argv[optind];
@ -173,7 +174,7 @@ int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
return EOF;
}
if( _tcscmp( argv[optind], _T( "--" ) ) == 0 ) {
if( strcmp( argv[optind], "--" ) == 0 ) {
optind++;
optarg = NULL;
if( optind < argc ) {
@ -187,23 +188,23 @@ int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
optind++;
}
TCHAR c = *next++;
TCHAR * cp = _tcschr( optstring, c );
char c = *next++;
char * cp = strchr( optstring, c );
if( cp == NULL || c == _T( ':' ) ) {
return _T( '?' );
if( cp == NULL || c == ':' ) {
return '?';
}
cp++;
if( *cp == _T( ':' ) ) {
if( *next != _T( '\0' ) ) {
if( *cp == ':' ) {
if( *next != '\0' ) {
optarg = next;
next = NULL;
} else if( optind < argc ) {
optarg = argv[optind];
optind++;
} else {
return _T( '?' );
return '?';
}
}

View file

@ -1,33 +0,0 @@
// 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

@ -31,8 +31,9 @@
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
#include <windows.h>
//#include <windows.h>
#include <stdio.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
@ -46,9 +47,9 @@
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
// int getopt(int argc, char *argv[], char *optstring)
//
// extern TCHAR *optarg;
// extern char *optarg;
// extern int optind;
//
// DESCRIPTION
@ -101,7 +102,7 @@
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[])
// {
// int c;
//
@ -149,23 +150,23 @@
//
///////////////////////////////////////////////////////////////////////////////
TCHAR * optarg; // global argument pointer
char * optarg; // global argument pointer
int optind = 0; // global argv index
int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
static TCHAR * next = NULL;
int getopt( int argc, char * argv[], char * optstring ) {
static char * next = NULL;
if( optind == 0 ) {
next = NULL;
}
optarg = NULL;
if( next == NULL || *next == _T( '\0' ) ) {
if( next == NULL || *next == '\0' ) {
if( optind == 0 ) {
optind++;
}
if( optind >= argc || argv[optind][0] != _T( '-' ) || argv[optind][1] == _T( '\0' ) ) {
if( optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0' ) {
optarg = NULL;
if( optind < argc ) {
optarg = argv[optind];
@ -173,7 +174,7 @@ int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
return EOF;
}
if( _tcscmp( argv[optind], _T( "--" ) ) == 0 ) {
if( strcmp( argv[optind], "--" ) == 0 ) {
optind++;
optarg = NULL;
if( optind < argc ) {
@ -187,23 +188,23 @@ int getopt( int argc, TCHAR * argv[], TCHAR * optstring ) {
optind++;
}
TCHAR c = *next++;
TCHAR * cp = _tcschr( optstring, c );
char c = *next++;
char * cp = strchr( optstring, c );
if( cp == NULL || c == _T( ':' ) ) {
return _T( '?' );
if( cp == NULL || c == ':' ) {
return '?';
}
cp++;
if( *cp == _T( ':' ) ) {
if( *next != _T( '\0' ) ) {
if( *cp == ':' ) {
if( *next != '\0' ) {
optarg = next;
next = NULL;
} else if( optind < argc ) {
optarg = argv[optind];
optind++;
} else {
return _T( '?' );
return '?';
}
}