#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <unistd.h> 

#define BASEPORT 0x378

union statusport
  {
  unsigned char byte;
  struct status 
     {
     unsigned int unused:3; // Bit 0-2 nicht verwendet 
     unsigned int fehler:1; // 0 = Error
     unsigned int online:1; // 1 = Drucker online        
     unsigned int papier:1; // 1 = kein Papier           
     unsigned int ack:1;    // 1 = Ack     
     unsigned int busy:1;   // 1 = Busy
     } bit;
  } statusport;

int main(void)
   {
   /* Port freischalten */
   if (ioperm(BASEPORT, 3, 1)) 
      { perror("Error: cannot access ioport"); exit(255); } 
   
   /* Get status port */
   statusport.byte = inb(BASEPORT + 1);
   
   if(statusport.bit.busy && statusport.bit.online) 
     {
     printf("Drucker ist bereit!\n");
     ioperm(BASEPORT, 3, 0);
     return 0;
     }
   else if(!statusport.bit.online)
      printf("Drucker nicht online!\n");
   else if(statusport.bit.papier)
      printf("Kein Papier vorhanden!\n");
   else
      printf("Drucker ist nicht bereit!\n");
   ioperm(BASEPORT, 3, 0);
   return 1;
   }

