示例#1
0
int main ()
{
    int32_t fd, cnt;
    uint8_t buf[SBUFSIZE];
    uint8_t search[BUFSIZE];

    if (0 != ece391_getargs (search, BUFSIZE)) {
        ece391_fdputs (1, (uint8_t*)"could not read argument\n");
        return 3;
    }

    if (-1 == (fd = ece391_open ((uint8_t*)"."))) {
        ece391_fdputs (1, (uint8_t*)"directory open failed\n");
	return 2;
    }

    while (0 != (cnt = ece391_read (fd, buf, SBUFSIZE-1))) {
        if (-1 == cnt) {
	    ece391_fdputs (1, (uint8_t*)"directory entry read failed\n");
	    return 3;
	}
	if ('.' == buf[0]) /* a directory... */
	    continue;
	buf[cnt] = '\0';
	if (0 != do_one_file ((char*)search, (char*)buf))
	    return 3;
    }

    return 0;
}
示例#2
0
int main ()
{
    int32_t fd, cnt;
    uint8_t buf[1024];

    if (0 != ece391_getargs (buf, 1024)) {
        ece391_fdputs (1, (uint8_t*)"could not read arguments\n");
	return 3;
    }

    if (-1 == (fd = ece391_open (buf))) {
        ece391_fdputs (1, (uint8_t*)"file not found\n");
	return 2;
    }

    while (0 != (cnt = ece391_read (fd, buf, 1024))) {
        if (-1 == cnt) {
	    ece391_fdputs (1, (uint8_t*)"file read failed\n");
	    return 3;
	}
	if (-1 == ece391_write (1, buf, cnt))
	    return 3;
    }

    return 0;
}
示例#3
0
int main ()
{
    uint8_t buf[BUFSIZE];

    if (0 != ece391_getargs (buf, BUFSIZE)) {
	    ece391_fdputs (1, (uint8_t*)"could not read filename\n");
	    return 3;
    }

    if (ece391_soundctrl(CTRL_PLAY_FILE, (int8_t*) buf) < 0) {
	    ece391_fdputs(1, (uint8_t*)"could not play; is something else playing or did you pass a non-existant file?\n");
    }

    return 0;
}
示例#4
0
int32_t
do_one_file (const char* s, const char* fname) 
{
    int32_t fd, cnt, last, line_start, line_end, check, s_len;
    uint8_t data[BUFSIZE+1];

    s_len = ece391_strlen ((uint8_t*)s);
    if (-1 == (fd = ece391_open ((uint8_t*)fname))) {
        ece391_fdputs (1, (uint8_t*)"file open failed\n");
        return -1;
    }
    last = 0;
    while (1) {
        cnt = ece391_read (fd, data + last, BUFSIZE - last);
	if (-1 == cnt) {
            ece391_fdputs (1, (uint8_t*)"file read failed\n");
            return -1;
	}
	last += cnt;
	line_start = 0;
	while (1) {
	    line_end = line_start;
	    while (line_end < last && '\n' != data[line_end])
		line_end++;
	    if ('\n' != data[line_end] && 0 != cnt && line_start != 0) {
		/* copy from line_start to last down to 0 and fix last */
		data[line_end] = '\0';
		ece391_strcpy (data, data + line_start);
		last -= line_start;
		break;
	    }
	    /* search the line */
	    data[line_end] = '\0';
	    for (check = line_start; check < line_end; check++) {
		if (s[0] == data[check] && 
		    0 == ece391_strncmp ((uint8_t*)(data + check), (uint8_t*)s, s_len)) {
		    ece391_fdputs (1, (uint8_t*)fname);
		    ece391_fdputs (1, (uint8_t*)":");
		    ece391_fdputs (1, data + line_start);
		    ece391_fdputs (1, (uint8_t*)"\n");
		    break;
		}
	    }
	    line_start = line_end + 1;
	    if (line_start >= last) {
	        last = 0;
		break;
	    }
	}
	if (0 == cnt)
	    break;
    }
    if (-1 == ece391_close (fd)) {
        ece391_fdputs (1, (uint8_t*)"file close failed\n");
        return -1;
    }
    return 0;
}
示例#5
0
int main ()
{
    int32_t cnt, rval;
    uint8_t buf[BUFSIZE];
    ece391_fdputs (1, (uint8_t*)"Starting 391 Shell\n");

    while (1) {
        ece391_fdputs (1, (uint8_t*)"391OS> ");
	if (-1 == (cnt = ece391_read (0, buf, BUFSIZE-1))) {
	    ece391_fdputs (1, (uint8_t*)"read from keyboard failed\n");
	    return 3;
	}
	if (cnt > 0 && '\n' == buf[cnt - 1])
	    cnt--;
	buf[cnt] = '\0';
	if (0 == ece391_strcmp (buf, (uint8_t*)"exit"))
	    return 0;
	if ('\0' == buf[0])
	    continue;
	rval = ece391_execute (buf);
	if (-1 == rval)
	    ece391_fdputs (1, (uint8_t*)"no such command\n");
	else if (256 == rval)
	    ece391_fdputs (1, (uint8_t*)"program terminated by exception\n");
	else if (0 != rval)
	    ece391_fdputs (1, (uint8_t*)"program terminated abnormally\n");
    }
}
示例#6
0
int main ()
{
    uint32_t i, cnt, max = 0;
    uint8_t buf[BUFSIZE];

    ece391_fdputs(1, (uint8_t*)"Enter the Test Number: (0): 100, (1): 10000, (2): 100000\n");
    if (-1 == (cnt = ece391_read(0, buf, BUFSIZE-1)) ) {
        ece391_fdputs(1, (uint8_t*)"Can't read the number from keyboard.\n");
     return 3;
    }
    buf[cnt] = '\0';

    if ((ece391_strlen(buf) > 2) || ((ece391_strlen(buf) == 1) && ((buf[0] < '0') || (buf[0] > '2')))) {
        ece391_fdputs(1, (uint8_t*)"Wrong Choice!\n");
        return 0;
    } else {
        switch (buf[0]) {
	        case '0':
                max = 100;
                break;
            case '1':
                max = 10000;
                break;
            case '2':
                max = 100000;
                break;
        }
    }

    for (i = 0; i < max; i++) {
        ece391_itoa(i+1, buf, 10);
        ece391_fdputs(1, buf);
        ece391_fdputs(1, (uint8_t*)"\n");
    }

    return 0;
}