Exemple #1
0
Fichier : cal.c Projet : Jmq14/XV6
char* cal3(char* a1, char* a2, char* s)
{
  char* ret = (char*)malloc(MAXNUM * sizeof(char));
  char* r = (char*)malloc(MAXNUM * sizeof(char));
  int res = 0;
  int i;
  int r1 = chars_to_int(a1);
  int r2 = chars_to_int(a2);
  switch (s[0])
  {
  case '+': res = r1 + r2; break;
  case '-': res = r1 - r2; break;
  case '*': res = r1 * r2; break;
  case '/': res = r1 / r2; break;
  }
  if (res >= 0) 
    ret = int_to_chars(ret, res);
  else
  {
    r = int_to_chars(r, -res);
    ret[0] = '-';
    ret[1] = 0;
    for (i = 0; i < 9; i++)
    {
      ret[i+1] = r[i];
    }
  }
  
  return ret;
}
Exemple #2
0
void hash_manager::fheader_page::bufferize(char buffer[hash_manager::page_size]) const {
	page::bufferize(buffer);
	int_to_chars(n_buckets,&buffer[9]);
	int_to_chars(n_pages,&buffer[13]);
	int_to_chars(level,&buffer[17]);
	int_to_chars(next,&buffer[21]);
}
Exemple #3
0
void hash_manager::pointer_page::bufferize(char buffer[hash_manager::page_size]) const {
	int_to_chars(static_cast<int>(ptr_bitmap.to_ulong()),&buffer[9]);
	int write_pos = 13;
	for (int i=0 ; i<n_pointers ; ++i) {
		if (ptr_bitmap[i]) {
			int_to_chars(ptr_array[i],&buffer[write_pos]);
			write_pos += 4;
		}
	}
}
Exemple #4
0
void hash_manager::content_page::bufferize(char buffer[hash_manager::page_size]) const {
	int_to_chars(static_cast<int>(data_bitmap.to_ulong()),&buffer[9]);
	int write_pos = 13;
	for (int i=0 ; i<n_data ; ++i) {
		if (data_bitmap[i]) {
			int_to_chars(data_array[i].first,&buffer[write_pos]);
			int_to_chars(data_array[i].second,&buffer[write_pos+4]);
			write_pos += 8;
		}
	}
}
Exemple #5
0
void hash_manager::page::bufferize(char buffer[hash_manager::page_size]) const {
	buffer[0] = type;
	int_to_chars(parent_pointer,&buffer[1]);
	int_to_chars(disc_writes,&buffer[5]);
}