int main(int argc, char *argv[]) { struct sigaction sa; int ret; sigset_t sigset; int flags; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ perror(options.filename); exit(1); } out_subd = 2; config_output(); fcntl(comedi_fileno(device), F_SETOWN, getpid()); flags = fcntl(comedi_fileno(device),F_GETFL); ret = fcntl(comedi_fileno(device),F_SETFL,flags|O_ASYNC); //ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC); if(ret<0)perror("fcntl"); memset(&sa,0,sizeof(sa)); sa.sa_handler = &sigio_handler; ret = sigaction(SIGIO,&sa,NULL); if(ret<0)perror("sigaction"); sigemptyset(&sigset); sigaddset(&sigset,SIGIO); ret = sigprocmask(SIG_UNBLOCK,&sigset,NULL); if(ret<0)perror("sigprocmask"); #if 0 { struct sched_param p; memset(&p,0,sizeof(p)); p.sched_priority = 1; ret = sched_setscheduler(0,SCHED_FIFO,&p); if(ret<0)perror("sched_setscheduler"); } #endif do_cmd_1(device, options.subdevice); return 0; }
static int console_config(struct simio_device *dev, const char *param, char **arg_text) { struct console *c = (struct console *)dev; if (!strcasecmp(param, "base")) { return config_addr(&c->base_addr, arg_text); } else if (!strcasecmp(param, "output")) { return config_output(&c->file, arg_text); } printc_err("console: config: unknown parameter: %s\n", param); return -1; }
int main(int argc, char *argv[]) { int ret; comedi_cmd cmd; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ perror(options.filename); exit(1); } out_subd = 0; config_output(); ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC); if(ret<0)perror("fcntl"); #if 0 { struct sched_param p; memset(&p,0,sizeof(p)); p.sched_priority = 1; ret = sched_setscheduler(0,SCHED_FIFO,&p); if(ret<0)perror("sched_setscheduler"); } #endif prepare_cmd(device, &cmd, options.subdevice); do_cmd(device,&cmd); return 0; }
int main(int argc, char **argv) { int c; char *blkszptr; char **path_argv; char *default_dot_path[] = {".", NULL}; struct winsize win; FTS* ftsptr; FTSENT *argv_list; FTSENT *cur; FTSENT *read; int fts_options = FTS_PHYSICAL; int (* comp)(const FTSENT** obj1, const FTSENT** obj2); /* * get term width * refers to NetBSD's implementation */ if (isatty(STDOUT_FILENO)) { if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&win.ws_col > 0) { win_width = win.ws_col; } } comp = sortbyname; setprogname(argv[0]); /* some default setting */ if (isatty(STDOUT_FILENO)) { all_flags.qflag = 1; all_flags.Cflag = 1; } else { all_flags.wflag = 1; all_flags.oneflag = 1; } /*-A always set for super user*/ if (getuid() == 0) { all_flags.Aflag = 1; } while( (c = getopt(argc, argv, "AacdFfhiklnqRrSstuw1xC")) != -1 ) { switch(c) { case 'A': all_flags.Aflag = 1; break; case 'a': all_flags.aflag = 1; break; case 'd': all_flags.dflag = 1; break; case 'f': comp = NULL; all_flags.fflag = 1; break; case 'F': all_flags.Fflag = 1; break; case 'R': all_flags.Rflag = 1; break; case 'i': all_flags.iflag = 1; break; case 'l': //overwrite all_flags.nflag = 0; all_flags.oneflag = 0; all_flags.Cflag = 0; all_flags.xflag = 0; all_flags.lflag = 1; break; case 'n': //overwrite all_flags.lflag = 0; all_flags.oneflag = 0; all_flags.Cflag = 0; all_flags.xflag = 0; all_flags.nflag = 1; break; case 's': all_flags.sflag = 1; break; case 'S': comp = sortbysize; all_flags.Sflag = 1; break; case 'q': all_flags.wflag = 0; all_flags.qflag = 1; break; case 'w': all_flags.qflag = 0; all_flags.wflag = 1; break; case 't': comp = sortbytime; all_flags.tflag = 1; break; case '1': all_flags.lflag = 0; all_flags.nflag = 0; all_flags.oneflag = 1; break; case 'c': all_flags.uflag = 0; all_flags.cflag = 1; break; case 'x': //overwirte all_flags.oneflag = 0; all_flags.lflag = 0; all_flags.nflag = 0; all_flags.Cflag = 0; all_flags.xflag = 1; break; case 'C': //overwrite all_flags.oneflag = 0; all_flags.lflag = 0; all_flags.nflag = 0; all_flags.xflag = 0; all_flags.Cflag = 1; break; case 'u': all_flags.cflag = 0; all_flags.uflag = 1; break; case 'k': all_flags.hflag = 0; all_flags.kflag = 1; break; case 'h': all_flags.kflag = 0; all_flags.hflag = 1; break; case 'r': all_flags.rflag = 1; break; default: usage(); break; } } argc -= optind; argv += optind; cldlist_init(); path_argv = (argc == 0) ? default_dot_path : argv; /*set block size, blksize_t shall be signed integer*/ if ( (blkszptr = getenv("BLOCKSIZE")) != NULL ) { blocksize = atoi(blkszptr); } else { blocksize = DEFAULT_BLOCKSIZE; } if (all_flags.kflag) { divide_term = 1024; } if (all_flags.aflag) { fts_options = fts_options | FTS_SEEDOT; } if (all_flags.rflag) { if (all_flags.Sflag) { comp = sortbyrsize; } else if (all_flags.tflag) { comp = sortbyrsize; } else { comp = sortbyname; } } if ( (ftsptr = fts_open(path_argv, fts_options, comp)) == NULL) { if (errno != 0) { (void)fprintf(stderr, "%s: fts_open error %s\n", getprogname(), strerror(errno)); exit(EXIT_FAILURE); } } /*the special use case of fts_children, go through all files in the argv list*/ if ( (argv_list = fts_children(ftsptr, 0)) == NULL ) { if (errno != 0) { (void)fprintf(stderr, "%s: fts_open error %s\n", getprogname(), strerror(errno)); exit(EXIT_FAILURE); } } /* * refer to NetBSD implementation * here we handle all `non-directory` files and error, * leave the directory for the fts_read below */ for (cur = argv_list; cur != NULL; cur = cur->fts_link) { if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS || cur->fts_info == FTS_DNR) { warnx("can't access %s: %s",cur->fts_name, strerror(cur->fts_errno)); /* * because error message also consider as an output * `outputnum++` will make the directory to output its path name */ outputnum++; continue; } if (!all_flags.dflag && cur->fts_info == FTS_D) { /*leave the directory to the fts_read below*/ outputnum++; continue; } outputentnum++; outputnum++; cook_entry(cur); } //Parent = NULL means it's at root level traverse_children(NULL); do{ if (all_flags.dflag) { break; } /* * handle the directory entry */ while( (read = fts_read(ftsptr)) != NULL) { unsigned short info = read->fts_info; if (info == FTS_DC) { warnx("%s causes a cycle in the tree ",read->fts_path); continue; } if (info == FTS_DNR || info == FTS_ERR) { warnx("can't access %s: %s",read->fts_path, strerror(read->fts_errno)); continue; } if (info == FTS_D) { FTSENT* childrenptr; childrenptr = fts_children(ftsptr,0); if (childrenptr == NULL && errno != 0) { /* * if error heppen we don't do anything this moment * error will be printed at the postorder visit */ continue; } config_output(childrenptr); // cook_multi_cols(); traverse_children(read); if (!all_flags.Rflag && childrenptr != NULL) { if (fts_set(ftsptr, read, FTS_SKIP) != 0) { (void)fprintf(stderr, "%s: fts_set error %s\n", getprogname(), strerror(errno)); exit(EXIT_FAILURE); } } } } }while(0); if (read == NULL && errno != 0) { (void)fprintf(stderr, "%s: fts_read error %s\n", getprogname(), strerror(errno)); exit(EXIT_FAILURE); } cldlist_clear(); return 0; }