Example #1
0
void 
CmdFraction(int code)
/******************************************************************************
 purpose: converts \frac{x}{y} (following Taupin's implementation in ltx2rtf)
******************************************************************************/
{
	char           *denominator, *numerator, *nptr, *dptr;

	numerator = getBraceParam();
	nptr = strdup_noendblanks(numerator);
	skipSpaces();
	denominator = getBraceParam();
	dptr = strdup_noendblanks(denominator);

	free(numerator);
	free(denominator);
	diagnostics(4,"CmdFraction -- numerator   = <%s>", nptr);
	diagnostics(4,"CmdFraction -- denominator = <%s>", dptr);

	fprintRTF(" \\\\F(");
	ConvertString(nptr);
	fprintRTF("%c", g_field_separator);
	ConvertString(dptr);
	fprintRTF(")");

	free(nptr);
	free(dptr);
}
Example #2
0
static char * 
getAngleParam(void)
/******************************************************************************
  purpose: return bracketed parameter
  			
  \item<1>  --->  "1"        \item<>   --->  ""        \item the  --->  NULL
       ^                           ^                         ^
  \item <1>  --->  "1"        \item <>  --->  ""        \item  the --->  NULL
       ^                           ^                         ^
 ******************************************************************************/
{
	char            c, *text;
	
	c = getNonBlank();

	if (c == '<') {
		text = getDelimitedText('<','>',TRUE);
		diagnostics(5, "getAngleParam [%s]", text);

	} else {
		ungetTexChar(c);
		text = NULL;
		diagnostics(5, "getAngleParam []");
	}
	
	return text;
}
Example #3
0
void 
CmdFontSize(int code)
/******************************************************************************
 purpose : handles LaTeX commands that change the font size
******************************************************************************/
{
	int             scaled_size;

	diagnostics(4,"CmdFontSize (before) depth=%d, family=%d, size=%d, shape=%d, series=%d",\
				   FontInfoDepth, RtfFontInfo[FontInfoDepth].family, \
	               RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape,\
	               RtfFontInfo[FontInfoDepth].series);

	if (code == F_SMALLER) 
		scaled_size = (int) (CurrentFontSize() / 1.2 + 0.5);
	else if (code == F_LARGER) 
		scaled_size = (int) (CurrentFontSize() * 1.2 + 0.5);
	else
		scaled_size = (int) (code * DefaultFontSize() / 20.0 + 0.5);

	fprintRTF("\\fs%d ", scaled_size);

	diagnostics(4,"CmdFontSize (after) depth=%d, family=%d, size=%d, shape=%d, series=%d",\
				   FontInfoDepth, RtfFontInfo[FontInfoDepth].family, \
	               RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape,\
	               RtfFontInfo[FontInfoDepth].series);
}
Example #4
0
void
CmdIndex(int code)
/******************************************************************************
purpose: convert \index{classe!article@\textit{article}!section}
              to {\xe\v "classe:{\i article}:section"}
******************************************************************************/
{
	char cThis, *text, *r, *s, *t;
	
	cThis = getNonBlank();
	text = getDelimitedText('{', '}', TRUE);
	diagnostics(4, "CmdIndex \\index{%s}", text);
	fprintRTF("{\\xe{\\v ");
	
	t = text;
	while (t) {
		s = t;
		t = strchr(s,'!');
		if (t) *t = '\0';
		r = strchr(s,'@');
		if (r) s=r+1;
		ConvertString(s);
/*		while (*s && *s != '@') putRtfChar(*s++);*/
		if (t) {
			fprintRTF("\\:");
			t++;
		}
	}
			
	fprintRTF("}}");
	diagnostics(4, "leaving CmdIndex");
	free(text);
}
Example #5
0
void 
ConvertString(char *string)
/******************************************************************************
     purpose : converts string in TeX-format to Rtf-format
 ******************************************************************************/
{
	char            temp[256];
	
	if (string==NULL) return;
	
	if (strlen(string)<250)
		strncpy(temp,string,250);
	else {
		strncpy(temp,string,125);
		strncpy(temp+125,"\n...\n", 5);
		strncpy(temp+130,string+strlen(string)-125,125);
		temp[255] = '\0';
	}
	
	if (PushSource(NULL, string) == 0) {
		diagnostics(4, "Entering Convert() from StringConvert()\n******\n%s\n*****",temp);
	
		while (StillSource())
			Convert();
			
		PopSource();
		diagnostics(4, "Exiting Convert() from StringConvert()");
	}
}
Example #6
0
static void
PutGifFile(char *s, double scale, double baseline, int full_path)
/******************************************************************************
 purpose   : Insert GIF file (from g_home_dir) into RTF file as a PNG image
 ******************************************************************************/
{
	char *cmd, *gif, *png, *tmp_png;
	size_t cmd_len;
	
	diagnostics(1, "filename = <%s>", s);
	png = strdup_new_extension(s, ".gif", ".png");
	if (png == NULL) {
		png = strdup_new_extension(s, ".GIF", ".png");
		if (png == NULL) return;
	}
	
	tmp_png = strdup_tmp_path(png);
	gif = strdup_together(g_home_dir,s);
	
	cmd_len = strlen(gif)+strlen(tmp_png)+10;
	cmd = (char *) malloc(cmd_len);
	snprintf(cmd, cmd_len, "convert %s %s", gif, tmp_png);	
	diagnostics(2, "system graphics command = [%s]", cmd);
	system(cmd);
	
	PutPngFile(tmp_png, scale, baseline, TRUE);
	my_unlink(tmp_png);

	free(tmp_png);
	free(cmd);
	free(gif);
	free(png);
}
Example #7
0
void 
CmdMusic(int code)
/******************************************************************************
  purpose: Process \begin{music} ... \end{music} environment
 ******************************************************************************/
{
	char *contents;
	char endmusic[] = "\\end{music}";

	if (!(code & ON)) {
		diagnostics(4, "exiting CmdMusic");
		return;
	}

	diagnostics(4, "entering CmdMusic");
	contents = getTexUntil(endmusic, TRUE);
	CmdEndParagraph(0);
	CmdVspace(VSPACE_SMALL_SKIP);
	CmdIndent(INDENT_NONE);
	CmdStartParagraph(FIRST_PAR);
	WriteLatexAsBitmap("\\begin{music}",contents,endmusic);
	ConvertString(endmusic);	
	CmdEndParagraph(0);
	CmdVspace(VSPACE_SMALL_SKIP);
	CmdIndent(INDENT_INHIBIT);
	free(contents);		
}
Example #8
0
static char *
pdf_to_png(char *pdf)
/******************************************************************************
     purpose : create a png file from an PDF file and return file name
 ******************************************************************************/
{
	char *cmd, *s1, *p, *png;
	size_t cmd_len;
	diagnostics(1, "filename = <%s>", pdf);

	s1 = strdup(pdf);
	if ((p=strstr(s1,".pdf")) == NULL && (p=strstr(s1,".PDF")) == NULL) {
		diagnostics(1, "<%s> is not a PDF file", pdf);
		free(s1);
		return NULL;
	}

	strcpy(p,".png");
	png = strdup_tmp_path(s1);
	cmd_len=strlen(pdf)+strlen(png)+40;
	cmd = (char *) malloc(cmd_len);
	snprintf(cmd, cmd_len, "convert -density %d %s %s", g_dots_per_inch, pdf, png);	
	diagnostics(2, "system graphics command = [%s]", cmd);
	system(cmd);	
	
	free(cmd);
	free(s1);
	return png;
}
Example #9
0
void
CmdArray(int code)
/******************************************************************************
 purpose   : Handles \begin{array}[c]{ccc} ... \end{array}
 ******************************************************************************/
{
char * v_align, * col_align, *s;
int n=0;

	if (code & ON) {
		v_align = getBracketParam();
		col_align = getBraceParam();
		diagnostics(4, "CmdArray() ... \\begin{array}[%s]{%s}", v_align?v_align:"", col_align);
		if (v_align) free(v_align);
		
		s = col_align;
		while (*s) {
			if (*s == 'c' || *s == 'l' || *s == 'r' ) n++;
			s++;
		}
		free(col_align);
		
		fprintRTF(" \\\\a \\\\ac \\\\co%d (", n);
		g_processing_arrays++;
		
	} else {
		fprintRTF(")");
		diagnostics(4, "CmdArray() ... \\end{array}");
		g_processing_arrays--;
	}
}
Example #10
0
char * exists_with_extension(char *s, char *ext)
/******************************************************************************
 purpose   : return s.ext or s.EXT if it exists otherwise return NULL
 ******************************************************************************/
{
	char *t,*x;
	FILE *fp;
	
	t=strdup_together(s,ext);
	fp=fopen(t,"r");
	diagnostics(4,"trying to open %s, result = %0x",t,fp);
	if (fp) {
		fclose(fp);
		return t;
	}
	free(t);
	
/* now try upper case version of ext */
	x=upper_case_string(ext);
	t=strdup_together(s,x);
	free(x);
	
	fp=fopen(t,"r");
	diagnostics(4,"trying to open %s, result = %0x",t,fp);
	if (fp) {
		fclose(fp);
		return t;
	}
	free(t);
	return NULL;
}
Example #11
0
/******************************************************************************
  purpose: remove 'tag{contents}' from text and return contents
           note that tag should typically be "\\caption"
 ******************************************************************************/
