ntpd: set offset to 0.0 in "usync" event
[oweals/busybox.git] / applets / applet_tables.c
index e48be46821e7ffe3a07cd33dcc4ca50a44371652..152d5f4418be27ccf316628e7a209bebe225a144 100644 (file)
@@ -5,15 +5,21 @@
  *
  * Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
  *
- * Licensed under GPLv2, see file License in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <unistd.h>
+
+#undef ARRAY_SIZE
+#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
 
 #include "../include/autoconf.h"
-#include "../include/busybox.h"
+#include "../include/applet_metadata.h"
 
 struct bb_applet {
        const char *name;
@@ -75,11 +81,11 @@ int main(int argc, char **argv)
        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);
+               printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
        }
        printf("\n");
 
-       printf("#ifndef SKIP_definitions\n");
+       //printf("#ifndef SKIP_definitions\n");
        printf("const char applet_names[] ALIGN1 = \"\"\n");
        for (i = 0; i < NUM_APPLETS; i++) {
                printf("\"%s\" \"\\0\"\n", applets[i].name);
@@ -123,9 +129,29 @@ int main(int argc, char **argv)
        }
        printf("};\n");
 #endif
-       printf("#endif /* SKIP_definitions */\n");
+       //printf("#endif /* SKIP_definitions */\n");
        printf("\n");
        printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
 
+       if (argv[2]) {
+               char line_old[80];
+               char line_new[80];
+               FILE *fp;
+
+               line_old[0] = 0;
+               fp = fopen(argv[2], "r");
+               if (fp) {
+                       fgets(line_old, sizeof(line_old), fp);
+                       fclose(fp);
+               }
+               sprintf(line_new, "#define NUM_APPLETS %u\n", NUM_APPLETS);
+               if (strcmp(line_old, line_new) != 0) {
+                       fp = fopen(argv[2], "w");
+                       if (!fp)
+                               return 1;
+                       fputs(line_new, fp);
+               }
+       }
+
        return 0;
 }