logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

keyword.c (1093B)


  1. /*
  2. * SPDX-FileCopyrightText: 2022 fosslinux <fosslinux@aussies.space>
  3. *
  4. * SPDX-License-Identifier: Python-2.0.1
  5. *
  6. * Reimplmentation of keyword.py main() in C, to break bootstrapping loop
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #define MAX_LINE 128
  12. int main() {
  13. char filename[] = "Lib/keyword.py";
  14. FILE *orig = fopen(filename, "r");
  15. /* Read-write until starter line */
  16. char *line = malloc(MAX_LINE);
  17. do {
  18. fgets(line, MAX_LINE, orig);
  19. puts(line);
  20. } while (strcmp(line, "#--start keywords--\n") != 0);
  21. /* Perform the actual transformation */
  22. while (fgets(line, MAX_LINE, stdin) != NULL) {
  23. char *token = line;
  24. while (*token != '"') token++;
  25. token++;
  26. /* Now at beginning of keyword */
  27. char *end = token;
  28. while (*end != '"') end++;
  29. *end = '\0';
  30. /* Write output line to stdout */
  31. printf("'%s',\n", token);
  32. /* For each line also advance orig pointer */
  33. fgets(line, MAX_LINE, orig);
  34. /* Cleanup */
  35. free(line);
  36. line = malloc(MAX_LINE);
  37. }
  38. /* Read-write until end */
  39. while (fgets(line, MAX_LINE, orig) != NULL) {
  40. puts(line);
  41. }
  42. }