char *ExtractAndRemoveTag(char *tag, char *text)
{
    char *s, *contents, *start=NULL;

    if (text==NULL || *text=='\0') return NULL;
    
    s = text;
    diagnostics(5, "target tag = <%s>", tag);
    diagnostics(5, "original text = <%s>", text);

    while (s) {                 /* find start of caption */
        start = strstr(s, tag);
        if (!start)
            return NULL;
        s = start + strlen(tag);
        if (*s == ' ' || *s == '{')
            break;
    }

    contents = getStringBraceParam(&s);
    if (contents == NULL) return NULL;
    
    /* erase "tag{contents}" */
    do
        *start++ = *s++;
    while (*s);               
    *start = '\0';

    diagnostics(5, "final contents = <%s>", contents);
    diagnostics(5, "final text = <%s>", text);

    return contents;
}
Example #12
0
void
CmdLeftRight(int code)
/******************************************************************************
 purpose   : Handles \left \right
 			 to properly handle \left. or \right. would require prescanning the
 			 entire equation.  
 ******************************************************************************/
{ 
	char delim;

	delim = getTexChar();
	if (delim == '\\')			/* might be \{ or \} */
		delim = getTexChar();
	
	if (code == 0) {
		diagnostics(4, "CmdLeftRight() ... \\left <%c>", delim);

		if (delim == '.')
			diagnostics(WARNING, "\\left. not supported");
		
		fprintRTF(" \\\\b ");
		if (delim == '(' || delim == '.')
			fprintRTF("(");
		else if (delim == '{')
			fprintRTF("\\\\bc\\\\\\{ (");
		else 
			fprintRTF("\\\\bc\\\\%c (", delim);

	} else {
		fprintRTF(")");
		if (delim == '.')
			diagnostics(WARNING, "\\right. not supported");
		diagnostics(4, "CmdLeftRight() ... \\right <%c>", delim);
	}
}
Example #13
0
/******************************************************************************
 purpose:  returns a new string consisting of s+t
******************************************************************************/
char *strdup_together(const char *s, const char *t)
{
    char *both;
    size_t siz;
    
    if (s == NULL) {
        if (t == NULL)
            return NULL;
        return strdup(t);
    }
    if (t == NULL)
        return strdup(s);

    if (0) diagnostics(1, "'%s' + '%s'", s, t);
    siz = strlen(s) + strlen(t) + 1;
    both = (char *) malloc(siz);

    if (both == NULL)
        diagnostics(ERROR, "Could not allocate memory for both strings.");

    my_strlcpy(both, s, siz);
    my_strlcat(both, t, siz);

    return both;
}
Example #14
0
void 
CmdClosing( /* @unused@ */ int code)
/******************************************************************************
 purpose: special command in the LaTex-letter-environment will be converted to a
	  similar Rtf-style
 globals: alignment
 ******************************************************************************/
{
	char           oldalignment;
	char           *s;
	
	oldalignment = alignment;

/* print closing on the right */
	alignment = RIGHT;
	fprintRTF("\n\\par\\pard\\q%c ", alignment);	
	diagnostics(5, "Entering ConvertString() from CmdClosing");
	s = getBraceParam();
	ConvertString(s);
	free(s);
	diagnostics(5, "Exiting ConvertString() from CmdClosing");

/* print signature a couple of lines down */
	fprintRTF("\n\\par\\par\\par ");

	diagnostics(5, "Entering ConvertString() from CmdSignature");
	ConvertString(g_letterSignature);
	diagnostics(5, "Exiting ConvertString() from CmdSignature");

	g_letterOpened = FALSE;
	alignment = oldalignment;
	fprintRTF("\n\\par\\pard\\q%c ", alignment);
}
Example #15
0
void
InsertBookmark(char *name, char *text)
{
	char *signet;
	if (!name) {
		fprintRTF("%s",text);
		return;
	}

	signet = strdup_nobadchars(name);

	if (ExistsBookmark(signet)) {
		diagnostics(3,"bookmark %s already exists",signet);

	} else {
		diagnostics(3,"bookmark %s being inserted around <%s>",signet,text);
		RecordBookmark(signet);
		if (g_fields_use_REF) 
			fprintRTF("{\\*\\bkmkstart BM%s}",signet);
		fprintRTF("%s",text);
		if (g_fields_use_REF) 
			fprintRTF("{\\*\\bkmkend BM%s}",signet);
	}
	
	free(signet);
}
Example #16
0
 DiagnosticBufferProvider&
 DiagnosticBufferProvider::access (BufferProvider const& provider)
 {
   if (!diagnostics().isCurrent (provider))
     throw error::Invalid("given Provider doesn't match (current) diagnostic data record."
                          "This might be an lifecycle error. Did you build() this instance beforehand?");
   
   return diagnostics();
 }
