template_lmo.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. struct lmo_entry {
  35. uint32_t key_id;
  36. uint32_t val_id;
  37. uint32_t offset;
  38. uint32_t length;
  39. } __attribute__((packed));
  40. typedef struct lmo_entry lmo_entry_t;
  41. struct lmo_archive {
  42. int fd;
  43. int length;
  44. uint32_t size;
  45. lmo_entry_t *index;
  46. char *mmap;
  47. char *end;
  48. struct lmo_archive *next;
  49. };
  50. typedef struct lmo_archive lmo_archive_t;
  51. struct lmo_catalog {
  52. char lang[6];
  53. struct lmo_archive *archives;
  54. struct lmo_catalog *next;
  55. };
  56. typedef struct lmo_catalog lmo_catalog_t;
  57. int lmo_load_catalog(const char *lang, const char *dir);
  58. int lmo_change_catalog(const char *lang);
  59. int lmo_translate(const char *key, int keylen, char **out, int *outlen);
  60. #endif