00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
#include "jf_config.h"
00019
00020
00021
00022
#ifdef HAVE_STRING_H
00023
# include <string.h>
00024
#endif
00025
#ifdef HAVE_STDIO_H
00026
# include <stdio.h>
00027
#endif
00028
00029
#include <jf/jf_patches.h>
00030
00031
00032
00033
00034
#ifdef JF_TRACE_MODULE
00035
# undef JF_TRACE_MODULE
00036
#endif
00037 #define JF_TRACE_MODULE JF_TRACE_MOD_LIB_PATCHES
00038
00039
00040
00041
#ifndef HAVE_GETOPT
00042 int opterr= 1;
00043 int optind= 1;
00044 int optopt= 0;
00045 char *
optarg= 0;
00046 static const char error1[]=
": option require an argument -- ";
00047 static const char error2[]=
": illegal option -- ";
00048
00049 int getopt(
int argc,
char *
const argv[],
const char *optstring)
00050 {
00051
static int flag= 1;
00052
char ct[2];
00053
int opt;
00054
char *p, *q;
00055
00056
if (flag == 1) {
00057
if (
optind >= argc || argv[
optind][0] !=
'-' ||
00058 argv[
optind][1] ==
'\0')
00059
return -1;
00060
if (strcmp(argv[
optind],
"--") == 0) {
00061
optind++;
00062
return -1;
00063 }
00064 }
00065
optopt = opt = argv[
optind][flag];
00066
00067
if (opt ==
':' || ! (p= strchr(optstring, opt))) {
00068
if (
opterr) {
00069 ct[0]= opt;
00070 ct[1]=
'\n';
00071 q = strrchr(argv[0],
'\\');
00072 q = q == NULL ? argv[0] : q+1;
00073 fwrite(strlwr(q), strlen(q), 1, stderr);
00074 fwrite(
error2, strlen(
error2), 1, stderr);
00075 fwrite(ct, 2, 1, stderr);
00076 }
00077
if (argv[
optind][++flag] ==
'\0')
00078
optind++, flag= 1;
00079
return '?';
00080 }
00081
if (*++p ==
':') {
00082
if (argv[
optind][flag+1] !=
'\0') {
00083
optarg= &argv[
optind++][flag+1];
00084 }
else {
00085
optind++;
00086
if (
optind >= argc) {
00087
if (
opterr) {
00088 ct[0] = opt;
00089 ct[1] =
'\n';
00090 fwrite(argv[0], strlen(argv[0]), 1,
00091 stderr);
00092 fwrite(
error1, strlen(
error1), 1,
00093 stderr);
00094 fwrite(ct, 2, 1, stderr);
00095 }
00096 flag = 1;
00097
return '?';
00098 }
00099
optarg = argv[
optind++];
00100 }
00101 flag = 1;
00102 }
else {
00103
if (argv[
optind][++flag] ==
'\0')
00104 flag = 1,
optind++;
00105
optarg= 0;
00106 }
00107
return opt;
00108 }
00109
#endif
00110
00111
00112
00113
#ifndef HAVE_BASENAME
00114
# ifdef __CYGWIN__
00115
char *basename(
char *path)
00116 {
00117
if (NULL == path ||
'\0' == *path)
00118
return ".";
00119
else if (NULL == strchr(path,
'/'))
00120
return path;
00121
else if (0 == strcmp(path,
"/"))
00122
return "/";
00123
if (strrchr(path,
'/') == path + strlen(path) - 1)
00124 *(strrchr(path,
'/')) =
'\0';
00125
return strrchr(path,
'/') + 1;
00126 }
00127
# endif
00128
#endif
00129
00130
00131