void readcclass(register classrec *cp) { register int n; register defn *dp; defn **dput; char store[MAXDEF]; /* for tags */ cp->weight = getw(InFile); instring(store, MAXDEF); cp->tags = (store[0] == '\0') ? NullTags : save(store); n = getw(InFile); if (n <= 0) badfile(); dput = &(cp->list); /* link on here */ while (n--) { dp = (defn *)my_alloc((unsigned) sizeof(defn)); *dput = dp; dp->cumul = getw(InFile); instring(store, MAXDEF); dp->string = save(store); dput = &(dp->next); } *dput = NULL; /* last one */ }
bool methodthere(char *shit, int *counter) { if (instring("{", shit)) (*counter)++; if (instring("}", shit)) (*counter)--; bool op = 0, cl = 0; for (int i = 0; i<strlen(shit); i++) { if (shit[i]=='(') op = 1; if (shit[i]==')') cl = 1; } return op && cl; }
bool fieldthere(char *shit, int *counter) { if (instring("{", shit)) (*counter)++; if (instring("}", shit)) (*counter)--; bool op = 0, cl = 0; for (int i = 0; i<strlen(shit); i++) { if (shit[i]=='(') op = 1; if (shit[i]==')') cl = 1; } return !(op || cl) && instring(";", shit); }
// static BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key) { std::string instring(str); size_t length = instring.size(); if (length < 1) { return FALSE; } if (length == 1) { char ch = toupper(instring[0]); if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('!' <= ch && ch <= '/') || // !"#$%&'()*+,-./ (':' <= ch && ch <= '@') || // :;<=>?@ ('[' <= ch && ch <= '`') || // [\]^_` ('{' <= ch && ch <= '~')) // {|}~ { *key = ch; return TRUE; } } LLStringUtil::toUpper(instring); KEY res = get_if_there(sNamesToKeys, instring, (KEY)0); if (res != 0) { *key = res; return TRUE; } LL_WARNS() << "keyFromString failed: " << str << LL_ENDL; return FALSE; }
// create new type in extracter void extracter_t::find_type(const char *tname1, const char *varname) { char *tname = new char [255]; strcpy(tname, tname1); //cout << tname << endl; if (typexist(tname)) return; if (typexist(nop(tname))) return; char bf[255]; char bf1[255]; char bf2[255]; if (instring("vector<", tname)) { tospace('<', tname); tospace('>', tname); sscanf(tname,"%s %s", bf1, bf); type_t *t = new type_t(-1, tname1, type); t->vec = 1; t->basetype = basetype(nop(bf)); t->addfield(bf, varname); // cout << bf; type->push_back(t); //find_type(nop(bf), varname); find_type(nop(bf), varname); //return; } //else cout << bf << endl; else find_type_infile(nop(tname1)); }
fp_Tree::fp_Tree(string filename , int f , int i) : freq(f) , item_ord(i) , item_count(i , 0) { ifstream infile(filename.c_str() , ios::in); string line; fp_Node root; tree.push_back(root); // insert every list int this_count = 0; while(getline(infile , line)) { istringstream instring(line); vector<int> v; int x; while(instring >> x) v.push_back(x); list_insert(v); ++this_count; } // insert the owner single item result.insert(make_pair(this_count , vector<int>(1 , item_ord))); // reverse the pointers adjust(); // get item_count for(int i = 0 ; i < item_ord ; ++i) { int now = header[i]; while(now != -1) { item_count[i] += tree[now].count; now = tree[now].next; } } }
yylex() { register c; int i; if (pass == PASS_1) { /* scan the input file */ do c = nextchar(); while (isspace(c) && c != '\n'); if (ISALPHA(c)) c = inident(c); else if (isdigit(c)) c = innumber(c); else switch (c) { case '=': case '<': case '>': case '|': case '&': c = induo(c); break; case ASC_SQUO: case ASC_DQUO: c = instring(c); break; case ASC_COMM: do c = nextchar(); while (c != '\n' && c != '\0'); break; case CTRL('A'): c = CODE1; readcode(1); break; case CTRL('B'): c = CODE2; readcode(2); break; case CTRL('C'): c = CODE4; readcode(4); break; } /* produce the intermediate token file */ if (c <= 0) return(0); if (c <= 127) putc(c, tempfile); else putval(c); } else { /* read from intermediate token file */ c = getc(tempfile); if (c == EOF) return(0); if (c > 127) { c += 128; c = getval(c); } } return(c); }
void Data::first_scan() { infile.open(is.c_str()); string line; // stage 1 : get item numbers and each support number while(getline(infile , line)) { istringstream instring(line); int x; while(instring >> x) { if(item_count.count(x) == 0) item_count[x] = 1; else ++item_count[x]; } if(x > item_num) item_num = x; ++set_num; } double d_freq = double(freq*set_num)/double(100); if(double(int(d_freq)) < (d_freq)) freq = int(d_freq)+1; else freq = int(d_freq); // stage 2 : sort the items b its support number map<int , int>::iterator it = item_count.begin(); for(; it != item_count.end() ; ++it) { item_list.push_back(make_pair(it->second , it->first)); } sort(item_list.begin() , item_list.end() , greater<pair<int , int> >() ); for(int i = 0 ; i < item_list.size() ; ++i) { if(item_list[i].first < freq) { item_list.erase(item_list.begin()+i , item_list.end()); break; } } // stage 3 : generate ord to item table and item to ord table item_to_ord.clear(); item_to_ord.resize(item_num+1 , -1); ord_to_item.clear(); valid_item_num = item_list.size(); ord_to_item.resize(valid_item_num); ord_to_item.resize(item_list.size()); for(int i = 0 ; i < item_list.size() ; ++i) { item_to_ord[item_list[i].second] = i; ord_to_item[i] = item_list[i].second; } // stage 4 : generating detached database (initialize but not input data) for(int i = valid_item_num ; i <= valid_item_num ; ++i) { char c[5]; sprintf(c , "%d" , i); string outdata = sub+"_d"+c+".dat"; ofstream out_data(outdata.c_str()); out_data.close(); } ofstream outfile(os.c_str()); outfile.close(); infile.close(); }
char* inside_vec(const char *type) { if (instring("vector ",type) || instring("vector<",type)) { char bf[255]; strcpy(bf, type); int l = findfirst(bf, '<'); int r = findfirst(bf, '>'); while(bf[l+1]==' ') l++; while(bf[r-1]==' ') r--; char *ret = new char[255]; strcpy(ret, ""); for (int i = l+1; i<r; i++) ret[i-l-1] = bf[i]; ret[r-l-1] = '\0'; return ret; } return NULL; }
//static BOOL LLKeyboard::maskFromString(const std::string& str, MASK *mask) { std::string instring(str); if (instring == "NONE") { *mask = MASK_NONE; return TRUE; } else if (instring == "SHIFT") { *mask = MASK_SHIFT; return TRUE; } else if (instring == "CTL") { *mask = MASK_CONTROL; return TRUE; } else if (instring == "ALT") { *mask = MASK_ALT; return TRUE; } else if (instring == "CTL_SHIFT") { *mask = MASK_CONTROL | MASK_SHIFT; return TRUE; } else if (instring == "ALT_SHIFT") { *mask = MASK_ALT | MASK_SHIFT; return TRUE; } else if (instring == "CTL_ALT") { *mask = MASK_CONTROL | MASK_ALT; return TRUE; } else if (instring == "CTL_ALT_SHIFT") { *mask = MASK_CONTROL | MASK_ALT | MASK_SHIFT; return TRUE; } else { return FALSE; } }
void Data::update_data(int x) { // open every database vector<int> v; ofstream of[x]; for(int i = 0 ; i < x ; ++i) { char c[5]; sprintf(c , "%d" , i); string outfilename = sub+"_d"+c+".dat"; (of[i]).open(outfilename.c_str() , ios::out | ios::app); } char c[5]; sprintf(c , "%d" , x); string filename = sub+"_d"+c+".dat"; ifstream infile(filename.c_str() , ios::in); string line; // get each list and update it into another database while(getline(infile , line)) { istringstream instring(line); vector<int> v; int x; while(instring >> x) v.push_back(x); if(v.size() == 1) continue; sort(v.begin() , v.end()); int head = v[v.size()-1]; for(int i = 0 ; i < v.size()-1 ; ++i) { (of[head]) << v[i] << ' '; } of[head] << endl; } for(int i = 0 ; i < x ; ++i) of[i].close(); infile.close(); // remove this database string command = "rm "+filename; system(command.c_str()); }
bool OSLCompilerImpl::preprocess_file (const std::string &filename, const std::string &stdoslpath, const std::vector<std::string> &defines, const std::vector<std::string> &includepaths, std::string &result) { // Read file contents into a string std::ifstream instream (filename.c_str()); if (! instream.is_open()) { error (ustring(filename), 0, "Could not open \"%s\"\n", filename.c_str()); return false; } instream.unsetf (std::ios::skipws); std::string instring (std::istreambuf_iterator<char>(instream.rdbuf()), std::istreambuf_iterator<char>()); instream.close (); return preprocess_buffer (instring, filename, stdoslpath, defines, includepaths, result); }
void Data::second_scan() { // scan the origin database again infile.open(is.c_str()); string line; while(getline(infile , line)) { istringstream instring(line); vector<int> v; int x; while(instring >> x) { if(item_to_ord[x] != -1) v.push_back(item_to_ord[x]); } // input the list into its related database sort(v.begin() , v.end()); if(!v.empty()) { // int head = v[v.size()-1]; store_data(valid_item_num , v); } } infile.close(); }
// extract type from file void extracter_t::find_type_infile(const char *tname1) { char *tname = new char [255]; strcpy(tname, nop(tname1)); // printf("%s\n",tname); //cout << tname; type_t *t = new type_t(UNDEF, tname, type); FILE *f = fopen(fname, "rt"); char *bf = new char [255]; strcpy(bf,""); int counter = 1; // printf("---%s %s\n", tname, bf); // class found lastspace(tname); while(1) { if (feof(f)) { fclose(f); return; } fgets(bf, 255, f); if (instring("class",bf)) { // printf("%s %s\n",tname ,bf); // printf("%d %d",strlen(tname) ,strlen(bf)); if (instring(tname, bf)) { // printf("match!!!!!!!!"); break; } } } if (feof(f)) { fclose(f); return; } fgets(bf, 255, f); fgets(bf, 255, f); fgets(bf, 255, f); char *bf1; while(!instring("};", bf)) { // get fields if (fieldthere(bf, &counter)) if (counter==1) { if (strlen(bf)==0) continue; // here field of tname bf1 = new char [255]; firstspace(bf); movestar(bf); if (!instring("char*",bf)) backstar(bf); sscanf(bf, "%s %s", bf1, bf); // cout << bf1 << " "; char *fname = new char[255]; tospace(';',bf); strcpy(fname, bf); t->addfield(bf1, fname); } fgets(bf, 255, f); if (feof(f)) { fclose(f); return; } } fclose(f); //cout << t->fields.size() << endl; type->push_back(t); for (int i = 0; i<t->fields.size(); i++) { // cout << t->fields[i] << " "; find_type(nop(t->fields[i]), t->fnames[i]); } }
void showFunction(HWND hwnd, EDITDATA *p, int ch) { sqlite3_int64 id, baseid; CCFUNCDATA *functionData = NULL; char name[2046], *q = name; int end = p->selstartcharpos; int pos = p->selstartcharpos - 1; POINT cpos; SIZE size; int curArg = 0; if (instring(p->cd->text, &p->cd->text[p->selstartcharpos])) return; p->cd->selecting = FALSE; if (pos <= 0 || PropGetInt(NULL, "CODE_COMPLETION") == 0) return ; if (ch == '(' || ch == ',' && !IsWindowVisible(hwndShowFunc)) { char name[512], *p1; int pos; int i; int commaCount = 0; DWINFO *info = (DWINFO *)GetWindowLong(GetParent(hwnd), 0); int lineno = SendMessage(hwnd, EM_EXLINEFROMCHAR, 0, p->selstartcharpos)+1; CCFUNCDATA * functionData = NULL; BOOL parsed = FALSE; CHARRANGE range; if (ch == ',') { int nesting =1 ; pos = p->selendcharpos-1; while (nesting > 0 && pos> 0 && p->cd->text[pos].ch != '{' && p->cd->text[pos].ch != '}') { if (p->cd->text[pos].ch == ')') nesting++; else if (p->cd->text[pos].ch == '(') nesting --; else if (p->cd->text[pos].ch == ',' && nesting == 1) commaCount++; pos--; } if (nesting) return; if (!pos || !isalnum(p->cd->text[pos-1].ch) && p->cd->text[pos-1].ch != '_') return; range.cpMin = pos; range.cpMax = pos; } else { range.cpMin = p->selendcharpos-1; range.cpMax = p->selendcharpos-1; } GetWordSpan(p, &range); if (range.cpMin == range.cpMax) return; pos = range.cpMin; while (pos && isspace(p->cd->text[pos-1].ch)) { pos--; } if (pos && p->cd->text[pos-1].ch == ':') { pos = CPPScanBackward(p, range.cpMax, TRUE); } else { pos = range.cpMin; } for (i=pos; i < range.cpMax; i++) name[i-pos] = p->cd->text[i].ch; name[i-pos] = 0; p1 = name; GetQualifiedName(name + i-pos + 1, &p1, FALSE, FALSE); strcpy(name, name +i-pos + 1); while (pos && isspace(p->cd->text[pos-1].ch)) { pos--; } if (pos && (p->cd->text[pos-1].ch == '.' || p->cd->text[pos-1].ch == '>')) { int start = 0; start = CPPScanBackward(p, p->selendcharpos, TRUE); if (start != pos) { char qual[2048]; for (i=start; i < pos; i++) qual[i-start] = p->cd->text[i].ch; qual[i-start] = 0; parsed = TRUE; sprintf(qual + strlen(qual), "@%s", name); functionData = ccLookupFunctionList(lineno, info->dwName, qual); } } if (!parsed) { CCFUNCDATA **scan; char funcbase[2048], nsbase[512], abase[512]; abase[0] = 0; GetContainerData(lineno, info->dwName, nsbase, funcbase); if (strrchr(name, '@') != name) { char *p = strrchr(name, '@'); strncpy(abase, name, p - name); abase[p-name] = 0; strcpy(name, p); *p = 0; } functionData = ccLookupFunctionList(lineno, info->dwName, name); if (!functionData) { name[0] = '_'; functionData = ccLookupFunctionList(lineno, info->dwName, name); name[0] = '@'; } scan = &functionData; while (*scan) { char nsbase2[2048]; if ((*scan)->args->member) { if (!funcbase[0] || strncmp(funcbase, (*scan)->fullname, strlen(funcbase))) { CCFUNCDATA *remove = *scan; *scan = (*scan)->next; remove->next = NULL; ccFreeFunctionList(remove); } else { scan = &(*scan)->next; } } else { char *last, *p ; int nesting = 0; p = last = (*scan)->fullname; while (*p) { switch(*p) { case '@': if (!nesting) last = p; break; case '#': nesting++; break; case '~': if (nesting) nesting--; break; } p++; } if (last != (*scan)->fullname && (strncmp((*scan)->fullname, funcbase, last - (*scan)->fullname) || funcbase[last - (*scan)->fullname] != '@' && funcbase[last - (*scan)->fullname] != 0)) { BOOL found = FALSE; char *p = nsbase; while (*p) { char *q = nsbase2; while (*p && *p != ';') *q++ = *p++; if (*p) p++; *q = 0; if (!strncmp((*scan)->fullname, nsbase2, last - (*scan)->fullname) &&( nsbase2[last - (*scan)->fullname] == '@' || nsbase2[last - (*scan)->fullname] == 0)) { found = TRUE; break; } } if (!found) { strcpy(nsbase2, abase); if (!strncmp((*scan)->fullname, nsbase2, last - (*scan)->fullname) && nsbase2[last - (*scan)->fullname] == 0) { found = TRUE; } } if (!found) { CCFUNCDATA *remove = *scan; *scan = (*scan)->next; remove->next = NULL; ccFreeFunctionList(remove); } else scan = &(*scan)->next; } else { BOOL found = abase[0] == '\0'; strcpy(nsbase2, abase); if (!strncmp((*scan)->fullname, nsbase2, last - (*scan)->fullname) && nsbase2[last - (*scan)->fullname] == 0) { found = TRUE; } if (!found) { CCFUNCDATA *remove = *scan; *scan = (*scan)->next; remove->next = NULL; ccFreeFunctionList(remove); } else { scan = &(*scan)->next; } } } } } if (functionData) { if (!hwndShowFunc) { hwndShowFunc = CreateWindowEx(0 | /*WS_EX_TOPMOST | WS_EX_LAYERED |*/ WS_EX_NOACTIVATE, "xccfuncclass", "", (WS_CHILD), CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndFrame, 0, GetModuleHandle(0), 0); // done this way to associate the popup with the application rather than the desktop SetWindowLong(hwndShowFunc, GWL_STYLE, (GetWindowLong(hwndShowFunc, GWL_STYLE) & ~WS_CHILD ) | WS_POPUP); } SendMessage(hwndShowFunc, WM_USER, 0, (LPARAM)functionData); SendMessage(hwndShowFunc, WM_USER+1, (WPARAM)hwnd, (LPARAM)p); SendMessage(hwndShowFunc, WM_USER+2, commaCount, 0); ShowWindow(hwndShowFunc, SW_SHOW); SetFocus(hwnd); } } }
Line * inlist(FILE *fp) { int c,i; char *s; Point p; Line *l=0; while (1) { c=fgetc(fp); switch (c) { case '\n': break; default: do c = fgetc(fp); while (c != '\n'); break; case 'w': case 'l': l = newline(inpoint(fp),l); l->Q = inpoint(fp); break; case 'b': l = newbox(inpoint(fp),l); l->Q = inpoint(fp); break; case 'd': l = newdots(inpoint(fp),l); l->Q = inpoint(fp); break; case 'z': l = newmacro(inpoint(fp),l); l->Q = inpoint(fp); break; case 's': s = instring(fp); i = inint(fp); p = inpoint(fp); if (*s != 0) { l = newstring(p,i,l); setstring((String *)l,s); } break; case 't': /* turn a jraw text into two graw strings */ s = instring(fp); i = jtog(inint(fp)); p = Pt(0,(showgrey ? GRID*2 : GRID)); l = newstring(p,i,l); setstring((String *)l,s); s = instring(fp); inint(fp); p = inpoint(fp); if (*s != 0) { /* gad, what a mess */ l = newstring(add(p,l->P),i,l); setstring((String *)l,s); l->next->P = p; } else /* watch carefully */ l->P = p; break; case 'r': l = newref(intern(instring(fp)),l); break; case 'i': s = intern(instring(fp)); l = newinst(inpoint(fp),s,l); break; case 'm': nest = 1; l = newmaster(intern(instring(fp)),l); ((Master *)l)->dl = inlist(fp); break; case 'e': if (nest == 0) dprint("found end of no macro\n"); nest = 0; case -1: return l; } } }
void method_t::gen_recv_method(FILE *out, char *fgclass) { // recv params for (int i = 0; i<params.size(); i++) { puttabs(tabs); type_t *curobj = type->at(0)->gettype(nop(params[i])); if (isp(params[i])) cout << params[i] << " " << names[i] << " = " \ << neg_func_by_type(nop(params[i]), fgclass) <<"(objrepr_recv(" << "ch, 1));\n"; else cout << params[i] << " *" << names[i] << " = " \ << neg_func_by_type(nop(params[i]), fgclass) <<"(objrepr_recv(" << "ch, 1));\n"; } puttabs(tabs); // call method if (!instring("void", ret)) { if (!retpointer && strcmp(ret, "char")) { cout << ret << " *ret = new " << ret << ";\n"; puttabs(tabs); cout << "*ret = obj->" << name << "("; } else { cout << ret << " *ret;\n"; puttabs(tabs); cout << "ret = obj->" << name << "("; } } else cout << "obj->" << name << "("; for (int i = 0; i<params.size(); i++) { if (isp(params[i])) cout << " " << nop(names[i]); else cout << " *" << nop(names[i]); if (i!=params.size()-1) cout << ","; } cout <<");\n"; puttabs(tabs); // !!!!!!!!!! TODO: clean memory for (int i = 0; i<params.size(); i++) if (isp(params[i])) { type_t *curobj = type->at(0)->gettype(nop(params[i])); if (curobj->vec) { } else {/* if (!strcmp(curobj->name, "char") || !strcmp(curobj->name, "char*")) { cout << "delete [] " << nop(names[i]) << ";\n"; }*/ } } //puttabs(tabs); // sendback ret cout << "objrepr_send(" << gen_func_by_type(ret, fgclass) << "(ret), ch, 1);\n"; /* puttabs(tabs); if (!strcmp(nop(ret), "char")) cout << "delete [] ret;\n"; else cout << "delete ret;\n";*/ }