Repositories » TXT0
Clone URL:  
Pushed to one repository · View In Graph Contained in v0.1 and tip

read_t()'s interface was modified to not pass it a Tok but leave it to
it to create a Tok and return a pointer to it. This makes it smoother

to read multiple concatenated .t documents piped to a program that
would usr read_t().

Changeset 11bda80192f6

Parent 21bb44f9ef38

by Rup Palchowdhury

Changes to 4 files · Browse files at 11bda80192f6 Showing diff from parent 21bb44f9ef38 Diff from another changeset...

Change 1 of 2 Show Entire File Makefile Stacked
 
22
23
24
25
 
26
27
28
 
30
31
32
 
 
 
33
34
35
 
22
23
24
 
25
26
27
28
 
30
31
32
33
34
35
36
37
38
@@ -22,7 +22,7 @@
   OBJ = $(patsubst %.c,$(O)/%.o,$(SRC))   -all: raw2t t2mem +all: raw2t t2mem ii    raw2t: $(O)/raw2t.o $(OBJ)   $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ $(LIBS) @@ -30,6 +30,9 @@
 t2mem: $(O)/t2mem.o $(OBJ)   $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ $(LIBS)   +ii: $(O)/ii.o $(OBJ) + $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ $(LIBS) +  $(O)/%.o: %.c $(DEPDIR)/%.d   $(CC) $(DEPFLAGS) $(CFLAGS) $(INCLUDES) -c $< -o $@   $(POSTCOMPILE)
Change 1 of 1 Show Entire File t2mem.c Stacked
 
10
11
12
13
14
15
 
 
 
16
17
 
10
11
12
 
 
 
13
14
15
16
17
@@ -10,8 +10,8 @@
 int main(void)  {   Tok *tok; - tok = newtok(TREC_ADHOC); - read_t(tok, stdin); - printtok(tok); + tok = read_t(stdin); + if (tok) + printtok(tok);   return 0;  }
Change 1 of 2 Show Entire File tok.c Stacked
 
69
70
71
72
 
73
74
 
 
75
 
 
 
76
 
 
 
 
77
78
79
80
81
82
 
 
 
 
83
84
85
86
87
88
89
90
 
 
91
92
93
 
95
96
97
98
99
 
 
100
101
102
103
104
105
106
 
107
108
109
 
69
70
71
 
72
73
 
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
90
91
92
93
94
95
96
97
98
99
 
 
100
101
102
103
104
 
106
107
108
 
 
109
110
111
112
113
114
115
116
 
117
118
119
120
@@ -69,25 +69,36 @@
  return n;  }   -int read_t(Tok *tok, FILE *fp) +Tok* read_t(FILE *fp)  { - int i, j, n, toread; + int i, n, toread; + Tok *tok;   Tokdoc *tokdoc; + + tok = newtok(TREC_ADHOC); +   n = fread(tok->header->block, 4, TOK_HEADER_BLOCKS, fp); + if (n != TOK_HEADER_BLOCKS) { + printf("ERROR: failed to read header\n"); + return NULL; + }     for (i = 0; i < tok->header->block[NUMDOCS]; i++) {   tokdoc = newtokdoc(TREC_ADHOC);   n = fread(tokdoc->header->block,   4, tok->header->block[NUMRES], fp); - + if (n != tok->header->block[NUMRES]) { + printf("ERROR: failed to read doc header\n"); + return NULL; + }   /* read the doc text */   toread = tokdoc->header->block[RES1DOCLEN];   if (toread > tokdoc->doc->n)   tokdoc->doc = resizebuffer(tokdoc->doc, toread);   if((n = fread(tokdoc->doc->b, 1, toread, fp)) != toread) {   printf("read %d of %d bytes\n", n, toread); - printf("ABORT: failed to read doc\n"); - exit(0); + printf("ERROR: failed to read doc\n"); + return NULL;   }   shiftpointer(tokdoc->doc, n);   @@ -95,15 +106,15 @@
  toread = tokdoc->header->block[RES2IDLEN];   if((n = fread(tokdoc->id->b, 1, toread, fp)) != toread) {   printf("read %d of %d bytes\n", n, toread); - printf("ABORT: failed to read docid\n"); - exit(0); + printf("ERROR: failed to read docid\n"); + return NULL;   }   shiftpointer(tokdoc->id, n);     tok->list = addfront(tok->list, newnode((void *)tokdoc));   }   - return n; + return tok;  }    void _printtokheader(Tokheader *h)
Change 1 of 1 Show Entire File tok.h Stacked
 
33
34
35
36
 
37
38
39
 
33
34
35
 
36
37
38
39
@@ -33,7 +33,7 @@
 Tokdoc *newtokdoc(E_doctype);  Tok *newtok(E_doctype);  int write_t(Tok*, FILE*); -int read_t(Tok*, FILE*); +Tok* read_t(FILE*);  void _printtokheader(Tokheader*);  void _printtokdocheader(Tokdocheader*, int numres);  void printtok(Tok*);