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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//  https://code.kx.com/q/interfaces/c-client-for-q/

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::os::raw;

pub type H = raw::c_short;
pub type I = raw::c_int;
pub type J = raw::c_longlong;
pub type S = *mut raw::c_char;
pub type Sconst = *const raw::c_char;
pub type G = raw::c_uchar;
pub type C = raw::c_char;
pub type E = raw::c_float;
pub type F = raw::c_double;
pub type V = raw::c_void;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct k0 {
    pub m: raw::c_schar, // m,a are for internal use.
    pub a: raw::c_schar,
    pub t: raw::c_schar, // The object's type
    pub u: C,            // The object's attribute flags
    pub r: I,            // The object's reference count
    _value: ValueUnion,
}

pub type K = *mut k0;

#[repr(C)]
#[derive(Copy, Clone)]
pub(crate) union ValueUnion {
    // The atoms are held in the following members:
    pub g: G,
    pub h: H,
    pub i: I,
    pub j: J,
    pub e: E,
    pub f: F,
    pub s: S,
    // The following members are used for more complex data.
    pub k: *mut k0,
    _collection: Collection,
    // align as 128 bits
    _union_align: [u64; 2usize],
}

#[repr(C)]
#[derive(Copy, Clone)]
pub(crate) struct Collection {
    pub n: J,            // number of elements in vector
    pub G0: [G; 1usize], // byte kG / char kC / pointer to underlying vectors
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct U {
    pub g: [G; 16usize],
}

// https://code.kx.com/v2/interfaces/capiref/
extern "C" {
    /// serialize
    pub fn b9(arg1: I, arg2: K) -> K;

    /// deserialize
    pub fn d9(arg1: K) -> K;

    /// date to number
    ///
    /// Converts a q date to a yyyymmdd integer.
    ///
    /// ```rust
    /// let date = unsafe{ q_capi::dj(0) };
    /// assert_eq!(date, 20000101 as q_capi::I);
    /// ```
    pub fn dj(arg1: I) -> I;

    /// dynamic link
    #[cfg(not(feature = "ipc"))]
    pub fn dl(arg1: *mut V, arg2: I) -> K;

    /// apply
    #[cfg(not(feature = "ipc"))]
    pub fn dot(arg1: K, arg2: K) -> K;

    /// error string
    pub fn ee(arg1: K) -> K;

    /// join value
    pub fn ja(arg1: *mut K, arg2: *mut V) -> K;

    /// join K object
    pub fn jk(arg1: *mut K, arg2: K) -> K;

    /// join string
    pub fn js(arg1: *mut K, arg2: S) -> K;

    /// join K lists
    pub fn jv(k: *mut K, arg2: K) -> K;

    /// evaluate
    pub fn k(arg1: I, arg2: Sconst, ...) -> K;

    /// create atom
    pub fn ka(arg1: I) -> K;

    /// create boolean
    pub fn kb(arg1: I) -> K;

    /// create char
    pub fn kc(arg1: I) -> K;

    /// disconnect
    #[cfg(not(feature = "embed"))]
    pub fn kclose(arg1: I) -> V;

    /// create date
    pub fn kd(arg1: I) -> K;

    /// create real
    pub fn ke(arg1: F) -> K;

    /// create float
    pub fn kf(arg1: F) -> K;

    /// create byte
    pub fn kg(arg1: I) -> K;

    /// create short
    pub fn kh(arg1: I) -> K;

    /// connect anonymously
    #[cfg(not(feature = "embed"))]
    pub fn khp(arg1: Sconst, arg2: I) -> I;

    /// connect, no timeout
    #[cfg(not(feature = "embed"))]
    pub fn khpu(arg1: Sconst, arg2: I, arg3: Sconst) -> I;

    /// connect
    #[cfg(not(feature = "embed"))]
    pub fn khpun(arg1: Sconst, arg2: I, arg3: Sconst, arg4: I) -> I;

    /// connect with capability
    #[cfg(not(feature = "embed"))]
    pub fn khpunc(arg1: Sconst, arg2: I, arg3: Sconst, arg4: I, arg5: I) -> I;

    /// creat int
    pub fn ki(arg1: I) -> K;

    /// create  long
    pub fn kj(arg1: J) -> K;

    /// create list
    pub fn knk(arg1: I, ...) -> K;

    /// create keyed table
    pub fn knt(arg1: J, arg2: K) -> K;

    /// create string
    pub fn kp(arg1: S) -> K;

    /// create fixed-length string
    pub fn kpn(arg1: S, arg2: J) -> K;

    /// signal C error
    pub fn krr(arg1: Sconst) -> K;

    /// create symbol
    pub fn ks(arg1: S) -> K;

    /// create time
    pub fn kt(arg1: I) -> K;

    /// create simple table
    pub fn ktd(arg1: K) -> K;

    /// create timestamp / create timespan
    pub fn ktj(arg1: I, arg2: J) -> K;

    /// create vector
    pub fn ktn(arg1: I, arg2: J) -> K;

    /// create guid
    pub fn ku(arg1: U) -> K;

    /// create datetime
    pub fn kz(arg1: F) -> K;

    /// release memory
    pub fn m9(arg1: V) -> V;

    /// verify IPC message
    pub fn okx(arg1: K) -> I;

    /// signal system error
    pub fn orr(arg1: Sconst) -> K;

    /// decrement refcount
    pub fn r0(arg1: K) -> V;

    /// increment refcount
    pub fn r1(arg1: K) -> K;

    /// remove callback
    #[cfg(not(feature = "ipc"))]
    pub fn sd0(arg1: I) -> V;

    /// remove callback conditional
    #[cfg(not(feature = "ipc"))]
    pub fn sd0x(arg1: I, arg2: I) -> V;

    /// set function on loop
    #[cfg(not(feature = "ipc"))]
    pub fn sd1(arg1: I, arg2: extern "C" fn(I) -> K) -> K;

    // toggle symbol lock
    pub fn setm(arg1: I) -> I;

    /// intern chars
    pub fn sn(arg1: S, arg2: I) -> S;

    /// intern string
    pub fn ss(arg1: S) -> S;

    /// sslInfo
    #[cfg(not(feature = "embed"))]
    pub fn sslInfo(arg1: K) -> K;

    /// release date
    #[cfg(not(feature = "embed"))]
    pub fn ver() -> I;

    /// create dictionary
    pub fn xD(arg1: K, arg2: K) -> K;

    /// table from dictioinary
    pub fn xT(arg1: K) -> K;

    /// numbers to date
    pub fn ymd(arg1: I, arg2: I, arg3: I) -> I;
}