libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_patches.c

Go to the documentation of this file.
00001 /* 00002 * This file is part of "libjf" package. 00003 * 00004 * "libjf" is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 2.1 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * "libjf" is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with ; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 #include "jf_config.h" 00019 00020 00021 00022 #ifdef HAVE_STRING_H 00023 # include <string.h> 00024 #endif /* HAVE_STRING_H */ 00025 #ifdef HAVE_STDIO_H 00026 # include <stdio.h> 00027 #endif /* HAVE_STDIO_H */ 00028 00029 #include <jf/jf_patches.h> 00030 00031 00032 00033 /* set module trace flag */ 00034 #ifdef JF_TRACE_MODULE 00035 # undef JF_TRACE_MODULE 00036 #endif /* JF_TRACE_MODULE */ 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 } /* if (strcmp(argv[optind],"--") == 0) */ 00064 } /* if (flag == 1) */ 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 } /* if (opterr) */ 00077 if (argv[optind][++flag] == '\0') 00078 optind++, flag= 1; 00079 return '?'; 00080 } /* if (opt == ':' || ! (p= strchr(optstring, opt))) */ 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 } /* if (opterr) */ 00096 flag = 1; 00097 return '?'; 00098 } /* if (optind >= argc) */ 00099 optarg = argv[optind++]; 00100 } /* if (argv[optind][flag+1] != '\0') */ 00101 flag = 1; 00102 } else { 00103 if (argv[optind][++flag] == '\0') 00104 flag = 1, optind++; 00105 optarg= 0; 00106 } /* if (*++p == ':') */ 00107 return opt; 00108 } 00109 #endif /* HAVE_GETOPT */ 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 /* __CYGWIN__ */ 00128 #endif /* HAVE_BASENAME */ 00129 00130 00131

Copyright 2005 © Tiian