Пример #1
0
int main(int argc, char **argv) {
	const char *outfn = "out.hex";

	while (argc > 1) {
		argc--;
		argv++;
		if (argv[0][0] == '-') {
			if (!strcmp(argv[0],"-o")) {
				if (argc > 1) {
					outfn = argv[1];
					argc--;
					argv++;
					continue;
				}
			}
			die("unknown option: %s", argv[0]);
		}
		assemble(argv[0]);
	}

	if (PC != 0) {
		linebuffer[0] = 0;
		resolve_fixups();
		emit(outfn);
	}
	return 0;
}
Пример #2
0
int main(int argc, char **argv) {
	const char *outfn = "out.hex";
	enum outformat oformat = OUTFORMAT_PRETTY;

	for (;;) {
		int c;
		int option_index = 0;

		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			{"output", 1, 0, 'o'},
			{"outformat", 1, 0, 'O'},
			{0, 0, 0, 0},
		};

		c = getopt_long(argc, argv, "ho:O:", long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case 'h':
				usage(argc, argv);
				return 0;
			case 'o':
				outfn = optarg;
				break;
			case 'O':
				if (!strcasecmp(optarg, "binary")) {
					oformat = OUTFORMAT_BINARY;
				} else if (!strcasecmp(optarg, "hex")) {
					oformat = OUTFORMAT_HEX;
				} else if (!strcasecmp(optarg, "pretty")) {
					oformat = OUTFORMAT_PRETTY;
				} else {
					usage(argc, argv);
					return 1;
				}
				break;
			default:
				usage(argc, argv);
				return 1;
		}
	}

	if (argc - optind < 1) {
		usage(argc, argv);
		return 1;
	}

	argc -= optind;
	argv += optind;

	while (argc >= 1) {
		assemble(argv[0]);
		argv++;
		argc--;
	}

	if (PC != 0) {
		linebuffer[0] = 0;
		resolve_fixups();
		emit(outfn, oformat);
	}
	return 0;
}