void readCommand(){ clearBuffer(); int pos = 0, line=((typeOffset/2)/VGA_W); //%VGA_H; clearLine(); updateCursor(typeOffset/2); key next; while(1){ if(key_queue_is_empty()) continue; next = remove_key(); /*printint(next.scancode); print(" "); continue;*/ if(next.scancode==75 && pos>0){pos--;} //left arrow if(next.scancode==77 && pos<bufferLength()-1){pos++;} //right arrow if(next.scancode==72) { lookupHistory(); pos=k_strlen(textBuffer); }//up arrow if(next.scancode==80) { lookdownHistory(); pos=k_strlen(textBuffer); }//down arrow if(next.key=='\n') { if(typeOffset>(VGA_H-1)*VGA_W*2) {scroll();typeOffset-=2*VGA_W;} typeOffset=(typeOffset+VGA_W*2)-(typeOffset/2)%VGA_W*2; return; }else if(next.key=='\b') {if(pos==0) continue; else charFromBuffer(pos--);} else if(next.key=='\t') { int num = splitString(textBuffer, ' '); int i; for(i =0;i<num;i++){argv[i]=stringArray[i];} char *ac = autoComp(argv[i-1]); while(*ac!=0) {charToBuffer(*ac,pos++); ac++;} }else if(next.key!=0) {if(pos>(BUFFERSIZE)/2-4) continue; else charToBuffer(next.key, pos++);} if(line==VGA_H-1 && bufferLength()>=VGA_W){scroll();line--;} typeOffset = line*VGA_W*2; typePrompt(); int save = typeOffset; print(textBuffer); clearLine(); typeOffset = save+pos*2; updateCursor(typeOffset/2); } }
nsresult SaveProfileTask::Run() { // Get file path #if defined(SPS_PLAT_arm_android) && !defined(MOZ_WIDGET_GONK) nsCString tmpPath; tmpPath.AppendPrintf("/sdcard/profile_%i_%i.txt", XRE_GetProcessType(), getpid()); #else nsCOMPtr<nsIFile> tmpFile; nsAutoCString tmpPath; if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)))) { LOG("Failed to find temporary directory."); return NS_ERROR_FAILURE; } tmpPath.AppendPrintf("profile_%i_%i.txt", XRE_GetProcessType(), getpid()); nsresult rv = tmpFile->AppendNative(tmpPath); if (NS_FAILED(rv)) return rv; rv = tmpFile->GetNativePath(tmpPath); if (NS_FAILED(rv)) return rv; #endif // Create a JSContext to run a JSObjectBuilder :( // Based on XPCShellEnvironment JSRuntime *rt; JSContext *cx; nsCOMPtr<nsIJSRuntimeService> rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1"); if (!rtsvc || NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) { LOG("failed to get RuntimeService"); return NS_ERROR_FAILURE;; } cx = JS_NewContext(rt, 8192); if (!cx) { LOG("Failed to get context"); return NS_ERROR_FAILURE; } { JSAutoRequest ar(cx); static const JSClass c = { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub }; JSObject *obj = JS_NewGlobalObject(cx, &c, nullptr, JS::FireOnNewGlobalHook); std::ofstream stream; stream.open(tmpPath.get()); if (stream.is_open()) { JSAutoCompartment autoComp(cx, obj); JSObject* profileObj = profiler_get_profile_jsobject(cx); JS::Rooted<JS::Value> val(cx, OBJECT_TO_JSVAL(profileObj)); JS_Stringify(cx, &val, JS::NullPtr(), JS::NullHandleValue, WriteCallback, &stream); stream.close(); LOGF("Saved to %s", tmpPath.get()); } else { LOG("Fail to open profile log file."); } } JS_DestroyContext(cx); return NS_OK; }