This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
internal compiler error
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: internal compiler error
- From: Aaron Maxwell <amaxwell at phy dot ucsf dot EDU>
- Date: Thu, 5 Aug 1999 11:13:55 -0700 (PDT)
Hi. I tried to compile LyX 1.0.3, using egcs 2.90.29, and received an
internal compiler error. I've attached a script of the compilation
session ("bug-typescript") and the .C file that the compiler blew
chunks on ("math_macro.C"). The compilation was run as root.
I obtained the LyX source from ftp.lyx.org . My Linux distro is Debian
2.0 ("Hamm").
`uname -a` on my system yields:
Linux leper-messiah 2.2.9 #2 Sun May 16 08:19:25 PDT 1999 i586 unknown
The hardware is an old Cyrix P150 clone, 32mb ram. I ran the compilation
in console mode (i.e., not in X).
On my system, the compiler is executed as `gcc` (as opposed to `egcs`);
`gcc --version` yields "2.7.2.3". From looking in the "specs" file in the
egcs lib directory, egcs' version is "2.90.29". I'm not super clear on
the relation between egcs and gcc, but hopefully i've given you all the
information you need to figure out which compiler I used. Good luck, let
me know if i can help more, and thanks much for the free hi-quality (rare
bugs like this notwithstanding) compiler!
Aaron
Script started on Wed Aug 4 10:35:07 1999
[0;10m[27m[24m[Jleper-messiah[1]# [K../config/
config/ config.status* configure* configure.cmd*[A[0;10m[27m[24m
# ig/
[Jzsh: permission denied: ./config
[0;10m[27m[24m[Jleper-messiah[2]# [K./config gure
configure* configure.cmd*[A[0;10m[27m[24m
# igure
[Jcreating cache ./config.cache
configuring LyX version 1.0.3
checking for prefix by checking for lyx... no
checking whether make sets ${MAKE}... yes
checking for a BSD compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for POSIXized ISC... no
checking how to run the C preprocessor... gcc -E
checking for AIX... no
checking for HP-UX... no
checking for SunOS 4.x... no
checking for SCO 3.2v4... no
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for executable suffix... no
checking for a working C++ compiler... g++
checking whether the C++ compiler (g++ ) is a cross-compiler... no
checking whether we are using GNU C++... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for sin in -lm... yes
checking for fopen in -lc... yes
checking size of void *... 4
checking size of int... 4
checking for gcc strength-reduce bug... no
checking whether the C++ compiler understands explicit... yes
checking for extra library directory... NONE
checking for extra include directory... NONE
checking for extra lib+include directory... NONE
checking for main in -liberty... no
checking for ptsname in -lpt... no
checking for X... libraries /usr/X11R6/lib, headers /usr/X11R6/include
checking for dnet_ntoa in -ldnet... no
checking for dnet_ntoa in -ldnet_stub... no
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking for XOpenIM... yes
checking for XpmCreateBufferFromImage in -lXpm... yes
checking for X11/xpm.h... yes
checking xpm header version... 4.7 (aka 3.4g)
checking for fl_initialize in -lforms... yes
checking for X11/forms.h... no
checking for forms.h... yes
checking xforms header version... 0.88
checking for dirent.h that defines DIR... yes
checking for opendir in -ldir... no
checking whether sys/types.h defines makedev... no
checking for sys/mkdev.h... no
checking for sys/sysmacros.h... yes
checking whether stat file-mode macros are broken... no
checking for errno.h... yes
checking for sys/time.h... yes
checking for sys/types.h... yes
checking for sys/select.h... yes
checking whether time.h and sys/time.h may both be included... yes
checking for ranlib... ranlib
checking for ANSI C header files... yes
checking for working const... yes
checking for inline... inline
checking for off_t... yes
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for unistd.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking for argz.h... yes
checking for limits.h... yes
checking for locale.h... yes
checking for nl_types.h... yes
checking for malloc.h... yes
checking for string.h... yes
checking for unistd.h... (cached) yes
checking for values.h... yes
checking for sys/param.h... yes
checking for getcwd... yes
checking for munmap... yes
checking for putenv... yes
checking for setenv... yes
checking for setlocale... yes
checking for strchr... yes
checking for strcasecmp... yes
checking for __argz_count... yes
checking for __argz_stringify... yes
checking for __argz_next... yes
checking for stpcpy... yes
checking for LC_MESSAGES... yes
checking whether NLS is requested... yes
checking whether included gettext is requested... no
checking for libintl.h... yes
checking for gettext in libc... yes
checking for msgfmt... no
checking whether catgets can be used... no
checking for msgfmt... (cached) no
checking for gmsgfmt... no
checking for xgettext... :
checking for catalogs to be installed... cs da de es fi fr hu it nl no pl pt ru sl sv tr wa
checking for mkfifo... yes
checking for memmove... yes
checking for memset... yes
checking for strchr... (cached) yes
checking types of arguments for select()... int,fd_set *,struct timeval *
checking for strerror... yes
checking for atexit... yes
checking for bool type... yes
checking for perl >= 5.002... /usr/bin/perl
updating cache ./config.cache
creating ./config.status
creating Makefile
creating src/Makefile
creating lib/Makefile
creating intl/Makefile
creating po/Makefile.in
creating lib/reLyX/reLyX
creating lib/reLyX/noweb2lyx
creating src/config.h
src/config.h is unchanged
linking ./intl/libgettext.h to src/libintl.h
configuring in lib
running /bin/sh ./configure --cache-file=.././config.cache --srcdir=.
checking for a LaTeX2e program...
+checking for "latex"... yes
checking for reLyX LaTeX-to-LyX translator...
+checking for "reLyX"... yes
checking for a Literate programming processor...
+checking for "noweave"... no
checking for a Postscript interpreter...
+checking for "gs"... yes
checking for a Postscript previewer...
+checking for "gv"... yes
checking for a *roff formatter...
+checking for "groff"... yes
checking for ChkTeX...
+checking for "chktex"... no
checking for a spell-checker...
+checking for "ispell"... yes
checking for a fax driver...
+checking for "sendfax"... no
+checking for "faxsend"... no
+checking for "fax"... no
checking for SGML-tools (aka LinuxDoc-SGML)...
+checking for "sgml2lyx"... no
checking for a spool command...
+checking for "lp"... no
+checking for "lpr"... yes
checking LaTeX configuration... auto
+Inspecting your LaTeX configuration.
+checking for LaTeX version... 1997/12/01
+checking for default encoding (this may take a long time)
+ checking for ec fonts... yes
+ checking for ec support in LaTeX format... yes
+checking for document class IEEEtran [IEEEtran.cls]... no
+checking for document class aapaper [aa]... no
+checking for document class amsart-plain [amsart]... yes
+checking for document class amsart-seq [amsart]... yes
+checking for document class amsart [amsart.cls]... yes
+checking for document class amsbook [amsbook.cls]... yes
+checking for document class apa [apa,apacite.sty]... no
+checking for document class article [article.cls]... yes
+checking for document class book [book.cls]... yes
+checking for document class broadway [broadway]... no
+checking for document class dinbrief [dinbrief.cls]... yes
+checking for document class egs [egs.cls]... no
+checking for document class ejour2 [ejour2.cls]... no
+checking for document class foils [foils.cls]... no
+checking for document class hollywood [hollywood]... no
+checking for document class iletter [iletter.cls]... no
+checking for document class latex8 [article,latex8.sty,times.sty]... no
+checking for document class letter [letter.cls]... yes
+checking for sgml class SGML (LinuxDoc article)... no
+checking for document class literate-article [article,noweb.sty]... no
+checking for document class literate-book [book,noweb.sty]... no
+checking for document class literate-report [report,noweb.sty]... no
+checking for sgml class SGML (LinuxDoc manpage)... no
+checking for document class paper [paper.cls]... no
+checking for document class report [report.cls]... yes
+checking for document class revtex [revtex.cls]... yes
+checking for document class scrartcl [scrartcl]... no
+checking for document class scrbook [scrbook]... no
+checking for document class scrlettr [scrlettr]... no
+checking for document class scrreprt [scrreprt]... no
+checking for document class slides [slides.cls]... yes
+checking for package a4 [a4.sty]... no
+checking for package a4wide [a4wide.sty]... yes
+checking for package babel [babel.sty]... yes
+checking for package color [color.sty]... yes
+checking for package fancyhdr [fancyhdr.sty]... yes
+checking for package floatflt [floatflt.sty]... yes
+checking for package setspace [setspace.sty]... yes
+checking for package subfigure [subfigure.sty]... yes
+checking for package geometry [geometry.sty]... yes
+checking for package linuxdoc-sgml [linuxdoc-sgml.sty]... no
+checking for package longtable [longtable.sty]... yes
+checking for package algorithm [algorithm.sty]... yes
+checking for package rotating [rotating.sty]... yes
+checking for package latex8 [latex8.sty]... no
+checking for package url [url.sty]... yes
+checking for package graphics [graphics.sty]... yes
+checking for graphics driver... default
+checking for package psnfss [times.sty]... yes
+Inspection done.
+Read the file doc/LaTeXConfig.lyx for more information.
creating textclass.lst
creating packages.lst
creating doc/LaTeXConfig.lyx
creating lyxrc.defaults
Configuration:
Source code location: .
Compiler: g++
Compiler flags: -g -O2
LyX binary dir: /usr/local/bin
LyX files dir: /usr/local/share/lyx
Special flags:
Configuration of LyX was successful.
Type 'make' to compile the program,
and then 'make install' to install it.
[0;10m[27m[24m[Jleper-messiah[3]# [Klless l mmake
for dir in intl po src lib ; do \
(cd $dir ; make all) || exit 1; \
done
make[1]: Entering directory `/usr/src/lyx-1.0.3/intl'
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 intl-compat.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 bindtextdom.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 dcgettext.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 dgettext.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 gettext.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 finddomain.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 loadmsgcat.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 localealias.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 textdomain.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 l10nflist.c
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DGNULOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale:.\" -DHAVE_CONFIG_H -I../src -I. -I../src -I../intl -I/usr/X11R6/include -g -O2 explodename.c
rm -f libintl.a
ar cru libintl.a intl-compat.o bindtextdom.o dcgettext.o dgettext.o gettext.o finddomain.o loadmsgcat.o localealias.o textdomain.o l10nflist.o explodename.o
ranlib libintl.a
make[1]: Leaving directory `/usr/src/lyx-1.0.3/intl'
make[1]: Entering directory `/usr/src/lyx-1.0.3/po'
PATH=../src:$PATH cp ./lyx.pot ./lyx.po ; : --default-domain=lyx --directory=.. \
--add-comments --keyword=_ --keyword=N_ \
--files-from=./POTFILES.in
rm -f ./lyx.pot
mv lyx.po ./lyx.pot
rm -f cat-id-tbl.tmp
sed -f ../intl/po2tbl.sed ./lyx.pot \
| sed -e "s/@PACKAGE NAME@/lyx/" > cat-id-tbl.tmp
if cmp -s cat-id-tbl.tmp ./cat-id-tbl.c; then \
rm cat-id-tbl.tmp; \
else \
echo cat-id-tbl.c changed; \
rm -f ./cat-id-tbl.c; \
mv cat-id-tbl.tmp ./cat-id-tbl.c; \
fi
cd . && rm -f stamp-cat-id && echo timestamp > stamp-cat-id
file=./`echo cs | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file cs.po;; \
*) touch $file ;; \
esac
file=./`echo da | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file da.po;; \
*) touch $file ;; \
esac
file=./`echo de | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file de.po;; \
*) touch $file ;; \
esac
file=./`echo es | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file es.po;; \
*) touch $file ;; \
esac
file=./`echo fi | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file fi.po;; \
*) touch $file ;; \
esac
file=./`echo fr | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file fr.po;; \
*) touch $file ;; \
esac
file=./`echo hu | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file hu.po;; \
*) touch $file ;; \
esac
file=./`echo it | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file it.po;; \
*) touch $file ;; \
esac
file=./`echo nl | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file nl.po;; \
*) touch $file ;; \
esac
file=./`echo no | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file no.po;; \
*) touch $file ;; \
esac
file=./`echo pl | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file pl.po;; \
*) touch $file ;; \
esac
file=./`echo pt | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file pt.po;; \
*) touch $file ;; \
esac
file=./`echo ru | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file ru.po;; \
*) touch $file ;; \
esac
file=./`echo sl | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file sl.po;; \
*) touch $file ;; \
esac
file=./`echo sv | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file sv.po;; \
*) touch $file ;; \
esac
file=./`echo tr | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file tr.po;; \
*) touch $file ;; \
esac
file=./`echo wa | sed 's,.*/,,'`.gmo \
&& case "PATH=../src:$PATH no" in \
*/msgfmt) rm -f $file && PATH=../src:$PATH no -o $file wa.po;; \
*) touch $file ;; \
esac
make[1]: Leaving directory `/usr/src/lyx-1.0.3/po'
make[1]: Entering directory `/usr/src/lyx-1.0.3/src'
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include -DPACKAGE=\"lyx\" -DLOCALEDIR=\"/usr/local/share/locale\" ../src/main.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include -DLYX_DIR=\"/usr/local/share/lyx\" -DTOP_SRCDIR=\"..\" -DLYX_NAME=\"lyx\" ../src/lyx_main.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyx_gui.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyx.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyx_cb.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyxfr0.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyxfr1.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include inset.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyxfont.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include texrow.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include paragraph.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include layout.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include screen.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include text.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include text2.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include spellchecker.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include kbmap.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include bmtable.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include math_symbols.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include lyxfunc.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include credits.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include menus.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include intl.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include form1.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include credits_form.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include layout_forms.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include print_form.C
g++ -c -g -O2 -I. -I. -I../images -I/usr/X11R6/include math_macro.C
math_macro.C: In method `bool MathMatrixInset::isMatrix()':
math_macro.C:551: Internal compiler error.
math_macro.C:551: Please submit a full bug report to `egcs-bugs@cygnus.com'.
make[1]: *** [math_macro.o] Error 1
make[1]: Leaving directory `/usr/src/lyx-1.0.3/src'
make: *** [all] Error 1
[0;10m[27m[24m[Jleper-messiah[4]# [K
Script done on Wed Aug 4 12:29:52 1999
// -*- C++ -*-
/*
* File: math_macro.C
* Purpose: Implementation of macro class for mathed
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
* Created: November 1996
* Description: WYSIWYG math macros
*
* Dependencies: Mathed
*
* Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
*
* Version: 0.2, Mathed & Lyx project.
*
* This code is under the GNU General Public Licence version 2 or later.
*/
#include <config.h>
#include FORMS_H_LOCATION
#ifdef __GNUG__
#pragma implementation "math_macro.h"
#pragma implementation "math_defs.h"
#endif
#include "LString.h"
#include "math_macro.h"
#include "math_iter.h"
#include "math_inset.h"
#include "error.h"
enum MathedMacroFlag {
MMF_Env=1,
MMF_Exp=2,
MMF_Edit=4
};
extern GC mathGC, mathFrameGC, latexGC;
extern int mathed_string_width(short type, int style, byte const* s, int ls);
extern int mathed_string_height(short, int, byte const*, int, int&, int&);
MathMacro::MathMacro(MathMacroTemplate* t):
MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate(t)
{
nargs = tmplate->getNoArgs();
tcode = tmplate->getTCode();
args = new MacroArgumentBase[nargs];
for (int i=0; i<nargs; i++) {
// if (tmplate->getMacroPar(i)->Permit(LMPF_ALLOW_CR))
// args[i].row = new MathedRowSt(tmplate->getMacroPar(i)->GetColumns());
// else
args[i].row = 0;
/* int k = tmplate->getMacroPar(i)->GetColumns();
if (k>0) {
args[i].array = new LyxArrayBase;
for (int j=0; j<k-1; j++) args[i].array->Insert(j, LM_TC_TAB);
}*/
}
idx = 0;
SetName(tmplate->GetName());
}
MathMacro::MathMacro(MathMacro* m):
MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
{
tmplate = m->tmplate;
nargs = tmplate->getNoArgs();
tcode = tmplate->getTCode();
args = new MacroArgumentBase[nargs];
idx = 0;
SetName(tmplate->GetName());
for (int i=0; i<tmplate->nargs; i++) {
m->setArgumentIdx(i);
MathedIter it(m->GetData());
args[i].row = m->args[i].row;
args[i].array = it.Copy();
}
}
MathMacro::~MathMacro()
{
for (idx=0; idx<nargs; idx++) {
MathedIter it(args[idx].array);
it. Clear();
delete args[idx].row;
}
delete[] args;
}
MathedInset *MathMacro::Clone()
{
MathMacro *m = new MathMacro(this);
return m;
}
void MathMacro::Metrics()
{
if (nargs>0)
tmplate->update(this);
tmplate->Metrics();
width = tmplate->Width();
ascent = tmplate->Ascent();
descent = tmplate->Descent();
}
void MathMacro::Draw(int x, int y)
{
xo = x; yo = y;
Metrics();
tmplate->update(this);
tmplate->SetStyle(size);
mathGC = latexGC;
tmplate->Draw(x, y);
for (int i=0; i<nargs; i++)
tmplate->GetMacroXY(i, args[i].x, args[i].y);
}
int MathMacro::GetColumns()
{
return tmplate->getMacroPar(idx)->GetColumns();
}
void MathMacro::GetXY(int& x, int& y) const
{
x = args[idx].x; y = args[idx].y;
}
bool MathMacro::Permit(short f)
{
return ((nargs>0) ? tmplate->getMacroPar(idx)->Permit(f): MathParInset::Permit(f));
}
void MathMacro::SetFocus(int x, int y)
{
tmplate->update(this);
tmplate->SetMacroFocus(idx, x, y);
}
void MathMacro::Write(FILE *file)
{
LString output;
MathMacro::Write(output);
fprintf(file, "%s", output.c_str());
}
void MathMacro::Write(LString &file)
{
if (tmplate->flags & MMF_Exp) {
lyxerr.debug(LString("Expand ")+ int(tmplate->flags)
+ ' ' + int(MMF_Exp),
Error::MATHED);
tmplate->update(this);
tmplate->Write(file);
} else {
if (tmplate->flags & MMF_Env) {
file += "\\begin{";
file += name;
file += "} ";
} else {
file += '\\';
file += name;
}
// if (options) {
// file += '[';
// file += options;
// file += ']';
// }
if (!(tmplate->flags & MMF_Env) && nargs>0)
file += '{';
for (int i=0; i<nargs; i++) {
array = args[i].array;
MathParInset::Write(file);
if (i<nargs-1)
file += "}{";
}
if (tmplate->flags & MMF_Env) {
file += "\\end{";
file += name;
file += '}';
} else {
if (nargs>0)
file += '}';
else
file += ' ';
}
}
}
/*--------------- Macro argument -----------------------------------*/
MathMacroArgument::MathMacroArgument(int n)
{
number = n;
expnd_mode = false;
SetType(LM_OT_MACRO_ARG);
}
void MathMacroArgument::Draw(int x, int baseline)
{
if (expnd_mode) {
MathParInset::Draw(x, baseline);
} else {
unsigned char s[3];
sprintf((char*)s, "#%d", number);
drawStr(LM_TC_TEX, size, x, baseline, &s[0], 2);
}
}
void MathMacroArgument::Metrics()
{
if (expnd_mode) {
MathParInset::Metrics();
} else {
unsigned char s[3];
sprintf((char*)s, "#%d", number);
width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
}
}
void MathMacroArgument::Write(FILE *file)
{
LString output;
MathMacroArgument::Write(output);
fprintf(file, "%s", output.c_str());
}
void MathMacroArgument::Write(LString &file)
{
if (expnd_mode) {
MathParInset::Write(file);
} else {
file += '#';
file += number;
file += ' ';
}
}
/* --------------------- MathMacroTemplate ---------------------------*/
MathMacroTemplate::MathMacroTemplate(char const *nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags(flg), nargs(na)
{
if (nargs>0) {
tcode = LM_TC_ACTIVE_INSET;
args = new MathMacroArgument[nargs];
for (int i=0; i<nargs; i++) {
args[i].setNumber(i+1);
}
} else
tcode = LM_TC_INSET;
}
MathMacroTemplate::~MathMacroTemplate()
{
// prevent to delete already deleted objects
for (int i=0; i<nargs; i++) {
args[i].SetData(0);
}
delete[] args;
}
void MathMacroTemplate::setEditMode(bool ed)
{
if (ed) {
flags |= MMF_Edit;
for (int i=0; i<nargs; i++) {
args[i].setExpand(false);
}
} else {
flags &= ~MMF_Edit;
for (int i=0; i<nargs; i++) {
args[i].setExpand(true);
}
}
}
void MathMacroTemplate::Draw(int x, int y)
{
int x2, y2;
bool expnd = (nargs>0) ? args[0].getExpand(): false;
if (flags & MMF_Edit) {
for (int i=0; i<nargs; i++) {
args[i].setExpand(false);
}
x2 = x; y2 = y;
} else {
for (int i=0; i<nargs; i++) {
args[i].setExpand(true);
}
x2 = xo; y2 = yo;
}
MathParInset::Draw(x, y);
xo = x2; yo = y2;
for (int i=0; i<nargs; i++) {
args[i].setExpand(expnd);
}
}
void MathMacroTemplate::Metrics()
{
bool expnd = (nargs>0) ? args[0].getExpand(): false;
if (flags & MMF_Edit) {
for (int i=0; i<nargs; i++) {
args[i].setExpand(false);
}
} else {
for (int i=0; i<nargs; i++) {
args[i].setExpand(true);
}
}
MathParInset::Metrics();
for (int i=0; i<nargs; i++) {
args[i].setExpand(expnd);
}
}
void MathMacroTemplate::update(MathMacro* macro)
{
int idx = (macro) ? macro->getArgumentIdx(): 0;
for (int i=0; i<nargs; i++) {
if (macro) {
macro->setArgumentIdx(i);
args[i].SetData(macro->GetData());
MathedRowSt *row = macro->getRowSt();
args[i].setRowSt(row);
}
}
if (macro)
macro->setArgumentIdx(idx);
}
void MathMacroTemplate::WriteDef(FILE *file)
{
fprintf(file, "\n\\newcommand{\\%s}", name);
if (nargs > 0 )
fprintf(file, "[%d]", nargs);
fprintf(file, "{");
for (int i=0; i<nargs; i++) {
args[i].setExpand(false);
}
Write(file);
fprintf(file, "}\n");
}
void MathMacroTemplate::WriteDef(LString &file)
{
file += "\n\\newcommand{\\";
file += name;
file += '}';
if (nargs > 0 ) {
file += '[';
file += nargs;
file += ']';
}
file += '{';
for (int i=0; i<nargs; i++) {
args[i].setExpand(false);
}
Write(file);
file += "}\n";
}
void MathMacroTemplate::setArgument(LyxArrayBase *a, int i)
{
args[i].SetData(a);
}
void MathMacroTemplate::GetMacroXY(int i, int& x, int& y) const
{
args[i].GetXY(x, y);
}
MathParInset *MathMacroTemplate::getMacroPar(int i) const
{
return ((i>=0 && i<nargs) ? (MathParInset*)&args[i]: 0);
}
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
{
for (int i=0; i<nargs; i++) {
if (args[i].Inside(x, y)) {
idx = i;
break;
}
}
}
/* -------------------------- MathMacroTable -----------------------*/
MathMacroTable::MathMacroTable(int n): max_macros(n)
{
macro_table = new MathMacroTemplateP[max_macros];
num_macros = 0;
}
MathMacroTable::~MathMacroTable()
{
delete[] macro_table;
}
// The search is currently linear but will be binary or hash, later.
MathMacroTemplate *MathMacroTable::getTemplate(char const* name) const
{
for (int i=0; i<num_macros; i++) {
if (strcmp(name, macro_table[i]->GetName())==0)
return macro_table[i];
}
return 0;
}
void MathMacroTable::addTemplate(MathMacroTemplate *m)
{
if (num_macros<max_macros)
macro_table[num_macros++] = m;
else
lyxerr.print("Error (MathMacroTable::addTemplate): "
"Macro table exhausted!");
}
// All this stuff aparently leaks because it's created here and is not
// deleted never, but it have to live all the LyX sesion. OK, would not
// so hard to do it in the MacroTable destructor, but this doesn't harm
// seriously, so don't bother me with purify results here. ;-)
void MathMacroTable::builtinMacros()
{
MathMacroTemplate *m;
MathedIter iter;
MathParInset* inset;// *arg;
LyxArrayBase *array, *array2;
built = true;
lyxerr.debug("Building macros", Error::MATHED);
// This macro doesn't have arguments
m = new MathMacroTemplate("notin"); // this leaks
addTemplate(m);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
m->SetData(array);
// These two are only while we are still with LyX 2.x
m = new MathMacroTemplate("emptyset"); // this leaks
addTemplate(m);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
m->SetData(array);
m = new MathMacroTemplate("perp"); // this leaks
addTemplate(m);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(LM_bot, LM_TC_BOP);
m->SetData(array);
// binom has two arguments
m = new MathMacroTemplate("binom", 2);
addTemplate(m);
array = new LyxArrayBase;
m->SetData(array);
iter.SetData(array);
inset = new MathDelimInset('(', ')');
iter.Insert(inset, LM_TC_ACTIVE_INSET);
array = new LyxArrayBase;
iter.SetData(array);
MathFracInset *frac = new MathFracInset(LM_OT_ATOP);
iter.Insert(frac, LM_TC_ACTIVE_INSET);
inset->SetData(array);
array = new LyxArrayBase;
array2 = new LyxArrayBase;
iter.SetData(array);
iter.Insert(m->getMacroPar(0));
iter.SetData(array2);
iter.Insert(m->getMacroPar(1));
frac->SetData(array, array2);
/*
// Cases has 1 argument
m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
addTemplate(m);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
arg = new MathMatrixInset(2,1); // this leaks
m->setArgument(arg);
arg->SetAlign('c',"ll");
iter.Insert(arg, LM_TC_ACTIVE_INSET);
inset = new MathDelimInset('{', '.'); // this leaks
inset->SetData(array);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(inset, LM_TC_ACTIVE_INSET);
m->SetData(array);
// the environment substack has 1 argument
m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
addTemplate(m);
arg = new MathMatrixInset(1,1); // this leaks
m->setArgument(arg);
arg->SetType(LM_OT_MACRO);
array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(arg, LM_TC_ACTIVE_INSET);
m->SetData(array);*/
}
MathMacroTable MathMacroTable::mathMTable(255);
bool MathMacroTable::built = false;