[PATCH 3/9] add support for long data types

william.jon.mccann at gmail.com william.jon.mccann at gmail.com
Mon Feb 23 12:35:51 PST 2009


From: William Jon McCann <jmccann at redhat.com>

---
 src/libply/ply-command-parser.c |   37 +++++++++++++++++++++++++++++++++++++
 src/libply/ply-command-parser.h |    3 ++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c
index 29d47fa..5d77e00 100644
--- a/src/libply/ply-command-parser.c
+++ b/src/libply/ply-command-parser.c
@@ -38,6 +38,7 @@ typedef union
   bool as_boolean;
   char *as_string;
   int as_integer;
+  int as_long;
 } ply_command_option_result_t;
 
 typedef struct
@@ -164,6 +165,9 @@ get_type_string (int type)
     case PLY_COMMAND_OPTION_TYPE_INTEGER:
       option_type_string = "=<integer>";
       break;
+    case PLY_COMMAND_OPTION_TYPE_LONG:
+      option_type_string = "=<long>";
+      break;
     default:
       option_type_string = "";
       break;
@@ -516,6 +520,16 @@ ply_command_parser_get_options_for_command (ply_command_parser_t *parser,
                   *option_result = option->result.as_integer;
                 }
               break;
+
+              case PLY_COMMAND_OPTION_TYPE_LONG:
+                {
+                  long *option_result;
+
+                  option_result = va_arg (args, long *);
+
+                  *option_result = option->result.as_long;
+                }
+              break;
             }
         }
 
@@ -678,6 +692,29 @@ ply_command_option_read_arguments (ply_command_option_t *option,
          ply_list_remove_node (arguments, node);
          return true;
         }
+
+      case PLY_COMMAND_OPTION_TYPE_LONG:
+        {
+         char *end;
+         long argument_as_long;
+
+         if (argument[0] == '\0')
+           return false;
+
+         argument_as_long = strtol (argument, &end, 0);
+
+         if (*end != '\0')
+           return false;
+
+         if ((argument_as_long == LONG_MIN
+              || argument_as_long == LONG_MAX) &&
+             errno == ERANGE)
+           return false;
+
+         option->result.as_long = argument_as_long;
+         ply_list_remove_node (arguments, node);
+         return true;
+        }
     }
 
   return option;
diff --git a/src/libply/ply-command-parser.h b/src/libply/ply-command-parser.h
index 38078e4..805b518 100644
--- a/src/libply/ply-command-parser.h
+++ b/src/libply/ply-command-parser.h
@@ -35,7 +35,8 @@ typedef enum
   PLY_COMMAND_OPTION_TYPE_FLAG = 0,
   PLY_COMMAND_OPTION_TYPE_BOOLEAN,
   PLY_COMMAND_OPTION_TYPE_STRING,
-  PLY_COMMAND_OPTION_TYPE_INTEGER
+  PLY_COMMAND_OPTION_TYPE_INTEGER,
+  PLY_COMMAND_OPTION_TYPE_LONG
 } ply_command_option_type_t;
 
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
-- 
1.6.1.3



More information about the plymouth mailing list