IDZEBRA 2.2.8
zint.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20#if HAVE_CONFIG_H
21#include <config.h>
22#endif
23#include <stdlib.h>
24#include <idzebra/util.h>
25
26void zebra_zint_encode(char **dst, zint pos)
27{
28 unsigned char *bp = (unsigned char*) *dst;
29
30 while (pos > 127)
31 {
32 *bp++ = (unsigned char) (128 | (pos & 127));
33 pos = pos >> 7;
34 }
35 *bp++ = (unsigned char) pos;
36 *dst = (char *) bp;
37}
38
39void zebra_zint_decode(const char **src, zint *pos)
40{
41 const unsigned char **bp = (const unsigned char **) src;
42 zint d = 0;
43 unsigned char c;
44 unsigned r = 0;
45
46 while (((c = *(*bp)++) & 128))
47 {
48 d += ((zint) (c & 127) << r);
49 r += 7;
50 }
51 d += ((zint) c << r);
52 *pos = d;
53}
54
55zint atozint(const char *src)
56{
57#if HAVE_ATOLL
58 return atoll(src);
59#else
60 return atoi(src);
61#endif
62}
63
64/*
65 * Local variables:
66 * c-basic-offset: 4
67 * c-file-style: "Stroustrup"
68 * indent-tabs-mode: nil
69 * End:
70 * vim: shiftwidth=4 tabstop=8 expandtab
71 */
72
long zint
Zebra integer.
Definition util.h:66
void zebra_zint_decode(const char **src, zint *pos)
Definition zint.c:39
void zebra_zint_encode(char **dst, zint pos)
Definition zint.c:26
zint atozint(const char *src)
Definition zint.c:55