Example #17
0
static void 
PutPictFile(char * s, double scale, double baseline, int full_path)
/******************************************************************************
     purpose : Include .pict file in RTF
 ******************************************************************************/
{
FILE *fp;
char *pict;
short buffer[5];
short top, left, bottom, right;
int width, height;

	if (full_path)
		pict = strdup(s);
	else
		pict = strdup_together(g_home_dir, s);		
	diagnostics(1, "PutPictFile <%s>", pict);

	fp = fopen(pict, "rb");
	free(pict);
	if (fp == NULL) return;
	
	if (fseek(fp, 514L, SEEK_SET) || fread(buffer, 2, 4, fp) != 4) {
		diagnostics (WARNING, "Cannot read graphics file <%s>", s);
		fclose(fp);
		return;
	}
	
	top    = buffer[0];
	left   = buffer[1];
	bottom = buffer[2];
	right  = buffer[3];

	width  = right - left;
	height = bottom - top;
	
	if (g_little_endian) {
		top    = LETONS(top);
		bottom = LETONS(bottom);
		left   = LETONS(left);
		right  = LETONS(right);
	}

	diagnostics(4,"top = %d, bottom = %d", top, bottom);
	diagnostics(4,"left = %d, right = %d", left, right);
	diagnostics(4,"width = %d, height = %d", width, height);
	fprintRTF("\n{\\pict\\macpict\\picw%d\\pich%d\n", width, height);
	if (scale != 1.0) {
		int iscale = (int) (scale * 100);
		fprintRTF("\\picscalex%d\\picscaley%d", iscale, iscale);
	}

	fseek(fp, -10L, SEEK_CUR);
	PutHexFile(fp);
	fprintRTF("}\n");
	fclose(fp);
}
Example #18
0
int my_getopt(int argc, char **argv, char *optstring)
{
    char *q;
    static char *rem = NULL;
    int c;
    int needarg = 0;

    optarg = NULL;

    diagnostics(4, "Processing option `%s'", argv[optind]);

    /* 
     * printf("optind = %d\n", optind);  if (rem) printf("rem=`%s'\n",
     * rem);
     */

    if (!rem) {
        if (optind < argc && argv[optind][0] == '-') {
            rem = argv[optind] + 1;
            if (*rem == 0)
                return EOF;     /* Treat lone "-" as a non-option arg */
            if (*rem == '-') {
                optind++;
                return EOF;
            }                   /* skip "--" and terminate */
        } else
            return EOF;
    }
    c = *rem;
    q = strchr(optstring, c);
    if (q && c != ':') {        /* matched */
        needarg = (q[1] == ':');
        if (needarg) {
            if (rem[1] != 0)
                optarg = rem + 1;
            else {
                optind++;
                if (optind < argc)
                    optarg = argv[optind];
                else {
                    diagnostics(ERROR, "Missing argument after -%c\n", c);
                }
            }
        } else
            rem++;
    } else {
        diagnostics(WARNING, "%s: illegal option -- %c\n", argv[0], c);
        c = '?';
        rem++;
    }
    if (needarg || *rem == 0) {
        rem = NULL;
        optind++;
    }
    return c;
}
Example #19
0
static char * 
ScanAux(char *token, char * reference, int code)
/*************************************************************************
purpose: obtains a reference from .aux file

code=0 means \token{reference}{number}       -> "number"
code=1 means \token{reference}{{sect}{line}} -> "sect"
 ************************************************************************/
{
	static FILE    *fAux = NULL;
	char            AuxLine[2048];
	char            target[512];
	char           *s,*t;
	int				braces;

	if (g_aux_file_missing || strlen(token) == 0) {
		return NULL;
	}

	diagnostics(4,"seeking in .aux for <%s>",reference);
	
	snprintf(target, 512, "\\%s{%s}", token, reference);
	
	if (fAux == NULL && (fAux = my_fopen(g_aux_name, "r")) == NULL) {
		diagnostics(WARNING, "No .aux file.  Run LaTeX to create %s\n", g_aux_name);
		g_aux_file_missing = TRUE;
		return NULL;
	}
	
	rewind(fAux);
	
	while (fgets(AuxLine, 2047, fAux) != NULL) {

		s = strstr(AuxLine, target);
		if (s) {
		
			s += strlen(target);		/* move to \token{reference}{ */			
			if (code==1) s++;			/* move to \token{reference}{{ */

			t = s;					
			braces = 1;
			while ( braces >= 1) {		/* skip matched braces */
				t++;
				if (*t == '{') braces++;
				if (*t == '}') braces--;
				if (*t == '\0') return NULL;
			}
			
			*t = '\0';
			diagnostics(4,"found <%s>",s+1);
			return strdup(s+1);
		}
	}
	return NULL;
}
Example #20
0
void
PutLatexFile(char *s, double scale, char *pre)
/******************************************************************************
 purpose   : Convert LaTeX to Bitmap and insert in RTF file
 ******************************************************************************/
{
	char *png, *cmd, *l2p;
	int err, baseline,second_pass;
	size_t cmd_len;
	unsigned long width, height, rw, rh;
	unsigned long maxsize=(unsigned long) (32767.0/20.0);
	int resolution = g_dots_per_inch; /*points per inch */
	
	diagnostics(4, "Entering PutLatexFile");

	png = strdup_together(s,".png");
	l2p = get_latex2png_name();

	cmd_len = strlen(l2p)+strlen(s)+25;
	if (g_home_dir)
		cmd_len += strlen(g_home_dir);

	cmd = (char *) malloc(cmd_len);

	do {
		second_pass = FALSE; 	/* only needed if png is too large for Word */
		if (g_home_dir==NULL)
			snprintf(cmd, cmd_len, "%s -d %d %s", l2p, resolution, s);	
		else
			snprintf(cmd, cmd_len, "%s -d %d -H \"%s\" %s", l2p, resolution, g_home_dir, s);	

		diagnostics(2, "system graphics command = [%s]", cmd);
		err=system(cmd);
		if (err) break;

		GetPngSize(png, &width, &height);
		baseline=GetBaseline(s, pre);
		diagnostics(4, "png size height=%d baseline=%d width=%d", height, baseline, width);
		
		if( (width>maxsize && height!=0) || (height>maxsize && width!=0) ){  
			second_pass = TRUE;
			rw=(unsigned long) ((resolution*maxsize)/width);
		 	rh=(unsigned long) ((resolution*maxsize)/height); 
			resolution=rw<rh?(int)rw:(int)rh;
		}
	} while (resolution>10 && ( (width>maxsize) || (height>maxsize)) );
	
	if (err==0)
		PutPngFile(png, scale*72.0/resolution, (double) baseline, TRUE);
	
	free(l2p);
	free(png);
	free(cmd);
}
Example #21
0
void
PopFontSettings(void)
{
	if (FontInfoDepth == 0)
		diagnostics(ERROR, "FontInfoDepth = 0, cannot PopFontSettings()!");
	
	FontInfoDepth--;
	diagnostics(6,"PopFontSettings depth=%d, family=%d, size=%d, shape=%d, series=%d",\
				   FontInfoDepth, RtfFontInfo[FontInfoDepth].family, \
	               RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape,\
	               RtfFontInfo[FontInfoDepth].series);
}
Example #22
0
void MonitorFontChanges(const unsigned char *text)
{
    int n;

    diagnostics(6, "\nMonitorFont %10s\n", text);
    diagnostics(6, "MonitorFont before depth=%d, family=%d, size=%d, shape=%d, series=%d",
      FontInfoDepth, RtfFontInfo[FontInfoDepth].family,
      RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape, RtfFontInfo[FontInfoDepth].series);

    if (strstart(text, "\\b0"))
        RtfFontInfo[FontInfoDepth].series = F_SERIES_MEDIUM;

    else if (strstart(text, "\\b ") || strstart(text, "\\b\\"))
        RtfFontInfo[FontInfoDepth].series = F_SERIES_BOLD;

    else if (strstart(text, "\\i0")) {
        int mode=getTexMode();
        if (mode==MODE_MATH || mode==MODE_DISPLAYMATH)
            RtfFontInfo[FontInfoDepth].shape = F_SHAPE_MATH_UPRIGHT;
        else
            RtfFontInfo[FontInfoDepth].shape = F_SHAPE_UPRIGHT;
    }
    else if (strstart(text, "\\i ") || strstart(text, "\\i\\"))
        RtfFontInfo[FontInfoDepth].shape = F_SHAPE_ITALIC;

    else if (strstart(text, "\\scaps0")){
        int mode=getTexMode();
        if (mode==MODE_MATH || mode==MODE_DISPLAYMATH)
            RtfFontInfo[FontInfoDepth].shape = F_SHAPE_MATH_UPRIGHT;
        else
            RtfFontInfo[FontInfoDepth].shape = F_SHAPE_UPRIGHT;
    }

    else if (strstart(text, "\\scaps ") || strstart(text, "\\scaps\\"))
        RtfFontInfo[FontInfoDepth].shape = F_SHAPE_CAPS;

    else if (strstartnum(text, "\\fs", &n))
        RtfFontInfo[FontInfoDepth].size = n;

    else if (strstartnum(text, "\\f", &n))
        RtfFontInfo[FontInfoDepth].family = n;

    else if (strstart(text, "\\plain")) {
        RtfFontInfo[FontInfoDepth].size = RtfFontInfo[0].size;
        RtfFontInfo[FontInfoDepth].family = RtfFontInfo[0].family;
        RtfFontInfo[FontInfoDepth].shape = RtfFontInfo[0].shape;
        RtfFontInfo[FontInfoDepth].series = RtfFontInfo[0].series;
    }

    diagnostics(6, "MonitorFont after depth=%d, family=%d, size=%d, shape=%d, series=%d",
      FontInfoDepth, RtfFontInfo[FontInfoDepth].family,
      RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape, RtfFontInfo[FontInfoDepth].series);
}
Example #23
0
void CmdTextNormal(int code)

