On Mon, Apr 21, 2025 at 02:56:05AM -0700, Kurt Pagani wrote:
> I wanted to create a sqlite database combining libdb.text and comdb.text. 
> Naively, I converted the files to csv assuming the pointers in the both 
> files would match -- without checking before :(

The attached FrICAS file joins back libdb and comdb.  Usage like:

)read joindb.input
p1 := "../fr-build110/target/x86_64-linux-gnu/algebra/libdb.text"
p2 := "../fr-build110/target/x86_64-linux-gnu/algebra/comdb.text"
joindb(p1, p2, "sum.out")

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/aAgJTsO7l8aUNqRV%40fricas.org.
char_tick := elt("`", 1)
find_ptr_pos(s) ==
    res : Integer := 0
    for i in 1..6 repeat
        res := position(char_tick, s, res + 1)
    res

joindb1(lf : TextFile, cf : TextFile, of : TextFile) : Void ==
    -- discard fake entry
    c := readLine!(cf)
    -- read lookahead line
    cu := readLineIfCan!(cf)
    repeat
        ilu := readLineIfCan!(lf)
        ilu case "failed" => break
        il := ilu::String
        ptr_pos := find_ptr_pos(il)
        il1 := il(1..ptr_pos)
        il2 := il((ptr_pos + 1)..#il)
        il2 = "0" =>
            writeLine!(of, il1)
        write!(of, il1)
        cu case "failed" =>
            error "Missing comment"
        c := cu::String
        ptr_pos := position(char_tick, c)
        c1 := c(1..ptr_pos)
        c2 := c((ptr_pos + 1)..#c)
        write!(of, c2)
        repeat
            cu := readLineIfCan!(cf)
            cu case "failed" => break
            c := cu::String
            c1 = c(1..ptr_pos) =>
                c2 := c((ptr_pos + 1)..#c)
                write!(of, c2)
            break
        writeLine!(of)
        
joindb(lfn : String, cfn : String, ofn : String) : Void ==
    lf := open(lfn)$TextFile
    cf := open(cfn)$TextFile
    of := open(ofn, "output")$TextFile
    joindb1(lf, cf, of)
    close!(lf)$TextFile
    close!(cf)$TextFile
    close!(of)$TextFile

Reply via email to