Commit de22d96e authored by Per Cederqvist's avatar Per Cederqvist

patch introduce-generation_position.patch

parent 26d67f86
remove-reclamation add-text_store
From: Per Cederqvist <ceder@lysator.liu.se> From: Per Cederqvist <ceder@lysator.liu.se>
Subject: Create empty files text-store.h and text-store.c, and include them in the link. * src/server/text-store.h: New file, currently empty. * src/server/text-store.c: New file. Include text-store.h, but do not yet do anything. * src/server/Makefile.am (DISKOBJS): Added text-store.c and text-store.h. (DBCK): Added text-store.c. Subject: patch introduce-generation_position.patch
...@@ -210,12 +210,32 @@ typedef struct { ...@@ -210,12 +210,32 @@ typedef struct {
*/ */
typedef unsigned long Garb_nice; typedef unsigned long Garb_nice;
typedef long Generation;
struct generation_position {
/* The generation number where the text mass is stored. */
Generation generation;
/* Start of the text. For generation 0, this is the start of the
actual text. For all other generations, this points is a
struct that contains some metadata and the text mass. See
foutput_text_mass() for the format. */
long file_pos;
/* Size of text and metadata. For generation 0, there is no
metadata, so file_size will be equal to no_of_chars in the
corresponding Text_stat. For all other generations, this will
include some overhead (see foutput_text_mass()). */
long file_size;
};
/* Struct for text status */ /* Struct for text status */
typedef struct { typedef struct {
Time creation_time; Time creation_time;
long generation;
long file_pos; /* Start of the text in the text file. */ /* Where the text can be found. */
struct generation_position text_store;
Pers_no author; Pers_no author;
unsigned short no_of_lines; unsigned short no_of_lines;
String_size no_of_chars; String_size no_of_chars;
......
...@@ -329,11 +329,11 @@ cached_get_text( Text_no text ) ...@@ -329,11 +329,11 @@ cached_get_text( Text_no text )
if ( text_arr[ text ] == NULL ) if ( text_arr[ text ] == NULL )
return EMPTY_STRING; return EMPTY_STRING;
else if (text_arr[text]->generation == 0) else if (text_arr[text]->text_store.generation == 0)
{ {
the_string.string = tmp_alloc( text_arr[text]->no_of_chars ); the_string.string = tmp_alloc( text_arr[text]->no_of_chars );
the_string.len = text_arr[text]->no_of_chars; the_string.len = text_arr[text]->no_of_chars;
fseek(text_file, text_arr[ text ]->file_pos, SEEK_SET); fseek(text_file, text_arr[ text ]->text_store.file_pos, SEEK_SET);
if ( fread(the_string.string, sizeof(char), the_string.len, text_file) if ( fread(the_string.string, sizeof(char), the_string.len, text_file)
!= (size_t)the_string.len ) != (size_t)the_string.len )
{ {
...@@ -424,8 +424,9 @@ cached_flush_text(Text_no text_no, ...@@ -424,8 +424,9 @@ cached_flush_text(Text_no text_no,
fseek(new_text_file, 0, SEEK_END); fseek(new_text_file, 0, SEEK_END);
#warning Generation > 0 not yet handled #warning Generation > 0 not yet handled
text_arr[ text_no ]->generation = 0; text_arr[ text_no ]->text_store.generation = 0;
text_arr[ text_no ]->file_pos = ftell(new_text_file); text_arr[ text_no ]->text_store.file_pos = ftell(new_text_file);
text_arr[ text_no ]->text_store.file_size = 0;
if ( fwrite(message.string, sizeof(char), message.len, new_text_file) if ( fwrite(message.string, sizeof(char), message.len, new_text_file)
!= (size_t)message.len ) != (size_t)message.len )
......
...@@ -608,8 +608,9 @@ copy_text_stat(const Text_stat *t) ...@@ -608,8 +608,9 @@ copy_text_stat(const Text_stat *t)
c = alloc_text_stat(); c = alloc_text_stat();
c->creation_time = t->creation_time; c->creation_time = t->creation_time;
c->generation = t->generation; c->text_store.generation = t->text_store.generation;
c->file_pos = t->file_pos; c->text_store.file_pos = t->text_store.file_pos;
c->text_store.file_size = t->text_store.file_size;
c->author = t->author; c->author = t->author;
c->no_of_lines = t->no_of_lines; c->no_of_lines = t->no_of_lines;
c->no_of_chars = t->no_of_chars; c->no_of_chars = t->no_of_chars;
...@@ -627,8 +628,9 @@ void ...@@ -627,8 +628,9 @@ void
init_text_stat (Text_stat *t) init_text_stat (Text_stat *t)
{ {
t->creation_time = NO_TIME; t->creation_time = NO_TIME;
t->generation = 0; t->text_store.generation = 0;
t->file_pos = 0; t->text_store.file_pos = 0;
t->text_store.file_size = 0;
t->author = 0; t->author = 0;
t->no_of_lines = 0; t->no_of_lines = 0;
t->no_of_chars = 0; t->no_of_chars = 0;
......
...@@ -325,7 +325,7 @@ foutput_text_stat_0(struct dbfile *fp, ...@@ -325,7 +325,7 @@ foutput_text_stat_0(struct dbfile *fp,
foutput_time(fp, t_stat->creation_time); foutput_time(fp, t_stat->creation_time);
foutput_ulong((unsigned long) t_stat->author, fp); foutput_ulong((unsigned long) t_stat->author, fp);
foutput_ulong((unsigned long) t_stat->file_pos, fp); foutput_ulong((unsigned long) t_stat->text_store.file_pos, fp);
foutput_ulong((unsigned long) t_stat->no_of_lines, fp); foutput_ulong((unsigned long) t_stat->no_of_lines, fp);
foutput_ulong((unsigned long) t_stat->no_of_chars, fp); foutput_ulong((unsigned long) t_stat->no_of_chars, fp);
foutput_ulong((unsigned long) t_stat->no_of_marks, fp); foutput_ulong((unsigned long) t_stat->no_of_marks, fp);
...@@ -351,7 +351,7 @@ foutput_text_stat_2(struct dbfile *fp, ...@@ -351,7 +351,7 @@ foutput_text_stat_2(struct dbfile *fp,
foutput_time(fp, t_stat->creation_time); foutput_time(fp, t_stat->creation_time);
foutput_ulong((unsigned long) t_stat->author, fp); foutput_ulong((unsigned long) t_stat->author, fp);
foutput_ulong((unsigned long) t_stat->file_pos, fp); foutput_ulong((unsigned long) t_stat->text_store.file_pos, fp);
foutput_ulong((unsigned long) t_stat->no_of_lines, fp); foutput_ulong((unsigned long) t_stat->no_of_lines, fp);
foutput_ulong((unsigned long) t_stat->no_of_chars, fp); foutput_ulong((unsigned long) t_stat->no_of_chars, fp);
foutput_ulong((unsigned long) t_stat->no_of_marks, fp); foutput_ulong((unsigned long) t_stat->no_of_marks, fp);
...@@ -380,8 +380,9 @@ foutput_text_stat_3(struct dbfile *fp, ...@@ -380,8 +380,9 @@ foutput_text_stat_3(struct dbfile *fp,
foutput_time(fp, t_stat->creation_time); foutput_time(fp, t_stat->creation_time);
foutput_ulong((unsigned long) t_stat->author, fp); foutput_ulong((unsigned long) t_stat->author, fp);
foutput_ulong((unsigned long) t_stat->generation, fp); foutput_ulong((unsigned long) t_stat->text_store.generation, fp);
foutput_ulong((unsigned long) t_stat->file_pos, fp); foutput_ulong((unsigned long) t_stat->text_store.file_pos, fp);
foutput_ulong((unsigned long) t_stat->text_store.file_size, fp);
foutput_ulong((unsigned long) t_stat->no_of_lines, fp); foutput_ulong((unsigned long) t_stat->no_of_lines, fp);
foutput_ulong((unsigned long) t_stat->no_of_chars, fp); foutput_ulong((unsigned long) t_stat->no_of_chars, fp);
foutput_ulong((unsigned long) t_stat->no_of_marks, fp); foutput_ulong((unsigned long) t_stat->no_of_marks, fp);
......
...@@ -1049,8 +1049,9 @@ fparse_text_stat_3(struct dbfile *fp, ...@@ -1049,8 +1049,9 @@ fparse_text_stat_3(struct dbfile *fp,
result->creation_time = fparse_time(fp); result->creation_time = fparse_time(fp);
result->author = fparse_long(fp); result->author = fparse_long(fp);
result->generation = fparse_long(fp); result->text_store.generation = fparse_long(fp);
result->file_pos = fparse_long(fp); result->text_store.file_pos = fparse_long(fp);
result->text_store.file_size = fparse_long(fp);
result->no_of_lines = fparse_long(fp); result->no_of_lines = fparse_long(fp);
result->no_of_chars = fparse_long(fp); result->no_of_chars = fparse_long(fp);
result->no_of_marks = fparse_long(fp); result->no_of_marks = fparse_long(fp);
...@@ -1166,8 +1167,9 @@ fparse_text_stat_2(struct dbfile *fp, ...@@ -1166,8 +1167,9 @@ fparse_text_stat_2(struct dbfile *fp,
result->creation_time = fparse_time(fp); result->creation_time = fparse_time(fp);
result->author = fparse_long(fp); result->author = fparse_long(fp);
result->generation = 0; result->text_store.generation = 0;
result->file_pos = fparse_long(fp); result->text_store.file_pos = fparse_long(fp);
result->text_store.file_size = 0;
result->no_of_lines = fparse_long(fp); result->no_of_lines = fparse_long(fp);
result->no_of_chars = fparse_long(fp); result->no_of_chars = fparse_long(fp);
result->no_of_marks = fparse_long(fp); result->no_of_marks = fparse_long(fp);
...@@ -1283,8 +1285,9 @@ fparse_text_stat_0(struct dbfile *fp, ...@@ -1283,8 +1285,9 @@ fparse_text_stat_0(struct dbfile *fp,
result->creation_time = fparse_time(fp); result->creation_time = fparse_time(fp);
result->author = fparse_long(fp); result->author = fparse_long(fp);
result->generation = 0; result->text_store.generation = 0;
result->file_pos = fparse_long(fp); result->text_store.file_pos = fparse_long(fp);
result->text_store.file_size = 0;
result->no_of_lines = fparse_long(fp); result->no_of_lines = fparse_long(fp);
result->no_of_chars = fparse_long(fp); result->no_of_chars = fparse_long(fp);
result->no_of_marks = fparse_long(fp); result->no_of_marks = fparse_long(fp);
......
...@@ -1052,15 +1052,15 @@ cached_get_text( Text_no text ) ...@@ -1052,15 +1052,15 @@ cached_get_text( Text_no text )
if ( (t_stat = cached_get_text_stat (text)) == NULL ) if ( (t_stat = cached_get_text_stat (text)) == NULL )
return EMPTY_STRING; return EMPTY_STRING;
else if (t_stat->generation == 0) else if (t_stat->text_store.generation == 0)
{ {
LOGACC(lt_text_mass, text); LOGACC(lt_text_mass, text);
the_string.string = tmp_alloc( t_stat->no_of_chars ); the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars; the_string.len = t_stat->no_of_chars;
if (fseek(text_file, t_stat->file_pos, SEEK_SET) != 0) if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0)
{ {
kom_log("Failed to seek to %ld in text mass file: %s.\n", kom_log("Failed to seek to %ld in text mass file: %s.\n",
t_stat->file_pos, strerror(errno)); t_stat->text_store.file_pos, strerror(errno));
return EMPTY_STRING; return EMPTY_STRING;
} }
...@@ -1227,8 +1227,8 @@ cached_create_text(const String message) ...@@ -1227,8 +1227,8 @@ cached_create_text(const String message)
((Text_stat *)node->ptr)->no_of_marks = 0; ((Text_stat *)node->ptr)->no_of_marks = 0;
((Text_stat *)node->ptr)->no_of_lines = 0; ((Text_stat *)node->ptr)->no_of_lines = 0;
((Text_stat *)node->ptr)->no_of_chars = 0; ((Text_stat *)node->ptr)->no_of_chars = 0;
((Text_stat *)node->ptr)->generation = 0; ((Text_stat *)node->ptr)->text_store.generation = 0;
((Text_stat *)node->ptr)->file_pos = file_pos; ((Text_stat *)node->ptr)->text_store.file_pos = file_pos;
text_set_mru( tno ); text_set_mru( tno );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment