Post Reply 
(Free42) txt2raw - raw2txt
05-23-2022, 03:15 PM
Post: #3
RE: (Free42) txt2raw - raw2txt
This 3rd program may look a bit silly first, but it can be used to pretty print your program.

txt2txt.cc
Code:
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>

#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);
    prgm = core_copy();

    std::ofstream txt;
    txt.open(argv[1]);
    txt << prgm;
    txt.close();

    return 0;
}

Don't forget to add this to the Makefile:
Code:
ifeq ($(EXE), txt2txt)
OBJS += txt2txt.o
endif

And then as before compile it with:

make EXE=txt2txt

Example

Let's start with your original file:

tmsht.txt
Code:
00 { 52-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY START"
04 RCL "DAY END"
05 RCL "DAY START"
06 HMS-
07 →HR
08 Σ+
09 END

Now run:

./txt2txt tmsht.txt

We end up with:
Code:
00 { 48-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY STA"
04 RCL "DAY END"
05 RCL "DAY STA"
06 HMS-
07 →HR
08 Σ+
09 END

We notice that "DAY START" has been shortened to 7 characters: "DAY STA".

Warning: Make a backup of the file (e.g. add it to Git) before running this program.
Text that can not be parsed correctly will be removed.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(Free42) txt2raw - raw2txt - Thomas Klemm - 05-22-2022, 12:27 PM
RE: (Free42) txt2raw - raw2txt - syzygetic - 05-23-2022, 01:34 PM
RE: (Free42) txt2raw - raw2txt - Thomas Klemm - 05-23-2022 03:15 PM



User(s) browsing this thread: 1 Guest(s)