/* * Shrink the current window. * Find the window that gains space. Hack at * the window descriptions. Ask the redisplay to * do all the hard work. */ shrinkwind(f, n) { register WINDOW *adjwp; register LINE *lp; register int i; if (n < 0) return enlargewind(f, -n); if (wheadp->w_wndp == NULL) { ewprintf("Only one window"); return FALSE; } /* * Bit of flakiness - KRANDOM means it was an internal call, and * to be trusted implicitly about sizes. */ if ( !(f & FFRAND) && curwp->w_ntrows <= n) { ewprintf("Impossible change"); return (FALSE); } if ((adjwp=curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } if (curwp->w_wndp == adjwp) { /* Grow below. */ lp = adjwp->w_linep; for (i=n-adjwp->w_lines; i>0 && lback(lp)!=adjwp->w_bufp->b_linep; ) { lp = lback(lp); i -= countlines(lp); } if (i>0) i = 0; if (i<0) i = -i; adjwp->w_linep = lp; adjwp->w_lines = i; adjwp->w_toprow -= n; } else { /* Grow above. */ lp = curwp->w_linep; for (i=n + curwp->w_lines; i>0 && lp!=curbp->b_linep;) { i -= countlines(lp); if (i<0) break; lp = lforw(lp); } if (i>0) i=countlines(lp)-1; /* LAST row */ if (i<0) i=countlines(lp)+i; curwp->w_linep = lp; curwp->w_lines = i; curwp->w_toprow += n; } curwp->w_ntrows -= n; adjwp->w_ntrows += n; curwp->w_flag |= WFMODE|WFHARD; adjwp->w_flag |= WFMODE|WFHARD; return (TRUE); }
/*ARGSUSED*/ enlargewind(f, n) { register WINDOW *adjwp; register LINE *lp; register int i; if (n < 0) return shrinkwind(f, -n); if (wheadp->w_wndp == NULL) { ewprintf("Only one window"); return FALSE; } if ((adjwp=curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } if (adjwp->w_ntrows <= n) { ewprintf("Impossible change"); return FALSE; } if (curwp->w_wndp == adjwp) { /* Shrink below. */ lp = adjwp->w_linep; for (i=n+adjwp->w_lines; i>0 && lp!=adjwp->w_bufp->b_linep; ) { i -= countlines(lp); if (i < 0) break; lp = lforw(lp); } if (i>0) i=countlines(lp)-1; /* LAST row */ if (i<0) i=countlines(lp)+i; adjwp->w_linep = lp; adjwp->w_lines = i; adjwp->w_toprow += n; } else { /* Shrink above. */ lp = curwp->w_linep; for (i=n-curwp->w_lines; i>0 && lback(lp)!=curbp->b_linep; ){ lp = lback(lp); i -= countlines(lp); } if (i>0) i= 0; if (i<0) i= -i; curwp->w_linep = lp; curwp->w_lines = i; curwp->w_toprow -= n; } curwp->w_ntrows += n; adjwp->w_ntrows -= n; curwp->w_flag |= WFMODE|WFHARD; adjwp->w_flag |= WFMODE|WFHARD; return TRUE; }
CFileSetPoint::CFileSetPoint(const char* filename) { CSimGod::registerInputFile(filename); //char fullFilename[1024]; m_numSteps= 0; FILE *pFile; int numLines = countlines(filename); if (numLines==0) return; char buffer [1024]; fopen_s(&pFile,filename,"r"); if (pFile!=0) { m_pSetPoints= new double [numLines]; m_pTimes= new double [numLines]; while (!feof(pFile)) { fgets(buffer,1024,pFile); if (sscanf_s(buffer,"%lf %lf\n",&m_pTimes[m_numSteps],&m_pSetPoints[m_numSteps])==2) m_numSteps++; } fclose(pFile); } else { throw std::exception((std::string("Couldn't open setpoint file: ") + std::string(filename)).c_str()); } m_totalTime= m_pTimes[m_numSteps-1]; }
void rdInclude(rdWin *w, char *str, size_t len) { size_t nlines; char *buf; char *prefix = "> "; size_t nlen, plen = strlen(prefix); ulong p0, p1; assert(w); assert(str); nlines = countlines(str, len); if (rpc_addr(wilyq, w->id, ".", &p0, &p1)) { DPRINT("Could not get address of dot"); return; } nlen = len + nlines*plen + 1; buf = salloc(nlen); prefixlines(str, len, prefix, plen, buf); if (rpc_insert(wilyq, w->id, p1, buf)) { DPRINT("Could not insert included text"); } w->bodylen += nlen; free(buf); }
int loadwordlist(const char * filename) { int count = 0; char line[WORDMAX]; FILE * f; if(!( f = fopen(filename, "r"))) return count; count = countlines(f); wordlist = malloc(count * sizeof(char *)); rewind(f); int i = 0; while(fgets(line, WORDMAX, f)) { int len = strlen(line); if(len>0 && line[len-1] == '\n') { line[len-1] = '\0'; --len; } if (len == 0 || line[0] =='#') continue; wordlist[i] = malloc(len*sizeof(char)); strncpy(wordlist[i], line, len); i++; } fclose(f); //debug for(i=0; i < count; i++) { wordsize += sizeof(wordlist[i]); } return count; }
static void load_data(mcmc * m, const char * filename) { FILE * input; int npoints = countlines(filename); int ndim = get_column_count(filename); gsl_matrix * data; IFDEBUGPARSER dump_i("lines", npoints); IFDEBUGPARSER dump_i("dimensions", ndim); data = gsl_matrix_alloc(npoints, ndim); input = openfile(filename); if (gsl_matrix_fscanf(input, data) != 0) { fprintf(stderr, "error reading input data. Perhaps inconsistent format?\n"); fprintf(stderr, "tried to read %d x %d.\n", ndim, npoints); exit(3); } assert(fclose(input) == 0); m->data = data; IFDEBUGPARSER dump_i("loaded data points", npoints); }
mcmc * mcmc_load_params(const char * filename) { mcmc * m; FILE * input; int currentline = 0; const int pretext = 0; int r; int nlines; nlines = countlines(filename); IFDEBUGPARSER dump_i("number of lines", nlines); m = mcmc_init(nlines - pretext); IFDEBUGPARSER debug("opening params file"); input = openfile(filename); while (currentline < nlines) { IFDEBUGPARSER dump_i("reading parameter", currentline); if (load_parameter(m, input, currentline - pretext) != 0) { fprintf(stderr, "Line %d of %s is of incorrect format.\n", currentline + 1, filename); exit(1); } currentline++; } IFDEBUGPARSER debug("closing params file"); r = fclose(input); assert (r == 0); IFDEBUGPARSER debug("finished reading params file"); return m; }
/* see usage. nvalues min max file */ int main(int argc, char ** argv) { if (argc <= 3) { usage(argv[0]); } else { run(argv[3], countlines(argv[3]), atof(argv[1]), atof(argv[2])); } return 0; }
float compute_ji_2(char *fname1, char *fname2, float start, float end){ FILE *f1,*f2; int i,N; float r1,r2,xi1,xi2, ji2=0., char stemp[slength]; N = countlines(fname1); if (countlines(fname2!=N)){ fprintf(stderr,"ERROR: the 2 CUTE files dont have the same number of lines\n"); exit(0); } if ((f1 = fopen(fname1, "r"))==NULL) { perror("fopen:"); fprintf(stderr,"Error while reading the file %s\n",fname1); exit(0);; } if ((f2 = fopen(fname2, "r"))==NULL) { perror("fopen:"); fprintf(stderr,"Error while reading the file %s\n",fname2); exit(0);; } for(i=0;i<N,i++){ fscanf(f1,"%e %e",r1,xi1); fscanf(f2,"%e %e",r2,xi2); if (r1!=r2){ fprintf(stder,"ERROR: r1[%d]!=r2[%d]",i,i); exit(0); } if (r1>=start && r1<=end) ji2 += (xi1-xi2)*(xi1-xi2)/(xi1*xi1); fgets(stemp,slength,f1); fgets(stemp,slength,f2); } return ji2; }
int main(int argc, const char* argv[]) { FILE* fstream = fopen(argv[1], "r"); FILE* ostream = fopen(argv[2], "wb"); char line[1024]; char buf[1024]; int lines = countlines(argv[1]); printf("the file contains %d lines!\n", lines); struct Info *ptr; ptr = malloc(sizeof(struct Info) * lines); memset(ptr, 0, sizeof(struct Info) * lines); size_t i = 0; while(fgets(line, 1024, fstream)){ char* id = strdup(line); char* surname = strdup(line); char* firstname = strdup(line); char* department = strdup(line); char* age = strdup(line); ptr[i].ID = atoi(getfield(id, 1)); sscanf(getfield(firstname, 2), "%s", ptr[i].Firstname); sscanf(getfield(surname, 3), "%s", ptr[i].Surname); sscanf(getfield(department, 4), "%s", ptr[i].Department); ptr[i].Age = atoi(getfield(age, 5)); printf("the ID is %d\n", ptr[i].ID); printf("the name is %s\n", ptr[i].Firstname); printf("the surname is %s\n", ptr[i].Surname); printf("the age is %d\n", ptr[i].Age); printf("the ID is %u\n", htonl(ptr[i].ID)); fprintf(ostream, "%u\n", htonl(ptr[i].ID)); printchar2bin(ptr[i].Firstname, sizeof(ptr[i].Firstname), ostream); printchar2bin(ptr[i].Surname, sizeof(ptr[i].Surname), ostream); printchar2bin(ptr[i].Department, sizeof(ptr[i].Department), ostream); fprintf(ostream, "%u\n", htonl(ptr[i].Age)); ++i; free(id); free(surname); free(firstname); free(department); free(age); } fclose(fstream); fclose(ostream); return 0; }
struct cat* read_cat(const char* fname, int64 nside, double radius_arcsec, int verbose) { FILE* fptr=open_file(fname); size_t nlines=countlines(fptr); if (verbose) wlog(" found %lu lines\n", nlines); rewind(fptr); struct cat* cat = _cat_read(fptr, nlines, nside, radius_arcsec, verbose); fclose(fptr); return cat; }
/*ARGSUSED*/ onlywind(f, n) { register WINDOW *wp; register LINE *lp; register int i; while (wheadp != curwp) { wp = wheadp; wheadp = wp->w_wndp; if (--wp->w_bufp->b_nwnd == 0) { wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_doto = wp->w_doto; } free((char *) wp); } while (curwp->w_wndp != NULL) { wp = curwp->w_wndp; curwp->w_wndp = wp->w_wndp; if (--wp->w_bufp->b_nwnd == 0) { wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_doto = wp->w_doto; } free((char *) wp); } lp = curwp->w_linep; i = curwp->w_toprow - curwp->w_lines; while (i>0 && lback(lp)!=curbp->b_linep) { lp = lback(lp); i -= countlines(lp); } if (i > 0) i = 0; if (i < 0) i = -i; curwp->w_toprow = 0; curwp->w_ntrows = nrow-2; /* 2 = mode, echo. */ curwp->w_linep = lp; curwp->w_lines = i; curwp->w_flag |= WFMODE|WFHARD; return TRUE; }
int main() { // faili lugemine FILE *inputFile = fopen(I_FILENAME, "r"); if (inputFile == NULL) { printf("Faili avamine ebaõnnestus\n"); return 0; } int lines = countlines(inputFile) - 1; // loeme read üle, selleks et teada massiivi suurust if (DEBUG) printf("Ridade arv: %d\n", lines); Isik vanemad[lines]; // loeme sisendfailist Isik llvanemad[lines]; // lastelastega vanemad rewind(inputFile); // resetib faili pointer tagasi algusesse. Alternatiiv oleks fail uuesti avada. fileInput(inputFile, vanemad); fclose(inputFile); // väljastame testimiseks if (DEBUG) { printf("\nLapsed:\n"); printEntries(vanemad, lines); } // leiame lapselapsed findGrandChildren(vanemad, llvanemad, lines); // väljastame testimiseks if (DEBUG) { printf("\n=====================\n"); printf("\nLapselapsed:\n"); printEntries(llvanemad, lines); } // TODO: faili kirjutamine return 0; }
int wc(int f) { int t; char *buf; ssize_t bufsize; if((bufsize=readtobuf(&buf,f))==-1) return -1; if(lflag||noflags) { printf("%u ",(t=countlines(buf,bufsize))); totall+=t; } if(wflag||noflags) { printf("%u ",(t=countwords(buf,bufsize))); totalw+=t; } if(cflag||noflags) { printf("%u ",bufsize); totalc+=bufsize; } fflush(stdout); /* You can never trust that sneaky bastard */ free(buf); return 0; }
CHHFileSetPoint::CHHFileSetPoint(const char* filename) : CFileSetPoint() { FILE* pHHFile; char buffer[1024]; char* pNext; CSimGod::registerInputFile(filename); int numLines = countlines(filename); if (numLines == 0) return; fopen_s(&pHHFile, filename, "r"); if (pHHFile) { m_pSetPoints = new double[numLines]; m_pTimes = new double[numLines]; while (!feof(pHHFile)) { fgets(buffer, 1024, pHHFile); if (buffer[0] != '!') //skip comments { m_pTimes[m_numSteps] = strtod(buffer, &pNext); //first value is the time m_pSetPoints[m_numSteps] = strtod(pNext, 0); //second value is the horizontal wind speed m_numSteps++; } } m_totalTime = m_pTimes[m_numSteps - 1]; fclose(pHHFile); } else { throw std::exception((std::string("Couldn't open setpoint file: ") + std::string(filename)).c_str()); } }
struct cat* read_cat(const char* fname, int64 nside, double radius_arcsec, int verbose) { int barsize=70; FILE* fptr=open_file(fname); size_t nlines=countlines(fptr); if (verbose) wlog(" found %lu lines\n", nlines); rewind(fptr); struct cat* cat = alloc_or_die(sizeof(struct cat), "catalog struct"); double radius_radians=0; if (radius_arcsec <= 0) { cat->radius_in_file=1; cat->cos_radius = alloc_or_die(nlines*sizeof(double), "cos_radius array"); } else { cat->radius_in_file=0; cat->cos_radius = alloc_or_die(sizeof(double), "cos_radius"); radius_radians = radius_arcsec/3600.*D2R; cat->cos_radius[0] = cos(radius_radians); } cat->hpix=NULL; cat->tree=NULL; cat->pts = alloc_or_die(nlines*sizeof(struct point),"points"); cat->size = nlines; if (verbose) wlog(" creating hpix\n"); cat->hpix = hpix_new(nside); if (verbose) { wlog(" reading and building tree\n"); repeat_char('.', barsize); wlog("\n"); } double ra=0, dec=0; struct i64stack* listpix = i64stack_new(0); // this will produce a more balanced tree across the whole sky int64 half_npix=cat->hpix->npix/2; size_t count=0; struct point* pt = &cat->pts[0]; for (size_t i=0; i<cat->size; i++) { if (2 != fscanf(fptr, "%lf %lf", &ra, &dec)) { wlog("expected to read point at line %lu\n", i); exit(EXIT_FAILURE); } if (cat->radius_in_file) { if (1 != fscanf(fptr, "%lf", &radius_arcsec)) { wlog("expected to read radius at line %lu\n", i); exit(EXIT_FAILURE); } radius_radians = radius_arcsec/3600.*D2R; cat->cos_radius[i] = cos(radius_radians); } hpix_eq2xyz(ra,dec,&pt->x,&pt->y,&pt->z); hpix_disc_intersect(cat->hpix, pt->x, pt->y, pt->z, radius_radians, listpix); int64* ptr=listpix->data; while (ptr < listpix->data + listpix->size) { tree_insert(&cat->tree, (*ptr)-half_npix, count); ptr++; } pt++; count++; if (verbose) incr_bar(i+1, cat->size, barsize, '='); } listpix=i64stack_delete(listpix); if (verbose) wlog("\n"); if (count != nlines) { wlog("expected %lu lines but read %lu\n", nlines, count); exit(EXIT_FAILURE); } if (verbose) wlog("fullest node has %lu members\n", tree_most_members(cat->tree)); fclose(fptr); return cat; }
uint4 MCRepeat::linecount() { return countlines(statements); }
/*ARGSUSED*/ splitwind(f, n) { register WINDOW *wp; register LINE *lp; register int ntru; register int ntrd; int ntrl; int lines; WINDOW *wp1, *wp2; if (curwp->w_ntrows < 3) { ewprintf("Cannot split a %d line window", curwp->w_ntrows); return (FALSE); } if ((wp = (WINDOW *)malloc(sizeof(WINDOW))) == NULL) { ewprintf("Can't get %d", sizeof(WINDOW)); return (FALSE); } ++curbp->b_nwnd; /* Displayed twice. */ wp->w_bufp = curbp; wp->w_dotp = curwp->w_dotp; wp->w_doto = curwp->w_doto; wp->w_flag = 0; wp->w_force = 0; ntru = (curwp->w_ntrows-1) / 2; /* Upper size */ ntrl = (curwp->w_ntrows-1) - ntru; /* Lower size */ lp = curwp->w_linep; ntrd = - curwp->w_lines; while (lp != curwp->w_dotp) { ntrd += countlines(lp); lp = lforw(lp); } { int x,y; ntrd += colrow(lp, curwp->w_doto, &x, &y); } lp = curwp->w_linep; lines = curwp->w_lines; if (ntrd <= ntru) { /* Old is upper window. */ if (ntrd == ntru) { /* Hit mode line. */ if ( countlines(lp) > lines+1 ) { ++lines; } else { lp = lforw(lp); lines=0; } } curwp->w_ntrows = ntru; wp->w_wndp = curwp->w_wndp; curwp->w_wndp = wp; wp->w_toprow = curwp->w_toprow+ntru+1; wp->w_ntrows = ntrl; } else { /* Old is lower window */ wp1 = NULL; wp2 = wheadp; while (wp2 != curwp) { wp1 = wp2; wp2 = wp2->w_wndp; } if (wp1 == NULL) wheadp = wp; else wp1->w_wndp = wp; wp->w_wndp = curwp; wp->w_toprow = curwp->w_toprow; wp->w_ntrows = ntru; ++ntru; /* Mode line. */ curwp->w_toprow += ntru; curwp->w_ntrows = ntrl; ntru += lines; while (ntru > 0) { ntru -= countlines(lp); if (ntru < 0) break; lp = lforw(lp); } if (ntru < 0) ntru = countlines(lp) + ntru; lines = ntru; } curwp->w_linep = lp; /* Adjust the top lines */ wp->w_linep = lp; /* if necessary. */ curwp->w_lines = lines; wp->w_lines = lines; curwp->w_flag |= WFMODE|WFHARD; wp->w_flag |= WFMODE|WFHARD; return TRUE; }
/*================================== MAIN ================================*/ int main(int argc, char *argv[]){ if (argc < 3){ printf("This program takes 2 arguments:\n"); printf("positions_file and velocities_file.\n"); printf("You only passed %d arguments.\n",argc-1); printf("You fool.\n"); exit(1); } //argv[1]: positions file //argv[2]: velocities file //Opens the files FILE *posfile, *velfile; char *namepos = argv[1]; char *namevel = argv[2]; posfile = fopen(namepos,"r"); velfile = fopen(namevel,"r"); long n_pos = countlines(posfile); long n_vel = countlines(velfile); if (n_pos != n_vel) { printf("Position file and velocity files have different lengths\n"); printf("Position file has %ld lines and vel. file has %ld lines.\n" ,n_pos,n_vel); printf("You fool.\n"); exit(1); } printf("Given files %s, %s\n",namepos,namevel); printf("length of file = %ld\n",n_pos); //Create array of particles struct point *masses; masses = ( struct point * ) malloc( n_pos * sizeof(struct point) ); //Import data from posfile, velfile into particle array get_data_from_files( posfile, velfile, n_pos, masses ); /*===== Neighborhoods =====*/ int i = 0, j = 0; double mean_dist = 0.0; printf("Number of neighbors = %d\n",N_NEIGH); printf("Obtaining neighborhoods...\n"); for (i=0; i < n_pos; ++i) { if (i%250 == 0) { printf("i = %d\n",i); } masses[i].neigh = (size_t * ) malloc( N_NEIGH * sizeof(size_t) ); neighborhood( masses[i].neigh, N_NEIGH, i, n_pos, masses, &mean_dist ); } mean_dist = 2.0* (mean_dist) / (n_pos*(n_pos + 1.0)); printf("Mean distance = %lf\n",mean_dist); /*===== Densities ===== */ printf("Calculating densities... "); size_t neigh_index = 1; double density = 0.0; for ( i = 0; i < n_pos; ++i){ density = 0.0; for ( j = 0; j < N_NEIGH; ++j){ neigh_index = masses[i].neigh[j]; density += density_kernel(masses[i], masses[neigh_index], 0.5* (mean_dist)); } masses[i].rho = 4.0/(M_PI * mean_dist * mean_dist) * density; } /*for (i = 0; i < n_pos; ++i){ masses[i].rho = 0.0; } i = 10; masses[i].rho = 10.0; for (j = 0; j < N_NEIGH; ++j){ neigh_index = masses[i].neigh[j]; masses[neigh_index].rho = 10.0; }*/ printf("done!\n"); /*===== Accelerations =====*/ /*===== Writing out =====*/ FILE * pf; pf = fopen("sph.dat","w"); fprintf(pf,"ID\t m\t x\t y\t vx\t vy\t ax\t ay\t rho\n"); for ( i = 0; i < n_pos; ++i){ //printf("Writing %d...\n",i); fprintf(pf, "%d\t %lf\t %lf\t %lf\t %lf\t %lf\t %lf\t %lf\t %lf\n", (int) masses[i].id, masses[i].mass, masses[i].x, masses[i].y, masses[i].vx, masses[i].vy, masses[i].ax, masses[i].ay, masses[i].rho); } fclose(pf); return 0; }
int yylex(){ int nstr; extern int yyprevious; #ifdef __cplusplus /* to avoid CC and lint complaining yyfussy not being used ...*/ static int __lex_hack = 0; if (__lex_hack) goto yyfussy; #endif while((nstr = yylook()) >= 0) yyfussy: switch(nstr){ case 0: if(yywrap()) return(0); break; case 1: # line 102 "lexer.l" { /* ignore comment */; } break; case 2: # line 104 "lexer.l" { /* ignore whitespace*/; } break; case 3: # line 106 "lexer.l" { lineno++; return T_newline; } break; case 4: # line 108 "lexer.l" { announce("<T_from>\n"); return T_from; } break; case 5: # line 110 "lexer.l" { announce("<T_into>\n"); return T_into; } break; case 6: # line 112 "lexer.l" { announce("<T_pipe>\n"); return T_pipe; } break; case 7: # line 114 "lexer.l" { int token,ok; ok=matchquotes(yytext); yylval.v.string=cleancpystring(yytext); if ( ok ) { announce1("<T_string(%s)>\n",yylval.v.string); token=T_string; } else { announce1("<T_badstring(%s)>\n",yylval.v.string); fprintf(stderr,"Unterminated string, line %d.\n", lineno); token=T_badstring; } lineno += countlines(yylval.v.string); return token; } break; case -1: break; default: (void)fprintf(yyout,"bad switch yylook %d",nstr); } return(0); }
void showhelp(const char *filename) { char nc,nr,ph; char *title,*text; union { char *buffer; void *vbuf; } buf; // This is to avoild type-punning issues char line[512]; size_t size; char scan; int rv,numlines,curr_line; nc = getnumcols(); nr = getnumrows(); ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1; cls(); drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX); drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0 if (filename == NULL) { // print file contents gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE); cswprint("Filename not given",0x07,HELP_LEFT_MARGIN); while (1) { inputc(&scan); if (scan == ESCAPE) break; } cls(); return; } rv = loadfile(filename,(void **)&buf.vbuf, &size); // load entire file into memory if (rv < 0) { // Error reading file or no such file sprintf(line, "Error reading file or file not found\n file=%s",filename); gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE); cswprint(line,0x07,HELP_LEFT_MARGIN); while (1) { inputc(&scan); if (scan == ESCAPE) break; } cls(); return; } title = buf.buffer; text = findline(title,1); // end of first line *text++='\0'; // end the title string and increment text // Now we have a file just print it. gotoxy(1,(nc-strlen(title))/2,HELPPAGE); csprint(title,0x07); numlines = countlines(text); curr_line = 0; scan = ESCAPE+1; // anything except ESCAPE while(scan != ESCAPE) { printtext(text,curr_line); gotoxy(HELP_BODY_ROW-1,nc-HELP_RIGHT_MARGIN,HELPPAGE); if (curr_line > 0) putch(HELP_MORE_ABOVE,0x07,HELPPAGE); else putch(' ',0x07,HELPPAGE); gotoxy(nr-HELP_BOTTOM_MARGIN+1,nc-HELP_RIGHT_MARGIN,HELPPAGE); if (curr_line < numlines - ph) putch(HELP_MORE_BELOW,0x07,HELPPAGE); else putch(' ',0x07,HELPPAGE); inputc(&scan); // wait for user keypress switch(scan) { case HOMEKEY: curr_line = 0; break; case ENDKEY: curr_line = numlines; break; case UPARROW: curr_line--; break; case DNARROW: curr_line++; break; case PAGEUP: curr_line -= ph; break; case PAGEDN: curr_line += ph; break; default: break; } if (curr_line > numlines - ph) curr_line = numlines-ph; if (curr_line < 0) curr_line = 0; } cls(); return; }
uint4 MCSwitch::linecount() { return countlines(statements); }
uint4 MCTry::linecount() { return countlines(trystatements) + countlines(catchstatements) + countlines(finallystatements); }
int main(int argc, char ** argv){ char *dir_sig, *f_dir_sig, *f_dir_ann, *dir_query; int id_sig, n, n_ann, i, basura; char **posiciones; FILE *f_signal, *f_ann, *f_query; float *signals[2]; int *ann_index, *ann_chs; /* Leer la señal y su id */ dir_sig = argv[1]; sscanf(dir_sig, "mitdb-%d-float.txt", &id_sig); /* Construye ele vector para guradar las posiciones de acuerdo con * el ecg_id */ posiciones = (char **) malloc(sizeof(char *) * DERIVACION_MIT_BIH); posiciones[0] = (char *) malloc(sizeof(char) * POSICION_LEN); posiciones[1] = (char *) malloc(sizeof(char) * POSICION_LEN); posicion_derivacion_MIT_ARHYTHMIA(id_sig, posiciones); //~ fprintf(stdout, "ELECTRO %d\n", id_sig); //~ fprintf(stdout, "Las posiciones son: %s %s\n", posiciones[0], posiciones[1]); //~ exit(1); /* Leer el archivo con la señal de ECG */ f_dir_sig = (char *) malloc(strlen(dir_sig) + strlen(BD_DIR) + 4); memset(f_dir_sig, '\0', strlen(dir_sig) + strlen(BD_DIR) + 4); sprintf(f_dir_sig, "%s/%s", BD_DIR, dir_sig); f_signal = fopen(f_dir_sig, "r"); if(f_signal == NULL){ fprintf(stdout, "Error al abrir el archivo %s\n", dir_query); exit(1); } n = countlines(f_signal); rewind(f_signal); signals[0] = (float *) malloc(sizeof(float) * n); signals[1] = (float *) malloc(sizeof(float) * n); for(i = 0; i < n; i++) fscanf(f_signal, "%d %f %f", &basura, &signals[0][i], &signals[1][i]); fclose(f_signal); /* Leer las anotaciones */ f_dir_ann = (char *) malloc(strlen(ANN_DIR) + 20); memset(f_dir_ann, '\0', strlen(ANN_DIR) + 20); sprintf(f_dir_ann, "%s/ant-%d.txt", ANN_DIR, id_sig); f_ann = fopen(f_dir_ann, "r"); if(f_ann == NULL){ fprintf(stdout, "Error al abrir el archivo: %s\n", f_dir_ann); exit(1); } n_ann = countlines(f_ann); rewind(f_ann); ann_index = (int *) malloc(sizeof(int) * n_ann); ann_chs = (int *) malloc(sizeof(int) * n_ann); for(i = 0; i < n_ann; i++) fscanf(f_ann, "%d %d", &ann_index[i], &ann_chs[i]); fclose(f_ann); /* Crea y abre el archivo de salida */ dir_query = (char *) malloc(sizeof(char) * 20); memset(dir_query, '\0', 20); sprintf(dir_query, "query_%d.sql", id_sig); f_query = fopen(dir_query, "w"); if(f_query == NULL){ fprintf(stderr, "Error al abrir el archivo %s\n", dir_query); exit(1); } fprintf(f_query, "INSERT INTO Paciente(ID_BD) VALUES((SELECT id from bd WHERE Nombre = 'MIT-BIH-Arrhytmia'));\n"); fprintf(f_query, "INSERT INTO Electrocardiografia(Frecuencia_Muestreo,Longitud,ID_Paciente) VALUES(360,%d,(SELECT max(ID) FROM Paciente));\n", n); fprintf(f_query, "INSERT INTO Derivacion(Posicion, Signal, ID_Electrocardiografia) VALUES('%s','{", posiciones[0]); for(i = 0; i < n-1; i++) fprintf(f_query, "%f,", signals[0][i]); fprintf(f_query, "%f}',(SELECT max(id) FROM Electrocardiografia);\n", signals[0][n-1]); for(i = 0; i < n_ann; i++){ fprintf(f_query, "INSERT INTO Anotacion(ID_Derivacion, Indice, Nota) VALUES((SELECT max(id) from Derivacion), %d, %d);\n", ann_index[i], ann_chs[i]); } fprintf(f_query, "INSERT INTO Derivacion(Posicion, Signal, ID_Electrocardiografia) VALUES('%s', '{", posiciones[1]); for(i = 0; i < n-1; i++) fprintf(f_query, "%f,", signals[1][i]); fprintf(f_query, "%f}',(SELECT max(id) FROM Electrocardiografia));\n", signals[1][n-1]); for(i = 0; i < n_ann; i++){ fprintf(f_query, "INSERT INTO Anotacion(ID_Derivacion, Indice, Nota) VALUES((SELECT max(id) from Derivacion), %d, %d);\n", ann_index[i], ann_chs[i]); } //~ for(i = 0; i < n_ann-1; i++) fprintf(f_query, "%d,", ann_index[i]); //~ fprintf(f_query, "%d}','{", ann_index[n_ann-1]); //~ for(i = 0; i < n_ann-1; i++) fprintf(f_query, "%d,", ann_chs[i]); //~ fprintf(f_query, "%d}',(SELECT max(id) FROM Electrocardiografia));\n", ann_chs[n_ann-1]); //~ for(i = 0; i < n_ann-1; i++) fprintf(f_query, "%d,", ann_index[i]); //~ fprintf(f_query, "%d}','{", ann_index[n_ann-1]); //~ //~ for(i = 0; i < n_ann-1; i++) fprintf(f_query, "%d,", ann_chs[i]); //~ fprintf(f_query, "%d}',(SELECT max(id) FROM Electrocardiografia));\n", ann_chs[n_ann-1]); fclose(f_query); return 0; }
void init_xcl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); int i; /* scratch */ xclstruct *dp; if (xcls == NULL) { if ((xcls = (xclstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (xclstruct))) == NULL) return; } dp = &xcls[MI_SCREEN(mi)]; /* Update every time */ dp->width = MI_WIDTH(mi); dp->height = MI_HEIGHT(mi); dp->mid_x = (dp->width / 2); dp->mid_y = (dp->height / 2); if(dp->no_preset != 1) { dp->no_preset = 1; /* some presettings */ dp->planes = MI_COUNT(mi); if (dp->planes < -MINPLANES) { dp->planes = NRAND(-MI_COUNT(mi) -MINPLANES + 1) + MINPLANES; } else if (dp->planes < MINPLANES) { dp->planes = MINPLANES; } if(dp->planes > MAXCOUNT) dp->planes = MAXCOUNT; dp->Alpha = 0.0; /* rotate.1 */ dp->Beta = 0.0; /* rotate.2 */ dp->Gamma = 0.0; /* rotate.3 */ dp->Vx = 1; /* width from zero in X */ dp->Vy = 800; /* width from zero in Y */ dp->Vz = -300; /* width from zero in Z */ dp->G = 500.0; /* ZOOM */ dp->time3 = 1.0; dp->drawtime = 25000; dp->xcldelay = STARTUPDELAY; for(i=0;i< dp->planes; i++) { dp->az[i] = 2 * M_PI * i / (float)((dp->planes)); dp->el[i] = 0.0; dp->alpha[i] = 0.75; /* direction */ dp->turn[i] = 0; dp->turn_direction[i] = 1; speed[i] = speed_in; /* see TODO */ } random_pid = getpid(); /* goes here first for randomstart */ if(randomstart) { for(i=0;i< dp->planes; i++) { switch(i) { case 0: dp->az[0] += (random_pid % 31) / 5.0; break; default: dp->az[i] = dp->az[0] + 2 * M_PI * i / (float)((dp->planes)); } } } dp->bg = MI_BLACK_PIXEL(mi); if(MI_NPIXELS(mi) <= 2) for(i=0;i< dp->planes; i++) { dp->planecolor[i] = MI_WHITE_PIXEL(mi); } else { if(!oldcolor) { for(i=0;i< dp->planes; i++) { dp->planecolor[i] = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); } } else { /* with count >2 no so good */ for(i=0;i< dp->planes; i++) { switch(i) { case 0: dp->planecolor[0] = get_color(mi, (char *) "yellow", (XColor *) NULL); break; case 1: dp->planecolor[1] = get_color(mi, (char *) "red", (XColor *) NULL); break; default: dp->planecolor[i] = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); } } } } if(dp->erase_gc == None) if (!get_GC(display, MI_WINDOW(mi), &(dp->erase_gc),dp->bg)) { free_xcl(display, dp); return; } dp->lines = countlines(); for(i=0;i< dp->planes; i++) { if(dp->gc[i] == None) if (!get_GC(display, MI_WINDOW(mi), &(dp->gc[i]), dp->planecolor[i])) { free_xcl(display, dp); return; } dp->omega_const[i] = speed[i]/3.6 /line_length*1000.0; if(dp->xseg[i] == NULL) if ((dp-> xseg[i] = (XSegment *) malloc(sizeof(XSegment) * dp->lines)) == NULL) { free_xcl(display, dp); return; } if(dp->xseg_old[i] == NULL) if ((dp->xseg_old[i] = (XSegment *) malloc(sizeof(XSegment) * dp->lines)) == NULL) { free_xcl(display, dp); return; } } if(MI_IS_VERBOSE(mi)) { (void) printf("X control line combat in a box\n"); #if !defined( lint ) && !defined( SABER ) (void) printf("Version: %s\n",sccsid); #endif (void) printf("Line length: %gm\n",line_length/1000.0); (void) printf("Speed %g km/h \n",speed[0]); (void) printf("Lines per plane: %d\n",dp->lines); (void) printf("Spectator at %gm\n",spectator/1000.0); (void) printf("Try %g frames per Second (frametime: %dus)\n", 1000000.0/frametime,frametime); (void) printf("Calibration at %d frames\n",REGULATE); } } /* clear the screen */ MI_CLEARWINDOW(mi); (void) gettimeofday(&(dp->tv1),0); dp->time1 = (double)dp->tv1.tv_sec + (double)dp->tv1.tv_usec/(double)1000000; dp->xcldelay = frametime; }
void more(FILE *fp) { struct winsize w; unsigned short sys_width; unsigned short sys_height; char cmdbuf[1]; int cmd; int n; int lines; char *buf; if (ioctl(STDERR_FILENO, TIOCGWINSZ, &w) == 0) { if (w.ws_row > 0) { sys_height = w.ws_row; } if (w.ws_col > 0) { sys_width = w.ws_col; } } if ((buf = readfile(fp->_file, MAX)) == NULL) { perror("malloc"); return; } lines = countlines(buf); putlines(buf, 0, sys_height - 1); n = sys_height - 1; while (n < lines) { read(tty, cmdbuf, 1); cmd = cmdchr(*cmdbuf); if (cmd == CMD_QUIT) { break; } else if (cmd == CMD_PNEXT) { putlines(buf, n, sys_height - 1); n += sys_height - 1; } else if (cmd == CMD_LNEXT) { putline(buf, n++); } else if (cmd == CMD_PPREV) { tputs_x(CL); if (n - (sys_height - 1) * 2 < 0) { n = 0; } else { n -= (sys_height - 1) * 2; } putlines(buf, n, sys_height - 1); n += sys_height - 1; } else if (cmd == CMD_LPREV) { if (n - sys_height < 0) { continue; } tputs_x(SC); // save pos tputs_x(HO); // set home pos tputs_x(SR); // scroll revrse putline(buf, n-- - sys_height); tputs_x(RC); // restore pos tputs_x(CE); // clr line } } free(buf); }
uint4 MCIf::linecount() { return countlines(thenstatements) + countlines(elsestatements); }