/****************************************************************************
 purpose: handle \textnormal{text}  {\normalfont ...} commands

     F_TEXT_NORMAL        for  \normalfont ... 
     F_TEXT_NORMAL_1
     F_TEXT_NORMAL_2      for  \textnormal{...}
     F_TEXT_NORMAL_3      for  \begin{normalfont} ... \end{normalfont}

 ******************************************************************************/
{
    int true_code = code & ~ON;

    diagnostics(5, "CmdTextNormal (before) depth=%d, family=%d, size=%d, shape=%d, series=%d",
      FontInfoDepth, RtfFontInfo[FontInfoDepth].family,
      RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape, RtfFontInfo[FontInfoDepth].series);

    if (true_code == F_TEXT_NORMAL_3 && !(code & ON))
        return;

    if (getTexMode() == MODE_VERTICAL)
        changeTexMode(MODE_HORIZONTAL);

    if (code == F_TEXT_NORMAL_2)
        fprintRTF("{");

    if (CurrentFontShape() != DefaultFontShape())
        CmdFontShape(DefaultFontShape());

    if (CurrentFontSeries() != DefaultFontSeries())
        CmdFontSeries(DefaultFontSeries());

    if (CurrentFontSize() != DefaultFontSize())
        CmdFontSize(DefaultFontSize());

    if (CurrentFontFamily() != DefaultFontFamily())
        CmdFontFamily(DefaultFontFamily());

    if (code == F_TEXT_NORMAL_2) {
        char *s;

        s = getBraceParam();
        ConvertString(s);
        free(s);
        fprintRTF("}");
    }

    diagnostics(5, "CmdTextNormal (after) depth=%d, family=%d, size=%d, shape=%d, series=%d",
      FontInfoDepth, RtfFontInfo[FontInfoDepth].family,
      RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape, RtfFontInfo[FontInfoDepth].series);
}
Example #24
0
void PopFontSettings(void)
{
    if (FontInfoDepth == 0)
        diagnostics(WARNING, "FontInfoDepth = 0, cannot PopFontSettings()!");

    FontInfoDepth--;
    diagnostics(6, "PopFontSettings  depth=%2d, family=%2d, size=%2d, shape=%2d, series=%2d, encoding=%2d",
      FontInfoDepth, RtfFontInfo[FontInfoDepth].family,
      RtfFontInfo[FontInfoDepth].size, 
      RtfFontInfo[FontInfoDepth].shape, 
      RtfFontInfo[FontInfoDepth].series,
      RtfFontInfo[FontInfoDepth].encoding);
}
Example #25
0
static void increase_buffer_size(void)
{
    char *new_section_buffer;

    new_section_buffer = (char *) malloc(2 * section_buffer_size + 1);
    if (new_section_buffer == NULL)
        diagnostics(ERROR, "Could not allocate enough memory to process file. Sorry.");
    memmove(new_section_buffer, section_buffer, section_buffer_size);
    section_buffer_size *= 2;
    free(section_buffer);
    section_buffer = new_section_buffer;
    diagnostics(4, "Expanded buffer size is now %ld", section_buffer_size);
}
Example #26
0
/**************************************************************************
 purpose: provide functionality of getBraceParam() for strings
 
        if s contains "aaa {stuff}cdef", then  
            parameter = getStringBraceParam(&s)
            
          gives
            parameter = "stuff"
            s="cdef"

     \alpha\beta   --->  "\beta"             \bar \alpha   --->  "\alpha"
           ^                                     ^
     \bar{text}    --->  "text"              \bar text     --->  "t"
         ^                                       ^
    _\alpha        ---> "\alpha"             _{\alpha}     ---> "\alpha"
     ^                                        ^
    _2             ---> "2"                  _{2}          ---> "2"
     ^                                        ^
 ******************************************************************************/
char *getStringBraceParam(char **s)

{
    char *p_start, *p, *parameter, last;
    int braces;
    
    if (*s == NULL) return strdup("");
    
    /* skip white space ... and one possible newline*/
    while (**s == ' ') (*s)++;
    if (**s == '\n') {
        while (**s == ' ') (*s)++;
    }
    
    p_start = *s;

    /* return simple command like \alpha */
    if (**s == '\\') {
        do { (*s)++; } while (isalpha(**s));
    diagnostics(1,"getstringbraceparam \\ before='%s'", *s);
        return my_strndup(p_start,(*s)-p_start);
    }
    
    /* no brace ... advance one and return next character */
    if (**s != '{' ) {
        (*s)++; 
        return my_strndup(p_start,1);
     }
    
    /* usual case, return contents between braces */
    p_start++;
    p=p_start;  
    last = '\0';
    braces = 1;
    while (*p != '\0' && braces > 0) {
        if (*p == '{' && last != '\\')
            braces++;
        if (*p == '}' && last != '\\')
            braces--;
        last = *p;
        p++;
    }
    
    parameter = my_strndup(p_start, p-p_start-1);
    *s = p;

    diagnostics(6,"Extract parameter=<%s> after=<%s>", parameter, *s); 
    
    return parameter;
    
}
QString YubiKeyWriter::reportError(bool chalresp = false) {
    QString errMsg;

    if (ykp_errno) {
        qDebug("Yubikey personalization error: %s\n", ykp_strerror(ykp_errno));
        emit diagnostics(ykp_strerror(ykp_errno));

        switch(ykp_errno) {
        case YKP_EYUBIKEYVER:
        case YKP_EOLDYUBIKEY:
            errMsg = tr(ERR_FEATURE_NOT_SUPPORTED);
            break;
        default:
            errMsg = tr(ERR_PROCESSING);
            break;
        }
        ykp_errno = 0;
    } else if (yk_errno) {
        if (yk_errno == YK_EUSBERR) {
            qDebug("USB error: %s\n", yk_usb_strerror());
            emit diagnostics(QString("USB error: %1").arg(yk_usb_strerror()));
        } else {
            qDebug("Yubikey core error: %s\n", yk_strerror(yk_errno));
            emit diagnostics(yk_strerror(yk_errno));
        }

        switch(yk_errno) {
        case YK_ENOKEY:
            errMsg = tr(ERR_KEY_NOT_FOUND);
            break;
        case YK_EFIRMWARE:
            errMsg = tr(ERR_FIRMWARE_NOT_SUPPORTED);
            break;
        default:
            if(chalresp) {
                errMsg = tr(ERR_PROCESSING_CHALRESP);
            } else {
                errMsg = tr(ERR_PROCESSING);
            }
            break;
        }
        yk_errno = 0;
    }


    if(!errMsg.isEmpty()) {
        emit errorOccurred(errMsg);
    }

    return errMsg;
}
Example #28
0
  size_t SymbolTable::add(STATE, std::string str, int enc) {
    size_t bytes = (str.size() + sizeof(std::string) + sizeof(int) + sizeof(Kind));
    diagnostics()->objects_++;
    diagnostics()->bytes_ += bytes;

    strings.push_back(str);
    encodings.push_back(enc);
    kinds.push_back(eUnknown);

    state->vm()->metrics().memory.symbols++;
    state->vm()->metrics().memory.symbols_bytes += bytes;

    return strings.size() - 1;
  }
