1 /*
2  *  Copyright (C) Ingo Brückl
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  *  MA 02110-1301 USA.
18  */
19 
20 #ifndef XARCHIVER_PARSER_H
21 #define XARCHIVER_PARSER_H
22 
23 #define GRAB_ITEMS(parts, item, cond)                        \
24 do                                                           \
25 {                                                            \
26   unsigned int part = 1;                                     \
27                                                              \
28   do                                                         \
29   {                                                          \
30     while (*line && (*line == ' ' || *line == '\t')) line++; \
31     if (part == 1) item = line;                              \
32     while (*line && (cond)) line++;                          \
33   }                                                          \
34   while (++part <= parts);                                   \
35                                                              \
36   if (*line) *line++ = 0;                                    \
37 }                                                            \
38 while (0)
39 
40 #define USE_PARSER         \
41 static void *_archive;     \
42 static int _pos;           \
43 unsigned int _len;         \
44 char *_start = line;       \
45                            \
46 (void) _len;               \
47                            \
48 do                         \
49 {                          \
50   if (_archive != archive) \
51   {                        \
52     _archive = archive;    \
53     _pos = -1;             \
54   }                        \
55 }                          \
56 while (0)
57 
58 #define NEXT_ITEMS(parts, item) GRAB_ITEMS(parts, item, *line != ' ' && *line != '\t' && *line != '\n')
59 #define NEXT_ITEM(item) NEXT_ITEMS(1, item)
60 #define SKIP_ITEM NEXT_ITEM(line)
61 #define LAST_ITEM(item)   /* for filenames */ \
62 do                                            \
63 {                                             \
64   int pos;                                    \
65                                               \
66   GRAB_ITEMS(1, item, *line != '\n');         \
67   pos = item - _start;                        \
68                                               \
69   if (_pos < 0 || pos < _pos) _pos = pos;     \
70   else if (pos > _pos) item = _start + _pos;  \
71 }                                             \
72 while (0)
73 
74 #define IF_ITEM_LINE(string) if ((_len = strlen(string)) && (strncmp(line, string, _len) == 0) && (line += _len))
75 #define DUPE_ITEM(item) item = g_strdup(g_strstrip(line))
76 
77 #endif
78