File: tokenize.h

package info (click to toggle)
ifupdown-ng 0.12.1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 964 kB
  • sloc: ansic: 3,572; sh: 980; makefile: 233
file content (57 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (4)
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
/*
 * libifupdown/tokenize.h
 * Purpose: tokenization helper
 *
 * Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * This software is provided 'as is' and without any warranty, express or
 * implied.  In no event shall the authors be liable for any damages arising
 * from the use of this software.
 */

#ifndef LIBIFUPDOWN_TOKENIZE_H__GUARD
#define LIBIFUPDOWN_TOKENIZE_H__GUARD

#include <ctype.h>

static inline char *
lif_next_token_eq(char **buf)
{
	char *out = *buf;

	while (*out && (isspace(*out) || *out == '='))
		out++;

	char *end = out;
	while (*end && !isspace(*end) && *end != '=')
		end++;

	*end++ = '\0';
	*buf = end;

	return out;
}

static inline char *
lif_next_token(char **buf)
{
	char *out = *buf;

	while (*out && isspace(*out))
		out++;

	char *end = out;
	while (*end && !isspace(*end))
		end++;

	*end++ = '\0';
	*buf = end;

	return out;
}

#endif