00001 #include "vapiLists.h"
00002 #include "vapiTypes.h"
00003 #include "vapiString.h"
00004 #ifndef VAPI_DEBUG_MACRO_BYPASS
00005 #define v_debug(val,...)
00006 #endif
00007 typedef struct _vBypassItem
00008 {
00009 char *macroTag;
00010 vBoolean *ByPassArray;
00011 vBoolean *StopByArray;
00012 int NumberOfMacroOperations;
00013 } vBypassItem;
00014
00015 static struct
00016 {
00017 vList *List;
00018 vBoolean Updatable;
00019 } Bypass;
00020
00021 void
00022 v_bypass_init ()
00023 {
00024 Bypass.List = v_list_new ();
00025 Bypass.Updatable = vTRUE;
00026 }
00027
00028 void
00029 v_bypass_append (const char *macroTag, int NumberOfMacroOperations)
00030 {
00031 vBypassItem *BypassItem;
00032 int i;
00033 v_debug ("bypass init macro Tags: %s", macroTag);
00034 BypassItem = malloc (sizeof (vBypassItem));
00035 BypassItem->NumberOfMacroOperations = NumberOfMacroOperations;
00036 if (NumberOfMacroOperations > 0)
00037 {
00038 BypassItem->ByPassArray =
00039 malloc (BypassItem->NumberOfMacroOperations *
00040 sizeof (vBoolean));
00041 BypassItem->StopByArray =
00042 malloc (BypassItem->NumberOfMacroOperations *
00043 sizeof (vBoolean));
00044 for (i = 0; i < BypassItem->NumberOfMacroOperations; i++)
00045 {
00046 BypassItem->ByPassArray[i] = vTRUE;
00047 BypassItem->StopByArray[i] = vFALSE;
00048
00049 }
00050 }
00051
00052 BypassItem->macroTag = v_printf ("%s", macroTag);
00053
00054
00055
00056
00057 if (strchr (macroTag, ':') == NULL && NumberOfMacroOperations)
00058 {
00059 BypassItem->
00060 StopByArray[(BypassItem->NumberOfMacroOperations -
00061 1)] = vTRUE;
00062 }
00063 v_list_append (Bypass.List, BypassItem);
00064 }
00065
00066 static vBypassItem *
00067 v_bypass_search (const char *macroTag)
00068 {
00069 int i, ListSize;
00070 vBypassItem *tempBypassItem;
00071 v_debug ("BYPASS SEARCH MAROTAG: %s", macroTag);
00072 ListSize = v_list_count_elements (Bypass.List);
00073 if (ListSize == 0)
00074 {
00075 return NULL;
00076 }
00077 for (i = 0; i < ListSize; i++)
00078 {
00079 tempBypassItem = v_list_get (Bypass.List, i);
00080
00081 if (!strcmp (tempBypassItem->macroTag, macroTag))
00082 {
00083 v_debug("bypass_search found");
00084 return tempBypassItem;
00085 }
00086 }
00087 v_debug("bypass_search nothing");
00088 return NULL;
00089 }
00090
00091 void
00092 v_bypass_set (const char *macroTag, int itemNum)
00093 {
00094 vBypassItem *tempBypassItem;
00095 tempBypassItem = v_bypass_search (macroTag);
00096
00097 if (tempBypassItem == NULL)
00098 {
00099 return;
00100 }
00101
00102 if (tempBypassItem->ByPassArray[itemNum])
00103 {
00104 tempBypassItem->ByPassArray[itemNum] = vFALSE;
00105 }
00106 else
00107 {
00108 tempBypassItem->ByPassArray[itemNum] = vTRUE;
00109 }
00110 }
00111
00112 vBoolean
00113 v_bypass_get (const char *macroTag, int itemNum)
00114 {
00115 vBypassItem *tempBypassItem;
00116 v_debug ("BYPASS TO SEARCH");
00117 tempBypassItem = v_bypass_search (macroTag);
00118 v_debug ("BYPASS FROM SEARCH");
00119 if (tempBypassItem == NULL)
00120 {
00121 v_debug ("BYPASS SEARCH NOTHING");
00122 return vTRUE;
00123 }
00124 v_debug ("BYPASS SEARCH ENCONTROU");
00125 return tempBypassItem->ByPassArray[itemNum];
00126 }
00127
00128 void
00129 v_bypass_item_free (vBypassItem * vFree)
00130 {
00131 if (vFree->NumberOfMacroOperations > 0)
00132 {
00133 free (vFree->ByPassArray);
00134 free (vFree->StopByArray);
00135 }
00136 free (vFree->macroTag);
00137 free (vFree);
00138 }
00139
00140 void
00141 v_bypass_clean ()
00142 {
00143 v_list_free (Bypass.List, (vpointer) & v_bypass_item_free);
00144 }
00145
00146 vBoolean
00147 v_stopby_get (const char *macroTag, int itemNum)
00148 {
00149 vBypassItem *tempBypassItem;
00150 tempBypassItem = v_bypass_search (macroTag);
00151 if (tempBypassItem == NULL)
00152 {
00153 v_debug ("BYPASS SEARCH NOTHING");
00154 return vTRUE;
00155 }
00156 v_debug ("BYPASS SEARCH STOP BY");
00157 if (tempBypassItem->StopByArray[itemNum])
00158 v_debug("STOP STP");
00159 return tempBypassItem->StopByArray[itemNum];
00160 }
00161
00162 void
00163 v_stopby_set (const char *macroTag, int itemNum)
00164 {
00165 vBypassItem *tempBypassItem;
00166 int j, ListSize;
00167
00168 ListSize = v_list_count_elements (Bypass.List);
00169 for (j = 0; j < ListSize; j++)
00170 {
00171 tempBypassItem = v_list_get (Bypass.List, j);
00172 if (!strcmp (macroTag, tempBypassItem->macroTag))
00173 {
00174 if (tempBypassItem->StopByArray[itemNum])
00175 {
00176 tempBypassItem->StopByArray[itemNum] = vFALSE;
00177 }
00178 else
00179 {
00180 tempBypassItem->StopByArray[itemNum] = vTRUE;
00181 }
00182 }
00183 }
00184 }
00185
00186
00187 void
00188 v_bypass_reload ()
00189 {
00190 int ListSize = v_list_count_elements (Bypass.List);
00191 v_debug ("bypass listsize %d", ListSize);
00192 if (ListSize > 0 && Bypass.Updatable)
00193 {
00194 v_bypass_clean ();
00195 v_bypass_init ();
00196 }
00197 }
00198
00199 void
00200 v_bypass_set_updatable (vBoolean Updatable)
00201 {
00202 Bypass.Updatable = Updatable;
00203 }
00204
00205