71 |
ib = strbuf_open(sb.st_size); |
ib = strbuf_open(sb.st_size); |
72 |
if ((ip = fopen(path, "r")) == NULL) |
if ((ip = fopen(path, "r")) == NULL) |
73 |
return -1; |
return -1; |
74 |
lineno = offset = 0; |
lineno = 1; |
75 |
|
offset = 0; |
76 |
for (offset = 0; |
for (offset = 0; |
77 |
(strbuf_fgets(ib, ip, STRBUF_APPEND), offset != strbuf_getlen(ib)); |
(strbuf_fgets(ib, ip, STRBUF_APPEND), offset != strbuf_getlen(ib)); |
78 |
offset = strbuf_getlen(ib)) |
offset = strbuf_getlen(ib)) |
115 |
* linetable_put: put a line into table. |
* linetable_put: put a line into table. |
116 |
* |
* |
117 |
* i) offset offset of the line |
* i) offset offset of the line |
118 |
* i) lineno line number of the line |
* i) lineno line number of the line (>= 1) |
119 |
*/ |
*/ |
120 |
static void |
static void |
121 |
linetable_put(offset, lineno) |
linetable_put(offset, lineno) |
122 |
int offset; |
int offset; |
123 |
int lineno; |
int lineno; |
124 |
{ |
{ |
125 |
|
if (lineno-- <= 0) |
126 |
|
die("line number must >= 1"); |
127 |
/* |
/* |
128 |
* Old implementations of realloc() may crash when a null pointer is passed. |
* Old implementations of realloc() may crash when a null pointer is passed. |
129 |
* Therefore, we cannot use realloc(NULL, total_lines * sizeof(int)). |
* Therefore, we cannot use realloc(NULL, total_lines * sizeof(int)). |
147 |
/* |
/* |
148 |
* linetable_get: get a line from table. |
* linetable_get: get a line from table. |
149 |
* |
* |
150 |
* i) lineno line number of the line |
* i) lineno line number of the line (>= 1) |
151 |
* o) offset offset of the line |
* o) offset offset of the line |
152 |
* if offset == NULL, nothing returned. |
* if offset == NULL, nothing returned. |
153 |
* r) line pointer |
* r) line pointer |
184 |
* linetable_print: print a line. |
* linetable_print: print a line. |
185 |
* |
* |
186 |
* i) op output file pointer |
* i) op output file pointer |
187 |
* i) lineno line number |
* i) lineno line number (>= 1) |
188 |
*/ |
*/ |
189 |
void |
void |
190 |
linetable_print(op, lineno) |
linetable_print(op, lineno) |