Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cinterf.h>
- #include <stdio.h>
- int main()
- {
- // 1) Create a 'fixedString' called 'queryValue' with 10 characters
- // You MUST use malloc(). Setting 'queryValue' to a string literal will throw a segfault.
- const int QUERY_SIZE = 10;
- char* queryValue = malloc(QUERY_SIZE);
- // 2) Initialize XSB
- if(xsb_init_string("/home/quantumech/Desktop/XSB"))
- {
- printf("++XSB failed to initialize with error: %s\n", xsb_get_init_error_message());
- exit(-1);
- }
- else
- {
- // 3) Load XSB script with defined terms such as 'f(a,b,c)' 'f(1,2,3)' etc.
- xsb_command_string("consult('./script.P').");
- // 'actualValueLength' gets set to what ever the actual query size turns out to be.
- // So if 10 characters are allocated for 'queryValue' but only 5 are used, then 'actualValueLength' would be 5
- int actualValueLength;
- // The extra '_b' means the XSB method works on 'fixedBuffer' strings (aka. C strings)
- // xsb_query_string_string_b(command, outputStr, outputStrSize, &actualValueLength, seperator)
- if(xsb_query_string_string_b("f(X,Y,Z).", queryValue, QUERY_SIZE, &actualValueLength,",") == XSB_SUCCESS)
- {
- // Keep passing query results into 'queryValue' until xsb_next_string() doesnt return anymore values
- while(xsb_next_string_b(queryValue, QUERY_SIZE, &actualValueLength, ",") == XSB_SUCCESS)
- {
- // Print result of query
- printf("Query result: %s\n", queryValue);
- }
- }
- // Terminate XSB
- xsb_close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement