ifparser.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. *
  3. * Copyright 1992 Network Computing Devices, Inc.
  4. *
  5. * Permission to use, copy, modify, and distribute this software and its
  6. * documentation for any purpose and without fee is hereby granted, provided
  7. * that the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Network Computing Devices may not be
  10. * used in advertising or publicity pertaining to distribution of the software
  11. * without specific, written prior permission. Network Computing Devices makes
  12. * no representations about the suitability of this software for any purpose.
  13. * It is provided ``as is'' without express or implied warranty.
  14. *
  15. * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  17. * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
  18. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  19. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Author: Jim Fulton
  24. * Network Computing Devices, Inc.
  25. *
  26. * Simple if statement processor
  27. *
  28. * This module can be used to evaluate string representations of C language
  29. * if constructs. It accepts the following grammar:
  30. *
  31. * EXPRESSION := VALUE
  32. * | VALUE BINOP EXPRESSION
  33. * | VALUE '?' EXPRESSION ':' EXPRESSION
  34. *
  35. * VALUE := '(' EXPRESSION ')'
  36. * | '!' VALUE
  37. * | '-' VALUE
  38. * | '~' VALUE
  39. * | 'defined' '(' variable ')'
  40. * | variable
  41. * | number
  42. *
  43. * BINOP := '*' | '/' | '%'
  44. * | '+' | '-'
  45. * | '<<' | '>>'
  46. * | '<' | '>' | '<=' | '>='
  47. * | '==' | '!='
  48. * | '&' | '^' | '|'
  49. * | '&&' | '||'
  50. *
  51. * The normal C order of precedence is supported.
  52. *
  53. *
  54. * External Entry Points:
  55. *
  56. * ParseIfExpression parse a string for #if
  57. */
  58. #include <stdio.h>
  59. typedef int Bool;
  60. #define False 0
  61. #define True 1
  62. typedef struct _if_parser {
  63. struct { /* functions */
  64. const char *(*handle_error) (struct _if_parser *, const char *,
  65. const char *);
  66. long (*eval_variable) (struct _if_parser *, const char *, int);
  67. int (*eval_defined) (struct _if_parser *, const char *, int);
  68. } funcs;
  69. char *data;
  70. } IfParser;
  71. const char *ParseIfExpression (
  72. IfParser *,
  73. const char *,
  74. long *
  75. );