/[global]/global/libutil/linetable.c
ViewVC logotype

Diff of /global/libutil/linetable.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by shigio, Tue Oct 19 14:46:50 2004 UTC revision 1.7 by shigio, Tue Oct 19 14:58:47 2004 UTC
# Line 71  linetable_open(path) Line 71  linetable_open(path)
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))
# Line 114  linetable_read(buf, size) Line 115  linetable_read(buf, size)
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)).
# Line 144  linetable_put(offset, lineno) Line 147  linetable_put(offset, lineno)
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
# Line 181  linetable_close() Line 184  linetable_close()
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)

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26