This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
/
go-harbour.go
141 lines (103 loc) · 2.93 KB
/
go-harbour.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
/*
#cgo CFLAGS: -I/usr/local/include/harbour -I/usr/include/postgresql
#cgo LDFLAGS: -L/usr/local/lib/harbour -lpq -lhbmzip -lz -lminizip -lhbct -lhbtip -lhbpgsql -lhbdebug -lharbour
#include <hbvmint.h>
#include <hbapi.h>
#include <hbstack.h>
#include <hbapiitm.h>
#include <hbapierr.h>
#include <hbapifs.h>
#include <hbvm.h>
#include <hbpcode.h>
#include <hbset.h>
#include <hb_io.h>
#include <hbhrb.ch>
#include "go.h"
#include <stdio.h>
extern void HB_FUNC_GO_FUN();
*/
import "C"
import(
"fmt"
"archive/zip"
"log"
"os"
"io"
// "unsafe"
)
//export HbGo
func HbGo(i int, cstr *C.char) {
fmt.Printf("i: %d str: %s\n", i, C.GoString(cstr))
fmt.Println("Harbor function written in go - pokrenuta iz HB_FUNC_GO_FUN (go.c)")
}
func main() {
C.hb_vmSetDefaultGT(C.CString("xwc"));
//C.hb_vmSetDefaultGT(C.CString("trm"));
C.hb_vmInit( C.HB_BOOL(0) )
/*
LoadDo("hrbext.hrb")
pDynSym := C.hb_dynsymGet(C.CString("B"))
pItem := C.hb_dynsymGetMemvar(pDynSym)
fmt.Println("go string -> harbour memvar")
C.hb_itemPutC(pItem, C.CString("GOGOGOGOGOOOOOOOOO"))
fmt.Printf("Uzimam iz harbour memvar B(1): %s\n", C.GoString(C.hb_itemGetC(pItem)))
LoadDo("hrbext2.hrb")
fmt.Println("harbour memvar B (nakon inputa) -> go string")
pItem = C.hb_dynsymGetMemvar(pDynSym)
fmt.Printf("Uzimam iz harbour memvar B(2): %s\n", C.GoString(C.hb_itemGetC(pItem)))
*/
//fmt.Println("test pgtest")
//LoadDo("hbgo.hrb")
fmt.Println("ucitavam tpostgre harbour klasu")
LoadDoHrb("tpostgre.hrb")
//LoadDoHrb("pg_object_test.hrb")
// LoadZip("common")
// LoadHrb("common/" + "f18_ini_utils.hrb")
// LoadHrb("common/" + "f18_init_login.hrb")
// LoadHrb("common/" + "f18_init_semaphores.hrb")
LoadDoHrb("common.hrb")
LoadDoHrb("fin.hrb")
LoadDoHrb("kalk.hrb")
LoadDoHrb("fakt.hrb")
LoadDoHrb("pos.hrb")
LoadDoHrb("run_main.hrb")
//LoadZip("fin")
//C.hb_conOutStd( C.CString("Ernad Husremovic\n"), C.HB_SIZE(20) )
fmt.Println("kraj")
}
func LoadZip(file string) {
r, err := zip.OpenReader(file + ".zip")
if err != nil {
log.Fatal(err)
}
defer r.Close()
// Iterate through the files in the archive,
// printing some of their contents.
for _, f := range r.File {
fmt.Printf("Contents of %s:\n", f.Name)
rc, err := f.Open()
if err != nil {
log.Fatal(err)
}
d, errd := os.Create(file + "/" + f.Name)
if errd != nil {
log.Fatal(errd)
}
if _, errc := io.Copy(d, rc); errc != nil {
d.Close()
log.Fatal(errc)
}
rc.Close()
fmt.Println()
}
}
func LoadDoHrb(file string) {
fmt.Println("load and do hrb ", file)
pBody := C.hb_hrbLoadFromFile( C.CString(file), C.HB_USHORT(1))
C.hb_hrbDo( pBody, 0, nil );
}
func LoadHbPostgresqlC() {
var conn *C.PGconn
C.PQreset(conn)
}