switch.h 2.4 KB

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