libs/web: include limits.h to fix compilation on OS X (#531)
[project/luci.git] / libs / web / src / template_lmo.h
1 /*
2  * lmo - Lua Machine Objects - General header
3  *
4  *   Copyright (C) 2009-2012 Jo-Philipp Wich <xm@subsignal.org>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18
19 #ifndef _TEMPLATE_LMO_H_
20 #define _TEMPLATE_LMO_H_
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdint.h>
25 #include <string.h>
26 #include <fcntl.h>
27 #include <sys/stat.h>
28 #include <sys/mman.h>
29 #include <arpa/inet.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <fnmatch.h>
33 #include <dirent.h>
34 #include <ctype.h>
35 #include <limits.h>
36
37 #if (defined(__GNUC__) && defined(__i386__))
38 #define sfh_get16(d) (*((const uint16_t *) (d)))
39 #else
40 #define sfh_get16(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
41                                            +(uint32_t)(((const uint8_t *)(d))[0]) )
42 #endif
43
44
45 struct lmo_entry {
46         uint32_t key_id;
47         uint32_t val_id;
48         uint32_t offset;
49         uint32_t length;
50 } __attribute__((packed));
51
52 typedef struct lmo_entry lmo_entry_t;
53
54
55 struct lmo_archive {
56         int         fd;
57         int             length;
58         uint32_t    size;
59         lmo_entry_t *index;
60         char        *mmap;
61         char            *end;
62         struct lmo_archive *next;
63 };
64
65 typedef struct lmo_archive lmo_archive_t;
66
67
68 struct lmo_catalog {
69         char lang[6];
70         struct lmo_archive *archives;
71         struct lmo_catalog *next;
72 };
73
74 typedef struct lmo_catalog lmo_catalog_t;
75
76
77 uint32_t sfh_hash(const char *data, int len);
78 uint32_t lmo_canon_hash(const char *data, int len);
79
80 lmo_archive_t * lmo_open(const char *file);
81 void lmo_close(lmo_archive_t *ar);
82
83
84 extern lmo_catalog_t *_lmo_catalogs;
85 extern lmo_catalog_t *_lmo_active_catalog;
86
87 int lmo_load_catalog(const char *lang, const char *dir);
88 int lmo_change_catalog(const char *lang);
89 int lmo_translate(const char *key, int keylen, char **out, int *outlen);
90 void lmo_close_catalog(const char *lang);
91
92 #endif