Пример #1
0
Inset::idx_type Inset::index(row_type row, col_type col) const
{
	if (row != 0)
		LYXERR0("illegal row: " << row);
	if (col != 0)
		LYXERR0("illegal col: " << col);
	return 0;
}
Пример #2
0
void Row::dump(char const * s) const
{
	LYXERR0(s << " pos: " << pos_ << " end: " << end_
		<< " width: " << dim_.wid
		<< " ascent: " << dim_.asc
		<< " descent: " << dim_.des);
}
Пример #3
0
void Inset::cursorPos(BufferView const & /*bv*/, CursorSlice const &,
		bool, int & x, int & y) const
{
	LYXERR0("Inset::cursorPos called directly");
	x = 100;
	y = 100;
}
Пример #4
0
void doAssert(char const * expr,  char const * file, long line)
{
    // TODO Should we try to print the call stack before exiting?

	LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
	// comment this out if not needed
	BOOST_ASSERT(false);
}
Пример #5
0
// the ref argument is the label name we are referencing.
// we expect ref to be in the form: pfx:suffix.
//
// if it isn't, then we can't produce a formatted reference, 
// so we return "\ref" and put ref into label.
//
// for refstyle, we return "\pfxcmd", and put suffix into 
// label and pfx into prefix. this is because refstyle expects
// the command: \pfxcmd{suffix}.
// 
// for prettyref, we return "\prettyref" and put ref into label
// and pfx into prefix. this is because prettyref uses the whole
// label, thus: \prettyref{pfx:suffix}.
//
docstring InsetRef::getFormattedCmd(docstring const & ref, 
	docstring & label, docstring & prefix) const
{
	static docstring const defcmd = from_ascii("\\ref");
	static docstring const prtcmd = from_ascii("\\prettyref");
	
	label = split(ref, prefix, ':');

	// we have to have xxx:xxxxx...
	if (label.empty()) {
		LYXERR0("Label `" << ref << "' contains no prefix.");
		label = ref;
		prefix = from_ascii("");
		return defcmd;
	}

	if (prefix.empty()) {
		// we have ":xxxx"
		label = ref;
		return defcmd;
	}
	
	if (!buffer().params().use_refstyle) {
		// \prettyref uses the whole label
		label = ref;
		return prtcmd;
	}

	// make sure the prefix is legal for a latex command
	int const len = prefix.size();
	for (int i = 0; i < len; i++) {
		char_type const c = prefix[i];
		if (!isAlphaASCII(c)) {
			LYXERR0("Prefix `" << prefix << "' is invalid for LaTeX.");
			// restore the label
			label = ref;
			return defcmd;
		}
	}
	return from_ascii("\\") + prefix + from_ascii("ref");
}
Пример #6
0
void CacheMimeData::update()
{
	time_t const start_time = current_time();
	LYXERR(Debug::ACTION, "Creating CacheMimeData object");
	cached_formats_ = read_clipboard()->formats();

	// Qt times out after 5 seconds if it does not recieve a response.
	if (current_time() - start_time > 3) {
		LYXERR0("No timely response from clipboard, perhaps process "
			<< "holding clipboard is frozen?");
	}
}
Пример #7
0
void Dialog::showData(string const & data)
{
	if (isBufferDependent() && !isBufferAvailable())
		return;

	if (!initialiseParams(data)) {
		LYXERR0("Dialog \"" << name()
			<< "\" failed to translate the data string passed to show()");
		return;
	}

	showView();
}
Пример #8
0
// Returns a file descriptor for a new connection from the socket
// descriptor 'sd' (or -1 in case of error)
int accept(int sd)
{
	int fd;

	// Returns the new file descriptor or -1 in case of error
	// Using null pointers for the second and third arguments
	// dismiss all information about the connecting client
	if ((fd = accept(sd, reinterpret_cast<sockaddr *>(0), reinterpret_cast<socklen_t *>(0))) == -1) {
		LYXERR0("lyx: Could not accept connection: "
		       << strerror(errno));
		return -1;
	}

	// Sets NONBLOCK mode for the file descriptor
	if (::fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
		LYXERR0("lyx: Could not set NONBLOCK mode for connection: "
		       << strerror(errno));
		::close(fd);
		return -1;
	}
	return fd;
}
Пример #9
0
Buffer & Inset::buffer()
{
	if (!buffer_) {
		odocstringstream s;
		string const iname = insetName(lyxCode());
		LYXERR0("Inset: " << this << " LyX Code: " << lyxCode()
					<< " name: " << iname);
		s << "LyX Code: " << lyxCode() << " name: " << iname;
		LATTEST(false);
		throw ExceptionMessage(BufferException, 
			from_ascii("Inset::buffer_ member not initialized!"), s.str());
	}
	return *buffer_;
}
Пример #10
0
static QMimeData const * read_clipboard() 
{
	LYXERR(Debug::ACTION, "Getting Clipboard");
	QMimeData const * source =
		qApp->clipboard()->mimeData(QClipboard::Clipboard);
	if (!source) {
		LYXERR0("0 bytes (no QMimeData)");
		return new QMimeData;
	}
	// It appears that doing IO between getting a mimeData object
	// and using it can cause a crash (maybe Qt used IO
	// as an excuse to free() it? Anyway let's not introduce
	// any new IO here, so e.g. leave the following line commented.
	// lyxerr << "Got Clipboard (" << (long) source << ")\n" ;
	return source;
}
Пример #11
0
int class_spacing(MathClass const mc1, MathClass const mc2,
                  MetricsBase const & mb)
{
	int spc_code = pair_spc[mc1][mc2];
	//lyxerr << class_to_string(mc1) << "+" << class_to_string(mc2)
	//	   << "=" << spc_code << " @" << mb.style << endl;
	if (spc_code < 0) {
		switch (mb.font.style()) {
		case LM_ST_DISPLAY:
		case LM_ST_TEXT:
		case LM_ST_IGNORE:
		case LM_ST_INHERIT:
			spc_code = abs(spc_code);
			break;
		case LM_ST_SCRIPT:
		case LM_ST_SCRIPTSCRIPT:
			spc_code = 0;
		}
	}

	int spc = 0;
	switch(spc_code) {
	case 0:
		break;
	case 1:
		spc = mathed_thinmuskip(mb.font);
		break;
	case 2:
		spc = mathed_medmuskip(mb.font);
		break;
	case 3:
		spc = mathed_thickmuskip(mb.font);
		break;
	default:
		LYXERR0("Impossible pair of classes: (" << mc1 << ", " << mc2 << ")");
		LATTEST(false);
	}
	return spc;
}
Пример #12
0
bool InsetCitation::addKey(string const & key)
{
	docstring const ukey = from_utf8(key);
	docstring const & curkeys = getParam("key");
	if (curkeys.empty()) {
		setParam("key", ukey);
		cache.recalculate = true;
		return true;
	}

	vector<docstring> keys = getVectorFromString(curkeys);
	vector<docstring>::const_iterator it = keys.begin();
	vector<docstring>::const_iterator en = keys.end();
	for (; it != en; ++it) {
		if (*it == ukey) {
			LYXERR0("Key " << key << " already present.");
			return false;
		}
	}
	keys.push_back(ukey);
	setParam("key", getStringFromVector(keys));
	cache.recalculate = true;
	return true;
}
Пример #13
0
bool CmdDef::read(string const & def_file)
{
	enum {
		BN_DEFFILE,
		BN_DEFINE
	};

	LexerKeyword cmdDefTags[] = {
		{ "\\def_file", BN_DEFFILE },
		{ "\\define", BN_DEFINE }
	};

	Lexer lex(cmdDefTags);
	FileName const tmp(i18nLibFileSearch("commands", def_file, "def"));
	lex.setContext("CmdDef::read");
	lex.setFile(tmp);
	if (!lex.isOK()) {
		LYXERR0( "CmdDef::read: cannot open def file:" << tmp);
		return false;
	}

	bool error = false;
	while (lex.isOK()) {
		switch (lex.lex()) {
		case Lexer::LEX_UNDEF:
			lex.printError("Unknown tag");
			error = true;
			continue;
		case Lexer::LEX_FEOF:
			continue;
		case BN_DEFINE:
		{
			string name, def;

			if (lex.next()) {
				name = lex.getString();
			} else {
				lex.printError("BN_DEFINE: Missing command name");
				error = true;
				break;
			}

			if (lex.next(true)) {
				def = lex.getString();
			} else {
				lex.printError("BN_DEFINE: missing command definition");
				error = true;
				break;
			}

			newCmdDefResult e = newCmdDef(name, def);
			switch (e) {
			case CmdDefNameEmpty:
				lex.printError("BN_DEFINE: Command name is empty");
				error = true;
				break;
			case CmdDefExists:
				lex.printError("BN_DEFINE: Command `" + name + "' already defined");
				error = true;
				break;
			case CmdDefInvalid:
				lex.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
				error = true;
				break;
			case CmdDefOk:
				break;
			}

			break;
		}
		case BN_DEFFILE:
			if (lex.next()) {
				string const tmp = lex.getString();
				error |= !read(tmp);
			} else {
				lex.printError("BN_DEFFILE: Missing file name");
				error = true;
				break;

			}
			break;
		}
	}

	if (error)
		LYXERR0("CmdDef::read: error while reading def file:" << tmp);
	return !error;
}
Пример #14
0
// Much of this is borrowed from LayoutFileList::read()
bool ModuleList::read()
{
	FileName const real_file = libFileSearch("", "lyxmodules.lst");
	LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');

	if (real_file.empty()) {
		LYXERR0("unable to find modules file `lyxmodules.lst'.\n"
			<< "No modules will be available.");
		return false;
	}

	Lexer lex;
	if (!lex.setFile(real_file)) {
		LYXERR0("lyxlex was not able to set file: "
			<< real_file << ".\nNo modules will be available.");
		return false;
	}

	if (!lex.isOK()) {
		LYXERR0("unable to open modules file  `"
			<< to_utf8(makeDisplayPath(real_file.absFileName(), 1000))
			<< "'\nNo modules will be available.");
		return false;
	}

	bool finished = false;
	// Parse modules files
	LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
	while (lex.isOK() && !finished) {
		LYXERR(Debug::TCLASS, "\tline by line");
		switch (lex.lex()) {
		case Lexer::LEX_FEOF:
			finished = true;
			break;
		default:
			string const modname = lex.getString();
			LYXERR(Debug::TCLASS, "Module name: " << modname);
			if (!lex.next())
				break;
			string const fname = lex.getString();
			LYXERR(Debug::TCLASS, "Filename: " << fname);
			if (!lex.next(true))
				break;
			string const desc = lex.getString();
			LYXERR(Debug::TCLASS, "Description: " << desc);
			//FIXME Add packages
			if (!lex.next())
				break;
			string str = lex.getString();
			LYXERR(Debug::TCLASS, "Packages: " << str);
			vector<string> pkgs;
			while (!str.empty()) {
				string p;
				str = split(str, p, ',');
				pkgs.push_back(p);
			}
			if (!lex.next())
				break;
			str = lex.getString();
			LYXERR(Debug::TCLASS, "Required: " << str);
			vector<string> req;
			while (!str.empty()) {
				string p;
				str = split(str, p, '|');
				req.push_back(p);
			}
			if (!lex.next())
				break;
			str = lex.getString();
			LYXERR(Debug::TCLASS, "Excluded: " << str);
			vector<string> exc;
			while (!str.empty()) {
				string p;
				str = split(str, p, '|');
				exc.push_back(p);
			}
			if (!lex.next())
				break;
			string const catgy = lex.getString();
			LYXERR(Debug::TCLASS, "Category: " << catgy);
			if (!lex.next())
				break;
			bool const local = lex.getString() == "true";
			LYXERR(Debug::TCLASS, "Local: " << local);
			// This code is run when we have
			// modName, fname, desc, pkgs, req, exc, catgy, and local
			addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy, local);
		} // end switch
	} //end while

	LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");

	if (!theModuleList.empty())
		sort(theModuleList.begin(), theModuleList.end(), ModuleSorter());
	return true;
}
Пример #15
0
void PreviewLoader::Impl::startLoading(bool wait)
{
	if (pending_.empty() || !pconverter_)
		return;

	// Only start the process off after the buffer is loaded from file.
	if (!buffer_.isFullyLoaded())
		return;

	LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()");

	// As used by the LaTeX file and by the resulting image files
	string const directory = buffer_.temppath();

	string const filename_base = unique_filename(directory);

	// Create an InProgress instance to place in the map of all
	// such processes if it starts correctly.
	InProgress inprogress(filename_base, pending_, pconverter_->to);

	// clear pending_, so we're ready to start afresh.
	pending_.clear();

	// Output the LaTeX file.
	FileName const latexfile(filename_base + ".tex");

	// we use the encoding of the buffer
	Encoding const & enc = buffer_.params().encoding();
	ofdocstream of;
	try { of.reset(enc.iconvName()); }
	catch (iconv_codecvt_facet_exception const & e) {
		LYXERR0("Caught iconv exception: " << e.what()
			<< "\nUnable to create LaTeX file: " << latexfile);
		return;
	}

	TexRow texrow;
	otexstream os(of, texrow);
	OutputParams runparams(&enc);
	LaTeXFeatures features(buffer_, buffer_.params(), runparams);

	if (!openFileWrite(of, latexfile))
		return;

	if (!of) {
		LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
					<< "Unable to create LaTeX file\n" << latexfile);
		return;
	}
	of << "\\batchmode\n";
	dumpPreamble(os);
	// handle inputenc etc.
	buffer_.params().writeEncodingPreamble(os, features);
	of << "\n\\begin{document}\n";
	dumpData(of, inprogress.snippets);
	of << "\n\\end{document}\n";
	of.close();
	if (of.fail()) {
		LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
					 << "File was not closed properly.");
		return;
	}

	double const font_scaling_factor = 
		buffer_.isExporting() ? 75.0 * buffer_.params().html_math_img_scale 
			: 0.01 * lyxrc.dpi * lyxrc.zoom * lyxrc.preview_scale_factor;

	// FIXME XHTML 
	// The colors should be customizable.
	ColorCode const bg = buffer_.isExporting() 
	               ? Color_white : PreviewLoader::backgroundColor();
	ColorCode const fg = buffer_.isExporting() 
	               ? Color_black : PreviewLoader::foregroundColor();
	// The conversion command.
	ostringstream cs;
	cs << pconverter_->command
	   << " " << quoteName(latexfile.toFilesystemEncoding())
	   << " --dpi " << int(font_scaling_factor)
	   << " --fg " << theApp()->hexName(fg)
	   << " --bg " << theApp()->hexName(bg);
	// FIXME what about LuaTeX?
	if (buffer_.params().useNonTeXFonts)
		cs << " --latex=xelatex";
	if (buffer_.params().encoding().package() == Encoding::japanese)
		cs << " --latex=platex";
	if (buffer_.params().bibtex_command != "default")
		cs << " --bibtex=" << quoteName(buffer_.params().bibtex_command);
	else if (buffer_.params().encoding().package() == Encoding::japanese)
		cs << " --bibtex=" << quoteName(lyxrc.jbibtex_command);
	else
		cs << " --bibtex=" << quoteName(lyxrc.bibtex_command);
	if (buffer_.params().bufferFormat() == "lilypond-book")
		cs << " --lilypond";

	string const command = libScriptSearch(cs.str());

	if (wait) {
		ForkedCall call(buffer_.filePath());
		int ret = call.startScript(ForkedProcess::Wait, command);
		static int fake = (2^20) + 1;
		int pid = fake++;
		inprogress.pid = pid;
		inprogress.command = command;
		in_progress_[pid] = inprogress;
		finishedGenerating(pid, ret);
		return;
	}

	// Initiate the conversion from LaTeX to bitmap images files.
	ForkedCall::SignalTypePtr
		convert_ptr(new ForkedCall::SignalType);
	convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));

	ForkedCall call(buffer_.filePath());
	int ret = call.startScript(command, convert_ptr);

	if (ret != 0) {
		LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
					<< "Unable to start process\n" << command);
		return;
	}

	// Store the generation process in a list of all such processes
	inprogress.pid = call.pid();
	inprogress.command = command;
	in_progress_[inprogress.pid] = inprogress;
}
Пример #16
0
	void warning(docstring const & title, docstring const & message,
				 bool const &)
	{
		LYXERR0(title);
		LYXERR0(message);
	}
