int main() { struct xrec * first; struct xrec temp; FILE * infile = fopen("data.txt", "r"); // Basic intialization to known values first = NULL; while (fscanf(infile, "%10s %11s %c %lf %lf %lf %lf", temp.name, temp.ssn, &temp.g, &temp.h, &temp.q, &temp.m, &temp.f) != EOF) { temp.name[10] = '\0'; first = prepend_to_list(first, temp); } fclose(infile); compute_grade(first); print_student_names(first); return 0; }
void insert_in_list_at(const Value value, Node **const pt_to_pt_to_node, int position) { if (position <= 0) { prepend_to_list(value, pt_to_pt_to_node); return; } Node *pt_to_new_node = create_node(value); if (!*pt_to_pt_to_node) { *pt_to_pt_to_node = pt_to_new_node; return; } Node *pt_to_node = *pt_to_pt_to_node; while (--position && pt_to_node->pt_to_next_node) pt_to_node = pt_to_node->pt_to_next_node; pt_to_new_node->pt_to_next_node = pt_to_node->pt_to_next_node; pt_to_node->pt_to_next_node = pt_to_new_node; }
bool insert_in_list_before(const Value value_1, Node **const pt_to_pt_to_node, const Value value_2) { if (!*pt_to_pt_to_node) return false; if (!compare_values((*pt_to_pt_to_node)->value, value_2)) { prepend_to_list(value_1, pt_to_pt_to_node); return true; } Node *pt_to_node = *pt_to_pt_to_node; while (pt_to_node->pt_to_next_node && compare_values(pt_to_node->pt_to_next_node->value, value_2)) pt_to_node = pt_to_node->pt_to_next_node; if (!pt_to_node->pt_to_next_node) return false; Node *const pt_to_new_node = create_node(value_1); pt_to_new_node->pt_to_next_node = pt_to_node->pt_to_next_node; pt_to_node->pt_to_next_node = pt_to_new_node; return true; }
void sys_send (struct msg *m, options_t options){ if(get_current_tid() == Posts[post].owner){ if(Threads[Posts[m->dest].owner].vm == Threads[Posts[m->from].owner].vm){ if(m->dest > POST_NUM_MAX || Posts[m->dest].owner == 0){ // TODO: send a error msg } prepend_to_list(Posts[m->dest].received, m); wake_thread(Posts[m->dest].owner); }else{ // TODO: move a page of a message to dest if(Posts[m->dest].handler == NULL){ // TODO: prepend_to_list(Posts[m->dest].received, m); }else{ // TODO: create thread and call handler } } } struct msg *sys_recv (post_id_t post, options_t options){ struct msg *m; if(get_current_tid() != Posts[post].owner) return NULL; if(is_list_empty(Posts[post].received)){ if(options & MSG_NOWAIT) return NULL; // wait for a message sleep_thread(Posts[m->dest].owner); } Posts[post].received = pop_from_list(Posts[post].received, (void *) &m); return m; } void sys_await (post_id_t post, void (*handler)(struct msg *m), uintmax_t max_thread_num){ if(get_current_tid() != Posts[post].owner) return; Posts[post].handler = handler; Posts[post].max_thread_num = max_thread_max; } struct msg *compose (size_t body_size){ return allocate_memory_block(sizeof(struct msg) + body_size); } void discard (struct msg *m){ free_memory_block(m); }