summaryrefslogtreecommitdiffabout
path: root/mimetypes/locus.h
blob: 08154ce030b8a09bb1de60bfc4982a643d087462 (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
64
65
66
67
68
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
/* This file is part of fileserv.
   Copyright (C) 2017-2019 Sergey Poznyakoff

   Fileserv is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Fileserv is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with fileserv.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef _MIMETYPES_LOCUS_H
#define _MIMETYPES_LOCUS_H

#include <string.h>
#include <stdarg.h>

struct locus_point
{
  char const *file;
  unsigned line;
  unsigned col;
};

#define LOCUS_POINT_INITIALIZER { NULL, 0, 0 }

struct locus_range
{
  struct locus_point beg;
  struct locus_point end;
};

#define LOCUS_RANGE_INITIALIZER \
  { LOCUS_POINT_INITIALIZER, LOCUS_POINT_INITIALIZER }

typedef struct linetrack *linetrack_t;

struct linetrack_stat
{
  size_t n_files; /* Number of source files */
  size_t n_lines; /* Number of lines, including the recent (incomplete) one */
  size_t n_chars; /* Total number of characters */
};
  
int ident_ref (char const *name, char const **refname);
int ident_deref (char const *);

int locus_point_set_file (struct locus_point *pt, const char *filename);
void locus_point_init (struct locus_point *pt);
void locus_point_deinit (struct locus_point *pt);
int locus_point_copy (struct locus_point *dest,
			 struct locus_point const *src);

void locus_range_init (struct locus_range *dest);
int locus_range_copy (struct locus_range *dest, struct locus_range const *src);
void locus_range_deinit (struct locus_range *lr);

static inline int
locus_point_same_file (struct locus_point const *a,
		       struct locus_point const *b)
{
  return a->file == b->file
         || (a->file && b->file && strcmp(a->file, b->file) == 0);
}

static inline int
locus_point_same_line (struct locus_point const *a,
			  struct locus_point const *b)
{
  return locus_point_same_file (a, b) && a->line == b->line;
}

static inline int
locus_point_eq (struct locus_point const *a,
		struct locus_point const *b)
{
  return locus_point_same_line (a, b) && a->col == b->col;
}

int linetrack_create (linetrack_t *ret,
			   char const *file_name, size_t max_lines);
int linetrack_origin (linetrack_t trk, struct locus_point const *pt);
int linetrack_rebase (linetrack_t trk, struct locus_point const *pt);
void linetrack_free (linetrack_t trk);
void linetrack_destroy (linetrack_t *trk);
void linetrack_advance (linetrack_t trk,
			struct locus_range *loc,
			char const *text, size_t leng);
int linetrack_retreat (linetrack_t trk, size_t n);

int linetrack_locus (struct linetrack *trk, struct locus_point *lp);
int linetrack_stat (linetrack_t trk, struct linetrack_stat *st);
int linetrack_at_bol (struct linetrack *trk);

void lrange_debug (struct locus_range const *loc, char const *fmt, ...);
ssize_t locus_range_format (char **pbuf, size_t *psize, struct locus_range const *lr);


#endif

Return to:

Send suggestions and report system problems to the System administrator.