Пример #17
0
	~Impl()
	{
		if (cd != invalid_cd && iconv_close(cd) == -1)
				LYXERR0("Error returned from iconv_close(" << errno << ")");
	}
Пример #18
0
void InsetMathString::write(WriteStream & os) const
{
	if (!os.latex() || os.lockedMode()) {
		os << (os.asciiOnly() ? escape(str_) : str_);
		return;
	}

	docstring::const_iterator cit = str_.begin();
	docstring::const_iterator end = str_.end();

	// We may already be inside an \ensuremath command.
	bool in_forced_mode = os.pendingBrace();

	// We will take care of matching braces.
	os.pendingBrace(false);

	while (cit != end) {
		bool mathmode = in_forced_mode ? os.textMode() : !os.textMode();
		char_type const c = *cit;
		docstring command(1, c);
		try {
			bool termination = false;
			if (isASCII(c) ||
			    Encodings::latexMathChar(c, mathmode, os.encoding(), command, termination)) {
				if (os.textMode()) {
					if (in_forced_mode) {
						// we were inside \lyxmathsym
						os << '}';
						os.textMode(false);
						in_forced_mode = false;
					}
					if (!isASCII(c) && os.textMode()) {
						os << "\\ensuremath{";
						os.textMode(false);
						in_forced_mode = true;
					}
				} else if (isASCII(c) && in_forced_mode) {
					// we were inside \ensuremath
					os << '}';
					os.textMode(true);
					in_forced_mode = false;
				}
			} else if (!os.textMode()) {
					if (in_forced_mode) {
						// we were inside \ensuremath
						os << '}';
						in_forced_mode = false;
					} else {
						os << "\\lyxmathsym{";
						in_forced_mode = true;
					}
					os.textMode(true);
			}
			os << command;
			// We may need a space if the command contains a macro
			// and the last char is ASCII.
			if (termination)
				os.pendingSpace(true);
		} catch (EncodingException const & e) {
			switch (os.output()) {
			case WriteStream::wsDryrun: {
				os << "<" << _("LyX Warning: ")
				   << _("uncodable character") << " '";
				os << docstring(1, e.failed_char);
				os << "'>";
				break;
			}
			case WriteStream::wsPreview: {
				// indicate the encoding error by a boxed '?'
				os << "{\\fboxsep=1pt\\fbox{?}}";
				LYXERR0("Uncodable character" << " '"
					<< docstring(1, e.failed_char)
					<< "'");
				break;
			}
			case WriteStream::wsDefault:
			default:
				// throw again
				throw(e);
			}
		}
		++cit;
	}

	if (in_forced_mode && os.textMode()) {
		// We have to care for closing \lyxmathsym
		os << '}';
		os.textMode(false);
	} else {
		os.pendingBrace(in_forced_mode);
	}
}
Пример #19
0
// Returns a local socket already in the "listen" state (or -1 in case
// of error). The first argument is the socket address, the second
// is the length of the queue for connections. If successful, a socket
// special file 'name' will be created in the filesystem.
int listen(FileName const & name, int queue)
{
	int fd; // File descriptor for the socket
	sockaddr_un addr; // Structure that hold the socket address

	// We use 'localname' to fill 'addr'
	string const localname = name.toFilesystemEncoding();
	string::size_type len = localname.size();
	// the field sun_path in sockaddr_un is a char[108]
	if (len > 107) {
		LYXERR0("lyx: Socket address '" << name.absFileName() << "' too long.");
		return -1;
	}
	// Synonims for AF_UNIX are AF_LOCAL and AF_FILE
	addr.sun_family = AF_UNIX;
	localname.copy(addr.sun_path, 107);
	addr.sun_path[len] = '\0';

	// This creates a file descriptor for the socket
	// Synonims for PF_UNIX are PF_LOCAL and PF_FILE
	// For local sockets, the protocol is always 0
	// socket() returns -1 in case of error
	if ((fd = ::socket(PF_UNIX, SOCK_STREAM, 0))== -1) {
		LYXERR0("lyx: Could not create socket descriptor: "
		       << strerror(errno));
		return -1;
	}

	// Set NONBLOCK mode for the file descriptor
	if (::fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
		LYXERR0("lyx: Could not set NONBLOCK mode for socket descriptor: "
		     << strerror(errno));
		::close(fd);
		return -1;
	}

	// bind() gives the local address 'name' for 'fd', also creating
	// the socket special file in the filesystem. bind() returns -1
	// in case of error
	if ((::bind (fd, reinterpret_cast<sockaddr *>(&addr), SUN_LEN(&addr))) == -1) {
		LYXERR0("lyx: Could not bind address '" << name.absFileName()
		       << "' to socket descriptor: " << strerror(errno));
		::close(fd);
		name.removeFile();
		return -1;
	}

	// Puts the socket in listen state, that is, ready to accept
	// connections. The second parameter of listen() defines the
	// maximum length the queue of pending connections may grow to.
	// It is not a restriction on the number of connections the socket
	// can accept. Returns -1 in case of error
	if (::listen (fd, queue) == -1) {
		LYXERR0("lyx: Could not put socket in 'listen' state: "
		       << strerror(errno));
		::close(fd);
		name.removeFile();
		return -1;
	}

	return fd;
}