/* Execute a javascript file */ static Handle<Value> msV8ExecuteScript(const char *path, int throw_exception = MS_FALSE) { char fullpath[MS_MAXPATHLEN]; map<string, Persistent<Script> >::iterator it; Isolate *isolate = Isolate::GetCurrent(); V8Context *v8context = (V8Context*)isolate->GetData(); /* construct the path */ msBuildPath(fullpath, v8context->paths.top().c_str(), path); char *filepath = msGetPath((char*)fullpath); v8context->paths.push(filepath); free(filepath); Handle<Script> script; it = v8context->scripts.find(fullpath); if (it == v8context->scripts.end()) { Handle<Value> source = msV8ReadFile(v8context, fullpath); Handle<String> script_name = String::New(msStripPath((char*)path)); script = msV8CompileScript(source->ToString(), script_name); if (script.IsEmpty()) { v8context->paths.pop(); if (throw_exception) { return ThrowException(String::New("Error compiling script")); } } /* cache the compiled script */ Persistent<Script> pscript; pscript.Reset(isolate, script); v8context->scripts[fullpath] = pscript; } else { script = v8context->scripts[fullpath]; } Handle<Value> result = msV8RunScript(script); v8context->paths.pop(); if (result.IsEmpty() && throw_exception) { return ThrowException(String::New("Error running script")); } return result; }
int msLoadFontSet(fontSetObj *fontset, mapObj *map) { FILE *stream; char buffer[MS_BUFFER_LENGTH]; char alias[64], file1[MS_PATH_LENGTH], file2[MS_PATH_LENGTH]; char *path; char szPath[MS_MAXPATHLEN]; int i; int bFullPath = 0; if(fontset->numfonts != 0) /* already initialized */ return(0); if(!fontset->filename) return(0); fontset->map = (mapObj *)map; path = msGetPath(fontset->filename); /* fontset->fonts = msCreateHashTable(); // create font hash */ /* if(!fontset->fonts) { */ /* msSetError(MS_HASHERR, "Error initializing font hash.", "msLoadFontSet()"); */ /* return(-1); */ /* } */ stream = fopen( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "r"); if(!stream) { msSetError(MS_IOERR, "Error opening fontset %s.", "msLoadFontset()", fontset->filename); return(-1); } i = 0; while(fgets(buffer, MS_BUFFER_LENGTH, stream)) { /* while there's something to load */ if(buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '\r' || buffer[0] == ' ') continue; /* skip comments and blank lines */ sscanf(buffer,"%s %s", alias, file1); if (!(*file1) || !(*alias) || (strlen(file1) <= 0)) continue; bFullPath = 0; #if defined(_WIN32) && !defined(__CYGWIN__) if (file1[0] == '\\' || (strlen(file1) > 1 && (file1[1] == ':'))) bFullPath = 1; #else if(file1[0] == '/') bFullPath = 1; #endif if(bFullPath) { /* already full path */ msInsertHashTable(&(fontset->fonts), alias, file1); } else { snprintf(file2, sizeof(file2), "%s%s", path, file1); /* msInsertHashTable(fontset->fonts, alias, file2); */ /* ** msBuildPath is use here, but if we have to save the fontset file ** the msBuildPath must be done everywhere the fonts are used and ** removed here. */ msInsertHashTable(&(fontset->fonts), alias, msBuildPath(szPath, fontset->map->mappath, file2)); } i++; } fontset->numfonts = i; fclose(stream); /* close the file */ free(path); return(0); }
int loadSymbolSet(symbolSetObj *symbolset, mapObj *map) { int status=1; char szPath[MS_MAXPATHLEN], *pszSymbolPath=NULL; int foundSymbolSetToken=MS_FALSE; int token; if(!symbolset) { msSetError(MS_SYMERR, "Symbol structure unallocated.", "loadSymbolSet()"); return(-1); } symbolset->map = (mapObj *)map; if(!symbolset->filename) return(0); /* ** Open the file */ if((msyyin = fopen(msBuildPath(szPath, symbolset->map->mappath, symbolset->filename), "r")) == NULL) { msSetError(MS_IOERR, "(%s)", "loadSymbolSet()", symbolset->filename); return(-1); } pszSymbolPath = msGetPath(szPath); msyystate = MS_TOKENIZE_FILE; /* restore lexer state to INITIAL, and do return comments */ msyylex(); /* sets things up, but doesn't process any tokens */ msyylineno = 0; /* reset line counter */ msyyrestart(msyyin); /* flush the scanner - there's a better way but this works for now */ /* ** Read the symbol file */ for(;;) { token = msyylex(); if(!foundSymbolSetToken && token != SYMBOLSET) { msSetError(MS_IDENTERR, "First token must be SYMBOLSET, this doesn't look like a symbol file.", "msLoadSymbolSet()"); return(-1); } switch(token) { case(END): case(EOF): status = 0; break; case(SYMBOL): /* Allocate/init memory for new symbol if needed */ if (msGrowSymbolSet(symbolset) == NULL) { status = -1; } else if((loadSymbol((symbolset->symbol[symbolset->numsymbols]), pszSymbolPath) == -1)) status = -1; else symbolset->numsymbols++; break; case(SYMBOLSET): foundSymbolSetToken = MS_TRUE; break; default: msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadSymbolSet()", msyystring_buffer, msyylineno); status = -1; } /* end switch */ if(status != 1) break; } /* end for */ fclose(msyyin); msyyin = NULL; free(pszSymbolPath); return(status); }