void help(int* tt) /*******************************/ /* Function: helps player */ /* */ /* Parameters: */ /* tt: IN a guess */ /*******************************/ { int z, w ; skipline(1); z = 0; /* Enter the guess you need the hint for */ while (z < 1 || z > cur) { z = 0; format_output("Enter the guess you need the hint for -> ",1); while((*tt = getchar()) != '\n') z = z * 10 + *tt - '0'; } w = 0; /*choose the peg you need the hint for */ while (w < 1 || w > 4) { w = 0; format_output("Which peg of guess",1); printf(" #%d -> ",z); while((*tt = getchar()) != '\n') w = w * 10 + *tt - '0'; } format_output("In guess",1); printf(" #%d,",z); printf("peg #%d received ",w); if (guesses[z - 1].pegs[w - 1].used == BLACK) format_output("a black peg.\n",0); if (guesses[z - 1].pegs[w - 1].used == WHITE) format_output("a white peg.\n",0); if (guesses[z - 1].pegs[w - 1].used == NONE) format_output("no peg.\n",0); skipline(1); }
wmo_message * get_wmo_message(xbuf *buf, wmo_message *mess) { init_wmo_message(buf, mess); #if 0 if(mess->msg == NULL || mess->msg[0] != SOH) return NULL; if(mess->len < MIN_WMO_MSG_LEN) return NULL; #endif /* skip SOH CR CR NL */ if(skipline(buf, 4) < 0) return NULL; if( get_wmo_start(buf, mess->start) == NULL ) return NULL; if( get_wmo_header(buf, mess->hdr) == NULL ) return NULL; #if 0 if(mess->msg[mess->len-1] != ETX ) return NULL; #endif #if 0 /* DEBUG */ fprint_wmo_header(stderr, mess->hdr); fputc(' ', stderr); fprint_wmo_start(stderr, mess->start); fprintf(stderr," \tplen %-7d ok\n", len); #endif return mess; }
int SimpleMixer::parse_output_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler) { int ret; int s[5]; int n = -1; buf = findtag(buf, buflen, 'O'); if ((buf == nullptr) || (buflen < 12)) { debug("output parser failed finding tag, ret: '%s'", buf); return -1; } if ((ret = sscanf(buf, "O: %d %d %d %d %d %n", &s[0], &s[1], &s[2], &s[3], &s[4], &n)) != 5) { debug("out scaler parse failed on '%s' (got %d, consumed %d)", buf, ret, n); return -1; } buf = skipline(buf, buflen); if (buf == nullptr) { debug("no line ending, line is incomplete"); return -1; } scaler.negative_scale = s[0] / 10000.0f; scaler.positive_scale = s[1] / 10000.0f; scaler.offset = s[2] / 10000.0f; scaler.min_output = s[3] / 10000.0f; scaler.max_output = s[4] / 10000.0f; return 0; }
void outrumor(void) { int rn, i; FILE *rumf; if (n_rumors <= n_used_rumors || (rumf = fopen(RUMORFILE, "r")) == (FILE *) 0) return; if (n_used_rumors < 0) init_rumors(rumf); if (!n_rumors) goto none; rn = rn2(n_rumors - n_used_rumors); i = 0; while (rn || used(i)) { (void) skipline(rumf); if (!used(i)) rn--; i++; } usedbits[i / CHARSZ] |= (1 << (i % CHARSZ)); n_used_rumors++; outline(rumf); none: (void) fclose(rumf); }
static fill_stack_t* xyread4f(FILE* stream, char* buf) { fill_stack_t* f; double r, g, b; double z; do if (fgets(buf, BUFSIZE, stream) == NULL) return NULL; while (skipline(buf)); if (sscanf(buf, "%lf %lf %lf %lf", &z, &r, &g, &b) != 4) { btrace("bad line: %s", buf); return NULL; } if ((f = malloc(sizeof(fill_stack_t))) == NULL) return NULL; f->fill.type = fill_colour; f->val = z; f->fill.u.colour.rgb.red = colour8(r); f->fill.u.colour.rgb.green = colour8(g); f->fill.u.colour.rgb.blue = colour8(b); f->next = xyread4f(stream, buf); return f; }
static fill_stack_t* xyread3i(FILE* stream, char* buf, int n) { fill_stack_t* f; int r, g, b; do if (fgets(buf, BUFSIZE, stream) == NULL) return NULL; while (skipline(buf)); if (sscanf(buf, "%d %d %d", &r, &g, &b) != 3) { btrace("bad line: %s", buf); return NULL; } if ((f = malloc(sizeof(fill_stack_t))) == NULL) return NULL; f->fill.type = fill_colour; f->val = n; f->fill.u.colour.rgb.red = r; f->fill.u.colour.rgb.green = g; f->fill.u.colour.rgb.blue = b; f->next = xyread3i(stream, buf, n+1); return f; }
static fill_stack_t* xyread2f(FILE* stream, char* buf) { fill_stack_t* f; double v, d; do if (fgets(buf, BUFSIZE, stream) == NULL) return NULL; while (skipline(buf)); if (sscanf(buf, "%lf %lf", &v, &d) != 2) { btrace("bad line: %s", buf); return NULL; } if ((f = malloc(sizeof(fill_stack_t))) == NULL) return NULL; f->fill.type = fill_grey; f->fill.u.grey = colour8(d); f->val = v; f->next = xyread2f(stream, buf); return f; }
static fill_stack_t* xyread1i(FILE* stream, char* buf, int n) { fill_stack_t* f; int i; do if (fgets(buf, BUFSIZE, stream) == NULL) return NULL; while (skipline(buf)); if (sscanf(buf, "%d", &i) != 1) { btrace("bad line: %s", buf); return NULL; } if ((f = malloc(sizeof(fill_stack_t))) == NULL) return NULL; f->fill.type = fill_grey; f->fill.u.grey = i; f->val = n; f->next = xyread1i(stream, buf, n+1); return f; }
/** * The constructor needs to scan the whole PTX file to find out the bounding box. Unluckily. * TODO: during the scan all the points are read and transformed. Afterwards, during loading * the points are read again and transformed again. It should be nice to save the * transformed points in a temporary file. That would mean a LAS file or something similar. * Unuseful. It's better to convert the PTX to LAS files. * TODO: it seems theat the PTXPointReader is asked to produce the bounding box more than once. * Maybe it should be saved somewhere. Chez moi, scanning 14m points needs 90 secs. The * process speed of the PTX file is about 1m points every 50 secs. */ PTXPointReader::PTXPointReader(string path) { this->path = path; if (fs::is_directory(path)) { // if directory is specified, find all ptx files inside directory for (fs::directory_iterator it(path); it != fs::directory_iterator(); it++) { fs::path filepath = it->path(); if (fs::is_regular_file(filepath)) { if (icompare(fs::path(filepath).extension().string(), ".ptx")) { files.push_back(filepath.string()); } } } } else { files.push_back(path); } // open first file this->currentFile = files.begin(); this->stream = new fstream(*(this->currentFile), ios::in); this->currentChunk = 0; skipline(*this->stream); loadChunk(this->stream, this->currentChunk, this->tr); }
EXPORT BOOL WINAPI xnoteadd( HSPEXINFO *hei, int p1, int p2, int p3 ) { // // xnoteadd "strings" (type$202) // char *buf, *p, *str_to_add; int size; int line; str_to_add = hei->HspFunc_prm_gets(); if (xn_pval->flag!=HSPVAR_FLAG_STR) return -1; buf = (char *)Hsp3GetBlockSize( hei, xn_pval, xn_aptr, &size ); p = buf; line=0; while (*p != '\0') { if (lineeq(p, str_to_add) ) { DataInc(line); return -line; } p = skipline(p); line ++; } addline( hei, xn_pval, xn_aptr, p - buf, str_to_add ); DataInc(line); return -line; }
void error(bsparse_error_s id, ...) { if(!error_callback) return; int line, column; getpos(p, line, column); error_callback(id, geturl(), line, column, (const char**)xva_start(id)); skipline(); }
void toNextValid(unsigned char* buf, unsigned int* index, unsigned int size) { nextnonwhitespace(buf,index,size); while(*index < size && buf[*index]=='/' && buf[(*index) + 1]=='/') { //comment //printf("Found comment at %i\n",*index); skipline(buf,index,size); nextnonwhitespace(buf,index,size); } }
/// gettok - Return the next token from standard input. int lexer::gettok() { // Skip any whitespace. c = skipspace(input, c, line_num); // identifier: [a-zA-Z][a-zA-Z0-9_]* if (isalpha(c)) { str = c; do { c = input->get(); if ( isalnum(c) || c=='_' ) str += c; else break; } while (true); if (unlikely(literal_p(str))) return token_type::literal; else return token_type::identifier; } // Number: [0-9]+([.][0-9]*(eE[+-][0-9]+)*)* if (isdigit(c) || c == '.') { str = ""; do { str += c; c = input->get(); } while (isdigit(c) || c == '.'); if (c == 'E' || c == 'e') { str += 'E'; c = input->get(); if (isdigit(c)) str += '+'; do { str += c; c = input->get(); } while (isdigit(c)); } return token_type::number; } // Comment until end of line. if (c == '#') { c = skipline(input); ++line_num; if (c != EOF) return gettok(); } // Check for end of file. Don't eat the EOF. if (c == EOF) return token_type::eof; // Otherwise, just return the character as its ascii value. int current = c; c = input->get(); return current; }
Gains_t* get_gold(const char* fname, Date_t* adate) { Gains_t *this; FILE *iFile; char /* char */ line[1024] , msgbuf[1024] ; double /* double */ gain1 , gain2 , gain3 , gain4 , gain5 , gain7 , ysl ; int /* int */ dsl , doy , year ; this = (Gains_t*)malloc(sizeof(Gains_t)); iFile= fopen(fname,"r"); if ( !iFile ) { sprintf(msgbuf,"unable to open file %s",fname); ERROR(msgbuf, "get_gold"); } skipline(iFile,2); this->valid_flag= false; while ( mygetline(line,1024,iFile)>=0 ) { sscanf(line,"%d %d %d %lg %lg %lg %lg %lg %lg %lg", &year,&doy,&dsl,&ysl,&gain1,&gain2,&gain3,&gain4,&gain5,&gain7); if ( year == adate->year && doy == adate->doy ) { this->gains[0]= (float)gain1; this->gains[1]= (float)gain2; this->gains[2]= (float)gain3; this->gains[3]= (float)gain4; this->gains[4]= (float)gain5; this->gains[6]= (float)gain7; this->valid_flag= true; break; } } return this; }
static void init_rumors(FILE *rumf) { int i; n_used_rumors = 0; while (skipline(rumf)) n_rumors++; rewind(rumf); i = n_rumors / CHARSZ; usedbits = alloc(i + 1); for (; i >= 0; i--) usedbits[i] = 0; }
void getpos(const char* p, int& line, int& column) { line = 0; column = 0; auto ps = getstart(); while(*ps) { line++; auto pe = skipline(ps); if(p >= ps && p < pe) { column = p - ps + 1; return; } ps = pe; } }
void skipline(FILE *fp) { int ch; while( (ch = fgetc(fp)) != '\n') if(ch == EOF) return; ch = fgetc(fp); if(ch == '#') { skipline (fp); } else { ungetc(ch, fp); } }
const char * wmo_err_ident(xbuf *buf) { static char identbuf[128]; char *cp = identbuf; xbuf clone[1]; int conv; (void) memset(identbuf, 0, sizeof(identbuf)); clone_xbuf(buf, clone, 0); #if 0 conv = sprintf(cp, "%8u ******************", (unsigned) clone->cnt); #else conv = sprintf(cp, "%8u", (unsigned) clone->cnt); #endif cp += conv; /* skip SOH CR CR NL */ if(skipline(clone, 4) < 0) return identbuf; { wmo_start_t start; if( get_wmo_start(clone, &start) == NULL ) return identbuf; conv = sprintf(cp, " %03d", start.seqno); cp += conv; } { wmo_header_t hdr; dtime time; hdr.time = &time; if( get_wmo_header(clone, &hdr) == NULL ) return identbuf; conv = sprintf(cp, " %s", s_wmo_header(&hdr)); cp += conv; log_assert(cp < &identbuf[sizeof(identbuf)]); } return identbuf; }
void outrumor() { int rn; int i; FILE *rumf; if(n_rumors <= n_used_rumors) { return; } else { rumf = fopen(RUMORFILE, "r"); if(rumf == NULL) { return; } } if(n_used_rumors < 0) { init_rumors(rumf); } if(n_rumors == 0) { fclose(rumf); return; } rn = rn2(n_rumors - n_used_rumors); i = 0; while((rn != 0) || (used(i) != 0)) { skipline(rumf); if(used(i) == 0) { --rn; } ++i; } usedbits[i / CHARSZ] |= (1 << (i % CHARSZ)); ++n_used_rumors; outline(rumf); fclose(rumf); }
void init_rumors(FILE *rumf) { int i; n_used_rumors = 0; while(skipline(rumf) != 0) { ++n_rumors; } rewind(rumf); i = n_rumors / CHARSZ; usedbits = (char *)alloc((unsigned)(i + 1)); while(i >= 0) { usedbits[i] = 0; --i; } }
void score_player() /**************************************/ /* Function: defines score for */ /* current guess */ /**************************************/ { int x, y; /* checks black pegs*/ for (x = 0; x < 4; x++) guesses[cur].pegs[x].used = code.pegs[x].used = NONE; for (x = 0; x < 4; x++) if (guesses[cur].pegs[x].color == code.pegs[x].color) { /* guess color = code color */ code.pegs[x].used = guesses[cur].pegs[x].used = BLACK; guesses[cur].blacks++; PDEBUG(0,guesses[cur].blacks); printf("b"); } if (guesses[cur].blacks != 4) /* if not game_won, checks white pegs*/ { for (x = 0; x < 4; x++) for (y = 0; y < 4; y++) if (guesses[cur].pegs[x].color == code.pegs[y].color && !code.pegs[y].used && !guesses[cur].pegs[x].used) { code.pegs[y].used = guesses[cur].pegs[x].used = WHITE; guesses[cur].whites++; printf("w"); } } else game_won = TRUE; if (guesses[cur].blacks != 0 || guesses[cur].whites != 0) skipline(2); else /*bad guess,no score */ format_output("No score.\n\n",1); }
char read_char(parser_t *p) { char c; if (feof(p->f)) { c = '0'; } else { c = fgetc(p->f); while (c == '#' || c == '!') { skipline(p); if (feof(p->f)) { c = '0'; } else { c = fgetc(p->f); }; } } return c; }
static const char* skipws(const char* p) { while(*p) { if(p[0] == 9 || p[0] == 0x20) { p++; continue; } else if(p[0] == '\\') { p++; if(p[0] == 10 || p[0] == 13) p = szskipcr(p); else p++; continue; } else if(p[0] == '/' && p[1] == '/') { // Comments p = skipline(p + 2); continue; } break; } return p; }
bool PTXPointReader::doReadNextPoint() { if (this->stream->eof()) { this->stream->close(); this->currentFile++; if (this->currentFile != files.end()) { this->stream = new fstream(*(this->currentFile), ios::in); this->currentChunk = 0; skipline(*stream); loadChunk(stream, currentChunk, tr); } else { return false; } } vector<double> split; getlined(*stream, split); if (1 == split.size()) { this->currentChunk++; loadChunk(stream, currentChunk, tr); getlined(*stream, split); } auto size1 = split.size(); if (size1 > 3) { this->p = transform(tr, split[0], split[1], split[2]); double intensity = split[3]; this->p.intensity = (unsigned short)(65535.0 * intensity); if (4 == size1) { this->p.color.x = (unsigned char)(intensity * 255.0); this->p.color.y = (unsigned char)(intensity * 255.0); this->p.color.z = (unsigned char)(intensity * 255.0); } else if (7 == size1) { this->p.color.x = (unsigned char)(split[4]); this->p.color.y = (unsigned char)(split[5]); this->p.color.z = (unsigned char)(split[6]); } } else { this->p.intensity = INVALID_INTENSITY; } return true; }
int SimpleMixer::parse_control_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler, uint8_t &control_group, uint8_t &control_index) { unsigned u[2]; int s[5]; buf = findtag(buf, buflen, 'S'); if ((buf == nullptr) || (buflen < 16)) { debug("control parser failed finding tag, ret: '%s'", buf); return -1; } if (sscanf(buf, "S: %u %u %d %d %d %d %d", &u[0], &u[1], &s[0], &s[1], &s[2], &s[3], &s[4]) != 7) { debug("control parse failed on '%s'", buf); return -1; } buf = skipline(buf, buflen); if (buf == nullptr) { debug("no line ending, line is incomplete"); return -1; } control_group = u[0]; control_index = u[1]; scaler.negative_scale = s[0] / 10000.0f; scaler.positive_scale = s[1] / 10000.0f; scaler.offset = s[2] / 10000.0f; scaler.min_output = s[3] / 10000.0f; scaler.max_output = s[4] / 10000.0f; return 0; }
static int getlig(struct mfile *mp, int warn) /* pick up ligature list */ { int lig; char *temp; lig = 0; while ((temp = sget(mp)) != NULL && strcmp(temp, "0") != 0) { if (strcmp(temp, "fi") == 0) lig |= LFI; else if (strcmp(temp, "fl") == 0) lig |= LFL; else if (strcmp(temp, "ff") == 0) lig |= LFF; else if (strcmp(temp, "ffi") == 0) lig |= LFFI; else if (strcmp(temp, "ffl") == 0) lig |= LFFL; else if (warn) errprint("illegal ligature %s\n", temp); } skipline(mp); return lig; }
int main(int argc, char *argv[]) { FILE *pnd; char *interface; struct ifinfo { char name[8]; unsigned int r_bytes, r_pkt, r_err, r_drop, r_fifo, r_frame; unsigned int r_compr, r_mcast; unsigned int x_bytes, x_pkt, x_err, x_drop, x_fifo, x_coll; unsigned int x_carrier, x_compr; } ifc; unsigned long long bin, bout, lbin, lbout; int first; struct timeval t_now, t_last; double maxbandwidth; double bwin, bwout, bwmeasure, timedelta; int opt; char *t_tmp, *g_tmp; /* Options */ int measure_input = 0; /* Input instead of output */ char *text_file = "ubar.txt"; /* Text filename */ char *graphics_file = "ubar.png"; /* Graphics filename */ char *unit_name = "Mbit/s"; /* Unit name */ double unit = 1.0e+6; /* Unit multiplier */ int interval = 15; /* Interval between measurements (s) */ int width = 600; /* Bar width */ int height = 4; /* Bar height */ int border = 1; /* Bar border */ program = argv[0]; while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGh", longopts, NULL)) != -1 ) { switch ( opt ) { case 'i': measure_input = 1; break; case 'o': measure_input = 0; break; case 'f': text_file = optarg; break; case 'p': graphics_file = optarg; break; case 't': interval = atoi(optarg); break; case 'x': width = atoi(optarg); break; case 'y': height = atoi(optarg); break; case 'b': border = atoi(optarg); break; case 'k': unit = 1.0e+3; unit_name = "kbit/s"; break; case 'M': unit = 1.0e+6; unit_name = "Mbit/s"; break; case 'G': unit = 1.0e+9; unit_name = "Gbit/s"; break; case 'h': usage(0); break; default: usage(1); break; } } if ( argc-optind != 2 ) usage(1); t_tmp = malloc(strlen(text_file) + 5); g_tmp = malloc(strlen(graphics_file) + 5); if ( !t_tmp || !g_tmp ) { perror(program); exit(1); } sprintf(t_tmp, "%s.tmp", text_file); sprintf(g_tmp, "%s.tmp", graphics_file); interface = argv[optind]; maxbandwidth = atof(argv[optind+1]) * unit; first = 1; lbin = 0; lbout = 0; gettimeofday(&t_last, NULL); while ( 1 ) { /**** Begin code that obtains bandwidth data ****/ gettimeofday(&t_now, NULL); pnd = fopen("/proc/net/dev", "r"); if ( !pnd ) { fprintf(stderr, "%s: /proc/net/dev: %s", argv[0], strerror(errno)); exit(1); } /* Skip header */ skipline(pnd); skipline(pnd); /* Get interface info */ do { if ( fscanf(pnd, " %[^:]:%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u", ifc.name, &ifc.r_bytes, &ifc.r_pkt, &ifc.r_err, &ifc.r_drop, &ifc.r_fifo, &ifc.r_frame, &ifc.r_compr, &ifc.r_mcast, &ifc.x_bytes, &ifc.x_pkt, &ifc.x_err, &ifc.x_drop, &ifc.x_fifo, &ifc.x_coll, &ifc.x_carrier, &ifc.x_compr) != 17 ) { exit(200); } skipline(pnd); } while ( strcmp(ifc.name, interface) ); bin = ifc.r_bytes + (lbin & ~0xffffffffULL); bout = ifc.x_bytes + (lbout & ~0xffffffffULL); if ( bin < lbin ) bin += (1ULL << 32); if ( bout < lbout ) bout += (1ULL << 32); /**** Begin code that generates output ****/ if ( !first ) { FILE *ubar, *pngmaker; timedelta = (double)(t_now.tv_sec - t_last.tv_sec) + (t_now.tv_usec - t_last.tv_usec)/1.0e+6; bwin = (bin-lbin)*8/timedelta; bwout = (bout-lbout)*8/timedelta; bwmeasure = measure_input ? bwin : bwout; ubar = fopen(t_tmp, "w"); pngmaker = fopen(g_tmp, "w"); if ( ubar ) { fprintf(ubar, "Current bandwidth utilization %6.2f %s\n", bwmeasure/unit, unit_name); fclose(ubar); rename(t_tmp, text_file); } if ( pngmaker ) { write_bar_graph(pngmaker, bwmeasure/maxbandwidth, width, height, border, 5); fclose(pngmaker); rename(g_tmp, graphics_file); } } else { first = 0; } lbin = bin; lbout = bout; t_last = t_now; fclose(pnd); sleep(interval); } }
int main(int npar, char ** parch) { double buff; int i,j,k; int nx, nt, NfMx; char c; char *cteq="CTEQ"; double *q,*x,*d; char version[30]; int ordr, nf,nf6,nf5,nf4,nf3; double ordrf, nff; double Mc,Mb,Mt; double lambda,L6,L5,L4,L3; int Ncteq; char names[4][10]={"(6 -6)", "(5 -5)", "(4 -4)", "(3 -3)"}; char * p; do scanf("%c",&c); while(c!=':'); scanf("%s",version); p=strstr(version,".tbl"); if(p) p[0]=0; for(i=0;i<4;i++) if(toupper(version[i]) !=cteq[i]) {fprintf(stderr,"Non expected file format\n"); return 1;} Ncteq=version[4]-'0'; switch(Ncteq) { case 5: Ncteq=4; break; case 4: case 6: break; default:{fprintf(stderr,"Unknown version CTEQ%d \n",Ncteq); return 2;} } skipline(2); if(6!=scanf("%lf %lf %lf %*lf %*lf %*lf %lf %lf %lf", &ordrf, &nff,&lambda,&Mc,&Mb,&Mt )) goto errExit; nf=nff; ordr=ordrf; skipline(2); if(3!=scanf("%d %d %d",&nx,&nt,&NfMx))goto errExit; printf("#distribution \"%s(proton)\" 2212 => ",version); for(i= 6-NfMx; i<4;i++) printf(" %s",names[i]); printf(" -1 -2 21 2 1 \n"); printf("#distribution \"%s(anti-proton)\" -2212 => ",version); for(i=6-NfMx; i<4;i++) printf(" %s",names[i]); printf(" 1 2 21 -2 -1\n"); skipline(2); scanf("%lf",&buff); printf("\n#q_min %.5E\n", buff); scanf("%lf",&buff); /* printf("\n#q_max %.5E\n", buff); */ skipline(1); q=(double *)malloc(sizeof(double)*(nt+1)); for(i=0;i<=nt;i++) scanf("%lf",q+i); printf("\n#Q_grid\n"); for(i=0,j=1;i<=nt;i++,j++) { printf(" %.5E",q[i]); if(j==10) {printf("\n"); j=0;} } printf("\n"); writeAlpha(stdout,nf,ordr,lambda,NfMx,Mc,Mb,Mt,nt+1,q); /* nf6=nf; L6=lambda; if(nf6==6) {nf5=5; L5=findLambda(5,ordr, alpha(6, ordr,L6, 175.) ,175.);} else {nf5=nf;L5=lambda;} if(nf5==5) {nf4=4; L4=findLambda(4,ordr, alpha(5, ordr,L5, 4.5 ) ,4.5);} else {nf4=nf;L4=lambda;} if(nf4==4) {nf3=3; L3=findLambda(3,ordr, alpha(4, ordr,L4, 1.4 ) ,1.4);} else {nf3=nf;L3=lambda;} printf("\n#Alpha\n"); for(i=0,j=1;i<=nt;i++,j++) { double al; double Q=q[i]; if(Q<1.4) al=alpha(nf3, ordr, L3, Q); else if(Q<4.5) al=alpha(nf4, ordr, L4, Q); else if(Q<175.) al=alpha(nf5, ordr, L5, Q); else al=alpha(nf6, ordr, L6, Q); printf(" %.5E",al); if(j==10) {printf("\n"); j=0;} } printf("\n"); */ skipline(2); scanf("%lf",&buff); printf("\n#x_min %.5E\n", buff); skipline(1); printf("\n#X_grid\n"); for(i=0,j=1;i<=nx;i++,j++) { scanf("%lf",&buff); printf(" %.5E ",buff); if(j==10) {printf("\n"); j=0;} } printf("\n"); skipline(2); printf("\n#Interpolation CTEQ%d %f ",Ncteq,lambda); for(k=0;k<3+NfMx;k++) { printf("\n#%d-parton\n",k+1); for(j=0;j<nt+1;j++) { for(i=0;i<nx+1;i++) {scanf("%lf",&buff); printf(" %.5E",buff);} printf("\n"); } } return 0; errExit: fprintf(stderr,"%d", ftell(stdin)); }
MultirotorMixer * MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen) { MultirotorGeometry geometry; char geomname[8]; int s[4]; int used; /* enforce that the mixer ends with a new line */ if (!string_well_formed(buf, buflen)) { return nullptr; } if (sscanf(buf, "R: %7s %d %d %d %d%n", geomname, &s[0], &s[1], &s[2], &s[3], &used) != 5) { debug("multirotor parse failed on '%s'", buf); return nullptr; } if (used > (int)buflen) { debug("OVERFLOW: multirotor spec used %d of %u", used, buflen); return nullptr; } buf = skipline(buf, buflen); if (buf == nullptr) { debug("no line ending, line is incomplete"); return nullptr; } debug("remaining in buf: %d, first char: %c", buflen, buf[0]); if (!strcmp(geomname, "4+")) { geometry = MultirotorGeometry::QUAD_PLUS; } else if (!strcmp(geomname, "4x")) { geometry = MultirotorGeometry::QUAD_X; } else if (!strcmp(geomname, "4h")) { geometry = MultirotorGeometry::QUAD_H; } else if (!strcmp(geomname, "4v")) { geometry = MultirotorGeometry::QUAD_V; } else if (!strcmp(geomname, "4w")) { geometry = MultirotorGeometry::QUAD_WIDE; } else if (!strcmp(geomname, "4s")) { geometry = MultirotorGeometry::QUAD_S250AQ; } else if (!strcmp(geomname, "4dc")) { geometry = MultirotorGeometry::QUAD_DEADCAT; } else if (!strcmp(geomname, "6+")) { geometry = MultirotorGeometry::HEX_PLUS; } else if (!strcmp(geomname, "6x")) { geometry = MultirotorGeometry::HEX_X; } else if (!strcmp(geomname, "6c")) { geometry = MultirotorGeometry::HEX_COX; } else if (!strcmp(geomname, "6t")) { geometry = MultirotorGeometry::HEX_T; } else if (!strcmp(geomname, "8+")) { geometry = MultirotorGeometry::OCTA_PLUS; } else if (!strcmp(geomname, "8x")) { geometry = MultirotorGeometry::OCTA_X; } else if (!strcmp(geomname, "8c")) { geometry = MultirotorGeometry::OCTA_COX; } else if (!strcmp(geomname, "6m")) { geometry = MultirotorGeometry::DODECA_TOP_COX; } else if (!strcmp(geomname, "6a")) { geometry = MultirotorGeometry::DODECA_BOTTOM_COX; } else if (!strcmp(geomname, "2-")) { geometry = MultirotorGeometry::TWIN_ENGINE; } else if (!strcmp(geomname, "3y")) { geometry = MultirotorGeometry::TRI_Y; } else { debug("unrecognised geometry '%s'", geomname); return nullptr; } debug("adding multirotor mixer '%s'", geomname); return new MultirotorMixer( control_cb, cb_handle, geometry, s[0] / 10000.0f, s[1] / 10000.0f, s[2] / 10000.0f, s[3] / 10000.0f); }
static void run_jq_tests(jv lib_dirs, FILE *testdata) { char prog[4096]; char buf[4096]; struct err_data err_msg; int tests = 0, passed = 0, invalid = 0; unsigned int lineno = 0; int must_fail = 0; int check_msg = 0; jq_state *jq = NULL; jq = jq_init(); assert(jq); if (jv_get_kind(lib_dirs) == JV_KIND_NULL) lib_dirs = jv_array(); jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs); while (1) { if (!fgets(prog, sizeof(prog), testdata)) break; lineno++; if (skipline(prog)) continue; if (checkfail(prog)) { must_fail = 1; check_msg = checkerrormsg(prog); jq_set_error_cb(jq, test_err_cb, &err_msg); continue; } if (prog[strlen(prog)-1] == '\n') prog[strlen(prog)-1] = 0; printf("Testing '%s' at line number %u\n", prog, lineno); int pass = 1; tests++; int compiled = jq_compile(jq, prog); if (must_fail) { jq_set_error_cb(jq, NULL, NULL); must_fail = 0; check_msg = 0; if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; } lineno++; if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0; if (compiled) { printf("*** Test program compiled that should not have at line %u: %s\n", lineno, prog); invalid++; continue; } if (check_msg && strcmp(buf, err_msg.buf) != 0) { printf("*** Erroneous test program failed with wrong message (%s) at line %u: %s\n", err_msg.buf, lineno, prog); invalid++; } else { passed++; } continue; } if (!compiled) { printf("*** Test program failed to compile at line %u: %s\n", lineno, prog); invalid++; // skip past test data while (fgets(buf, sizeof(buf), testdata)) { lineno++; if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) break; } continue; } printf("Disassembly:\n"); jq_dump_disassembly(jq, 2); printf("\n"); if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; } lineno++; jv input = jv_parse(buf); if (!jv_is_valid(input)){ invalid++; continue; } jq_start(jq, input, JQ_DEBUG_TRACE); while (fgets(buf, sizeof(buf), testdata)) { lineno++; if (skipline(buf)) break; jv expected = jv_parse(buf); if (!jv_is_valid(expected)){ invalid++; continue; } jv actual = jq_next(jq); if (!jv_is_valid(actual)) { jv_free(actual); printf("*** Insufficient results for test at line number %u: %s\n", lineno, prog); pass = 0; break; } else if (!jv_equal(jv_copy(expected), jv_copy(actual))) { printf("*** Expected "); jv_dump(jv_copy(expected), 0); printf(", but got "); jv_dump(jv_copy(actual), 0); printf(" for test at line number %u: %s\n", lineno, prog); pass = 0; } jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOUR|JV_PRINT_REFCOUNT)); jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string))); assert(jv_equal(jv_copy(expected), jv_copy(reparsed))); jv_free(as_string); jv_free(reparsed); jv_free(expected); jv_free(actual); } if (pass) { jv extra = jq_next(jq); if (jv_is_valid(extra)) { printf("*** Superfluous result: "); jv_dump(extra, 0); printf(" for test at line number %u, %s\n", lineno, prog); pass = 0; } else { jv_free(extra); } } passed+=pass; } jq_teardown(&jq); printf("%d of %d tests passed (%d malformed)\n", passed,tests,invalid); if (passed != tests) exit(1); }