コードレス電話を活用したメール着信表示プログラム
(2000-10-11)

■ ソース

------------------------------------------------------------------------
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>

#define ARRIVE  1
#define NO      0
#define ON      1
#define OFF     0

unsigned char   current_status = NO;
long            mail_size = 0;
char            spool_path[] = {"/var/mail/USER"};

char *DEV = "/dev/cuaa1";
int fd;
int ctrl;
int flags;
int set_bits = 255;

int
get_232status()
{
  int r;
  if ((fd = open(DEV, O_RDWR | O_NDELAY)) < 0) {
    exit(1);
  }
  ioctl(fd, TIOCMSET, &set_bits);
  sleep(5);
  ioctl(fd, TIOCMGET, &flags);
  close(fd);
  if (flags & TIOCM_CD)  {
    r = 1;
  } else {
    r = 0;
    }
  return(r);
}

void
disp_LED(int mailflag)
{
  int tmp;
  int result = 1;
  while(result) {
      tmp = get_232status();
      if(mailflag != tmp) {
        continue;
      }
      result = 0;
    }
}

main(){
  int mailflag = 1;
  struct stat     file_stat;

  if ((stat(spool_path, &file_stat) == 0) && (file_stat.st_size != 0)) {
    /* There are Mail */
    if (current_status == NO) {
      /* NEW mail !! */
      current_status = ARRIVE;
      mail_size = file_stat.st_size;
      disp_LED(ON);
    }
  } else {
    disp_LED(OFF);
  }
}

-- EOF ---------------------------------------------------------------------------