Skip to content

Commit

Permalink
静态库外部使用
Browse files Browse the repository at this point in the history
  • Loading branch information
candlewill committed Mar 30, 2017
1 parent 8575ba2 commit 8ce2dd6
Show file tree
Hide file tree
Showing 148 changed files with 1,284,749 additions and 11 deletions.
20 changes: 20 additions & 0 deletions Bot_tools/Usage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CMake 最低版本号要求
cmake_minimum_required (VERSION 3.0)
# 项目信息
project (ChatScript_Main)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 添加头文件目录INCLUDE_DIRECTORIES
include_directories(./ChatScript/include)

# 添加math子目录
# 使用命令 add_subdirectory 指明本项目包含一个子目录 math,这样 math 目录下的 CMakeLists.txt 文件和源代码也会被处理
link_directories("./ChatScript")

# 指定生成目标
add_executable(ChatScript_Main Dialog.cpp)

# 添加链接库
# 使用命令 target_link_libraries 指明可执行文件 main 需要连接一个名为 MathFunctions 的链接库
target_link_libraries(ChatScript_Main ChatScript curl)
File renamed without changes.
232 changes: 232 additions & 0 deletions Bot_tools/Usage/ChatScript/include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#ifndef _MAXH_
#define _MAXH_
#ifdef INFORMATION
Copyright (C) 2011-2017 by Bruce Wilcox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif

// These can be used to shed components of the system to save space
//#define DISCARDSERVER 1
//#define DISCARDSCRIPTCOMPILER 1
//#define DISCARDPARSER 1
//#define DISCARDTESTING 1
//#define DISCARDTCPOPEN 1
//#define DISCARDMYSQL 1
//#define DISCARDPOSTGRES 1
//#define DISCARDMONGO 1
//#define DISCARDJSON 1
//#define DISCARDJAVASCRIPT 1
#define DISCARDMYSQL 1

// these can add components
//#define TREETAGGER 1

#ifdef LOEBNER
#define DISCARDSERVER 1
#define DISCARDSCRIPTCOMPILER 1
#define DISCARDTESTING 1
#define DISCARDTCPOPEN 1
#define DISCARDMYSQL 1
#define DISCARDPOSTGRES 1
#define DISCARDMONGO 1
#define DISCARDCOUNTER 1
#define DISCARDCLIENT 1
#define DISCARDJSON 1
#define DISCARDJAVASCRIPT 1

#elif WIN32
//#define USERPATHPREFIX 1
#define DISCARDMYSQL 1
#define DISCARDPOSTGRES 1
#define DISCARDMONGO 1

#elif IOS
#define DISCARDCOUNTER 1
#define DISCARDMYSQL 1
#define DISCARDPOSTGRES 1
#define DISCARDMONGO 1
#define DISCARDCOUNTER 1
#define DISCARDCLIENT 1
#define DISCARDJSON 1

#elif ANDROID
#define DISCARDCOUNTER 1
#define DISCARDMYSQL 1
#define DISCARDPOSTGRES 1
#define DISCARDMONGO 1
#define DISCARDCOUNTER 1
#define DISCARDCLIENT 1
#define DISCARDJSON 1

#elif __MACH__
#define DISCARDCOUNTER 1
#define DISCARDCLIENT 1
#define DISCARDPOSTGRES 1
#define DISCARDMYSQL 1
//#define DISCARDMONGO 1

#else // GENERIC LINUX
#ifndef EVSERVER
#define SAFETIME 1 // protect server from time concurrency issues in C++ library.
#endif
#endif

// These can be used to include LINUX EVSERVER component - this is automatically done by the makefile in src - EV Server does not work under windows
// #define EVSERVER 1

// These can be used to embed chatscript within another application (then you must call InitSystem on startup yourself)
// #define NOMAIN 1

// ʹÓÃPrivate_Code
#define PRIVATE_CODE

#ifndef WIN32
typedef long long long_t;
typedef unsigned long long ulong_t;
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#define stricmp strcasecmp
#define strnicmp strncasecmp
#else
typedef long long_t;
typedef unsigned long ulong_t;
#endif

#ifdef WIN32
#pragma comment(lib, "ws2_32.lib")
#pragma warning( disable : 4100 )
#pragma warning( disable : 4189 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4996 )

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_WARNINGS 1
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h> // needs to compile before any refs to winsock.h
#include <ws2tcpip.h>
#include <iphlpapi.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
#elif IOS
#include <dirent.h>
#include <mach/clock.h>
#include <mach/mach.h>
#elif __MACH__
#include <dirent.h>
#include <mach/clock.h>
#include <mach/mach.h>
#else // LINUX
#include <dirent.h>
#ifndef LINUX
#define LINUX 1
#endif
#endif

#ifdef IOS
#elif __MACH__
#include <sys/malloc.h>
#else
#include <malloc.h>
#endif

#include <algorithm>
#include <assert.h>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <errno.h>
#include <exception>
#include <fcntl.h>
#include <iostream>
#include <math.h>
#include <memory.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <sys/stat.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

#ifdef EVSERVER
#define EV_STANDALONE 1
#define EV_CHILD_ENABLE 1
#ifdef DISCARDMONGO
#ifdef DISCARDPOSTGRES
#define LOCKUSERFILE 1 // protect from multiple servers hitting same file
//#define USERPATHPREFIX 1 // do binary tree of log file - for high speed servers recommend userlog, no server log and this (large server logs are a pain to handle)
#endif
#endif
#endif

#include "common1.h"

#include "os.h"
#include "dictionarySystem.h"
#include "mainSystem.h"
#include "factSystem.h"
#include "functionExecute.h"

