コード例 #1
0
ファイル: forkargs.c プロジェクト: cme/forkargs
/* Parse command-line arguments */
void parse_args(int argc, char *argv[], int *first_arg_p)
{
  int i;
  for (i = 1; i < argc && argv[i][0] == '-'; i++)
    {
      if (argv[i][1] == 'j')
        {
          if (argv[i][2])
            /* '-j<string>' */
            slots_string = &argv[i][2];
          else if (i + 1 < argc)
            /* '-j' '<string>' */
            slots_string = argv[++i];
          else
            missing_arg (argv[i]);
        }
      else if (argv[i][1] == 'k' && !argv[i][2])
        continue_on_error = 1;
      else if (argv[i][1] == 'v' && !argv[i][2])
        verbose = 1;
      else if (argv[i][1] == 'n' && !argv[i][2])
        skip_slot_test = 1;
      else if (argv[i][1] == 't')
        {
          const char *trace_name = "-";
          if (argv[i][2])
            /* '-t<filename>' */
            trace_name = &argv[i][2];
          else if (i + 1 < argc)
            /* '-t <filename>' */
            trace_name = argv[++i];
          else
            /* '-t' */
            missing_arg (argv[i]);
          if (trace_name[0] == '-' && trace_name[1] == '\0')
            trace = stderr;
          else
            trace = fopen (trace_name, "w");
          if (trace_name && !trace)
            {
              fprintf (stderr, "Cannot open trace file '%s'\n", trace_name);
              exit (0);
            }
        }
      else if (argv[i][1] == 'f')
        {
          const char *in_arguments_name = "-";
          if (argv[i][2])
            in_arguments_name = &argv[i][2];
          else if (i + 1 < argc)
            in_arguments_name = argv[++i];
          else
            missing_arg (argv[i]);
          if (in_arguments_name[0] == '-' && in_arguments_name[1] == '\0')
            in_arguments = stdin;
          else
            in_arguments = fopen(in_arguments_name, "r");
          if (!in_arguments)
            {
              fprintf (stderr, "Cannot open input file '%s'\n",
                       in_arguments_name);
              exit (0);
            }
        }
      else if (argv[i][1] == 'h' || (argv[i][1] == '-' && argv[i][2] == 'h'))
        {
          help();
          exit (0);
        }
      else if (!strcmp(argv[i], "sync"))
        {
          sync_working_dirs = 1;
        }
      else
        bad_arg (argv[i]);
    }
  *first_arg_p = i;
}
コード例 #2
0
ファイル: serdi.c プロジェクト: anukat2015/serd
int
main(int argc, char** argv)
{
	if (argc < 2) {
		return print_usage(argv[0], true);
	}

	FILE*          in_fd         = NULL;
	SerdSyntax     input_syntax  = SERD_TURTLE;
	SerdSyntax     output_syntax = SERD_NTRIPLES;
	bool           from_file     = true;
	bool           bulk_read     = true;
	bool           bulk_write    = false;
	bool           full_uris     = false;
	bool           lax           = false;
	bool           quiet         = false;
	const uint8_t* in_name       = NULL;
	const uint8_t* add_prefix    = NULL;
	const uint8_t* chop_prefix   = NULL;
	const uint8_t* root_uri      = NULL;
	int            a             = 1;
	for (; a < argc && argv[a][0] == '-'; ++a) {
		if (argv[a][1] == '\0') {
			in_name = (const uint8_t*)"(stdin)";
			in_fd   = stdin;
			break;
		} else if (argv[a][1] == 'b') {
			bulk_write = true;
		} else if (argv[a][1] == 'e') {
			bulk_read = false;
		} else if (argv[a][1] == 'f') {
			full_uris = true;
		} else if (argv[a][1] == 'h') {
			return print_usage(argv[0], false);
		} else if (argv[a][1] == 'l') {
			lax = true;
		} else if (argv[a][1] == 'q') {
			quiet = true;
		} else if (argv[a][1] == 'v') {
			return print_version();
		} else if (argv[a][1] == 's') {
			in_name = (const uint8_t*)"(string)";
			from_file = false;
			++a;
			break;
		} else if (argv[a][1] == 'i') {
			if (++a == argc) {
				return missing_arg(argv[0], 'i');
			} else if (!set_syntax(&input_syntax, argv[a])) {
				return print_usage(argv[0], true);
			}
		} else if (argv[a][1] == 'o') {
			if (++a == argc) {
				return missing_arg(argv[0], 'o');
			} else if (!set_syntax(&output_syntax, argv[a])) {
				return print_usage(argv[0], true);
			}
		} else if (argv[a][1] == 'p') {
			if (++a == argc) {
				return missing_arg(argv[0], 'p');
			}
			add_prefix = (const uint8_t*)argv[a];
		} else if (argv[a][1] == 'c') {
			if (++a == argc) {
				return missing_arg(argv[0], 'c');
			}
			chop_prefix = (const uint8_t*)argv[a];
		} else if (argv[a][1] == 'r') {
			if (++a == argc) {
				return missing_arg(argv[0], 'r');
			}
			root_uri = (const uint8_t*)argv[a];
		} else {
			SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
			return print_usage(argv[0], true);
		}
	}

	if (a == argc) {
		SERDI_ERROR("missing input\n");
		return 1;
	}

	const uint8_t* input = (const uint8_t*)argv[a++];
	if (from_file) {
		in_name = in_name ? in_name : input;
		if (!in_fd) {
			input = serd_uri_to_path(in_name);
			if (!input || !(in_fd = serd_fopen((const char*)input, "r"))) {
				return 1;
			}
		}
	}

	SerdURI  base_uri = SERD_URI_NULL;
	SerdNode base     = SERD_NODE_NULL;
	if (a < argc) {  // Base URI given on command line
		base = serd_node_new_uri_from_string(
			(const uint8_t*)argv[a], NULL, &base_uri);
	} else if (from_file && in_fd != stdin) {  // Use input file URI
		base = serd_node_new_file_uri(input, NULL, &base_uri, false);
	}

	FILE*    out_fd = stdout;
	SerdEnv* env    = serd_env_new(&base);

	int output_style = 0;
	if (output_syntax == SERD_NTRIPLES) {
		output_style |= SERD_STYLE_ASCII;
	} else {
		output_style |= SERD_STYLE_ABBREVIATED;
		if (!full_uris) {
			output_style |= SERD_STYLE_CURIED;
		}
	}

	if (input_syntax != SERD_NTRIPLES || (output_style & SERD_STYLE_CURIED)) {
		// Base URI may change and/or we're abbreviating URIs, so must resolve
		output_style |= SERD_STYLE_RESOLVED;  // Base may chan
	}

	if (bulk_write) {
		output_style |= SERD_STYLE_BULK;
	}

	SerdWriter* writer = serd_writer_new(
		output_syntax, (SerdStyle)output_style,
		env, &base_uri, serd_file_sink, out_fd);

	SerdReader* reader = serd_reader_new(
		input_syntax, writer, NULL,
		(SerdBaseSink)serd_writer_set_base_uri,
		(SerdPrefixSink)serd_writer_set_prefix,
		(SerdStatementSink)serd_writer_write_statement,
		(SerdEndSink)serd_writer_end_anon);

	serd_reader_set_strict(reader, !lax);
	if (quiet) {
		serd_reader_set_error_sink(reader, quiet_error_sink, NULL);
		serd_writer_set_error_sink(writer, quiet_error_sink, NULL);
	}

	SerdNode root = serd_node_from_string(SERD_URI, root_uri);
	serd_writer_set_root_uri(writer, &root);
	serd_writer_chop_blank_prefix(writer, chop_prefix);
	serd_reader_add_blank_prefix(reader, add_prefix);

	SerdStatus status = SERD_SUCCESS;
	if (!from_file) {
		status = serd_reader_read_string(reader, input);
	} else if (bulk_read) {
		status = serd_reader_read_file_handle(reader, in_fd, in_name);
	} else {
		status = serd_reader_start_stream(reader, in_fd, in_name, false);
		while (!status) {
			status = serd_reader_read_chunk(reader);
		}
		serd_reader_end_stream(reader);
	}

	serd_reader_free(reader);

	if (from_file) {
		fclose(in_fd);
	}

	serd_writer_finish(writer);
	serd_writer_free(writer);
	serd_env_free(env);
	serd_node_free(&base);

	return (status > SERD_FAILURE) ? 1 : 0;
}
コード例 #3
0
ファイル: mindy.c プロジェクト: sparkhom/mindy
int main(int argc, char *argv[])
{
    struct thread *thread;
    enum pause_reason reason;
    struct variable *var;
#if ! NO_ARGV_0
    char *argv0 = "mindy";
#endif

    exec_file_name = argv[0];

    init_color(false);

    init();

    thread = thread_make(symbol("main"));
    *thread->sp++ = make_raw_function("startup", obj_Nil,
                                      true, obj_False, false,
                                      obj_Nil, obj_ObjectClass,
                                      startup);

    while (*++argv != NULL) {
        if (strcmp(*argv, "-f") == 0) {
            if (*++argv == NULL)
                missing_arg("-f");
            load(*argv);
#if ! NO_SHARP_BANG
        } else if (strcmp(*argv, "-x") == 0) {
            if (*++argv == NULL)
                missing_arg("-f");
#if ! NO_ARGV_0
            if (strcmp(*argv, "-") != 0)
                argv0 = *argv;
#endif
            load(*argv);
            argv += 1;
            break;
#endif
#if ! NO_ARGV_0
        } else if (strcmp(*argv, "-0") == 0) {
            if (*++argv == NULL)
                missing_arg("-0");
            argv0 = *argv;
#endif
        } else {
            break;
        }
    }

#if ! NO_ARGV_0
        *thread->sp++ = make_byte_string(argv0);    /* pass command name */
#endif
    while (*argv != NULL)
        *thread->sp++ = make_byte_string(*argv++);

    finalize_modules();

    while (1) {
        thread_restart(thread);

        reason = do_stuff();
        if (reason != pause_NothingToRun)
            invoke_debugger(reason);

        var = find_variable(module_BuiltinStuff, symbol("exit"),
                            false, false);
        if (var == NULL)
            lose("main undefined?");

        thread = thread_make(symbol("exit"));
        *thread->sp++ = var->value;
    }
    return 0;
}
コード例 #4
0
int
main(int argc, char **argv)
{
    int argn;
    FT_Error ftrc;
    int rc, ll = 0;
    char prefix[NPREFIX];

    ProgramName = argv[0];
    encodingPrefix = NULL;
    exclusionSuffix = NULL;

    if(getcwd(prefix, NPREFIX - 1) == NULL) {
        perror("Couldn't get cwd");
        exit(1);
    }
    if(prefix[strlen(prefix) - 1] != '/')
        strcat(prefix, "/");
    encodingPrefix = dsprintf("%s", prefix);

    outfilename = NULL;

    encodings = makeList((char **)encodings_array, countof(encodings_array), NULL, 0);

    extra_encodings = makeList((char**)extra_encodings_array,
                               countof(extra_encodings_array),
                               NULL, 0);
    doBitmaps = 0;
    doISO10646_1_encoding = 1;
    doScalable = 1;
    onlyEncodings = 0;
    relative = 0;
    reencodeLegacy = 1;
    encodingsToDo = NULL;

    argn = 1;
    while(argn < argc) {
        if(argv[argn][0] == '\0' || argv[argn][0] != '-')
            break;
        if(argv[argn][1] == '-') {
            argn++;
            break;
        } else if (strcmp(argv[argn], "-x") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-x");
            }
            exclusionSuffix = argv[argn + 1];
            argn += 2;
        } else if(strcmp(argv[argn], "-a") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-a");
            }
            makeList(&argv[argn + 1], 1, encodings, 0);
            argn += 2;
        } else if(strcmp(argv[argn], "-p") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-p");
            }
            if(strlen(argv[argn + 1]) > NPREFIX - 1) {
                fprintf(stderr, "%s: argument to -p cannot be longer than "
                        "%d characters\n", ProgramName, NPREFIX - 1);
                usage();
            }
            free(encodingPrefix);
            encodingPrefix = dsprintf("%s", argv[argn + 1]);
            argn += 2;
        } else if(strcmp(argv[argn], "-e") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-e");
            }
            rc = readEncodings(encodingsToDo, argv[argn + 1]);
            if(rc < 0)
                exit(1);
            argn += 2;
        } else if(strcmp(argv[argn], "-b") == 0) {
            doBitmaps = 1;
            argn++;
        } else if(strcmp(argv[argn], "-u") == 0) {
            doISO10646_1_encoding = 0;
            argn++;
        } else if(strcmp(argv[argn], "-U") == 0) {
            doISO10646_1_encoding = 1;
            argn++;
        } else if(strcmp(argv[argn], "-s") == 0) {
            doScalable = 0;
            argn++;
        } else if(strcmp(argv[argn], "-n") == 0) {
            onlyEncodings = 1;
            argn++;
        } else if(strcmp(argv[argn], "-r") == 0) {
            relative = 1;
            argn++;
        } else if(strcmp(argv[argn], "-l") == 0) {
            reencodeLegacy = !reencodeLegacy;
            argn++;
        } else if(strcmp(argv[argn], "-o") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-o");
            }
            outfilename = argv[argn + 1];
            argn += 2;
        } else if(strcmp(argv[argn], "-f") == 0) {
            if(argn >= argc - 1) {
                missing_arg("-f");
            }
            bigEncodingFuzz = atof(argv[argn + 1]) / 100.0;
            argn += 2;
	} else if (strcmp(argv[argn], "-v") == 0) {
	    printf("%s\n", PACKAGE_STRING);
	    exit(0);
	} else {
            usage();
        }
    }

    if(outfilename == NULL) {
        if(doBitmaps)
            outfilename = "fonts.dir";
        else
            outfilename = "fonts.scale";
    }

    ftrc = FT_Init_FreeType(&ft_library);
    if(ftrc) {
        fprintf(stderr, "Could not initialise FreeType library: %d\n", ftrc);
        exit(1);
    }

    ll = listLength(encodingsToDo);

    if (argn == argc)
        doDirectory(".", ll, encodingsToDo);
    else
        while(argn < argc) {
            doDirectory(argv[argn], ll, encodingsToDo);
            argn++;
        }
    return 0;
}
コード例 #5
0
ファイル: atobm.c プロジェクト: Bluerise/openbsd-xenocara
int
main (int argc, char *argv[])
{
    int i;
    int xhot = -1, yhot = -1;
    char *filename = NULL;
    const char *chars = "-#";
    const char *name = NULL;
    FILE *fp;

    ProgramName = argv[0];

    for (i = 1; i < argc; i++) {
	char *arg = argv[i];

	if (arg[0] == '-') {
	    switch (arg[1]) {
	      case '\0':
		filename = NULL;
		continue;
	      case 'c':
		if (++i >= argc) missing_arg("-chars");
		chars = argv[i];
		continue;
	      case 'n':
		if (++i >= argc) missing_arg("-name");
		name = argv[i];
		continue;
	      case 'x':
		if (++i >= argc) missing_arg("-xhot");
		xhot = atoi (argv[i]);
		continue;
	      case 'y':
		if (++i >= argc) missing_arg("-yhot");
		yhot = atoi (argv[i]);
		continue;
	      default:
		fprintf(stderr, "%s: unrecognized option '%s'\n",
			ProgramName, argv[i]);
		usage (NULL);
	    }
	} else {
	    filename = arg;
	}
    }

    if (strlen (chars) != 2) {
	fprintf (stderr,
	 "%s:  bad character list \"%s\", must have exactly 2 characters\n",
		 ProgramName, chars);
	exit (1);
    }

    if (filename) {
	fp = fopen (filename, "r");
	if (!fp) {
	    fprintf (stderr, "%s:  unable to open file \"%s\".\n",
		     ProgramName, filename);
	    exit (1);
	}
    } else {
	fp = stdin;
    }

    if (!name)
	name = filename ? cify_name (StripName (filename)) : "";
    doit (fp, filename, chars, xhot, yhot, name);

    if (filename) (void) fclose (fp);
    exit (0);
}