int get_opts(int argc, char *argv[], struct wldbg_options *opts) { int n = 1; for (; n < argc; ++n) { /* separator */ if (strcmp("--", argv[n]) == 0) { ++n; break; } /* options */ if (is_prefix_of("--", argv[n])) { if (!set_opt(argv[n] + 2, opts)) return -1; } else if (is_prefix_of("-", argv[n])) { /* -g is a synonym for objinfo */ if (argv[n][1] == 'g' && argv[n][2] == 0) { /* objinfo */ set_opt("objinfo", opts); continue; } if (!set_opt(argv[n] + 1, opts)) return -1; } else break; } dbg("Passes or programs are starting at %d\n", n); /* return how many options we have */ return n; }
int cmd_config(int argc,char **argv,struct sub_command* cmd) { char* home=configdir(); char* path=cat(home,"config",NULL); if(argc==1) { printf("oneshot:\n"); print_opts(local_opt); printf("local:\n"); print_opts(global_opt); }else { struct opts* opt=global_opt; struct opts** opts=&opt; // TBD parse options if(argc==2) { unset_opt(opts, argv[1]); save_opts(path,opt); }else { if(strcmp(argv[1],"set")==0) { set_opt(opts, argv[2],(char*)argv[3],0); save_opts(path,opt); }else if (strcmp(argv[1],"show")==0) { printf("%s\n",_get_opt(opt,argv[2])); }else { set_opt(opts, argv[1],(char*)argv[2],0); save_opts(path,opt); } } } s(home),s(path); return 0; }
static void copyprefs(void) { int button; /* Set states of appropriate options buttons */ set_opt(copyoptions, options.cprefs, CF_COPY, CCOPY); set_opt(copyoptions, options.cprefs, CF_DEL, CDEL); set_opt(copyoptions, options.cprefs, CF_OVERW, COVERW); set_opt(copyoptions, options.cprefs, CF_PRINT, CPRINT); /* DjV 031 010203 */ /* set_opt(copyoptions, options.cprefs, CF_KEEP, CKEEP); DjV 016 140203 nothing done yet */ itoa(options.bufsize, copybuffer, 10); button = xd_dialog(copyoptions, 0); if (button == COPTOK) /* selected OK ? */ { /* Get new states of options buttons and new copy buffer size */ get_opt( copyoptions, &options.cprefs, CF_COPY, CCOPY ); get_opt( copyoptions, &options.cprefs, CF_DEL, CDEL ); get_opt( copyoptions, &options.cprefs, CF_OVERW, COVERW ); get_opt( copyoptions, &options.cprefs, CF_PRINT, CPRINT ); /* DjV 031 010203 */ /* get_opt( copyoptions, &options.cprefs, CF_KEEP, CKEEP ); DjV 016 140203 nothing done about thio yet */ if ((options.bufsize = atoi(copybuffer)) < 1) options.bufsize = 1; } }
/* ------------------------------------------------------------- ** ** Functions to read / parse the config file. ** ------------------------------------------------------------- */ int process_cmdline(int argc, char *argv[]) { int i; struct option_array *opt; sstr *arg; char *optp, *argp; set_defaults(); if (argc <= 1) return 0; arg = sstr_init(0); i = 1; optp = argv[i] + 1; while (i < argc) { if (argv[i][0] != '-') usage(-1); opt = opts; if (*optp == '-') usage(-1); /*?TODO longopts */ else { while (opt->name != NULL && opt->cmdline != *optp) opt++; if (opt->name == NULL) usage(*optp); if (strlen(cmdline_set) < 99) cmdline_set[strlen(cmdline_set)] = *optp; if (opt->type == BOOL) { sstr_cpy2(arg, "yes"); set_opt(opt, arg); if (*(++optp) == 0) { i++; optp = argv[i] + 1; } } else { argp = optp + 1; if (*argp == 0) { if (i >= argc - 1 || *(argp = argv[++i]) == '-') usage(*optp); } sstr_cpy2(arg, argp); set_opt(opt, arg); i++; optp = argv[i] + 1; } } } sstr_free(arg); return (0); }
static int parse_options(struct f2fs_sb_info *sbi, char *options) { substring_t args[MAX_OPT_ARGS]; char *p; if (!options) return 0; while ((p = strsep(&options, ",")) != NULL) { int token; if (!*p) continue; token = match_token(p, f2fs_tokens, args); switch (token) { case Opt_gc_background_off: clear_opt(sbi, BG_GC); break; case Opt_disable_roll_forward: set_opt(sbi, DISABLE_ROLL_FORWARD); break; case Opt_discard: set_opt(sbi, DISCARD); break; case Opt_noheap: set_opt(sbi, NOHEAP); break; #ifdef CONFIG_F2FS_FS_XATTR case Opt_nouser_xattr: clear_opt(sbi, XATTR_USER); break; #else case Opt_nouser_xattr: pr_info("nouser_xattr options not supported\n"); break; #endif #ifdef CONFIG_F2FS_FS_POSIX_ACL case Opt_noacl: clear_opt(sbi, POSIX_ACL); break; #else case Opt_noacl: pr_info("noacl options not supported\n"); break; #endif default: return -EINVAL; } } return 0; }
static void default_options(struct f2fs_sb_info *sbi) { /* init some FS parameters */ sbi->active_logs = NR_CURSEG_TYPE; set_opt(sbi, BG_GC); set_opt(sbi, INLINE_DATA); #ifdef CONFIG_F2FS_FS_XATTR set_opt(sbi, XATTR_USER); #endif #ifdef CONFIG_F2FS_FS_POSIX_ACL set_opt(sbi, POSIX_ACL); #endif }
int main(void) { int fd; int nread; char buff[10]; char testbf[] = {"abcde"}; int ntestbf = 5; memset(buff, 0, 10); if ((fd = open_port()) < 0) { perror("open_port error"); return -1; } if (set_opt(fd, 9600, 8, 'N', 1) < 0) { perror("set_opt error"); return -1; } printf("fd = %d\n", fd); while(1) { nread = read(fd, buff, 10); printf("nread = %d\n", nread); tcflush(fd, TCIFLUSH); if (nread > 0) printf("result: %d %s\n", nread, buff); //memset(buff, 0, sizeof(buff)); //write(fd, buff, nread); write(fd, testbf, ntestbf); sleep(1); tcflush(fd, TCOFLUSH); } close(fd); return 0; }
/* parse_line Parses a line from the config file. Lines must be of the form "option-name[whitespace]value[\n]" We're kinda restrictive for now, but the options are so simple that we shouldn't need anything complex for now. Returns -1 on error, 0 otherwise. */ static int parse_line(char *line) { char *opt = line, *val, *p; p = strchr(line, '\n'); /* Strip the trailing newline. */ if(p != NULL) *p = '\0'; /* Seperate the value from the option. */ val = opt; while(!isspace(*val)) { val++; if(*val == '\0') { io_err("Missing value for '%s'!'\n", opt); return -1; } } *val = '\0'; val++; while(isspace(*val)) { val++; if(*val == '\0') { io_err("Missing value for '%s'!'\n", opt); return -1; } } if(is_default_opt(opt) && !parsed_yet) return set_opt(opt, val); return 0; }
int main() { int fd; int nread; char command[256]; char buf; int nset; fd = open("/dev/ttySAC1", O_RDONLY); if (fd == -1) { printf("open failed\n"); exit(1); } nset = set_opt(fd, 4800, 8, 'N', 1); if (nset == -1) { printf("set_opt failed\n"); exit(1); } memset(command, '\0', 256); while (1) { nread = read(fd, &buf, 1); if (nread > 0) { concat_command(command, buf); if (buf == 'q') break; } } close(fd); return (0); }
int main(void) { int fd; int nwrite, i; char buff[] = "Hello\n"; /*打开串口*/ if((fd = open_port(fd, 1))<0){ perror("open_port error"); return; } /*对串口进行设置*/ if((i = set_opt(fd, 115200, 8, 'N', 1))<0){ perror("set_opt error"); return; } printf("fd=%d\n",fd); /*对串口进行写操作*/ for(i = 0; i < 20; i++){ nwrite = write(fd, buff, 6); printf("nwrite=%d,%s\n", nwrite, buff); sleep(1); } close(fd); return; }
int parse_line(sstr * buf) { struct option_array *opt; sstr *tok; tok = sstr_init(0); if (sstr_getchar(buf, 0) == '#') return (0); if (sstr_token(buf, tok, " =\t\r\n", 0) == -1) return (0); if (!sstr_casecmp2(tok, "EndSection")) return (sublevel > 0 ? 1 : -1); opt = opts; while (opt->name != NULL && sstr_casecmp2(tok, opt->name)) opt++; if (opt->name == NULL) { fprintf(stderr,"Unrecognised option \"%s\" at line %d of %s\n", sstr_buf(tok), line_no, config.config_file); return (-1); } if (opt->cmdline && strchr(cmdline_set, opt->cmdline)) { fprintf(stderr, "\"%s\" specified on the command line: ignored\n", opt->name); return (0); } if (set_opt(opt, buf) == -1) { fprintf(stderr, "Invalid argument to %s at line %d of %s\n", opt->name, line_no, config.config_file); return (-1); } return (0); }
int main(void) { int fd; int nread; char buff[10]; if((fd=open_port(0))<0) { perror("open_port error"); return; } if(set_opt(fd,115200,8,'N',1)<0) { perror("set_opt error"); return; } printf("fd=%d\n",fd); int i; while(1) { memset(buff,'\0',sizeof(buff)); if((nread=read(fd,buff,11)) != 0) { // for(i=0;i<4;i++) printf("nread=%d,%u,%d,%s\n",nread,*((unsigned int*)buff),buff,buff); } else printf("hehe\n"); } close(fd); return; }
void Options::set_opt ( const QString &opt, const QList<int> &val ) { QStringList vals; for (QList<int>::const_iterator itVal = val.begin(); itVal != val.end(); ++itVal ) vals << QString::number( *itVal ); set_opt( opt, vals ); }
int main(void) { int fd1,fd2,nset1,nset2,nread; char buf; char buff[256]; fd2 = open("/dev/ttySAC1", O_RDONLY); // fd2 = open( "/home/junhan/Desktop/part4/test1", O_RDWR); //for ok6410-B GPS module if (fd2 == -1) exit(1); nset2 = set_opt(fd2, 4800, 8, 'N', 1); if (nset2 == -1) exit(1); //使用的时候取消注释 memset(buff, '\0', 256); while(1) { nread = read(fd2, &buf, 1); if(nread > 0){ concat_command(buff,buf); if(buf == 'q') break; } } close(fd2); return 0; }
void Options::save_window_position( const QString &name, const QWidget *widget_p ) { bool maximized ; long posx, posy, height, width ; maximized = widget_p->isMaximized(); posx = widget_p->x(); posy = widget_p->y(); height = widget_p->height(); width = widget_p->width(); set_opt( "WIDGET_POS_" + name + "_MAXIMIZED", maximized ); set_opt( "WIDGET_POS_" + name + "_X", posx ); set_opt( "WIDGET_POS_" + name + "_Y", posy ); set_opt( "WIDGET_POS_" + name + "_WIDTH", width ); set_opt( "WIDGET_POS_" + name + "_HEIGHT", height ); }
MyPrint::MyPrint() { //int num; if (num=set_opt()<0){ printf("set_opt error"); //return -1; } }
void Serial_Init(void) { SerFd_1 = open("/dev/ttySAC0",O_RDWR|O_NOCTTY|O_NDELAY); if(0 < SerFd_1){ set_opt(SerFd_1,B115200,DATA_BIT_8,PARITY_NONE,STOP_BIT_1); printf("open /dev/ttySAC0 is ok \n"); }else{ printf("open /dev/ttySAC0 error \n"); } SerFd = open("/dev/ttySAC1",O_RDWR|O_NOCTTY|O_NDELAY); if(0 < SerFd){ set_opt(SerFd,B115200,DATA_BIT_8,PARITY_NONE,STOP_BIT_1); printf("open /dev/ttySAC1 is ok \n"); }else{ printf("open /dev/ttySAC1 error \n"); } }
static Cmdret conf_setting(List *args, Cmdarg *ca) { log_msg("CONFIG", "conf_setting"); char *name = list_arg(args, 1, VAR_STRING); Token *oper = tok_arg(args, 2); Token *rhs = tok_arg(args, 3); if (!name|| !oper || !rhs) return NORET; char *value = cmdline_line_from(ca->cmdline, 3); set_opt(name, value); return NORET; }
void *pthread_ck2316_alarm(void *arg) { int com_fd; int recv_ret = 0; //unsigned char recv_buffer[72] = {0}; while (1) { recv_ret = ck2316_alarm_init(); if (recv_ret == -1) { printf("FUNC[%s] LINE[%d]\tCK2316 alarm init failed!\n",__FUNCTION__, __LINE__); sleep(10); } else break; } while (1) { com_fd = OpenDev(CK2316_UART_DEVICE); if (com_fd == -1) { printf("FUNC[%s] LINE[%d]\tOpen uart failed!\n",__FUNCTION__, __LINE__); sleep(10); continue; } //fd nSpeed nBits nEvent nStop) //set_opt(com_fd, 2400, 3, 2, 0); //for ck2316 //recv_ret = set_opt(com_fd, 9600, 3, 0, 0); //for ck2316 //recv_ret = set_opt(com_fd, CK2316_UART_BOARD, CK2316_UART_DATA_BIT, CK2316_UART_CHECK_BIT, CK2316_UART_STOP_BIT); recv_ret = set_opt(com_fd, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.dwBaudRate, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byDataBit, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byParity, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byStopBit); if (recv_ret == -1) { printf("FUNC[%s] LINE[%d]\tInit uart failed!\n",__FUNCTION__, __LINE__); sleep(10); continue; } ClrCom(com_fd); recv_ret = ck2316_alarm_handshake_and_setup(&com_fd); if (recv_ret == -1) { close(com_fd); sleep(10); } } return (void *)1; }
void Options::save_window_position( const QMdiArea *workspace_p ) { QList<QMdiSubWindow *> windows = workspace_p->subWindowList( QMdiArea::StackingOrder ); QMdiSubWindow *mdi_subwindow_p; long nb_widget = windows.count(); set_opt( "WIDGET_NB_WIDGET", nb_widget ); int id = 0; for ( QList<QMdiSubWindow *>::const_iterator it = windows.begin(); it != windows.end(); ++it ) { mdi_subwindow_p = *it; QString name = "WORKSPACE" + QString::number( id ); OCamlSource *sourceview_p = dynamic_cast<OCamlSource*>( mdi_subwindow_p->widget() ); if ( sourceview_p ) { set_opt( "TYPE_" + name, QString( "SOURCEVIEW" ) ); QString source = sourceview_p->currentFile(); set_opt( "SOURCE_" + name, source ); set_opt( "SOURCE_USER_LOADED_" + name, sourceview_p->fromUserLoaded() ); save_window_position( name, mdi_subwindow_p ); } id++; } }
// 开启通信服务 int CComDev::Start() { if (OpenDev(m_cDev) != TRUE) { return FALSE; } if (set_opt(115200, 8, 'N', 1) != TRUE) { return FALSE; } //开启接收线程 pthread_create(&m_RecvPt, NULL, threadRecv, this); return TRUE; }
int ext2_remount (struct super_block * sb, int * flags, char * data) { struct ext2_super_block * es; unsigned short resuid = sb->u.ext2_sb.s_resuid; unsigned short resgid = sb->u.ext2_sb.s_resgid; unsigned long new_mount_opt; unsigned long tmp; /* * Allow the "check" option to be passed as a remount option. */ set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL); if (!parse_options (data, &tmp, &resuid, &resgid, &new_mount_opt)) return -EINVAL; sb->u.ext2_sb.s_mount_opt = new_mount_opt; sb->u.ext2_sb.s_resuid = resuid; sb->u.ext2_sb.s_resgid = resgid; es = sb->u.ext2_sb.s_es; if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) return 0; if (*flags & MS_RDONLY) { if (es->s_state & EXT2_VALID_FS || !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS)) return 0; /* * OK, we are remounting a valid rw partition rdonly, so set * the rdonly flag and then mark the partition as valid again. */ es->s_state = sb->u.ext2_sb.s_mount_state; es->s_mtime = CURRENT_TIME; mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1); sb->s_dirt = 1; ext2_commit_super (sb, es); } else { /* * Mounting a RDONLY partition read-write, so reread and * store the current valid flag. (It may have been changed * by e2fsck since we originally mounted the partition.) */ sb->u.ext2_sb.s_mount_state = es->s_state; sb->s_flags &= ~MS_RDONLY; ext2_setup_super (sb, es); } return 0; }
int Serial::init() { SerFd = -1; SerFd = open("/dev/ttyUSB0", O_RDWR|O_NOCTTY|O_NDELAY); if (0 < SerFd) { set_opt(SerFd, BAUD_2400, DATA_BIT_8, PARITY_NONE, STOP_BIT_1); } else { printf("open_port ERROR !\n"); return -1; } return 0; }
int set_para() { int set_serial; fd_gps = open(dev_path,O_RDWR|O_NONBLOCK); if(-1 == fd_gps ) { perror("Error opening gps device\n"); return -1; } set_serial = set_opt(fd_gps,9600,8,'N',1); //set serial parameters if(-1 == set_serial) { perror("Error setting serial port\n"); return -1; } return 0; }
void *pthread_matrix_control(void *arg) { int com_fd; int recv_ret = 0; //unsigned char send_buffer[] = {0xBB, 0x00, 0x06, 0x02}; while (1) { com_fd = OpenDev(MATRIX_UART_DEVICE); if (com_fd == -1) { printf("FUNC[%s] LINE[%d]\tOpen uart failed!\n",__FUNCTION__, __LINE__); sleep(10); continue; } //fd nSpeed nBits nEvent nStop) //recv_ret = set_opt(com_fd, 9600, 3, 0, 0); //for matrix recv_ret = set_opt(com_fd, MATRIX_UART_BOARD, MATRIX_UART_DATA_BIT, MATRIX_UART_CHECK_BIT, MATRIX_UART_STOP_BIT); if (recv_ret == -1) { printf("FUNC[%s] LINE[%d]\tInit uart failed!\n",__FUNCTION__, __LINE__); sleep(10); continue; } ClrCom(com_fd); #if 0 while (1) { send_buffer[2] = 0x07; printf("1\n"); write(com_fd, send_buffer, 4); sleep(2); } #endif recv_ret = matrix_handshake_and_setup(&com_fd); if (recv_ret == -1) { close(com_fd); sleep(10); } } return (void *)1; }
int main(void) { int fd1, nset1, nread; char buf[1024]; int i; int fdFileSave = 0; if ((fdFileSave = open(fileSave, O_WRONLY | O_CREAT | O_APPEND)) == -1) { printf("Open %s Error\n", fileSave); exit(1); } //fd1 = open("/dev/ttyACM0", O_RDWR|O_NONBLOCK);//打开串口 fd1 = open("/dev/ttyS1", O_RDWR | O_NONBLOCK);//打开串口 if (fd1 == -1) exit(1); nset1 = set_opt(fd1, 9600, 8, 'N', 1);//设置串口属性 if (nset1 == -1) exit(1); while (1) { memset(buf, 0, 1024); nread = read(fd1, buf, 1024);//读串口 write(fdFileSave, buf, nread);//将数据保存在文件fdFileSave 即"fileSave.txt" if (nread > 0){ printf("\nGPS DATALen=%d\n", nread); buf[nread] = '\0'; printf("GPS\n"); /*for (i = 0; i < nread; i++){ printf("%c", buf[i]); }*/ printf("%s\n", buf); //输出所读数据 } sleep(5);//睡眠,等待数据多一点 } close(fd1); return 0; }
/*************************初始化输出视频*************************/ int init_output(const videoFile* inVideo,const char* filename,videoFile* pOutVideo) { pOutVideo->video_st = av_new_stream(pOutVideo->pFormatCtx, 0); if (pOutVideo->video_st==NULL) { return -1; } AVOutputFormat* fmt = pOutVideo->pFormatCtx->oformat; pOutVideo->pCodecCtx = pOutVideo->video_st->codec; pOutVideo->pCodecCtx->codec_id = fmt->video_codec; pOutVideo->pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; pOutVideo->pCodecCtx->pix_fmt=PIX_FMT_YUV420P; pOutVideo->pCodecCtx->width = inVideo->pCodecCtx->width; pOutVideo->pCodecCtx->height = inVideo->pCodecCtx->height; pOutVideo->pCodecCtx->time_base.num = 1; pOutVideo->pCodecCtx->time_base.den =25; //pOutVideo->pCodecCtx->bit_rate = inVideo->pCodecCtx->bit_rate; //pOutVideo->pCodecCtx->gop_size=inVideo->pCodecCtx->gop_size; //pOutVideo->pCodecCtx->qmin = inVideo->pCodecCtx->qmin; //pOutVideo->pCodecCtx->qmax = inVideo->pCodecCtx->qmax; //pOutVideo->pCodecCtx->qcompress = 0; //pOutVideo->pCodecCtx->max_b_frames=0; //H264 pOutVideo->pCodecCtx->me_range=1; pOutVideo->pCodecCtx->max_qdiff = 4; av_opt_set_defaults(&pOutVideo->pCodecCtx->priv_data); AVDictionary* codec_options=NULL; set_opt(&codec_options); pOutVideo->pCodec = avcodec_find_encoder(AV_CODEC_ID_H264); if (avcodec_open2(pOutVideo->pCodecCtx, pOutVideo->pCodec,&codec_options) < 0) { fprintf(stderr,"编码器打开失败!\n"); return -1; } //av_opt_set(pOutVideo->pCodecCtx->priv_data, "preset","ultrafast", 0); //av_opt_set_defaults(pOutVideo->pCodecCtx->priv_data); }
int main(void){ int fd; int nread, i; char buff[] = "Hello\n"; if((fd = open_port(fd,1))<0){ perror("open_port error"); return; } if((i = set_opt(fd,115200,8,'N',1)) < 0){ perror("set_opt error"); return; } printf("fd=%d\n",fd); // fd=3; nread = read(fd, buff, 8); printf("nread=%d,%s\n", nread, buff); close(fd); return; }
int main(int ac, char **av) { t_sys sys; set_opt(&sys, ac, av); init_sys(&sys, av[2]); if (test_solv(&sys)) { print_list(&sys, sys.open); printf("This Puzzle is not solvable\n"); exit(0); } if (sys.size > 3) run_ida_star(&sys); else run_a_star(&sys); printf("Time complexity: %d\n", sys.time_complexity); printf("Size complexity: %d\n", sys.size_complexity); return (0); }
int cmd_script(int argc,char **argv,struct sub_command* cmd) { char* current=get_opt("program",0); cond_printf(1,"script_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]); cond_printf(1,"current=%s\n",current); if(argc==1 && !current && strcmp(argv[0],"--")==0) { char* tmp[]={"help","--"}; return proccmd(2,tmp,top_options,top_commands); }else { char* result=q(""); char* tmp[]={"script"}; int i=strcmp(argv[0],"--")==0?1:0; for (;i<argc;++i) { char* val=escape_string(argv[i]); result=cat(result,"\"",val,"\"",NULL); s(val); } set_opt(&local_opt,"script",result,0); s(result); cmd_run_star(1,tmp,cmd); } return 0; }