/* clear a variable 3-17 */ void dbl_clear(variable* field) { if (gettype(field)<=tALPHA) memset(getdata(field),' ',getsize(field)); if (gettype(field)==tDECIMAL) memset(getdata(field),'0',getsize(field)); }
/* ** traverse grammar at index 'arg', pushing all its keys and patterns ** into the stack. Create a new table (before all pairs key-pattern) to ** collect all keys and their associated positions in the final tree ** (the "position table"). ** Return the number of rules and (in 'totalsize') the total size ** for the new tree. */ static int collectrules (lua_State *L, int arg, int *totalsize) { int n = 1; /* to count number of rules */ int postab = lua_gettop(L) + 1; /* index of position table */ int size; /* accumulator for total size */ lua_newtable(L); /* create position table */ getfirstrule(L, arg, postab); size = 2 + getsize(L, postab + 2); /* TGrammar + TRule + rule */ lua_pushnil(L); /* prepare to traverse grammar table */ while (lua_next(L, arg) != 0) { if (lua_tonumber(L, -2) == 1 || lua_equal(L, -2, postab + 1)) { /* initial rule? */ lua_pop(L, 1); /* remove value (keep key for lua_next) */ continue; } if (!testpattern(L, -1)) /* value is not a pattern? */ luaL_error(L, "rule '%s' is not a pattern", val2str(L, -2)); luaL_checkstack(L, LUA_MINSTACK, "grammar has too many rules"); lua_pushvalue(L, -2); /* push key (to insert into position table) */ lua_pushinteger(L, size); lua_settable(L, postab); size += 1 + getsize(L, -1); /* update size */ lua_pushvalue(L, -2); /* push key (for next lua_next) */ n++; } *totalsize = size + 1; /* TTrue to finish list of rules */ return n; }
static u32 ParseLine(char *line ,upg_info_t *upg_priv) { u32 len = strlen((char *)line); u32 i = 0,j = 0; u8 *p_p = NULL; u8 *p_pl = NULL; for(j = 0; j < len; j++) { if((' ' != line[j]) && ('\t' != line[j]) //ignore space and tab && ('\r' != line[j])) //ignore dos sign break; } if(j >= len) { return 0; //ignore the a line full of space or tab } p_pl =(u8 *) &line[j]; for(i = 0; i < LINE_TOTAL_TYPE; i++) { if(0 == strncasecmp((char *)p_pl,line_type[i],strlen((char *)line_type[i])))//find cmd break; } if(i >= LINE_TOTAL_TYPE) { return -1; } p_p = &p_pl[strlen((char *)line_type[i])]; switch(i) { case LINE_COMMENTS: //OS_PRINTF("comment: %s\n", line); break; case LINE_SEPARATOR: //OS_PRINTF("separator: %s\n", line); break; case LINE_BLOCK_NUM: upg_priv->blk_num = getsize(p_p); break; case LINE_BLOCK_ID: upg_priv->blk_cnt ++; upg_priv->m_block[upg_priv->blk_cnt].id = getsize(p_p); break; case LINE_BLOCK_VERSION: upg_priv->m_block[upg_priv->blk_cnt].version = getsize(p_p); break; case LINE_BLOCK_NAME: getstring(upg_priv,LINE_BLOCK_NAME,p_p); break; default: OS_PRINTF("unknown type: %s\n", p_p); break; } return 0; }
/** * @brief Determines and returns size of data that can be processed */ static size_t __clamp_size(void *ip, size_t n) { if (n > getsize(ip)) return 0; else if ((getposition(ip) + n) > getsize(ip)) return getsize(ip) - getposition(ip); else return n; }
//メイン関数 int main(int argc, char *argv[]) { char *inputfilename; int width, height; FILE *fp; //乱数初期化 srand( time(NULL) ); //引数チェック if(argc != 3){ //引数がおかしいとき if( argc == 2 && !strcmp(argv[1], "-h") ){ help(); //ヘルプ表示 return 0; } printf("エラー:引数が少ない、または多いです。\n"); //エラー表示 printf("ヘルプ : stereogram -h\n"); return 1; //エラー終了1 } //サイズ取得 if( getsize(&width, strtok(argv[1], "x")) || //文字列をxで区切る getsize(&height, strtok(NULL, "x")) ){ //どちらかでエラーが発生した場合 printf("サイズ取得でエラーを起こしました。1番目の引数を確認してください。"); return 2; //エラー終了2 } //入力ファイル名取得 inputfilename = argv[2]; printf("読み取り結果:\nサイズ 横%d 縦%d\n入力ファイル名%s\n", width, height, inputfilename); //入力画像読み込み int in_size = width*height*COLORSIZE; unsigned char *source = new unsigned char[ in_size ]; //バッファ作成 if ((fp = fopen(inputfilename, "rb")) != NULL) { fread(source, in_size, 1, fp); fclose(fp); } else { printf("%sが開けませんでした。", inputfilename); return 3; //エラー終了3 } //表示 for(int y=3; y < height; y+=5 ){ for(int x=3; x < width; x+=5 ){ //判定 if( source[ (y * width + x)*COLORSIZE ] == 0 ){ putchar('*'); }else{ putchar(' '); } } putchar('\n'); } return 0; }
// reject degenerate tetrahedra void minimesh::reject() { unsigned int i; miniv3d v1,v2,v3,v4; double d1,d2,d3,d4; double e1,e2,e3,e4,e5,e6; double mind,maxe; // check all tetrahedra for validity for (i=0; i<getsize(); i++) if (get(i).check()) { remove(i); i--; } // check all tetrahedra for degeneracy for (i=0; i<getsize(); i++) { // get vertices of the actual tetrahedron v1=get(i).vtx1; v2=get(i).vtx2; v3=get(i).vtx3; v4=get(i).vtx4; // calculate distances of corners to opposing face d1=minigeom_plane<double>(v1,v2,v3,v4).getdistance(v4); d2=minigeom_plane<double>(v1,v4,v2,v3).getdistance(v3); d3=minigeom_plane<double>(v2,v4,v3,v1).getdistance(v1); d4=minigeom_plane<double>(v3,v4,v1,v2).getdistance(v2); // calculate squared corner distances e1=(v4-v1)*(v4-v1); e2=(v4-v2)*(v4-v2); e3=(v4-v3)*(v4-v3); e4=(v2-v1)*(v2-v1); e5=(v3-v2)*(v3-v2); e6=(v1-v3)*(v1-v3); // calculate minimum and maximum distance mind=dmin(dmin(d1,d2),dmin(d3,d4)); maxe=sqrt(dmax(dmax(dmax(e1,e2),dmax(e3,e4)),dmax(e5,e6))); // remove tetrahedra with degenerate size or aspect if (mind<CONFIGURE_DEGENERATE_SIZE || mind/maxe<CONFIGURE_DEGENERATE_ASPECT) { remove(i); i--; } } }
int main(int argc, char *argv[]) { int fd = 0, retval = 0; int o_flags = O_LARGEFILE; struct fd_state *state = calloc(sizeof(struct fd_state),1); int writeEstimate = 0; int verifyEstimate = 0; printf("into the file at least."); if (argc != 4) usage(argv[0]); iter = strtoull(argv[2],NULL,10); if (!strcmp(argv[1],"write")) { fd = open(argv[3], O_RDWR | o_flags); if (fd == -1) { fprintf(stderr,"\nUnable to open [%s], (err %d)!\n",argv[3],0 - errno); return 1; } if (getsize(fd, state)!=0) return -1; retval = write_testpattern(fd, state, 0, NULL); } else if (!strcmp(argv[1],"verify")) { fd = open(argv[3], O_RDONLY | o_flags); if (fd == -1) { fprintf(stderr,"\nUnable to open [%s], (err %d)!\n",argv[3],0 - errno); return 1; } if (getsize(fd, state)!=0) return -1; retval = verify_testpattern(fd, state, 0, NULL); } else if (!strcmp(argv[1],"report")) { fd = open(argv[3], O_RDWR | o_flags); if (fd == -1) { fprintf(stderr,"\nUnable to open [%s], (err %d)!\n",argv[3],0 - errno); return 1; } if (getsize(fd, state)!=0) return -1; retval = write_testpattern(fd, state, 1, &writeEstimate); retval = verify_testpattern(fd, state, 1, &verifyEstimate); printf("Estimated time: %s", (writeEstimate + verifyEstimate)); } else usage(argv[0]); close(fd); return retval; }
void Proc::get_df() { df_count = 0; FILE * fd; struct mntent * mntents; struct statfs sfs; fd = setmntent("/etc/mtab", "r"); if(!fd) { printf("set mount entry error!\n"); return; } while(1) { char * fname;//文件系统名 char * dir;//文件系统挂载点,文件系统目录 if(fd) { mntents = getmntent(fd); if(!mntents) { endmntent(fd); break; } } else continue; fname = mntents->mnt_fsname; dir = mntents->mnt_dir; if(strstr(fname,"none")) continue; df[df_count].device = fname; df[df_count].mounted = dir; if(statfs(dir, &sfs) != 0)//根据文件系统的挂载点,将该文件系统的信息读取到staffs中 { printf("statfs error\n"); continue; } if(sfs.f_blocks > 0 ) { df[df_count].percent = (sfs.f_blocks - sfs.f_bfree) * 100.0 /(double)sfs.f_blocks; df[df_count].size = getsize(sfs.f_blocks, sfs.f_bsize); df[df_count].useless = getsize(sfs.f_bavail, sfs.f_bsize); df[df_count].free = getsize(sfs.f_bfree,sfs.f_bsize); df[df_count].used = getsize(sfs.f_blocks - sfs.f_bfree, sfs.f_bsize); df_count++; } } }
// get barycenter of mesh miniv3d minimesh::barycenter() const { unsigned int i; miniv3d b; b=miniv3d(0.0); if (getsize()==0) return(b); for (i=0; i<getsize(); i++) b+=get(i).vtx1+get(i).vtx2+get(i).vtx3+get(i).vtx4; return(b/(4.0*getsize())); }
static void assemble(void) { off_t mypos; int i, fd; const char *args[3]; mypos = 0; for (i=0; i<me; i++) { mypos += getsize(mergedname(i)); } fd = doopen(PATH_SORTED, O_WRONLY, 0); dolseek(PATH_SORTED, fd, mypos, SEEK_SET); if (dup2(fd, STDOUT_FILENO) < 0) { complain("dup2"); exit(1); } doclose(PATH_SORTED, fd); args[0] = "cat"; args[1] = mergedname(me); args[2] = NULL; execv("/bin/cat", (char **) args); complain("/bin/cat: exec"); exit(1); }
static void sortbins(void) { const char *name; int i, fd; off_t binsize; for (i=0; i<numprocs; i++) { name = binname(me, i); binsize = getsize(name); if (binsize % sizeof(int) != 0) { complainx("%s: bin size %ld no good", name, (long) binsize); exit(1); } if (binsize > (off_t) sizeof(workspace)) { complainx("proc %d: %s: bin too large", me, name); exit(1); } fd = doopen(name, O_RDWR, 0); doexactread(name, fd, workspace, binsize); sortints(workspace, binsize/sizeof(int)); dolseek(name, fd, 0, SEEK_SET); dowrite(name, fd, workspace, binsize); doclose(name, fd); } }
/******************************************************************************* *** FUNCTION PARAMTAIL() ******************************************************************************* *** DESCRIPTION : Processes PARAMTAIL grammar rule. *** *** PARAMTAIL -> , TYPE idt PARAMTAIL | *** e ******************************************************************************/ void RecursiveParser::PARAMTAIL(int & offset, ParamPtr & paramptr, int & local_size, int & param_num, int & param_size) { if (global->Token == Global::commat) { EntryPtr ptr; VarType type; paramptr->Next = new ParamNode(); paramptr = paramptr->Next; match(Global::commat); TYPE(type); checkduplicate(global->Lexeme, depth); symtab->insert(global->Lexeme, global->Token, depth); ptr = symtab->lookup(global->Lexeme); ptr->TypeOfEntry = varEntry; ptr->var.TypeOfVariable = type; ptr->var.Offset = offset + typesize(type); ptr->var.size = typesize(type); ptr->isParam = true; param_size += typesize(type); paramptr->typeOfParameter = type; local_size += getsize(type, offset); param_num++; match(Global::idt); PARAMTAIL(offset, paramptr, local_size, param_num, param_size); } else return; }
double Tag::getmax()const{ double max=getvalue(0); for (unsigned int i=0;i<getsize();i++){ if (getvalue(i)>max) max=getvalue(i); } return max; }
/* xlength - return the length of a list or string */ LVAL xlength(void) { FIXTYPE n=0; LVAL arg; /* get the list or string */ arg = xlgetarg(); xllastarg(); /* find the length of a list */ if (listp(arg)) for (n = 0; consp(arg); n++) arg = cdr(arg); /* find the length of a string */ else if (stringp(arg)) n = (FIXTYPE)getslength(arg)-1; /* find the length of a vector */ else if (vectorp(arg)) n = (FIXTYPE)getsize(arg); /* otherwise, bad argument type */ else xlerror("bad argument type",arg); /* return the length */ return (cvfixnum(n)); }
double Multispectrum::getmax()const{ double max=getspectrum(0)->getmax(); for (unsigned int i=1;i<getsize();i++){ if (getspectrum(i)->getmax()>max) max=getspectrum(i)->getmax(); } return max; }
// get the maximum extent of the tetrahedra double minimesh::getextent() const { unsigned int i; minihedron tet; double ext2,len2; ext2=0.0; for (i=0; i<getsize(); i++) { tet=get(i); len2=(tet.vtx1-tet.vtx2)*(tet.vtx1-tet.vtx2); if (len2>ext2) ext2=len2; len2=(tet.vtx1-tet.vtx3)*(tet.vtx1-tet.vtx3); if (len2>ext2) ext2=len2; len2=(tet.vtx1-tet.vtx4)*(tet.vtx1-tet.vtx4); if (len2>ext2) ext2=len2; len2=(tet.vtx2-tet.vtx3)*(tet.vtx2-tet.vtx3); if (len2>ext2) ext2=len2; len2=(tet.vtx2-tet.vtx4)*(tet.vtx2-tet.vtx4); if (len2>ext2) ext2=len2; len2=(tet.vtx3-tet.vtx4)*(tet.vtx3-tet.vtx4); if (len2>ext2) ext2=len2; } return(sqrt(ext2)); }
// add offset to mesh void minimesh::offset(const miniv3d &offset) { unsigned int i; if (offset!=miniv3d(0.0)) for (i=0; i<getsize(); i++) ref(i).offset(offset); }
// shrink tetrahedra by factor relative to barycenter void minimesh::shrink(const double shrink) { unsigned int i; if (shrink!=1.0) for (i=0; i<getsize(); i++) ref(i).shrink(shrink); }
// scale mesh by factor void minimesh::scale(const double scale) { unsigned int i; if (scale!=1.0) for (i=0; i<getsize(); i++) ref(i).scale(scale); }
/* Parse an atom with explicit length --- one that starts with a byte length, as a decimal ASCII number. */ static svn_skel_t * explicit_atom(const char *data, apr_size_t len, apr_pool_t *pool) { const char *end = data + len; const char *next; apr_size_t size; svn_skel_t *s; /* Parse the length. */ size = getsize(data, end - data, &next, end - data); data = next; /* Exit if we overflowed, or there wasn't a valid number there. */ if (! data) return NULL; /* Skip the whitespace character after the length. */ if (data >= end || skel_char_type[(unsigned char) *data] != type_space) return NULL; data++; /* Check the length. */ if (data + size > end) return NULL; /* Allocate the skel representing this string. */ s = apr_pcalloc(pool, sizeof(*s)); s->is_atom = TRUE; s->data = data; s->len = size; return s; }
void dbl_display(variable* ch, int count, ...) { Channel* canal=findchannel(decimal2integer(ch)); va_list arg; int i; variable* field; FILE* fh; if (canal->terminal==1) fh=stdout; else fh=canal->fh; va_start(arg,count); for (i = 0; i < count; i++) { field=va_arg(arg,variable*); if (gettype(field)<=tALPHA) fwrite(getdata(field),getsize(field),1,fh); if (gettype(field)==tDECIMAL) { int64 code; code=decimal2integer(field); code%=256; fprintf(fh,"%c",code); } } fflush(fh); va_end(arg); }
TreeNode *sortedListToBST(ListNode *head) { // Start typing your C/C++ solution below // DO NOT write int main() function int n = getsize(head); return sortedListToBST(head, n); }
double Multispectrum::getmin()const{ double min=getspectrum(0)->getmin(); for (unsigned int i=1;i<getsize();i++){ if (getspectrum(i)->getmin()<min) min=getspectrum(i)->getmin(); } return min; }
int main(int argc, char * const argv[]) { int i, opt; size_t s; const char *opts = "hlv"; while ((opt = getopt(argc, argv, opts)) != -1) switch (opt) { case 'h': printf("Usage: %s [-%s] [types ...]\n", argv[0], opts); break; case 'l': for (i = 0; i < len; i++) puts(sizes[i].name); break; case 'v': printf("%s v %s\n", argv[0], VERSION); break; default: exit(1); } for (i = optind; i < argc; i++) if ((s = getsize(argv[i]))) { printf("%s: %d\n", argv[i], s); } else { fprintf(stderr, "%s: unknown type: %s\n", argv[0], argv[i]); exit(1); } return 0; }
void *realloc(void *ptr, size_t size) { t_reg **regs; t_reg *reg; void *new_ptr; size = getsize(size); if (!ptr) return (malloc(size)); else if (!(reg = blockregion(ptr, ®s))) return (NULL); else if (size + 2 * sizeof(size_t) <= *((size_t*)ptr - 1)) return (ptr); else if (checknext(ptr, size, reg)) { enlargeblock(ptr, size, reg); return (ptr); } else { new_ptr = malloc(size); ft_memcpy(new_ptr, ptr, *(size_t*)(ptr - sizeof(size_t)) - 2 * sizeof(size_t)); free(ptr); return (new_ptr); } return (NULL); }
void makeframe() { reshapeviewport(); getsize(&xsize,&ysize); getorigin(&xorg,&yorg); clearscreen(); }
int sysctlfs_node_getattr(struct puffs_usermount *pu, void *opc, struct vattr *va, const struct puffs_cred *pcr) { struct puffs_node *pn = opc; struct sfsnode *sfs = pn->pn_data; memset(va, 0, sizeof(struct vattr)); if (ISADIR(sfs)) { va->va_type = VDIR; va->va_mode = 0555; } else { va->va_type = VREG; va->va_mode = fileperms; } va->va_uid = fileuid; va->va_gid = filegid; va->va_nlink = getlinks(sfs, &pn->pn_po); va->va_fileid = sfs->myid; va->va_size = getsize(sfs, &pn->pn_po); va->va_gen = 1; va->va_rdev = PUFFS_VNOVAL; va->va_blocksize = 512; va->va_filerev = 1; va->va_atime = va->va_mtime = va->va_ctime = va->va_birthtime = fstime; return 0; }
static void genkeys(void) { long seedspace[numprocs]; int i; /* Create the file. */ docreate(PATH_KEYS); /* Generate random seeds for each subprocess. */ srandom(randomseed); for (i=0; i<numprocs; i++) { seedspace[i] = random(); } /* Do it. */ seeds = seedspace; doforkall("Initialization", genkeys_sub); seeds = NULL; /* Cross-check the size of the output. */ if (getsize(PATH_KEYS) != correctsize) { complainx("%s: file is wrong size", PATH_KEYS); exit(1); } /* Checksum the output. */ checksum = checksum_file(PATH_KEYS); complainx("Checksum of unsorted keys: %ld", checksum); }
static void docreate(const char *file, const char *sizespec, int doforce) { int fd; off_t size; if (!doforce) { fd = open(file, O_RDONLY); if (fd >= 0) { fprintf(stderr, "disk161: %s: %s\n", file, strerror(EEXIST)); exit(1); } } fd = doopen(file, O_RDWR|O_CREAT|O_TRUNC, 0664); doflock(file, fd, LOCK_EX); size = getsize(sizespec); checksize(size); dotruncate(file, fd, HEADERSIZE + size); writeheader(file, fd); doflock(file, fd, LOCK_UN); close(fd); }
int solve(FILE* fp){ int n = getsize(fp),i,j; float *array = (float *) malloc (((n+1)*n)*sizeof(float)); float det = 1.0; generate(array,n,fp); int flag = 0; for(j=0;j<n-1;j++){ int k=j,l; float pivot=*(array+(n)*j+j); if(abs(pivot)<=0.01){ //Swap if pivots get too small flag += rowswap(array,j,n); pivot=*(array+(n)*j+j); } for(l=k+1;l<n;l++){ float next=*(array+(n)*(l)+j)/pivot; for(i=j;i<n+1;i++) *(array+(n)*l+i)-=*(array+(n)*(k)+i)*next; } } for(i=0;i<n;i++){ float ii = *(array + n*i + i); det *= ii; } for(i=0;i<flag;i++){ det*=-1; } printf("Determinant: %f\n",det); free(array); return 0; }