Version 6.3
Copyright © 2005 - 2012 Lowell D. Thomas
APG
  … ABNF Parser Generator
All Data Structures Files Functions Variables Typedefs Macros Pages
Callbacks.c
Go to the documentation of this file.
1 /*******************************************************************************
2  APG Version 6.3
3  Copyright (C) 2005 - 2012 Lowell D. Thomas, all rights reserved
4 
5  author: Lowell D. Thomas
6  email: lowell@coasttocoastresearch.com
7  website: http://www.coasttocoastresearch.com
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see
21  <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
22  or write to the Free Software Foundation, Inc.,
23  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 *******************************************************************************/
25 #include "main.h"
29 static apg_uint examples(APG_CBDATA* spData){
30  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
31  if(spData->uiState == PRE_AST){
32  spCallbackCtx->spFile = fopen(spCallbackCtx->cpFileName, "w");
33  MASSERT(spCallbackCtx->spFile, "examples: can't open output file name");
34  spCallbackCtx->uiExampleNo = 0;
35  fprintf(spCallbackCtx->spFile, "<body>");
36  fprintf(spCallbackCtx->spFile, "<h1>APG Version 6.3</h1>");
37  fprintf(spCallbackCtx->spFile, "Copyright &copy; 2005 - 2012 Lowell D. Thomas<br>");
38  fprintf(spCallbackCtx->spFile, "lowell@coasttocoastresearch.com");
39  fprintf(spCallbackCtx->spFile, "<h2>Wide Characters Example</h2>");
40  fprintf(spCallbackCtx->spFile, "<p>To view this example correctly, your browser should ");
41  fprintf(spCallbackCtx->spFile, "support the UNICODE code charts for Cherokee, Greek and Cyrillic.</br>");
42  fprintf(spCallbackCtx->spFile, "See <a href=\"http://unicode.org/versions/latest/\">http://unicode.org/versions/latest/</a> and");
43  fprintf(spCallbackCtx->spFile, "See <a href=\"http://unicode.org/charts/\">http://unicode.org/charts/</a>.</p>");
44  } else{
45  fprintf(spCallbackCtx->spFile, "</body>\n");
46  spCallbackCtx->spFile = fopen(spCallbackCtx->cpFileName, "w");
47  spCallbackCtx->spFile = NULL;
48  }
49  return APG_UNDEFINED;
50 }
51 
52 static apg_uint end(APG_CBDATA* spData){
53  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
54  if(spData->uiState == POST_AST){
55  spCallbackCtx->uiExampleNo++;
56  }
57  return APG_UNDEFINED;
58 }
59 
60 static apg_uint er_ex(APG_CBDATA* spData){
61  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
62  if(spData->uiState == PRE_AST){
63  fprintf(spCallbackCtx->spFile, "error: unknown language: ");
64  } else{
65  fprintf(spCallbackCtx->spFile, "</br>\n");
66  fprintf(spCallbackCtx->spFile, "\n");
67  }
68  return APG_UNDEFINED;
69 }
70 
71 static apg_uint er_char(APG_CBDATA* spData){
72  const apg_achar* acpString = spData->acpSrc + spData->uiPhraseOffset;
73  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
74  if(spData->uiState == POST_AST){
75  apg_achar acChar = acpString[0];
76  if(acChar >= (apg_achar)32 && acChar <= (apg_achar)126){
77  fprintf(spCallbackCtx->spFile, "%c", (char)acChar);
78  }
79  fprintf(spCallbackCtx->spFile, "&#x%x;", acChar);
80  }
81  return APG_UNDEFINED;
82 }
83 
84 static apg_uint cher_ex(APG_CBDATA* spData){
85  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
86  if(spData->uiState == PRE_AST){
87  fprintf(spCallbackCtx->spFile, "Cherokee: ");
88  } else{
89  fprintf(spCallbackCtx->spFile, "</br>\n");
90  fprintf(spCallbackCtx->spFile, "\n");
91  }
92  return APG_UNDEFINED;
93 }
94 
95 static apg_uint cher_char(APG_CBDATA* spData){
96  const apg_achar* acpString = spData->acpSrc + spData->uiPhraseOffset;
97  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
98  if(spData->uiState == POST_AST){
99  fprintf(spCallbackCtx->spFile, "&#x%x;", acpString[0]);
100  }
101  return APG_UNDEFINED;
102 }
103 
104 static apg_uint cyr_ex(APG_CBDATA* spData){
105  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
106  if(spData->uiState == PRE_AST){
107  fprintf(spCallbackCtx->spFile, "Cyrillic: ");
108  } else{
109  fprintf(spCallbackCtx->spFile, "</br>\n");
110  fprintf(spCallbackCtx->spFile, "\n");
111  }
112  return APG_UNDEFINED;
113 }
114 
115 static apg_uint cyr_char(APG_CBDATA* spData){
116  const apg_achar* acpString = spData->acpSrc + spData->uiPhraseOffset;
117  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
118  if(spData->uiState == POST_AST){
119  fprintf(spCallbackCtx->spFile, "&#x%x;", acpString[0]);
120  }
121  return APG_UNDEFINED;
122 }
123 
124 static apg_uint gr_ex(APG_CBDATA* spData){
125  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
126  if(spData->uiState == PRE_AST){
127  fprintf(spCallbackCtx->spFile, "Greek: ");
128  } else{
129  fprintf(spCallbackCtx->spFile, "</br>\n");
130  fprintf(spCallbackCtx->spFile, "\n");
131  }
132  return APG_UNDEFINED;
133 }
134 
135 static apg_uint gr_char(APG_CBDATA* spData){
136  const apg_achar* acpString = spData->acpSrc + spData->uiPhraseOffset;
137  CALLBACK_CTX* spCallbackCtx = (CALLBACK_CTX*)spData->vpUserData;
138  if(spData->uiState == POST_AST){
139  fprintf(spCallbackCtx->spFile, "&#x%x;", acpString[0]);
140  }
141  return APG_UNDEFINED;
142 }
143 
145 void vSemanticInit(APG_CALLBACK* spSemantic){
146  APG_CALLBACK* spBeg = spSemantic;
147  APG_CALLBACK* spEnd = spSemantic + RULE_COUNT_WIDEGRAMMAR;
148  for(; spBeg < spEnd; spBeg++){*spBeg = NULL;}
149  spSemantic[RULE_WIDEGRAMMAR_UTF32_EXAMPLES] = examples;
150  spSemantic[RULE_WIDEGRAMMAR_CHEROKEE_CHAR] = cher_char;
151  spSemantic[RULE_WIDEGRAMMAR_CHEROKEE_EXAMPLE] = cher_ex;
152  spSemantic[RULE_WIDEGRAMMAR_CYRILLIC_CHAR] = cyr_char;
153  spSemantic[RULE_WIDEGRAMMAR_CYRILLIC_EXAMPLE] = cyr_ex;
154  spSemantic[RULE_WIDEGRAMMAR_END] = end;
155  spSemantic[RULE_WIDEGRAMMAR_ERROR_EXAMPLE] = er_ex;
156  spSemantic[RULE_WIDEGRAMMAR_ERROR_CHAR] = er_char;
157  spSemantic[RULE_WIDEGRAMMAR_GREEK_CHAR] = gr_char;
158  spSemantic[RULE_WIDEGRAMMAR_GREEK_EXAMPLE] = gr_ex;
159 }
POST_AST
#define POST_AST
Definition: Apg.h:556
APG_CBDATA::acpSrc
const apg_achar * acpSrc
Definition: Apg.h:455
apg_uint
unsigned int apg_uint
Definition: Apg.h:169
APG_CALLBACK
apg_uint(* APG_CALLBACK)(APG_CBDATA *spData)
Definition: Apg.h:515
APG_CBDATA::uiPhraseOffset
apg_uint uiPhraseOffset
Definition: Apg.h:457
MASSERT
#define MASSERT(cond, msg)
Definition: main.cpp:33
APG_CBDATA::uiState
apg_uint uiState
Definition: Apg.h:458
apg_achar
unsigned char apg_achar
Definition: Apg.h:183
APG_CBDATA
The data structure passed to all syntax and AST callback functions, both rule and UDT.
Definition: Apg.h:453
APG_UNDEFINED
#define APG_UNDEFINED
Definition: Apg.h:194
APG_CBDATA::vpUserData
void * vpUserData
Definition: Apg.h:460
PRE_AST
#define PRE_AST
Definition: Apg.h:550
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/licenses.html or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.