template_lmo.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * lmo - Lua Machine Objects - General header
  3. *
  4. * Copyright (C) 2009-2012 Jo-Philipp Wich <jow@openwrt.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. #ifndef _TEMPLATE_LMO_H_
  19. #define _TEMPLATE_LMO_H_
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <string.h>
  24. #include <fcntl.h>
  25. #include <sys/stat.h>
  26. #include <sys/mman.h>
  27. #include <arpa/inet.h>
  28. #include <unistd.h>
  29. #include <errno.h>
  30. #include <fnmatch.h>
  31. #include <dirent.h>
  32. #include <ctype.h>
  33. #include <limits.h>
  34. #if (defined(__GNUC__) && defined(__i386__))
  35. #define sfh_get16(d) (*((const uint16_t *) (d)))
  36. #else
  37. #define sfh_get16(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
  38. +(uint32_t)(((const uint8_t *)(d))[0]) )
  39. #endif
  40. struct lmo_entry {
  41. uint32_t key_id;
  42. uint32_t val_id;
  43. uint32_t offset;
  44. uint32_t length;
  45. } __attribute__((packed));
  46. typedef struct lmo_entry lmo_entry_t;
  47. struct lmo_archive {
  48. int fd;
  49. int length;
  50. uint32_t size;
  51. lmo_entry_t *index;
  52. char *mmap;
  53. char *end;
  54. struct lmo_archive *next;
  55. };
  56. typedef struct lmo_archive lmo_archive_t;
  57. struct lmo_catalog {
  58. char lang[6];
  59. struct lmo_archive *archives;
  60. struct lmo_catalog *next;
  61. };
  62. typedef struct lmo_catalog lmo_catalog_t;
  63. int lmo_load_catalog(const char *lang, const char *dir);
  64. int lmo_change_catalog(const char *lang);
  65. int lmo_translate(const char *key, int keylen, char **out, int *outlen);
  66. #endif