int main (int argc, char **argv) { gchar *translation_dict_fn = NULL; GOptionContext *ctx; GOptionEntry options[] = { {"translation-dictionary", 0, 0, G_OPTION_ARG_FILENAME, &translation_dict_fn, "Filename of translations dictionary to write", NULL}, {NULL} }; StringTable *string_table; GError *err = NULL; GList *l; int idx = 0; ctx = g_option_context_new (""); g_option_context_add_main_entries (ctx, options, NULL); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_printerr ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); read_licenses (LIBLICENSE_DATA_PREFIX); g_printerr ("%d licenses\n", g_list_length (licenses)); unknown_sources = g_hash_table_new (g_str_hash, g_str_equal); for (l = licenses; l != NULL; l = l->next) { License *license = l->data; /* if the license has as source, check if we can 'pack' it into the * original license as a jurisdiction-specific variant */ if (license->source != NULL) { License *source = find_license (license->source); if (source != NULL) { if (source->flags != license->flags) { g_printerr ("Source and derived license have different flags:\n" "\t0x%08x : %s\n\t0x%08x : %s\n", source->flags, source->ref, license->flags, license->ref); source = NULL; } else { if (source->descriptions == NULL) { /* neither should the derived one then */ g_assert (license->descriptions == NULL); } else { /* make sure we're not settling for fewer descriptions than * there are */ g_assert (g_hash_table_size (license->titles) <= g_hash_table_size (source->titles)); g_assert (g_hash_table_size (license->descriptions) <= g_hash_table_size (source->descriptions)); } } } else { /* a source is referenced that we haven't encountered * (possibly a referencing bug? seems to happen e.g. when there's a * 2.1 version of a jurisdiction license and it refers to a 2.1 * source version, but there's only a 2.0 or 2.5 source version. So * maybe it's supposed to refer to the 2.0 source then, who knows) */ if (!g_hash_table_lookup (unknown_sources, license->source)) { g_printerr ("Unknown source license %s\n", license->source); g_hash_table_insert (unknown_sources, g_strdup (license->source), GUINT_TO_POINTER (TRUE)); } /* g_print ("Unknown source license %s referenced from %s\n", * license->source, license->ref); */ } /* should we pack this into the source or not */ if (source != NULL) { source->jurisdiction |= license->jurisdiction; source->derived = g_list_insert_sorted (source->derived, license, (GCompareFunc) license_ref_cmp); license->packed_into_source = TRUE; } } else { /* no source license */ if (license->titles == NULL) g_error ("License has no titles: %s\n", license->ref); if (license->descriptions == NULL); g_printerr ("License %s has no descriptions!\n", license->ref); } } licenses = g_list_sort (licenses, (GCompareFunc) license_ref_cmp); string_table = string_table_new (); g_print ("/* created by mklicensestables.c */\n"); g_print ("static const struct {\n" " /* jurisdictions in addition to the generic version, bitfield */\n" " const guint64 jurisdictions;\n" " const GstTagLicenseFlags flags;\n" " /* the bit after http://creativecommons.org/licenses/ */\n" " const gchar ref[18];\n" " gint16 title_idx; /* index in string table */\n" " gint16 desc_idx; /* index in string table */\n" "} licenses[] = {\n"); for (l = licenses; l != NULL; l = l->next) { const gchar *title_en, *desc_en; int idx_title, idx_desc; License *license; license = l->data; if (license->packed_into_source) continue; title_en = g_hash_table_lookup (license->titles, "en"); g_assert (title_en != NULL); idx_title = string_table_add_string (string_table, title_en); g_assert (idx_title <= G_MAXINT16); if (license->descriptions != NULL) { desc_en = g_hash_table_lookup (license->descriptions, "en"); g_assert (desc_en != NULL); idx_desc = string_table_add_string (string_table, desc_en); g_assert (idx_desc <= G_MAXINT16); } else { idx_desc = -1; } /* output comments with license refs covered by the next stanza */ if (license->derived != NULL) { GList *d; g_print (" /* %2d %s\n", idx, license->ref); for (d = license->derived; d != NULL; d = d->next) { License *derived_license = d->data; g_print (" * %2d %s%s\n", idx, derived_license->ref, (d->next == NULL) ? " */" : ""); } } else { g_print (" /* %2d %s */\n", idx, license->ref); } /* output essential data */ { gchar *ref; ref = g_strdup (license->ref + strlen ("http://creativecommons.org/licenses/")); /* remove jurisdiction suffix from ref if this is non-generic, since * the suffix is already contained in the jurisdiction flags */ if (license->jurisdiction_suffix != NULL) { gsize suffix_len = strlen (license->jurisdiction_suffix); gchar *cutoff; cutoff = ref + strlen (ref) - suffix_len; g_assert (!strncmp (cutoff, license->jurisdiction_suffix, suffix_len)); g_assert (cutoff[suffix_len - 1] == '/'); g_assert (cutoff[suffix_len] == '\0'); *cutoff = '\0'; } g_print (" { 0x%016" G_GINT64_MODIFIER "x, 0x%08x, \"%s\", %d, %d }%s\n", license->jurisdiction, license->flags, ref, idx_title, idx_desc, (l->next != NULL) ? "," : ""); g_free (ref); } ++idx; } g_print ("};\n"); g_print ("\nstatic const gchar license_strings[] =\n"); string_table_print (string_table); string_table_free (string_table); string_table = NULL; if (translation_dict_fn != NULL) { write_translations_dictionary (licenses, translation_dict_fn); } return 0; }
static void xml_string_table_create(void) { if (xml_string_table == NULL) xml_string_table = string_table_new(); }