expunge-gconv-modules 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # This script is used to generate a gconv-modules file that takes into
  3. # account only the gconv modules installed by Buildroot. It receives
  4. # on its standard input the original complete gconv-modules file from
  5. # the toolchain, and as arguments the list of gconv modules that were
  6. # actually installed, and writes on its standard output the new
  7. # gconv-modules file.
  8. # The format of gconv-modules is precisely documented in the
  9. # file itself. It consists of two different directives:
  10. # module FROMSET TOSET FILENAME COST
  11. # alias ALIAS REALNAME
  12. # and that's what this script parses and generates.
  13. #
  14. # There are two kinds of 'module' directives:
  15. # - the first defines conversion of a charset to/from INTERNAL representation
  16. # - the second defines conversion of a charset to/from another charset
  17. # we handle each with slightly different code, since the second never has
  18. # associated aliases.
  19. gawk -v files="${1}" '
  20. $1 == "alias" {
  21. aliases[$3] = aliases[$3] " " $2;
  22. }
  23. $1 == "module" && $2 != "INTERNAL" && $3 == "INTERNAL" {
  24. file2internals[$4] = file2internals[$4] " " $2;
  25. mod2cost[$2] = $5;
  26. }
  27. $1 == "module" && $2 != "INTERNAL" && $3 != "INTERNAL" {
  28. file2cset[$4] = file2cset[$4] " " $2 ":" $3;
  29. mod2cost[$2] = $5;
  30. }
  31. END {
  32. nb_files = split(files, all_files);
  33. for(f = 1; f <= nb_files; f++) {
  34. file = all_files[f];
  35. printf("# Modules and aliases for: %s\n", file);
  36. nb_mods = split(file2internals[file], mods);
  37. for(i = 1; i <= nb_mods; i++) {
  38. nb_aliases = split(aliases[mods[i]], mod_aliases);
  39. for(j = 1; j <= nb_aliases; j++) {
  40. printf("alias\t%s\t%s\n", mod_aliases[j], mods[i]);
  41. }
  42. printf("module\t%s\t%s\t%s\t%d\n", mods[i], "INTERNAL", file, mod2cost[mods[i]]);
  43. printf("module\t%s\t%s\t%s\t%d\n", "INTERNAL", mods[i], file, mod2cost[mods[i]]);
  44. printf("\n" );
  45. }
  46. printf("%s", nb_mods != 0 ? "\n" : "");
  47. nb_csets = split(file2cset[file], csets);
  48. for(i = 1; i <= nb_csets; i++) {
  49. split(csets[i], cs, ":");
  50. printf("module\t%s\t%s\t%s\t%d\n", cs[1], cs[2], file, mod2cost[cs[1]]);
  51. }
  52. printf("%s", nb_csets != 0 ? "\n\n" : "");
  53. }
  54. }
  55. '