void DbgInit() { DbgLastObj = NULL; if (NULL == (Log = StreamOpen("log", "w+"))) Log = stdout; if (NULL == (Display = StreamOpen("display", "w+"))) Display = stdout; #ifdef MACOS #else if (Log != stdout) setvbuf(Log, NULL, _IONBF, 0L); #endif Out = stdout; }
static void OutputArrayValues(parsercontext *p, const tchar_t *name, tchar_t *values[], size_t size) { tchar_t Path[MAXPATH]; tchar_t Value[MAXPATH]; textwriter Output, StringOutput; size_t i; stprintf_s(Value, TSIZEOF(Value), T("res_%s"), name); for (i=0; i<size; ++i) { stprintf_s(Path, TSIZEOF(Path), T("values-%s"), values[i]); FolderCreate((nodecontext*)p, Path); if (PathIsFolder((nodecontext*)p, Path)) { tcscat_s(Path, TSIZEOF(Path), T("/resinfo.xml")); memset(&Output,0,sizeof(Output)); Output.Stream = StreamOpen(p, Path, SFLAG_WRONLY|SFLAG_CREATE); TextElementXML(p, &Output, T("resources")); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), Value, TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), values[i]); TextElementEndData(&StringOutput, Path); TextElementEnd(&Output); StreamClose(Output.Stream); } } }
void ProveIt(char *goal_filename, char *rule_filename, char *fact_filename, char *output_filename) { Obj *goal; ObjList *rules; ObjList *facts; Proof *proofs; FILE *outstream; if (NULL == (outstream = StreamOpen(output_filename, "w+"))) { return; } goal = ObjFileRead(goal_filename); if (goal == NULL) { return; } rules = ObjListFileRead(rule_filename); facts = ObjListFileRead(fact_filename); fprintf(outstream, "input goal = "); ObjPrint(outstream, goal); fputc(NEWLINE, outstream); fprintf(outstream, "input rules =\n"); ObjListPrint(outstream, rules); fprintf(outstream, "input facts =\n"); ObjListPrint(outstream, facts); if (Prove1(&TsNA, NULL, goal, rules, facts, 1, 0, &proofs)) { fprintf(outstream, "found proofs:\n"); ProofPrintAll(outstream, proofs); } else { fprintf(outstream, "did not find proofs\n"); } StreamClose(outstream); }
int open (const char* path, int flags, int mode) { int fd; int ret; SYS_RET ( ret, StreamOpen(path, flags, mode, &fd) ); return fd; }
static void LoadTXT(const tchar_t* FileName,void* Buffer) { stream* p = StreamOpen(FileName,0); if (p) { StringAddText(Buffer,p->Read(p,Buffer,MAXTEXT)); StreamClose(p); } }
static stream* DummyDuplicate(void* p,int Flags) { tchar_t URL[MAXPATHFULL]; if (Node_Get(p,STREAM_URL,URL,sizeof(URL)) != ERR_NONE) return NULL; return StreamOpen(p,URL,Flags); }
void DbgLogClear() { StreamClose(Log); Log = stdout; /* REALLY */ if (NULL == (Log = StreamOpen("log", "w+"))) Log = stdout; #ifdef MACOS #else if (Log != stdout) setvbuf(Log, NULL, _IONBF, 0L); #endif }
Obj *ObjFileRead(char *filename) { FILE *instream; Obj *obj; if (NULL == (instream = StreamOpen(filename, "r"))) { return NULL; } obj = ObjRead(instream); return obj; }
ObjList *ObjListFileRead(char *filename) { FILE *instream; ObjList *objs; Obj *obj; if (NULL == (instream = StreamOpen(filename, "r"))) { return NULL; } objs = NULL; while ((obj = ObjRead(instream))) { objs = ObjListCreate(obj, objs); } return objs; }
int TA_TaggerPrune1(char *fn, TaggerWords *tw, Channel *ch) { int cnt, spliced; long wordnum; char word[PHRASELEN], tag[FEATLEN]; size_t pos; int firstchar; FILE *stream; PNode *pn, *prev; if (NULL == (stream = StreamOpen(fn, "r"))) { return(0); } wordnum = 0L; pn = ch->pnf->first; prev = NULL; while (pn) { if (!TA_TaggedWordRead(stream, word, tag)) break; Dbg(DBGGEN, DBGHYPER, "<%s>.<%s>", word, tag); if (wordnum >= tw->len) { Dbg(DBGGEN, DBGBAD, "TA_TaggerPrune1 length mismatch"); break; } if (!PennIsPunct(tag)) { pos = tw->positions[wordnum]; firstchar = tw->firstchars[wordnum]; TA_TaggerPrune2(pn, prev, 0, pos, firstchar, ch, word, tag, NULL, NULL, &cnt, &spliced); if ((spliced > 0) && (spliced < cnt) && /* Don't rule out all words. */ (cnt > 1)) { /* Don't rule out the only instance of a word. */ TA_TaggerPrune2(pn, prev, 1, pos, firstchar, ch, word, tag, &pn, &prev, NULL, NULL); } } wordnum++; } StreamClose(stream); return(1); }
char *StringReadFile(char *fn, int useroot) { char *s; size_t cnt; FILE *stream; struct stat statrec; char fn1[FILENAMELEN]; if (useroot) { sprintf(fn1, "%s/%s", TTRoot, fn); fn = fn1; } if (0 > stat(fn, &statrec)) { Dbg(DBGGEN, DBGBAD, "Trouble opening %s\n", fn); return(NULL); } if (NULL == (stream = StreamOpen(fn, "r"))) return(NULL); s = (char *)MemAlloc(statrec.st_size+1L, "char StringReadFile"); cnt = fread(s, 1L, statrec.st_size, stream); #ifdef notdef /* Some kind of newline problem on PCs? */ if (cnt < statrec.st_size) { Dbg(DBGGEN, DBGBAD, "StringReadFile: %ld < %ld", cnt, statrec.st_size); MemFree(s, "char StringReadFile"); fclose(stream); return(NULL); } #endif s[statrec.st_size] = TERM; fclose(stream); #ifdef MACOS if (StringTailEq(fn, ".iso")) { /* todo: Need to add this to ChannelReadBatch too. */ StringISO_8859_1ToMacDestructive(s); } #endif return(s); }
int TA_TaggerWriteInput(char *fn, TaggerWords *tw, Channel *ch) { int eoschar; size_t pos; PNode *pn; FILE *stream; if (NULL == (stream = StreamOpen(fn, "w+"))) { return(0); } pos = 0; pn = ch->pnf->first; while (pos < ch->len) { if (NULL == (pn = PNodeGetNext(pn, pos))) break; if (pn->type == PNTYPE_END_OF_SENT) { eoschar = ch->buf[pn->lowerb]; TA_TaggerWriteSentence(stream, tw, ch, pos, pn->lowerb, eoschar); } pos = pn->upperb+1; } StreamClose(stream); return(1); }
void String_Init() { void* Buffer; StringAlloc(); Buffer = malloc(MAXTEXT); if (Buffer) { #ifdef NO_PLUGINS { int n; HANDLE Module = GetModuleHandle(NULL); HRSRC Rsrc = FindResource(Module,MAKEINTRESOURCE(2000),T("LANGTAR")); if (Rsrc) { int Size = SizeofResource(Module,Rsrc); HGLOBAL Global = LoadResource(Module,Rsrc); if (Global) { void* p = LockResource(Global); if (p) { stream* Stream = StreamOpenMem(p,Size); if (Stream) { LoadTGZ(Stream,Buffer); StreamCloseMem(Stream); } } } } for (n=2000;(Rsrc = FindResource(Module,MAKEINTRESOURCE(n),T("LANG")))!=NULL;++n) { int Size = SizeofResource(Module,Rsrc); HGLOBAL Global = LoadResource(Module,Rsrc); if (Global) { void* p = LockResource(Global); if (p) StringAddText(p,Size); } } } #endif #ifndef NO_LANG { tchar_t Path[MAXPATH]; stream* p; GetModulePath(Path,T("common.dll")); tcscat_s(Path,TSIZEOF(Path),T("language.tgz")); p = StreamOpen(Path,0); if (p) { LoadTGZ(p,Buffer); StreamClose(p); } GetModulePath(Path,T("common.dll")); FindFiles(Path,T("*.txt"),LoadTXT,Buffer); } #endif free(Buffer); } }
void TranslateInit() { TranslateStream = StreamOpen("outtrans.txt", "w+"); TranslationOn = 0; }
static void OutputValues(parsercontext *p, size_t size, size_t night, size_t density, size_t touchscreen, size_t keyboard, size_t textinput, size_t navstate, size_t navmethod) { tchar_t Path[MAXPATH]; textwriter Output, StringOutput; stprintf_s(Path, TSIZEOF(Path), T("values") T("-%s") // T("-%s") T("-%s") // T("-%s") // T("-%s") // T("-%s") // T("-%s") // T("-%s") ,Size[size] // ,Night[night] ,Density[density] // ,TouchScreen[touchscreen] // ,Keyboard[keyboard] // ,TextInput[textinput] // ,NavigationState[navstate] // ,NavigationMethod[navmethod] ); FolderCreate((nodecontext*)p, Path); if (PathIsFolder((nodecontext*)p, Path)) { tcscat_s(Path, TSIZEOF(Path), T("/resinfo.xml")); memset(&Output,0,sizeof(Output)); Output.Stream = StreamOpen(p, Path, SFLAG_WRONLY|SFLAG_CREATE); TextElementXML(p, &Output, T("resources")); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_size"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), Size[size]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_night"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), Night[night]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_density"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), Density[density]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_touchscreen"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), TouchScreen[touchscreen]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_keyboard"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), Keyboard[keyboard]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_textinput"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), TextInput[textinput]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_navstate"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), NavigationState[navstate]); TextElementEndData(&StringOutput, Path); TextElementBegin(&StringOutput, &Output, T("string")); TextAttrib(&StringOutput, T("name"), T("res_navmethod"), TYPE_STRING); TcsToUpper(Path, TSIZEOF(Path), NavigationMethod[navmethod]); TextElementEndData(&StringOutput, Path); TextElementEnd(&Output); StreamClose(Output.Stream); } }