How can I use ChatScript Library with function in my own program? - chat

How can I write a program that inside it, I can call ChatScript program, pass my input file to it and get the results as an output text file?
This is a example using ChatScript Library :
#include <fstream>
#include <iostream>
#include <string>
#include <chatScript.h> //for example!
using namespace std;
int main()
{
ofstream output;
string str1, str2;
getline(cin, str1);
//This is the ChatScript function that i am looking for!
str2= ChatScript_input(str1);
output.open("output.txt");
output<< "str2";
output.close();
return 0;
}

I would suggest you ask the developer of ChatScript directly on the forum he monitors https://www.chatbots.org/ai_zone/viewforum/44/
Hope this is not against the rules here to post a link to an external forum.
As far as I understand CS opens a socket through which you are supposed to communicate with it.
Here is the manual explaining how that can be done:
https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/CLIENTS-AND-SERVERS/ChatScript-ClientServer-Manual.md

Related

AFL hello world example

I'm trying to figure out how to use AFL, but I can't seem to make a simple example running.
Here is my C program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
char *remove_white_space(char *s)
{
while (s && *s++)
if (*s == ' ')
return "moish";
return s;
}
int main(int argc, char **argv)
{
char buffer[256]={0};
FILE *fl = fopen(argv[1],"rt");
if (fl == NULL) return 0;
assert(fscanf(fl,"%s",buffer) > 0);
char *res = remove_white_space(buffer);
if (strcmp(res,"a b c d") == 0)
{
assert(0);
}
fclose(fl);
return 0;
}
My input seed is a text file with a single line abhgsd.
Here is what I did:
$ afl-gcc main.c -o main
afl-cc 2.56b by <lcamtuf#google.com>
afl-as 2.56b by <lcamtuf#google.com>
[+] Instrumented 62 locations (64-bit, non-hardened mode, ratio 100%).
$ afl-fuzz -i INPUTS/ -o OUTPUTS ./main ##
And I got this red CAPITAL CRASH message:
afl-fuzz 2.56b by <lcamtuf#google.com>
[+] You have 8 CPU cores and 1 runnable tasks (utilization: 12%).
[+] Try parallel jobs - see /usr/local/share/doc/afl/parallel_fuzzing.txt.
[*] Checking CPU core loadout...
[+] Found a free CPU core, binding to #0.
[*] Checking core_pattern...
[-] Hmm, your system is configured to send core dump notifications to an
external utility. This will cause issues: there will be an extended delay
between stumbling upon a crash and having this information relayed to the
fuzzer via the standard waitpid() API.
To avoid having crashes misinterpreted as timeouts, please log in as root
and temporarily modify /proc/sys/kernel/core_pattern, like so:
echo core >/proc/sys/kernel/core_pattern
[-] PROGRAM ABORT : Pipe at the beginning of 'core_pattern'
Location : check_crash_handling(), afl-fuzz.c:7316
I'm a bit reluctant to change something unless I'm sure what I'm doing.
What's going on here? Should I listen to what AFL is saying?
You should probably change your core pattern, but you can change it back later. Many linux distros have a crash reporting service like apport, which relies on having core dumps from crashing processes piped to it via a core pattern like |/usr/share/apport/apport %p %s %c %d %P (see man 5 core) When the core pattern is set up this way, every time a program crashes, apport is run and the core is fed to it as standard input. So if you change the core pattern to just core, do your fuzzing, and then change the core pattern back to whatever it is currently, your distro's crash reporter should resume its normal operation.
AFL may have an environment variable to disable this check, as I know there exist environment variables to disable other pre-fuzzing checks (like AFL_SKIP_CRASHES allowing crashing input in the initial seeds), but this one is pretty low-cost to toggle.
The answer is right there in front of you.
log in as root and echo core >/proc/sys/kernel/core_pattern

Linux DD passing data to serial port ttyS0

Hi i want to pass a data from my char device driver to serial port ttyS0..
I have created a simple char driver module which reads and write and it's my first tym doing it.. i am using debian guest os...
e.g.
echo "hello" > /dev/mydev
now when /dev/mydev receives the data it will then alter the string into something like "hello too" which is passed to my serial port /dev/ttyS0..
how can i alter the string?.. is it possible to use if statement inside mydev?
e.g
if(string=="hello"){
alterstringTO: hello to;
pass "hello to" /dev/ttyS0;
like echoing in terminal..
echo "hello to" > /dev/ttyS0
}
Is that possible?... or is there any other way doing it?
Here some of the code..
ssize_t dev_read(struct file *filp, char *buf, size_t clen, loff_t *f_pos){
short cnt =0;
while(clen && (msg[Pos]!=0))
{
put_user(msg[Pos],buf++);
cnt++;
clen--;
Pos++;
}
return cnt;
}
ssize_t dev_write(struct file *filp, const char *buf, size_t clen, loff_t *f_pos){
short dec = clen-1;
short cnt=0;
memset(msg,0,50);
Pos=0;
while(clen>0)
{
msg[cnt++] = buf[dec--];
clen--;
}
return cnt;
}
Thanks in advance..
Just a comment on writing to the serial port:
Remember the Linux foundations, everything is a file in Linux. To write to the device driver from a program you need to open the file for writing and then you can fprintf whatever data you want. You can do that from user space as well (the recommended way)
Refer to the following man pages:
man fopen
man fread/fwrite
man fprintf
man fclose
I'm not exactly sure what you are trying to achieve here, as the question and the intent seems unclear to me. I'll provide some guidance, but recommend that you edit your question and make it more readable.
Your snippet to compare strings is not correct. You can learn more about how to compare strings in C in here.
Altering a string in C is a basic operation that you learn when you start working with strings. This should help you getting started.
As final remark, please note that programming for the kernel requires extra care. A small mistake may lead to a crash and loss of data. If you really must, then the book Linux Device Drivers 3rd Edition is freely available and can help you further.

