Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correctly handle lowercase and default values for route/symmetrical.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 26 Nov 2020 10:16:27 +0000 (11:16 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 26 Nov 2020 11:07:28 +0000 (12:07 +0100)
src/bindings/lua/lua_platf.cpp
src/surf/xml/surfxml_sax_cb.cpp

index 44845b5..44fd143 100644 (file)
@@ -370,16 +370,7 @@ int console_add_route(lua_State *L) {
    */
   lua_pushstring(L,"symmetrical");
   lua_gettable(L,-2);
-  if (lua_isstring(L, -1)) {
-    const char* value = lua_tostring(L, -1);
-    if (strcmp("YES", value) == 0)
-      route.symmetrical = true;
-    else
-      route.symmetrical = false;
-  }
-  else {
-    route.symmetrical = true;
-  }
+  route.symmetrical = (not lua_isstring(L, -1) || strcasecmp("YES", lua_tostring(L, -1)) == 0);
   lua_pop(L,1);
 
   route.gw_src = nullptr;
@@ -442,16 +433,7 @@ int console_add_ASroute(lua_State *L) {
 
   lua_pushstring(L,"symmetrical");
   lua_gettable(L,-2);
-  if (lua_isstring(L, -1)) {
-    const char* value = lua_tostring(L, -1);
-    if (strcmp("YES", value) == 0)
-      ASroute.symmetrical = true;
-    else
-      ASroute.symmetrical = false;
-  }
-  else {
-    ASroute.symmetrical = true;
-  }
+  ASroute.symmetrical = (not lua_isstring(L, -1) || strcasecmp("YES", lua_tostring(L, -1)) == 0);
   lua_pop(L,1);
 
   sg_platf_new_route(&ASroute);
index 2fcff2f..62c38ee 100644 (file)
@@ -610,7 +610,9 @@ void ETag_surfxml_route(){
   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
   route.gw_src    = nullptr;
   route.gw_dst    = nullptr;
-  route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
+  route.symmetrical = (A_surfxml_route_symmetrical == AU_surfxml_route_symmetrical ||
+                       A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES ||
+                       A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_yes);
 
   route.link_list.swap(parsed_link_list);
 
@@ -638,17 +640,9 @@ void ETag_surfxml_zoneRoute()
 
   ASroute.link_list.swap(parsed_link_list);
 
-  switch (A_surfxml_zoneRoute_symmetrical) {
-  case AU_surfxml_zoneRoute_symmetrical:
-  case A_surfxml_zoneRoute_symmetrical_YES:
-    ASroute.symmetrical = true;
-    break;
-  case A_surfxml_zoneRoute_symmetrical_NO:
-    ASroute.symmetrical = false;
-    break;
-  default:
-    THROW_IMPOSSIBLE;
-  }
+  ASroute.symmetrical = (A_surfxml_zoneRoute_symmetrical == AU_surfxml_zoneRoute_symmetrical ||
+                         A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_YES ||
+                         A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_yes);
 
   sg_platf_new_route(&ASroute);
 }