ps,top: add an option to show threads. +260 bytes of code
[oweals/busybox.git] / applets / applet_tables.c
index 3945f7c5152b920ae86b7995502e165e99f38757..17135ddc1f43beaef7f8e6a02991f905ea724a92 100644 (file)
@@ -32,7 +32,7 @@ struct bb_applet {
 /* Define struct bb_applet applets[] */
 #include "../include/applets.h"
 
-enum { NUM_APPLETS = sizeof(applets)/sizeof(applets[0]) };
+enum { NUM_APPLETS = ARRAY_SIZE(applets) };
 
 static int offset[NUM_APPLETS];
 
@@ -47,6 +47,7 @@ int main(int argc, char **argv)
 {
        int i;
        int ofs;
+       unsigned MAX_APPLET_NAME_LEN = 1;
 
        qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
 
@@ -69,15 +70,23 @@ int main(int argc, char **argv)
 
        /* Keep in sync with include/busybox.h! */
 
-       puts("/* This is a generated file, don't edit */");
+       puts("/* This is a generated file, don't edit */\n");
 
-       puts("const char applet_names[] ALIGN1 = \"\" \n");
+       printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
+       if (NUM_APPLETS == 1) {
+               printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
+               printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
+       }
+
+       puts("\nconst char applet_names[] ALIGN1 = \"\"");
        for (i = 0; i < NUM_APPLETS; i++) {
                printf("\"%s\" \"\\0\"\n", applets[i].name);
+               if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
+                       MAX_APPLET_NAME_LEN = strlen(applets[i].name);
        }
        puts(";");
 
-       puts("int (*const applet_main[])(int argc, char **argv) = {");
+       puts("\nint (*const applet_main[])(int argc, char **argv) = {");
        for (i = 0; i < NUM_APPLETS; i++) {
                printf("%s_main,\n", applets[i].main);
        }
@@ -92,7 +101,7 @@ int main(int argc, char **argv)
                        + (applets[i].noexec << 13)
 #endif
 #if ENABLE_FEATURE_SUID
-                       + (applets[i].need_suid   << 14) /* 2 bits */
+                       + (applets[i].need_suid << 14) /* 2 bits */
 #endif
                );
        }
@@ -108,8 +117,10 @@ int main(int argc, char **argv)
                printf("0x%02x,\n", v);
                i++;
        }
-       puts("};");
+       puts("};\n");
 #endif
 
+       printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
+
        return 0;
 }