]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Sort help by command
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 25 Jul 2013 09:28:15 +0000 (11:28 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 25 Jul 2013 09:28:15 +0000 (11:28 +0200)
rpp/lib/cmdproc/src/commands/doc/Makefile
rpp/lib/cmdproc/src/commands/doc/docgen.c

index 9c8815f67eb95c30c97e094f6823544803181ce4..b1a40a0c464586a1d44228516f89cd437edd30cb 100644 (file)
@@ -1,7 +1,7 @@
 COMMANDS=$(wildcard ../*.c)
 OBJS=$(COMMANDS:../%.c=%.o)
 
-CFLAGS=-Wall -I../../../include -I../../../../rpp/include -DDOCGEN -DNULL=0 -D'CMD_HANDLER(x)=0'
+CFLAGS=-Wall -std=c99 -I../../../include -I../../../../rpp/include -DDOCGEN -DNULL=0 -D'CMD_HANDLER(x)=0'
 
 all: print-doc
 
index 0696c10bf1de5324e44fb38835d8ab3b0201b501..2383f16b49cf35084149072606a6a6ab7628af4b 100644 (file)
@@ -2,6 +2,7 @@
 #include <cmdproc.h>
 #include <string.h>
 #include "commands/cmd.h"
+#include <stdlib.h>
 
 #define CMD_ARR_STACK_SIZE 4
 
@@ -30,6 +31,12 @@ void print_wiki(const cmd_des_t *des)
        printf("%s", des->long_help);
 }
 
+static int cmp_des(const void *p1, const void *p2)
+{
+       const cmd_des_t **c1 = p1, **c2 = p2;
+       return strcmp((*c1)->name, (*c2)->name);
+
+}
 
 int main(int argc, char *argv[])
 {
@@ -38,6 +45,9 @@ int main(int argc, char *argv[])
        cmd_des_t const **arr_stack[CMD_ARR_STACK_SIZE];
        int arr_stack_sp=0;
        enum disp_mode mode = SHORT_HELP;
+       #define LEN 1000
+       const cmd_des_t *sorted_des[LEN];
+       int num = 0;
 
        if (argc > 1) {
                if (strcmp(argv[1], "full") == 0)
@@ -74,6 +84,14 @@ int main(int argc, char *argv[])
                        }
                }
 
+               sorted_des[num++] = des;
+       }
+
+       qsort(sorted_des, num, sizeof(*sorted_des), cmp_des);
+
+       for (int i = 0; i < num; i++) {
+               des = sorted_des[i];
+
                switch (mode) {
                case SHORT_HELP:
                        print_one_line(des);