#include "csocket.h"
#include "constructCode.h"
#include "english.h"
#include "infer.h"
#include "json.h"
#include "markSystem.h"
#include "mongodb.h"
#include "my_sql.h"
#include "outputSystem.h"
#include "patternSystem.h"
#include "postgres.h"
#include "scriptCompile.h"
#include "spellcheck.h"
#include "systemVariables.h"
#include "tagger.h"
#include "testing.h"
#include "textUtilities.h"
#include "tokenSystem.h"
#include "topicSystem.h"
#include "userCache.h"
#include "userSystem.h"
#include "variableSystem.h"

#ifdef PRIVATE_CODE
#include "privatesrc.h"
#include "../privatecode/preprocess.h"
#endif

#ifdef WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif

#endif
84 changes: 84 additions & 0 deletions Bot_tools/Usage/ChatScript/include/common1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef COMMON1H
#define COMMON1H

typedef unsigned long long int uint64;
typedef signed long long int64;
#define ALWAYS (1 == always)

#define MAX_ARGUMENT_COUNT 400 // assume 10 args 40 nested calls max.
extern char* callArgumentList[MAX_ARGUMENT_COUNT+1]; // function callArgumentList
extern unsigned int callArgumentBase;

#define ARGUMENT(n) callArgumentList[callArgumentBase+n]
char* ReadCompiledWord(char* ptr, char* word,bool noquote = false,bool var = false);
char* ReadCompiledWordOrCall(char* ptr, char* word,bool noquote = false,bool var = false);

#define INPUT_BUFFER_SIZE 80000
#define MAX_BUFFER_SIZE 80000

#define NUMBER_OF_LAYERS 3

typedef unsigned int MEANING; // a flagged indexed dict ptr
#define MAX_DICTIONARY 0x001fffff // 2M word vocabulary limit
#define NODEBITS 0x00ffffff
#define MULTIWORDHEADER_SHIFT 24
#define MULTIHEADERBITS 0xFF000000

#define MAX_MEANING 63 // limit
#define MEANING_BASE 0x001fffff // the index of the dictionary item (may expand to use synset_marker
#define SYNSET_MARKER 0x00200000 // this meaning is a synset head - on keyword import, its quote flag for binary read
#define INDEX_BITS 0x0fC00000 // 6 bits of ontology meaning indexing ability 63 possible meanings allowed
#define INDEX_MINUS 0x00400000 // what to decrement to decrement the meaning index
#define INDEX_OFFSET 22 // shift for ontoindex (rang 0..63)
#define TYPE_RESTRICTION 0xf0000000 // corresponds to basic pos
#define TYPE_RESTRICTION_SHIFT 0

// A meaning = TYPE_RESTRICTION(4 bit) + INDEX_BITS (6 bits) + MEANING_BASE(21 bits) + SYNSET_MARKER(1 bit)

#define SYSVAR_PREFIX '%'
#define MATCHVAR_PREFIX '_'
#define USERVAR_PREFIX '$'
#define TRANSIENTVAR_PREFIX '$'
#define LOCALVAR_PREFIX '_'
#define FACTSET_PREFIX '@'
#define FUNCTIONVAR_PREFIX '^'
#define TOPICCONCEPT_PREFIX '~'

#define BIG_WORD_SIZE 10000
#define MAX_WORD_SIZE 3000
#define SMALL_WORD_SIZE 500

#undef WORDP // remove windows version (unsigned short) for ours

// DoFunction results
enum FunctionResult {
NOPROBLEM_BIT = 0,
ENDRULE_BIT = 0x00000001,
FAILRULE_BIT = 0x00000002,

RETRYRULE_BIT = 0x00000004,
RETRYTOPRULE_BIT = 0x00000008,

ENDTOPIC_BIT = 0x00000010,
FAILTOPIC_BIT = 0x00000020,
RETRYTOPIC_BIT = 0x00000040,

ENDSENTENCE_BIT = 0x00000080,
FAILSENTENCE_BIT = 0x00000100,
RETRYSENTENCE_BIT = 0x00000200,

ENDINPUT_BIT = 0x00000400,
FAILINPUT_BIT = 0x00000800,
RETRYINPUT_BIT = 0x00001000,

FAILMATCH_BIT = 0x00002000, // transient result of TestRule, converts to FAILRULE_BIT
FAILLOOP_BIT = 0x00004000,
ENDLOOP_BIT = 0x00008000,

UNDEFINED_FUNCTION = 0x00010000, // potential function call has no definition so isnt
ENDCALL_BIT = 0x00020000,
NEXTLOOP_BIT = 0x00040000,
RESTART_BIT = 0x00080000
};
FunctionResult JavascriptArgEval(unsigned int index, char* buffer);
#endif
22 changes: 22 additions & 0 deletions Bot_tools/Usage/ChatScript/include/constructCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _CONSTRUCTCODEH_
#define _CONSTRUCTCODEH_
#ifdef INFORMATION
Copyright (C) 2011-2017 by Bruce Wilcox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif

extern int impliedIf;
extern unsigned int withinLoop;
char* HandleIf(char* ptr, char* buffer, FunctionResult &result);
char* HandleLoop(char* ptr, char* buffer, FunctionResult &result);
FunctionResult HandleRelation(char* word1,char* op, char* word2,bool iflog,int& id,char* word1val, char* word2val);
#endif
10 changes: 10 additions & 0 deletions Bot_tools/Usage/ChatScript/include/cs_ev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __CS_EV_H__
#define __CS_EV_H__

#ifndef DISCARDSERVER
#ifdef EVSERVER
#include "evserver/ev.h"
#endif
#endif

#endif /* __CS_EV_H__ */
Loading

0 comments on commit 8ce2dd6

Please sign in to comment.