Face* dirface(char *dir, char *num) { Face *f; char *from, *date; char buf[1024], pwd[1024], *info, *p, *digest; int n, fd; ulong len; /* * loadmbox leaves us in maildir, so we needn't * walk /mail/fs/mbox for each face; this makes startup * a fair bit quicker. */ if(getwd(pwd, sizeof pwd) != nil && strcmp(pwd, dir) == 0) sprint(buf, "%s/info", num); else sprint(buf, "%s/%s/info", dir, num); len = dirlen(buf); if(len <= 0) return nil; fd = open(buf, OREAD); if(fd < 0) return nil; info = emalloc(len+1); n = readn(fd, info, len); close(fd); if(n < 0){ free(info); return nil; } info[n] = '\0'; f = emalloc(sizeof(Face)); from = iline(info, &p); /* from */ iline(p, &p); /* to */ iline(p, &p); /* cc */ iline(p, &p); /* replyto */ date = iline(p, &p); /* date */ setname(f, estrdup(from)); f->time = parsedate(date); f->tm = *localtime(f->time); sprint(buf, "%s/%s", dir, num); f->str[Sshow] = estrdup(buf); iline(p, &p); /* subject */ iline(p, &p); /* mime content type */ iline(p, &p); /* mime disposition */ iline(p, &p); /* filename */ digest = iline(p, &p); /* digest */ f->str[Sdigest] = estrdup(digest); free(info); return f; }
/** * Load a dataset stored in a file. * * @param filename Dataset filename */ bool Dataset::loadDataset(const string& nomefile) { int version; string line, dummy; ifstream infile(nomefile.c_str()); if(!infile.is_open()) { cout << "[Error] Unable to open the dataset file" << endl; return false; } else { trainings.clear(); // Version getline(infile,line); // First line is WiiC log version if(line.find("WiiC") == string::npos) { cout << "[Error] Bad log format." << endl; return false; } istringstream iline(line); iline >> dummy >> version; if(version > WIIC_LOG_VERSION) { cout << "[Error] Unsupported WiiC log version." << endl; return false; } getline(infile,line); // Date (we should load this as well...) // For each training int counter = 0; while(!infile.eof()) { getline(infile,line); istringstream iline(line); string cmd; unsigned long ts; iline >> cmd >> ts; if(cmd == "START") { // Each training is inserted in the training vector trainings.push_back(new Training()); trainings[counter]->setTimestampFromMidnight(ts); if(!(trainings[counter++]->loadTraining(infile))) { cout << "[Error] Unable to load a training in the dataset" << endl ; return false; } } } } infile.close(); loaded = true; return loaded; }
int main(int argC, char* argv[]) { if(argc < 1) { cerr << "need training data" << endl; exit(1); } corpus trainingData; { ifstream datafile(argv[1]); char line[255]; while(datafile.getline(line,255)) { sentence s; string word; istrstream iline(line,strlen(line)); while(iline >> word) { s.push_back(word); } if(s.size() > 0) trainingData.push_back(s); } } cerr << "reading cnf grammar..." << endl; PCFG aPCFG; cin >> aPCFG; aPCFG.train(trainingData); cout << aPCFG; }
/*=============================================+ * vprog_error -- Report a run time program error * node: current parsed node * fmt, args: printf style message * ...: printf style varargs * Prints error to the stdout-style curses window * and to the report log (if one was specified in config file) * Always includes line number of node, if available * Only includes file name if not same as previous error * Returns static buffer with one-line description *============================================*/ static STRING vprog_error (PNODE node, STRING fmt, va_list args) { INT num; STRING rptfile; ZSTR zstr=zs_newn(256); static char msgbuff[100]; if (rpt_cancelled) return _("Report cancelled"); rptfile = getlloptstr("ReportLog", NULL); if (node) { STRING fname = irptinfo(node)->fullpath; INT lineno = iline(node)+1; /* Display filename if not same as last error */ if (!eqstr(vprog_prevfile, fname)) { llstrsets(vprog_prevfile, sizeof(vprog_prevfile), uu8, fname); zs_apps(zstr, _("Report file: ")); zs_apps(zstr, fname); zs_appc(zstr, '\n'); vprog_prevline = -1; /* force line number display */ } /* Display line number if not same as last error */ if (vprog_prevline != lineno) { vprog_prevline = lineno; if (progparsing) zs_appf(zstr, _("Parsing Error at line %d: "), lineno); else zs_appf(zstr, _("Runtime Error at line %d: "), lineno); } } else { zs_apps(zstr, _("Aborting: ")); } zs_appvf(zstr, fmt, args); llwprintf("\n"); llwprintf(zs_str(zstr)); ++progerror; /* if user specified a report error log (in config file) */ if (rptfile && rptfile[0]) { FILE * fp = fopen(rptfile, LLAPPENDTEXT); if (fp) { if (progerror == 1) { LLDATE creation; get_current_lldate(&creation); fprintf(fp, "\n%s\n", creation.datestr); } fprintf(fp, "%s", zs_str(zstr)); fprintf(fp, "\n"); fclose(fp); } } if ((num = getlloptint("PerErrorDelay", 0))) sleep(num); zs_free(&zstr); return msgbuff; }
/*==========================================+ * evaluate_func -- Evaluate builtin function *=========================================*/ PVALUE evaluate_func (PNODE node, SYMTAB stab, BOOLEAN *eflg) { PVALUE val; *eflg = FALSE; if (prog_trace) trace_outl("evaluate_func called: %d: %s", iline(node)+1, iname(node)); val = (*(PFUNC)ifunc(node))(node, stab, eflg); return val; }
static void loop() { int timediff; struct tbuf *tp; if (wb.ut_line[0] == '\0') /* It's an init admin process */ return; /* no connect accounting data here */ switch (wb.ut_type) { case OLD_TIME: datetime = wb.ut_xtime; return; case NEW_TIME: if (datetime == 0) return; timediff = wb.ut_xtime - datetime; for (tp = tbuf; tp <= &tbuf[tsize]; tp++) tp->ttime += timediff; datetime = 0; ndates++; return; case DOWN_TIME: return; case BOOT_TIME: upall(); case ACCOUNTING: case RUN_LVL: lastime = wb.ut_xtime; bootshut(); return; case USER_PROCESS: case LOGIN_PROCESS: case INIT_PROCESS: case DEAD_PROCESS: /* WHCC mod 3/86 */ update(&tbuf[iline()]); return; case EMPTY: return; default: cftime(time_buf, DATE_FMT, &wb.ut_xtime); fprintf(stderr, "acctcon: invalid type %d for %s %s %s", wb.ut_type, wb.ut_name, wb.ut_line, time_buf); } }
Face* dirface(char *dir, char *num) { Face *f; char buf[1024], *info, *p, *t, *s; int n; ulong len; CFid *fid; sprint(buf, "%s/%s/info", dir, num); len = fsdirlen(mailfs, buf); if(len <= 0) return nil; fid = fsopen(mailfs, buf, OREAD); if(fid == nil) return nil; info = emalloc(len+1); n = fsreadn(fid, info, len); fsclose(fid); if(n < 0){ free(info); return nil; } info[n] = '\0'; f = emalloc(sizeof(Face)); for(p=info; (s=iline(p, &p)) != nil; ){ t = strchr(s, ' '); if(t == nil) continue; *t++ = 0; if(strcmp(s, "unixdate") == 0){ f->time = atoi(t); f->tm = *localtime(f->time); } else if(strcmp(s, "from") == 0) setname(f, t); else if(strcmp(s, "digest") == 0) f->str[Sdigest] = estrdup(t); } sprint(buf, "%s/%s", dir, num); f->str[Sshow] = estrdup(buf); free(info); return f; }
int RF2::run(istream& in) { const streamsize ilinelen = 1024; scoped_array<char> iline(new char[ilinelen]); int cnt = 0; dmlif::DMLIF dmlif(fSessionID, fTflg, fDflg, fVflg); for (;;) { dmlif.rf2Start(fSchema); for (int i = 0; i < fPack; i++) { in.getline(iline.get(), ilinelen); if (in.eof()) break; typedef char_separator<char> cs; typedef tokenizer<cs> tk; cs sep("|"); tk tok(string(iline.get()), sep); tk::iterator iter = tok.begin(); idbassert(iter != tok.end()); string keystr = *iter; ++iter; //idbassert(iter == tok.end()); int64_t okey = strtol(keystr.c_str(), 0, 0); dmlif.rf2Add(okey); } dmlif.rf2Send(); cnt++; if ((cnt % fIntvl) == 0) dmlif.sendOne("COMMIT;"); if (in.eof()) break; } dmlif.sendOne("COMMIT;"); return 0; }
int body() { char c, CR, buf[64]; while(1){ printf("=======================================\n"); printQueue(readyQueue); printf("proc %d %s in Kmode\n", running->pid, running->name); printf("input a command (s|f|u|q|i|o) : "); c=getc(); putc(c); CR=getc(); putc(CR); switch(c){ case 's' : tswitch(); break; case 'u' : printf("\nProc %d ready to go U mode\n", running->pid); goUmode(); break; case 'f': fork(); break; case 'q' : kexit(); break; case 'i' : iline(); break; case 'o' : oline(); break; } } }
/*=============================+ * evaluate -- Generic evaluator *============================*/ PVALUE evaluate (PNODE node, SYMTAB stab, BOOLEAN *eflg) { if (prog_trace) { trace_out("%d: ", iline(node)+1); trace_pnode(node); trace_endl(); } if (iistype(node, IIDENT)) return evaluate_iden(node, stab, eflg); if (iistype(node, IBCALL)) return evaluate_func(node, stab, eflg); if (iistype(node, IFCALL)) return evaluate_ufunc(node, stab, eflg); *eflg = FALSE; if (iistype(node, IICONS)) return copy_pvalue(ivalue(node)); if (iistype(node, ISCONS)) return copy_pvalue(ivalue(node)); if (iistype(node, IFCONS)) return copy_pvalue(ivalue(node)); *eflg = TRUE; return NULL; }
/** * Load dataset from a file into a class Dataset */ void Dataset::loadDataset(const string& nomefile) { int size; string line; ifstream infile(nomefile.c_str()); if(!infile.is_open()) { cout<<"[Error] Unable to open the dataset file"<<endl; } else { trainings.clear(); getline(infile,line); istringstream iline(line); iline >> size; for(int i = 0 ; i < size ; i++) { // Each training is inserted in the training vector trainings.push_back(new Training()); // Each training is filled with its relative values (polymorphism) trainings[i]->loadTraining(infile); } } infile.close(); }
void cont(int x0, int y0) { iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0))); return; }
void line(int x0, int y0, int x1, int y1) { iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1))); return; }
cont(x0,y0){ iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0))); return; }
line(x0,y0,x1,y1){ iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1))); return; }