//sends the buffer to the leds //render <channel>,0,AABBCCDDEEFF... //optional the colors for leds: //AABBCC are RGB colors for first led //DDEEFF is RGB for second led,... void render(char * args){ int channel=0; int r,g,b; int led_index; int size; int start; char value[MAX_VAL_LEN]; char color_string[6]; if (debug) printf("Render %s\n", args); if (ledstring.device==NULL){ printf("Error you must call setup first!\n"); return; } if (args!=NULL){ args = read_val(args, value, MAX_VAL_LEN); channel = atoi(value)-1; if (channel<0 || channel > 1) channel=0; if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); //read start position start = atoi(value); while (*args!=0 && (*args==' ' || *args==',')) args++; //skip white space if (debug) printf("Render channel %d selected start at %d leds %d\n", channel, start, ledstring.channel[channel].count); size = strlen(args); led_index = start % ledstring.channel[channel].count; while (*args!=0){ //if (debug) printf("r %d %d\n", hextable[args[0]], hextable[args[1]]); int i=0; while (*args!=0 && i<6){ if (*args!=' ' && *args!='\t'){ color_string[i]=*args; i++; } args++; } if (i==6){ r = (hextable[color_string[0]]<<4) + hextable[color_string[1]]; g = (hextable[color_string[2]]<<4) + hextable[color_string[3]]; b = (hextable[color_string[4]]<<4) + hextable[color_string[5]]; if (debug) printf(" set pixel %d to %d,%d,%d\n", led_index, r,g,b); ledstring.channel[channel].leds[led_index] = color(r,g,b); led_index += (led_index %ledstring.channel[channel].count); } } } } if (ledstring.device!=NULL) ws2811_render(&ledstring); }
//shifts all colors 1 position //rotate <channel>,<places>,<direction>,<new_color> //if new color is set then the last led will have this color instead of the color of the first led void rotate(char * args){ char value[MAX_VAL_LEN]; int channel=0, nplaces=1, direction=1, new_color=-1; if (args!=NULL){ args = read_val(args, value, MAX_VAL_LEN); channel = atoi(value)-1; if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); nplaces = atoi(value); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); direction = atoi(value); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); if (strlen(value)==6){ new_color = color((hextable[value[0]]<<4) + hextable[value[1]],(hextable[value[2]]<<4) + hextable[value[3]], (hextable[value[4]]<<4) + hextable[value[5]]); }else{ printf("Invalid color\n"); } } } } } if (debug) printf("Rotate %d %d %d %d\n", channel, nplaces, direction, new_color); int tmp,i,n; for(n=0;n<nplaces;n++){ if (direction==1){ tmp = ledstring.channel[channel].leds[0]; for(i=1;i<ledstring.channel[channel].count;i++){ ledstring.channel[channel].leds[i-1] = ledstring.channel[channel].leds[i]; } if (new_color!=-1) ledstring.channel[channel].leds[ledstring.channel[channel].count-1]=new_color; else ledstring.channel[channel].leds[ledstring.channel[channel].count-1]=tmp; }else{ tmp = ledstring.channel[channel].leds[ledstring.channel[channel].count-1]; for(i=ledstring.channel[channel].count-1;i>0;i--){ ledstring.channel[channel].leds[i] = ledstring.channel[channel].leds[i-1]; } if (new_color!=-1) ledstring.channel[channel].leds[0]=new_color; else ledstring.channel[channel].leds[0]=tmp; } } }
int ddr_init( void ) { // tell dramc to configure set_val( P1MEMCCMD, 0x4 ); // set refresh period set_val( P1REFRESH, nstoclk(7800) ); // set timing para set_val( P1CASLAT, ( 3 << 1 ) ); set_val( P1T_DQSS, 0x1 ); // 0.75 - 1.25 set_val( P1T_MRD, 0x2 ); set_val( P1T_RAS, nstoclk(45) ); set_val( P1T_RC, nstoclk(68) ); unsigned int trcd = nstoclk( 23 ); set_val( P1T_RCD, trcd | (( trcd - 3 ) << 3 ) ); unsigned int trfc = nstoclk( 80 ); set_val( P1T_RFC, trfc | ( ( trfc-3 ) << 5 ) ); unsigned int trp = nstoclk( 23 ); set_val( P1T_RP, trp | ( ( trp - 3 ) << 3 ) ); set_val( P1T_RRD, nstoclk(15) ); set_val( P1T_WR, nstoclk(15) ); set_val( P1T_WTR, 0x7 ); set_val( P1T_XP, 0x2 ); set_val( P1T_XSR, nstoclk(120) ); set_val( P1T_ESR, nstoclk(120) ); // set mem cfg set_nbit( P1MEMCFG, 0, 3, 0x2 ); /* 10 column address */ /* set_nbit: 把从第bit位开始的一共len位消零,然后把这几位设为val */ set_nbit( P1MEMCFG, 3, 3, 0x3 ); /* 14 row address */ set_zero( P1MEMCFG, 6 ); /* A10/AP */ set_nbit( P1MEMCFG, 15, 3, 0x2 ); /* Burst 4 */ set_nbit( P1MEMCFG2, 0, 4, 0x5 ); set_2bit( P1MEMCFG2, 6, 0x1 ); /* 32 bit */ set_nbit( P1MEMCFG2, 8, 3, 0x3 ); /* Mobile DDR SDRAM */ set_2bit( P1MEMCFG2, 11, 0x1 ); set_one( P1_chip_0_cfg, 16 ); /* Bank-Row-Column organization */ // memory init set_val( P1DIRECTCMD, 0xc0000 ); // NOP set_val( P1DIRECTCMD, 0x000 ); // precharge set_val( P1DIRECTCMD, 0x40000 );// auto refresh set_val( P1DIRECTCMD, 0x40000 );// auto refresh set_val( P1DIRECTCMD, 0xa0000 ); // EMRS set_val( P1DIRECTCMD, 0x80032 ); // MRS set_val( MEM_SYS_CFG, 0x0 ); // set dramc to "go" status set_val( P1MEMCCMD, 0x000 ); // wait ready while( !(( read_val( P1MEMSTAT ) & 0x3 ) == 0x1)); }
static int find_i(T *thiz, mkey_t *key, mval_t *v, mkv_t *tkv) { int r, i; hdr_block_t *hdr; off_t off; fkv_t fkv; fkv.kv = tkv; RWLOCK_READ(LOCK); r = krange_cmp(thiz, key); if (r != 0) { r = RC_NOT_FOUND; goto _out; } hdr = thiz->hdr; off = (hdr->node_cnt - 1) * BTR_INDEX_BLK_SIZE; /* root off */ for (i = 0; i < hdr->tree_heigh; i++) { off = find_in_index(thiz, off, key, NULL); if (off <= 0) { r = RC_NOT_FOUND; goto _out; } off = off - (off_t)(hdr->leaf_off); } r = find_in_leaf(thiz, off, key, &fkv, NULL); if (r != 0) { r = RC_NOT_FOUND; goto _out; } if (v != NULL) { v->len = tkv->v.len; v->data = MY_Malloc(v->len); r = read_val(thiz->rfd, fkv.blkoff, fkv.voff, v); if (r != 0) { r = RC_ERR; MY_Free(v->data); goto _out; } tkv->v.data = v->data; check_fval(thiz->rfd, tkv); } r = RC_FOUND; DEBUG("hit %.*s in %s", (int)key->len, key->data, thiz->file); _out: RWUNLOCK(LOCK); return r; }
//fills leds with certain color //fill <channel>,<color>,<start>,<len> void fill(char * args){ char value[MAX_VAL_LEN]; int channel=0, fill_color=0,start=0,len=-1; if (args!=NULL){ args = read_val(args, value, MAX_VAL_LEN); channel = atoi(value)-1; if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); if (strlen(value)==6){ fill_color = color((hextable[value[0]]<<4) + hextable[value[1]],(hextable[value[2]]<<4) + hextable[value[3]], (hextable[value[4]]<<4) + hextable[value[5]]); }else{ printf("Invalid color\n"); } if (debug) printf(args); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); start = atoi(value); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); len = atoi(value); } } } } if (channel!=0 && channel!=1) channel=0; if (len<=0 || len>ledstring.channel[channel].count) len=ledstring.channel[channel].count; if (start<0 || start>=ledstring.channel[channel].count) start=0; if (debug) printf("fill %d,%d,%d,%d\n", channel, fill_color, start, len); int i; for (i=start;i<start+len;i++){ ledstring.channel[channel].leds[i]=fill_color; } }
//dims leds (adjust brightness of all on channel) //brightness <channel>,<brightness> (brightness: 0-255) void brightness(char * args){ char value[MAX_VAL_LEN]; int channel=0, brightness=255; if (args!=NULL){ args = read_val(args, value, MAX_VAL_LEN); channel = atoi(value)-1; if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); brightness = atoi(value); } } if (channel!=0 && channel!=1) channel=0; if (brightness<0 || brightness>0xFF) brightness=255; if (debug) printf("Changing brightness %d, %d\n", channel, brightness); ledstring.channel[channel].brightness=brightness; }
int cw_ktv_parse_string(struct cw_KTV_Reader *r, char *key, char *type, char *val) { int n; n = read_key (r,key,CW_KTV_MAX_KEY_LEN); n = read_type(r,type,200); if (n==1) return -1; n = read_val(r,val,200); return n; }
//fills pixels with rainbow effect //count tells how many rainbows you want //rainbow <channel>,<count>,<start>,<stop> //start and stop = color values on color wheel (0-255) void rainbow(char * args) { char value[MAX_VAL_LEN]; int channel=0, count=1,start=0,stop=255; if (args!=NULL){ args = read_val(args, value, MAX_VAL_LEN); channel = atoi(value)-1; if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); count = atoi(value); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); start = atoi(value); if (*args!=0){ args++; args = read_val(args, value, MAX_VAL_LEN); stop = atoi(value); } } } } if (channel!=0 && channel!=1) channel=0; if (start<0 || start > 255) start=0; if (stop<0 || stop > 255) stop = 255; if (debug) printf("Rainbow %d,%d\n", channel, count); int numPixels = ledstring.channel[channel].count; int i, j; for(i=0; i<numPixels; i++) { ledstring.channel[channel].leds[i] = deg2color(abs(stop-start) * i * count / numPixels + start); } }
/* Read a timestamp from [*BUF, END) stopping at the terminator. Set *RESULT to the resulting timestamp, or 0 if there is none. Use POOL for temporary allocations. Make *BUF point after the terminator. */ static svn_error_t * read_time(apr_time_t *result, char **buf, const char *end, apr_pool_t *pool) { const char *val; SVN_ERR(read_val(&val, buf, end)); if (val) SVN_ERR(svn_time_from_cstring(result, val, pool)); else *result = 0; return SVN_NO_ERROR; }
int main() { char buf[83]; char* p; int len; double a, b; gtop=0; while(fgets(buf, 82, stdin)) { p = buf; while((len = tokenize(p))) { switch(*p) { case ' ': break; case '*': b = pop(); a = pop(); push(a*b); break; case '+': b = pop(); a = pop(); push(a+b); break; case '/': b = pop(); a = pop(); push(a/b); break; case '-': if(len == 1) { b = pop(); a = pop(); push(a-b); break; } /* fall through */ default: push(read_val(p, len)); break; } p+=len; } assert(gtop==1); printf("%f\n",pop()); assert(gtop==0); } return 0; }
/* Read a revision number from [*BUF, END) stopping at the terminator. Set *RESULT to the revision number, or SVN_INVALID_REVNUM if there is none. Use POOL for temporary allocations. Make *BUF point after the terminator. */ static svn_error_t * read_revnum(svn_revnum_t *result, char **buf, const char *end, apr_pool_t *pool) { const char *val; SVN_ERR(read_val(&val, buf, end)); if (val) *result = SVN_STR_TO_REV(val); else *result = SVN_INVALID_REVNUM; return SVN_NO_ERROR; }
/* Read a boolean field from [*BUF, END), placing the result in *RESULT. If there is no boolean value (just a terminator), it defaults to false. Else, the value must match FIELD_NAME, in which case *RESULT will be set to true. Advance *BUF to point after the terminator. */ static svn_error_t * read_bool(svn_boolean_t *result, const char *field_name, char **buf, const char *end) { const char *val; SVN_ERR(read_val(&val, buf, end)); if (val) { if (strcmp(val, field_name) != 0) return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL, _("Invalid value for field '%s'"), field_name); *result = TRUE; } else *result = FALSE; return SVN_NO_ERROR; }
GHashTable* mu_str_parse_arglist (const char *args, GError **err) { GHashTable *hash; const char *cur; g_return_val_if_fail (args, NULL); hash = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); cur = args; while ((isblank(*cur))) ++cur; do { char *key, *val; const char *valstart, *valend; key = read_key (cur, &valstart, err); if (!key) goto errexit; val = read_val (valstart, &valend, err); if (!val) goto errexit; /* g_print ("%s->%s\n", key, val); */ g_hash_table_insert (hash, key, val); cur = valend; while ((isblank(*cur))) ++cur; } while (*cur); return hash; errexit: g_hash_table_destroy (hash); return NULL; }
int extract_fval(int fd, fkv_t *fkv) { int r; if (fkv->kv->type & KV_OP_DEL) { ASSERT(fkv->kv->v.len == 0); return 0; } fkv->kv->v.data = MY_Malloc(fkv->kv->v.len); r = read_val(fd, fkv->blkoff, fkv->voff, &fkv->kv->v); if (r != 0) { MY_Free(fkv->kv->v.data); return -1; } fkv->kv->type |= KV_VTP_FROM_FILE; check_fval(fd, fkv->kv); return 0; }
int main(){ _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); int istep, nstep, outp_size; double t, tmax; std::string name("state"); read_grid("KIRPICH.GRD"); read_val("initval"); read_opt("opt", nstep, tmax, outp_size); if(!recover("schG1.ini", istep, t)){istep = 0; t = 0;} show(name); while(istep < nstep || t < tmax){ step(t); istep++; std::stringstream ss; ss<<istep; std::string s(name); s.append(ss.str()); show(s); } free_all(); return 0; }
int chaco_input_graph( ZOLTAN_FILE *fin, /* input file */ char *inname, /* name of input file */ int **start, /* start of edge list for each vertex */ int **adjacency, /* edge list data */ int *nvtxs, /* number of vertices in graph */ int *vwgt_dim, /* # of vertex weights per node */ float **vweights, /* vertex weight list data */ int *ewgt_dim, /* # of edge weights per edge */ float **eweights /* edge weight list data */ ) { const char *yo = "chaco_input_graph"; int *adjptr; /* loops through adjacency data */ float *ewptr; /* loops through edge weight data */ int narcs; /* number of edges expected in graph */ int nedges; /* twice number of edges really in graph */ int nedge; /* loops through edges for each vertex */ int flag; /* condition indicator */ int found_flag; /* is vertex found in adjacency list? */ int skip_flag; /* should this edge be ignored? */ int end_flag; /* indicates end of line or file */ int vtx; /* vertex in graph */ int line_num; /* line number in input file */ int sum_edges; /* total number of edges read so far */ int option = 0; /* input option */ int using_ewgts; /* are edge weights in input file? */ int using_vwgts; /* are vertex weights in input file? */ int vtxnums; /* are vertex numbers in input file? */ int vertex; /* current vertex being read */ int new_vertex; /* new vertex being read */ float weight; /* weight being read */ float eweight; /* edge weight being read */ int neighbor; /* neighbor of current vertex */ int self_edge; /* is a self edge encountered? */ int ignore_me; /* is this edge being ignored? */ int ignored; /* how many edges are ignored? */ int error_flag; /* error reading input? */ int j; /* loop counters */ DEBUG_TRACE_START(0, yo); /* Read first line of input (= nvtxs, narcs, option). */ /* The (decimal) digits of the option variable mean: 1's digit not zero => input edge weights 10's digit not zero => input vertex weights 100's digit not zero => include vertex numbers */ *start = NULL; *adjacency = NULL; *vweights = NULL; *eweights = NULL; error_flag = 0; line_num = 0; /* Read any leading comment lines */ end_flag = 1; while (end_flag == 1) { *nvtxs = read_int(fin, &end_flag); ++line_num; } if (*nvtxs <= 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of vertices (%d).\n", *nvtxs); ZOLTAN_FILE_close(fin); return(1); } narcs = read_int(fin, &end_flag); if (narcs < 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of expected edges (%d).\n", narcs); ZOLTAN_FILE_close(fin); return(1); } /* Check if vertex or edge weights are used */ if (!end_flag) { option = read_int(fin, &end_flag); } using_ewgts = option - 10 * (option / 10); option /= 10; using_vwgts = option - 10 * (option / 10); option /= 10; vtxnums = option - 10 * (option / 10); /* Get weight dimensions from Chaco option */ (*vwgt_dim) = using_vwgts; (*ewgt_dim) = using_ewgts; /* Read weight dimensions if they are specified separately */ if (!end_flag && using_vwgts==1){ j = read_int(fin, &end_flag); if (!end_flag) (*vwgt_dim) = j; } if (!end_flag && using_ewgts==1){ j = read_int(fin, &end_flag); if (!end_flag) (*ewgt_dim) = j; } /* Discard rest of line */ while (!end_flag) j = read_int(fin, &end_flag); /* Allocate space for rows and columns. */ *start = (int *) malloc((unsigned) (*nvtxs + 1) * sizeof(int)); if (narcs != 0) *adjacency = (int *) malloc((unsigned) (2 * narcs + 1) * sizeof(int)); else *adjacency = NULL; if (using_vwgts) *vweights = (float *) malloc((unsigned) (*nvtxs) * (*vwgt_dim) * sizeof(float)); else *vweights = NULL; if (using_ewgts) *eweights = (float *) malloc((unsigned) (2 * narcs + 1) * (*ewgt_dim) * sizeof(float)); else *eweights = NULL; adjptr = *adjacency; ewptr = *eweights; self_edge = 0; ignored = 0; sum_edges = 0; nedges = 0; (*start)[0] = 0; vertex = 0; vtx = 0; new_vertex = TRUE; while ((using_vwgts || vtxnums || narcs) && end_flag != -1) { ++line_num; /* If multiple input lines per vertex, read vertex number. */ if (vtxnums) { j = read_int(fin, &end_flag); if (end_flag) { if (vertex == *nvtxs) break; printf("ERROR in graph file `%s':", inname); printf(" no vertex number in line %d.\n", line_num); ZOLTAN_FILE_close(fin); return (1); } if (j != vertex && j != vertex + 1) { printf("ERROR in graph file `%s':", inname); printf(" out-of-order vertex number in line %d.\n", line_num); ZOLTAN_FILE_close(fin); return (1); } if (j != vertex) { new_vertex = TRUE; vertex = j; } else new_vertex = FALSE; } else vertex = ++vtx; if (vertex > *nvtxs) break; /* If vertices are weighted, read vertex weight. */ if (using_vwgts && new_vertex) { for (j=0; j<(*vwgt_dim); j++){ weight = read_val(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" not enough weights for vertex %d.\n", vertex); ZOLTAN_FILE_close(fin); return (1); } if ((weight < 0) && Debug_Chaco_Input) { printf("ERROR in graph file `%s':", inname); printf(" negative weight entered for vertex %d.\n", vertex); ZOLTAN_FILE_close(fin); return (1); } (*vweights)[(vertex-1)*(*vwgt_dim)+j] = weight; } } nedge = 0; /* Read number of adjacent vertex. */ neighbor = read_int(fin, &end_flag); while (!end_flag) { skip_flag = FALSE; ignore_me = FALSE; if (Debug_Chaco_Input){ if (neighbor > *nvtxs) { printf("ERROR in graph file `%s':", inname); printf(" nvtxs=%d, but edge (%d,%d) was input.\n", *nvtxs, vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (neighbor < 0) { printf("ERROR in graph file `%s':", inname); printf(" negative vertex in edge (%d,%d).\n", vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (neighbor == vertex) { if (!self_edge && Debug_Chaco_Input) { printf("WARNING: Self edge (%d, %d) being ignored.\n", vertex, vertex); } skip_flag = TRUE; ++self_edge; } /* Check if adjacency is repeated. */ if (!skip_flag) { found_flag = FALSE; for (j = (*start)[vertex - 1]; !found_flag && j < sum_edges + nedge; j++) { if ((*adjacency)[j] == neighbor) found_flag = TRUE; } if (found_flag) { printf("WARNING: Multiple occurences of edge (%d,%d) ignored\n", vertex, neighbor); skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } } } if (using_ewgts) { /* Read edge weight if it's being input. */ for (j=0; j<(*ewgt_dim); j++){ eweight = read_val(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" not enough weights for edge (%d,%d).\n", vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (eweight <= 0 && Debug_Chaco_Input) { printf("WARNING: Bad weight entered for edge (%d,%d). Edge ignored.\n", vertex, neighbor); skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } else { *ewptr++ = eweight; } } } if (Debug_Chaco_Input){ /* Check for edge only entered once. */ if (neighbor < vertex && !skip_flag) { found_flag = FALSE; for (j = (*start)[neighbor - 1]; !found_flag && j < (*start)[neighbor]; j++) { if ((*adjacency)[j] == vertex) found_flag = TRUE; } if (!found_flag) { printf("ERROR in graph file `%s':", inname); printf(" Edge (%d, %d) entered but not (%d, %d)\n", vertex, neighbor, neighbor, vertex); error_flag = 1; } } } /* Add edge to data structure. */ if (!skip_flag) { if (++nedges > 2*narcs) { printf("ERROR in graph file `%s':", inname); printf(" at least %d adjacencies entered, but nedges = %d\n", nedges, narcs); ZOLTAN_FILE_close(fin); return (1); } *adjptr++ = neighbor; nedge++; } /* Read number of next adjacent vertex. */ neighbor = read_int(fin, &end_flag); } sum_edges += nedge; (*start)[vertex] = sum_edges; } /* Make sure there's nothing else in file. */ flag = FALSE; while (!flag && end_flag != -1) { read_int(fin, &end_flag); if (!end_flag) flag = TRUE; } if (flag && Debug_Chaco_Input) { printf("WARNING: Possible error in graph file `%s'\n", inname); printf(" Data found after expected end of file\n"); } (*start)[*nvtxs] = sum_edges; if (self_edge > 1 && Debug_Chaco_Input) { printf("WARNING: %d self edges were read and ignored.\n", self_edge); } if (vertex != 0) { /* Normal file was read. */ /* Make sure narcs was reasonable. */ if (nedges + 2 * self_edge != 2 * narcs && nedges + 2 * self_edge + ignored != 2 * narcs && nedges + self_edge != 2 * narcs && nedges + self_edge + ignored != 2 * narcs && nedges != 2 * narcs && nedges + ignored != 2 * narcs && Debug_Chaco_Input) { printf("WARNING: I expected %d edges entered twice, but I only count %d.\n", narcs, nedges); } } else { /* Graph was empty */ free(*start); if (*adjacency != NULL) free(*adjacency); if (*vweights != NULL) free(*vweights); if (*eweights != NULL) free(*eweights); *start = NULL; *adjacency = NULL; } ZOLTAN_FILE_close(fin); DEBUG_TRACE_END(0, yo); return (error_flag); }
/* Given the heap dump data and the utf8 map, check/write the heap dump. */ static int check_heap_tags(struct LookupTable *utab, unsigned char *pstart, int nbytes) { int nrecords; unsigned char *p; unsigned char *psave; struct LookupTable *ctab; CmapInfo cmap; char *label; unsigned tag; HprofType ty; HprofId id, id2, fr, sup; int num_elements; int num_bytes; SerialNumber trace_serial_num; SerialNumber thread_serial_num; int npos; int i; int inst_size; ctab = table_initialize("temp ctab", 64, 64, 512, sizeof(CmapInfo)); /* First pass over heap records just fills in the CmapInfo table */ nrecords = 0; p = pstart; while ( p < (pstart+nbytes) ) { nrecords++; /*LINTED*/ npos = (int)(p - pstart); tag = read_u1(&p); switch ( tag ) { CASE_HEAP(HPROF_GC_ROOT_UNKNOWN) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL) id = read_id(&p); id2 = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK) id = read_id(&p); thread_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK) id = read_id(&p); thread_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ) id = read_id(&p); thread_serial_num = read_u4(&p); trace_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_CLASS_DUMP) (void)memset((void*)&cmap, 0, sizeof(cmap)); id = read_id(&p); trace_serial_num = read_u4(&p); { HprofId ld, si, pr, re1, re2; sup = read_id(&p); ld = read_id(&p); si = read_id(&p); pr = read_id(&p); re1 = read_id(&p); re2 = read_id(&p); cmap.sup = sup; } inst_size = read_u4(&p); cmap.inst_size = inst_size; num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { (void)read_u2(&p); ty = read_u1(&p); (void)read_val(&p, ty); } num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { (void)read_id(&p); ty = read_u1(&p); (void)read_val(&p, ty); } num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; id = read_id(&p); ty = read_u1(&p); add_inst_field_to_cmap(&cmap, id, ty); } (void)table_create_entry(ctab, &id, sizeof(id), &cmap); break; CASE_HEAP(HPROF_GC_INSTANCE_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); id2 = read_id(&p); /* class id */ num_bytes = read_u4(&p); p += num_bytes; break; CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); num_elements = read_u4(&p); id2 = read_id(&p); p += num_elements*(int)sizeof(HprofId); break; CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); num_elements = read_u4(&p); ty = read_u1(&p); p += type_size[ty]*num_elements; break; default: label = "UNKNOWN"; check_printf("H#%d@%d %s: ERROR!\n", nrecords, npos, label); HPROF_ERROR(JNI_TRUE, "unknown heap record type"); break; } } CHECK_FOR_ERROR(p==pstart+nbytes); /* Scan again once we have our cmap */ nrecords = 0; p = pstart; while ( p < (pstart+nbytes) ) { nrecords++; /*LINTED*/ npos = (int)(p - pstart); tag = read_u1(&p); switch ( tag ) { CASE_HEAP(HPROF_GC_ROOT_UNKNOWN) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL) id = read_id(&p); id2 = read_id(&p); check_printf("H#%d@%d %s: id=0x%x, id2=0x%x\n", nrecords, npos, label, id, id2); break; CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n", nrecords, npos, label, id, thread_serial_num, fr); break; CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n", nrecords, npos, label, id, thread_serial_num, fr); break; CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK) id = read_id(&p); thread_serial_num = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num); break; CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK) id = read_id(&p); thread_serial_num = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num); break; CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ) id = read_id(&p); thread_serial_num = read_u4(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u," " trace_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num, trace_serial_num); break; CASE_HEAP(HPROF_GC_CLASS_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u\n", nrecords, npos, label, id, trace_serial_num); { HprofId ld, si, pr, re1, re2; sup = read_id(&p); ld = read_id(&p); si = read_id(&p); pr = read_id(&p); re1 = read_id(&p); re2 = read_id(&p); check_printf(" su=0x%x, ld=0x%x, si=0x%x," " pr=0x%x, re1=0x%x, re2=0x%x\n", sup, ld, si, pr, re1, re2); } inst_size = read_u4(&p); check_printf(" instance_size=%d\n", inst_size); num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { HprofType ty; unsigned cpi; jvalue val; cpi = read_u2(&p); ty = read_u1(&p); val = read_val(&p, ty); check_printf(" constant_pool %d: cpi=%d, ty=%d, val=", i, cpi, ty); check_printf_val(ty, val, 1); check_printf("\n"); } num_elements = read_u2(&p); check_printf(" static_field_count=%d\n", num_elements); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; jvalue val; id = read_id(&p); ty = read_u1(&p); val = read_val(&p, ty); check_printf(" static field %d: ", i); check_print_utf8(utab, "id=", id); check_printf(", ty=%d, val=", ty); check_printf_val(ty, val, 1); check_printf("\n"); } num_elements = read_u2(&p); check_printf(" instance_field_count=%d\n", num_elements); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; id = read_id(&p); ty = read_u1(&p); check_printf(" instance_field %d: ", i); check_print_utf8(utab, "id=", id); check_printf(", ty=%d\n", ty); } break; CASE_HEAP(HPROF_GC_INSTANCE_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); id2 = read_id(&p); /* class id */ num_bytes = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u," " cid=0x%x, nbytes=%d\n", nrecords, npos, label, id, trace_serial_num, id2, num_bytes); /* This is a packed set of bytes for the instance fields */ if ( num_bytes > 0 ) { TableIndex cindex; int ifield; CmapInfo *map; cindex = table_find_entry(ctab, &id2, sizeof(id2)); HPROF_ASSERT(cindex!=0); map = (CmapInfo*)table_get_info(ctab, cindex); HPROF_ASSERT(map!=NULL); HPROF_ASSERT(num_bytes==map->inst_size); psave = p; ifield = 0; do { for(i=0;i<map->n_finfo;i++) { HprofType ty; HprofId id; jvalue val; ty = map->finfo[i].ty; id = map->finfo[i].id; HPROF_ASSERT(ty!=0); HPROF_ASSERT(id!=0); val = read_val(&p, ty); check_printf(" field %d: ", ifield); check_print_utf8(utab, "id=", id); check_printf(", ty=%d, val=", ty); check_printf_val(ty, val, 1); check_printf("\n"); ifield++; } id2 = map->sup; map = NULL; cindex = 0; if ( id2 != 0 ) { cindex = table_find_entry(ctab, &id2, sizeof(id2)); HPROF_ASSERT(cindex!=0); map = (CmapInfo*)table_get_info(ctab, cindex); HPROF_ASSERT(map!=NULL); } } while ( map != NULL ); HPROF_ASSERT(num_bytes==(p-psave)); } break; CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); num_elements = read_u4(&p); id2 = read_id(&p); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, nelems=%d, eid=0x%x\n", nrecords, npos, label, id, trace_serial_num, num_elements, id2); for(i=0; i<num_elements; i++) { HprofId id; id = read_id(&p); check_printf(" [%d]: id=0x%x\n", i, id); } break; CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); num_elements = read_u4(&p); ty = read_u1(&p); psave = p; check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, " "nelems=%d, ty=%d\n", nrecords, npos, label, id, trace_serial_num, num_elements, ty); HPROF_ASSERT(HPROF_TYPE_IS_PRIMITIVE(ty)); if ( num_elements > 0 ) { int count; int long_form; int max_count; char *quote; quote = ""; long_form = 1; max_count = 8; count = 0; switch ( ty ) { case HPROF_CHAR: long_form = 0; max_count = 72; quote = "\""; /*FALLTHRU*/ case HPROF_INT: case HPROF_DOUBLE: case HPROF_LONG: case HPROF_BYTE: case HPROF_BOOLEAN: case HPROF_SHORT: case HPROF_FLOAT: check_printf(" val=%s", quote); for(i=0; i<num_elements; i++) { jvalue val; if ( i > 0 && count == 0 ) { check_printf(" %s", quote); } val = read_val(&p, ty); check_printf_val(ty, val, long_form); count += 1; if ( count >= max_count ) { check_printf("\"\n"); count = 0; } } if ( count != 0 ) { check_printf("%s\n", quote); } break; } } HPROF_ASSERT(type_size[ty]*num_elements==(p-psave)); break; default: label = "UNKNOWN"; check_printf("H#%d@%d %s: ERROR!\n", nrecords, npos, label); HPROF_ERROR(JNI_TRUE, "unknown heap record type"); break; } } CHECK_FOR_ERROR(p==pstart+nbytes); table_cleanup(ctab, &cmap_cleanup, NULL); return nrecords; }
/* Read and parse an old-style 'entries' file in the administrative area of PATH, filling in ENTRIES with the contents. The results will be allocated in RESULT_POOL, and temporary allocations will be made in SCRATCH_POOL. */ svn_error_t * svn_wc__read_entries_old(apr_hash_t **entries, const char *dir_abspath, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { char *curp; const char *endp; svn_wc_entry_t *entry; svn_stream_t *stream; svn_string_t *buf; *entries = apr_hash_make(result_pool); /* Open the entries file. */ SVN_ERR(svn_wc__open_adm_stream(&stream, dir_abspath, SVN_WC__ADM_ENTRIES, scratch_pool, scratch_pool)); SVN_ERR(svn_string_from_stream(&buf, stream, scratch_pool, scratch_pool)); /* We own the returned data; it is modifiable, so cast away... */ curp = (char *)buf->data; endp = buf->data + buf->len; /* If the first byte of the file is not a digit, then it is probably in XML format. */ if (curp != endp && !svn_ctype_isdigit(*curp)) SVN_ERR(parse_entries_xml(dir_abspath, *entries, buf->data, buf->len, result_pool, scratch_pool)); else { int entryno, entries_format; const char *val; /* Read the format line from the entries file. In case we're in the middle of upgrading a working copy, this line will contain the original format pre-upgrade. */ SVN_ERR(read_val(&val, &curp, endp)); if (val) entries_format = (int)apr_strtoi64(val, NULL, 0); else return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL, _("Invalid version line in entries file " "of '%s'"), svn_dirent_local_style(dir_abspath, scratch_pool)); entryno = 1; while (curp != endp) { svn_error_t *err = read_entry(&entry, &curp, endp, entries_format, result_pool); if (! err) { /* We allow extra fields at the end of the line, for extensibility. */ curp = memchr(curp, '\f', endp - curp); if (! curp) err = svn_error_create(SVN_ERR_WC_CORRUPT, NULL, _("Missing entry terminator")); if (! err && (curp == endp || *(++curp) != '\n')) err = svn_error_create(SVN_ERR_WC_CORRUPT, NULL, _("Invalid entry terminator")); } if (err) return svn_error_createf(err->apr_err, err, _("Error at entry %d in entries file for " "'%s':"), entryno, svn_dirent_local_style(dir_abspath, scratch_pool)); ++curp; ++entryno; svn_hash_sets(*entries, entry->name, entry); } } /* Fill in any implied fields. */ return svn_error_trace(resolve_to_defaults(*entries, result_pool)); }
void daemonize(void) { int v_ret; pid_t v_pid; char v_name[128]; char v_buf[512]; struct inotify_event iev; struct sigaction actions; v_pid = fork(); if(v_pid > 0) { exit(0); } sprintf(v_buf,"emw820w_tool (%s) daemonizing ...\n", g_vers); logging(ANDROID_LOG_ERROR, v_buf); g_loop=1; close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = sighdl; sigaction(SIGTERM,& actions, NULL); g_ifd = inotify_init(); if(g_ifd < 0) { sprintf(v_buf,"inotify_init() error %d\n", errno); logging(ANDROID_LOG_ERROR, v_buf); exit(1); } logging(ANDROID_LOG_DEBUG, "entering watchdog mode ...\n"); if(get_mode() != 1404) { set_1404(); sleep(2); } read_val("/sys/bus/usb/devices/1-1/power/autosuspend", g_curval); while(g_loop == 1) { getport(v_name); g_wfd = inotify_add_watch(g_ifd, v_name, IN_DELETE_SELF); if(g_wfd < 0) { sprintf(v_buf,"watchdog: inotify_add_watch() error %d\n", errno); logging(ANDROID_LOG_ERROR, v_buf); sleep(2); } else { sprintf(v_buf,"watchdog for %s initialized\n", v_name); logging(ANDROID_LOG_DEBUG, v_buf); iev.mask = 0; while(iev.mask != IN_DELETE_SELF) { v_ret=read(g_ifd, &iev, sizeof(iev)); if(g_loop == 0) { break; } } v_ret = inotify_rm_watch(g_ifd, g_wfd); if(g_loop == 1) { sleep(5); if((v_ret = get_mode()) != 1404) { logging(ANDROID_LOG_DEBUG,"3G crash detected!\n"); logging(ANDROID_LOG_DEBUG,"activating wakelock\n"); v_ret = write_val("/sys/power/wake_lock", "em820w_tool\n"); while (v_ret != 1404) { set_1404(); sleep(10); v_ret = get_mode(); } logging(ANDROID_LOG_DEBUG,"deactivating wakelock\n"); v_ret = write_val("/sys/power/wake_unlock", "em820w_tool\n"); } sleep(2); } } } logging(ANDROID_LOG_DEBUG,"exiting...\n"); close(g_wfd); close(g_ifd); exit(0); }
//initializes the ws2811 driver code //setup freq=400,dma=5,channels=1,channel_1_gpio=18,channel_1_invert=0,channel_1_count=250,channel_1_brightness=255,channel_2_... void setup_ledstring(char * args){ char key[MAX_KEY_LEN], value[MAX_VAL_LEN]; int key_index, value_index; if (ledstring.device!=NULL) ws2811_fini(&ledstring); ledstring.device = NULL; ledstring.freq = WS2811_TARGET_FREQ; ledstring.dmanum = 5; ledstring.channel[0].gpionum = 18; ledstring.channel[0].invert = 0; ledstring.channel[0].count = 1; ledstring.channel[0].brightness = 255; ledstring.channel[1].gpionum = 0; ledstring.channel[1].invert = 0; ledstring.channel[1].count = 0; ledstring.channel[1].brightness = 0; //char * key = strtok(args, " ="); //char c = args; if (debug) printf("Setup\n"); if (args!=NULL){ while (*args){ //first we get the key args = read_key(args, key,MAX_KEY_LEN); if (*args!=0) *args++; //now read the value part args = read_val(args, value,MAX_VAL_LEN); if (*args!=0) *args++; if (debug) printf("Setting %s=%s\n", key, value); if (strlen(key)>0 && strlen(value) > 0){ if (strcmp(key,"freq")==0){ ledstring.freq = atoi(value); }else if (strcmp(key, "dma")==0){ ledstring.dmanum = atoi(value); }else if (strcmp(key, "channels")==0){ if (value[0]=='1'){ ledstring.channel[1].gpionum=0; ledstring.channel[1].invert = 0; ledstring.channel[1].count = 0; ledstring.channel[1].brightness = 0; }else{ ledstring.channel[1].gpionum=0; ledstring.channel[1].invert = 0; ledstring.channel[1].count = 1; ledstring.channel[1].brightness = 255; } }else if (strcmp(key, "channel_1_gpio")==0){ ledstring.channel[0].gpionum=atoi(value); }else if (strcmp(key, "channel_1_invert")==0){ ledstring.channel[0].invert=atoi(value); }else if (strcmp(key, "channel_1_count")==0){ ledstring.channel[0].count=atoi(value); }else if (strcmp(key, "channel_1_brightness")==0){ ledstring.channel[0].brightness=atoi(value); }else if (strcmp(key, "channel_2_gpio")==0){ ledstring.channel[1].gpionum=atoi(value); }else if (strcmp(key, "channel_2_invert")==0){ ledstring.channel[1].invert=atoi(value); }else if (strcmp(key, "channel_2_count")==0){ ledstring.channel[1].count=atoi(value); }else if (strcmp(key, "channel_2_brightness")==0){ ledstring.channel[1].brightness=atoi(value); } } //args++; } } int size = ledstring.channel[0].count; if (ledstring.channel[1].count> size) size= ledstring.channel[1].count; malloc_command_line(DEFAULT_COMMAND_LINE_SIZE + size * 6); //allocate memory for full render data if (ws2811_init(&ledstring)){ perror("Initialization failed.\n"); return; } }
int main() { int fd = open(bri_name, O_WRONLY); if ( fd < 0) { perror(bri_name); return 1; } char buff[10]; int notquit = 1, val= read_val(bri_name), max = read_val("/sys/class/backlight/s3c/max_brightness"); if ( max <= 0) return 1; GR_WINDOW_ID wid; /* window id */ GR_GC_ID gc; /* graphics context id */ GR_EVENT event; /* current event */ GR_SCREEN_INFO si; /* screen information */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); return 1; } GrGetScreenInfo(&si); printf("R=%d C=%d\n", si.rows, si.cols); wid = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 50, max, HEIGHT, 1, BLACK, WHITE); GR_WM_PROPERTIES props; props.title = "Nx Light"; props.flags = GR_WM_FLAGS_TITLE; GrSetWMProperties( wid, &props); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN ); GrMapWindow(wid); gc = GrNewGC(); while (notquit) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_MOUSE_MOTION: if ( !((GR_EVENT_MOUSE *)&event)->buttons ) break; if ( (event.mouse.x > 0) && (event.mouse.x < max)) { snprintf(buff, 9, "%d\n", val = event.mouse.x); write( fd, buff, strlen(buff)); } GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_EXPOSURE: if (event.exposure.wid == wid) GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_CLOSE_REQ: notquit = 0; } } close(fd); return 0; }
int chaco_input_geom( ZOLTAN_FILE *fingeom, /* geometry input file */ char *geomname, /* name of geometry file */ int nvtxs, /* number of coordinates to read */ int *igeom, /* dimensionality of geometry */ float **x, /* coordinates of vertices */ float **y, float **z ) { const char *yo = "chaco_input_geom"; float xc, yc, zc =0; /* first x, y, z coordinate */ int nread; /* number of lines of coordinates read */ int flag; /* any bad data at end of file? */ int line_num; /* counts input lines in file */ int end_flag; /* return conditional */ int ndims; /* number of values in an input line */ int i=0; /* loop counter */ DEBUG_TRACE_START(0, yo); *x = *y = *z = NULL; line_num = 0; end_flag = 1; while (end_flag == 1) { xc = read_val(fingeom, &end_flag); ++line_num; } if (end_flag == -1) { printf("No values found in geometry file `%s'\n", geomname); ZOLTAN_FILE_close(fingeom); return (1); } ndims = 1; yc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 2; zc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 3; read_val(fingeom, &end_flag); if (!end_flag) { printf("Too many values on input line of geometry file `%s'\n", geomname); printf(" Maximum dimensionality is 3\n"); ZOLTAN_FILE_close(fingeom); return (1); } } } *igeom = ndims; *x = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*x)[0] = xc; if (ndims > 1) { *y = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*y)[0] = yc; } if (ndims > 2) { *z = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*z)[0] = zc; } for (nread = 1; nread < nvtxs; nread++) { ++line_num; if (ndims == 1) { i = ZOLTAN_FILE_scanf(fingeom, "%f", &((*x)[nread])); } else if (ndims == 2) { i = ZOLTAN_FILE_scanf(fingeom, "%f%f", &((*x)[nread]), &((*y)[nread])); } else if (ndims == 3) { i = ZOLTAN_FILE_scanf(fingeom, "%f%f%f", &((*x)[nread]), &((*y)[nread]), &((*z)[nread])); } if (i == EOF) { printf("Too few lines of values in geometry file; nvtxs=%d, but only %d read\n", nvtxs, nread); ZOLTAN_FILE_close(fingeom); return (1); } else if (i != ndims) { printf("Wrong number of values in line %d of geometry file `%s'\n", line_num, geomname); ZOLTAN_FILE_close(fingeom); return (1); } } /* Check for spurious extra stuff in file. */ flag = 0; end_flag = 0; while (!flag && end_flag != -1) { read_val(fingeom, &end_flag); if (!end_flag) flag = 1; } if (flag && Debug_Chaco_Input) { printf("Warning: possible error in geometry file `%s'\n", geomname); printf(" Numerical data found after expected end of file\n"); } ZOLTAN_FILE_close(fingeom); DEBUG_TRACE_END(0, yo); return (0); }
int input_graph(FILE *fin, char *inname, int **start, int **adjacency, int *nvtxs, int **vweights, float **eweights) /* * FILE *fin; input file * char *inname; name of input file * int **start; start of edge list for each vertex * int **adjacency; edge list data * int *nvtxs; number of vertices in graph * int **vweights; vertex weight list data * float **eweights; edge weight list data */ { extern FILE *Output_File; /* output file or null */ extern int CHECK_INPUT; /* print warnings or not? */ extern int DEBUG_INPUT; /* echo that input file read successful? */ extern int DEBUG_TRACE; /* trace main execution path */ int *adjptr; /* loops through adjacency data */ float *ewptr; /* loops through edge weight data */ int narcs; /* number of edges expected in graph */ int nedges; /* twice number of edges really in graph */ int nedge; /* loops through edges for each vertex */ int flag; /* condition indicator */ int found_flag; /* is vertex found in adjacency list? */ int skip_flag; /* should this edge be ignored? */ int end_flag; /* indicates end of line or file */ int vtx; /* vertex in graph */ int line_num; /* line number in input file */ int sum_edges; /* total number of edges read so far */ int option=0; /* input option */ int using_ewgts; /* are edge weights in input file? */ int using_vwgts; /* are vertex weights in input file? */ int vtxnums; /* are vertex numbers in input file? */ int vertex; /* current vertex being read */ int new_vertex; /* new vertex being read */ int weight; /* weight being read */ float eweight; /* edge weight being read */ int neighbor; /* neighbor of current vertex */ int self_edge; /* is a self edge encountered? */ int ignore_me; /* is this edge being ignored? */ int ignored; /* how many edges are ignored? */ int error_flag; /* error reading input? */ int j; /* loop counters */ int read_int(); double read_val(); if (DEBUG_TRACE > 0) { printf("<Entering input_graph>\n"); } /* Read first line of input (= nvtxs, narcs, option). */ /* The (decimal) digits of the option variable mean: 1's digit not zero => input edge weights 10's digit not zero => input vertex weights 100's digit not zero => include vertex numbers */ *start = NULL; *adjacency = NULL; *vweights = NULL; *eweights = NULL; error_flag = 0; line_num = 0; /* Read any leading comment lines */ end_flag = 1; while (end_flag == 1) { *nvtxs = read_int(fin, &end_flag); ++line_num; } if (*nvtxs <= 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of vertices (%d).\n", *nvtxs); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " Invalid number of vertices (%d).\n", *nvtxs); } fclose(fin); return(1); } narcs = read_int(fin, &end_flag); if (narcs < 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of expected edges (%d).\n", narcs); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " Invalid number of expected edges (%d).\n", narcs); } fclose(fin); return(1); } if (!end_flag) { option = read_int(fin, &end_flag); } while (!end_flag) j = read_int(fin, &end_flag); using_ewgts = option - 10 * (option / 10); option /= 10; using_vwgts = option - 10 * (option / 10); option /= 10; vtxnums = option - 10 * (option / 10); /* Allocate space for rows and columns. */ *start = smalloc((*nvtxs + 1) * sizeof(int)); if (narcs != 0) *adjacency = smalloc((2 * narcs + 1) * sizeof(int)); else *adjacency = NULL; if (using_vwgts) *vweights = smalloc((*nvtxs) * sizeof(int)); else *vweights = NULL; if (using_ewgts && narcs != 0) *eweights = smalloc((2 * narcs + 1) * sizeof(float)); else *eweights = NULL; adjptr = *adjacency; ewptr = *eweights; self_edge = 0; ignored = 0; sum_edges = 0; nedges = 0; (*start)[0] = 0; vertex = 0; vtx = 0; new_vertex = TRUE; while ((narcs || using_vwgts || vtxnums) && end_flag != -1) { ++line_num; /* If multiple input lines per vertex, read vertex number. */ if (vtxnums) { j = read_int(fin, &end_flag); if (end_flag) { if (vertex == *nvtxs) break; printf("ERROR in graph file `%s':", inname); printf(" no vertex number in line %d.\n", line_num); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " no vertex number in line %d.\n", line_num); } fclose(fin); return (1); } if (j != vertex && j != vertex + 1) { printf("ERROR in graph file `%s':", inname); printf(" out-of-order vertex number in line %d.\n", line_num); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " out-of-order vertex number in line %d.\n", line_num); } fclose(fin); return (1); } if (j != vertex) { new_vertex = TRUE; vertex = j; } else new_vertex = FALSE; } else vertex = ++vtx; if (vertex > *nvtxs) break; /* If vertices are weighted, read vertex weight. */ if (using_vwgts && new_vertex) { weight = read_int(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" no weight for vertex %d.\n", vertex); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " no weight for vertex %d.\n", vertex); } fclose(fin); return (1); } if (weight <= 0) { printf("ERROR in graph file `%s':", inname); printf(" zero or negative weight entered for vertex %d.\n", vertex); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " zero or negative weight entered for vertex %d.\n", vertex); } fclose(fin); return (1); } (*vweights)[vertex-1] = weight; } nedge = 0; /* Read number of adjacent vertex. */ neighbor = read_int(fin, &end_flag); while (!end_flag) { skip_flag = FALSE; ignore_me = FALSE; if (neighbor > *nvtxs) { printf("ERROR in graph file `%s':", inname); printf(" nvtxs=%d, but edge (%d,%d) was input.\n", *nvtxs, vertex, neighbor); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " nvtxs=%d, but edge (%d,%d) was input.\n", *nvtxs, vertex, neighbor); } fclose(fin); return (1); } if (neighbor <= 0) { printf("ERROR in graph file `%s':", inname); printf(" zero or negative vertex in edge (%d,%d).\n", vertex, neighbor); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " zero or negative vertex in edge (%d,%d).\n", vertex, neighbor); } fclose(fin); return (1); } if (neighbor == vertex) { if (!self_edge && CHECK_INPUT) { printf("WARNING: Self edge (%d, %d) being ignored.\n", vertex, vertex); if (Output_File != NULL) { fprintf(Output_File, "WARNING: Self edge (%d, %d) being ignored.\n", vertex, vertex); } } skip_flag = TRUE; ++self_edge; } /* Check if adjacency is repeated. */ if (!skip_flag) { found_flag = FALSE; for (j = (*start)[vertex - 1]; !found_flag && j < sum_edges + nedge; j++) { if ((*adjacency)[j] == neighbor) found_flag = TRUE; } if (found_flag) { printf("WARNING: Multiple occurences of edge (%d,%d) ignored\n", vertex, neighbor); if (Output_File != NULL) { fprintf(Output_File, "WARNING: Multiple occurences of edge (%d,%d) ignored\n", vertex, neighbor); } skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } } if (using_ewgts) { /* Read edge weight if it's being input. */ eweight = read_val(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" no weight for edge (%d,%d).\n", vertex, neighbor); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " no weight for edge (%d,%d).\n", vertex, neighbor); } fclose(fin); return (1); } if (eweight <= 0 && CHECK_INPUT) { printf("WARNING: Bad weight entered for edge (%d,%d). Edge ignored.\n", vertex, neighbor); if (Output_File != NULL) { fprintf(Output_File, "WARNING: Bad weight entered for edge (%d,%d). Edge ignored.\n", vertex, neighbor); } skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } else { *ewptr++ = eweight; } } /* Check for edge only entered once. */ if (neighbor < vertex && !skip_flag) { found_flag = FALSE; for (j = (*start)[neighbor - 1]; !found_flag && j < (*start)[neighbor]; j++) { if ((*adjacency)[j] == vertex) found_flag = TRUE; } if (!found_flag) { printf("ERROR in graph file `%s':", inname); printf(" Edge (%d, %d) entered but not (%d, %d)\n", vertex, neighbor, neighbor, vertex); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " Edge (%d, %d) entered but not (%d, %d)\n", vertex, neighbor, neighbor, vertex); } error_flag = 1; } } /* Add edge to data structure. */ if (!skip_flag) { if (++nedges > 2*narcs) { printf("ERROR in graph file `%s':", inname); printf(" at least %d adjacencies entered, but nedges = %d\n", nedges, narcs); if (Output_File != NULL) { fprintf(Output_File, "ERROR in graph file `%s':", inname); fprintf(Output_File, " at least %d adjacencies entered, but nedges = %d\n", nedges, narcs); } fclose(fin); return (1); } *adjptr++ = neighbor; nedge++; } /* Read number of next adjacent vertex. */ neighbor = read_int(fin, &end_flag); } sum_edges += nedge; (*start)[vertex] = sum_edges; } /* Make sure there's nothing else in file. */ flag = FALSE; while (!flag && end_flag != -1) { read_int(fin, &end_flag); if (!end_flag) flag = TRUE; } if (flag && CHECK_INPUT) { printf("WARNING: Possible error in graph file `%s'\n", inname); printf(" Data found after expected end of file\n"); if (Output_File != NULL) { fprintf(Output_File, "WARNING: Possible error in graph file `%s'\n", inname); fprintf(Output_File, " Data found after expected end of file\n"); } } (*start)[*nvtxs] = sum_edges; if (self_edge > 1 && CHECK_INPUT) { printf("WARNING: %d self edges were read and ignored.\n", self_edge); if (Output_File != NULL) { fprintf(Output_File, "WARNING: %d self edges were read and ignored.\n", self_edge); } } if (vertex != 0) { /* Normal file was read. */ /* Make sure narcs was reasonable. */ if (nedges + 2 * self_edge != 2 * narcs && nedges + 2 * self_edge + ignored != 2 * narcs && nedges + self_edge != 2 * narcs && nedges + self_edge + ignored != 2 * narcs && nedges != 2 * narcs && nedges + ignored != 2 * narcs && CHECK_INPUT) { printf("WARNING: I expected %d edges entered twice, but I only count %d.\n", narcs, nedges); if (Output_File != NULL) { fprintf(Output_File, "WARNING: I expected %d edges entered twice, but I only count %d.\n", narcs, nedges); } } } else { /* Graph was empty => must be using inertial method. */ sfree(*start); if (*adjacency != NULL) sfree(*adjacency); if (*eweights != NULL) sfree(*eweights); *start = NULL; *adjacency = NULL; } fclose(fin); if (DEBUG_INPUT > 0) { printf("Done reading graph file `%s'.\n", inname); } return (error_flag); }
/* Allocate an entry from POOL and read it from [*BUF, END). The buffer may be modified in place while parsing. Return the new entry in *NEW_ENTRY. Advance *BUF to point at the end of the entry record. The entries file format should be provided in ENTRIES_FORMAT. */ static svn_error_t * read_entry(svn_wc_entry_t **new_entry, char **buf, const char *end, int entries_format, apr_pool_t *pool) { svn_wc_entry_t *entry = alloc_entry(pool); const char *name; #define MAYBE_DONE if (**buf == '\f') goto done /* Find the name and set up the entry under that name. */ SVN_ERR(read_path(&name, buf, end, pool)); entry->name = name ? name : SVN_WC_ENTRY_THIS_DIR; /* Set up kind. */ { const char *kindstr; SVN_ERR(read_val(&kindstr, buf, end)); if (kindstr) { if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0) entry->kind = svn_node_file; else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0) entry->kind = svn_node_dir; else return svn_error_createf (SVN_ERR_NODE_UNKNOWN_KIND, NULL, _("Entry '%s' has invalid node kind"), (name ? name : SVN_WC_ENTRY_THIS_DIR)); } else entry->kind = svn_node_none; } MAYBE_DONE; /* Attempt to set revision (resolve_to_defaults may do it later, too) */ SVN_ERR(read_revnum(&entry->revision, buf, end, pool)); MAYBE_DONE; /* Attempt to set up url path (again, see resolve_to_defaults). */ SVN_ERR(read_url(&entry->url, buf, end, entries_format, pool)); MAYBE_DONE; /* Set up repository root. Make sure it is a prefix of url. */ SVN_ERR(read_url(&entry->repos, buf, end, entries_format, pool)); if (entry->repos && entry->url && ! svn_uri__is_ancestor(entry->repos, entry->url)) return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL, _("Entry for '%s' has invalid repository " "root"), name ? name : SVN_WC_ENTRY_THIS_DIR); MAYBE_DONE; /* Look for a schedule attribute on this entry. */ { const char *schedulestr; SVN_ERR(read_val(&schedulestr, buf, end)); entry->schedule = svn_wc_schedule_normal; if (schedulestr) { if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0) entry->schedule = svn_wc_schedule_add; else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0) entry->schedule = svn_wc_schedule_delete; else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0) entry->schedule = svn_wc_schedule_replace; else return svn_error_createf( SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL, _("Entry '%s' has invalid 'schedule' value"), name ? name : SVN_WC_ENTRY_THIS_DIR); } } MAYBE_DONE; /* Attempt to set up text timestamp. */ SVN_ERR(read_time(&entry->text_time, buf, end, pool)); MAYBE_DONE; /* Checksum. */ SVN_ERR(read_str(&entry->checksum, buf, end, pool)); MAYBE_DONE; /* Setup last-committed values. */ SVN_ERR(read_time(&entry->cmt_date, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_revnum(&entry->cmt_rev, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_str(&entry->cmt_author, buf, end, pool)); MAYBE_DONE; /* has-props, has-prop-mods, cachable-props, present-props are all deprecated. Read any values that may be in the 'entries' file, but discard them, and just put default values into the entry. */ { const char *unused_value; /* has-props flag. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->has_props = FALSE; MAYBE_DONE; /* has-prop-mods flag. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->has_prop_mods = FALSE; MAYBE_DONE; /* Use the empty string for cachable_props, indicating that we no longer attempt to cache any properties. An empty string for present_props means that no cachable props are present. */ /* cachable-props string. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->cachable_props = ""; MAYBE_DONE; /* present-props string. */ SVN_ERR(read_val(&unused_value, buf, end)); entry->present_props = ""; MAYBE_DONE; } /* Is this entry in a state of mental torment (conflict)? */ { SVN_ERR(read_path(&entry->prejfile, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_old, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_new, buf, end, pool)); MAYBE_DONE; SVN_ERR(read_path(&entry->conflict_wrk, buf, end, pool)); MAYBE_DONE; } /* Is this entry copied? */ SVN_ERR(read_bool(&entry->copied, ENTRIES_BOOL_COPIED, buf, end)); MAYBE_DONE; SVN_ERR(read_url(&entry->copyfrom_url, buf, end, entries_format, pool)); MAYBE_DONE; SVN_ERR(read_revnum(&entry->copyfrom_rev, buf, end, pool)); MAYBE_DONE; /* Is this entry deleted? */ SVN_ERR(read_bool(&entry->deleted, ENTRIES_BOOL_DELETED, buf, end)); MAYBE_DONE; /* Is this entry absent? */ SVN_ERR(read_bool(&entry->absent, ENTRIES_BOOL_ABSENT, buf, end)); MAYBE_DONE; /* Is this entry incomplete? */ SVN_ERR(read_bool(&entry->incomplete, ENTRIES_BOOL_INCOMPLETE, buf, end)); MAYBE_DONE; /* UUID. */ SVN_ERR(read_str(&entry->uuid, buf, end, pool)); MAYBE_DONE; /* Lock token. */ SVN_ERR(read_str(&entry->lock_token, buf, end, pool)); MAYBE_DONE; /* Lock owner. */ SVN_ERR(read_str(&entry->lock_owner, buf, end, pool)); MAYBE_DONE; /* Lock comment. */ SVN_ERR(read_str(&entry->lock_comment, buf, end, pool)); MAYBE_DONE; /* Lock creation date. */ SVN_ERR(read_time(&entry->lock_creation_date, buf, end, pool)); MAYBE_DONE; /* Changelist. */ SVN_ERR(read_str(&entry->changelist, buf, end, pool)); MAYBE_DONE; /* Keep entry in working copy after deletion? */ SVN_ERR(read_bool(&entry->keep_local, ENTRIES_BOOL_KEEP_LOCAL, buf, end)); MAYBE_DONE; /* Translated size */ { const char *val; /* read_val() returns NULL on an empty (e.g. default) entry line, and entry has already been initialized accordingly already */ SVN_ERR(read_val(&val, buf, end)); if (val) entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0); } MAYBE_DONE; /* Depth. */ { const char *result; SVN_ERR(read_val(&result, buf, end)); if (result) { svn_boolean_t invalid; svn_boolean_t is_this_dir; entry->depth = svn_depth_from_word(result); /* Verify the depth value: THIS_DIR should not have an excluded value and SUB_DIR should only have excluded value. Remember that infinity value is not stored and should not show up here. Otherwise, something bad may have happened. However, infinity value itself will always be okay. */ is_this_dir = !name; /* '!=': XOR */ invalid = is_this_dir != (entry->depth != svn_depth_exclude); if (entry->depth != svn_depth_infinity && invalid) return svn_error_createf( SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL, _("Entry '%s' has invalid 'depth' value"), name ? name : SVN_WC_ENTRY_THIS_DIR); } else entry->depth = svn_depth_infinity; } MAYBE_DONE; /* Tree conflict data. */ SVN_ERR(read_str(&entry->tree_conflict_data, buf, end, pool)); MAYBE_DONE; /* File external URL and revision. */ { const char *str; SVN_ERR(read_str(&str, buf, end, pool)); SVN_ERR(svn_wc__unserialize_file_external(&entry->file_external_path, &entry->file_external_peg_rev, &entry->file_external_rev, str, pool)); } MAYBE_DONE; done: *new_entry = entry; return SVN_NO_ERROR; }
int input_geom ( FILE *fingeom, /* geometry input file */ char *geomname, /* name of geometry file */ int nvtxs, /* number of coordinates to read */ int *igeom, /* dimensionality of geometry */ float **x, float **y, float **z /* coordiates of vertices */ ) { extern int CHECK_INPUT; /* print any warning messages? */ extern int DEBUG_INPUT; /* echo that read was successful? */ extern int DEBUG_TRACE; /* trace main execution path */ float xc, yc, zc; /* first x, y, z coordinate */ int nread; /* number of lines of coordinates read */ int flag; /* any bad data at end of file? */ int line_num; /* counts input lines in file */ int end_flag; /* return conditional */ int ndims; /* number of values in an input line */ int i=0; /* loop counter */ double read_val(); if (DEBUG_TRACE > 0) { printf("<Entering input_geom>\n"); } *x = *y = *z = NULL; line_num = 0; end_flag = 1; while (end_flag == 1) { xc = read_val(fingeom, &end_flag); ++line_num; } if (end_flag == -1) { printf("No values found in geometry file `%s'\n", geomname); fclose(fingeom); return (1); } ndims = 1; yc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 2; zc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 3; read_val(fingeom, &end_flag); if (!end_flag) { printf("Too many values on input line of geometry file `%s'\n", geomname); printf(" Maximum dimensionality is 3\n"); fclose(fingeom); return (1); } } } *igeom = ndims; *x = smalloc(nvtxs * sizeof(float)); (*x)[0] = xc; if (ndims > 1) { *y = smalloc(nvtxs * sizeof(float)); (*y)[0] = yc; } if (ndims > 2) { *z = smalloc(nvtxs * sizeof(float)); (*z)[0] = zc; } for (nread = 1; nread < nvtxs; nread++) { ++line_num; if (ndims == 1) { i = fscanf(fingeom, "%f", &((*x)[nread])); } else if (ndims == 2) { i = fscanf(fingeom, "%f%f", &((*x)[nread]), &((*y)[nread])); } else if (ndims == 3) { i = fscanf(fingeom, "%f%f%f", &((*x)[nread]), &((*y)[nread]), &((*z)[nread])); } if (i == EOF) { printf("Too few lines of values in geometry file; nvtxs=%d, but only %d read\n", nvtxs, nread + 1); fclose(fingeom); return (1); } else if (i != ndims) { printf("Wrong number of values in line %d of geometry file `%s'\n", line_num, geomname); fclose(fingeom); return (1); } } /* Check for spurious extra stuff in file. */ flag = FALSE; end_flag = 0; while (!flag && end_flag != -1) { read_val(fingeom, &end_flag); if (!end_flag) flag = TRUE; } if (flag && CHECK_INPUT) { printf("Warning: possible error in geometry file `%s'\n", geomname); printf(" Numerical data found after expected end of file\n"); } fclose(fingeom); if (DEBUG_INPUT > 0) { printf("Finished reading geometry file `%s'; dimension = %d.\n", geomname, ndims); } return (0); }