Esempio n. 1
0
void naomi_m1_board::enc_fill()
{
    while(buffer_actual_size < BUFFER_SIZE && !stream_ended) {
        switch(lookb(3)) {
        // 00+2 - 0000+esc
        case 0:
        case 1: {
            skipb(2);
            int addr = getb(2);
            if(addr)
                wb(dict[addr]);
            else
                wb(getb(8));
            break;
        }

        // 010+2
        case 2:
            skipb(3);
            wb(dict[getb(2)+4]);
            break;

        // 011+3
        case 3:
            skipb(3);
            wb(dict[getb(3)+8]);
            break;

        // 10+5
        case 4:
        case 5:
            skipb(2);
            wb(dict[getb(5)+16]);
            break;

        // 11+6
        case 6:
        case 7: {
            skipb(2);
            int addr = getb(6)+48;
            if(addr == 111)
                stream_ended = true;
            else
                wb(dict[addr]);
            break;
        }
        }
    }

    while(buffer_actual_size < BUFFER_SIZE)
        buffer[buffer_actual_size++] = 0;
}
Esempio n. 2
0
/*
 * tokenize -- a version of the standard strtok with specific behavior.
 */
static char *
tokenize(char *line)
{
	static char *p = NULL;
	static char saved = 0;
	char *q;

	if (line == NULL && p == NULL) {
		/* It's the very first time */
		return (NULL);
	} else if (line != NULL) {
		/* Initialize with a new line */
		q = skipb(line);
	} else {
		/* Restore previous line. */
		*p = saved;
		q = skipb(p);
	}
	/* q is at the beginning of a token or at EOL, p is irrelevant. */

	if (*q == '\0') {
		/* It's at EOL. */
		p = q;
	} else if (in_specials(*q)) {
		/* We have a special-character token. */
		p = q + 1;
	} else if (*q == '#') {
		/* The whole rest of the line is a comment token. */
		return (NULL);
	} else {
		/* We have a word token. */
		p = skipover(q);
	}
	saved = *p;
	*p = '\0';

	if (p == q) {
		/* End of line */
		return (NULL);
	} else {
		return (q);
	}
}
Esempio n. 3
0
File: port.c Progetto: davecb/port
/*
 * quote -- return a string with any ' characters
 *	protected from sh and echo. Serially reusable only.
 */
 static char *
quote(char *p) {
	static char buffer[MAXLINE];
	char	*q = &buffer[0];

	p = skipb(p);
	while (*p != '\0') {
		switch(*p) {
		case '\'':
			*q++ = '\\';
			*q++ = '0';
			*q++ = '4';
			*q++ = '7';
			p++;
			break;
		default:
			*q++ = *p++;
			break;
		}
	}
	*q = '\0';
	return &buffer[0];
}
Esempio n. 4
0
main(int argc, char **argv)
{
    FILE *fp;
    long start, count;

    if (argc < 2)
    {
        puts("Usage: HEXDUMP file_name [start] [length]");
        return (EXIT_FAILURE);
    }
    if (argc > 2)
    {
        start = strtol(*(argv + 2), NULL, 0);
    }
    else
    {
        start = 0L;
    }
    if (argc > 3)
    {
        count = strtol(*(argv + 3), NULL, 0);
    }
    else
    {
        count = -1L;
    }
    fp = fopen(*(argv + 1), "rb");
    if (fp == NULL)
    {
        printf("unable to open file %s for input\n", *(argv + 1));
        return (EXIT_FAILURE);
    }
    skipb(fp, start);
    dodump(fp, start, count);
    return (EXIT_SUCCESS);
}
Esempio n. 5
0
inline UINT32 naomi_m1_board::getb(int bits)
{
	UINT32 res = lookb(bits);
	skipb(bits);
	return res;
}