1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*
CVSNT Generic API
Copyright (C) 2004 Tony Hoyle and March-Hare Software Ltd
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdarg.h>
#include <config.h>
#include "lib/api_system.h"
#include <assert.h>
#include <ctype.h>
#include "ServerIO.h"
#ifdef _WIN32
#include "../pcre/pcreposix.h"
#else
#ifdef HAVE_PCRE
#include <pcreposix.h>
#elif defined(HAVE_REGEX_H)
#include <sys/types.h>
#include <regex.h>
#else
#error "Need pcre or regex."
#endif
#endif
#include "cvs_string.h"
// Win32 doesn't support template instantiation, however some
// platforms prefer it.
// OSX barfs if we try this also.
// Also HPUX aCC
#if !defined (_WIN32) && !defined(__APPLE__) && !defined(__hpux)
template class std::char_traits<char>;
template class std::char_traits<wchar_t>;
template class std::basic_string<char>;
template class std::basic_string<wchar_t>;
#endif
// Note that if we're using PCRE the string match is always extended...
// for this reason avoid setting extended=false as it'll behave differently on
// different platforms.
bool cvs::wildcard_filename::matches_regexp(const char *regexp, bool extended /*= true*/)
{
regex_t r;
if(regcomp(&r,regexp,(FsCaseSensitive?0:REG_ICASE)|REG_NOSUB|(extended?REG_EXTENDED:0)))
return false;
int res=regexec(&r,c_str(),0,NULL,0);
regfree(&r);
return res?false:true;
}
// Based on BSD vsprintf
// Assert if a null string reference is passed. Causes
// failure on 'safe' platforms so that unsafe ones eg. solaris
// don't have strange inexplicable crashes.
bool cvs::str_prescan(const char *fmt, va_list va)
{
char *s;
int qualifier;
const char *ofmt = fmt;
int argno = 0;
for (; *fmt ; fmt++)
{
if (*fmt != '%')
continue;
// Process flags
repeat:
fmt++; // This also skips first '%'
switch (*fmt)
{
case '-':
case '+':
case ' ':
case '#':
case '0':
goto repeat;
}
// Get field width
if (isdigit((unsigned char)*fmt))
{
while(isdigit((unsigned char)*fmt))
fmt++;
}
else if (*fmt == '*')
{
fmt++;
va_arg(va, int);
argno++;
}
// Get the precision
if (*fmt == '.')
{
++fmt;
if (isdigit((unsigned char)*fmt))
{
while(isdigit((unsigned char)*fmt))
fmt++;
}
else if (*fmt == '*')
{
++fmt;
va_arg(va, int);
argno++;
}
}
// Get the conversion qualifier
qualifier = -1;
if(!strncmp(fmt,"I64",3))
{
fmt+=3;
qualifier = 'L';
}
else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
{
qualifier = (*fmt++);
if(*fmt=='l' && qualifier=='l')
{
fmt++; // %ll
qualifier = 'L';
}
}
switch (*fmt)
{
case 'c':
va_arg(va, int);
argno++;
continue;
case 's':
case 'S':
s = va_arg(va, char *);
argno++;
if(!s)
{
CServerIo::error("Format = %s\n",ofmt);
CServerIo::error("Argument %d is null\n",argno);
assert(s);
}
continue;
case 'p':
va_arg(va, void *);
argno++;
continue;
case 'n':
va_arg(va, int *);
argno++;
continue;
case 'A':
case 'a':
va_arg(va, unsigned char *);
argno++;
continue;
case 'o':
case 'X':
case 'x':
case 'd':
case 'i':
case 'u':
break;
case 'E':
case 'G':
case 'e':
case 'f':
case 'g':
va_arg(va, double);
argno++;
continue;
default:
if (!*fmt)
--fmt;
continue;
}
if (qualifier == 'L')
{
#ifdef _WIN32
va_arg(va, __int64);
#else
va_arg(va, long long);
#endif
argno++;
}
else if (qualifier == 'l')
{
va_arg(va, long);
argno++;
}
else if (qualifier == 'h')
{
va_arg(va, int);
argno++;
}
else
{
va_arg(va, int);
argno++;
}
}
return true;
}
|