drawingcollectiontype *load_drawing_collection( char *filename ){ int i,j,k; char *str; char *tok; char *tok_r; drawingcollectiontype *r; r = malloc(sizeof(drawingcollectiontype)); str = string_from_file( filename); r->num_drawings = read_number(str,&tok_r); r->drawing = malloc(sizeof(drawingtype) * r->num_drawings ); for ( i = 0; i < r->num_drawings; i++ ){ r->drawing[i].num_polys = read_number(NULL,&tok_r); r->drawing[i].poly = malloc(sizeof(polytype) * r->drawing[i].num_polys ); for ( j = 0; j < r->drawing[i].num_polys; j++ ){ r->drawing[i].poly[j].r = read_number(NULL,&tok_r); r->drawing[i].poly[j].g = read_number(NULL,&tok_r); r->drawing[i].poly[j].b= read_number(NULL,&tok_r); r->drawing[i].poly[j].a = read_number(NULL,&tok_r); r->drawing[i].poly[j].pts = read_number(NULL,&tok_r); r->drawing[i].poly[j].pt = malloc(sizeof(int) * r->drawing[i].poly[j].pts ); for ( k = 0; k < r->drawing[i].poly[j].pts; k++ ){ r->drawing[i].poly[j].pt[k] = read_number(NULL,&tok_r); } } } free(str); return r; }
int main() { char *txt=string_from_file("test.tcl"); bool err; struct parmac stk[2048],*p; struct tcl_parser tp; p=stk; tp.errMsg=NULL; tp.markStart=txt; tp.markEnd=txt; tp.pos=0; tp.row=0; tp.col=0; tcl_parser_main_machine(p,txt); while(parmac_run(&p,&tp,&err)) { } printf("\n"); if(err) { printf("Error.\n"); if(tp.errMsg!=NULL) { printf(tp.errMsg); } } printf("done %p.\n",p); return 0; }
int wc(char *docname){ char *doc = string_from_file(docname); if (!doc) return 0; char *delimiters = " `~!@#$%^&*()_-+={[]}|\\;:\",<>./?\n"; ok_array *words = ok_array_new(doc, delimiters); if (!words) return 0; double out= words->length; ok_array_free(words); return out; }
string Theme::post_template() { if (EMPTY_STR == _post_template) { bf::path post_temp_path = _path; post_temp_path.append("post.mustache"); if (isValid() && bf::is_regular_file(post_temp_path)) { _post_template = string_from_file(post_temp_path.string()); } } else { return _post_template; } return _post_template; }
void *wc(void *voidin){ wc_struct *in = voidin; char *doc = string_from_file(in->docname); if (!doc) return NULL; static GMutex count_lock; char *delimiters = " `~!@#$%^&*()_-+={[]}|\\;:\",<>./?\n\t"; ok_array *words = ok_array_new(doc, delimiters); if (!words) return NULL; in->wc = words->length; ok_array_free(words); g_mutex_lock(&count_lock); for (int i=0; i< in->wc; i++) global_wc++; //a slow global_wc += in->wc; g_mutex_unlock(&count_lock); return NULL; }
bool Post::load() { try { string load_str = string_from_file(_path.string()); stringstream ss(load_str); int nu = 0; string md; string line; boost::regex pattern("^\\+{3}\\s*"); boost::regex title_pattern("^title\\:"); boost::regex date_pattern("^date\\:"); boost::regex tag_pattern("^tags\\:"); boost::smatch what; while (getline(ss, line, '\n')) { if (nu > 1) { if (line != "") { md += line; md += '\n'; } } else if (boost::regex_match(line, pattern)) { nu += 1; } else if (boost::regex_search(line, what, title_pattern)) { string config = ba::erase_first_copy(line, what[0]); ba::trim(config); _title.reset(new string(config)); } else if (boost::regex_search(line, what, tag_pattern)) { string tags = ba::erase_first_copy(line, what[0]); ba::split(_tags, tags, ba::is_any_of(",")); for (auto &tag:_tags) { ba::trim(tag); } } else if (boost::regex_search(line, what, date_pattern)) { string date = ba::erase_first_copy(line, what[0]); ba::trim(date); _date = bg::from_simple_string(date); } } _content.reset(new string(md)); return true; } catch (IOException &ex) { return false; } }
int main(int argc, char *argv[]) { if (argc < 2) { puts("*** call like this: ./get_css_path ./script.mfl"); exit(1); } // set up embedded lua interpreter and run on script lua_State *L = get_lua(argv[1]); //// get css file as string char *csspath = get_css_path(argv[1]); char *css_str = string_from_file(csspath); free(csspath); char *key = "test.one"; char *tag = calloc(strlen(key), 1); strcat(tag, "["); strcat(tag, key); strcat(tag, "]"); char *cursor = strstr(css_str, tag); if( ! cursor ) { warn("[%s] not found", key); exit(1); } walk_lua_global(L, key); // attrs will be garbage is nothing found char *attrs = stack_index_as_css(L, -1, key, css_str, cursor); puts(attrs); return(0); }
int main() { char *sourcefilename = "mflib.lua"; char *outfilename = "mflib_lua.c"; char *libstr = string_from_file(sourcefilename); char *cursor = NULL; int advance = 0; //// escape quotes ////////////////////////////////////////////////////////// while ( (cursor = strchr(libstr + advance, '"')) ){ advance = cursor - libstr + 2; // how much to advance next search // make new string 1 char longer to accomodate '\\' int libstrbufflen = strlen(libstr) + 1; char *new = calloc(libstrbufflen + 1, 1); // make room for '\\' // copy chars up to cursor char *libstr_cursor = libstr; char *new_cursor = new; while ( libstr_cursor < cursor ) { *new_cursor++ = *libstr_cursor++; } *new_cursor++ = '\\'; *new_cursor++ = '"'; libstr_cursor++; // skip over found '"' // finish string while ( *libstr_cursor != '\0' ) { *new_cursor++ = *libstr_cursor++; } free(libstr); // free old string libstr = new; } ///////////////////////////////////////////////////////////////////////////// //// escape quotes ////////////////////////////////////////////////////////// advance = 0; while ( (cursor = strchr(libstr + advance, '\n')) ){ advance = cursor - libstr + 2; // how much to advance next search // make new string 1 char longer to accomodate '\\' int libstrbufflen = strlen(libstr) + 1; char *new = calloc(libstrbufflen + 1, 1); // make room for '\\' // copy chars up to cursor char *libstr_cursor = libstr; char *new_cursor = new; while ( libstr_cursor < cursor ) { *new_cursor++ = *libstr_cursor++; } *new_cursor++ = '\\'; *new_cursor++ = 'n'; libstr_cursor++; // skip over found '"' // finish string while ( *libstr_cursor != '\0' ) { *new_cursor++ = *libstr_cursor++; } free(libstr); // free old string libstr = new; } ///////////////////////////////////////////////////////////////////////////// printf("generating file %s using source %s\n", outfilename, sourcefilename); // wrap string in source file ////////////////////////////////////////////// FILE * pFile; pFile = fopen (outfilename, "w"); if ( pFile != NULL ) { fputs("// Generated by mflib_lua_to_source, DON'T EDIT\n\n", pFile); fputs("char *mflib_lua = \"", pFile); fputs(libstr, pFile); fputs("\";\n\n", pFile); fclose (pFile); } //////////////////////////////////////////////////////////////////////////// return(0); }
int main() { char *txt=string_from_file("test.tcl"); if (!txt) { return 1; } bool err; struct parmac *stk,*p; struct tcl_parser tp; char closings[256]; int stkNum=2048; stk=(struct parmac*)malloc(sizeof(struct parmac)*stkNum); p=stk; tp.errMsg=NULL; tp.markStart=txt; tp.markEnd=txt; tp.pos=0; tp.row=0; tp.col=0; tp.closingStart=closings; tp.closingEnd=endof(closings); tp.closingIt=NULL; tp.recurseDepth=-1; tp.buildStk=NULL; tp.rootStmt=NULL; // tcl_parser_main_machine(p,txt); // int c = 0; while(parmac_run(&p,&tp,&err)) { // c++; // if(p+1==stk+sizeof(struct parmac)*stkNum) { // stkNum*=2; // int n=(p-stk);///sizeof(struct parmac); // stk=(struct parmac*)realloc(stk,sizeof(struct parmac)*stkNum); // p=stk+n; // printf("%i %p %p\n",n,p,stk+n); // } } printf("\n"); if(err) { printf("Error.\n"); if(tp.errMsg!=NULL) { printf(tp.errMsg); } } // printSyntax(tp.rootStmt,0); printf("done %p.\n",p); #ifdef _MSC_VER system("pause"); #endif return 0; }
Part * GameSite::create(const Request& request) { return new Part("",string_from_file("src/web/content/index.html")); }