switch.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2009 iptelorg GmbH
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __switch_h
  17. #define __switch_h
  18. #include <stddef.h>
  19. #include <regex.h>
  20. #include "route_struct.h"
  21. struct case_stms{
  22. struct rval_expr* ct_rve;
  23. struct action* actions;
  24. struct case_stms* next;
  25. struct case_stms** append;
  26. int type; /**< type: MATCH_UNKOWN, MATCH_INT, MATCH_STR, MATCH_RE */
  27. int re_flags; /**< used only for REs */
  28. int is_default;
  29. union {
  30. int match_int;
  31. str match_str;
  32. regex_t* match_re;
  33. } label; /**< fixed case argument */
  34. };
  35. struct switch_cond_table{
  36. int n; /**< size */
  37. int* cond; /**< int labels array */
  38. struct action** jump; /**< jump points array */
  39. struct action* def; /**< default jump */
  40. };
  41. struct switch_jmp_table{
  42. int first; /**< first int label in the jump table */
  43. int last; /**< last int label in the jump table */
  44. struct action** tbl; /**< jmp table [v-first] iff first<=v<=last */
  45. struct switch_cond_table rest; /**< normal cond. table for the rest */
  46. };
  47. enum match_str_type { MATCH_UNKNOWN, MATCH_INT, MATCH_STR, MATCH_RE };
  48. struct match_str{
  49. enum match_str_type type;/**< string or RE */
  50. int flags; /**< flags for re */
  51. union{
  52. str s; /* string */
  53. regex_t* regex; /**< compiled regex */
  54. }l;
  55. };
  56. struct match_cond_table{
  57. int n; /**< size */
  58. struct match_str* match; /**< match array */
  59. struct action** jump; /**< jump points array */
  60. struct action* def; /**< default jmp */
  61. };
  62. int fix_switch(struct action* t);
  63. #endif /*__switch_h*/
  64. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */