TextConverter.Mod 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. MODULE TextConverter; (** AUTHOR "negelef"; PURPOSE "automated text format convertion"; *)
  2. IMPORT Commands, Streams, Diagnostics, Files, Texts, TextUtilities;
  3. TYPE Converter = PROCEDURE (text : Texts.Text; CONST filename : ARRAY OF CHAR; VAR res : WORD);
  4. PROCEDURE Convert (diagnostics: Diagnostics.Diagnostics; list: Streams.Reader; converter: Converter);
  5. VAR text: Texts.Text; filename: Files.FileName; format, res: LONGINT;
  6. BEGIN
  7. WHILE list.GetString (filename) DO
  8. NEW (text);
  9. TextUtilities.LoadAuto (text, filename, format, res);
  10. IF res = 0 THEN
  11. converter (text, filename, res);
  12. IF res = 0 THEN
  13. diagnostics.Information (filename, Diagnostics.Invalid, "successfully converted");
  14. ELSE
  15. diagnostics.Information (filename, Diagnostics.Invalid, "failed to store");
  16. END
  17. ELSE
  18. diagnostics.Error (filename, Diagnostics.Invalid, "failed to load");
  19. END;
  20. END;
  21. END Convert;
  22. (* converts the provided list of text files into the oberon format *)
  23. PROCEDURE Oberon* (context: Commands.Context);
  24. VAR diagnostics: Diagnostics.StreamDiagnostics;
  25. BEGIN
  26. NEW (diagnostics, context.error);
  27. Convert (diagnostics, context.arg, TextUtilities.StoreOberonText);
  28. END Oberon;
  29. PROCEDURE UTF8*(context : Commands.Context);
  30. VAR diagnostics: Diagnostics.StreamDiagnostics;
  31. BEGIN
  32. NEW (diagnostics, context.error);
  33. Convert (diagnostics, context.arg, TextUtilities.ExportUTF8);
  34. END UTF8;
  35. END TextConverter.