version 1.16, 2004/03/04 03:31:28 |
version 1.17, 2004/03/04 05:16:42 |
|
|
* 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.15 2004/03/04 01:41:32 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.16 2004/03/04 03:31:28 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 69 void Pclear_tb(); |
|
Line 69 void Pclear_tb(); |
|
void Pstring_to_tb(); |
void Pstring_to_tb(); |
void Pquotetotex_tb(); |
void Pquotetotex_tb(); |
void Pquotetotex(); |
void Pquotetotex(); |
void Ptrim_tb(); |
|
void fnodetotex_tb(FNODE f,TB tb); |
void fnodetotex_tb(FNODE f,TB tb); |
char *symbol_name(char *name); |
char *symbol_name(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); |
void fargstotex_tb(char *opname,FNODE f,TB tb); |
void fargstotex_tb(char *opname,FNODE f,TB tb); |
void dp_trim_tb(TB tb); |
|
|
|
struct ftab str_tab[] = { |
struct ftab str_tab[] = { |
{"rtostr",Prtostr,1}, |
{"rtostr",Prtostr,1}, |
Line 90 struct ftab str_tab[] = { |
|
Line 88 struct ftab str_tab[] = { |
|
{"clear_tb",Pclear_tb,1}, |
{"clear_tb",Pclear_tb,1}, |
{"tb_to_string",Ptb_to_string,1}, |
{"tb_to_string",Ptb_to_string,1}, |
{"string_to_tb",Pstring_to_tb,1}, |
{"string_to_tb",Pstring_to_tb,1}, |
{"trim_tb",Ptrim_tb,2}, |
|
{"quotetotex_tb",Pquotetotex_tb,2}, |
{"quotetotex_tb",Pquotetotex_tb,2}, |
{"quotetotex",Pquotetotex,1}, |
{"quotetotex",Pquotetotex,1}, |
{0,0,0}, |
{0,0,0}, |
Line 106 void write_tb(char *s,TB tb) |
|
Line 103 void write_tb(char *s,TB tb) |
|
tb->next++; |
tb->next++; |
} |
} |
|
|
void dp_trim_tb(TB tb) |
|
{ |
|
int i,j,l,onei,onej; |
|
char *p; |
|
|
|
if ( !tb->next ) return; |
|
/* number 1 => number */ |
|
onei = -1; onej = -1; |
|
for ( i = tb->next-1; i >= 0; i-- ) { |
|
p = tb->body[i]; |
|
l = strlen(p); |
|
if ( onei < 0 ) { |
|
for ( j = l-1; j >= 0 && isspace(p[j]); j-- ); |
|
if ( j < 0 ) continue; |
|
if ( p[j] != '1' ) return; |
|
/* we found 1 */ |
|
onei = i; onej = j; j--; |
|
} else |
|
j = l-1; |
|
/* we search the previous non-space character */ |
|
for ( ; j >= 0 && isspace(p[j]); j-- ); |
|
if ( j < 0 ) continue; |
|
if ( p[j] == '+' || p[j] == '-' ) return; |
|
else break; |
|
} |
|
if ( i < 0 ) return; |
|
/* the previous character is a number */ |
|
l = strlen(tb->body[onei]); |
|
p = (char *)MALLOC_ATOMIC(l+1); |
|
strcpy(p,tb->body[onei]); |
|
p[onej] = ' '; |
|
tb->body[onei] = p; |
|
} |
|
|
|
void Ptrim_tb(NODE arg,Q *rp) |
|
{ |
|
asir_assert(ARG0(arg),O_TB,"trim_tb"); |
|
if ( !INT(ARG1(arg)) ) error("trim_tb : invalid argument"); |
|
switch ( QTOS((Q)ARG1(arg)) ) { |
|
case O_DP: |
|
dp_trim_tb((TB)ARG0(arg)); |
|
break; |
|
default: |
|
break; |
|
} |
|
*rp = 0; |
|
} |
|
|
|
void Pwrite_to_tb(NODE arg,Q *rp) |
void Pwrite_to_tb(NODE arg,Q *rp) |
{ |
{ |
int i; |
int i; |
Line 515 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 464 void fnodetotex_tb(FNODE f,TB tb) |
|
char *opname; |
char *opname; |
Obj obj; |
Obj obj; |
int i,len,allzero; |
int i,len,allzero; |
FNODE fi; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
if ( !f ) { |
if ( !f ) { |
Line 564 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 513 void fnodetotex_tb(FNODE f,TB tb) |
|
} else if ( !strcmp(opname,"*") ) { |
} else if ( !strcmp(opname,"*") ) { |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(" ",tb); |
write_tb(" ",tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
/* XXX special care for DP */ |
|
f2 = (FNODE)FA2(f); |
|
if ( f2->id == I_EV ) { |
|
n = (NODE)FA0(f2); |
|
for ( i = 0; n; n = NEXT(n), i++ ) { |
|
fi = (FNODE)BDY(n); |
|
if ( fi->id != I_FORMULA || FA0(fi) ) |
|
break; |
|
} |
|
if ( n ) |
|
fnodetotex_tb((FNODE)FA2(f),tb); |
|
} else |
|
fnodetotex_tb((FNODE)FA2(f),tb); |
} else if ( !strcmp(opname,"/") ) { |
} else if ( !strcmp(opname,"/") ) { |
write_tb("\\frac{",tb); |
write_tb("\\frac{",tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |