/* 这个函数的功能是将一串以空格分隔的命令行参数转换为标准的数组参数 */
void GOL_callmain0()
{
	int argc = 0, i;
	//GetCommandLineA是libmingw中的一个函数,获取当前进程的命令参数缓冲区指针
	UCHAR *p = GetCommandLineA(), *q, *q0, **argv;
	//因此有必要将命令拷贝到程序的空间里面来
	q = q0 = GOL_sysmalloc(GO_strlen(p) + 1);
	do {
		while ((*q++ = *p++) > ' ');
		argc++;		//遇到空格表示一个参数结束,因此argc加1
		p--;		//由于p是后增式,所以现在的p已经指向空格下一个字符了,所以要向前移动一个
		*(q - 1) = '\0';	//将参数放到数组中时参数以\0分隔
		while ('\0' < *p && *p <= ' ')	//跳过无效字符
			p++;
	} while (*p);						//处理所有的参数

	/* 生成标准的argv参数 */
	argv = GOL_sysmalloc((argc + 1) * sizeof (char *));
	argv[0] = q = q0;
	i = 1;
	/* 将argv和每个参数对应起来。 */
	while (i < argc) {
		while (*q++);
		argv[i++] = q;
	}
	argv[i] = NULL;

	/* 标准方式调用传到下一个函数 */
	GOL_callmain(argc, argv);
}
예제 #2
0
파일: cc1drv.c 프로젝트: FuDesign2008/mess
int main(int argc, UCHAR **argv)
/* かならず、-oオプションを付ける */
/* ここで、-oオプションは剥ぎ取られる */
/* しかし入力ファイル名は書く(標準入力ではsizeが測定できないため) */
{
	struct bss_alloc *bss0;
	UCHAR **argv1, **p;
	bss0 = (struct bss_alloc *) malloc(sizeof (struct bss_alloc));
	GO_stdout.p0 = GO_stdout.p = bss0->_stdout;
	GO_stdout.p1 = GO_stdout.p0 + SIZ_STDOUT;
	GO_stdout.dummy = ~0;
	GO_stderr.p0 = GO_stderr.p = bss0->_stderr;
	GO_stderr.p1 = GO_stderr.p0 + (SIZ_STDERR - 128); /* わざと少し小さくしておく */
	GO_stderr.dummy = ~0;
	GOL_memmaninit(&GOL_sysman, SIZ_SYSWRK, bss0->syswrk);
	GOL_memmaninit(&GOL_memman, SIZ_WORK, GOL_work0 = bss0->work);
	GOL_callmain(argc, argv);
	return 0; /* ダミー */
}