Exemplo n.º 1
0
char *
expandEnvironment(int thedef, int code)
/**************************************************************************
     purpose: retrieves and expands a \newenvironment 
**************************************************************************/
{
	if (thedef<0 || thedef>=iNewEnvironmentCount)
		return NULL;
	
	if (code == CMD_BEGIN) {
	
		diagnostics(3, "\\begin{%s} <%s>", NewEnvironments[thedef].name, \
										   NewEnvironments[thedef].begdef);
		return expandmacro(NewEnvironments[thedef].begdef, 
				   NewEnvironments[thedef].opt_param, 
				   NewEnvironments[thedef].params);
	
	} else {

		diagnostics(3, "\\end{%s} <%s>", NewEnvironments[thedef].name, \
										 NewEnvironments[thedef].enddef);
		return expandmacro(NewEnvironments[thedef].enddef, NULL, 0);
	}
}
Exemplo n.º 2
0
char *
expandDefinition(int thedef)
/**************************************************************************
     purpose: retrieves and expands a \newcommand macro 
**************************************************************************/
{

	if (thedef<0 || thedef>=iDefinitionCount)
		return NULL;
	
	diagnostics(3, "expandDefinition name     =<%s>", Definitions[thedef].name);
	diagnostics(3, "expandDefinition opt_param=<%s>", 
	        (Definitions[thedef].opt_param) ? Definitions[thedef].opt_param : "");
	diagnostics(3, "expandDefinition def      =<%s>", Definitions[thedef].def);
	diagnostics(3, "expandDefinition params   =<%d>", Definitions[thedef].params);

	return expandmacro(Definitions[thedef].def, Definitions[thedef].opt_param, Definitions[thedef].params);
}
Exemplo n.º 3
0
char *expandmacro(char *st)
{
  char *buffer;
  char *pin, *pout;
  int cmd;
  char *argstart, *argend;
  char temp;
  char *remsg;

  //the size of buffer will never be larger than 100+4*len(st), I hope.
  buffer=malloc(100+strlen(st)*4);

  pin=st;
  pout=buffer;

  while(*pin!=0) {
    if(*pin!='\\') {
      *pout=*pin;
      pin++;
      pout++;
    } else {
      cmd=extractcommand(basecmdlist,pin+1,&argstart,&argend);
      if(cmd==-1) {
        *pout='\\';
        *(pout+1)='\\';
        pout+=2;
        pin++;
      } else {
        temp=*argend;
        *argend=0;

        switch(cmd) {
          case 0:
            pout=appendstr(pout,"\\<a href=\\\"");
            pout=appendstr(pout,argstart);
            pout=appendstr(pout,"\\\"\\>");
            pout=appendstr(pout,argstart);
            pout=appendstr(pout,"\\</a\\>");
            break;
          case 1:
            pout=appendstr(pout,"\\<img src=\\\"");
            pout=appendstr(pout,argstart);
            pout=appendstr(pout,"\\\"\\>");
            break;
          case 2:
            remsg=expandmacro(argstart);
            pout=appendstr(pout,"\\<b\\>");
            pout=appendstr(pout,remsg);
            pout=appendstr(pout,"\\</b\\>");
            free(remsg);
            break;
          case 3:
            pout=appendstr(pout,argstart);
            break;
          case 4:
            remsg=expandmacro(argstart);
            pout=appendstr(pout,"\\<center\\>");
            pout=appendstr(pout,remsg);
            pout=appendstr(pout,"\\</center\\>");
            free(remsg);
            break;
        }

        *argend=temp;
        if(*argend=='}')
          pin=argend+1;
        else
          pin=argend;
      }
    }
  } 
  *pout=0;

  return buffer;
}