The repository formerly known as dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

aes.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 2019 C. McEnroe <june@causal.agency>
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Affero General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <locale.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <wchar.h>
  20. typedef unsigned char byte;
  21. static const wchar_t Table[128] = {
  22. L"\x00\x01\x02\x03\x04\x05\x06\x07"
  23. L"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
  24. L"\x10\x11\x12\x13\x14\x15\x16\x17"
  25. L"\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
  26. L" !"#$%&'()*+,-./"
  27. L"0123456789:;<=>?"
  28. L"@ABCDEFGHIJKLMNO"
  29. L"PQRSTUVWXYZ[\]^_"
  30. L"`abcdefghijklmno"
  31. L"pqrstuvwxyz{|}~\x7F"
  32. };
  33. static void enwiden(const char *ch) {
  34. for (; *ch; ++ch) {
  35. if ((byte)*ch < 128) printf("%lc", (wint_t)Table[(byte)*ch]);
  36. else printf("%c", *ch);
  37. }
  38. }
  39. int main(int argc, char *argv[]) {
  40. setlocale(LC_CTYPE, "");
  41. for (int i = 1; i < argc; ++i) {
  42. enwiden(argv[i]);
  43. if (i < argc - 1) printf("%lc", (wint_t)Table[' ']);
  44. else printf("\n");
  45. }
  46. if (argc > 1) return EXIT_SUCCESS;
  47. char *line = NULL;
  48. size_t cap = 0;
  49. while (0 < getline(&line, &cap, stdin)) {
  50. enwiden(line);
  51. }
  52. }