Esempio n. 1
0
void be_bc(int todc[2], int fromdc[2])
/*
 *	read from stdin and convert into to RPN, send down pipe
 *	then read from other pipe and print to user
 *	Uses fdopen() to convert a file descriptor to a stream
 */
{
	FILE	*fpout, *fpin, *fdopen();
	char	buf[BUFSIZ];

	/* setup */
	close(todc[0]);			/* won't read from pipe to dc  */
	close(fromdc[1]);		/* won't write to pipe from dc */

	fpout = fdopen( todc[1],   "w" );	/* convert file desc-  */
	fpin  = fdopen( fromdc[0], "r" );	/* riptors to streams  */
	if ( fpout == NULL || fpin == NULL )
		fatal("Error convering pipes to streams");

	/* main loop */
	while( read_and_translate(stdin, fpout) > 0 ){
		if ( fgets( buf, BUFSIZ, fpin ) == NULL )
			break;
		fputs(buf,stdout);
	}
	fclose(fpout);		/* close pipe		*/
	fclose(fpin);		/* dc will see EOF	*/
}
Esempio n. 2
0
int main(void) {
	char *devpath = find_keyboard();
	if (devpath != NULL) {
		printf("keyboard located at '%s'\n", devpath);
	}
	else {
		fprintf(stderr, "no keyboard found\n");
		return 1;
	}
	int fd = open(devpath, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "could not open devfile\n");
		return 1;
	}

	kbd_t kbd = { .fd = fd, .keymap = DVORAK_WITH_ESC };
	while (true) {
		int kv = read_and_translate(NULL, 0, &kbd);
		putchar(kv);
	}
}
Esempio n. 3
0
void compile_only()
{
	while( read_and_translate(stdin,stdout) > 0 )
		;
}