void read() { int cluster_id = 0; int new_cluster_id = 0; int argument_pointer = 0; int prev_pointer = 0; int empty_index = 0; int entry_id = 0; int file_size = 0; while (argument[argument_pointer] != 0) { prev_pointer = argument_pointer; argument_pointer += basename(argument + argument_pointer, filename); argument_pointer += 1; // skip "/" } prev_pointer -= 1; while (prev_pointer < argument_pointer) { argument[prev_pointer] = 0; prev_pointer += 1; } if (resolve_argument_path(argument[ARGUMENT_HEAP_SIZE-1], argument, resolve_result) == -1) { copy_string(argument, file_not_found_error_message); return; } directory_id = resolve_result[2]; entry_id = find_entry_by_name(directory_id, filename); if (entry_id == ENTRY_NOT_FOUND_ID) { buffer[0] = EOF; file_id = 0; } else { file_id = get_cluster_id(directory_id, entry_id); file_size = get_file_size(directory_id, entry_id); read_file(file_id, file_size, file_content); { int line = 0; int column = 0; int ptr = 0; int got_newline = 0; initialize_array(buffer, 2400, 0); while (ptr < file_size) { buffer[C(line, column)] = file_content[ptr]; if (file_content[ptr] == '\n') { line += 1; column = 0; } else { column += 1; } ptr += 1; } buffer[C(line, column)] = EOF; } } }
int commonio_remove(struct commonio_db *db, const char *name) { struct commonio_entry *p; if (!db->isopen || db->readonly) { errno = EINVAL; return 0; } p = find_entry_by_name(db, name); if (!p) { errno = ENOENT; return 0; } commonio_del_entry(db, p); if (p->line) free(p->line); if (p->eptr) db->ops->free(p->eptr); return 1; }
void get_bin_cluster_id() { int root_entry = 0; int entry_id = find_entry_by_name(root_entry, bin_token); if (entry_id == ENTRY_NOT_FOUND_ID) { put_char('n'); put_char('o'); put_char(' '); put_char('b'); put_char('i'); put_char('n'); return; } bin_cluster_id = get_cluster_id(root_entry, entry_id); }
const void * commonio_locate(struct commonio_db *db, const char *name) { struct commonio_entry *p; if (!db->isopen) { errno = EINVAL; return NULL; } p = find_entry_by_name(db, name); if (!p) { errno = ENOENT; return NULL; } db->cursor = p; return p->eptr; }
int commonio_update(struct commonio_db *db, const void *eptr) { struct commonio_entry *p; void *nentry; if (!db->isopen || db->readonly) { errno = EINVAL; return 0; } if (!(nentry = db->ops->dup(eptr))) { errno = ENOMEM; return 0; } p = find_entry_by_name(db, db->ops->getname(eptr)); if (p) { db->ops->free(p->eptr); p->eptr = nentry; p->changed = 1; db->cursor = p; db->changed = 1; return 1; } /* not found, new entry */ p = (struct commonio_entry *) malloc(sizeof *p); if (!p) { db->ops->free(nentry); errno = ENOMEM; return 0; } p->eptr = nentry; p->line = NULL; p->changed = 1; #if KEEP_NIS_AT_END add_one_entry_nis(db, p); #else add_one_entry(db, p); #endif db->changed = 1; return 1; }
void execute_bin(char * program, char * argument) { int entry_id = find_entry_by_name(bin_cluster_id, program); int cluster_id = get_cluster_id(bin_cluster_id, entry_id); int program_size = get_file_size(bin_cluster_id, entry_id); if (entry_id == ENTRY_NOT_FOUND_ID) { put_char('n'); put_char('o'); put_char(' '); put_char('s'); put_char('u'); put_char('c'); put_char('h'); put_char(' '); put_char('b'); put_char('i'); put_char('n'); return; } read_file(cluster_id, program_size, file_content); execute(file_content, program_size, argument); print_return_argument(argument); }
/********************************************************************** * find_entry * * Find a resource entry */ static NTSTATUS find_entry( HMODULE hmod, const LDR_RESOURCE_INFO *info, ULONG level, const void **ret, int want_dir ) { ULONG size; const void *root; const IMAGE_RESOURCE_DIRECTORY *resdirptr; WORD list[9]; /* list of languages to try */ int i, pos = 0; root = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &size ); if (!root) return STATUS_RESOURCE_DATA_NOT_FOUND; if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND; resdirptr = root; if (!level--) goto done; if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level ))) return STATUS_RESOURCE_TYPE_NOT_FOUND; if (!level--) return STATUS_SUCCESS; resdirptr = *ret; if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level ))) return STATUS_RESOURCE_NAME_NOT_FOUND; if (!level--) return STATUS_SUCCESS; if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */ /* 1. specified language */ pos = push_language( list, pos, info->Language ); /* 2. specified language with neutral sublanguage */ pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(info->Language), SUBLANG_NEUTRAL ) ); /* 3. neutral language with neutral sublanguage */ pos = push_language( list, pos, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) ); /* if no explicitly specified language, try some defaults */ if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL) { /* user defaults, unless SYS_DEFAULT sublanguage specified */ if (SUBLANGID(info->Language) != SUBLANG_SYS_DEFAULT) { /* 4. current thread locale language */ pos = push_language( list, pos, LANGIDFROMLCID(NtCurrentTeb()->CurrentLocale) ); /* 5. user locale language */ pos = push_language( list, pos, LANGIDFROMLCID(user_lcid) ); /* 6. user locale language with neutral sublanguage */ pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(user_lcid), SUBLANG_NEUTRAL ) ); } /* now system defaults */ /* 7. system locale language */ pos = push_language( list, pos, LANGIDFROMLCID( system_lcid ) ); /* 8. system locale language with neutral sublanguage */ pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(system_lcid), SUBLANG_NEUTRAL ) ); /* 9. English */ pos = push_language( list, pos, MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) ); } resdirptr = *ret; for (i = 0; i < pos; i++) if ((*ret = find_entry_by_id( resdirptr, list[i], root, want_dir ))) return STATUS_SUCCESS; /* if no explicitly specified language, return the first entry */ if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL) { if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS; } return STATUS_RESOURCE_LANG_NOT_FOUND; done: *ret = resdirptr; return STATUS_SUCCESS; }