コード例 #1
0
ファイル: assembler.c プロジェクト: jacob-hegna/open8080
int assemble(char *filename) {
    FILE *file = fopen(filename, "r");
    if(file == NULL) {
        printf("Error: cannot open '%s'\n", filename);
        exit(1);
    }

    FILE *output = fopen("a.out", "wb");

    fseek(file, 0L, SEEK_END);
    int fsize = ftell(file);
    fseek(file, 0L, SEEK_SET);

    char *chardump = malloc(fsize);
    fread(chardump, fsize, 1, file);
    fclose(file);

    int line_amt = 1;
    for(int i = 0; i < fsize; ++i) {
        if(chardump[i] == '\n') ++line_amt;
    }

    char **lines = malloc(sizeof(char*) * line_amt);

    char *tok = strtok(chardump, "\n");
    for(int i = 0; i < line_amt; ++i) {
        lines[i] = tok;
        tok = strtok(NULL, "\n");
    }
    free(chardump);

    for(int i = 0; i < line_amt; ++i) {
        assemble_line(output, cstrlwr(lines[i]));
    }

    free(lines);
    fclose(output);
    return 0;
}
コード例 #2
0
ファイル: util.c プロジェクト: walterdejong/bbs100
/*
	convert key code to long color code
	some key codes do not have a long equivalent

	flags can be USR_SHORT_DL_COLORS, which means that the color codes should be
	represented in short format
*/
int short_color_to_long(char c, char *buf, int max_len, int flags) {
int i;

	if (buf == NULL || max_len <= 0)
		return -1;

	buf[0] = 0;
	switch(c) {
		case KEY_CTRL('Q'):				/* don't auto-color this string */
			break;

		case KEY_CTRL('X'):
			break;

		case KEY_CTRL('A'):
			cstrcpy(buf, "<beep>", max_len);
			break;

		case KEY_CTRL('L'):				/* clear screen */
			break;

		case KEY_CTRL('Z'):
		case KEY_CTRL('R'):
		case KEY_CTRL('G'):
		case KEY_CTRL('Y'):
		case KEY_CTRL('B'):
		case KEY_CTRL('M'):
		case KEY_CTRL('C'):
		case KEY_CTRL('W'):
			for(i = 0; i < NUM_COLORS; i++) {
				if (color_table[i].key == c) {
					if (flags & USR_SHORT_DL_COLORS) {
/*
	black is Ctrl-Z, but actually has to entered as Ctrl-K
	see also edit_color() in edit.c

	(this is confusing, but black is blacK, while the K is for hotkeys)
*/
						if (c == KEY_CTRL('Z'))
							c = KEY_CTRL('K');

						bufprintf(buf, max_len, "^%c", c + 'A' - 1);
					} else {
						bufprintf(buf, max_len, "<%s>", color_table[i].name);
						cstrlwr(buf);
					}
					break;
				}
			}
			break;

		case KEY_CTRL('K'):
			cstrcpy(buf, "<hotkey>", max_len);
			break;

		case KEY_CTRL('N'):
			cstrcpy(buf, "<normal>", max_len);
			break;

		case KEY_CTRL('D'):
			cstrcpy(buf, "<default>", max_len);
			break;

		default:
			if (c >= ' ' && c <= '~' && max_len >= 2) {
				buf[0] = c;
				buf[1] = 0;
			}
	}
	return 0;
}