/*
 * Simple parallel port output control program for Linux
 * Written and copyright by Tomi Engdahl 1998
 * (e-mail: tomi.engdahl@hut.fi)
 * 
 * hacked without permission by Steve Pomeroy <steve_x@earthling.net>
 * to read from stdin
 *
 * compile with:
 * gcc -O2 stdinlpt.c -o stdinlpt
 *
 * The program output the data value to PC parallel port data pins
 * (default lpt1 I/O address 0x378). The data values are given
 * through stdin, one byte per line. The number can be
 * in decimal (0..255).
 *
 */

#include <stdio.h>
#include <asm/io.h>

#define base 0x378           /* printer port base address */
/* #define base 0x3bc           /* printer port base address */

main()
{
  int value;
  char *inbuf;

  if (ioperm(base,1,1))
    fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);
  do{
    fgets(inbuf,4,stdin);            // read a byte from stdin
    sscanf(inbuf,"%i",&value);       // then convert it to a number
    if(value < 0 || value > 255)     // bound checking
      fprintf(stderr, "Error: Value %i is invalid\n", base),exit(1);
    outb((unsigned char)value, base);  // write the data in value to port base
  }
while(!feof(stdin));
}                                            
