05-22-2022, 12:27 PM
There was a recent wish for a command line utility to translate between txt and raw files of Free42 programs.
So I cloned https://github.com/thomasokken/free42.git and wrote two simple programs:
txt2raw.cc
This program uses core_paste to read the program from a txt-file and core_export_programs to write it to a raw-file.
raw2txt.cc
This program uses core_import_programs to read the program from a raw-file and core_copy to write it to a txt-file.
To compile them put them into the gtk directory.
You need a small patch of the Makefile:
And then you have to comment out or remove the main function of gtk/shell_main.cc:
Now you can compile the binaries with:
make EXE=txt2raw
or
make EXE=raw2txt
Example Usage
./txt2raw tmsht.txt tmsht.raw
./raw2txt tmsht.raw tmsht.txt
You will notice annoying error messages related to Gtk and GdkPixbuf which can be ignored.
To do this, simply redirect STDERR to /dev/null by appending: 2> /dev/null
This works on a MacBook and I would guess on Linux too.
But I have no idea about the other platforms.
It is a bit of hack, but I couldn't figure out an easy way to disentangle the core from the shell.
Therefore, the GUI libraries have to be linked, which leads to the error messages.
Possibly an initialisation of the GUI is missing.
But since the programs were running, I didn't bother to find out.
Nevertheless, I hope that these programs will be useful for others as well.
So I cloned https://github.com/thomasokken/free42.git and wrote two simple programs:
txt2raw.cc
This program uses core_paste to read the program from a txt-file and core_export_programs to write it to a raw-file.
Code:
#include <sstream>
#include <fstream>
#include "core_main.h"
#include "core_globals.h"
int main(int argc, char *argv[]) {
std::ostringstream sstream;
std::ifstream fs(argv[1]);
sstream << fs.rdbuf();
const std::string str(sstream.str());
const char* prgm = str.c_str();
core_init(0, 0, NULL, 0);
flags.f.prgm_mode = true;
core_paste(prgm);
const int indexes[] = { 0 };
core_export_programs(1, indexes, argv[2]);
return 0;
}
raw2txt.cc
This program uses core_import_programs to read the program from a raw-file and core_copy to write it to a txt-file.
Code:
#include <string.h>
#include <iostream>
#include <fstream>
#include "core_main.h"
#include "core_globals.h"
int main(int argc, char *argv[]) {
core_init(0, 0, NULL, 0);
core_import_programs(0, argv[1]);
flags.f.prgm_mode = true;
const char *prgm = core_copy();
std::ofstream txt;
txt.open(argv[2]);
txt << prgm;
txt.close();
return 0;
}
To compile them put them into the gtk directory.
You need a small patch of the Makefile:
Code:
ifeq ($(EXE), txt2raw)
OBJS += txt2raw.o
endif
ifeq ($(EXE), raw2txt)
OBJS += raw2txt.o
endif
And then you have to comment out or remove the main function of gtk/shell_main.cc:
Code:
// int main(int argc, char *argv[]) {
// for (int i = 1; i < argc; i++) {
// if (strcmp(argv[i], "-skin") == 0)
// skin_arg = ++i < argc ? argv[i] : NULL;
// else if (strcmp(argv[i], "-compactmenu") == 0)
// use_compactmenu = 1;
// else {
// fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
// exit(1);
// }
// }
// GtkApplication *app;
// int status;
// app = gtk_application_new("com.thomasokken.free42", G_APPLICATION_FLAGS_NONE);
// g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
// status = g_application_run(G_APPLICATION(app), 0, NULL);
// g_object_unref(app);
// return status;
// }
Now you can compile the binaries with:
make EXE=txt2raw
or
make EXE=raw2txt
Example Usage
./txt2raw tmsht.txt tmsht.raw
./raw2txt tmsht.raw tmsht.txt
You will notice annoying error messages related to Gtk and GdkPixbuf which can be ignored.
To do this, simply redirect STDERR to /dev/null by appending: 2> /dev/null
This works on a MacBook and I would guess on Linux too.
But I have no idea about the other platforms.
It is a bit of hack, but I couldn't figure out an easy way to disentangle the core from the shell.
Therefore, the GUI libraries have to be linked, which leads to the error messages.
Possibly an initialisation of the GUI is missing.
But since the programs were running, I didn't bother to find out.
Nevertheless, I hope that these programs will be useful for others as well.