[BACK]Return to strobj.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Diff for /OpenXM_contrib2/asir2000/builtin/strobj.c between version 1.36 and 1.40

version 1.36, 2004/03/10 05:37:24 version 1.40, 2004/03/11 07:40:41
Line 45 
Line 45 
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  *   *
  * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.35 2004/03/10 05:27:03 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.39 2004/03/11 04:52:17 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 78  void Pquotetotex_env();
Line 78  void Pquotetotex_env();
 void fnodetotex_tb(FNODE f,TB tb);  void fnodetotex_tb(FNODE f,TB tb);
 char *symbol_name(char *name);  char *symbol_name(char *name);
 char *conv_rule(char *name);  char *conv_rule(char *name);
 char *conv_subscript(char *name);  char *conv_subs(char *name);
 char *call_convfunc(char *name);  char *call_convfunc(char *name);
 void tb_to_string(TB tb,STRING *rp);  void tb_to_string(TB tb,STRING *rp);
 void fnodenodetotex_tb(NODE n,TB tb);  void fnodenodetotex_tb(NODE n,TB tb);
Line 116  void write_tb(char *s,TB tb)
Line 116  void write_tb(char *s,TB tb)
   
 int register_symbol_table(Obj arg);  int register_symbol_table(Obj arg);
 int register_conv_rule(Obj arg);  int register_conv_rule(Obj arg);
   int register_conv_func(Obj arg);
 int register_dp_vars(Obj arg);  int register_dp_vars(Obj arg);
 int register_dp_vars_prefix(Obj arg);  int register_dp_vars_prefix(Obj arg);
 int register_dp_vars_hweyl(Obj arg);  int register_dp_vars_hweyl(Obj arg);
 int register_show_lt(Obj arg);  int register_show_lt(Obj arg);
   char *objtostr(Obj obj);
 static struct TeXSymbol *user_texsymbol;  static struct TeXSymbol *user_texsymbol;
 static char **dp_vars;  static char **dp_vars;
 static int dp_vars_len;  static int dp_vars_len;
