Fossil SCM
eliminate the need for <tchar.h>
Commit
1bfa3a0bbff5c8cda8c7f74e402a6ad90fc95dd5
Parent
ad91647ea761c65…
2 files changed
+18
-19
+5
-5
+18
-19
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -359,80 +359,79 @@ | ||
| 359 | 359 | ** |
| 360 | 360 | ** Results: |
| 361 | 361 | ** Fills argcPtr with the number of arguments and argvPtr with the array |
| 362 | 362 | ** of arguments. |
| 363 | 363 | */ |
| 364 | -#include <tchar.h> | |
| 365 | -#define tchar_isspace(X) ((X)==TEXT(' ') || (X)==TEXT('\t')) | |
| 364 | +#define wchar_isspace(X) ((X)==' ' || (X)=='\t') | |
| 366 | 365 | static void parse_windows_command_line( |
| 367 | 366 | int *argcPtr, /* Filled with number of argument strings. */ |
| 368 | 367 | void *argvPtr /* Filled with argument strings (malloc'd). */ |
| 369 | 368 | ){ |
| 370 | - TCHAR *cmdLine, *p, *arg, *argSpace; | |
| 371 | - TCHAR **argv; | |
| 369 | + WCHAR *cmdLine, *p, *arg, *argSpace; | |
| 370 | + WCHAR **argv; | |
| 372 | 371 | int argc, size, inquote, copy, slashes; |
| 373 | 372 | |
| 374 | 373 | cmdLine = GetCommandLine(); |
| 375 | 374 | |
| 376 | 375 | /* |
| 377 | 376 | ** Precompute an overly pessimistic guess at the number of arguments in |
| 378 | 377 | ** the command line by counting non-space spans. |
| 379 | 378 | */ |
| 380 | 379 | 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) ){ | |
| 383 | 382 | size++; |
| 384 | - while( tchar_isspace(*p) ){ | |
| 383 | + while( wchar_isspace(*p) ){ | |
| 385 | 384 | p++; |
| 386 | 385 | } |
| 387 | - if( *p==TEXT('\0') ){ | |
| 386 | + if( *p=='\0' ){ | |
| 388 | 387 | break; |
| 389 | 388 | } |
| 390 | 389 | } |
| 391 | 390 | } |
| 392 | 391 | |
| 393 | 392 | 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)); | |
| 397 | 396 | size--; |
| 398 | 397 | |
| 399 | 398 | p = cmdLine; |
| 400 | 399 | for(argc=0; argc<size; argc++){ |
| 401 | 400 | argv[argc] = arg = argSpace; |
| 402 | - while( tchar_isspace(*p) ){ | |
| 401 | + while( wchar_isspace(*p) ){ | |
| 403 | 402 | p++; |
| 404 | 403 | } |
| 405 | - if (*p == TEXT('\0')) { | |
| 404 | + if (*p == '\0') { | |
| 406 | 405 | break; |
| 407 | 406 | } |
| 408 | 407 | inquote = 0; |
| 409 | 408 | slashes = 0; |
| 410 | 409 | while(1){ |
| 411 | 410 | copy = 1; |
| 412 | - while( *p==TEXT('\\') ){ | |
| 411 | + while( *p=='\\' ){ | |
| 413 | 412 | slashes++; |
| 414 | 413 | p++; |
| 415 | 414 | } |
| 416 | - if( *p==TEXT('"') ){ | |
| 415 | + if( *p=='"' ){ | |
| 417 | 416 | if( (slashes&1)==0 ){ |
| 418 | 417 | copy = 0; |
| 419 | - if( inquote && p[1]==TEXT('"') ){ | |
| 418 | + if( inquote && p[1]=='"' ){ | |
| 420 | 419 | p++; |
| 421 | 420 | copy = 1; |
| 422 | 421 | }else{ |
| 423 | 422 | inquote = !inquote; |
| 424 | 423 | } |
| 425 | 424 | } |
| 426 | 425 | slashes >>= 1; |
| 427 | 426 | } |
| 428 | 427 | while( slashes ){ |
| 429 | - *arg = TEXT('\\'); | |
| 428 | + *arg = '\\'; | |
| 430 | 429 | arg++; |
| 431 | 430 | slashes--; |
| 432 | 431 | } |
| 433 | - if( *p==TEXT('\0') || (!inquote && tchar_isspace(*p)) ){ | |
| 432 | + if( *p=='\0' || (!inquote && wchar_isspace(*p)) ){ | |
| 434 | 433 | break; |
| 435 | 434 | } |
| 436 | 435 | if( copy!=0 ){ |
| 437 | 436 | *arg = *p; |
| 438 | 437 | arg++; |
| @@ -442,11 +441,11 @@ | ||
| 442 | 441 | *arg = '\0'; |
| 443 | 442 | argSpace = arg + 1; |
| 444 | 443 | } |
| 445 | 444 | argv[argc] = NULL; |
| 446 | 445 | *argcPtr = argc; |
| 447 | - *((TCHAR ***)argvPtr) = argv; | |
| 446 | + *((WCHAR ***)argvPtr) = argv; | |
| 448 | 447 | } |
| 449 | 448 | #endif /* defined(_WIN32) */ |
| 450 | 449 | |
| 451 | 450 | |
| 452 | 451 | /* |
| 453 | 452 |
| --- 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 @@ | ||
| 146 | 146 | SOCKET s = INVALID_SOCKET; |
| 147 | 147 | SOCKADDR_IN addr; |
| 148 | 148 | int idCnt = 0; |
| 149 | 149 | int iPort = mnPort; |
| 150 | 150 | Blob options; |
| 151 | - TCHAR zTmpPath[MAX_PATH]; | |
| 151 | + WCHAR zTmpPath[MAX_PATH]; | |
| 152 | 152 | |
| 153 | 153 | if( zStopper ) file_delete(zStopper); |
| 154 | 154 | blob_zero(&options); |
| 155 | 155 | if( zNotFound ){ |
| 156 | 156 | blob_appendf(&options, " --notfound %s", zNotFound); |
| @@ -249,11 +249,11 @@ | ||
| 249 | 249 | struct HttpService { |
| 250 | 250 | int port; /* Port on which the http server should run */ |
| 251 | 251 | const char *zNotFound; /* The --notfound option, or NULL */ |
| 252 | 252 | int flags; /* One or more HTTP_SERVER_ flags */ |
| 253 | 253 | int isRunningAsService; /* Are we running as a service ? */ |
| 254 | - const TCHAR *zServiceName;/* Name of the service */ | |
| 254 | + const WCHAR *zServiceName;/* Name of the service */ | |
| 255 | 255 | SOCKET s; /* Socket on which the http server listens */ |
| 256 | 256 | }; |
| 257 | 257 | |
| 258 | 258 | /* |
| 259 | 259 | ** Variables used for running as windows service. |
| @@ -384,11 +384,11 @@ | ||
| 384 | 384 | if( argc>0 ){ |
| 385 | 385 | hsData.zServiceName = argv[0]; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /* Register the service control handler function */ |
| 389 | - sshStatusHandle = RegisterServiceCtrlHandler(TEXT(""), win32_http_service_ctrl); | |
| 389 | + sshStatusHandle = RegisterServiceCtrlHandler(L"", win32_http_service_ctrl); | |
| 390 | 390 | if( !sshStatusHandle ){ |
| 391 | 391 | win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0); |
| 392 | 392 | return; |
| 393 | 393 | } |
| 394 | 394 | |
| @@ -429,11 +429,11 @@ | ||
| 429 | 429 | const char *zNotFound, /* The --notfound option, or NULL */ |
| 430 | 430 | int flags /* One or more HTTP_SERVER_ flags */ |
| 431 | 431 | ){ |
| 432 | 432 | /* Define the service table. */ |
| 433 | 433 | 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}}; | |
| 435 | 435 | |
| 436 | 436 | /* Initialize the HttpService structure. */ |
| 437 | 437 | hsData.port = nPort; |
| 438 | 438 | hsData.zNotFound = zNotFound; |
| 439 | 439 | hsData.flags = flags; |
| @@ -566,11 +566,11 @@ | ||
| 566 | 566 | |
| 567 | 567 | if( strncmp(zMethod, "create", n)==0 ){ |
| 568 | 568 | SC_HANDLE hScm; |
| 569 | 569 | SC_HANDLE hSvc; |
| 570 | 570 | SERVICE_DESCRIPTION |
| 571 | - svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")}; | |
| 571 | + svcDescr = {L"Fossil - Distributed Software Configuration Management"}; | |
| 572 | 572 | char *zErrFmt = "unable to create service '%s': %s"; |
| 573 | 573 | DWORD dwStartType = SERVICE_DEMAND_START; |
| 574 | 574 | const char *zDisplay = find_option("display", "D", 1); |
| 575 | 575 | const char *zStart = find_option("start", "S", 1); |
| 576 | 576 | const char *zUsername = find_option("username", "U", 1); |
| 577 | 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 | 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 |