summaryrefslogtreecommitdiff
path: root/Build/source/texk/lcdf-typetools/lcdf-typetools-2.99/include/lcdf/slurper.hh
blob: 2e400d3c3f2b56df2716033c746c3d1fb2025ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// -*- related-file-name: "../../liblcdf/slurper.cc" -*-
#ifndef LCDF_SLURPER_HH
#define LCDF_SLURPER_HH
#include <lcdf/landmark.hh>
#include <lcdf/filename.hh>
#include <stdio.h>

class Slurper { public:

    Slurper(const Filename &, FILE * = 0);
    ~Slurper();

    bool ok() const			{ return _f != 0; }

    Landmark landmark() const	{ return Landmark(_filename.name(), _lineno); }
    operator Landmark() const		{ return landmark(); }
    unsigned lineno() const		{ return _lineno; }

    const Filename &filename() const	{ return _filename; }
    char *peek_line();
    char *next_line();
    char *append_next_line();
    void save_line()			{ _saved_line = true; }

    char *cur_line() const		{ return (char *)_line; }
    unsigned cur_line_length() const	{ return _line_len; }
    void shorten_line(unsigned);

 private:

    FILE *_f;
    Filename _filename;
    unsigned _lineno;
    bool _own_f;

    unsigned char *_data;
    unsigned _cap;
    unsigned _pos;
    unsigned _len;

    unsigned char *_line;
    unsigned _line_len;

    bool _saved_line;
    bool _at_eof;

    void grow_buffer();
    inline int more_data();
    char *get_line_at(unsigned);

};


inline void
Slurper::shorten_line(unsigned pos)
{
  if (pos < _line_len) {
    _line_len = pos;
    _line[_line_len] = 0;
  }
}

#endif