Просмотр исходного кода

Merge pull request #4 from mysterywolf/master

更新到官方最新
流光 4 лет назад
Родитель
Сommit
2892db0482
2 измененных файлов с 26 добавлено и 26 удалено
  1. 25 25
      example/optparse_demo.c
  2. 1 1
      optparse.c

+ 25 - 25
example/optparse_demo.c

@@ -3,52 +3,52 @@
 
 int optparse_short_test(int argc, char **argv)
 {
-    int ch; 
+    int ch;
     struct optparse options;
-    
-    optparse_init(&options, argv); 
+
+    optparse_init(&options, argv);
     while((ch = optparse(&options, "ab:c::")) != -1)
     {
-        ch = ch; 
-        
-        rt_kprintf("\n"); 
+        ch = ch;
+
+        rt_kprintf("\n");
         rt_kprintf("optopt = %c\n", options.optopt);
         rt_kprintf("optarg = %s\n", options.optarg);
         rt_kprintf("optind = %d\n", options.optind);
     }
     rt_kprintf("\n");
-    
-    return RT_EOK; 
+
+    return RT_EOK;
 }
-MSH_CMD_EXPORT_ALIAS(optparse_short_test, ost, test optparse_short cmd.); 
+MSH_CMD_EXPORT_ALIAS(optparse_short_test, ost, test optparse_short cmd.);
 
-static struct optparse_long long_opts[] = 
+static struct optparse_long long_opts[] =
 {
-    {"aaa", 'a', OPTPARSE_NONE    }, 
-    {"bbb", 'b', OPTPARSE_REQUIRED}, 
-    {"ccc", 'c', OPTPARSE_OPTIONAL}, 
+    {"aaa", 'a', OPTPARSE_NONE    },
+    {"bbb", 'b', OPTPARSE_REQUIRED},
+    {"ccc", 'c', OPTPARSE_OPTIONAL},
     { NULL,  0,  OPTPARSE_NONE    }
-}; 
+};
 
 int optparse_long_test(int argc, char **argv)
 {
-    int ch; 
-    int option_index; 
+    int ch;
+    int option_index;
     struct optparse options;
-    
-    optparse_init(&options, argv); 
+
+    optparse_init(&options, argv);
     while((ch = optparse_long(&options, long_opts, &option_index)) != -1)
     {
-        ch = ch; 
-        
-        rt_kprintf("\n"); 
+        ch = ch;
+
+        rt_kprintf("\n");
         rt_kprintf("optopt = %c\n", options.optopt);
         rt_kprintf("optarg = %s\n", options.optarg);
         rt_kprintf("optind = %d\n", options.optind);
-        rt_kprintf("option_index = %d\n", option_index); 
+        rt_kprintf("option_index = %d\n", option_index);
     }
     rt_kprintf("\n");
-    
-    return RT_EOK; 
+
+    return RT_EOK;
 }
-MSH_CMD_EXPORT_ALIAS(optparse_long_test, olt, test optparse_long cmd.); 
+MSH_CMD_EXPORT_ALIAS(optparse_long_test, olt, test optparse_long cmd.);

+ 1 - 1
optparse.c

@@ -80,7 +80,7 @@ static void optparse_from_long(const struct optparse_long *longopts, char *optst
     int i;
     for (i = 0; !optparse_longopts_end(longopts, i); i++)
     {
-        if (longopts[i].shortname)
+        if (longopts[i].shortname && longopts[i].shortname < 127)
         {
             int a;
             *p++ = longopts[i].shortname;