void process_files(Dllist dir_list, JRB inode, JRB paths, char *name, JRB links){ int dup_inode, dup_path; char buf[PATH_MAX+1]; tar *t; dup_inode = 1; dup_path = 1; t = (tar*) malloc(sizeof(tar)); strcpy(t->name,realpath(name, buf)); if(lstat(t->name, &t->istat) < 0){ fprintf(stderr,"ERROR: %s No such file or directory\n",t->name); exit(1); } if(jrb_find_str(paths,realpath(t->name,buf)) != NULL){ //my problem could be here dup_path = 0; jrb_insert_str(links,strdup(name), new_jval_v(jrb_find_str(paths,realpath(t->name,buf)))); // printf("Ignoring Duplicate %s\n",t->name); } if(jrb_find_int(inode, t->istat.st_ino) != NULL){ dup_inode = 0; // jrb_insert_str(links,strdup(t->name), // new_jval_v(jrb_find_str(paths,realpath(t->name,buf)))); // printf("Ignoring Duplicate %s\n",t->name); } if(dup_path && dup_inode) { jrb_insert_str(paths,strdup(realpath(t->name,buf)),new_jval_v(t)); jrb_insert_int(inode,(int)t->istat.st_ino,new_jval_v(t)); } if(S_ISDIR(t->istat.st_mode)){ trav_dir(dir_list, inode, paths, name); } }
void set_file(char *name) { JRB entry; if (!*name) name = "<stdin>"; entry = jrb_find_str(file_names,name); if (entry) name = jval_v(jrb_val(entry)); else { name = stralloc(name); jrb_insert_str(file_names,name,new_jval_v(name)); } current_loc.file = name; current_loc.line = 1; }
void BFS_Visit(Graph_Struct Graph,char start[]) { Graph_Symbol_Table *Table; char *u,*v; JRB node_rbt,tree,ele; Dllist node_queue,queue = new_dllist(); printf("%s ",start); u = malloc(MAX_LENGTH_STRING); v = malloc(MAX_LENGTH_STRING); Table = Search_On_Table(Graph,start); Table->colour = 'g'; dll_append(queue, new_jval_s(start)); while(!dll_empty(queue)) { node_queue = dll_first(queue); u = jval_s(node_queue->val); dll_delete_node(node_queue); node_rbt = jrb_find_str(Graph.Edges,u); if(node_rbt != NULL) { tree = (JRB)jval_v(node_rbt->val); jrb_traverse(ele,tree) { v = jval_s(ele->key); Table = Search_On_Table(Graph,v); if(Table->colour == 'w') { printf("%s ",v); Table->colour = 'g'; if(Table->previous == NULL) { Table->previous = malloc(MAX_LENGTH_STRING); } strcpy(Table->previous,u); dll_append(queue, new_jval_s(v)); } } }
static char *get_scopename(void *xc, FILE *extload) { static char sbuff[65537]; char * rc; #ifdef _WAVE_HAVE_JUDY PPvoid_t PPValue; #else JRB str; Jval jv; #endif for(;;) { rc = fgets(sbuff, 65536, extload); if(rc) { if(isspace(rc[0])) { char sbuff2[65537]; sbuff2[0] = 0; if(strstr(rc+1, "Struct Name:")) { sscanf(rc+14,"%s", sbuff2); if(sbuff2[0]) { sprintf(rc, "Scope: vcd_struct %s NULL\n", sbuff2); } } else if(strstr(rc+1, "Struct End")) { sprintf(rc, "Upscope:\n"); } } } else { return(NULL); } if(rc[0] == 'V') { if(!strncmp("Var: ", rc, 5)) { char *pnt = rc + 5; char *pntd = strrchr(pnt, ':'); if(pntd) { unsigned char vd = FST_VD_IMPLICIT; pntd = strchr(pntd, ' '); if(pntd) { pntd++; if(*pntd == 'o') { vd = FST_VD_OUTPUT; } else if(!strncmp(pntd, "in", 2)) { vd = (pntd[2] == 'p') ? FST_VD_INPUT : FST_VD_INOUT; } } var_direction[var_direction_idx++] = vd; } } } else if(rc[0] == 'S') { if(!strncmp(rc, "Scope:", 6)) { char vht[2048]; char cname[2048]; char ctype[2048]; int mtype = FST_ST_VCD_MODULE; cname[0] = ctype[1] = 0; sscanf(rc+6, "%s %s %s", vht, cname, ctype+1); if(!strncmp("vcd_", vht, 4)) { switch(vht[4]) { case 'g': mtype = FST_ST_VCD_GENERATE; break; /* other code looks for non-modules to replace type with */ case 's': mtype = FST_ST_VCD_STRUCT; break; /* other code looks for non-modules to replace type with */ default: break; } } else if(!strncmp("sv_", vht, 3)) { switch(vht[3]) { case 'i': mtype = FST_ST_VCD_INTERFACE; break; /* other code looks for non-modules to replace type with */ default: break; } } else if(!strncmp(vht, "vhdl_", 5)) { switch(vht[5]) { case 'a': mtype = FST_ST_VHDL_ARCHITECTURE; break; case 'r': mtype = FST_ST_VHDL_RECORD; break; case 'b': mtype = FST_ST_VHDL_BLOCK; break; case 'g': mtype = FST_ST_VHDL_GENERATE; break; case 'i': mtype = FST_ST_VHDL_IF_GENERATE; break; case 'f': mtype = (vht[6] == 'u') ? FST_ST_VHDL_FUNCTION : FST_ST_VHDL_FOR_GENERATE; break; case 'p': mtype = (!strncmp(vht+6, "roces", 5)) ? FST_ST_VHDL_PROCESS: FST_ST_VHDL_PROCEDURE; break; default: break; } } ctype[0] = mtype + 1; /* bias for zero terminated string */ fst_scope_name = fstReaderPushScope(xc, cname, NULL); /* process fst_scope_name + cname vs ctype here */ if((strcmp(ctype+1, "NULL") && strcmp(cname, ctype+1)) || (mtype != FST_ST_VCD_MODULE)) { #ifdef _WAVE_HAVE_JUDY PPValue = JudySLIns(&PJArray, (uint8_t *)fst_scope_name, PJE0); if(!*((char **)PPValue)) { *((char **)PPValue) = strdup(ctype); } #else char cstring[65537]; strcpy(cstring, fst_scope_name); str = jrb_find_str(comp_name_jrb, cstring); if(!str) { jv.s = strdup(ctype); jrb_insert_str(comp_name_jrb, strdup(cstring), jv); } #endif } } } else if(rc[0] == 'U') { fst_scope_name = fstReaderPopScope(xc); } } return(rc); }
main(int argc, char **argv) { IS is; JRB people, tmp; JRB elevators; double t; Elevator *e; char name[100]; Person *p; elevators = make_jrb(); people = make_jrb(); is = new_inputstruct(NULL); while (get_line(is) > 0) { sscanf(is->fields[0], "%lf", &t); if (strcmp(is->fields[1], "Elevator") == 0) { e = get_elevator(atoi(is->fields[2]), elevators); if (strcmp(is->fields[3], "opening") == 0) { if (e->door != 0) { printf("Line %d: Elevator %d opening a door that's already open\n", is->line, e->id); exit(1); } if (e->state == 'O') { printf("Line %d: Elevator %d opening a door twice\n", is->line, e->id); exit(1); } if (e->state == 'C') { printf("Line %d: Elevator %d opening a door that is closing\n", is->line, e->id); exit(1); } e->state = 'O'; e->time = t; } else if (strcmp(is->fields[3], "closing") == 0) { if (e->door != 1) { printf("Line %d: Elevator %d closing a door that's already closed\n", is->line, e->id); exit(1); } if (e->state == 'C') { printf("Line %d: Elevator %d closing a door twice\n", is->line, e->id); exit(1); } if (e->state == 'O') { printf("Line %d: Elevator %d closing a door that is opening\n", is->line, e->id); exit(1); } e->state = 'C'; e->time = t; } else if (strcmp(is->fields[5], "closed.") == 0) { if (e->state != 'C') { printf("Line %d: Elevator %d closed a door that was not closing.\n", is->line, e->id); exit(1); } e->state = 'R'; e->door = 0; e->time = t; } else if (strcmp(is->fields[5], "open.") == 0) { if (e->state != 'O') { printf("Line %d: Elevator %d opened a door that was not opening.\n", is->line, e->id); exit(1); } e->state = 'R'; e->door = 1; e->time = t; } else if (strcmp(is->fields[3], "moving") == 0) { if (e->state != 'R') { printf("Line %d: Elevator %d moving from a non-rest state.\n", is->line, e->id); exit(1); } if (e->door != 0) { printf("Line %d: Elevator %d moving when the door is open.\n", is->line, e->id); exit(1); } if (atoi(is->fields[6]) != e->floor) { printf("Line %d: Elevator %d moving from a bad floor.\n", is->line, e->id); exit(1); } e->floor = atoi(is->fields[9]); e->state = 'M'; e->time = t; } else if (strcmp(is->fields[3], "arrives") == 0) { if (e->state != 'M') { printf("Line %d: Elevator %d arriving from a non-moving state.\n", is->line, e->id); exit(1); } if (e->door != 0) { printf("Line %d: Elevator %d arriving when the door is open.\n", is->line, e->id); exit(1); } if (atoi(is->fields[6]) != e->floor) { printf("Line %d: Elevator %d arriving at the wrong floor (%d).\n", is->line, e->id, e->floor); exit(1); } e->state = 'R'; e->time = t; } } else if (strcmp(is->fields[1], "Simulation") == 0) { exit(0); } else { sprintf(name, "%s %s", is->fields[1], is->fields[2]); if (strcmp(is->fields[3], "arrives") == 0) { if (jrb_find_str(people, name) != NULL) { printf("%d: Duplicate person %s\n", is->line, name); exit(1); } p = talloc(Person, 1); p->name = strdup(name); jrb_insert_str(people, p->name, new_jval_v((void *) p)); p->from = atoi(is->fields[6]); p->to = atoi(is->fields[12]); p->state = 'A'; } else { tmp = jrb_find_str(people, name); if (tmp == NULL) { printf("Line %d: Person %s doesn't exist\n", is->line, name); exit(1); } p = (Person *) tmp->val.v; if (strcmp(is->fields[4], "on") == 0) { if (p->state != 'A') { printf("Line %d: Person %s not in arriving state when getting on an elevator\n", is->line, p->name); exit(1); } if (atoi(is->fields[9]) != p->from) { printf("Line %d: Person %s not getting on the proper floor\n", is->line, p->name); exit(1); } e = get_elevator(atoi(is->fields[6]), elevators); if (e->floor != p->from) { printf("Line %d: Person %s getting on an elevator not on the right floor\n", is->line, p->name); exit(1); } if (e->door != 1) { printf("Line %d: Person %s getting on an elevator whose door isn't open.\n", is->line, p->name); exit(1); } if (e->state != 'R') { printf("Line %d: Person %s getting on an elevator who is not at rest.\n", is->line, p->name); exit(1); } p->state = 'O'; p->e = e; } else if (strcmp(is->fields[4], "off") == 0) { if (p->state != 'O') { printf("Line %d: Person %s not on the elevator when getting off\n", is->line, p->name); exit(1); } if (atoi(is->fields[9]) != p->to) { printf("Line %d: Person %s not getting off on the proper floor\n", is->line, p->name); exit(1); } e = get_elevator(atoi(is->fields[6]), elevators); if (e != p->e) { printf("Line %d: Person %s getting off the wrong elevator\n", is->line, p->name); exit(1); } if (e->floor != p->to) { printf("Line %d: Person %s getting off an elevator not on the right floor\n", is->line, p->name); exit(1); } if (e->door != 1) { printf("Line %d: Person %s getting off an elevator whose door isn't open.\n", is->line, p->name); exit(1); } if (e->state != 'R') { printf("Line %d: Person %s getting off an elevator who is not at rest.\n", is->line, p->name); exit(1); } p->state = 'F'; } else if (strcmp(is->fields[4], "done.") == 0) { if (p->state != 'F') { printf("Line %d: Person %s done before getting off the elevator\n", is->line, p->name); exit(1); } jrb_delete_node(tmp); free(p->name); free(p); } } } } exit(0); }