/*
- * Copyright (C) 2013 Intel Corporation.
+ * Copyright (C) 2013-2014 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "heap.h"
#include "buffer.h"
#include "foreign.h"
+#include "sha256sum.h"
/*======================================================================*/
h Produce the C header with the enumeration of the variables\n\
c Produce the C code to hash the variable names\n\
rpm Produce the macro file to use with RPM\n\
+signup Produce the signup data for the proxy linked statically\n\
\n\
";
static char gperf_head[] = "\
struct varassoc {\n\
int offset;\n\
- enum tzplatform_variable id;\n\
+ int id;\n\
};\n\
%%\n\
";
\n\
";
+static char signup_head[] = "\
+/* I'm generated. Dont edit me! */\n\
+static char tizen_platform_config_signup[33] = {\n\
+ '\\x00',\n\
+";
+
+static char signup_tail[] = "\
+ };\n\
+";
+
/*== GLOBALS VARIABLES =================================================*/
/* name of the meta file to process */
static int dependant = 0;
/* action to perform */
-static enum { CHECK, PRETTY, GENC, GENH, RPM } action = CHECK;
+static enum { CHECK, PRETTY, GENC, GENH, RPM, SIGNUP } action = CHECK;
/* output of error */
static int notstderr = 0;
/*======================================================================*/
+/* compare two keys */
+static int keycmp(const void *a, const void *b)
+{
+ const struct key *ka = *(const struct key **)a;
+ const struct key *kb = *(const struct key **)b;
+ return strcmp(ka->name, kb->name);
+}
+
+/* sort the keys and return their count */
+static int sortkeys()
+{
+ struct key *key = keys, **array;
+ int count = 0, index;
+
+ while (key) {
+ key = key->next;
+ count++;
+ }
+
+ array = malloc( count * sizeof * array);
+ if (array == NULL)
+ return -1;
+
+ key = keys;
+ index = 0;
+
+ while (key) {
+ array[index++] = key;
+ key = key->next;
+ }
+
+ qsort(array, count, sizeof * array, keycmp);
+
+ while (index) {
+ array[--index]->next = key;
+ key = array[index];
+ }
+ keys = key;
+ free( array);
+
+ return count;
+}
+
+/*======================================================================*/
+
/* pretty print the read file */
static int pretty( const char *buffer, size_t length, FILE *output)
{
struct key *key;
int status;
+#ifndef NO_SORT_KEYS
+ status = sortkeys();
+ if (status < 0)
+ return status;
+#endif
+
status = fprintf( output, "%s", genh_head);
if (status < 0)
return status;
int result, sts;
size_t l;
+#ifndef NO_SORT_KEYS
+ sts = sortkeys();
+ if (sts < 0)
+ return sts;
+#endif
+
result = pipe(fds);
if (result != 0)
return result;
struct key *key;
int status;
+#ifndef NO_SORT_KEYS
+ status = sortkeys();
+ if (status < 0)
+ return status;
+#endif
+
status = fprintf( output, "%s", rpm_head);
if (status < 0)
return status;
return 0;
}
+/* generate the signup */
+static int signup( FILE *output)
+{
+ struct key *key;
+ int status;
+ int i;
+ struct sha256sum *sum;
+ char term;
+ char signup[32];
+
+#ifndef NO_SORT_KEYS
+ status = sortkeys();
+ if (status < 0)
+ return status;
+#endif
+
+ sum = sha256sum_create();
+ if (sum == NULL)
+ return -1;
+
+ term = ';';
+ for (key = keys ; key != NULL ; key = key->next) {
+ status = sha256sum_add_data(sum, key->name, strlen(key->name));
+ if (status < 0)
+ return status;
+ status = sha256sum_add_data(sum, &term, 1);
+ if (status < 0)
+ return status;
+ }
+
+ status = sha256sum_get(sum, signup);
+ if (status < 0)
+ return status;
+
+ status = fprintf( output, "%s", signup_head);
+ if (status < 0)
+ return status;
+
+ for (i=0 ; i<32 ; i++) {
+ status = fprintf( output, "%s'\\x%02x'%s",
+ (i & 7) ? " " : " ",
+ (int)(unsigned char)signup[i],
+ (i & 7) < 7 ? "," : i == 31 ? "\n" : ",\n");
+ if (status < 0)
+ return status;
+ }
+ status = fprintf( output, "%s", signup_tail);
+ if (status < 0)
+ return status;
+ return 0;
+}
+
/* main of processing */
static int process()
{
case RPM:
rpm( stdout);
break;
+ case SIGNUP:
+ signup( stdout);
+ break;
}
buffer_destroy( &buffer);
action = RPM;
argv++;
}
- else if (0 == strcmp( *argv, "help")) {
+ else if (0 == strcmp( *argv, "signup")) {
+ action = SIGNUP;
+ argv++;
+ }
+ else if (0 == strcmp( *argv, "help") || 0 == strcmp( *argv, "--help")) {
printf("%s", help);
exit(0);
return -1;