Line 130  static int is_lt;
Line 132  static int is_lt;
 static int conv_flag;  static int conv_flag;
 static int dp_vars_hweyl;  static int dp_vars_hweyl;
   
 #define CONV_SUBSCRIPT (1U<<0)  #define CONV_TABLE (1U<<0)
 #define CONV_DMODE (1U<<1)  #define CONV_SUBS (1U<<1)
 #define CONV_USERFUNC (1U<<31)  #define CONV_DMODE (1U<<2)
   
 static struct {  static struct {
         char *name;          char *name;
Line 141  static struct {
Line 143  static struct {
 } qtot_env[] = {  } qtot_env[] = {
         {"symbol_table",0,register_symbol_table},          {"symbol_table",0,register_symbol_table},
         {"conv_rule",0,register_conv_rule},          {"conv_rule",0,register_conv_rule},
           {"conv_func",0,register_conv_func},
         {"dp_vars",0,register_dp_vars},          {"dp_vars",0,register_dp_vars},
         {"dp_vars_prefix",0,register_dp_vars_prefix},          {"dp_vars_prefix",0,register_dp_vars_prefix},
         {"dp_vars_hweyl",0,register_dp_vars_hweyl},          {"dp_vars_hweyl",0,register_dp_vars_hweyl},
Line 154  char *conv_rule(char *name)
Line 157  char *conv_rule(char *name)
 {  {
         char *body,*r;          char *body,*r;
   
           if ( convfunc )
                   name = call_convfunc(name);
         if ( conv_flag & CONV_DMODE ) {          if ( conv_flag & CONV_DMODE ) {
                 if ( *name == 'd' ) {                  if ( *name == 'd' ) {
                         if ( conv_flag & CONV_SUBSCRIPT )                          body = conv_flag&CONV_SUBS?conv_subs(name+1):symbol_name(name+1);
                                 body = conv_subscript(name+1);                          if ( !body ) {
                         else                                  r = MALLOC_ATOMIC((strlen(PARTIAL)+1)*sizeof(char));
                                 body = name+1;                                  strcpy(r,PARTIAL);
                         r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char));                          } else {
                         sprintf(r,"{%s}_{%s}",PARTIAL,body);                                  r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)
                                           *sizeof(char));
                                   sprintf(r,strlen(body)==1?"{%s}_%s":"{%s}_{%s}",PARTIAL,body);
                           }
                         return r;                          return r;
                 } else {                  } else
                         if ( conv_flag & CONV_SUBSCRIPT )                          return conv_flag&CONV_SUBS?conv_subs(name):symbol_name(name);
                                 body = conv_subscript(name);          } else
                         else                  return conv_flag&CONV_SUBS?conv_subs(name):symbol_name(name);
                                 body = name;  
                 }  
         } else if ( conv_flag & CONV_SUBSCRIPT )  
                 return conv_subscript(name);  
         else if ( conv_flag & CONV_USERFUNC && convfunc )  
                 return call_convfunc(name);  
         else  
                 return name;  
 }  }
   
 char *conv_subscript(char *name)  int _is_delimiter(char c)
 {  {
           if ( (c == ' ' || c == '_' || c == ',') ) return 1;
           else return 0;
   }
   
   int _is_alpha(char c)
   {
           if ( isdigit(c) || c == '{' || _is_delimiter(c) ) return 0;
           else return 1;
   }
   
   char *conv_subs(char *name)
   {
         int i,j,k,len,clen,slen,start,level;          int i,j,k,len,clen,slen,start,level;
         char *buf,*head,*r,*h,*brace;          char *buf,*head,*r,*h,*brace;
         char **subs;          char **subs;
   
         len = strlen(name);          len = strlen(name);
           if ( !len ) return 0;
         subs = (char **)ALLOCA(len*sizeof(char* ));          subs = (char **)ALLOCA(len*sizeof(char* ));
         for ( i = 0, j = 0, start = i; ; j++ ) {          for ( i = 0, j = 0, start = i; ; j++ ) {
                 while ( (i < len) &&                  while ( (i < len) && _is_delimiter(name[i]) ) i++;
                         (name[i] == ' ' || name[i] == '_' || name[i] == ',') ) i++;  
                 start = i;                  start = i;
                 if ( i == len ) break;                  if ( i == len ) break;
                 if ( name[i] == '{' ) {                  if ( name[i] == '{' ) {
Line 196  char *conv_subscript(char *name)
Line 208  char *conv_subscript(char *name)
                                 else if ( name[i] == '}' ) level--;                                  else if ( name[i] == '}' ) level--;
                         }                          }
                         slen = i-start;                          slen = i-start;
                         brace = (char *)ALLOCA((slen+1)*sizeof(char));                          if ( slen >= 3 ) {
                         strncpy(brace,name+start+1,slen-2);                                  brace = (char *)ALLOCA((slen+1)*sizeof(char));
                         brace[slen-2] = 0;                                  strncpy(brace,name+start+1,slen-2);
                         buf = conv_subscript(brace);                                  brace[slen-2] = 0;
                         subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char));                                  buf = conv_subs(brace);
                         sprintf(subs[j],"{%s}",buf);                                  subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char));
                                   if ( strlen(buf) == 1 )
                                           strcpy(subs[j],buf);
                                   else
                                           sprintf(subs[j],"{%s}",buf);
                           } else
                                   subs[j] = "{}";
                 } else {                  } else {
                         if ( isdigit(name[i]) )                          if ( isdigit(name[i]) )
                                 while ( i < len && isdigit(name[i]) ) i++;                                  while ( i < len && isdigit(name[i]) ) i++;
                         else                          else
                                 while ( i < len && (isalpha(name[i]) || name[i] == '\\') ) i++;                                  while ( i < len && _is_alpha(name[i]) ) i++;
                         slen = i-start;                          slen = i-start;
                         buf = (char *)ALLOCA((slen+1)*sizeof(char));                          buf = (char *)ALLOCA((slen+1)*sizeof(char));
                         strncpy(buf,name+start,slen); buf[slen] = 0;                          strncpy(buf,name+start,slen); buf[slen] = 0;
Line 219  char *conv_subscript(char *name)
Line 237  char *conv_subscript(char *name)
         if ( j == 1 )          if ( j == 1 )
                 sprintf(h,"{%s}",subs[0]);                  sprintf(h,"{%s}",subs[0]);
         else {          else {
                 sprintf(h,"{%s}_{{%s}",subs[0],subs[1]);                  sprintf(h,"{%s}_{%s",subs[0],subs[1]);
                 h += strlen(h);                  h += strlen(h);
                 for ( k = 2; k < j; k++ ) {                  for ( k = 2; k < j; k++ ) {
                         sprintf(h,",{%s}",subs[k]);                          sprintf(h,",%s",subs[k]);
                         h += strlen(h);                          h += strlen(h);
                 }                  }
                 strcpy(h,"}");                  strcpy(h,"}");
Line 311  int register_conv_rule(Obj arg)
Line 329  int register_conv_rule(Obj arg)
                 conv_flag = QTOS((Q)arg);                  conv_flag = QTOS((Q)arg);
                 convfunc = 0;                  convfunc = 0;
                 return 1;                  return 1;
         } else if ( OID(arg) == O_P &&          } else return 0;
                 (int)(VR((P)arg))->attr == V_SR ) {  }
                 conv_flag = CONV_USERFUNC;  
   int register_conv_func(Obj arg)
   {
           if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) {
                 convfunc = (FUNC)(VR((P)arg)->priv);                  convfunc = (FUNC)(VR((P)arg)->priv);
                 /* f must be a function which takes single argument */                  /* f must be a function which takes single argument */
                 return 1;                  return 1;
Line 755  char *symbol_name(char *name)
Line 776  char *symbol_name(char *name)
 {  {
         int i;          int i;
   
           if ( !(conv_flag & CONV_TABLE) )
                   return name;
   
         if ( user_texsymbol )          if ( user_texsymbol )
                 for ( i = 0; user_texsymbol[i].text; i++ )                  for ( i = 0; user_texsymbol[i].text; i++ )
                         if ( !strcmp(user_texsymbol[i].text,name) )                          if ( !strcmp(user_texsymbol[i].text,name) )
Line 768  char *symbol_name(char *name)
Line 792  char *symbol_name(char *name)
 void fnodetotex_tb(FNODE f,TB tb)  void fnodetotex_tb(FNODE f,TB tb)
 {  {
         NODE n,t,t0;          NODE n,t,t0;
         char vname[BUFSIZ];          char vname[BUFSIZ],prefix[BUFSIZ];
         char *opname,*vname_conv;          char *opname,*vname_conv,*prefix_conv;
         Obj obj;          Obj obj;
         int i,len,allzero,elen,elen2;          int i,len,allzero,elen,elen2;
           C cplx;
           char *r;
         FNODE fi,f2;          FNODE fi,f2;
   
         write_tb(" ",tb);          write_tb(" ",tb);
Line 958  void fnodetotex_tb(FNODE f,TB tb)
Line 984  void fnodetotex_tb(FNODE f,TB tb)
   
                 /* function */                  /* function */
                 case I_FUNC:                  case I_FUNC:
                         opname = conv_rule(((FUNC)FA0(f))->name);                          if ( !strcmp(((FUNC)FA0(f))->name,"@pi") )
                         write_tb(opname,tb);                                  write_tb("\\pi",tb);
                         write_tb("(",tb);                          else if ( !strcmp(((FUNC)FA0(f))->name,"@e") )
                         fargstotex_tb(opname,FA1(f),tb);                                  write_tb("e",tb);
                         write_tb(")",tb);                          else {
                                   opname = conv_rule(((FUNC)FA0(f))->name);
                                   write_tb(opname,tb);
                                   write_tb("(",tb);
                                   fargstotex_tb(opname,FA1(f),tb);
                                   write_tb(")",tb);
                           }
                         break;                          break;
   
                 /* XXX */                  /* XXX */
Line 997  void fnodetotex_tb(FNODE f,TB tb)
Line 1029  void fnodetotex_tb(FNODE f,TB tb)
                                 fi = (FNODE)BDY(n);                                  fi = (FNODE)BDY(n);
                                 if ( fi->id == I_FORMULA && !FA0(fi) ) continue;                                  if ( fi->id == I_FORMULA && !FA0(fi) ) continue;
                                 allzero = 0;                                  allzero = 0;
                                 if ( dp_vars_hweyl ) {                                  if ( dp_vars && i < dp_vars_len ) {
                                         if ( i < elen2 )                                          strcpy(vname,dp_vars[i]);
                                                 if ( dp_vars_prefix )                                          vname_conv = conv_rule(vname);
                                                         sprintf(vname,"%s_{%d}",dp_vars_prefix,i);                                  } else {
                                           if ( dp_vars_hweyl ) {
                                                   if ( i < elen2 )
                                                           strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x");
                                                   else if ( i < elen )
                                                           strcpy(prefix,"\\partial");
                                                 else                                                  else
                                                         sprintf(vname,"x_{%d}",i);                                                          strcpy(prefix,"h");
                                         else if ( i < elen )                                          } else
                                                 sprintf(vname,"{\\partial}_{%d}",i-elen2);                                                  strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x");
                                           prefix_conv = conv_rule(prefix);
                                           vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50);
                                           if ( i < 10 )
                                                   sprintf(vname_conv,"%s_%d",prefix_conv,i);
                                         else                                          else
                                                 strcpy(vname,"h");                                                  sprintf(vname_conv,"%s_{%d}",prefix_conv,i);
                                 } else if ( dp_vars && i < dp_vars_len )                                  }
                                         strcpy(vname,dp_vars[i]);  
                                 else if ( dp_vars_prefix )  
                                         sprintf(vname,"%s_{%d}",dp_vars_prefix,i);  
                                 else  
                                         sprintf(vname,"x_{%d}",i);  
                                 vname_conv = conv_rule(vname);  
                                 if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) {                                  if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) {
                                         len = strlen(vname_conv);                                          len = strlen(vname_conv);
                                         opname = MALLOC_ATOMIC(len+2);                                          opname = MALLOC_ATOMIC(len+2);
Line 1046  void fnodetotex_tb(FNODE f,TB tb)
Line 1081  void fnodetotex_tb(FNODE f,TB tb)
                 /* internal object */                  /* internal object */
                 case I_FORMULA:                  case I_FORMULA:
                         obj = (Obj)FA0(f);                          obj = (Obj)FA0(f);
                         if ( obj && OID(obj) == O_P ) {                          if ( !obj )
                                 opname = conv_rule(VR((P)obj)->name);                                  opname = "0";
                         } else {                          else if ( OID(obj) == O_N && NID(obj) == N_C ) {
                                 len = estimate_length(CO,obj);                                  cplx = (C)obj;
                                 opname = (char *)MALLOC_ATOMIC(len+1);                                  write_tb("(",tb);
                                 soutput_init(opname);                                  if ( cplx->r ) {
                                 sprintexpr(CO,obj);                                          r = objtostr((Obj)cplx->r); write_tb(r,tb);
                         }                                  }
                         write_tb(opname,tb);                                  if ( cplx->i ) {
                                           if ( cplx->r && compnum(0,cplx->i,0) > 0 ) {
                                                   write_tb("+",tb);
                                                   if ( !UNIQ(cplx->i) ) {
                                                           r = objtostr((Obj)cplx->i); write_tb(r,tb);
                                                   }
                                           } else if ( MUNIQ(cplx->i) )
                                                   write_tb("-",tb);
                                           else if ( !UNIQ(cplx->i) ) {
                                                   r = objtostr((Obj)cplx->i); write_tb(r,tb);
                                           }
                                           write_tb("\\sqrt{-1}",tb);
                                   }
                                   write_tb(")",tb);
                           } else if ( OID(obj) == O_P )
                                   write_tb(conv_rule(VR((P)obj)->name),tb);
                           else
                                   write_tb(objtostr(obj),tb);
                         break;                          break;
   
                 /* program variable */                  /* program variable */
Line 1068  void fnodetotex_tb(FNODE f,TB tb)
Line 1120  void fnodetotex_tb(FNODE f,TB tb)
                 default:                  default:
                         error("fnodetotex_tb : not implemented yet");                          error("fnodetotex_tb : not implemented yet");
         }          }
   }
   
   char *objtostr(Obj obj)
   {
           int len;
           char *r;
   
           len = estimate_length(CO,obj);
           r = (char *)MALLOC_ATOMIC(len+1);
           soutput_init(r);
           sprintexpr(CO,obj);
           return r;
 }  }
   
 void fnodenodetotex_tb(NODE n,TB tb)  void fnodenodetotex_tb(NODE n,TB tb)

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.40

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>