[Fawkes Git] branch/jrothe/plugin_generator: plugin_generator: check if plugin_name input is valid

Johannes Rothe johannes.rothe at rwth-aachen.de
Tue Sep 6 15:54:31 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, jrothe/plugin_generator has been updated
        to  b5a08f86909c04a9e064ec401434c56a630f9ff6 (commit)
      from  719b73418b66a30c5078d2fc099d27c68e06f101 (commit)

http://git.fawkesrobotics.org/fawkes.git/jrothe/plugin_generator

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit b5a08f86909c04a9e064ec401434c56a630f9ff6
Author:     Johannes Rothe <johannes.rothe at rwth-aachen.de>
AuthorDate: Tue Sep 6 15:54:02 2016 +0200
Commit:     Johannes Rothe <johannes.rothe at rwth-aachen.de>
CommitDate: Tue Sep 6 15:54:02 2016 +0200

    plugin_generator: check if plugin_name input is valid

http://git.fawkesrobotics.org/fawkes.git/commit/b5a08f8
http://trac.fawkesrobotics.org/changeset/b5a08f8

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/tools/plugin_generator/main.cpp             |   30 +++++++++++++---------
 src/tools/plugin_generator/plugin_generator.cpp |    2 +
 2 files changed, 20 insertions(+), 12 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* b5a08f86909c04a9e064ec401434c56a630f9ff6 - - - - - - - - - -
Author:  Johannes Rothe <johannes.rothe at rwth-aachen.de>
Date:    Tue Sep 6 15:54:02 2016 +0200
Subject: plugin_generator: check if plugin_name input is valid

 src/tools/plugin_generator/main.cpp             |   30 +++++++++++++---------
 src/tools/plugin_generator/plugin_generator.cpp |    2 +
 2 files changed, 20 insertions(+), 12 deletions(-)

_Diff for modified files_:
diff --git a/src/tools/plugin_generator/main.cpp b/src/tools/plugin_generator/main.cpp
index 3051a0e..cf1dfc5 100644
--- a/src/tools/plugin_generator/main.cpp
+++ b/src/tools/plugin_generator/main.cpp
@@ -28,16 +28,6 @@
 using namespace std;
 using namespace fawkes;
 
-/*
- * Usage:
- * Author -> from input
- * Date -> from system
- * Name of the plugin -> from input 
- * Description -> from input
- *
- * Maybe libraries to include in the Makefile and as includes
- */
-
 void
 print_usage(const char *program_name)
 {
@@ -63,6 +53,17 @@ generate_plugin(std::string author_name, std::string plugin_name, std::string de
   generator->generate();
 }
 
+bool
+plugin_name_valid(std::string plugin_name){
+  for (char& c : plugin_name){
+    if (isalpha(c) || c == '-' || c == '_') {
+    } else {
+      return false;
+    }
+  }
+  return true;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -75,10 +76,15 @@ main(int argc, char **argv)
 
   std::string author_name, plugin_name, description, directory;
   if (argp.num_items() != 4) {
-    printf("Invalid number of arguments\n");
+    printf("ERROR: Invalid number of arguments\n");
     print_usage(argv[0]);
     exit(1);
-  } else {
+  } else if (!plugin_name_valid(argp.items()[1])) {
+    printf("ERROR: Invalid plugin name: Only alphanumerical chars allowed. \n"
+        "To separate multiple words use '-' or '_'\n");
+    exit(2);
+  }
+    else {
     author_name = argp.items()[0];
     plugin_name = argp.items()[1];
     description = argp.items()[2];
diff --git a/src/tools/plugin_generator/plugin_generator.cpp b/src/tools/plugin_generator/plugin_generator.cpp
index 3b14aa3..2fb3b9d 100644
--- a/src/tools/plugin_generator/plugin_generator.cpp
+++ b/src/tools/plugin_generator/plugin_generator.cpp
@@ -383,4 +383,6 @@ PluginGenerator::generate()
   fclose(thread_h);
   fclose(plugin_cpp);
   fclose(makefile);
+
+  printf("Plugin %s successfully created!\n",  _plugin_name.c_str());
 }




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list