ifparser.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $XConsortium: ifparser.h /main/4 1996/09/28 16:15:24 rws $
  25. *
  26. * Copyright 1992 Network Computing Devices, Inc.
  27. *
  28. * Permission to use, copy, modify, and distribute this software and its
  29. * documentation for any purpose and without fee is hereby granted, provided
  30. * that the above copyright notice appear in all copies and that both that
  31. * copyright notice and this permission notice appear in supporting
  32. * documentation, and that the name of Network Computing Devices may not be
  33. * used in advertising or publicity pertaining to distribution of the software
  34. * without specific, written prior permission. Network Computing Devices makes
  35. * no representations about the suitability of this software for any purpose.
  36. * It is provided ``as is'' without express or implied warranty.
  37. *
  38. * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  39. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  40. * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
  41. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  42. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  43. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  44. * PERFORMANCE OF THIS SOFTWARE.
  45. *
  46. * Author: Jim Fulton
  47. * Network Computing Devices, Inc.
  48. *
  49. * Simple if statement processor
  50. *
  51. * This module can be used to evaluate string representations of C language
  52. * if constructs. It accepts the following grammar:
  53. *
  54. * EXPRESSION := VALUE
  55. * | VALUE BINOP EXPRESSION
  56. *
  57. * VALUE := '(' EXPRESSION ')'
  58. * | '!' VALUE
  59. * | '-' VALUE
  60. * | 'defined' '(' variable ')'
  61. * | variable
  62. * | number
  63. *
  64. * BINOP := '*' | '/' | '%'
  65. * | '+' | '-'
  66. * | '<<' | '>>'
  67. * | '<' | '>' | '<=' | '>='
  68. * | '==' | '!='
  69. * | '&' | '|'
  70. * | '&&' | '||'
  71. *
  72. * The normal C order of precidence is supported.
  73. *
  74. *
  75. * External Entry Points:
  76. *
  77. * ParseIfExpression parse a string for #if
  78. */
  79. #include <stdlib.h>
  80. #include <stdio.h>
  81. #define const /**/
  82. typedef int Bool;
  83. #define False 0
  84. #define True 1
  85. typedef struct _if_parser {
  86. struct { /* functions */
  87. char *(*handle_error) (/* struct _if_parser *, const char *,
  88. const char * */);
  89. long (*eval_variable) (/* struct _if_parser *, const char *, int */);
  90. int (*eval_defined) (/* struct _if_parser *, const char *, int */);
  91. } funcs;
  92. char *data;
  93. } IfParser;
  94. char *ParseIfExpression (
  95. #ifdef __STDC__
  96. IfParser *,
  97. const char *,
  98. long *
  99. #endif
  100. );