⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imake.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 3 页
字号:
	make_argv[ make_argindex ] = NULL;}voidAddCppArg(arg)	char	*arg;{	errno = 0;	if (cpp_argindex >= ARGUMENTS-1)		LogFatal("Out of internal storage.", "");	cpp_argv[ cpp_argindex++ ] = arg;	cpp_argv[ cpp_argindex ] = NULL;}voidSetOpts(argc, argv)	int	argc;	char	**argv;{	errno = 0;	/*	 * Now gather the arguments for make	 */	for(argc--, argv++; argc; argc--, argv++) {	    /*	     * We intercept these flags.	     */	    if (argv[0][0] == '-') {		if (argv[0][1] == 'D') {		    AddCppArg(argv[0]);		} else if (argv[0][1] == 'I') {		    AddCppArg(argv[0]);		} else if (argv[0][1] == 'f') {		    if (argv[0][2])			Imakefile = argv[0]+2;		    else {			argc--, argv++;			if (! argc)			    LogFatal("No description arg after -f flag", "");			Imakefile = argv[0];		    }		} else if (argv[0][1] == 's') {		    if (argv[0][2])			Makefile = ((argv[0][2] == '-') && !argv[0][3]) ?			    NULL : argv[0]+2;		    else {			argc--, argv++;			if (!argc)			    LogFatal("No description arg after -s flag", "");			Makefile = ((argv[0][0] == '-') && !argv[0][1]) ?			    NULL : argv[0];		    }		    show = TRUE;		} else if (argv[0][1] == 'e') {		   Makefile = (argv[0][2] ? argv[0]+2 : NULL);		   show = FALSE;		} else if (argv[0][1] == 'T') {		    if (argv[0][2])			Template = argv[0]+2;		    else {			argc--, argv++;			if (! argc)			    LogFatal("No description arg after -T flag", "");			Template = argv[0];		    }		} else if (argv[0][1] == 'C') {		    if (argv[0][2])			ImakefileC = argv[0]+2;		    else {			argc--, argv++;			if (! argc)			    LogFatal("No imakeCfile arg after -C flag", "");			ImakefileC = argv[0];		    }		} else if (argv[0][1] == 'v') {		    verbose = TRUE;		} else		    AddMakeArg(argv[0]);	    } else		AddMakeArg(argv[0]);	}#ifdef USE_CC_E	if (!cpp)	{		AddCppArg("-E");		cpp = DEFAULT_CC;	}#else	if (!cpp)		cpp = DEFAULT_CPP;#endif	cpp_argv[0] = cpp;	AddCppArg(ImakefileC);}char *FindImakefile(Imakefile)	char	*Imakefile;{	if (Imakefile) {		if (access(Imakefile, R_OK) < 0)			LogFatal("Cannot find %s.", Imakefile);	} else {		if (access("Imakefile", R_OK) < 0)			if (access("imakefile", R_OK) < 0)				LogFatal("No description file.", "");			else				Imakefile = "imakefile";		else			Imakefile = "Imakefile";	}	return(Imakefile);}voidLogFatalI(s, i)	char *s;	int i;{	/*NOSTRICT*/	LogFatal(s, (char *)(long)i);}voidLogFatal(x0,x1)	char *x0, *x1;{	static boolean	entered = FALSE;	if (entered)		return;	entered = TRUE;	LogMsg(x0, x1);	fprintf(stderr, "  Stop.\n");	wrapup();	exit(1);}voidLogMsg(x0,x1)	char *x0, *x1;{	int error_number = errno;	if (error_number) {		fprintf(stderr, "%s: ", program);		fprintf(stderr, "%s\n", strerror(error_number));	}	fprintf(stderr, "%s: ", program);	fprintf(stderr, x0, x1);	fprintf(stderr, "\n");}voidshowargs(argv)	char	**argv;{	for (; *argv; argv++)		fprintf(stderr, "%s ", *argv);	fprintf(stderr, "\n");}#define ImakefileCHeader "/* imake - temporary file */"voidCheckImakefileC(masterc)	char *masterc;{	char mkcbuf[1024];	FILE *inFile;	if (access(masterc, F_OK) == 0) {		inFile = fopen(masterc, "r");		if (inFile == NULL)			LogFatal("Refuse to overwrite: %s", masterc);		if ((fgets(mkcbuf, sizeof(mkcbuf), inFile) &&		     strncmp(mkcbuf, ImakefileCHeader, 			     sizeof(ImakefileCHeader)-1)))		{			fclose(inFile);			LogFatal("Refuse to overwrite: %s", masterc);		}		fclose(inFile);	}}#define LocalDefineFmt	"#define %s \"%s\"\n"#define IncludeFmt	"#include %s\n"#define ImakeDefSym	"INCLUDE_IMAKEFILE"#define ImakeTmplSym	"IMAKE_TEMPLATE"#define OverrideWarning	"Warning: local file \"%s\" overrides global macros."booleanoptional_include(inFile, defsym, fname)        FILE	*inFile;        char    *defsym;        char    *fname;{	errno = 0;	if (access(fname, R_OK) == 0) {		LogMsg(OverrideWarning, fname);		return (fprintf(inFile, LocalDefineFmt, defsym, fname) < 0 ||			fprintf(inFile, IncludeFmt, defsym) < 0);	}	return FALSE;}voiddoit(outfd, cmd, argv)	FILE	*outfd;	char    *cmd;	char	**argv;{	int	pid;	waitType	status;	/*	 * Fork and exec the command.	 */#ifdef WIN32	if (outfd)		dup2(fileno(outfd), 1);	status = _spawnvp(_P_WAIT, cmd, argv);	if (status < 0)		LogFatal("Cannot spawn %s.", cmd);	if (status > 0)		LogFatalI("Exit code %d.", status);#else	pid = fork();	if (pid < 0)		LogFatal("Cannot fork.", "");	if (pid) {	/* parent... simply wait */		while (wait(&status) > 0) {			errno = 0;			if (WIFSIGNALED(status))				LogFatalI("Signal %d.", waitSig(status));			if (WIFEXITED(status) && waitCode(status))				LogFatalI("Exit code %d.", waitCode(status));		}	}	else {	/* child... dup and exec cmd */		if (verbose)			showargs(argv);		if (outfd)			dup2(fileno(outfd), 1);		execvp(cmd, argv);		LogFatal("Cannot exec %s.", cmd);	}#endif}#ifndef WIN32static voidparse_utsname(name, fmt, result, msg)     struct utsname *name;     char *fmt;     char *result;     char *msg;{  char buf[SYS_NMLN * 5 + 1];  char *ptr = buf;  int arg;  /* Assemble all the pieces into a buffer. */  for (arg = 0; fmt[arg] != ' '; arg++)    {      /* Our buffer is only guaranteed to hold 5 arguments. */      if (arg >= 5)	LogFatal(msg, fmt);      switch (fmt[arg])	{	case 's':	  if (arg > 0)	    *ptr++ = ' ';	  strcpy(ptr, name->sysname);	  ptr += strlen(ptr);	  break;	case 'n':	  if (arg > 0)	    *ptr++ = ' ';	  strcpy(ptr, name->nodename);	  ptr += strlen(ptr);	  break;	case 'r':	  if (arg > 0)	    *ptr++ = ' ';	  strcpy(ptr, name->release);	  ptr += strlen(ptr);	  break;	case 'v':	  if (arg > 0)	    *ptr++ = ' ';	  strcpy(ptr, name->version);	  ptr += strlen(ptr);	  break;	case 'm':	  if (arg > 0)	    *ptr++ = ' ';	  strcpy(ptr, name->machine);	  ptr += strlen(ptr);	  break;	default:	  LogFatal(msg, fmt);	}    }  /* Just in case... */  if (strlen(buf) >= sizeof(buf))    LogFatal("Buffer overflow parsing uname.", "");  /* Parse the buffer.  The sscanf() return value is rarely correct. */  *result = '\0';  (void) sscanf(buf, fmt + arg + 1, result);}/* Trim leading 0's and periods from version names.  The 0's cause   the number to be interpreted as octal numbers.  Some version strings   have the potential for different numbers of .'s in them. */	static char *trim_version(p)	char *p;{	if (p != 0 && *p != '\0')	{		while ((*p == '0' || *p == '.') && *(p + 1) != '\0')			++p;	}	return (p);}#endif#ifdef linuxconst char *libc_c="#include <stdio.h>\n""#include <ctype.h>\n""\n""#if 0\n""#pragma weak gnu_get_libc_version\n""#pragma weak __libc_version\n""#pragma weak __linux_C_lib_version\n""#else\n""asm (\".weak gnu_get_libc_version\");\n""asm (\".weak __libc_version\");\n""asm (\".weak __linux_C_lib_version\");\n""#endif\n""\n""extern const char * gnu_get_libc_version (void);\n""extern const char * __linux_C_lib_version;\n""extern const char __libc_version [];\n""\n""int\n""main ()\n""{\n""  int libcmajor = 0, libcminor = 0, libcteeny = 0;\n""\n""  if (((&__linux_C_lib_version != 0)\n""       && ((&__libc_version != 0) || (gnu_get_libc_version != 0)))\n""      || (!(&__linux_C_lib_version != 0) && !(&__libc_version != 0)\n""	  && !(gnu_get_libc_version != 0)))\n""  {\n""    libcmajor = 0;\n""    libcminor = 0;\n""    libcteeny = 0;\n""  }\n""  else\n""  {\n""    const char * ptr;\n""    int glibcmajor = 0;\n""\n""    if (gnu_get_libc_version != 0)\n""    {\n""      ptr = gnu_get_libc_version ();\n""      glibcmajor = 4;\n""    }\n""    else if (&__libc_version != 0)\n""    {\n""      ptr = __libc_version;\n""      glibcmajor = 4;\n""    }\n""    else\n""      ptr = __linux_C_lib_version;\n""\n""    while (!isdigit (*ptr))\n""      ptr++;\n""\n""    sscanf (ptr, \"%d.%d.%d\", &libcmajor, &libcminor, &libcteeny);\n""    libcmajor += glibcmajor;\n""  }\n""\n""  printf(\"#define DefaultLinuxCLibMajorVersion %d\\n\", libcmajor);\n""  printf(\"#define DefaultLinuxCLibMinorVersion %d\\n\", libcminor);\n""  printf(\"#define DefaultLinuxCLibTeenyVersion %d\\n\", libcteeny);\n""\n""  return 0;\n""}\n";static void get_libc_version(inFile)  FILE* inFile;{  char *aout = tmpnam (NULL);  FILE *fp;  const char *format = "%s -o %s -x c -";  char *cc;  int len;  char *command;  cc = getenv ("CC");  if (cc == NULL)    cc = "gcc";  len = strlen (aout) + strlen (format) + strlen (cc);  if (len < 128) len = 128;  command = alloca (len);  if (snprintf (command , len, format, cc, aout) == len)    abort ();  fp = popen (command, "w");  if (fp == NULL || fprintf (fp, "%s\n", libc_c) < 0      || pclose (fp) != 0)    abort ();  fp = popen (aout, "r");  if (fp == NULL)    abort ();  while (fgets (command, len, fp))    fprintf (inFile, command);    len = pclose (fp);  remove (aout);  if (len)    abort ();}static void get_ld_version(inFile)  FILE* inFile;{  FILE* ldprog = popen ("ld -v", "r");  char c;  int ldmajor, ldminor;  if (ldprog) {    do {      c = fgetc (ldprog);    } while (c != EOF && !isdigit (c));    ungetc (c, ldprog);    (void) fscanf (ldprog, "%d.%d", &ldmajor, &ldminor);    fprintf(inFile, "#define DefaultLinuxBinUtilsMajorVersion %d\n", 	    ldmajor * 10 + ldminor);        pclose (ldprog);  }}#endif#ifndef PATH_MAX#define PATH_MAX 1024#endif#ifndef __EMX__static void get_gcc_incdir(inFile)  FILE* inFile;{  static char* gcc_path[] = {#if defined(linux) || defined(__OpenBSD__)    "/usr/bin/cc",	/* for Linux PostIncDir */#endif    "/usr/local/bin/gcc",    "/opt/gnu/bin/gcc"  };  struct stat sb;  int i;  FILE* gccproc;  char buf[PATH_MAX];  char cmd[PATH_MAX];  char* ptr;  buf[0] = '\0';  for (i = 0; i < sizeof gcc_path / sizeof gcc_path[0]; i++) {    if (lstat (gcc_path[i], &sb) == 0) {      strcpy (cmd, gcc_path[i]);      strcat (cmd, " --print-libgcc-file-name");      if ((gccproc = popen (cmd, "r")) != NULL) {	if (fgets (buf, PATH_MAX, gccproc) != NULL) {	  ptr = strstr (buf, "libgcc.a");	  if (ptr) strcpy (ptr, "include");	}	(void) pclose (gccproc);	break;      }    }  }  if (buf[0])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -