コード例 #1
0
ファイル: parser.c プロジェクト: Totktonada/shell
void print_cmd_pipeline(FILE *stream, cmd_pipeline *pipeline)
{
    cmd_pipeline_item *current;

    if (pipeline == NULL) {
        fprintf(stream, "NULL_PIPELINE");
        return;
    }

    current = pipeline->first_item;
    while (current != NULL) {
        if (current->cmd_lst == NULL) {
            print_argv(stream, current->argv);
        } else {
            fprintf(stream, "(");
            print_cmd_list(stream, current->cmd_lst, 0);
            fprintf(stream, ")");
        }
        if (current->next != NULL)
            fprintf(stream, " | ");
        current = current->next;
    }

    if (pipeline->input != NULL) {
        fprintf(stream, " < [%s]", pipeline->input);
    }
    if (pipeline->output != NULL) {
        if (pipeline->append)
            fprintf(stream, " >> [%s]", pipeline->output);
        else
            fprintf(stream, " > [%s]", pipeline->output);
    }
}
コード例 #2
0
ファイル: push.c プロジェクト: anlaneg/openvpn
void
push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
{
    const char **argv = make_extended_arg_array(p, gc);
    char *opt = print_argv(argv, gc, 0);
    push_option(o, opt, msglevel);
}
コード例 #3
0
ファイル: misc.c プロジェクト: huamichaelchen/openvpn
const char *
argv_str (const struct argv *a, struct gc_arena *gc, const unsigned int flags)
{
  if (a->argv)
    return print_argv ((const char **)a->argv, gc, flags);
  else
    return "";
}
コード例 #4
0
ファイル: main.c プロジェクト: harningt/optparse
void try_getopt(int argc, char **argv)
{
    print_argv(argv);
    int opt;
    while ((opt = getopt(argc, argv, "abc:d::")) != -1) {
        printf("%c (%d) = '%s'\n", opt, optind, optarg);
    }
    printf("optind = %d\n", optind);
    for (; optind < argc; optind++)
        printf("argument: %s\n", argv[optind]);
}
コード例 #5
0
void
plugin_option_list_print (const struct plugin_option_list *list, int msglevel)
{
  int i;
  struct gc_arena gc = gc_new ();

  for (i = 0; i < list->n; ++i)
    {
      const struct plugin_option *o = &list->plugins[i];
      msg (msglevel, "  plugin[%d] %s '%s'", i, o->so_pathname, print_argv (o->argv, &gc, PA_BRACKET));
    }

  gc_free (&gc);
}
コード例 #6
0
static void
plugin_open_item (struct plugin *p,
		  const struct plugin_option *o,
		  struct openvpn_plugin_string_list **retlist,
		  const char **envp,
		  const int init_point)
{
  ASSERT (p->initialized);

  /* clear return list */
  if (retlist)
    *retlist = NULL;

  if (!p->plugin_handle && init_point == p->requested_initialization_point)
    {
      struct gc_arena gc = gc_new ();

      dmsg (D_PLUGIN_DEBUG, "PLUGIN_INIT: PRE");
      plugin_show_args_env (D_PLUGIN_DEBUG, o->argv, envp);

      /*
       * Call the plugin initialization
       */
      if (p->open2)
	p->plugin_handle = (*p->open2)(&p->plugin_type_mask, o->argv, envp, retlist);
      else if (p->open1)
	p->plugin_handle = (*p->open1)(&p->plugin_type_mask, o->argv, envp);
      else
	ASSERT (0);

      msg (D_PLUGIN, "PLUGIN_INIT: POST %s '%s' intercepted=%s %s",
	   p->so_pathname,
	   print_argv (o->argv, &gc, PA_BRACKET),
	   plugin_mask_string (p->plugin_type_mask, &gc),
	   (retlist && *retlist) ? "[RETLIST]" : "");
      
      if ((p->plugin_type_mask | plugin_supported_types()) != plugin_supported_types())
	msg (M_FATAL, "PLUGIN_INIT: plugin %s expressed interest in unsupported plugin types: [want=0x%08x, have=0x%08x]",
	     p->so_pathname,
	     p->plugin_type_mask,
	     plugin_supported_types());

      if (p->plugin_handle == NULL)
	msg (M_FATAL, "PLUGIN_INIT: plugin initialization function failed: %s",
	     p->so_pathname);

      gc_free (&gc);
    }
}
コード例 #7
0
ファイル: main.c プロジェクト: harningt/optparse
void try_optparse(char **argv)
{
    print_argv(argv);
    struct optparse options;
    optparse_init(&options, argv);
    int opt;
    while ((opt = optparse(&options, "abc:d::")) != -1) {
        if (opt == '?')
            printf("%s: %s\n", argv[0], options.errmsg);
        printf("%c (%d) = '%s'\n", opt, options.optind, options.optarg);
    }
    printf("optind = %d\n", options.optind);
    char *arg;
    while ((arg = optparse_arg(&options)))
        printf("argument: %s\n", arg);
}
コード例 #8
0
ファイル: display.cpp プロジェクト: Quna/mspdev
/**
   Generates target name listing, designed for text output and console viewing.
*/
static void
print_target_verbose (const struct target_opts *defaults)
{
    assert (defaults->verbose);

    printf ("%s ", "Executing \"");
    print_argv (defaults->argv, 0 /* no newline */);

    /* print stdin, stdout, and stderr redirections */
    if (defaults->infname && *defaults->infname)
        printf (" <%s", defaults->infname);

    if (defaults->outfname && *defaults->outfname)
        printf (" >%s 2>&1", defaults->outfname);

    puts ("\"");

    /* flush to prevent killing a signal from not displaying the text */
    fflush (stdout);
}
コード例 #9
0
ファイル: main.c プロジェクト: harningt/optparse
void try_optparse_long(char **argv)
{
    print_argv(argv);
    struct optparse options;
    optparse_init(&options, argv);
    struct optparse_long longopts[] = {
        {"amend", 'a', OPTPARSE_NONE},
        {"brief", 'b', OPTPARSE_NONE},
        {"color", 'c', OPTPARSE_REQUIRED},
        {"delay", 'd', OPTPARSE_OPTIONAL},
        {0}
    };
    int opt, longindex;
    while ((opt = optparse_long(&options, longopts, &longindex)) != -1) {
        if (opt == '?')
            printf("%s: %s\n", argv[0], options.errmsg);
        printf("%c (%d, %d) = '%s'\n",
               opt, options.optind, longindex, options.optarg);
    }
    printf("optind = %d\n", options.optind);
    char *arg;
    while ((arg = optparse_arg(&options)))
        printf("argument: %s\n", arg);
}
コード例 #10
0
int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
{
	int n = *np, col = *colp;
	char *argv[CONFIG_SYS_MAXARGS + 1];		/* NULL terminated	*/
	char *cmdv[20];
	char *s, *t;
	const char *sep;
	int i, j, k, len, seplen, argc;
	int cnt;
	char last_char;

	if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
		return 0;	/* not in normal console */

	cnt = strlen(buf);
	if (cnt >= 1)
		last_char = buf[cnt - 1];
	else
		last_char = '\0';

	/* copy to secondary buffer which will be affected */
	strcpy(tmp_buf, buf);

	/* separate into argv */
	argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv);

	/* do the completion and return the possible completions */
	i = complete_cmdv(argc, argv, last_char, sizeof(cmdv)/sizeof(cmdv[0]), cmdv);

	/* no match; bell and out */
	if (i == 0) {
		if (argc > 1)	/* allow tab for non command */
			return 0;
		putc('\a');
		return 1;
	}

	s = NULL;
	len = 0;
	sep = NULL;
	seplen = 0;
	if (i == 1) { /* one match; perfect */
		k = strlen(argv[argc - 1]);
		s = cmdv[0] + k;
		len = strlen(s);
		sep = " ";
		seplen = 1;
	} else if (i > 1 && (j = find_common_prefix(cmdv)) != 0) {	/* more */
		k = strlen(argv[argc - 1]);
		j -= k;
		if (j > 0) {
			s = cmdv[0] + k;
			len = j;
		}
	}

	if (s != NULL) {
		k = len + seplen;
		/* make sure it fits */
		if (n + k >= CONFIG_SYS_CBSIZE - 2) {
			putc('\a');
			return 1;
		}

		t = buf + cnt;
		for (i = 0; i < len; i++)
			*t++ = *s++;
		if (sep != NULL)
			for (i = 0; i < seplen; i++)
				*t++ = sep[i];
		*t = '\0';
		n += k;
		col += k;
		puts(t - k);
		if (sep == NULL)
			putc('\a');
		*np = n;
		*colp = col;
	} else {
		print_argv(NULL, "  ", " ", 78, cmdv);

		puts(prompt);
		puts(buf);
	}
	return 1;
}
コード例 #11
0
ファイル: display.cpp プロジェクト: Quna/mspdev
/**
   Generates output header in verbose mode.
*/
static void
print_header_verbose (const char* const argv[])
{
    print_argv (argv, 1 /* append newline */);
}
コード例 #12
0
int main(int argc,char** argv,char *envp[])
{
	int a;
	f = stdin;
	if((a = set_opts(argc,argv)) < argc) f = fopen(argv[a],"r");

	if(argfile != NULL) read_file(argfile);
	//printf("%d %d %s\n",ignore_errors,verbose,argfile);
	char input[128];
	while(fgets(input,sizeof(input),f)!=NULL)
	{
		unsigned int j = 0;
		//input[strlen(input)-1] = '\0';
		find_first_comment(input);
		char* toks[64];
		char* token;
		token = strtok(input," ");
		while(token !=NULL)
		{
			toks[j++] = token;
			token = strtok(NULL," ");
		}
		toks[j] = NULL;

		char **args;
		if(argfile != NULL) args = append_args(j,toks);
		else args = toks;

		if(verbose) print_argv(args);
		int exitstat;
		switch(child_pid = fork())
		{
			case -1:
				exit(1);
			case 0:
				child_stat = execvp(args[0],args);
				exit(child_stat);
			default:
				if (timeout)
				{
					exitstat = th(0);
					milliseconds = 0;
				}
				else
				{
					waitpid(child_pid, &child_stat,0);
					exitstat = WEXITSTATUS(child_stat);
				}
				if(argfile != NULL) free(args);
		}

		if (exitstat)
		{
			if(ignore_errors) error_seen = 1;
			else 
			{	
				if(exitstat == -2) exit(2);
				else exit(1);
			}
		}
	}
	return error_seen;
}
コード例 #13
0
ファイル: plugin.c プロジェクト: xnuxer/vpnconnect
static void
plugin_open_item (struct plugin *p,
		  const struct plugin_option *o,
		  struct vpnconnect_plugin_string_list **retlist,
		  const char **envp,
		  const int init_point)
{
  ASSERT (p->initialized);

  /* clear return list */
  if (retlist)
    *retlist = NULL;

  if (!p->plugin_handle && init_point == p->requested_initialization_point)
    {
      struct gc_arena gc = gc_new ();

      dmsg (D_PLUGIN_DEBUG, "PLUGIN_INIT: PRE");
      plugin_show_args_env (D_PLUGIN_DEBUG, o->argv, envp);

      /*
       * Call the plugin initialization
       */
      if (p->open3) {
        struct vpnconnect_plugin_args_open_in args = { p->plugin_type_mask,
                                                    (const char ** const) o->argv,
                                                    (const char ** const) envp,
                                                    &callbacks,
                                                    SSLAPI,
                                                    PACKAGE_VERSION,
                                                    VPNCONNECT_VERSION_MAJOR,
                                                    VPNCONNECT_VERSION_MINOR,
                                                    _VPNCONNECT_PATCH_LEVEL
        };
        struct vpnconnect_plugin_args_open_return retargs;

        CLEAR(retargs);
        retargs.return_list = retlist;
        if ((*p->open3)(VPNCONNECT_PLUGINv3_STRUCTVER, &args, &retargs) == VPNCONNECT_PLUGIN_FUNC_SUCCESS) {
          p->plugin_type_mask = retargs.type_mask;
          p->plugin_handle = retargs.handle;
        } else {
          p->plugin_handle = NULL;
        }
      } else if (p->open2)
	p->plugin_handle = (*p->open2)(&p->plugin_type_mask, o->argv, envp, retlist);
      else if (p->open1)
	p->plugin_handle = (*p->open1)(&p->plugin_type_mask, o->argv, envp);
      else
	ASSERT (0);

      msg (D_PLUGIN, "PLUGIN_INIT: POST %s '%s' intercepted=%s %s",
	   p->so_pathname,
	   print_argv (o->argv, &gc, PA_BRACKET),
	   plugin_mask_string (p->plugin_type_mask, &gc),
	   (retlist && *retlist) ? "[RETLIST]" : "");
      
      if ((p->plugin_type_mask | plugin_supported_types()) != plugin_supported_types())
	msg (M_FATAL, "PLUGIN_INIT: plugin %s expressed interest in unsupported plugin types: [want=0x%08x, have=0x%08x]",
	     p->so_pathname,
	     p->plugin_type_mask,
	     plugin_supported_types());

      if (p->plugin_handle == NULL)
	msg (M_FATAL, "PLUGIN_INIT: plugin initialization function failed: %s",
	     p->so_pathname);

      gc_free (&gc);
    }
}
コード例 #14
0
ファイル: cc2cl.c プロジェクト: JamesLinus/CompilerInterface
int main(int argc, char **argv) {
#define FIND_LONG_OPTION(ARRAY) \
	{															\
		for(i = 0; i < sizeof (ARRAY) / sizeof(struct option); i++) {							\
			struct option *o = (ARRAY) + i;										\
			if(o->arg < 2) {											\
				if(strcmp(arg, o->opt) == 0) {									\
					const char *a = o->arg ? *++v : argv[0];						\
					if(o->arg && !a) {									\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			} else {												\
				size_t len = strlen(o->opt);									\
				if(strncmp(arg, o->opt, len) == 0) {								\
					if(arg[len] && arg[len] != '=') continue;						\
					if(!arg[len] || !arg[len + 1]) {							\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					const char *a = arg + len + 1;								\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			}													\
		}														\
	}

#define UNRECOGNIZED_OPTION(O) \
	do {									\
		fprintf(stderr, "%s: error: unrecognized option '%s'\n",	\
			argv[0], (O));						\
		return 1;							\
	} while(0)


	int verbose = 0;
	int no_link = 0;
	int preprocess_only = -1;
	int no_warning = -1;
	int end_of_options = 0;
	const char *output_file = NULL;
	char **v = argv;
	init_argv();

	const char *vs_path = getenv("VS_PATH");
	if(!vs_path) vs_path = getenv("VSINSTALLDIR");
	if(!getenv("INCLUDE")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 12 + len + 24 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/include;", 12);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/include;");
			setenv("INCLUDE", buffer, 0);
		} else {
			no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system include path set\n", argv[0]);
		}
	}
	if(!getenv("LIB")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 8 + len + 20 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/lib;", 8);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/lib;");
			setenv("LIB", buffer, 0);
		} else {
			if(no_warning == -1) no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system library path set\n", argv[0]);
		}
	}

first_loop:
	while(*++v) {
		if(!end_of_options && **v == '-') {
			int i;
			if((*v)[1] == '-') {
				const char *arg = *v + 2;
				if(!*arg) {
					end_of_options = 1;
					continue;
				}
				FIND_LONG_OPTION(double_dash_long_options);
				if(strcmp(arg, "verbose") == 0) {
					verbose = 1;
				} else UNRECOGNIZED_OPTION(*v);
			} else {
				const char *arg = *v + 1;
				FIND_LONG_OPTION(singal_dash_long_options);
				switch(*arg) {
					case 0:
						goto not_an_option;
					case 'c':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-c");
						no_link = 1;
						break;
					case 'D':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *d = *++v;
							if(!d) {
								fprintf(stderr, "%s: error: macro name missing after '-D'\n",
									argv[0]);
								return 1;
							}
							define(d);
						}
						break;
					case 'E':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-E");
						preprocess_only = 1;						
						break;
					case 'f':
						if(arg[1]) set_feature(arg + 1);
						else {
							const char *feature = *++v;
							if(!feature) {
								fprintf(stderr, "%s: error: option '-f' need an argument\n",
									argv[0]);
								return -1;
							}
							set_feature(feature);
						}
						break;
					case 'g':
						// -g[coff][<level>] (level: 0~3)
						if(arg[1]) {
							const char *level = arg + 1;
							if(strncmp(level, "coff", 4) == 0) level += 4;
							if(*level && *level != '-') {
								int i = 0;
								do {
									if(!isdigit(level[i])) {
										fprintf(stderr, "%s: error: unrecognized debug output level \"%s\"\n",
											argv[0], level);
										return 1;
									}
								} while(level[++i]);
								/*
								if(i > 1 || *level > '3') {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
								if(*level == '0') break;
								*/
								int l = atoi(level);
								if(!l) break;
								if(l > 3) {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
							}
						}
						add_to_argv("-Zi");
						break;
					case 'I':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						//if(arg[1]) add_to_argv(*v);
						if(arg[1]) add_include_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-I' need an argument\n",
									argv[0]);
								return 1;
							}
							add_include_path(path, no_warning);
						}
						break;
					case 'L':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						if(arg[1]) add_library_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-L' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library_path(path, no_warning);
						}
						break;
					case 'l':
						if(arg[1]) add_library(arg + 1);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-l' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library(path);
						}
						break;
					case 'M':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-showIncludes");
						break;
					case 'm':
						if(arg[1]) set_machine(arg + 1);
						else {
							const char *machine = *++v;
							if(!machine) {
								fprintf(stderr, "%s: argument to `-m' is missing\n",
									argv[0]);
								return 1;
							}
							set_machine(machine);
						}
						break;
					case 'O':
						if(arg[1]) {
							const char *o = arg + 1;
							if(strcmp(o, "0") == 0) add_to_argv("-Od");
							else if(strcmp(o, "1") == 0) add_to_argv("-O2");
							else if(strcmp(o, "3") == 0) add_to_argv("-Ox");
							else if(strcmp(o, "s") == 0) add_to_argv("-O1");
							else if(strcmp(o, "fast") == 0) add_to_argv("-O2");
							else add_to_argv(*v);
						} else add_to_argv("-O2");
						break;
					case 'o':
						if(arg[1]) output_file = arg + 1;
						else {
							output_file = *++v;
							if(!output_file) {
								fprintf(stderr, "%s: error: option '-o' need an argument\n",
									argv[0]);
								return 1;
							}
						}
						break;
					case 'P':
						if(preprocess_only == -1) preprocess_only = find_argv(argv, "-E");
						if(preprocess_only) add_to_argv("-EP");
						break;
					case 's':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						break;
					case 'U':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *u = *++v;
							if(!u) {
								fprintf(stderr, "%s: error: macro name missing after '-U'\n",
									argv[0]);
								return 1;
							}
							undefine(u);
						}
						break;
					case 'v':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						verbose = 1;
						break;
					case 'W':
						if(!arg[1]) {
							if(no_warning == -1) no_warning = find_argv(argv, "-w");
							if(!no_warning) {
								fprintf(stderr, "%s: warning: option '-W' is deprecated; use '-Wextra' instead\n",
									argv[0]);
							}
							add_to_argv("-Wall");
							break;
						}
						if(strncmp(arg, "Wa,", 3) == 0 || strncmp(arg, "Wp,", 3) == 0 || strncmp(arg, "Wl,", 3) == 0) {
							(*v)[3] = 0;		// XXX
							fprintf(stderr, "%s: warning: option '%s' is not supported\n", argv[0], *v);
							break;
						} 
						if(set_warning(arg + 1)) break;
						add_to_argv(*v);
						break;
					case 'w':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-w");
						no_warning = 1;
						break;
					case 'x':
						if(arg[1]) set_language(arg + 1);
						else {
							const char *lang = *++v;
							if(!lang) {
								fprintf(stderr, "%s: error: missing argument to ‘-x’",
									argv[0]);
								return 4;
							}
							set_language(lang);
						}
						break;
					default:
						fprintf(stderr, "%s: error: unrecognized option '%s'\n", argv[0], *v);
						return 1;
				}
			}
		} else {
not_an_option:
#if defined __INTERIX && !defined _NO_CONV_PATH
			if(**v == '/') {
				char buffer[PATH_MAX + 1];
				if(unixpath2win(*v, 0, buffer, sizeof buffer) == 0) {
					add_input_file(buffer);
				} else {
					if(no_warning == -1) no_warning = find_argv(argv, "-w");
					if(!no_warning) {
						fprintf(stderr, "%s: warning: cannot convert '%s' to Windows path name, %s\n",
							argv[0], *v, strerror(errno));
					}
					add_input_file(*v);
				}
			} else
#endif
			add_input_file(*v);
		}
	}
	setvbuf(stdout, NULL, _IOLBF, 0);
	if(preprocess_only == -1) preprocess_only = 0;
	if(no_warning == -1) no_warning = 0;
	if(last_language && last_language_unused && !no_warning) {
		fprintf(stderr, "%s: warning: '-x %s' after last input file has no effect\n", argv[0], last_language);
	}
	if(!first_input_file) {
		if(verbose) {
			if(!no_link) add_to_argv("-c");
			start_cl();
			return 0;
		}
		fprintf(stderr, "%s: no input files\n", argv[0]);
		return 1;
	}
	if(multiple_input_files && (preprocess_only || no_link)) {
		if(output_file) {
			fprintf(stderr, "%s: error: cannot specify -o with -c or -E with multiple files\n", argv[0]);
			return 4;
		} else if(no_link) {
			fprintf(stderr, "%s: error: '-c' with multiple files is currently not supported\n", argv[0]);
			return -1;
		}
	}
	if(!output_file && !preprocess_only) {
		if(no_link) {
			size_t len = strlen(first_input_file);
			int n = get_last_dot(first_input_file, len);
			if(n >= 0) len = n;
			char *p = malloc(len + 3);
			if(!p) {
				perror(argv[0]);
				return 1;
			}
			memcpy(p, first_input_file, len);
			strcpy(p + len, ".o");
			output_file = p;
		} else output_file = DEFAULT_OUTPUT_FILENAME;
	}
	if(!verbose) add_to_argv("-nologo");
	if(preprocess_only) {
		if(output_file) target.name = output_file;
		target.type = PREPROCESSED_SOURCE;
	} else set_output_file(output_file, no_link, no_warning);
	//if(no_static_link) add_to_argv("-MD");
	add_to_argv(no_static_link ? "-MD" : "-MT");
	add_libraries_to_argv();
	if(verbose) print_argv();
	return start_cl();
}
コード例 #15
0
ファイル: part3.c プロジェクト: shawntan/schoolwork
int main(int argc,char** argv,char *envp[])
{
	int a;
	f = stdin;
	if((a = set_opts(argc,argv)) < argc) f = fopen(argv[a],"r");

	if(argfile != NULL) read_file(argfile);

	//printf("%d %d %s\n",ignore_errors,verbose,argfile);
	char input[128];
	int stat = 0;
	while(fgets(input,sizeof(input),f)!=NULL)
	{
		unsigned int j = 0;
		input[strlen(input)-1] = '\0';
		if(input[0] !='#') 
		{
			char* toks[64];
			char* token;
			token = strtok(input," ");
			while(token !=NULL)
			{
				toks[j++] = token;
				token = strtok(NULL," ");
			}
			toks[j] = NULL;

			char **args;
			if(argfile != NULL) args = append_args(j,toks);
			else args = toks;

			if(verbose) print_argv(args);
			struct itimerval new;
			switch(child_pid = fork())
			{
				case -1:
					exit(1);
				case 0:
					stat = execvp(args[0],args);
					exit(stat);
				default:
					/*
					memset(&sa,0,sizeof(sa));
					sa.sa_handler = timeout_handler;
					sigaction(SIGALRM,&sa,NULL);
					*/
					signal(SIGALRM,timeout_handler);
					ualarm(1000,0);
					/*
					new.it_interval.tv_usec = 0;
					new.it_interval.tv_sec = 0;
					new.it_value.tv_sec =  1;
					new.it_value.tv_usec =(long int)1000*ms;
					setitimer(ITIMER_REAL, &new,NULL);
					*/
					waitpid(child_pid,&stat,0);
					if(argfile != NULL) free(args);
			}

			int exitstat = WEXITSTATUS(stat);
			if (exitstat)
			{
				if(ignore_errors) error_seen = 1;
				else exit(1);
			}
		}
	}