static PipeMemoryReader createPipeMemoryReader() { PipeMemoryReader Reader; if (pipe(Reader.to_child)) errorAndExit("Couldn't create pipes to child process"); if (pipe(Reader.from_child)) errorAndExit("Couldn't create pipes from child process"); return Reader; }
static void PipeMemoryReader_receiveReflectionInfo(SwiftReflectionContextRef RC, const PipeMemoryReader *Reader) { int WriteFD = PipeMemoryReader_getParentWriteFD(Reader); write(WriteFD, REQUEST_REFLECTION_INFO, 2); size_t NumReflectionInfos; PipeMemoryReader_collectBytesFromPipe(Reader, &NumReflectionInfos, sizeof(NumReflectionInfos)); if (NumReflectionInfos == 0) return; RemoteReflectionInfo *RemoteInfos = calloc(NumReflectionInfos, sizeof(RemoteReflectionInfo)); if (RemoteInfos == NULL) errorAndExit("malloc failed"); for (size_t i = 0; i < NumReflectionInfos; ++i) { RemoteInfos[i] = makeRemoteReflectionInfo( makeRemoteSection(Reader), makeRemoteSection(Reader), makeRemoteSection(Reader), makeRemoteSection(Reader), makeRemoteSection(Reader), makeRemoteSection(Reader)); } // Now pull in the remote sections into our address space. for (size_t i = 0; i < NumReflectionInfos; ++i) { RemoteReflectionInfo RemoteInfo = RemoteInfos[i]; void *Buffer = malloc(RemoteInfo.TotalSize); int Success = PipeMemoryReader_readBytes((void *)Reader, RemoteInfo.StartAddress, Buffer, RemoteInfo.TotalSize); if (!Success) errorAndExit("Couldn't read reflection information"); swift_reflection_info_t Info = { makeLocalSection(Buffer, RemoteInfo.fieldmd, RemoteInfo), makeLocalSection(Buffer, RemoteInfo.assocty, RemoteInfo), makeLocalSection(Buffer, RemoteInfo.builtin, RemoteInfo), makeLocalSection(Buffer, RemoteInfo.capture, RemoteInfo), makeLocalSection(Buffer, RemoteInfo.typeref, RemoteInfo), makeLocalSection(Buffer, RemoteInfo.reflstr, RemoteInfo), /*LocalStartAddress*/ (uintptr_t) Buffer, /*RemoteStartAddress*/ RemoteInfo.StartAddress, }; swift_reflection_addReflectionInfo(RC, Info); } free(RemoteInfos); }
int ScriptParser::forCommand() { last_nest_info->next = new NestInfo(); last_nest_info->next->previous = last_nest_info; last_nest_info = last_nest_info->next; last_nest_info->nest_mode = NestInfo::FOR; script_h.readVariable(); if ( script_h.current_variable.type != ScriptHandler::VAR_INT ) errorAndExit( "for: no integer variable." ); last_nest_info->var_no = script_h.current_variable.var_no; script_h.pushVariable(); if ( !script_h.compareString("=") ) errorAndExit( "for: missing '='" ); script_h.setCurrent(script_h.getNext() + 1); int from = script_h.readInt(); script_h.setInt( &script_h.pushed_variable, from ); if ( !script_h.compareString("to") ) errorAndExit( "for: missing 'to'" ); script_h.readLabel(); last_nest_info->to = script_h.readInt(); if ( script_h.compareString("step") ){ script_h.readLabel(); last_nest_info->step = script_h.readInt(); } else{ last_nest_info->step = 1; } if ((last_nest_info->step > 0 && from > last_nest_info->to) || (last_nest_info->step < 0 && from < last_nest_info->to)) break_flag = true; else break_flag = false; /* ---------------------------------------- */ /* Step forward callee's label info */ last_nest_info->next_script = script_h.getNext(); return RET_CONTINUE; }
const char *ScriptHandler::readStr() { end_status = END_NONE; current_variable.type = VAR_NONE; current_script = next_script; SKIP_SPACE( current_script ); char *buf = current_script; string_buffer[0] = '\0'; string_counter = 0; while(1){ parseStr(&buf); buf = checkComma(buf); string_counter += strlen(str_string_buffer); if (string_counter+1 >= STRING_BUFFER_LENGTH) errorAndExit("readStr: string length exceeds 2048 bytes."); strcat(string_buffer, str_string_buffer); if (buf[0] != '+') break; buf++; } next_script = buf; return string_buffer; }
void SeafileApplet::initLog() { if (applet_log_init(toCStr(configurator_->ccnetDir())) < 0) { errorAndExit(tr("Failed to initialize log: %s").arg(g_strerror(errno))); } else { // give a change to override DEBUG_LEVEL by environment QString debug_level = qgetenv("SEAFILE_CLIENT_DEBUG"); if (!debug_level.isEmpty() && debug_level != "false" && debug_level != "0") seafile_client_debug_level = DEBUG; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #define qInstallMsgHandler qInstallMessageHandler #endif if (seafile_client_debug_level == DEBUG) qInstallMsgHandler(myLogHandlerDebug); else qInstallMsgHandler(myLogHandler); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #undef qInstallMsgHandler #endif } }
int ScriptParser::returnCommand() { if ( !last_nest_info->previous || last_nest_info->nest_mode != NestInfo::LABEL ) errorAndExit( "return: not in gosub" ); current_label_info = script_h.getLabelByAddress( last_nest_info->next_script ); current_line = script_h.getLineByAddress( last_nest_info->next_script ); const char *label = script_h.readStr(); if (label[0] != '*') script_h.setCurrent( last_nest_info->next_script ); else setCurrentLabel( label+1 ); bool textgosub_flag = last_nest_info->textgosub_flag; char *wait_script = last_nest_info->wait_script; last_nest_info = last_nest_info->previous; delete last_nest_info->next; last_nest_info->next = NULL; if (textgosub_flag){ if (wait_script && label[0] != '*'){ script_h.setCurrent(wait_script); return RET_CONTINUE; } // if this is the end of the line, pretext becomes enabled line_enter_status = 0; page_enter_status = 0; } return RET_CONTINUE; }
void ScriptHandler::addStringBuffer( char ch ) { if (string_counter+1 == STRING_BUFFER_LENGTH) errorAndExit("addStringBuffer: string length exceeds 2048."); string_buffer[string_counter++] = ch; string_buffer[string_counter] = '\0'; }
int ScriptParser::roffCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "roff: not in the define section" ); rmode_flag = false; return RET_CONTINUE; }
/* * Internal buffer looks like this. * num[0] op[0] num[1] op[1] num[2] * If priority of op[0] is higher than op[1], (num[0] op[0] num[1]) is computed, * otherwise (num[1] op[1] num[2]) is computed. * Then, the next op and num is read from the script. * Num is an immediate value, a variable or a bracketed expression. */ void ScriptHandler::readNextOp(const char** buf, int* op, int* num) { bool minus_flag = false; SKIP_SPACE(*buf); const char* buf_start = *buf; if (op) { if ((*buf)[0] == '+') *op = OP_PLUS; else if ((*buf)[0] == '-') *op = OP_MINUS; else if ((*buf)[0] == '*') *op = OP_MULT; else if ((*buf)[0] == '/') *op = OP_DIV; else if ((*buf)[0] == 'm' && (*buf)[1] == 'o' && (*buf)[2] == 'd' && ((*buf)[3] == ' ' || (*buf)[3] == '\t' || (*buf)[3] == '$' || (*buf)[3] == '%' || (*buf)[3] == '?' || ((*buf)[3] >= '0' && (*buf)[3] <= '9'))) *op = OP_MOD; else { *op = OP_INVALID; return; } if (*op == OP_MOD) *buf += 3; else (*buf)++; SKIP_SPACE(*buf); } else { if ((*buf)[0] == '-') { minus_flag = true; (*buf)++; SKIP_SPACE(*buf); } } if ((*buf)[0] == '(') { (*buf)++; *num = parseIntExpression(buf); if (minus_flag) *num = -*num; SKIP_SPACE(*buf); if ((*buf)[0] != ')') errorAndExit(") is not found."); (*buf)++; } else { *num = parseInt(buf); if (minus_flag) *num = -*num; if (current_variable.type == VAR_NONE) { if (op) *op = OP_INVALID; *buf = buf_start; } } }
int ScriptParser::soundpressplginCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "soundpressplgin: not in the define section" ); const char *buf = script_h.readStr(); int buf_len = (int) strlen(buf); char buf2[1024]; if (buf_len + 1 > 1024) return RET_NOMATCH; strcpy(buf2, buf); // only nbzplgin.dll is supported for (int i=0 ; i<12 ; i++) if (buf2[i] >= 'A' && buf2[i] <= 'Z') buf2[i] += 'a' - 'A'; if (strncmp(buf2, "nbzplgin.dll", 12)){ fprintf( stderr, " *** plugin %s is not available, ignored. ***\n", buf); return RET_CONTINUE; } while(*buf && *buf != '|') buf++; if (*buf == 0) return RET_CONTINUE; buf++; script_h.cBR->registerCompressionType( buf, BaseReader::NBZ_COMPRESSION ); return RET_CONTINUE; }
int ScriptParser::mode_extCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "mode_ext: not in the define section" ); mode_ext_flag = true; return RET_CONTINUE; }
//-------------------------------------------------------------------------------------------------- void IncrementalBlueNoise::removeTriangle(Edge& edge) { Edge* e1 = getLeadingEdgeInTriangle(&edge); #ifdef DEBUG_HE if (e1 == NULL) errorAndExit("Triangulation::removeTriangle: could not find leading edge"); #endif removeLeadingEdgeFromList(e1); // cout << "No leading edges = " << leadingEdges_.size() << endl; // Remove the triangle Edge* e2 = e1->getNextEdgeInFace(); Edge* e3 = e2->getNextEdgeInFace(); if (e1->getTwinEdge()) e1->getTwinEdge()->setTwinEdge(NULL); if (e2->getTwinEdge()) e2->getTwinEdge()->setTwinEdge(NULL); if (e3->getTwinEdge()) e3->getTwinEdge()->setTwinEdge(NULL); delete e1; delete e2; delete e3; }
int ScriptParser::getparamCommand() { if ( !last_nest_info->previous || last_nest_info->nest_mode != NestInfo::LABEL ) errorAndExit( "getpapam: not in a subroutine" ); int end_status; do{ script_h.readVariable(); script_h.pushVariable(); script_h.pushCurrent(last_nest_info->next_script); if ( script_h.pushed_variable.type & ScriptHandler::VAR_PTR ){ script_h.readVariable(); script_h.setInt( &script_h.pushed_variable, script_h.current_variable.var_no ); } else if ( script_h.pushed_variable.type & ScriptHandler::VAR_INT || script_h.pushed_variable.type & ScriptHandler::VAR_ARRAY ){ script_h.setInt( &script_h.pushed_variable, script_h.readInt() ); } else if ( script_h.pushed_variable.type & ScriptHandler::VAR_STR ){ const char *buf = script_h.readStr(); setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, buf ); } end_status = script_h.getEndStatus(); last_nest_info->next_script = script_h.getNext(); script_h.popCurrent(); } while(end_status & ScriptHandler::END_COMMA); return RET_CONTINUE; }
//Mion int ScriptParser::setlayerCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( script_h.getStringBuffer(), "not in the define section" ); int no = script_h.readInt(); int interval = script_h.readInt(); const char *dll = script_h.readStr(); #ifndef NO_LAYER_EFFECTS Layer *handler = NULL; if (!strncmp(dll, "oldmovie.dll", 12)) { handler = new OldMovieLayer( screen_width, screen_height ); } else if (!strncmp(dll, "snow.dll", 8)) { handler = new FuruLayer( screen_width, screen_height, false, script_h.cBR ); } else if (!strncmp(dll, "hana.dll", 8)) { handler = new FuruLayer( screen_width, screen_height, true, script_h.cBR ); } else { printf("layer effect '%s' is not implemented.\n", dll); return RET_CONTINUE; } printf("Setup layer effect for '%s'.\n", dll); LayerInfo *layer = new LayerInfo(); layer->num = no; layer->interval = interval; layer->handler = handler; layer->next = layer_info; layer_info = layer; #endif // ndef NO_LAYER_EFFECTS return RET_CONTINUE; }
int ScriptParser::globalonCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "globalon: not in the define section" ); globalon_flag = true; return RET_CONTINUE; }
int ScriptParser::addCommand() { script_h.readVariable(); if ( script_h.current_variable.type == ScriptHandler::VAR_INT || script_h.current_variable.type == ScriptHandler::VAR_ARRAY ){ int val = script_h.getIntVariable( &script_h.current_variable ); script_h.pushVariable(); script_h.setInt( &script_h.pushed_variable, val+script_h.readInt() ); } else if ( script_h.current_variable.type == ScriptHandler::VAR_STR ){ int no = script_h.current_variable.var_no; const char *buf = script_h.readStr(); ScriptHandler::VariableData &vd = script_h.getVariableData(no); char *tmp_buffer = vd.str; if ( tmp_buffer ){ vd.str = new char[ strlen( tmp_buffer ) + strlen( buf ) + 1 ]; strcpy( vd.str, tmp_buffer ); strcat( vd.str, buf ); delete[] tmp_buffer; } else{ vd.str = new char[ strlen( buf ) + 1 ]; strcpy( vd.str, buf ); } } else errorAndExit( "add: no variable." ); return RET_CONTINUE; }
int ScriptParser::midCommand() { script_h.readStr(); if ( script_h.current_variable.type != ScriptHandler::VAR_STR ) errorAndExit( "mid: no string variable" ); int no = script_h.current_variable.var_no; script_h.readStr(); const char *save_buf = script_h.saveStringBuffer(); unsigned int start = script_h.readInt(); unsigned int len = script_h.readInt(); ScriptHandler::VariableData &vd = script_h.getVariableData(no); if ( vd.str ) delete[] vd.str; if ( start >= strlen(save_buf) ){ vd.str = NULL; } else{ if ( start+len > strlen(save_buf ) ) len = strlen(save_buf) - start; vd.str = new char[len+1]; memcpy( vd.str, save_buf+start, len ); vd.str[len] = '\0'; } return RET_CONTINUE; }
int ScriptParser::windowbackCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( script_h.getStringBuffer(), "not in the define section" ); windowback_flag = true; return RET_CONTINUE; }
int ScriptParser::nextCommand() { if (!last_nest_info->previous || last_nest_info->nest_mode != NestInfo::FOR) errorAndExit("next: not in for loop\n"); int val; if ( !break_flag ){ val = script_h.getVariableData(last_nest_info->var_no).num; script_h.setNumVariable( last_nest_info->var_no, val + last_nest_info->step ); } val = script_h.getVariableData(last_nest_info->var_no).num; if ( break_flag || ((last_nest_info->step > 0) && (val > last_nest_info->to)) || ((last_nest_info->step < 0) && (val < last_nest_info->to)) ){ break_flag = false; last_nest_info = last_nest_info->previous; delete last_nest_info->next; last_nest_info->next = NULL; } else{ script_h.setCurrent( last_nest_info->next_script ); current_label_info = script_h.getLabelByAddress( last_nest_info->next_script ); current_line = script_h.getLineByAddress( last_nest_info->next_script ); } return RET_CONTINUE; }
int ScriptParser::windowchipCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( script_h.getStringBuffer(), "not in the define section" ); windowchip_sprite_no = script_h.readInt(); return RET_CONTINUE; }
int ScriptParser::caseCommand() { if (!switch_flag) { // delete &script_h.switch_buf; return RET_SKIP_LINE; } if ( script_h.switch_buf.type == ScriptHandler::VAR_INT || script_h.switch_buf.type == ScriptHandler::VAR_ARRAY ){ int val = script_h.getIntVariable( &script_h.switch_buf ); int comp = script_h.readInt(); if ( val == comp ){ switch_flag = false; return RET_CONTINUE; } else return RET_SKIP_LINE; } else if ( script_h.switch_buf.type == ScriptHandler::VAR_STR ){ const char *val = script_h.getVariableData(script_h.switch_buf.var_no).str; const char *buf = script_h.readStr(); if (strcmp( val, buf )==0) { switch_flag = false; return RET_CONTINUE; } else return RET_SKIP_LINE; } errorAndExit("case : invailid case value."); return RET_CONTINUE; }
int ScriptParser::savedirCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "savedir: not in the define section" ); const char *buf = script_h.readStr(); // Only allow setting the savedir once, no empty path if ((*buf != '\0') && (!script_h.savedir)) { // Note that savedir is relative to save_path script_h.savedir = new char[ strlen(buf) + strlen(script_h.save_path) + 2]; sprintf( script_h.savedir, "%s%s%c", script_h.save_path, buf, DELIMITER ); /* // insert savedir onto the front of archive_path // The string returned by get_all_paths is deleted in ~DirPaths(), so the // simplest way to do this is to create the new object before deleting the // old one. DirPaths* new_paths = new DirPaths(script_h.savedir); new_paths->add(archive_path->get_all_paths()); delete archive_path; archive_path = new_paths; ((DirectReader*) script_h.cBR)->setArchivePath(archive_path); */ } return RET_CONTINUE; }
int ScriptParser::maxkaisoupageCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "maxkaisoupage: not in the define section" ); max_page_list = script_h.readInt()+1; return RET_CONTINUE; }
int ScriptParser::underlineCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "underline: not in the define section" ); underline_value = script_h.readInt() * screen_ratio1 / screen_ratio2; return RET_CONTINUE; }
int ScriptParser::labellogCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "labellog: not in the define section" ); labellog_flag = true; return RET_CONTINUE; }
int ScriptParser::loadgosubCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "loadgosub: not in the define section" ); setStr( &loadgosub_label, script_h.readStr()+1 ); return RET_CONTINUE; }
int ScriptParser::usewheelCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "usewheel: not in the define section" ); usewheel_flag = true; return RET_CONTINUE; }
void SeafileApplet::initLog() { if (applet_log_init(toCStr(configurator_->ccnetDir())) < 0) { errorAndExit(tr("Failed to initialize log")); } else { qInstallMsgHandler(myLogHandler); } }
int ScriptParser::clickskippageCommand() { if ( current_mode != DEFINE_MODE ) errorAndExit( "clickskippage: not in the define section" ); click_skip_page_flag = true; return RET_CONTINUE; }
int ScriptParser::shadedistanceCommand() { if (current_mode != DEFINE_MODE) errorAndExit( "shadedistance: not in the define section" ); shade_distance[0] = script_h.readInt(); shade_distance[1] = script_h.readInt(); return RET_CONTINUE; }