Ejemplo n.º 1
0
void board_load_board(int board_type)
{
  FILE *fl;
  int i, j, len1, len2;
  char *tmp1, *tmp2;

  if (!(fl = fopen(FILENAME(board_type), "rb"))) {
    if (errno != ENOENT)
      perror("SYSERR: Error reading board");
    return;
  }
  if (fread(&(num_of_msgs[board_type]), sizeof(int), 1, fl) != 1)
    return;
  if (num_of_msgs[board_type] < 1 || num_of_msgs[board_type] > MAX_BOARD_MESSAGES) {
    log("SYSERR: Board file %d corrupt.  Resetting.", board_type);
    board_reset_board(board_type);
    return;
  }
  for (i = 0; i < num_of_msgs[board_type]; i++) {
    j = fread(&(msg_index[board_type][i]), sizeof(struct board_msginfo), 1, fl);
    if ((len1 = msg_index[board_type][i].heading_len) <= 0) {
      log("SYSERR: Board file %d corrupt!  Resetting.", board_type);
      board_reset_board(board_type);
      return;
    }
    CREATE(tmp1, char, len1);
    j = fread(tmp1, sizeof(char), len1, fl);
    MSG_HEADING(board_type, i) = tmp1;

    if ((MSG_SLOTNUM(board_type, i) = find_slot()) == -1) {
      log("SYSERR: Out of slots booting board %d!  Resetting...", board_type);
      board_reset_board(board_type);
      return;
    }
    if ((len2 = msg_index[board_type][i].message_len) > 0) {
      CREATE(tmp2, char, len2);
      j = fread(tmp2, sizeof(char), len2, fl);
      msg_storage[MSG_SLOTNUM(board_type, i)] = tmp2;
    } else
      msg_storage[MSG_SLOTNUM(board_type, i)] = NULL;
  }

  fclose(fl);
}
Ejemplo n.º 2
0
void board_load_board() {
	FILE *the_file;
	int ind, len = 0;

	board_reset_board();
	the_file = fopen(SAVE_FILE, "rb");
	if (!the_file) {
		error_log("Can't open message file. Board will be empty.\r\n",0);
		return;
	}
	fread(&msg_num, sizeof(int), 1, the_file);
	
	if (msg_num < 1 || msg_num > MAX_MSGS || feof(the_file)) {
		error_log("Board-message file corrupt or nonexistent.\r\n");
		fclose(the_file);
		return;
	}
	for (ind = 0; ind < msg_num; ind++) {
		fread(&len, sizeof(int), 1, the_file);
		head[ind] = (char *)malloc(len + 1);
		if (!head[ind]) {
			error_log("Malloc for board header failed.\r\n");
			board_reset_board();
			fclose(the_file);
			return;
		}
		fread(head[ind], sizeof(char), len, the_file);
		fread(&len, sizeof(int), 1, the_file);
		msgs[ind] = (char *)malloc(len + 1);
		if (!msgs[ind]) {
			error_log("Malloc for board msg failed..\r\n");
			board_reset_board();
			fclose(the_file);
			return;
		}
		fread(msgs[ind], sizeof(char), len, the_file);
	}
	fclose(the_file);
	board_fix_long_desc(msg_num, head);
	return;
}