From: ian Date: Mon, 9 Aug 2004 21:14:20 +0000 (+0000) Subject: train-pic-prog-select X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=16efb377f22cb6d68e277a4a98811b521b76160e;p=trains.git train-pic-prog-select --- diff --git a/parport/.cvsignore b/parport/.cvsignore index af0105d..1d2ba6a 100644 --- a/parport/.cvsignore +++ b/parport/.cvsignore @@ -1 +1,2 @@ parport-ctl +train-pic-prog-select diff --git a/parport/Makefile b/parport/Makefile index 4be6f6a..105c3e0 100644 --- a/parport/Makefile +++ b/parport/Makefile @@ -2,4 +2,4 @@ CFLAGS= -Wall -Wwrite-strings -Wpointer-arith \ -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes \ -O2 -targets: parport-ctl +targets: parport-ctl train-pic-prog-select diff --git a/parport/train-pic-prog-select.c b/parport/train-pic-prog-select.c new file mode 100644 index 0000000..c10229a --- /dev/null +++ b/parport/train-pic-prog-select.c @@ -0,0 +1,107 @@ +/**/ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#define COLUMNS 7 +#define ROWS 8 + +static const void badusage(const char *what) { + fprintf(stderr,"bad usage: %s\n" + "usage: train-pic-prog-select [-p/dev/parport] picno|range...\n" + "ranges are picno-picno (inclusive)\n", + what); + exit(126); +} + +typedef unsigned char yesno; + +const char *parport= "/dev/parport0"; + +static union { + yesno rect[COLUMNS][ROWS]; + yesno lin[COLUMNS*ROWS]; +} yesses; + +static int fd; + +static void doioctl(int ioctlnum, void *vp, unsigned long vpv) { + int r; + errno=0; + r= ioctl(fd, ioctlnum, vp); + if (r) { + fprintf(stderr,"ioctl #%d 0x%lx gave %d %s\n", + ioctlnum, vpv, r, strerror(errno)); + exit(127); + } +} + +static void wpause(int ioctlnum, unsigned char value) { + printf(" %s%02x", + ioctlnum == PPWCONTROL ? "C" : + ioctlnum == PPWDATA ? "" : 0, + value); + doioctl(ioctlnum, &value, value); + usleep(5000); +} + +int main(int argc, const char *const *argv) { + long first, last; + int row, col, v; + char *ep; + const char *arg; + + if (!*argv++) badusage("need argv[0]"); + while ((arg= *argv) && arg[0]=='-') { + argv++; + if (arg[1]=='p') { + parport= arg+2; + } else { + badusage("unknown option"); + } + } + if (!*argv) badusage("need to specify pics"); + while ((arg= *argv++)) { + first= last= strtol(arg,&ep,10); + if (ep==arg) badusage("syntactically incorrect pic number"); + if (*ep == '-') { + last= strtol((arg=ep+1),&ep,10); + if (ep==arg) badusage("syntactically incorrect range"); + } + if (*ep) badusage("syntactically incorrect picno or range"); + if (first<0 || last>COLUMNS*ROWS-1 || first