Example #29
0
void 
CmdEmphasize(int code)
/****************************************************************************
 purpose: LaTeX commands \em, \emph, and \begin{em} ... \end{em}
 
 		  the \emph{string} construction is handled by \textit{string} or \textup{string}
 		  
 		  {\em string} should be properly localized by brace mechanisms
 		  
 		  \begin{em} ... \end{em} will be localized by environment mechanisms

	 F_EMPHASIZE_1        for  \em ... 
	 F_EMPHASIZE_2        for  \emph{...}
	 F_EMPHASIZE_3        for  \begin{em} ... \end{em}
 ******************************************************************************/
{
	int true_code  = code & ~ON;
	
	diagnostics(4,"CmdEmphasize (before) depth=%d, family=%d, size=%d, shape=%d, series=%d",\
				   FontInfoDepth, RtfFontInfo[FontInfoDepth].family, \
	               RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape,\
	               RtfFontInfo[FontInfoDepth].series);
	               
	if (true_code == F_EMPHASIZE_3 && !(code & ON)) 
	     return;

	if (true_code == F_EMPHASIZE_2) {

		if (CurrentFontShape() == F_SHAPE_UPRIGHT) 
			CmdFontShape(F_SHAPE_ITALIC_2);
		else
			CmdFontShape(F_SHAPE_UPRIGHT_2);
	
	} else {
	
		if (CurrentFontShape() == F_SHAPE_UPRIGHT)
			fprintRTF("\\i ");
		else
			fprintRTF("\\i0 ");

	}

	diagnostics(4,"CmdEmphasize (after) depth=%d, family=%d, size=%d, shape=%d, series=%d",\
				   FontInfoDepth, RtfFontInfo[FontInfoDepth].family, \
	               RtfFontInfo[FontInfoDepth].size, RtfFontInfo[FontInfoDepth].shape,\
	               RtfFontInfo[FontInfoDepth].series);
	               
}
Example #30
0
int 
CurrentCyrillicFontFamily(void)
/******************************************************************************
  purpose: returns the cyrillic font that should be used ... 
           if the current font is cyrillic font then -1 is returned
 ******************************************************************************/
{
	int            num,i;
	char          *font_type;
	ConfigEntryT **font_handle;

	num = CurrentFontFamily();

/* obtain name and type of current active font */
	font_handle = CfgStartIterate(FONT_A);
	for (i=0; i<=num-3; i++)
		font_handle = CfgNext(FONT_A, font_handle);
		
	font_type = (char *) (*font_handle)->TexCommand;
	diagnostics(6,"CurrentCyrillicFontFamily current active font type =<%s>", font_type);
	
	if (strncmp(font_type, "Cyrillic", 8)==0)
		return -1;
		
	if (strcmp(font_type, "Slanted")==0) 
		return TexFontNumber("Cyrillic Slanted");
		
	if (strcmp(font_type, "Sans Serif")==0) 
		return TexFontNumber("Cyrillic Sans Serif");

	if (strcmp(font_type, "Typewriter")==0) 
		return TexFontNumber("Cyrillic Typewriter");

	return TexFontNumber("Cyrillic Roman");
}