Eclipse CDT : don't print to screen until input first

Here is my simple code :
#include <stdio.h>
int main(){
printf("Hello new world\n");
char c[10];
scanf("%s",c);
printf("%s",c);
return 0;
}
Normal, We will see: Hello new world, after that, we input some string, and C will print this string for us.
But in my eclipse CDT, when running, console is empty. I must input a string first, for example, stackoverflow. after that, my program will print :
Hello new world
stackoverflow
I don't know why happen, please teach me to fix this.
Thanks :)
It's something that developers of Eclipse do not consider for a bug.
You can read more about this "bug" here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=173732
Anyway... Ugly but working solution is to put
fflush(stdout);
after every printf() and puts().

problem with nvmex in matlab

i have installed matlab on my system and also have installed the CUDA SDK for windows. however i am not able to compile any .cu files. I have included the nvmex script file in the bin directory of the Matlab installation path. Can some body help?
nvmex isn't really supported in any recent versions of Matlab or the Cuda SDK. Instead, I would suggest writing a simple DLL in Visual Studio which uses the standard MEX interface to run Cuda. I'm going to assume that your project is called "addAtoB" and that you just want to add two numbers together to make the example simpler.
When you installed the Cuda SDK, you need to tell it to add the CUDA Custom Build Rules to Visual Studio so that it will know how to compile .CU files.
Your main cpp should look something like this:
// addAtoB.cpp
#include <mex.h>
#include <cuda.h>
#include <driver_types.h>
#include <cuda_runtime_api.h>
#pragma comment(lib,"libmx.lib") // link with the Matlab MEX API
#pragma comment(lib,"libmex.lib")
#pragma comment(lib,"cudart.lib") // link with CUDA
// forward declare the function in the .cu file
void runMyCUDAKernel(void);
// input and output variables for the function in the .cu file
float A, B, C;
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
A = (float) mxGetScalar(prhs[0]);
B = (float) mxGetScalar(prhs[1]);
runMyCUDAKernel();
// allocate output
nlhs = 1;
plhs[0] = mxCreateDoubleScalar(C);
mexPrintf("GPU: %f + %f = %f\nCPU: %f", A, B, C, A+B);
cudaDeviceReset();
}
You need add several directories to your Include Path: C:\Program Files\MATLAB\R2009a\extern\include and the CUDA directories.
Add to your Linker Path: C:\Program Files\MATLAB\R2009a\extern\lib\win32\microsoft , $(CUDA_PATH)\lib\$(PlatformName)
Next, add a .DEF file to your project which looks something like this:
LIBRARY "addAtoB"
EXPORTS
mexFunction
Next, create a file called runMyCUDAKernel.cu in the current directory, type in contents something like this, and then add the file to your project:
// runMyCUDAKernel.cu:
#include <cuda.h>
extern float A, B, C;
// Device kernel
__global__ void addAtoB(float A1, float B1, float* C1)
{
*C1 = A1+B1;
}
void runMyCUDAKernel(void)
{
float* pOutput;
cudaMalloc( (void**) &pOutput, 1*sizeof(float));
dim3 dimBlock(1, 1);
dim3 dimGrid(1, 1);
addAtoB<<< dimGrid, dimBlock >>>(A, B, pOutput);
cudaMemcpy( &C, pOutput, 1*sizeof(float), cudaMemcpyDeviceToHost);
cudaDeviceSynchronize();
cudaFree(pOutput);
}
Build the DLL and rename it from .dll to .mexw32 (or .mexw64, if you're using a 64-bit Matlab). Then you should be able to run it with the command addAtoB(1, 2).
I would suggest using CUDA mex from the Matlab file exchange.
It enables you to compile through Matlab. This gets better compatibility across Matlab and Visual Studio versions by not forcing you to specify the mex dependencies explicitly through Visual Studio.

Send Return Code back from child script to the Parent script

My child script can create a rc=110 when a FTPed file is not located. The Parent script sets the Error Handling RC=1. I want the Error Handling to set to the RC created in child script. Any ideas?
What operating system? In linux you can forward the paramenter using standard input/output using the | (pipe)
./script | ./binaryName
This forwards the output of ./script as the input of ./binaryName
and in your main:
int main(int argc, char **argv){
//Don't use argv[0]!
char* yourOutput = argv[1];
return 0;
}
I just realized your "parent" is a script too. Which language is this? All the languages I've worked with have a manner to get arguements like I just showed you in C++.