--- embedtools/src/pceng.c 2011/07/22 15:03:30 1.1.2.5 +++ embedtools/src/pceng.c 2011/07/23 23:41:00 1.1.2.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: pceng.c,v 1.1.2.5 2011/07/22 15:03:30 misho Exp $ + * $Id: pceng.c,v 1.1.2.7 2011/07/23 23:41:00 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -94,8 +94,11 @@ int main(int argc, char **argv) { char ch, ledno; - int i, io, ret = 0, mode = 1; + int i, ret = 0, mode = 1; struct sigaction sact; +#ifdef HAVE_IO + int io; +#endif while ((ch = getopt(argc, argv, "vhDc:")) != -1) switch (ch) { @@ -115,32 +118,38 @@ main(int argc, char **argv) } argc -= optind; argv += optind; + if (argc && argc % 2) { + printf("Error:: not enough parameters ...\n"); + return 1; + } if (!mode) openlog("pceng", LOG_CONS | LOG_PID, LOG_DAEMON); else openlog("pceng", LOG_CONS | LOG_PID | LOG_PERROR, LOG_USER); - io = open(_PATH_DEVIO, O_RDWR); +#ifdef HAVE_IO + io = open(_PATH_DEVIO, O_RDONLY); if (io == -1) { printf("Error:: in open dev %s #%d - %s\n", _PATH_DEVIO, errno, strerror(errno)); ret = 2; goto end; } +#endif - if (argc > 1 && !(argc % 2)) { + if (LoadConfig(szConf, &cfg)) { + printf("Error:: #%d - %s\n", cfg_GetErrno(), cfg_GetError()); + ret = 1; + return 1; + } + + if (argc) { + VERB(1) syslog(LOG_WARNING, "LED client ..."); for (i = 0; !ret && i < argc; i += 2) { ledno = (char) strtol(argv[i], NULL, 0); ch = (char) strtol(argv[i + 1], NULL, 0); - ret = LED(io, (u_char) ledno, (u_char) ch); + ret = LED((u_char) ledno, (u_char) ch); } - if (ret) - goto end; - } - - if (LoadConfig(szConf, &cfg)) { - printf("Error:: #%d - %s\n", cfg_GetErrno(), cfg_GetError()); - ret = 1; goto end; } @@ -175,12 +184,14 @@ main(int argc, char **argv) goto end; } - ret = Run(io); + ret = Run(); end: UnloadConfig(&cfg); +#ifdef HAVE_IO if (io > 2) close(io); +#endif closelog(); return ret; }