/* 这个函数的功能是将一串以空格分隔的命令行参数转换为标准的数组参数 */
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);
}
Exemple #2
0
GOL_FILE *GOL_open(struct GOL_STR_DIR *dir, const UCHAR *name)
{
	GOL_FILE *gfp;
	UCHAR *fp;
	int size;
	fp = osain(name, &size);
	if (fp == NULL)
		return (GOL_FILE *) ~0;
	gfp = GOL_sysmalloc(sizeof (struct GOL_STR_FILE));
	gfp->size = size;
	gfp->p0 = fp;
	gfp->linkcount = 1;
	return gfp;
}
Exemple #3
0
int cc1main(struct STR_CC1MAIN *str_cc1main)
{
//	static char execflag = 0;
	int argc;
	UCHAR **argv;
	UCHAR **argv1, **p;
	GO_stdout.p0 = GO_stdout.p = str_cc1main->dest0;
	GO_stdout.p1 = str_cc1main->dest1;
	GO_stdout.dummy = ~0;
	GO_stderr.p0 = GO_stderr.p = str_cc1main->err0;
	GO_stderr.p1 = str_cc1main->err1;
	GO_stderr.dummy = ~0;

	/* 多重実行阻止 (staticを再初期化すればできるが) */
//	if (execflag)
//		return 7;
//	execflag = 1;

	if (setjmp(setjmp_env)) {
		str_cc1main->dest0 = GO_stdout.p;
		str_cc1main->err0 = GO_stderr.p;
		return GOL_abortcode;
	}

	if (str_cc1main->work1 - str_cc1main->work0 < SYSWORK_SIZE * 2)
		return GO_TERM_WORKOVER;
	GOL_memmaninit(&GOL_sysman, SYSWORK_SIZE, str_cc1main->work0);
	GOL_memmaninit(&GOL_memman, str_cc1main->work1 - str_cc1main->work0 - SYSWORK_SIZE,
		str_cc1main->work0 + SYSWORK_SIZE);
	argv = ConvCmdLine1(&argc, str_cc1main->cmdlin);
	p = argv1 = GOL_sysmalloc((argc + 1) * sizeof (char *));
	for (;;) {
		if ((*p = *argv) == NULL)
			break;
		if ((*argv)[0] == '-' && (*argv)[1] == 'o') {
			str_cc1main->outname = &((*argv)[2]);
			if ((*argv)[2] == '\0') {
				if (argv[1] != NULL)
					str_cc1main->outname = (argv++)[1];
			}
			p--;  /* delete -o */
		}
		p++;
		argv++;
	}
	str_cc1main->errcode = main1(p - argv1, argv1);
	GOL_sysabort(GO_TERM_NORMAL);
}