int loadObjects(resource_mgr_t *resmgr) { int i; int *classes, class_count; int positions[1000]; if (objects_init(resmgr)) { #ifdef SCRIPT_DEBUG perror("objects_init"); #endif return 1; } classes = vocabulary_get_classes(resmgr, &class_count); for (i = 0; i < 1000; i++) positions[i] = 0; for (i = 0; i < class_count; i++) { #ifdef SCRIPT_DEBUG printf("\n\nReading class 0x%02X\n", i); #endif if (read_class(resmgr, classes[i], positions) == 0) { #ifdef SCRIPT_DEBUG fprintf(stderr, "Failed to load class %d, which is a parent.\n", i); #endif return 1; } } for (i = 0; i < 1000; i++) positions[i] = 0; for (i = 0; i < 1000; i++) while (read_object(resmgr, i, positions)); object_map = fobjects.data; max_object = fobjects.used; return 0; }
/* ---------------- ac_read ---------------------------------- * Given a pointer to a filename, read in the data. * This is an interface function, visible to the outside world. */ struct aa_clssfcn * ac_read (const char *fname) { FILE *fp; size_t n_class, n_att; struct aa_clssfcn *aa_clssfcn = NULL; size_t i; const char *this_sub = "ac_read"; # ifndef BUFSIZ enum {BUFSIZ = 1024}; # endif char buf [BUFSIZ]; if ((fp = mfopen (fname, "r", this_sub)) == NULL) return (NULL); if ((n_class = get_n_class (fp, buf, BUFSIZ)) == 0) goto end; if ((n_att = get_n_att (fp, buf, BUFSIZ)) == 0) goto end; aa_clssfcn = new_aa_clssfcn ( n_class, n_att); for (i = 0; i < n_class; i++) { if (read_class (fp, buf, BUFSIZ, aa_clssfcn, i, MIN_AA)==EXIT_FAILURE){ aa_clssfcn_destroy (aa_clssfcn); goto end; } } end: fclose (fp); return (aa_clssfcn); }
Class *read_class_from_file_name(char *file_name) { FILE *file = fopen(file_name, "r"); if (!file) { fprintf(stderr, "Could not open '%s': %s\n", file_name, strerror(errno)); return NULL; } // Check the file header for .class nature if (!is_class(file)) { fprintf(stderr, "Skipping '%s': not a valid class file\n", file_name); return NULL; } const ClassFile cf = {file_name, file}; return read_class(cf); }
u8int read_constant_pool(FILE* f, u16int *i, u16int *cpcount, cp_info** cpinfo) { u16int *j= (u16int*) malloc(sizeof(u16int)); s32int* integer, *i2; u8int *raw = malloc(4), *raw2 = malloc(8); cp_info* info; debugmsg("Constant pool: \n"); for(*i=0;*i < ((*cpcount)-1); (*i)++) { info = (cp_info*) malloc(sizeof(cp_info)); memset(info, 0, sizeof(cp_info)); info->tag = fgetc(f); switch(info->tag) { case CONSTANT_Class: { read_class(f, j, info); debugmsg("#%d Class #%d\n", (*i)+1, MAKE_U16( ((CONSTANT_Class_info*) info->data)->name_index )); break; } case CONSTANT_Fieldref: { read_fieldref(f, j, info); debugmsg("#%d Fieldref #%d.#%d\n", (*i)+1, MAKE_U16( ((CONSTANT_Fieldref_info*)info->data)->class_index ), MAKE_U16( ((CONSTANT_Fieldref_info*)info->data)->name_and_type_index )); break; } case CONSTANT_Methodref: { read_methodref(f, j, info); debugmsg("#%d Methodref #%d.#%d\n", (*i)+1, MAKE_U16( ((CONSTANT_Methodref_info*)info->data)->class_index ), MAKE_U16( ((CONSTANT_Methodref_info*)info->data)->name_and_type_index )); break; } case CONSTANT_InterfaceMethodref: { read_interfacemethodref(f, j, info); debugmsg("#%d InterfaceMethodref #%d.#%d\n", (*i)+1, MAKE_U16( ((CONSTANT_InterfaceMethodref_info*)info->data)->class_index ), MAKE_U16( ((CONSTANT_InterfaceMethodref_info*)info->data)->name_and_type_index )); break; } case CONSTANT_String: { read_string(f, j, info); debugmsg("#%d String #%d\n", (*i)+1, MAKE_U16( ((CONSTANT_String_info*)info->data)->string_index)); break; } case CONSTANT_Integer: { read_integer(f, j, info); MAKE_S32(raw, ((CONSTANT_Integer_info*)info->data)->bytes); integer = (s32int*) raw; debugmsg("#%d Integer %d\n", (*i) + 1, *integer); break; } case CONSTANT_Float: { read_float(f, j, info); COPY_FLOAT(raw, ((CONSTANT_Float_info*)info->data)->bytes); debugmsg("#%d Float %f\n", (*i)+1, *((float32*) raw)); break; } case CONSTANT_Long: { read_long(f, j, info); MAKE_S64(raw2, ((CONSTANT_Long_info*)info->data)->high_bytes ); debugmsg("#%d Long %ld\n", (*i)+1, *( (s64int*) raw2)); cpinfo[(*i)++] = NULL; break; } case CONSTANT_Double: { read_double(f, j, info); COPY_DOUBLE(raw2, ((CONSTANT_Double_info*) info->data)->high_bytes); debugmsg("#%d Double %f\n", (*i)+1, *( (float64*) raw2)); cpinfo[(*i)++] = NULL; break; } case CONSTANT_NameAndType: { read_nameandtype(f, j, info); debugmsg("#%d NameAndType #%d.#%d\n", (*i)+1, MAKE_U16( ((CONSTANT_NameAndType_info*) info->data)->name_index) , MAKE_U16(((CONSTANT_NameAndType_info*) info->data)->descriptor_index ) ); break; } case CONSTANT_Utf8: { read_utf8(f, j, info); debugmsg("#%d Utf8 %s\n", (*i)+1, utf8_to_cstring(((CONSTANT_Utf8_info*) info->data)->bytes)); break; } case CONSTANT_MethodHandle: { read_methodhandle(f, j, info); debugmsg("#%d MethodHandle Kind:%d #%d\n", *(i)+1, ((CONSTANT_MethodHandle_info*) info->data)->reference_kind, MAKE_U16(((CONSTANT_MethodHandle_info*) info->data)->reference_index)); break; } case CONSTANT_MethodType: { read_methodtype(f, j, info); debugmsg("#%d MethodType #%d\n", *(i)+1, MAKE_U16(((CONSTANT_MethodType_info*) info->data)->descriptor_index)); break; } case CONSTANT_InvokeDynamic: { read_invokedynamic(f,j,info); debugmsg("#%d InvokeDynamic #%d.#%d\n", *(i)+1, MAKE_U16(((CONSTANT_InvokeDynamic_info*) info->data)->bootstrap_method_attr_index), MAKE_U16(((CONSTANT_InvokeDynamic_info*) info->data)->name_and_type_index)); break; } default: { debugerr("Unrecognized tag: %02X!\n", info->tag); free(info); return 0; } } cpinfo[(*i)] = info; } debugmsg("Done reading Constant Pool\n"); free(j); free(raw); free(raw2); return 1; }
void *edu_runner(void *arg){ Runner_Arg *rarg = (Runner_Arg *) arg; int read; int fd_is_close; while(1){ // lock ; read file; int locked = pthread_mutex_lock(rarg->read_fd_lock); if (locked!=0) return error_lock("Could not lock on file : ", rarg->read_fd_lock); char *line = read_line_from_input(rarg->fd, &fd_is_close); if (!line){ if (fd_is_close){ pthread_mutex_unlock(rarg->read_fd_lock); //TODO - next step. return NULL; } return error_lock("Strange... could not allocate memory? : " , rarg->read_fd_lock); } if (pthread_mutex_unlock(rarg->read_fd_lock) != 0){ perror("Unlock :"); } char **arguments = split(line, &read); // Check arguments is clean: if (arguments == NULL ) return error_("Could not allocate in split of input line: "); if (read < 5 ){ fprintf(stderr, "Ignoring input line: %s .", line); freeArray(arguments); continue; } // return "add Education course C2 MI"; if (strcasecmp(arguments[2], "course")== 0) { if (read_course(rarg, arguments, read) != 0){ return error_(""); } else{ freeArray(arguments); continue; } } // return "add Education group T1 TurmaMEI 60"; //Create new Staff entity. if (strcasecmp(arguments[2], "group") == 0){ if (read_turma(rarg, arguments, read) != 0){ return error_("Reading arguments group: "); } else{ freeArray(arguments); continue; } } //return "add Education class 1 C1 4 LAB T1"; if (strcasecmp(arguments[2], "class") ==0){ int ret; if ((ret = read_class(rarg, arguments, read)) != 0){ return error_("Reading arguments class: "); } else { freeArray(arguments); continue; } } freeArray(arguments); //We got here. So we do not recognize this shit fprintf(stderr, "EntityType %s is not valid\n", arguments[2]); } }