Esempio n. 1
0
Elevator *get_elevator(int id, JRB elevators)
{
  Elevator *e;
  JRB tmp;
 
  tmp = jrb_find_int(elevators, id);
  if (tmp != NULL) return (Elevator *) tmp->val.v;

  e = talloc(Elevator, 1);
  e->time = 0;
  e->id = id;
  e->door = 0;
  e->floor = 1;
  e->state = 'R';
  jrb_insert_int(elevators, id, new_jval_v((void *) e));
  return e;
}
Esempio n. 2
0
int deepFirstSearch(Graph graph, int start, int stop, Dllist close) {
	Dllist node, stack;
	JRB visited;
	int output[100];
	int temp;

	int i, n;

	visited = make_jrb();
	stack = new_dllist();
	dll_prepend(stack, new_jval_i(start));

	while(!dll_empty(stack)) {
		node = dll_first(stack);
		temp = jval_i(node->val);
		dll_delete_node(node);

		if(jrb_find_int(visited, temp) == NULL) {
			// reportFunc(temp);
			dll_append(close, new_jval_i(temp));
			jrb_insert_int(visited, temp, new_jval_i(temp));
			
			if(compare(temp, stop) == 0) {
				jrb_free_tree(visited);
				free_dllist(stack);
				return 1;
			}

			n = outdegree(graph, temp, output);
			for(i = 0; i < n; i++) {
				if(jrb_find_int(visited, output[i]) == NULL) {
					dll_prepend(stack, new_jval_i(output[i]));
				}
			}
		}
	}

	jrb_free_tree(visited);
	free_dllist(stack);

	return 0;
}
Esempio n. 3
0
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);
	}


}
Esempio n. 4
0
int UShortestPath(Graph graph, int start, int stop, Dllist close) {
	Dllist node, queue, stackVisit;
	JRB visited;
	int output[100];
	int temp;

	int i, n;

	visited = make_jrb();
	queue = new_dllist();
	stackVisit = new_dllist();
	dll_append(queue, new_jval_i(start));

	while(!dll_empty(queue)) {
		node = dll_first(queue);
		temp = jval_i(node->val);
		dll_delete_node(node);

		if(jrb_find_int(visited, temp) == NULL) {
			jrb_insert_int(visited, temp, new_jval_i(temp));
			dll_prepend(stackVisit, new_jval_i(temp));
			
			if(temp == stop) {
				return solution(graph, start, stop, stackVisit, close);
			}

			n = outdegree(graph, temp, output);
			for(i = 0; i < n; i++) {
				if(jrb_find_int(visited, output[i]) == NULL) {
					dll_append(queue, new_jval_i(output[i]));
				}
			}
		}
	}

	return -1;
}
Esempio n. 5
0
main()
{
  JRB level_1, level_2;
  JRB bn, bn2;
  IS is;

  is = new_inputstruct(NULL);
  level_1 = make_jrb();

  while (get_line(is) >= 0) {
    bn = jrb_find_int(level_1, atoi(is->text1));
    if (bn == NULL) {
      bn = jrb_insert_int(level_1, atoi(is->text1), 
                               new_jval_v((void *)make_jrb()));
    }
    level_2 = (JRB ) jval_v(bn->val);
    jrb_insert_str(level_2, strdup(is->text1), new_jval_v(NULL));
  }

  jrb_traverse(bn, level_1) {
    level_2 = (JRB ) jval_v(bn->val);
    jrb_traverse(bn2, level_2) {
      printf("%s", bn2->key.s);
    }
Esempio n. 6
0
void *initialize_user_process(void *arg)
{
  //  printf("Enters initalize_user_process\n");
  int i;
  char **filename = (char **)arg;
  int argc = 0;
    
  while (filename[argc]!=NULL)
    {
       printf("This is filename[%i]: %s\n", argc, filename[argc]);
      argc++;
    }
  //    printf("This is argc in init: %i\n", argc);
    
  //Step 19: putting in argc
  //k = WordToMachine(argc);
  //memcpy(main_memory+MemorySize-40+12, &k, 4);
    
  //L3 Step 18: start first process, is this init? 
    init=(PCB *)malloc(sizeof(PCB));
    init->registers = (int *)malloc(NumTotalRegs*sizeof(int));
    for (i=0; i < NumTotalRegs; i++)
    {  
      init->registers[i] = 0;
    }
    init->pid = (int *)0;
    //    printf("This is init's pid: %i\n", (int)init->pid);
    //L3 Step 19: 
    init->waiter_sem = make_kt_sem(0);
    init->waiters = new_dllist();
    init->children = make_jrb();

    //Allocate a new PCB
  PCB *temp=(PCB *)malloc(sizeof(PCB));
  temp->registers = (int *)malloc(NumTotalRegs*sizeof(int));
  temp->user_base = 0;
  //printf("Initial user_base: %i\n", temp->user_base);
  //Changed Step 12: temp->user_limit = MemorySize-2048;
  temp->user_limit = MemorySize/8;
  //printf("Initial user_limt: %i\n", temp->user_limit);
  
  //L3 Step 18: 
  temp->parent = init;
  //L3 Step 19: 
  temp->waiter_sem = make_kt_sem(0);
  temp->waiters = new_dllist();
  //L3 Step 21: make rb tree for children 
  temp->children = make_jrb();
  
  //Changed at Step 12: User_Base = temp->user_base;
  User_Base = memory8();
  User_Limit = temp->user_limit;
  //printf("This is User_Base in initialize: %i\n", User_Base);
  //printf("This is User_Limit in initialize: %i\n", User_Limit);

  //set the regs of the
  //printf("Setting all the registers to 0 in initalize_user_process\n");
  for (i=0; i < NumTotalRegs; i++)
    temp->registers[i] = 0;
  
  //printf("Setting pid in init\n");
  temp->pid = (int *)get_new_pid();
  printf("First Pid: %i and its parent's should be 0 init: %i\n", temp->pid, temp->parent->pid );
  /* set up the program counters and the stack register */
  temp->registers[PCReg] = 0;
  temp->registers[NextPCReg] = 4;

  //insert the first process as init's child; WOW you can use this function!
  Jval tempN = new_jval_v((void*)temp); //can only insert Jvals 
  jrb_insert_int(init->children, (int)temp->pid, tempN); //JRB tree, int ikey, Jval val 
  //JRB ptr;
  //  jrb_traverse(ptr, init->children)
  //{
  //printf("This is child pid %i of init %i\n", ptr->key, (int)init->pid);
  //}
  //perform_execve(job, fn, argv)
  // where job is the new PCB, fn is the name of your initial executable (at this point, mine is a.out),
  //and argv is the argv of this initial job.
  //returns-> 0 success, errno if error
  //PrintStack(temp->registers[StackReg], temp->user_base);
  int errno = perform_execve(temp, filename[0],filename);
  // printf("This is perform_execve: %i\n", errno);
    //returns to initialize_user_process(), it either exits because there was an error, or it puts the new job onto the ready queue and calls kt_exit()
  PrintStack(temp->registers[StackReg], temp->user_base);
  if (errno!=0)
  {
      printf("Perform_execve returned unsucessful\n"); 
      kt_exit();
  }
  //printf("Placing jval into queue\n");
  Jval value = new_jval_v((void *)temp);
  //value.v = temp;
  //printf("This is the value being placed into the readyq in the initalize_user_process: %s\n",value.v );
  dll_append(readyq, value);
  // printf("Program %s loaded\n", kos_argv[0]);
  kt_exit();
}
Esempio n. 7
0
void *initialize_user_process(void *arg){

  PCB *user_process;
  Jval jval_pcb;
  Jval user_process_child_node;
  char **filename;
  int base;
  int arg_count;
  int errno;
  int i;
  
  arg_count = 0;
  errno = 0;
  i = 0;
  
  
  
  /* Unmarshalling */
  filename = (char **) arg;
  
  
  /* Create the global init process */
  init = (PCB *)malloc(sizeof(PCB));
  init->registers = (int *)malloc(sizeof(int) * NumTotalRegs);
  
  // Initialize init's registers */
  for (i = 0; i < NumTotalRegs; i++) {
    init->registers[i] = 0;
  }
  
  // Initialize init's other variables
  init->pid = (int *)0;
  init->waiter = make_kt_sem(0);
  init->waiters = new_dllist();
  init->children = make_jrb();
  
  
  
  /* Allocate new PCB and initialize registers */
  user_process = (PCB *)malloc(sizeof(PCB));
  user_process->registers = (int *)malloc(NumTotalRegs * sizeof(int));
  for (i = 0; i < NumTotalRegs; i++) {
    user_process->registers[i] = 0;
  }
  
  // Obtain pid and partiton memory for new process
  user_process->pid = (int *)get_new_pid();
  base = partition_memory(user_process->pid);
  
  
  // Initialize first process' other variables
  user_process->waiter = make_kt_sem(0);
  user_process->waiters = new_dllist();
  user_process->children = make_jrb(); 
  

  // Set base and limit for new process
  user_process->base = 0;
  user_process->limit = MemorySize/8;
  
  // Set User global vars
  User_Base = base;
  User_Limit = user_process->limit;
  
  // Set process' PCRegs
  user_process->registers[PCReg] = 0;
  user_process->registers[NextPCReg] = 4;
  
  
  // Set first process' parent as init and add to init's children
  user_process->parent = (struct PCB *)init;
  user_process_child_node.v = user_process;
  jrb_insert_int(init->children, (int)user_process->pid, user_process_child_node);
    
  
  // Get number of args and turn off exec flag.
  while (filename[arg_count] != NULL) {
    arg_count++;
  }
  totalArgs = arg_count;
  is_exec = 0;
  
  /* Call perform_execve */
  errno = perform_execve(user_process, filename[0], filename);
  
  // If errors, returns proper errno
  if (errno != 1) {
    syscall_return(user_process, errno);
  } else {
  // Puts new job onto readyQ and calls kt_exit()
    jval_pcb.v = user_process;
    dll_append(readyQ, jval_pcb);
    kt_exit();
  }
  
}