Example #1
0
void mini_crt_entry(void)
{
int ret;

#ifdef WIN32
	int flag = 0;
	int argc = 0;
	char* argv[16];
	char* cl=GetCommandLineA();

	argv[0]=cl;
	argc++;
	while(*cl)
	{
		if(*cl == '\"')
		{
			if(flag == 0)
				flag = 1;
			else
				flag = 0;
		}
		else if(*cl == ' ' && flag == 0)
		{
			if(*(cl+1))
			{
				argv[argc] = cl + 1;
				argc++;
			}
		}
		cl++;

	}//end of while

#else
	int argc;
	char** argv;

	char* ebp_reg = 0;
	// ebp_reg = %ebp;
	asm("movl %%ebp, %0 \n":"=r"(ebp_reg));

	argc = *(int*)(ebp_reg + 4);
	argv = (char**)(ebp_reg + 8);
#endif

	if(!mini_crt_heap_init())
		crt_fatal_error("heap initialize failed");
	if(!mini_crt_io_init())
		crt_fatal_error("IO initialize failed");

	ret = main(argc,argv);
	exit(ret);


}
Example #2
0
//入口函数,初始化参数,并调用初始化堆与IO的函数
void mini_crt_entry(void)
{
    int ret;
    int flag = 0, argc = 0;
    char *argv[16];
    char *cl = GetCommandLineA();

    argv[argc++] = cl;
    //每个位置判断若是空格,且后一个位置非空格,则视为参数
    for (; *cl; cl++) {
        if (*cl == '\"') flag ^= 1;
        else if (*cl == ' ' && !flag) {
            if (*(cl + 1) && *(cl + 1) != ' ')
                argv[argc++] = cl + 1;
            *cl = 0;
        }
    }
    if (!mini_crt_heap_init() || !mini_crt_io_init()) exit(1);
    do_global_ctors();

    ret = main(argc, argv);
    exit(ret);
}