int System::getEnumCount() { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_getfield(L,FXUSERENUMS,"count"); assert( lua_isnumber(L,-1) ); return (int)lua_tointeger(L,-1); }
int System::getEffectCount( EffectType effecttype ) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_rawgeti(L,FXBUILDER, effecttype); lua_getfield(L,-1,"count"); int count = (int)lua_tointeger(L,-1); return count; }
void TwoQStrategy::preserve(uint64_t id) { lockPreserved(); if (_preserved[id]) { pthread_cond_wait(&_preserved_changed, &_preserved_mutex); unlockPreserved(); preserve(id); return; } _preserved[id] = true; unlockPreserved(); }
error System::addLibrary(const char* funcname, const char* buffer, size_t buffersize) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_getglobal(L,funcname); lua_pushlstring(L,buffer,buffersize); if (lua_pcall(L,1,0,FXERROR)){ updateError(); return true; } return false; }
static void dump_content(saxctxt *ctx) { urlmap *m; char *found; size_t s_from, s_to; size_t match; char c = 0; int nmatch; ap_regmatch_t pmatch[10]; char *subs; size_t len, offs; urlmap *themap = ctx->map; #ifndef GO_FASTER int verbose = APLOGrtrace1(ctx->f->r); #endif pappend(ctx, &c, 1); /* append null byte */ /* parse the text for URLs */ for (m = themap; m; m = m->next) { if (!(m->flags & M_CDATA)) continue; if (m->flags & M_REGEX) { nmatch = 10; offs = 0; while (!ap_regexec(m->from.r, ctx->buf+offs, nmatch, pmatch, 0)) { match = pmatch[0].rm_so; s_from = pmatch[0].rm_eo - match; subs = ap_pregsub(ctx->f->r->pool, m->to, ctx->buf+offs, nmatch, pmatch); s_to = strlen(subs); len = strlen(ctx->buf); offs += match; VERBOSEB( const char *f = apr_pstrndup(ctx->f->r->pool, ctx->buf + offs, s_from); ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, ctx->f->r, "C/RX: match at %s, substituting %s", f, subs); ) if (s_to > s_from) { preserve(ctx, s_to - s_from); memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from, len + 1 - s_from - offs); memcpy(ctx->buf+offs, subs, s_to); } else { memcpy(ctx->buf + offs, subs, s_to); memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from, len + 1 - s_from - offs); } offs += s_to; } }
EffectID System::getEffect( EffectType effecttype, int i ) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_rawgeti (L,FXBUILDER, effecttype); lua_getfield(L,-1,"effects"); lua_rawgeti (L,-1,i + 1); assert(lua_istable(L,-1) && "illegal index"); EffectID id = (EffectID)getID(); return id; }
void step() { old_logp_value_ = logp_value_; preserve(); jump(); update(); logp_value_ = logp(); if(reject(logp_value_, old_logp_value_)) { revert(); logp_value_ = old_logp_value_; rejected_ += 1; } else { accepted_ += 1; } }
void PoeditListCtrl::Sort() { if ( m_catalog && m_catalog->GetCount() ) { SelectionPreserver preserve(this); CreateSortMap(); RefreshItems(0, m_catalog->GetCount()-1); } else { Refresh(); } }
EnumID System::getEnum( const char* name ) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_getfield(L,FXUSERENUMS,"enums"); lua_getfield(L,-1,name); if (!lua_istable(L,-1)){ return 0; } EnumID id = (EnumID)getID(); return id; }
/* * When a hangup occurs our actions are similar to a preserve * command. If the buffer has not been [Modified], then we do * nothing but remove the temporary files and exit. * Otherwise, we sync the temp file and then attempt a preserve. * If the preserve succeeds, we unlink our temp files. * If the preserve fails, we leave the temp files as they are * as they are a backup even without preservation if they * are not removed. */ void onhup(int i) { (void)i; if (chng == 0) { cleanup(1); exit(0); } if (setexit() == 0) { if (preserve()) { cleanup(1); exit(0); } } exit(1); }
EffectID System::getEffect( EffectType effecttype, const char* name ) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_rawgeti (L,FXBUILDER, effecttype ); lua_getfield(L,-1,"effects"); lua_getfield(L,-1,name); if (!lua_istable(L,-1)){ return 0; } EffectID id = (EffectID)getID(); return id; }
EnumID System::getEnum( int i ) { LuaState L = m_luaState; LuaStatePreserve preserve(L); lua_getfield(L,FXUSERENUMS,"enums"); lua_rawgeti(L,-1,i+1); if (!lua_istable(L,-1)){ return 0; } LuaStateCheck(L); EnumID id = (EnumID)getID(); return id; }
/* * When a hangup occurs our actions are similar to a preserve * command. If the buffer has not been [Modified], then we do * nothing but remove the temporary files and exit. * Otherwise, we sync the temp file and then attempt a preserve. * If the preserve succeeds, we unlink our temp files. * If the preserve fails, we leave the temp files as they are * as they are a backup even without preservation if they * are not removed. */ void onhup(int i) { (void)i; /* * USG tty driver can send multiple HUP's!! */ signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); if (chng == 0) { cleanup(1); ex_exit(0); } if (setexit() == 0) { if (preserve()) { cleanup(1); ex_exit(0); } } ex_exit(1); }
void PoeditListCtrl::CatalogChanged(const CatalogPtr& catalog) { wxWindowUpdateLocker no_updates(this); const bool isSameCatalog = (catalog == m_catalog); const bool sizeChanged = (catalog && (int)catalog->GetCount() != GetItemCount()); SelectionPreserver preserve(isSameCatalog ? this : nullptr); // this is to prevent crashes (wxMac at least) when shortening virtual // listctrl when its scrolled to the bottom: if (sizeChanged) { m_catalog.reset(); SetItemCount(0); } // now read the new catalog: m_catalog = catalog; CreateColumns(); ReadCatalog(/*resetSizeAndSelection=*/sizeChanged); }
/* ** 'clear_program' is called when a 'NEW' command is issued to clear the old ** program from memory. The start of an existing program is preserved in ** 'oldstart' in case 'OLD' is used so that the old program can be restored ** to health */ void clear_program(void) { clear_varlists(); clear_strings(); clear_heap(); basicvars.start = basicvars.top = basicvars.page+MARKERSIZE; memmove(basicvars.page, startmark, STARTMARKSIZE); preserve(); /* Preserve the start of program in memory (if any) */ mark_end(basicvars.top); basicvars.lomem = basicvars.vartop = basicvars.top+ENDMARKSIZE; basicvars.stacklimit.bytesp = basicvars.top+STACKBUFFER; basicvars.stacktop.bytesp = basicvars.himem; basicvars.lastsearch = basicvars.start; basicvars.procstack = NIL; basicvars.liblist = NIL; basicvars.error_line = 0; basicvars.error_number = 0; basicvars.error_handler.current = NIL; basicvars.escape = FALSE; basicvars.misc_flags.badprogram = FALSE; basicvars.runflags.running = FALSE; basicvars.runflags.has_offsets = FALSE; basicvars.runflags.has_variables = FALSE; basicvars.runflags.closefiles = TRUE; basicvars.runflags.make_array = FALSE; basicvars.tracehandle = 0; basicvars.traces.lines = FALSE; basicvars.traces.pause = FALSE; basicvars.traces.procs = FALSE; basicvars.traces.branches = FALSE; basicvars.traces.backtrace = TRUE; basicvars.staticvars[ATPERCENT].varentry.varinteger = STDFORMAT; basicvars.curcount = 0; basicvars.printcount = 0; basicvars.printwidth = DEFWIDTH; basicvars.program[0] = NUL; basicvars.linecount = 0; last_added = NIL; init_stack(); }
void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { if (!m_pData) return; if (nNewLength == -1) nNewLength = FXSYS_strlen(m_pData->m_String); nNewLength = std::min(nNewLength, m_pData->m_nAllocLength); if (nNewLength == 0) { clear(); return; } ASSERT(m_pData->m_nRefs == 1); m_pData->m_nDataLength = nNewLength; m_pData->m_String[nNewLength] = 0; if (m_pData->m_nAllocLength - nNewLength >= 32) { // Over arbitrary threshold, so pay the price to relocate. Force copy to // always occur by holding a second reference to the string. CFX_ByteString preserve(*this); ReallocBeforeWrite(nNewLength); } }
// p0 is the beginning of the operation's def // p point to ${body} // indent is the one of the operation const char * UmlOperation::generate_body(QTextStream & f, WrapperStr indent, const char * p) { if(isAbstract()) return p + 7; const char * body = 0; WrapperStr modeler_body; bool no_indent; char s_id[9]; if (preserve() && !isBodyGenerationForced()) { unsigned id = get_id(); sprintf(s_id, "%08X", id); body = bodies.find((long) id); } if (body == 0) { no_indent = !javaContextualBodyIndent(); modeler_body = javaBody(); // to not free the string body = modeler_body; } else // body from file, respect its indent no_indent = TRUE; // get keyword indent WrapperStr bindent = indent; while (*p != '$') bindent += *p++; if (preserve() && !isBodyGenerationForced()) f << bindent << BodyPrefix << s_id << '\n'; if ((body != 0) && (*body != 0)) { // output body if (bindent.isEmpty() || no_indent) { f << body; body += strlen(body); } else { f << bindent; while (*body) { f << *body; if (*body++ == '\n') { if (*body == 0) break; f << bindent; } } } if (body[-1] != '\n') f << '\n'; } if (preserve() && !isBodyGenerationForced()) f << bindent << BodyPostfix << s_id << '\n'; f << indent; // for the } return p + 7; }
double LayerNet::direcmin ( TrainingSet *tptr , // Training set to use double start_err , // Error (function value) at starting coefficients int itmax , // Upper limit on number of iterations allowed double eps , // Small, but greater than machine precision double tol , // Brent's tolerance (>= sqrt machine precision) double *base , // Work area (stepping out point) double *direc ) // Work area (stepping out direction) { int key, user_quit, iter ; double step, x1, x2, x3, t1, t2, numer, denom, max_step ; double xlow, xhigh, xbest, testdist ; double current_err, err, previous_err, step_err ; double prevdist, etemp, frecent, fthirdbest, fsecbest, fbest ; double tol1, tol2, xrecent, xthirdbest, xsecbest, xmid; double first_step = 2.5 ; // Heuristically found best user_quit = 0 ; /* Take one step out in the gradient direction. First preserve original weights for use as departure point parameterized by STEP. */ preserve ( base ) ; // Establishes a base for stepping out step_out ( first_step , direc , base ) ; err = trial_error ( tptr ) ; /* If it increased, we had numerical problems computing the direction or the direction itself is too large a step. Negate the direction and use -1, 0 and 1.618 as first three steps. Otherwise use 0, 1 and 2.618 as first three steps. */ if (err > start_err) { negate_dir ( direc ) ; x1 = -first_step ; x2 = 0. ; previous_err = err ; current_err = start_err ; } else { x1 = 0. ; x2 = first_step ; previous_err = start_err ; current_err = err ; } /* At this point we have taken a single step and the function decreased. Take one more step in the golden ratio. Also keep errors lined up as 'previous_err', 'current_err' and 'err'. The corresponding abscissae will be x1, x2 and x3. */ /************************************************************************ if (kbhit()) { // Was a key pressed? key = getch () ; // Read it if so while (kbhit()) // Flush key buffer in case function key getch () ; // or key was held down if (key == 27) // ESCape return (- err) ; } ***********************************************************************/ x3 = x2 + 1.618034 * first_step ; step_out ( x3 , direc , base ) ; err = trial_error ( tptr ) ; /* We now have three points x1, x2 and x3 with corresponding errors of 'previous_err', 'current_err' and 'err'. Endlessly loop until we bracket the minimum with the outer two. */ while (err < current_err) { // As long as we are descending... /********************************************************************* if (kbhit()) { // Was a key pressed? key = getch () ; // Read it if so while (kbhit()) // Flush key buffer in case function key getch () ; // or key was held down if (key == 27) { // ESCape user_quit = 1 ; break ; } } ********************************************************************/ /* Try a parabolic fit to estimate the location of the minimum. */ t1 = (x2 - x1) * (current_err - err) ; t2 = (x2 - x3) * (current_err - previous_err) ; denom = 2. * ( t2 - t1 ) ; if (fabs ( denom ) < eps) { if (denom > 0.) denom = eps ; else denom = -eps ; } step = x2 + ((x2 - x1) * t1 - (x2 - x3) * t2) / denom ;//Here if perfect max_step = x2 + 200. * (x3 - x2) ; // Don't jump too far if ((x2 - step) * (step - x3) > 0.) { // It's between x2 and x3 step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; if (step_err < err) { // It worked! We found min between b and c. x1 = x2 ; x2 = step ; previous_err = current_err ; current_err = step_err ; goto BOUNDED ; } else if (step_err > current_err) { // Slight miscalc. Min at x2. x3 = step ; err = step_err ; goto BOUNDED ; } else { // Parabolic fit was total waste. Use default. step = x3 + 1.618034 * (x3 - x2) ; step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; } } else if ((x3 - step) * (step - max_step) > 0.0) { // Between x3 and lim step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; if (step_err < err) { // Decreased, so advance by golden ratio x2 = x3 ; x3 = step ; step = x3 + 1.618034 * (x3 - x2) ; current_err = err ; err = step_err ; step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; } } else if ((step - max_step) * (max_step - x3) >= 0.) { // Beyond limit step = max_step ; step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; if (step_err < err) { // Decreased, so advance by golden ratio x2 = x3 ; x3 = step ; step = x3 + 1.618034 * (x3 - x2) ; current_err = err ; err = step_err ; step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; } } else { // Wild! Reject parabolic and use golden ratio. step = x3 + 1.618034 * (x3 - x2) ; step_out ( step , direc , base ) ; step_err = trial_error ( tptr ) ; } /* Shift three points and continue endless loop */ x1 = x2 ; x2 = x3 ; x3 = step ; previous_err = current_err ; current_err = err ; err = step_err ; } // Endless stepping out loop BOUNDED: step_out ( x2 , direc , base);//Leave coefs at min if (x1 > x3) { // We may have switched direction at start. t1 = x1 ; // Brent's method which follows assumes ordered parameter. x1 = x3 ; x3 = t1 ; } if (user_quit) { update_dir ( x2 , direc ) ;// Make it be the actual dist moved return -current_err ; } /* -------------------------------------------------------------------------------- At this point we have bounded the minimum between x1 and x3. Go to the refinement stage. We use Brent's algorithm. -------------------------------------------------------------------------------- */ /* Initialize prevdist, the distance moved on the previous step, to 0 so that the 'if (fabs ( prevdist ) > tol1)' encountered on the first iteration below will fail, forcing a golden section the first time. Also initialize step to 0 to avoid a zealous compiler from pointing out that it was referenced before being set. */ prevdist = step = 0.0 ; /* We always keep the minimum bracketed between xlow and xhigh. xbest has the min function so far (or latest if tie). xsecbest and xthirdbest are the second and third best. */ xbest = xsecbest = xthirdbest = x2 ; xlow = x1 ; xhigh = x3 ; fbest = fsecbest = fthirdbest = current_err ; /* Main loop. For safety we impose a limit on iterations. */ for (iter=0 ; iter<itmax ; iter++) { xmid = 0.5 * (xlow + xhigh) ; tol1 = tol * (fabs ( xbest ) + eps) ; tol2 = 2. * tol1 ; /*************************************************************************** if (kbhit()) { // Was a key pressed? key = getch () ; // Read it if so while (kbhit()) // Flush key buffer in case function key getch () ; // or key was held down if (key == 27) { // ESCape user_quit = 1 ; break ; } } **************************************************************************/ /* The following convergence test simultaneously makes sure xhigh and xlow are close relative to tol2, and that xbest is near the midpoint. */ if (fabs ( xbest - xmid ) <= (tol2 - 0.5 * (xhigh - xlow))) break ; if (fabs ( prevdist ) > tol1) { // If we moved far enough try parabolic fit t1 = (xbest - xsecbest) * (fbest - fthirdbest) ; // Temps for the t2 = (xbest - xthirdbest) * (fbest - fsecbest) ; // parabolic estimate numer = (xbest - xthirdbest) * t2 - (xbest - xsecbest) * t1 ; denom = 2. * (t1 - t2) ; // Estimate will be numer / denom testdist = prevdist ; // Will soon verify interval is shrinking prevdist = step ; // Save for next iteration if (denom != 0.0) // Avoid dividing by zero step = numer / denom ; // This is the parabolic estimate to min else step = 1.e30 ; // Assures failure of next test if ((fabs ( step ) < fabs ( 0.5 * testdist ))// If shrinking && (step + xbest > xlow) // and within known bounds && (step + xbest < xhigh)) { // then we can use the xrecent = xbest + step ; // parabolic estimate if ((xrecent - xlow < tol2) || // If we are very close (xhigh - xrecent < tol2)) { // to known bounds if (xbest < xmid) // then stabilize step = tol1 ; else step = -tol1 ; } } else { // Parabolic estimate poor, so use golden section prevdist = (xbest >= xmid) ? xlow - xbest : xhigh - xbest ; // Poor so use step = .3819660 * prevdist ; } } else { // prevdist did not exceed tol1: we did not move far enough // to justify a parabolic fit. Use golden section. prevdist = (xbest >= xmid) ? xlow - xbest : xhigh - xbest ; step = .3819660 * prevdist ; } if (fabs (step) >= tol1) // In order to numerically justify xrecent = xbest + step ; // another trial we must move a else { // decent distance. if (step > 0.) xrecent = xbest + tol1 ; else xrecent = xbest - tol1 ; } /* At long last we have a trial point 'xrecent'. Evaluate the function. */ step_out ( xrecent , direc , base ) ; frecent = trial_error ( tptr ) ; if (frecent <= fbest) { // If we improved... if (xrecent >= xbest) // Shrink the (xlow,xhigh) interval by xlow = xbest ; // replacing the appropriate endpoint else xhigh = xbest ; xthirdbest = xsecbest ; // Update x and f values for best, xsecbest = xbest ; // second and third best xbest = xrecent ; fthirdbest = fsecbest ; fsecbest = fbest ; fbest = frecent ; } else { // We did not improve if (xrecent < xbest) // Shrink the (xlow,xhigh) interval by xlow = xrecent ; // replacing the appropriate endpoint else xhigh = xrecent ; if ((frecent <= fsecbest) // If we at least beat the second best || (xsecbest == xbest)) { // or we had a duplication xthirdbest = xsecbest ; // we can update the second and third xsecbest = xrecent ; // best, though not the best. fthirdbest = fsecbest ; // Recall that we started iters with fsecbest = frecent ; // best, sec and third all equal. } else if ((frecent <= fthirdbest) // Oh well. Maybe at least we can || (xthirdbest == xbest) // beat the third best or rid || (xthirdbest == xsecbest)) { // ourselves of a duplication xthirdbest = xrecent ; // (which is how we start the fthirdbest = frecent ; // iterations) } } } step_out ( xbest , direc , base );//Leave coefs at min update_dir ( xbest , direc ) ;// Make it be the actual distance moved if (user_quit) return -fbest ; else return fbest ; }
// p point to ${body} const char * UmlOperation::generate_body(QTextStream & f, WrapperStr indent, BooL & indent_needed, const char * p) { if(isAbstract()) return p + 7; const char * body = 0; WrapperStr modeler_body; WrapperStr body_indent; char s_id[9]; if (preserve() && !isBodyGenerationForced()) { unsigned id = get_id(); sprintf(s_id, "%08X", id); body = bodies.value((long) id); } if (body == 0) { modeler_body = pythonBody(); // to not free the string body = modeler_body; if (pythonContextualBodyIndent()) body_indent = indent; } if (name() == "__init__") { const QList<UmlParameter> & params = this->params(); if (params.count() != 0) ((UmlClass *) parent())->generate_instance_att_rel(f, indent, indent_needed, params[0].name + "."); else { WrapperStr err = " <font color=\"red\"><b><i>" + parent()->name() + ".__init__()</i> doesn't have parameter, instance variables not generated </b></font><br>"; write_trace_header(); UmlCom::trace(err); incr_warning(); } } if (preserve() && !isBodyGenerationForced()) { if (indent_needed) f << indent; f << BodyPrefix << s_id << '\n' << body_indent; } else if (indent_needed) f << body_indent; if ((body != 0) && (*body != 0)) { // output body while (*body) { f << *body; if (*body++ == '\n') { if (*body == 0) break; f << body_indent; } } if (body[-1] != '\n') f << '\n'; } else f << "pass\n"; if (preserve() && !isBodyGenerationForced()) f << indent << BodyPostfix << s_id << '\n'; indent_needed = TRUE; return p + 7; }
void UmlArtifact::generate() { if (! managed) { managed = TRUE; if (stereotype() == "text") { generate_text(); return; } else if (stereotype() != "source") return; package_of_generated_artifact = package(); current = this; const WrapperStr filedef = pythonSource(); if (filedef.isEmpty()) return; const WrapperStr & name = this->name(); WrapperStr path = package_of_generated_artifact->file_path(name); UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); // get bodies if preserve const QVector<UmlClass*> & cls = associatedClasses(); if (preserve()) UmlOperation::read_bodies(path); // generate file WrapperStr indent; BooL indent_needed; unsigned n = cls.count(); unsigned index; QByteArray file; // note : QTextStream(FILE *) does not work under windows QTextStream f(&file); const char * p = filedef; const char * pp = 0; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; } if (*p == '@') { indent_needed = FALSE; manage_alias(p, f, indent, indent_needed); } else if (*p != '$') f << *p++; else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${name}", 7)) { p += 7; f << name; } else if (!strncmp(p, "${Name}", 7)) { p += 7; f << capitalize(name); } else if (!strncmp(p, "${NAME}", 7)) { p += 7; f << name.upper(); } else if (!strncmp(p, "${nAME}", 7)) { p += 7; f << name.lower(); } else if (!strncmp(p, "${definition}", 13)) { indent_needed = TRUE; for (index = 0; index != n; index += 1) cls[index]->generate(f, indent, indent_needed); p += 13; if (*p == '\n') p += 1; } else if (!strncmp(p, "${import}", 9)) { imports = ""; generate_imports(f, imports); for (index = 0; index != n; index += 1) cls[index]->generate_imports(f, imports); p += 9; } else f << *p++; } f << '\000'; if (must_be_saved(path, file)) { write_trace_header(); FILE * fp; if ((fp = fopen((const char *) path, "wb")) == 0) { write_trace_header(); UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + "</i> : cannot open <i> " + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + package_of_generated_artifact->name() + "</i> Python directory specification</b></font><br>"); incr_error(); } else { fputs((const char *) file, fp); fclose(fp); } } else if (get_trace_header().isEmpty()) UmlCom::trace(WrapperStr("<font face=helvetica><i> ") + path + "</i> not modified</font><br>"); } }
void UmlArtifact::generate() { if (! managed) { managed = TRUE; if (stereotype() == "text") { generate_text(); return; } else if (stereotype() != "source") return; package_of_generated_artifact = package(); const WrapperStr hdef = cppHeader(); QLOG_INFO() << "Read header as: " + hdef.operator QString(); const WrapperStr srcdef = cppSource(); if (hdef.isEmpty() && srcdef.isEmpty()) { if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>artifact <i>") + name() + "</i> has an empty C++ definition</font><br>"); return; } const WrapperStr & name = UmlArtifact::name(); UmlPackage * pack = package(); WrapperStr h_path = pack->header_path(name); WrapperStr src_path = pack->source_path(name); WrapperStr nasp_start; WrapperStr nasp_end; const char * cnasp = pack->cppNamespace(); WrapperStr nasp = ((cnasp[0] == ':') && (cnasp[1] == ':')) ? cnasp + 2 : cnasp; if (!nasp.isEmpty()) { int index = 0; int index2; WrapperStr closed = "\n} // namespace "; while ((index2 = nasp.find(':', index)) != -1) { WrapperStr na = nasp.mid(index, index2 - index); nasp_start += WrapperStr("namespace ") + na + " {\n\n"; closed += na; nasp_end = closed + "\n" + nasp_end; closed += "::"; nasp.replace(index2, 2, "_"); index = index2 + 1; } nasp_start += WrapperStr("namespace ") + nasp.mid(index) + " {\n\n"; closed += nasp.mid(index); nasp_end = closed + "\n" + nasp_end; } else { WrapperStr s; if (!hdef.isEmpty()) s = " in <i> " + h_path + "</i>"; if (!srcdef.isEmpty()) { if (!hdef.isEmpty()) s += " and <i> " + src_path + "</i>"; else s = " in <i> " + src_path + "</i>"; } UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ") + name + "</i>" + s + "</font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ") + name + "</i>" + s + "</font><br>"); } // get bodies if preserve const Q3PtrVector<UmlClass> & cls = associatedClasses(); if (preserve()) UmlOperation::read_bodies(h_path, src_path); // compute dependencies bool all_in_h = (hdef.find("${all_includes}") != -1); Q3PtrList<CppRefType> dependencies; unsigned n = cls.count(); unsigned index; for (index = 0; index != n; index += 1) cls[index]->compute_dependencies(dependencies, all_in_h); // generate header file WrapperStr h_incl; WrapperStr src_incl; WrapperStr decl; bool incl_computed = FALSE; if (!hdef.isEmpty()) { //headerFile->append("Test DAta"); QLOG_INFO() << "openign file for writing: "; //QTextStream f_h(file.data()); //[lgfreitas] Now QTextStream receives a pointer to a byte array... QSharedPointer<QByteArray> headerFile(new QByteArray()); QTextStream f_h(headerFile.data(), QFile::WriteOnly); f_h.setCodec(QTextCodec::codecForLocale()); //QTextStream f_h(headerFile.data(), QIODevice::WriteOnly); //QString h_copy = QString(hdef.operator QString()); const char * p = hdef; const char * pp = 0; for (;;) { QLOG_INFO() << "At this point P is: " << QString(p); if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; } if (*p == '@') manage_alias(p, f_h); else if (*p != '$') { QTextCodec* codec = QTextCodec::codecForLocale(); //f_h << codec->fromUnicode(*p,1); //p++; f_h << toLocale(p); } else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment()); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${name}", 7)) { p += 7; f_h << name; } else if (!strncmp(p, "${Name}", 7)) { p += 7; //QLOG_INFO() << "Outputting name: " << name; f_h << capitalize(name); } else if (!strncmp(p, "${NAME}", 7)) { p += 7; f_h << name.upper(); } else if (!strncmp(p, "${nAME}", 7)) { p += 7; f_h << name.lower(); } else if (!strncmp(p, "${namespace}", 12)) { p += 12; f_h << nasp; } else if (!strncmp(p, "${NAMESPACE}", 12)) { p += 12; f_h << nasp.upper(); } else if (!strncmp(p, "${includes}", 11) || !strncmp(p, "${all_includes}", 15)) { QLOG_INFO() << "REaDING INCLUDES"; p += (p[2] == 'a') ? 15 : 11; QLOG_INFO() << "Modified p 1 to be" << QString(p); if (!incl_computed) { incl_computed = TRUE; CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this); QLOG_INFO() << "Modified hdef to be: " << hdef.operator QString(); } QLOG_INFO() << "Modified p 2 to be" << QString(p); if (!h_incl.isEmpty()) { f_h << h_incl; if (*p != '\n') f_h << '\n'; } else if (*p == '\n') p += 1; QLOG_INFO() << "FINISHED INCLUDES"; } else if (!strncmp(p, "${declarations}", 15)) { p += 15; if (!incl_computed) { incl_computed = TRUE; CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this); } QLOG_INFO() << "DECLS IS: " << decl.operator QString(); if (!decl.isEmpty()) { f_h << decl; if (*p != '\n') f_h << '\n'; } else if (*p == '\n') p += 1; } else if (!strncmp(p, "${namespace_start}", 18)) { p += 18; if (!nasp_start.isEmpty()) f_h << nasp_start; if (*p == '\n') p += 1; } else if (!strncmp(p, "${namespace_end}", 16)) { p += 16; if (!nasp_end.isEmpty()) f_h << nasp_end; if (*p == '\n') p += 1; } else if (!strncmp(p, "${definition}", 13)) { p += 13; for (index = 0; index != n; index += 1) cls[index]->generate_decl(f_h, current_indent(p, hdef.operator QString())); if (*p == '\n') p += 1; } else // strange f_h << toLocale(p); } f_h << '\000'; f_h.flush(); if (must_be_saved(h_path, headerFile->data())) { QLOG_INFO() << "this is essentially what goes to the header file: " << headerFile->size(); write_trace_header(); //FILE * fp_h; QFile file(h_path); if (!file.open(QFile::WriteOnly)) { UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + "</i> : cannot open <i> " + h_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + pack->name() + "</i> C++ directory specification</b></font><br>"); incr_error(); } else { QLOG_INFO() << "this is essentially what goes to the file: " << headerFile->constData(); QTextCodec* codec = QTextCodec::codecForLocale(); QTextStream out(&file); out.setCodec(QTextCodec::codecForLocale()); QString temp(*headerFile.data()); out << codec->toUnicode(temp); //out << *headerFile.data(); out.flush(); } } else { WrapperStr th = get_trace_header(); if (th.isEmpty()) UmlCom::trace(WrapperStr("<br><font face=helvetica><i> ") + h_path + "</i> not modified</font><br>"); else set_trace_header(th + "<font face=helvetica><i> " + h_path + "</i> not modified</font><br>"); } } // generate source file if (!srcdef.isEmpty()) { QSharedPointer<QByteArray> file(new QByteArray()); QTextStream f_src(file.data(), QIODevice::WriteOnly); const char * p = srcdef; const char * pp = 0; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; } if (*p == '@') manage_alias(p, f_src); else if (*p != '$') f_src << toLocale(p); else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment()); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${name}", 7)) { // for file header p += 7; f_src << name; } else if (!strncmp(p, "${includes}", 11)) { p += 11; if (!incl_computed) { incl_computed = TRUE; CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this); } if (!src_incl.isEmpty()) { f_src << src_incl; if (*p != '\n') f_src << '\n'; } else if (*p == '\n') p += 1; } else if (!strncmp(p, "${members}", 10)) { p += 10; for (index = 0; index != n; index += 1) cls[index]->generate_def(f_src, current_indent(p, srcdef), FALSE); if (*p == '\n') p += 1; } else if (!strncmp(p, "${namespace_start}", 18)) { p += 18; if (!nasp_start.isEmpty()) f_src << nasp_start; if (*p == '\n') p += 1; } else if (!strncmp(p, "${namespace_end}", 16)) { p += 16; if (!nasp_end.isEmpty()) f_src << nasp_end; if (*p == '\n') p += 1; } else // strange f_src << toLocale(p); } f_src << '\000'; f_src.flush(); if (must_be_saved(src_path, file->data())) { write_trace_header(); FILE * fp_src; if ((fp_src = fopen((const char *) src_path, "wb")) == 0) { write_trace_header(); UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + " : </i> cannot open <i> " + src_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + pack->name() + "</i> C++ directory specification</b></font><br>"); incr_error(); } else { fputs((const char *) file->data(), fp_src); fclose(fp_src); } } else if (get_trace_header().isEmpty()) UmlCom::trace(WrapperStr("<font face=helvetica><i> ") + src_path + "</i> not modified</font><br>"); } } }
static void pstartElement(void *ctxt, const xmlChar * uname, const xmlChar ** uattrs) { int num_match; char *subs; int is_uri; const char **a; size_t s_to, s_from; saxctxt *ctx = (saxctxt *) ctxt; apr_array_header_t *linkattrs; int i; const char *name = (const char *) uname; const char **attrs = (const char **) uattrs; const htmlElemDesc *desc = htmlTagLookup(uname); /* VoxCDN FIXME: rewrite this, it's ridiculously bad */ #if 0 /* for now, err on the side of leaving stuff alone */ int enforce = 0; if ((ctx->cfg->doctype == fpi_html) || (ctx->cfg->doctype == fpi_xhtml)) { /* enforce html */ enforce = 2; if (!desc || desc->depr) return; } else if ((ctx->cfg->doctype == fpi_html) || (ctx->cfg->doctype == fpi_xhtml)) { enforce = 1; /* enforce html legacy */ if (!desc) { return; } } if (!desc && enforce) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, ctx->f->r, "Bogus HTML element %s dropped", name) ; return; } if (desc && desc->depr && (enforce == 2) ) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, ctx->f->r, "Deprecated HTML element %s dropped", name) ; return; } #endif ap_fputc(ctx->f->next, ctx->bb, '<'); ap_fputs(ctx->f->next, ctx->bb, name); if (attrs) { linkattrs = apr_hash_get(ctx->cfg->links, name, APR_HASH_KEY_STRING); for (a = attrs; *a; a += 2) { ctx->offset = 0; if (a[1]) { pappend(ctx, a[1], strlen(a[1]) + 1); is_uri = 0; if (linkattrs) { tattr *attrs = (tattr *) linkattrs->elts; for (i = 0; i < linkattrs->nelts; ++i) { if (!strcmp(*a, attrs[i].val)) { is_uri = 1; break; } } } if(is_uri) { /* first do the server replacements */ if(ctx->cfg->map) { server_remap_t *remaps = (server_remap_t *)ctx->cfg->map->elts; for(i = 0; i < ctx->cfg->map->nelts; ++i) { if(!ap_regexec(&(remaps[i].regex), ctx->buf, 0, 0, 0)) { int add_auth = ctx->cfg->global_auth | (remaps[i].flags & REMAP_FLAG_AUTH); int add_qstring_ignore = ctx->cfg->global_qstring_ignore | (remaps[i].flags & REMAP_FLAG_QSTRING_IGNORE); subs = remap_url(ctx, ctx->buf, add_auth, add_qstring_ignore); if(subs) { ++num_match; s_to = strlen(subs); s_from = strlen(ctx->buf); if(s_to > s_from) preserve(ctx, s_to - s_from); memcpy(ctx->buf, subs, s_to+1); break; /* only do one substitution per link */ } } } } } } if (!a[1]) ap_fputstrs(ctx->f->next, ctx->bb, " ", a[0], NULL); else { /* write the attribute */ ap_fputstrs(ctx->f->next, ctx->bb, " ", a[0], "=\"", NULL); pcharacters(ctx, (const xmlChar *) ctx->buf, strlen(ctx->buf)); ap_fputc(ctx->f->next, ctx->bb, '"'); } } } ctx->offset = 0; if(desc && desc->empty) ap_fputs(ctx->f->next, ctx->bb, "/>"); else ap_fputc(ctx->f->next, ctx->bb, '>'); }
/* * Main loop for command mode command decoding. * A few commands are executed here, but main function * is to strip command addresses, do a little address oriented * processing and call command routines to do the real work. */ void commands(bool noprompt, bool exitoneof) { register line *addr; register int c; register int lchng; int given; int seensemi; int cnt; bool hadpr; resetflav(); nochng(); for (;;) { /* * If dot at last command * ended up at zero, advance to one if there is a such. */ if (dot <= zero) { dot = zero; if (dol > zero) dot = one; } shudclob = 0; /* * If autoprint or trailing print flags, * print the line at the specified offset * before the next command. */ if (pflag || (lchng != chng && value(AUTOPRINT) && !inglobal && !inopen && endline)) { pflag = 0; nochng(); if (dol != zero) { addr1 = addr2 = dot + poffset; if (addr1 < one || addr1 > dol) error("Offset out-of-bounds|Offset after command too large"); setdot1(); goto print; } } nochng(); /* * Print prompt if appropriate. * If not in global flush output first to prevent * going into pfast mode unreasonably. */ if (inglobal == 0) { flush(); if (!hush && value(PROMPT) && !globp && !noprompt && endline) { ex_putchar(':'); hadpr = 1; } TSYNC(); } /* * Gobble up the address. * Degenerate addresses yield ".". */ addr2 = 0; given = seensemi = 0; do { addr1 = addr2; addr = address(0); c = getcd(); if (addr == 0) { if (c == ',') addr = dot; else if (addr1 != 0) { addr2 = dot; break; } else break; } addr2 = addr; given++; if (c == ';') { c = ','; dot = addr; seensemi = 1; } } while (c == ','); if (c == '%') { /* %: same as 1,$ */ addr1 = one; addr2 = dol; given = 2; c = ex_getchar(); } if (addr1 == 0) addr1 = addr2; if (c == ':') c = ex_getchar(); /* * Set command name for special character commands. */ tailspec(c); /* * If called via : escape from open or visual, limit * the set of available commands here to save work below. */ if (inopen) { if (c=='\n' || c=='\r' || c==CTRL('d') || c==EOF) { if (addr2) dot = addr2; if (c == EOF) return; continue; } if (any(c, "o")) notinvis: tailprim(Command, 1, 1); } switch (c) { case 'a': switch(peekchar()) { case 'b': /* abbreviate */ tail("abbreviate"); setnoaddr(); mapcmd(0, 1); anyabbrs = 1; continue; case 'r': /* args */ tail("args"); setnoaddr(); eol(); pargs(); continue; } /* append */ if (inopen) goto notinvis; tail("append"); setdot(); aiflag = exclam(); ex_newline(); vmacchng(0); deletenone(); setin(addr2); inappend = 1; ignore(append(gettty, addr2)); inappend = 0; nochng(); continue; case 'c': switch (peekchar()) { /* copy */ case 'o': tail("copy"); vmacchng(0); move(); continue; #ifdef CHDIR /* cd */ case 'd': tail("cd"); goto changdir; /* chdir */ case 'h': ignchar(); if (peekchar() == 'd') { register char *p; tail2of("chdir"); changdir: if (savedfile[0] == '/' || !value(WARN)) ignore(exclam()); else ignore(quickly()); if (skipend()) { p = getenv("HOME"); if (p == NULL) error("Home directory unknown"); } else getone(), p = file; eol(); if (chdir(p) < 0) filioerr(p); if (savedfile[0] != '/') edited = 0; continue; } if (inopen) tailprim("change", 2, 1); tail2of("change"); break; #endif default: if (inopen) goto notinvis; tail("change"); break; } /* change */ aiflag = exclam(); setCNL(); vmacchng(0); setin(addr1); delete(0); inappend = 1; ignore(append(gettty, addr1 - 1)); inappend = 0; nochng(); continue; /* delete */ case 'd': /* * Caution: dp and dl have special meaning already. */ tail("delete"); c = cmdreg(); setCNL(); vmacchng(0); if (c) YANKreg(c); delete(0); appendnone(); continue; /* edit */ /* ex */ case 'e': tail(peekchar() == 'x' ? "ex" : "edit"); editcmd: if (!exclam() && chng) c = 'E'; filename(c); if (c == 'E') { ungetchar(lastchar()); ignore(quickly()); } setnoaddr(); doecmd: init(); addr2 = zero; laste++; ex_sync(); rop(c); nochng(); continue; /* file */ case 'f': tail("file"); setnoaddr(); filename(c); noonl(); /* synctmp(); */ continue; /* global */ case 'g': tail("global"); global(!exclam()); nochng(); continue; /* insert */ case 'i': if (inopen) goto notinvis; tail("insert"); setdot(); nonzero(); aiflag = exclam(); ex_newline(); vmacchng(0); deletenone(); setin(addr2); inappend = 1; ignore(append(gettty, addr2 - 1)); inappend = 0; if (dot == zero && dol > zero) dot = one; nochng(); continue; /* join */ case 'j': tail("join"); c = exclam(); setcount(); nonzero(); ex_newline(); vmacchng(0); if (given < 2 && addr2 != dol) addr2++; join(c); continue; /* k */ case 'k': casek: pastwh(); c = ex_getchar(); if (endcmd(c)) serror("Mark what?|%s requires following letter", Command); ex_newline(); if (!islower(c)) error("Bad mark|Mark must specify a letter"); setdot(); nonzero(); names[c - 'a'] = *addr2 &~ 01; anymarks = 1; continue; /* list */ case 'l': tail("list"); setCNL(); ignorf(setlist(1)); pflag = 0; goto print; case 'm': if (peekchar() == 'a') { ignchar(); if (peekchar() == 'p') { /* map */ tail2of("map"); setnoaddr(); mapcmd(0, 0); continue; } /* mark */ tail2of("mark"); goto casek; } /* move */ tail("move"); vmacchng(0); move(); continue; case 'n': if (peekchar() == 'u') { tail("number"); goto numberit; } /* next */ tail("next"); setnoaddr(); ckaw(); ignore(quickly()); if (getargs()) makargs(); next(); c = 'e'; filename(c); goto doecmd; /* open */ case 'o': tail("open"); oop(); pflag = 0; nochng(); continue; case 'p': case 'P': switch (peekchar()) { /* put */ case 'u': tail("put"); setdot(); c = cmdreg(); eol(); vmacchng(0); if (c) putreg(c); else put(); continue; case 'r': ignchar(); if (peekchar() == 'e') { /* preserve */ tail2of("preserve"); eol(); if (preserve() == 0) error("Preserve failed!"); else error("File preserved."); } tail2of("print"); break; default: tail("print"); break; } /* print */ setCNL(); pflag = 0; print: nonzero(); if (CL && span() > EX_LINES) { flush1(); vclear(); } plines(addr1, addr2, 1); continue; /* quit */ case 'q': tail("quit"); setnoaddr(); c = quickly(); eol(); if (!c) quit: nomore(); if (inopen) { vgoto(WECHO, 0); if (!ateopr()) vnfl(); else { tostop(); } flush(); setty(normf); } cleanup(1); ex_exit(0); case 'r': if (peekchar() == 'e') { ignchar(); switch (peekchar()) { /* rewind */ case 'w': tail2of("rewind"); setnoaddr(); if (!exclam()) { ckaw(); if (chng && dol > zero) error("No write@since last chage (:rewind! overrides)"); } eol(); erewind(); next(); c = 'e'; ungetchar(lastchar()); filename(c); goto doecmd; /* recover */ case 'c': tail2of("recover"); setnoaddr(); c = 'e'; if (!exclam() && chng) c = 'E'; filename(c); if (c == 'E') { ungetchar(lastchar()); ignore(quickly()); } init(); addr2 = zero; laste++; ex_sync(); recover(); rop2(); revocer(); if (status == 0) rop3(c); if (dol != zero) change(); nochng(); continue; } tail2of("read"); } else tail("read"); /* read */ if (savedfile[0] == 0 && dol == zero) c = 'e'; pastwh(); vmacchng(0); if (peekchar() == '!') { setdot(); ignchar(); unix0(0); filter(0); continue; } filename(c); rop(c); nochng(); if (inopen && endline && addr1 > zero && addr1 < dol) dot = addr1 + 1; continue; case 's': switch (peekchar()) { /* * Caution: 2nd char cannot be c, g, or r * because these have meaning to substitute. */ /* set */ case 'e': tail("set"); setnoaddr(); set(); continue; /* shell */ case 'h': tail("shell"); setNAEOL(); vnfl(); putpad(TE); flush(); unixwt(1, unixex("-i", (char *) 0, 0, 0)); vcontin(0); continue; /* source */ case 'o': #ifdef notdef if (inopen) goto notinvis; #endif tail("source"); setnoaddr(); getone(); eol(); source(file, 0); continue; #ifdef SIGTSTP /* stop, suspend */ case 't': tail("stop"); goto suspend; case 'u': tail("suspend"); suspend: if (!dosusp) error("Old tty driver|Not using new tty driver/shell"); c = exclam(); eol(); if (!c) ckaw(); onsusp(0); continue; #endif } /* fall into ... */ /* & */ /* ~ */ /* substitute */ case '&': case '~': Command = "substitute"; if (c == 's') tail(Command); vmacchng(0); if (!substitute(c)) pflag = 0; continue; /* t */ case 't': if (peekchar() == 'a') { tail("tag"); tagfind(exclam()); if (!inopen) lchng = chng - 1; else nochng(); continue; } tail("t"); vmacchng(0); move(); continue; case 'u': if (peekchar() == 'n') { ignchar(); switch(peekchar()) { /* unmap */ case 'm': tail2of("unmap"); setnoaddr(); mapcmd(1, 0); continue; /* unabbreviate */ case 'a': tail2of("unabbreviate"); setnoaddr(); mapcmd(1, 1); anyabbrs = 1; continue; } /* undo */ tail2of("undo"); } else tail("undo"); setnoaddr(); markDOT(); c = exclam(); ex_newline(); undo(c); continue; case 'v': switch (peekchar()) { case 'e': /* version */ tail("version"); setNAEOL(); ex_printf("@(#) Version 3.6, 11/3/80" " (4.0BSD). git " "160803 14:24" +5); noonl(); continue; /* visual */ case 'i': tail("visual"); if (inopen) { c = 'e'; goto editcmd; } vop(); pflag = 0; nochng(); continue; } /* v */ tail("v"); global(0); nochng(); continue; /* write */ case 'w': c = peekchar(); tail(c == 'q' ? "wq" : "write"); wq: if (skipwh() && peekchar() == '!') { pofix(); ignchar(); setall(); unix0(0); filter(1); } else { setall(); wop(1); nochng(); } if (c == 'q') goto quit; continue; /* xit */ case 'x': tail("xit"); if (!chng) goto quit; c = 'q'; goto wq; /* yank */ case 'y': tail("yank"); c = cmdreg(); setcount(); eol(); vmacchng(0); if (c) YANKreg(c); else yank(); continue; /* z */ case 'z': zop(0); pflag = 0; continue; /* * */ /* @ */ case '*': case '@': c = ex_getchar(); if (c=='\n' || c=='\r') ungetchar(c); if (any(c, "@*\n\r")) c = lastmac; if (isupper(c)) c = tolower(c); if (!islower(c)) error("Bad register"); ex_newline(); setdot(); cmdmac(c); continue; /* | */ case '|': endline = 0; goto caseline; /* \n */ case '\n': endline = 1; caseline: notempty(); if (addr2 == 0) { if (UP != NOSTR && c == '\n' && !inglobal) c = CTRL('k'); if (inglobal) addr1 = addr2 = dot; else { if (dot == dol) error("At EOF|At end-of-file"); addr1 = addr2 = dot + 1; } } setdot(); nonzero(); if (seensemi) addr1 = addr2; ex_getline(*addr1); if (c == CTRL('k')) { flush1(); destline--; if (hadpr) shudclob = 1; } plines(addr1, addr2, 1); continue; /* " */ case '"': comment(); continue; /* # */ case '#': numberit: setCNL(); ignorf(setnumb(1)); pflag = 0; goto print; /* = */ case '=': ex_newline(); setall(); if (inglobal == 2) pofix(); ex_printf("%d", lineno(addr2)); noonl(); continue; /* ! */ case '!': if (addr2 != 0) { vmacchng(0); unix0(0); setdot(); filter(2); } else { unix0(1); pofix(); putpad(TE); flush(); unixwt(1, unixex("-c", uxb, 0, 0)); vclrech(1); /* vcontin(0); */ nochng(); } continue; /* < */ /* > */ case '<': case '>': for (cnt = 1; peekchar() == c; cnt++) ignchar(); setCNL(); vmacchng(0); shift(c, cnt); continue; /* ^D */ /* EOF */ case CTRL('d'): case EOF: if (exitoneof) { if (addr2 != 0) dot = addr2; return; } if (!isatty(0)) { if (intty) /* * Chtty sys call at UCB may cause a * input which was a tty to suddenly be * turned into /dev/null. */ onhup(0); return; } if (addr2 != 0) { setlastchar('\n'); putnl(); } if (dol == zero) { if (addr2 == 0) putnl(); notempty(); } ungetchar(EOF); zop(hadpr); continue; default: if (!isalpha(c)) break; ungetchar(c); tailprim("", 0, 0); } ierror("What?|Unknown command character '%c'", c); } }
void UmlArtifact::generate() { if (! managed) { managed = TRUE; if (stereotype() == "text") { generate_text(); return; } else if (stereotype() != "source") return; package_of_generated_artifact = package(); current = this; const WrapperStr filedef = javaSource(); if (filedef.isEmpty()) return; const WrapperStr & name = this->name(); WrapperStr path = package_of_generated_artifact->file_path(name); UmlCom::message(name); if (verbose()) UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); else set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ") + name + "</i> in " + path + "</i></font><br>"); // get bodies if preserve const QVector<UmlClass*> & cls = associatedClasses(); if (preserve()) UmlOperation::read_bodies(path); // generate file unsigned n = cls.count(); unsigned index; WrapperStr incl; QSharedPointer<QByteArray> headerFile(new QByteArray()); QTextStream f(headerFile.data(), QIODevice::WriteOnly); const char * p = filedef; const char * pp = 0; for (;;) { if (*p == 0) { if (pp == 0) break; // comment management done p = pp; pp = 0; if (*p == 0) break; } if (*p == '@') manage_alias(p, f); else if (*p != '$') f << *p++; else if (!strncmp(p, "${comment}", 10)) manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment()); else if (!strncmp(p, "${description}", 14)) manage_description(p, pp); else if (!strncmp(p, "${name}", 7)) { p += 7; f << name; } else if (!strncmp(p, "${Name}", 7)) { p += 7; f << capitalize(name); } else if (!strncmp(p, "${NAME}", 7)) { p += 7; f << name.upper(); } else if (!strncmp(p, "${nAME}", 7)) { p += 7; f << name.lower(); } else if (!strncmp(p, "${imports}", 10)) { WrapperStr indent = current_indent(p, filedef); for (index = 0; index != n; index += 1) cls[index]->generate_import(f, indent); p += 10; if (*p == '\n') p += 1; } else if (!strncmp(p, "${package}", 10)) { p += 10; const WrapperStr & package = package_of_generated_artifact->javaPackage(); if (!package.isEmpty()) f << "package " << package << ";\n\n"; if (*p == '\n') p += 1; } else if (!strncmp(p, "${definition}", 13)) { WrapperStr indent = current_indent(p, filedef); for (index = 0; index != n; index += 1) cls[index]->generate(f, indent); p += 13; if (*p == '\n') p += 1; } else // strange f << *p++; } f << '\000'; f.flush(); if (must_be_saved(path, headerFile->data())) { write_trace_header(); FILE * fp; if ((fp = fopen((const char *) path, "wb")) == 0) { write_trace_header(); UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ") + name + "</i> : cannot open <i> " + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>" + package_of_generated_artifact->name() + "</i> Java directory specification</b></font><br>"); incr_error(); } else { fputs((const char *) headerFile->data(), fp); fclose(fp); } } else if (get_trace_header().isEmpty()) UmlCom::trace(WrapperStr("<font face=helvetica><i> ") + path + "</i> not modified</font><br>"); if (imports != 0) { delete imports; imports = 0; } } }
static void pappend(saxctxt *ctx, const char *buf, const size_t len) { preserve(ctx, len); memcpy(ctx->buf+ctx->offset, buf, len); ctx->offset += len; }