Fossil SCM

eliminate the need for <tchar.h>

jan.nijtmans 2012-09-21 11:24 trunk
Commit 1bfa3a0bbff5c8cda8c7f74e402a6ad90fc95dd5
2 files changed +18 -19 +5 -5
+18 -19
--- src/main.c
+++ src/main.c
@@ -359,80 +359,79 @@
359359
**
360360
** Results:
361361
** Fills argcPtr with the number of arguments and argvPtr with the array
362362
** of arguments.
363363
*/
364
-#include <tchar.h>
365
-#define tchar_isspace(X) ((X)==TEXT(' ') || (X)==TEXT('\t'))
364
+#define wchar_isspace(X) ((X)==' ' || (X)=='\t')
366365
static void parse_windows_command_line(
367366
int *argcPtr, /* Filled with number of argument strings. */
368367
void *argvPtr /* Filled with argument strings (malloc'd). */
369368
){
370
- TCHAR *cmdLine, *p, *arg, *argSpace;
371
- TCHAR **argv;
369
+ WCHAR *cmdLine, *p, *arg, *argSpace;
370
+ WCHAR **argv;
372371
int argc, size, inquote, copy, slashes;
373372
374373
cmdLine = GetCommandLine();
375374
376375
/*
377376
** Precompute an overly pessimistic guess at the number of arguments in
378377
** the command line by counting non-space spans.
379378
*/
380379
size = 2;
381
- for(p=cmdLine; *p!=TEXT('\0'); p++){
382
- if( tchar_isspace(*p) ){
380
+ for(p=cmdLine; *p!='\0'; p++){
381
+ if( wchar_isspace(*p) ){
383382
size++;
384
- while( tchar_isspace(*p) ){
383
+ while( wchar_isspace(*p) ){
385384
p++;
386385
}
387
- if( *p==TEXT('\0') ){
386
+ if( *p=='\0' ){
388387
break;
389388
}
390389
}
391390
}
392391
393392
argSpace = fossil_malloc(size * sizeof(char*)
394
- + (_tcslen(cmdLine) * sizeof(TCHAR)) + sizeof(TCHAR));
395
- argv = (TCHAR**)argSpace;
396
- argSpace += size*(sizeof(char*)/sizeof(TCHAR));
393
+ + (wcslen(cmdLine) * sizeof(WCHAR)) + sizeof(WCHAR));
394
+ argv = (WCHAR**)argSpace;
395
+ argSpace += size*(sizeof(char*)/sizeof(WCHAR));
397396
size--;
398397
399398
p = cmdLine;
400399
for(argc=0; argc<size; argc++){
401400
argv[argc] = arg = argSpace;
402
- while( tchar_isspace(*p) ){
401
+ while( wchar_isspace(*p) ){
403402
p++;
404403
}
405
- if (*p == TEXT('\0')) {
404
+ if (*p == '\0') {
406405
break;
407406
}
408407
inquote = 0;
409408
slashes = 0;
410409
while(1){
411410
copy = 1;
412
- while( *p==TEXT('\\') ){
411
+ while( *p=='\\' ){
413412
slashes++;
414413
p++;
415414
}
416
- if( *p==TEXT('"') ){
415
+ if( *p=='"' ){
417416
if( (slashes&1)==0 ){
418417
copy = 0;
419
- if( inquote && p[1]==TEXT('"') ){
418
+ if( inquote && p[1]=='"' ){
420419
p++;
421420
copy = 1;
422421
}else{
423422
inquote = !inquote;
424423
}
425424
}
426425
slashes >>= 1;
427426
}
428427
while( slashes ){
429
- *arg = TEXT('\\');
428
+ *arg = '\\';
430429
arg++;
431430
slashes--;
432431
}
433
- if( *p==TEXT('\0') || (!inquote && tchar_isspace(*p)) ){
432
+ if( *p=='\0' || (!inquote && wchar_isspace(*p)) ){
434433
break;
435434
}
436435
if( copy!=0 ){
437436
*arg = *p;
438437
arg++;
@@ -442,11 +441,11 @@
442441
*arg = '\0';
443442
argSpace = arg + 1;
444443
}
445444
argv[argc] = NULL;
446445
*argcPtr = argc;
447
- *((TCHAR ***)argvPtr) = argv;
446
+ *((WCHAR ***)argvPtr) = argv;
448447
}
449448
#endif /* defined(_WIN32) */
450449
451450
452451
/*
453452
--- src/main.c
+++ src/main.c
@@ -359,80 +359,79 @@
359 **
360 ** Results:
361 ** Fills argcPtr with the number of arguments and argvPtr with the array
362 ** of arguments.
363 */
364 #include <tchar.h>
365 #define tchar_isspace(X) ((X)==TEXT(' ') || (X)==TEXT('\t'))
366 static void parse_windows_command_line(
367 int *argcPtr, /* Filled with number of argument strings. */
368 void *argvPtr /* Filled with argument strings (malloc'd). */
369 ){
370 TCHAR *cmdLine, *p, *arg, *argSpace;
371 TCHAR **argv;
372 int argc, size, inquote, copy, slashes;
373
374 cmdLine = GetCommandLine();
375
376 /*
377 ** Precompute an overly pessimistic guess at the number of arguments in
378 ** the command line by counting non-space spans.
379 */
380 size = 2;
381 for(p=cmdLine; *p!=TEXT('\0'); p++){
382 if( tchar_isspace(*p) ){
383 size++;
384 while( tchar_isspace(*p) ){
385 p++;
386 }
387 if( *p==TEXT('\0') ){
388 break;
389 }
390 }
391 }
392
393 argSpace = fossil_malloc(size * sizeof(char*)
394 + (_tcslen(cmdLine) * sizeof(TCHAR)) + sizeof(TCHAR));
395 argv = (TCHAR**)argSpace;
396 argSpace += size*(sizeof(char*)/sizeof(TCHAR));
397 size--;
398
399 p = cmdLine;
400 for(argc=0; argc<size; argc++){
401 argv[argc] = arg = argSpace;
402 while( tchar_isspace(*p) ){
403 p++;
404 }
405 if (*p == TEXT('\0')) {
406 break;
407 }
408 inquote = 0;
409 slashes = 0;
410 while(1){
411 copy = 1;
412 while( *p==TEXT('\\') ){
413 slashes++;
414 p++;
415 }
416 if( *p==TEXT('"') ){
417 if( (slashes&1)==0 ){
418 copy = 0;
419 if( inquote && p[1]==TEXT('"') ){
420 p++;
421 copy = 1;
422 }else{
423 inquote = !inquote;
424 }
425 }
426 slashes >>= 1;
427 }
428 while( slashes ){
429 *arg = TEXT('\\');
430 arg++;
431 slashes--;
432 }
433 if( *p==TEXT('\0') || (!inquote && tchar_isspace(*p)) ){
434 break;
435 }
436 if( copy!=0 ){
437 *arg = *p;
438 arg++;
@@ -442,11 +441,11 @@
442 *arg = '\0';
443 argSpace = arg + 1;
444 }
445 argv[argc] = NULL;
446 *argcPtr = argc;
447 *((TCHAR ***)argvPtr) = argv;
448 }
449 #endif /* defined(_WIN32) */
450
451
452 /*
453
--- src/main.c
+++ src/main.c
@@ -359,80 +359,79 @@
359 **
360 ** Results:
361 ** Fills argcPtr with the number of arguments and argvPtr with the array
362 ** of arguments.
363 */
364 #define wchar_isspace(X) ((X)==' ' || (X)=='\t')
 
365 static void parse_windows_command_line(
366 int *argcPtr, /* Filled with number of argument strings. */
367 void *argvPtr /* Filled with argument strings (malloc'd). */
368 ){
369 WCHAR *cmdLine, *p, *arg, *argSpace;
370 WCHAR **argv;
371 int argc, size, inquote, copy, slashes;
372
373 cmdLine = GetCommandLine();
374
375 /*
376 ** Precompute an overly pessimistic guess at the number of arguments in
377 ** the command line by counting non-space spans.
378 */
379 size = 2;
380 for(p=cmdLine; *p!='\0'; p++){
381 if( wchar_isspace(*p) ){
382 size++;
383 while( wchar_isspace(*p) ){
384 p++;
385 }
386 if( *p=='\0' ){
387 break;
388 }
389 }
390 }
391
392 argSpace = fossil_malloc(size * sizeof(char*)
393 + (wcslen(cmdLine) * sizeof(WCHAR)) + sizeof(WCHAR));
394 argv = (WCHAR**)argSpace;
395 argSpace += size*(sizeof(char*)/sizeof(WCHAR));
396 size--;
397
398 p = cmdLine;
399 for(argc=0; argc<size; argc++){
400 argv[argc] = arg = argSpace;
401 while( wchar_isspace(*p) ){
402 p++;
403 }
404 if (*p == '\0') {
405 break;
406 }
407 inquote = 0;
408 slashes = 0;
409 while(1){
410 copy = 1;
411 while( *p=='\\' ){
412 slashes++;
413 p++;
414 }
415 if( *p=='"' ){
416 if( (slashes&1)==0 ){
417 copy = 0;
418 if( inquote && p[1]=='"' ){
419 p++;
420 copy = 1;
421 }else{
422 inquote = !inquote;
423 }
424 }
425 slashes >>= 1;
426 }
427 while( slashes ){
428 *arg = '\\';
429 arg++;
430 slashes--;
431 }
432 if( *p=='\0' || (!inquote && wchar_isspace(*p)) ){
433 break;
434 }
435 if( copy!=0 ){
436 *arg = *p;
437 arg++;
@@ -442,11 +441,11 @@
441 *arg = '\0';
442 argSpace = arg + 1;
443 }
444 argv[argc] = NULL;
445 *argcPtr = argc;
446 *((WCHAR ***)argvPtr) = argv;
447 }
448 #endif /* defined(_WIN32) */
449
450
451 /*
452
+5 -5
--- src/winhttp.c
+++ src/winhttp.c
@@ -146,11 +146,11 @@
146146
SOCKET s = INVALID_SOCKET;
147147
SOCKADDR_IN addr;
148148
int idCnt = 0;
149149
int iPort = mnPort;
150150
Blob options;
151
- TCHAR zTmpPath[MAX_PATH];
151
+ WCHAR zTmpPath[MAX_PATH];
152152
153153
if( zStopper ) file_delete(zStopper);
154154
blob_zero(&options);
155155
if( zNotFound ){
156156
blob_appendf(&options, " --notfound %s", zNotFound);
@@ -249,11 +249,11 @@
249249
struct HttpService {
250250
int port; /* Port on which the http server should run */
251251
const char *zNotFound; /* The --notfound option, or NULL */
252252
int flags; /* One or more HTTP_SERVER_ flags */
253253
int isRunningAsService; /* Are we running as a service ? */
254
- const TCHAR *zServiceName;/* Name of the service */
254
+ const WCHAR *zServiceName;/* Name of the service */
255255
SOCKET s; /* Socket on which the http server listens */
256256
};
257257
258258
/*
259259
** Variables used for running as windows service.
@@ -384,11 +384,11 @@
384384
if( argc>0 ){
385385
hsData.zServiceName = argv[0];
386386
}
387387
388388
/* Register the service control handler function */
389
- sshStatusHandle = RegisterServiceCtrlHandler(TEXT(""), win32_http_service_ctrl);
389
+ sshStatusHandle = RegisterServiceCtrlHandler(L"", win32_http_service_ctrl);
390390
if( !sshStatusHandle ){
391391
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
392392
return;
393393
}
394394
@@ -429,11 +429,11 @@
429429
const char *zNotFound, /* The --notfound option, or NULL */
430430
int flags /* One or more HTTP_SERVER_ flags */
431431
){
432432
/* Define the service table. */
433433
SERVICE_TABLE_ENTRY ServiceTable[] =
434
- {{TEXT(""), (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
434
+ {{L"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
435435
436436
/* Initialize the HttpService structure. */
437437
hsData.port = nPort;
438438
hsData.zNotFound = zNotFound;
439439
hsData.flags = flags;
@@ -566,11 +566,11 @@
566566
567567
if( strncmp(zMethod, "create", n)==0 ){
568568
SC_HANDLE hScm;
569569
SC_HANDLE hSvc;
570570
SERVICE_DESCRIPTION
571
- svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
571
+ svcDescr = {L"Fossil - Distributed Software Configuration Management"};
572572
char *zErrFmt = "unable to create service '%s': %s";
573573
DWORD dwStartType = SERVICE_DEMAND_START;
574574
const char *zDisplay = find_option("display", "D", 1);
575575
const char *zStart = find_option("start", "S", 1);
576576
const char *zUsername = find_option("username", "U", 1);
577577
--- src/winhttp.c
+++ src/winhttp.c
@@ -146,11 +146,11 @@
146 SOCKET s = INVALID_SOCKET;
147 SOCKADDR_IN addr;
148 int idCnt = 0;
149 int iPort = mnPort;
150 Blob options;
151 TCHAR zTmpPath[MAX_PATH];
152
153 if( zStopper ) file_delete(zStopper);
154 blob_zero(&options);
155 if( zNotFound ){
156 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -249,11 +249,11 @@
249 struct HttpService {
250 int port; /* Port on which the http server should run */
251 const char *zNotFound; /* The --notfound option, or NULL */
252 int flags; /* One or more HTTP_SERVER_ flags */
253 int isRunningAsService; /* Are we running as a service ? */
254 const TCHAR *zServiceName;/* Name of the service */
255 SOCKET s; /* Socket on which the http server listens */
256 };
257
258 /*
259 ** Variables used for running as windows service.
@@ -384,11 +384,11 @@
384 if( argc>0 ){
385 hsData.zServiceName = argv[0];
386 }
387
388 /* Register the service control handler function */
389 sshStatusHandle = RegisterServiceCtrlHandler(TEXT(""), win32_http_service_ctrl);
390 if( !sshStatusHandle ){
391 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
392 return;
393 }
394
@@ -429,11 +429,11 @@
429 const char *zNotFound, /* The --notfound option, or NULL */
430 int flags /* One or more HTTP_SERVER_ flags */
431 ){
432 /* Define the service table. */
433 SERVICE_TABLE_ENTRY ServiceTable[] =
434 {{TEXT(""), (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
435
436 /* Initialize the HttpService structure. */
437 hsData.port = nPort;
438 hsData.zNotFound = zNotFound;
439 hsData.flags = flags;
@@ -566,11 +566,11 @@
566
567 if( strncmp(zMethod, "create", n)==0 ){
568 SC_HANDLE hScm;
569 SC_HANDLE hSvc;
570 SERVICE_DESCRIPTION
571 svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
572 char *zErrFmt = "unable to create service '%s': %s";
573 DWORD dwStartType = SERVICE_DEMAND_START;
574 const char *zDisplay = find_option("display", "D", 1);
575 const char *zStart = find_option("start", "S", 1);
576 const char *zUsername = find_option("username", "U", 1);
577
--- src/winhttp.c
+++ src/winhttp.c
@@ -146,11 +146,11 @@
146 SOCKET s = INVALID_SOCKET;
147 SOCKADDR_IN addr;
148 int idCnt = 0;
149 int iPort = mnPort;
150 Blob options;
151 WCHAR zTmpPath[MAX_PATH];
152
153 if( zStopper ) file_delete(zStopper);
154 blob_zero(&options);
155 if( zNotFound ){
156 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -249,11 +249,11 @@
249 struct HttpService {
250 int port; /* Port on which the http server should run */
251 const char *zNotFound; /* The --notfound option, or NULL */
252 int flags; /* One or more HTTP_SERVER_ flags */
253 int isRunningAsService; /* Are we running as a service ? */
254 const WCHAR *zServiceName;/* Name of the service */
255 SOCKET s; /* Socket on which the http server listens */
256 };
257
258 /*
259 ** Variables used for running as windows service.
@@ -384,11 +384,11 @@
384 if( argc>0 ){
385 hsData.zServiceName = argv[0];
386 }
387
388 /* Register the service control handler function */
389 sshStatusHandle = RegisterServiceCtrlHandler(L"", win32_http_service_ctrl);
390 if( !sshStatusHandle ){
391 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
392 return;
393 }
394
@@ -429,11 +429,11 @@
429 const char *zNotFound, /* The --notfound option, or NULL */
430 int flags /* One or more HTTP_SERVER_ flags */
431 ){
432 /* Define the service table. */
433 SERVICE_TABLE_ENTRY ServiceTable[] =
434 {{L"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
435
436 /* Initialize the HttpService structure. */
437 hsData.port = nPort;
438 hsData.zNotFound = zNotFound;
439 hsData.flags = flags;
@@ -566,11 +566,11 @@
566
567 if( strncmp(zMethod, "create", n)==0 ){
568 SC_HANDLE hScm;
569 SC_HANDLE hSvc;
570 SERVICE_DESCRIPTION
571 svcDescr = {L"Fossil - Distributed Software Configuration Management"};
572 char *zErrFmt = "unable to create service '%s': %s";
573 DWORD dwStartType = SERVICE_DEMAND_START;
574 const char *zDisplay = find_option("display", "D", 1);
575 const char *zStart = find_option("start", "S", 1);
576 const char *zUsername = find_option("username", "U", 1);
577

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button