40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
static Uint8 inserting,saved_inserting;
static sqlite3_stmt*autowin;
static size_t dum_size; // not used by Free Hero Mesh, but needed by some C library functions.
int encode_move(FILE*fp,MoveItem v) {
// Encodes a single move and writes the encoded move to the file.
// Returns the number of bytes of the encoded move.
fputc(v,fp);
return 1;
}
int encode_move_list(FILE*fp) {
// Encodes the current replay list into the file; returns the number of bytes.
// Does not write a null terminator.
fwrite(replay_list,1,replay_count,fp);
return replay_count;
}
MoveItem decode_move(FILE*fp) {
// Decodes a single move from the file, and returns the move.
// Returns zero if there is no more moves.
int v=fgetc(fp);
return (v==EOF?0:v);
}
int decode_move_list(FILE*fp) {
// Decodes a move list from the file, and stores it in replay_list and replay_count.
// Returns the number of moves (replay_count).
MoveItem v;
FILE*o;
|
>
|
|
>
>
>
>
>
|
|
>
|
>
>
>
>
>
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
static Uint8 inserting,saved_inserting;
static sqlite3_stmt*autowin;
static size_t dum_size; // not used by Free Hero Mesh, but needed by some C library functions.
int encode_move(FILE*fp,MoveItem v) {
// Encodes a single move and writes the encoded move to the file.
// Returns the number of bytes of the encoded move.
if(v>=8 && v<256) {
fputc(v,fp);
return 1;
} else {
fatal("Unencodable move (%u)\n",(int)v);
}
}
int encode_move_list(FILE*fp) {
// Encodes the current replay list into the file; returns the number of bytes.
// Does not write a null terminator.
int i;
int c=0;
for(i=0;i<replay_count;i++) c+=encode_move(fp,replay_list[i]);
return c;
}
MoveItem decode_move(FILE*fp) {
// Decodes a single move from the file, and returns the move.
// Returns zero if there is no more moves.
int v=fgetc(fp);
if(v>=8 && v<256) {
return v;
} else if(v==EOF || !v) {
return 0;
} else {
fatal("Undecodable move (%u)\n",v);
}
}
int decode_move_list(FILE*fp) {
// Decodes a move list from the file, and stores it in replay_list and replay_count.
// Returns the number of moves (replay_count).
MoveItem v;
FILE*o;
|