?? wince_stdlib_main.c
字號(hào):
/* Copyright (C) Jungo 1999 - 2006 */
#include <windows.h>
#include <stdlib.h>
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
TCHAR g_sAppName[1024] = {'\0'};
HINSTANCE g_hInstance = NULL;
#if !defined(_NO_MAIN_FUNC_)
#if defined(_WIN32_WCE) && (_WIN32_WCE==200)
#include "wince_200/stdio.h"
#else
#include <stdio.h>
#endif
extern int __cdecl main(int argc, char *argv[]);
// TCHAR to Ansi Char string copy
void TC2C_strcpy(CHAR *dst, TCHAR *src)
{
int i;
for (i=0; src[i]; i++)
dst[i] = (CHAR) src[i];
dst[i] = (CHAR) src[i];
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow)
{
char argv0[256];
TCHAR t_argv0[256];
char *argv_all;
char *argv[256];
int ret_val;
int argc = 0;
BOOL fInArg = FALSE;
BOOL fInQuote;
int i,j;
g_hInstance = hInstance;
GetModuleFileName(hInstance, t_argv0, sizeof (t_argv0));
wcscpy (g_sAppName, t_argv0);
TC2C_strcpy(argv0, t_argv0);
argv[argc++] = argv0;
argv_all = (char *) malloc (wcslen(szCmdLine)+1);
j = 0;
for (i=0; (char) szCmdLine[i]; i++)
{
char ch = (char) szCmdLine[i];
if (fInArg)
{
if (fInQuote && ch=='\"' || !fInQuote && (ch==' ' || ch=='\t'))
{
fInArg = FALSE;
argv_all[j++] = '\0';
}
else
{
argv_all[j++] = ch;
}
}
else
{
if (ch!=' ' && ch!='\t')
{
fInArg = TRUE;
fInQuote = ch=='\"';
if (!fInQuote)
i--;
argv[argc] = argv_all + j;
argc++;
}
}
}
if (fInArg)
argv_all[j++] = '\0';
argv[argc] = NULL;
ret_val = main(argc, argv);
free (argv_all);
#if defined(_WIN32_WCE) && (_WIN32_WCE==200)
printf ("\nPress enter to exit\n");
{ char line[100]; gets(line); }
#endif
return ret_val;
}
time_t __cdecl time()
{
SYSTEMTIME sysTime;
FILETIME fileTime;
LARGE_INTEGER *pLargeInt = (LARGE_INTEGER *) &fileTime;
GetSystemTime (&sysTime);
SystemTimeToFileTime (&sysTime, &fileTime);
pLargeInt->QuadPart /= 10000000;
pLargeInt->QuadPart -= 11644473600; // displacement
return pLargeInt->LowPart;
}
#endif
#if defined(_WIN32_WCE) && (_WIN32_WCE==200)
#include "wince_200/stdio_resource.h"
#ifndef isspace
#define isspace(c) ((c)==' ' || (c)=='\t' || (c)=='\n' || (c)=='\r')
#endif
#ifndef isdigit
#define isdigit(c) ((c)>='0' && (c)<='9')
#endif
#ifndef isalpha
#define isalpha(c) (((c)>='a' && (c)<='z') || ((c)>='A' && (c)<='Z'))
#endif
#ifndef isupper
#define isupper(c) ((c)>='A' && (c)<='Z')
#endif
#ifndef ULONG_MAX
#define ULONG_MAX 0xffffffffUL /* maximum unsigned long value */
#endif
static int __cdecl skip_atoi(const char **s)
{
int i=0;
while (isdigit(**s))
i = i*10 + *((*s)++) - '0';
return i;
}
#define ZEROPAD 1 /* pad with zero */
#define SIGN 2 /* unsigned/signed long */
#define PLUS 4 /* show plus */
#define SPACE 8 /* space if plus */
#define LEFT 16 /* left justified */
#define SPECIAL 32 /* 0x */
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
static int __cdecl do_div(long *n, int base)
{
int res;
res = ((unsigned long) *n) % (unsigned) base;
*n = ((unsigned long) *n) / (unsigned) base;
return res;
}
static char * __cdecl number(char * str, long num, int base, int size, int precision, int type)
{
char c,sign,tmp[66];
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
int i;
if (type & LARGE)
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (type & LEFT)
type &= ~ZEROPAD;
if (base < 2 || base > 36)
return 0;
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN)
{
if (num < 0)
{
sign = '-';
num = -num;
size--;
}
else if (type & PLUS)
{
sign = '+';
size--;
}
else if (type & SPACE)
{
sign = ' ';
size--;
}
}
if (type & SPECIAL)
{
if (base == 16)
size -= 2;
else if (base == 8)
size--;
}
i = 0;
if (num == 0)
tmp[i++]='0';
else while (num != 0)
tmp[i++] = digits[do_div(&num,base)];
if (i > precision)
precision = i;
size -= precision;
if (!(type&(ZEROPAD+LEFT)))
while(size-->0)
*str++ = ' ';
if (sign)
*str++ = sign;
if (type & SPECIAL)
if (base==8)
*str++ = '0';
else if (base==16)
{
*str++ = '0';
*str++ = digits[33];
}
if (!(type & LEFT))
while (size-- > 0)
*str++ = c;
while (i < precision--)
*str++ = '0';
while (i-- > 0)
*str++ = tmp[i];
while (size-- > 0)
*str++ = ' ';
return str;
}
int __cdecl vsprintf(char *buf, const char *fmt, va_list args)
{
int len;
unsigned long num;
int i, base;
char * str;
const char *s;
const WCHAR *sc;
int flags;
int field_width;
int precision;
int qualifier;
for (str=buf ; *fmt ; ++fmt)
{
if (*fmt != '%')
{
*str++ = *fmt;
continue;
}
flags = 0;
repeat:
++fmt;
switch (*fmt)
{
case '-': flags |= LEFT; goto repeat;
case '+': flags |= PLUS; goto repeat;
case ' ': flags |= SPACE; goto repeat;
case '#': flags |= SPECIAL; goto repeat;
case '0': flags |= ZEROPAD; goto repeat;
}
field_width = -1;
if (isdigit(*fmt))
field_width = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;
field_width = va_arg(args, int);
if (field_width < 0)
{
field_width = -field_width;
flags |= LEFT;
}
}
precision = -1;
if (*fmt == '.')
{
++fmt;
if (isdigit(*fmt))
precision = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;
precision = va_arg(args, int);
}
if (precision < 0)
precision = 0;
}
qualifier = -1;
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
{
qualifier = *fmt;
++fmt;
}
base = 10;
switch (*fmt)
{
case 'c':
if (!(flags & LEFT))
while (--field_width > 0)
*str++ = ' ';
*str++ = (char) va_arg(args, int);
while (--field_width > 0)
*str++ = ' ';
continue;
case 'C':
if (!(flags & LEFT))
while (--field_width > 0)
*str++ = ' ';
*str++ = (unsigned char) va_arg(args, int);
while (--field_width > 0)
*str++ = ' ';
continue;
case 's':
s = va_arg(args, char *);
if (!s)
s = "<NULL>";
len = strlen(s);
if (precision!=-1 && len>precision)
len = precision;
if (!(flags & LEFT))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
case 'S':
sc = (WCHAR *) va_arg(args, char *);
if (!sc)
sc = L"<NULL>";
len = wcslen(sc);
if (len>precision)
len = precision;
if (!(flags & LEFT))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len; ++i)
*str++ = (char) *sc++;
while (len < field_width--)
*str++ = ' ';
continue;
case 'p':
if (field_width == -1)
{
field_width = 2*sizeof(void *);
flags |= ZEROPAD;
}
str = number(str,
(unsigned long) va_arg(args, void *), 16,
field_width, precision, flags);
continue;
case 'n':
if (qualifier == 'l')
{
long * ip = va_arg(args, long *);
*ip = (str - buf);
}
else
{
int * ip = va_arg(args, int *);
*ip = (str - buf);
}
continue;
case 'o':
base = 8;
break;
case 'X':
flags |= LARGE;
case 'x':
base = 16;
break;
case 'd':
case 'i':
flags |= SIGN;
case 'u':
break;
default:
if (*fmt != '%')
*str++ = '%';
if (*fmt)
*str++ = *fmt;
else
--fmt;
continue;
}
if (qualifier == 'l')
num = va_arg(args, unsigned long);
else if (qualifier == 'h')
if (flags & SIGN)
num = va_arg(args, short);
else
num = va_arg(args, unsigned short);
else if (flags & SIGN)
num = va_arg(args, int);
else
num = va_arg(args, unsigned int);
str = number(str, num, base, field_width, precision, flags);
}
*str = '\0';
return str-buf;
}
int __cdecl sprintf(char *buf, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
i=vsprintf(buf,fmt,args);
va_end(args);
return i;
}
char __cdecl toupper(char ch)
{
return ch>='a' && ch<='z' ? ch-('a'-'A') : ch;
}
char printf_buf[4096];
TCHAR printf_buf_w[8192];
int __cdecl printf(const char *format, ...)
{
int i = strlen(printf_buf);
va_list Next;
va_start(Next, format);
vsprintf(printf_buf + i, format, Next);
return 0;
}
char *gets_buf;
// This is the Speaker Main dialog Window Proc.
BOOL PASCAL consoleMainDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg)
{
case WM_INITDIALOG:
{
int i,j;
for (i=0,j=0; printf_buf[i]; i++)
{
if (printf_buf[i]=='\n')
printf_buf_w[j++] = '\r';
printf_buf_w[j++] = printf_buf[i];
}
printf_buf_w[j++] = printf_buf[i];
SetDlgItemText( hDlg, IDC_PRINTF, printf_buf_w);
printf_buf[0] = '\0';
SetWindowText (hDlg, g_sAppName);
}
return TRUE;
case WM_COMMAND:
switch ( LOWORD( wParam ))
{
case IDC_OK:
{
WCHAR gets_buf_w[1024];
int i;
GetDlgItemText(hDlg, IDC_EDIT, gets_buf_w, sizeof(gets_buf_w));
for (i=0; gets_buf_w[i]; i++) gets_buf[i] = (char) gets_buf_w[i];
gets_buf[i] = (char) gets_buf_w[i];
}
EndDialog( hDlg, TRUE );
return TRUE;
case IDCANCEL:
gets_buf[0] = '\0';
EndDialog( hDlg, TRUE );
return TRUE;
}
break;
}
return FALSE;
}
char * __cdecl gets(char *buf)
{
buf[0] = '\0';
gets_buf = buf;
// create the console window
DialogBoxParam( g_hInstance, MAKEINTRESOURCE( IDD_FORMVIEW ), NULL, consoleMainDlgProc, (LPARAM) NULL);
return buf;
}
long __cdecl strtol (const char *nptr, char **endptr, int base)
{
int negative;
unsigned long int cutoff;
unsigned int cutlim;
unsigned long int i;
const char *s;
unsigned char c;
const char *save;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
while (isspace(*s))
++s;
if (*s == '\0')
goto noconv;
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && toupper(s[1]) == 'X')
s += 2;
if (base == 0)
if (*s == '0')
{
if (toupper(s[1]) == 'X')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
save = s;
cutoff = ULONG_MAX / (unsigned long int) base;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -