Beispiel #1
0
void InsetRef::latex(otexstream & os, OutputParams const & rp) const
{
	string const cmd = getCmdName();
	docstring const data = getEscapedLabel(rp);

	if (rp.inulemcmd)
		os << "\\mbox{";

	if (cmd == "eqref" && buffer().params().use_refstyle) {
		// we advertise this as printing "(n)", so we'll do that, at least
		// for refstyle, since refstlye's own \eqref prints, by default,
		// "equation n". if one wants \eqref, one can get it by using a
		// formatted label in this case.
		os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
	} 
	else if (cmd == "formatted") {
		docstring label;
		docstring prefix;
		docstring const fcmd = getFormattedCmd(data, label, prefix);
		os << fcmd << '{' << label << '}';
	}
	else {
		// We don't want to output p_["name"], since that is only used 
		// in docbook. So we construct new params, without it, and use that.
		InsetCommandParams p(REF_CODE, cmd);
		docstring const ref = getParam("reference");
		p["reference"] = ref;
		os << p.getCommand(rp);
	}

	if (rp.inulemcmd)
		os << "}";
}
Beispiel #2
0
// Have to overwrite the default InsetCommand method in order to check that
// the \cite command is valid. Eg, the user has natbib enabled, inputs some
// citations and then changes his mind, turning natbib support off. The output
// should revert to the default citation command as provided by the citation
// engine, e.g. \cite[]{} for the basic engine.
void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
{
	vector<CitationStyle> citation_styles = buffer().params().citeStyles();
	CitationStyle cs = asValidLatexCommand(getCmdName(), citation_styles);
	BiblioInfo const & bi = buffer().masterBibInfo();
	// FIXME UNICODE
	docstring const cite_str = from_utf8(citationStyleToString(cs));

	if (runparams.inulemcmd > 0)
		os << "\\mbox{";

	os << "\\" << cite_str;

	docstring const & before = getParam("before");
	docstring const & after  = getParam("after");
	if (!before.empty() && cs.textBefore)
		os << '[' << before << "][" << after << ']';
	else if (!after.empty() && cs.textAfter)
		os << '[' << after << ']';

	if (!bi.isBibtex(getParam("key")))
		// escape chars with bibitems
		os << '{' << escape(cleanupWhitespace(getParam("key"))) << '}';
	else
		os << '{' << cleanupWhitespace(getParam("key")) << '}';

	if (runparams.inulemcmd)
		os << "}";
}
Beispiel #3
0
void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
{
	docstring const & ref = getParam("reference");
	// register this inset into the buffer reference cache.
	buffer().addReference(ref, this, it);

	docstring label;
	for (int i = 0; !types[i].latex_name.empty(); ++i) {
		if (getCmdName() == types[i].latex_name) {
			label = _(types[i].short_gui_name);
			break;
		}
	}
	label += ref;
	
	if (!buffer().params().isLatex() && !getParam("name").empty()) {
		label += "||";
		label += getParam("name");
	}
	
	screen_label_ = label;
	bool shortened = false;
	unsigned int const maxLabelChars = 24;
	if (screen_label_.size() > maxLabelChars) {
		screen_label_.erase(maxLabelChars - 3);
		screen_label_ += "...";
		shortened = true;
	}
	if (shortened)
		tooltip_ = label;
	else 
		tooltip_ = from_ascii("");
}
Beispiel #4
0
void InsetRef::validate(LaTeXFeatures & features) const
{
	string const cmd = getCmdName();
	if (cmd == "vref" || cmd == "vpageref")
		features.require("varioref");
	else if (cmd == "formatted") {
		docstring const data = getEscapedLabel(features.runparams());
		docstring label;
		docstring prefix;
		string const fcmd = to_utf8(getFormattedCmd(data, label, prefix));
		if (buffer().params().use_refstyle) {
			features.require("refstyle");
			if (prefix == "cha")
				features.addPreambleSnippet("\\let\\charef=\\chapref");
			else if (!prefix.empty()) {
				string lcmd = "\\AtBeginDocument{\\providecommand" + 
						fcmd + "[1]{\\ref{" + to_utf8(prefix) + ":#1}}}";
				features.addPreambleSnippet(lcmd);
			}
		} else {
			features.require("prettyref");
			// prettyref uses "cha" for chapters, so we provide a kind of
			// translation.
			if (prefix == "chap")
				features.addPreambleSnippet("\\let\\pr@chap=\\pr@cha");
		}
	} else if (cmd == "eqref" && !buffer().params().use_refstyle)
		// with refstyle, we simply output "(\ref{label})"
		features.require("amsmath");
	else if (cmd == "nameref")
		features.require("nameref");
}
bool JdbcUtil::showStatus(void)
{
	if (!attachMemory()) return false;

	int idx=0;
	int freeCount=0;
	printf("Process Status:\n");
	for (idx=0; idx<MAX_PROCESSES; idx++)
	{
		if (sharedMemory->processTable[idx].processId)
		{
			char *pending;
			if (sharedMemory->processTable[idx].pending) pending = "Yes";
			else pending = "No";
			printf("    Pid: %u\n",
				sharedMemory->processTable[idx].processId);
			printf("      Cmd:       %s\n",getCmdName(sharedMemory->processTable[idx].cmd));
			printf("      Pending:   %s\n",pending);
			printf("      Parameter: %s\n",sharedMemory->processTable[idx].parameter);
		}
		else freeCount++;
	}
	if (freeCount==MAX_PROCESSES) printf("    Process Table Empty.\n");
	return true;
}
// Have to overwrite the default InsetCommand method in order to check that
// the \cite command is valid. Eg, the user has natbib enabled, inputs some
// citations and then changes his mind, turning natbib support off. The output
// should revert to \cite[]{}
void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
{
	CiteEngine cite_engine = buffer().params().citeEngine();
	BiblioInfo const & bi = buffer().masterBibInfo();
	// FIXME UNICODE
	docstring const cite_str = from_utf8(
		asValidLatexCommand(getCmdName(), cite_engine));

	if (runparams.inulemcmd)
		os << "\\mbox{";

	os << "\\" << cite_str;

	docstring const & before = getParam("before");
	docstring const & after  = getParam("after");
	if (!before.empty() && cite_engine != ENGINE_BASIC)
		os << '[' << before << "][" << after << ']';
	else if (!after.empty())
		os << '[' << after << ']';

	if (!bi.isBibtex(getParam("key")))
		// escape chars with bibitems
		os << '{' << escape(cleanupWhitespace(getParam("key"))) << '}';
	else
		os << '{' << cleanupWhitespace(getParam("key")) << '}';

	if (runparams.inulemcmd)
		os << "}";
}
Beispiel #7
0
void InsetPrintNomencl::latex(otexstream & os, OutputParams const & runparams_in) const
{
	OutputParams runparams = runparams_in;
	if (getParam("set_width") == "auto") {
		docstring widest = nomenclWidest(buffer(), runparams);
		// Set the label width via nomencl's command \nomlabelwidth.
		// This must be output before the command \printnomenclature
		if (!widest.empty()) {
			os << "\\settowidth{\\nomlabelwidth}{"
			   << widest
			   << "}\n";
		}
	} else if (getParam("set_width") == "custom") {
		// custom length as optional arg of \printnomenclature
		string const width =
			Length(to_ascii(getParam("width"))).asLatexString();
		os << '\\'
		   << from_ascii(getCmdName())
		   << '['
		   << from_ascii(width)
		   << "]{}";
		return;
	}
	// output the command \printnomenclature
	os << getCommand(runparams);
}
Beispiel #8
0
int InsetCitation::plaintext(odocstringstream & os,
       OutputParams const &, size_t) const
{
	string const & cmd = getCmdName();
	if (cmd == "nocite")
		return 0;

	docstring const label = generateLabel(false);
	os << label;
	return label.size();
}
Beispiel #9
0
docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
{
	string const & cmd = getCmdName();
	if (cmd == "nocite")
		return docstring();

	// have to output this raw, because generateLabel() will include tags
	xs << XHTMLStream::ESCAPE_NONE << generateLabel(true);

	return docstring();
}
Beispiel #10
0
void test(int argc, char * argv[]){
    auto pm = new PluginManager<ICmd>(); //load 

    
    const char * cmdName = "print";
    const char * dev = "a.img";
    const int fatType = 1;
    auto params = new Parameters(cmdName, dev, fatType);
        
    ICmd * cmd = pm->getPlugin(params->getCmdName());
    if(cmd != NULL){
        cmd->config(params);
        cmd->execute();
    }

    delete params;
    delete pm; //unload 
}
Beispiel #11
0
docstring InsetCitation::complexLabel(bool for_xhtml) const
{
	Buffer const & buf = buffer();
	// Only start the process off after the buffer is loaded from file.
	if (!buf.isFullyLoaded())
		return docstring();

	BiblioInfo const & biblist = buf.masterBibInfo();
	if (biblist.empty())
		return docstring();

	docstring const & key = getParam("key");
	if (key.empty())
		return _("No citations selected!");

	// We don't currently use the full or forceUCase fields.
	string cite_type = getCmdName();
	if (cite_type[0] == 'C')
		// If we were going to use them, this would mean ForceUCase
		cite_type = string(1, 'c') + cite_type.substr(1);
	if (cite_type[cite_type.size() - 1] == '*')
		// and this would mean FULL
		cite_type = cite_type.substr(0, cite_type.size() - 1);

	docstring const & before = getParam("before");
	docstring const & after = getParam("after");

	// FIXME: allow to add cite macros
	/*
	buffer().params().documentClass().addCiteMacro("!textbefore", to_utf8(before));
	buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after));
	*/
	docstring label;
	vector<docstring> keys = getVectorFromString(key);
	label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, UINT_MAX, before, after);
	return label;
}
docstring InsetCitation::complexLabel(bool for_xhtml) const
{
	Buffer const & buf = buffer();
	// Only start the process off after the buffer is loaded from file.
	if (!buf.isFullyLoaded())
		return docstring();

	BiblioInfo const & biblist = buf.masterBibInfo();
	if (biblist.empty())
		return docstring();

	// the natbib citation-styles
	// CITET:	author (year)
	// CITEP:	(author,year)
	// CITEALT:	author year
	// CITEALP:	author, year
	// CITEAUTHOR:	author
	// CITEYEAR:	year
	// CITEYEARPAR:	(year)
	// jurabib supports these plus
	// CITE:	author/<before field>

	CiteEngine const engine = buffer().params().citeEngine();
	// We don't currently use the full or forceUCase fields.
	string cite_type = asValidLatexCommand(getCmdName(), engine);
	if (cite_type[0] == 'C')
		// If we were going to use them, this would mean ForceUCase
		cite_type = string(1, 'c') + cite_type.substr(1);
	if (cite_type[cite_type.size() - 1] == '*')
		// and this would mean FULL
		cite_type = cite_type.substr(0, cite_type.size() - 1);

	docstring const & before = getParam("before");
	docstring before_str;
	if (!before.empty()) {
		// In CITET and CITEALT mode, the "before" string is
		// attached to the label associated with each and every key.
		// In CITEP, CITEALP and CITEYEARPAR mode, it is attached
		// to the front of the whole only.
		// In other modes, it is not used at all.
		if (cite_type == "citet" ||
		    cite_type == "citealt" ||
		    cite_type == "citep" ||
		    cite_type == "citealp" ||
		    cite_type == "citeyearpar")
			before_str = before + ' ';
		// In CITE (jurabib), the "before" string is used to attach
		// the annotator (of legal texts) to the author(s) of the
		// first reference.
		else if (cite_type == "cite")
			before_str = '/' + before;
	}

	docstring const & after = getParam("after");
	docstring after_str;
	// The "after" key is appended only to the end of the whole.
	if (cite_type == "nocite")
		after_str =  " (" + _("not cited") + ')';
	else if (!after.empty()) {
		after_str = ", " + after;
	}

	// One day, these might be tunable (as they are in BibTeX).
	char op, cp;	// opening and closing parenthesis.
	const char * sep;	// punctuation mark separating citation entries.
	if (engine == ENGINE_BASIC) {
		op  = '[';
		cp  = ']';
		sep = ",";
	} else {
		op  = '(';
		cp  = ')';
		sep = ";";
	}

	docstring const op_str = ' ' + docstring(1, op);
	docstring const cp_str = docstring(1, cp) + ' ';
	docstring const sep_str = from_ascii(sep) + ' ';

	docstring label;
	vector<docstring> keys = getVectorFromString(getParam("key"));
	vector<docstring>::const_iterator it  = keys.begin();
	vector<docstring>::const_iterator end = keys.end();
	for (; it != end; ++it) {
		// get the bibdata corresponding to the key
		docstring const author = biblist.getAbbreviatedAuthor(*it);
		docstring const year = biblist.getYear(*it, for_xhtml);
		docstring const citenum = for_xhtml ? biblist.getCiteNumber(*it) : *it;

		if (author.empty() || year.empty())
			// We can't construct a "complex" label without that info.
			// So fail safely.
			return docstring();

		// authors1/<before>;  ... ;
		//  authors_last, <after>
		if (cite_type == "cite") {
			if (engine == ENGINE_BASIC) {
				label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
			} else if (engine == ENGINE_JURABIB) {
				if (it == keys.begin())
					label += wrapCitation(*it, author, for_xhtml) + before_str + sep_str;
				else
					label += wrapCitation(*it, author, for_xhtml) + sep_str;
			}
		} 
		// nocite
		else if (cite_type == "nocite") {
			label += *it + sep_str;
		} 
		// (authors1 (<before> year);  ... ;
		//  authors_last (<before> year, <after>)
		else if (cite_type == "citet") {
			switch (engine) {
			case ENGINE_NATBIB_AUTHORYEAR:
				label += author + op_str + before_str +
					wrapCitation(*it, year, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_NATBIB_NUMERICAL:
				label += author + op_str + before_str + 
					wrapCitation(*it, citenum, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_JURABIB:
				label += before_str + author + op_str +
					wrapCitation(*it, year, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_BASIC:
				break;
			}
		} 
		// author, year; author, year; ...	
		else if (cite_type == "citep" ||
			   cite_type == "citealp") {
			if (engine == ENGINE_NATBIB_NUMERICAL) {
				label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
			} else {
				label += wrapCitation(*it, author + ", " + year, for_xhtml) + sep_str;
			}

		} 
		// (authors1 <before> year;
		//  authors_last <before> year, <after>)
		else if (cite_type == "citealt") {
			switch (engine) {
			case ENGINE_NATBIB_AUTHORYEAR:
				label += author + ' ' + before_str +
					wrapCitation(*it, year, for_xhtml) + sep_str;
				break;
			case ENGINE_NATBIB_NUMERICAL:
				label += author + ' ' + before_str + '#' + 
					wrapCitation(*it, citenum, for_xhtml) + sep_str;
				break;
			case ENGINE_JURABIB:
				label += before_str + 
					wrapCitation(*it, author + ' ' + year, for_xhtml) + sep_str;
				break;
			case ENGINE_BASIC:
				break;
			}

		
		} 
		// author; author; ...
		else if (cite_type == "citeauthor") {
			label += wrapCitation(*it, author, for_xhtml) + sep_str;
		}
		// year; year; ...
		else if (cite_type == "citeyear" ||
			   cite_type == "citeyearpar") {
			label += wrapCitation(*it, year, for_xhtml) + sep_str;
		}
	}
	label = rtrim(rtrim(label), sep);

	if (!after_str.empty()) {
		if (cite_type == "citet") {
			// insert "after" before last ')'
			label.insert(label.size() - 1, after_str);
		} else {
			bool const add =
				!(engine == ENGINE_NATBIB_NUMERICAL &&
				  (cite_type == "citeauthor" ||
				   cite_type == "citeyear"));
			if (add)
				label += after_str;
		}
	}

	if (!before_str.empty() && (cite_type == "citep" ||
				    cite_type == "citealp" ||
				    cite_type == "citeyearpar")) {
		label = before_str + label;
	}

	if (cite_type == "citep" || cite_type == "citeyearpar" || 
	    (cite_type == "cite" && engine == ENGINE_BASIC) )
		label = op + label + cp;

	return label;
}
Beispiel #13
0
docstring InsetTOC::screenLabel() const
{
	if (getCmdName() == "tableofcontents")
		return buffer().B_("Table of Contents");
	return _("Unknown TOC type");
}
Beispiel #14
0
bool
AVCCommand::fire()
{
    memset( &m_fcpFrame,  0x0,  sizeof( m_fcpFrame ) );

    Util::Cmd::BufferSerialize se( m_fcpFrame, sizeof( m_fcpFrame ) );
    if ( !serialize( se ) ) {
        debugFatal(  "fire: Could not serialize\n" );
        return false;
    }

    unsigned short fcpFrameSize = se.getNrOfProducesBytes();

    if (getDebugLevel() >= DEBUG_LEVEL_VERY_VERBOSE) {
        debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "%s:\n", getCmdName() );
        debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,  "  Request:\n");
        showFcpFrame( m_fcpFrame, fcpFrameSize );

        Util::Cmd::StringSerializer se_dbg;
        serialize( se_dbg );
        
        // output the debug message in smaller chunks to avoid problems
        // with a max message size
        unsigned int chars_to_write=se_dbg.getString().size();
        unsigned int chars_written=0;
        while (chars_written<chars_to_write) {
            debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "%s\n",
                         se_dbg.getString().substr(chars_written, DEBUG_MAX_MESSAGE_LENGTH).c_str());
            chars_written += DEBUG_MAX_MESSAGE_LENGTH-1;
        }
    }

    bool result = false;
    unsigned int resp_len;
    quadlet_t* resp = m_p1394Service->transactionBlock( m_nodeId,
                                                        (quadlet_t*)m_fcpFrame,
                                                        ( fcpFrameSize+3 ) / 4,
                                                        &resp_len );
    if ( resp ) {
        resp_len *= 4;
        unsigned char* buf = ( unsigned char* ) resp;

        m_eResponse = ( EResponse )( *buf );
        switch ( m_eResponse )
        {
            case eR_Accepted:
            case eR_Implemented:
            case eR_Rejected:
            case eR_NotImplemented:
            {
                Util::Cmd::BufferDeserialize de( buf, resp_len );
                result = deserialize( de );
    
                debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,"  Response:\n");
                showFcpFrame( buf, de.getNrOfConsumedBytes() );
    
                Util::Cmd::StringSerializer se_dbg;
                serialize( se_dbg );
    
                // output the debug message in smaller chunks to avoid problems
                // with a max message size
                unsigned int chars_to_write=se_dbg.getString().size();
                unsigned int chars_written=0;
                while (chars_written<chars_to_write) {
                    debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "%s\n",
                                se_dbg.getString().substr(chars_written, DEBUG_MAX_MESSAGE_LENGTH).c_str());
                    chars_written += DEBUG_MAX_MESSAGE_LENGTH-1;
                }
            }
            break;
            default:
                debugWarning( "unexpected response received (0x%x)\n", m_eResponse );
                debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,"  Response:\n");
    
                Util::Cmd::BufferDeserialize de( buf, resp_len );
                deserialize( de );
    
                showFcpFrame( buf, de.getNrOfConsumedBytes() );
                result = false;

        }
        debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n" );
        m_p1394Service->transactionBlockClose();
    } else {
        debugOutput( DEBUG_LEVEL_VERBOSE, "no response\n" );
        result = false;
        m_p1394Service->transactionBlockClose();
    }

    return result;
}
Beispiel #15
0
int InsetTOC::plaintext(odocstream & os, OutputParams const &) const
{
	os << screenLabel() << "\n\n";
	buffer().tocBackend().writePlaintextTocList(getCmdName(), os);
	return PLAINTEXT_NEWLINE;
}
Beispiel #16
0
int InsetTOC::docbook(odocstream & os, OutputParams const &) const
{
	if (getCmdName() == "tableofcontents")
		os << "<toc></toc>";
	return 0;
}
Beispiel #17
0
char *aliasexpand(const char * const Xcmd)
{	char *cmd;				/* work buffer */
	char *cp, *name, *alias;
	unsigned ofs, *expanded, *he;
	int i, numExpanded, newlen, len;

	assert(Xcmd);

	if((cmd = estrdup(Xcmd)) == 0)
		return (char*)Xcmd;

	numExpanded = 0;
	expanded = 0;
	name = 0;

redo:						/* iteration to expand all aliases */
	cp = ltrimcl(cmd);		/* skip leading whitespaces */

	/* Check if the user disabled alias expansion */
	if(*cp == '*') {
		*cp = ' ';
		goto errRet;
	}

	myfree(name);
	/* Get the name of this command */
	if((name = getCmdName(&(const char*)cp)) == 0 || is_pathdelim(*cp))
		goto errRet;

	StrFUpr(name);			/* all aliases are uppercased */
	if((ofs = env_findVar(ctxtAlias, name)) == (unsigned)-1)
		/* not found -> no alias */
		goto errRet;

	/* Prevent recursion by recording the offset of the found variable */
	for(i = 0; i < numExpanded; ++i)
		if(expanded[i] == ofs)		/* already used -> ignore */
			goto errRet;

	if((he = realloc(expanded, ++numExpanded)) == 0) {
		error_out_of_memory();
		goto errRet;
	}
	expanded = he;
	expanded[numExpanded - 1] = ofs;

	/************ Expand the command line "cp" with the alias at
						MK_FP(ctxtAlias, ofs)  ***********************/
	alias = ctxtP(ctxtAlias, ofs + strlen(name) + 1);
		/* Check that the total command line won't overflow MAX_INT */
	if((newlen = strlen(alias)) >= 0
	 && (len = strlen(cp)) >= 0 && ++len > 0 && newlen + len > 0) {
	 	int dst = cp - cmd;		/* destination index within cmd[] */
	 	if(newlen > dst) {
	 		/* need to increase the buffer */
	 		char *p;

	 		if((p = realloc(cmd, newlen + len)) == 0)
	 			goto errRet1;

	 		cmd = p;
	 	}
	 	/* else ignore to shrink the buffer; it will be done
	 		automatically with the next ALIAS expansion or when
	 		this function returns */
	 	assert(len);
	 	if(newlen != dst)
	 		/* need to move the command tail */
	 		memmove(&cmd[newlen], &cmd[dst], len);

		/* prepend alias value to remaining command line */
		memcpy(cmd, alias, newlen);
		goto redo;				/* next expansion */
	}

errRet1:
	error_long_internal_line();

errRet:							/* return to caller */
	myfree(expanded);
	myfree(name);

	return StrTrim(cmd);
}