Version 6.3
Copyright © 2005 - 2012 Lowell D. Thomas
APG
  … ABNF Parser Generator
All Data Structures Files Functions Variables Typedefs Macros Pages
Callbacks.cpp
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 "Apg.h"
26 #include "ApgUtilities.h"
27 #include "MEGACO.h"
28 #include <iostream>
29 
40 void MEGACO::vDefineSyntaxCallbacks(APG_CALLBACK* sppRuleCallbacks, APG_CALLBACK* sppUdtCallbacks){
41  if(sppRuleCallbacks){
42  memset((void*)sppRuleCallbacks, 0, sizeof(APG_CALLBACK) * MEGACO::RULEID_COUNT);
43  sppRuleCallbacks[MEGACO::RULEID_MEGACOMESSAGE] = MEGACO::uiSyn_megacoMessage;
44  sppRuleCallbacks[MEGACO::RULEID_MEGACOPTOKEN] = MEGACO::uiSyn_MegacopToken;
45  sppRuleCallbacks[MEGACO::RULEID_SEGMENTREPLY] = MEGACO::uiSyn_segmentReply;
46  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONPENDING] = MEGACO::uiSyn_transactionPending;
47  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONREPLY] = MEGACO::uiSyn_transactionReply;
48  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONREQUEST] = MEGACO::uiSyn_transactionRequest;
49  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONRESPONSEACK] = MEGACO::uiSyn_transactionResponseAck;
50  sppRuleCallbacks[MEGACO::RULEID_VERSION] = MEGACO::uiSyn_Version;
51  }
52  if(sppUdtCallbacks){
53  memset((void*)sppUdtCallbacks, 0, sizeof(APG_CALLBACK) * MEGACO::UDTID_COUNT);
54  }
55 }
56 // To initialize the AST callback functions before AST translation,
57 // uncomment any required callback functions.
58 // sppRuleCallbacks array length must be at least MEGACO::RULEID_COUNT.
59 // sppUdtCallbacks array length must be at least MEGACO::UDTID_COUNT.
60 // No bounds checking is done.
61 // Arguments may be NULL.
62 void MEGACO::vDefineAstCallbacks(APG_CALLBACK* sppRuleCallbacks, APG_CALLBACK* sppUdtCallbacks){
63  if(sppRuleCallbacks){
64  memset((void*)sppRuleCallbacks, 0, sizeof(APG_CALLBACK) * MEGACO::RULEID_COUNT);
65  sppRuleCallbacks[MEGACO::RULEID_MEGACOMESSAGE] = MEGACO::uiAst_megacoMessage;
66  sppRuleCallbacks[MEGACO::RULEID_MEGACOPTOKEN] = MEGACO::uiAst_MegacopToken;
67  sppRuleCallbacks[MEGACO::RULEID_SEGMENTREPLY] = MEGACO::uiAst_segmentReply;
68  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONPENDING] = MEGACO::uiAst_transactionPending;
69  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONREPLY] = MEGACO::uiAst_transactionReply;
70  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONREQUEST] = MEGACO::uiAst_transactionRequest;
71  sppRuleCallbacks[MEGACO::RULEID_TRANSACTIONRESPONSEACK] = MEGACO::uiAst_transactionResponseAck;
72  sppRuleCallbacks[MEGACO::RULEID_VERSION] = MEGACO::uiAst_Version;
73  }
74  if(sppUdtCallbacks){
75  memset((void*)sppUdtCallbacks, 0, sizeof(APG_CALLBACK) * MEGACO::UDTID_COUNT);
76  }
77 }
78 
79 static void vSynTranslate(apg_uint uiState, const char* cpName){
80  switch(uiState){
81  case PRE_PARSE:
82  printf(" PRE_PARSE: %s\n", cpName);
83  break;
84  case NOMATCH:
85  printf(" NOMATCH: %s\n", cpName);
86  break;
87  case MATCH:
88  printf(" MATCH: %s\n", cpName);
89  break;
90  case EMPTY:
91  printf(" EMPTY: %s\n", cpName);
92  break;
93  }
94 }
95 apg_uint MEGACO::uiSyn_megacoMessage(APG_CBDATA* spData){
96  apg_uint uiRet = APG_FALSE;
97  if(spData->uiState == PRE_PARSE){printf("\nMEGACO: syntax callback messages: begin\n");}
98  vSynTranslate(spData->uiState, "uiSyn_megacoMessage");
99  if(spData->uiState != PRE_PARSE){printf("MEGACO: syntax callback messages: end\n");}
100  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
101 }
102 
103 apg_uint MEGACO::uiSyn_MegacopToken(APG_CBDATA* spData){
104  apg_uint uiRet = APG_FALSE;
105  vSynTranslate(spData->uiState, "uiSyn_MegacopToken");
106  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
107 }
108 
109 apg_uint MEGACO::uiSyn_segmentReply(APG_CBDATA* spData){
110  apg_uint uiRet = APG_FALSE;
111  vSynTranslate(spData->uiState, "uiSyn_segmentReply");
112  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
113 }
114 
115 apg_uint MEGACO::uiSyn_transactionPending(APG_CBDATA* spData){
116  apg_uint uiRet = APG_FALSE;
117  vSynTranslate(spData->uiState, "uiSyn_transactionPending");
118  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
119 }
120 
121 apg_uint MEGACO::uiSyn_transactionReply(APG_CBDATA* spData){
122  apg_uint uiRet = APG_FALSE;
123  vSynTranslate(spData->uiState, "uiSyn_transactionReply");
124  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
125 }
126 
127 apg_uint MEGACO::uiSyn_transactionResponseAck(APG_CBDATA* spData){
128  apg_uint uiRet = APG_FALSE;
129  vSynTranslate(spData->uiState, "uiSyn_transactionResponseAck");
130  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
131 }
132 
133 apg_uint MEGACO::uiSyn_transactionRequest(APG_CBDATA* spData){
134  apg_uint uiRet = APG_FALSE;
135  vSynTranslate(spData->uiState, "uiSyn_transactionRequest");
136  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
137 }
138 
139 apg_uint MEGACO::uiSyn_Version(APG_CBDATA* spData){
140  apg_uint uiRet = APG_FALSE;
141  vSynTranslate(spData->uiState, "uiSyn_Version");
142  return uiRet; // if APG_TRUE this function will override the normal parsing of this rule
143 }
144 
145 static void vAstTranslate(apg_uint uiState, const char* cpName){
146  switch(uiState){
147  case PRE_AST:
148  printf(" PRE_AST: %s\n", cpName);
149  break;
150  case POST_AST:
151  printf(" POST_AST: %s\n", cpName);
152  break;
153  }
154 }
155 apg_uint MEGACO::uiAst_megacoMessage(APG_CBDATA* spData){
156  if(spData->uiState == PRE_AST){printf("\nMEGACO: AST callback messages: begin\n");}
157  vAstTranslate(spData->uiState, "uiAst_megacoMessage");
158  if(spData->uiState == POST_AST){printf("MEGACO: AST callback messages: end\n");}
159  return APG_UNDEFINED; // return value ignored by parser
160 }
161 
162 apg_uint MEGACO::uiAst_MegacopToken(APG_CBDATA* spData){
163  vAstTranslate(spData->uiState, "uiAst_MegacopToken");
164  return APG_UNDEFINED; // return value ignored by parser
165 }
166 
167 apg_uint MEGACO::uiAst_Version(APG_CBDATA* spData){
168  vAstTranslate(spData->uiState, "uiAst_Version");
169  return APG_UNDEFINED; // return value ignored by parser
170 }
171 
172 apg_uint MEGACO::uiAst_transactionRequest(APG_CBDATA* spData){
173  vAstTranslate(spData->uiState, "uiAst_transactionRequest");
174  return APG_UNDEFINED; // return value ignored by parser
175 }
176 
177 apg_uint MEGACO::uiAst_transactionReply(APG_CBDATA* spData){
178  vAstTranslate(spData->uiState, "uiAst_transactionReply");
179  return APG_UNDEFINED; // return value ignored by parser
180 }
181 
182 apg_uint MEGACO::uiAst_transactionResponseAck(APG_CBDATA* spData){
183  vAstTranslate(spData->uiState, "uiAst_transactionResponseAck");
184  return APG_UNDEFINED; // return value ignored by parser
185 }
186 
187 apg_uint MEGACO::uiAst_transactionPending(APG_CBDATA* spData){
188  vAstTranslate(spData->uiState, "uiAst_transactionPending");
189  return APG_UNDEFINED; // return value ignored by parser
190 }
191 
192 apg_uint MEGACO::uiAst_segmentReply(APG_CBDATA* spData){
193  vAstTranslate(spData->uiState, "uiAst_segmentReply");
194  return APG_UNDEFINED; // return value ignored by parser
195 }
POST_AST
#define POST_AST
Definition: Apg.h:556
apg_uint
unsigned int apg_uint
Definition: Apg.h:169
APG_CALLBACK
apg_uint(* APG_CALLBACK)(APG_CBDATA *spData)
Definition: Apg.h:515
PRE_PARSE
#define PRE_PARSE
Definition: Apg.h:526
Apg.h
Required header file for all APG-generated parsers. Contains important configuration macros and decla...
EMPTY
#define EMPTY
Definition: Apg.h:538
APG_CBDATA::uiState
apg_uint uiState
Definition: Apg.h:458
ApgUtilities.h
Declarations of all APG utility functions.
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
MATCH
#define MATCH
Definition: Apg.h:544
APG_FALSE
#define APG_FALSE
Definition: Apg.h:190
PRE_AST
#define PRE_AST
Definition: Apg.h:550
NOMATCH
#define NOMATCH
Definition: Apg.h:532
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.