Back to index

wims  3.65+svn20090927
Defines | Functions | Variables
text.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MAX_TLEN   96
#define TEXT_PROC_NO   (sizeof(text_proc)/sizeof(text_proc[0]))

Functions

void _text_cut (char *p, char *w)
void text_common (char *p)
void text_compare (char *p)
void text_copy (char *p)
void text_count (char *p)
void text_diff (char *p)
void text_expand (char *p)
void text_insert (char *p)
void text_interact (char *p)
void text_mark (char *p)
void text_max (char *p)
void text_min (char *p)
void text_occur (char *p)
void text_remove (char *p)
void text_reorder (char *p)
void text_repeat (char *p)
void text_reverse (char *p)
void text_select (char *p)
int textab_verify (void)
void text (char *p)

Variables

unsigned char t_buf [4][MAX_LINELEN+1]
char maskbuf [MAX_LINELEN+1]
struct {
char * name
int tag
void(* routine )(char *p)
text_proc []

Define Documentation

#define MAX_TLEN   96

Definition at line 137 of file text.c.

#define TEXT_PROC_NO   (sizeof(text_proc)/sizeof(text_proc[0]))

Definition at line 364 of file text.c.


Function Documentation

void _text_cut ( char *  p,
char *  w 
)

Definition at line 22 of file text.c.

{
    char *p1, *p2;
    p1=wordchr(p,w); if(p1==NULL) error2("syntax_error");
    *p1=0; p2=find_word_start(p1+strlen(w));
    strcpy(t_buf[0],p); strcpy(t_buf[1],p2);
    strip_trailing_spaces(t_buf[0]);
    substitute(t_buf[0]); substitute(t_buf[1]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void text ( char *  p)

Definition at line 371 of file text.c.

{
    int i,j,n;
    char *p1, *p2;
    char c,cc;
    char buf[MAX_LINELEN+1];
    p1=find_word_start(p); p2=find_word_end(p1);
    if(p2<=p1 || *p2==0) error2("syntax_error");
    *p2=0;
    i=search_list(text_proc,TEXT_PROC_NO,sizeof(text_proc[0]),p1);
    if(i<0) error2("syntax_error");
    snprintf(buf,sizeof(buf),"%s",find_word_start(p2+1));
    if((text_proc[i].tag&1)!=0 && (p1=wordchr(buf,"mask"))!=NULL) {
       *p1=0; strip_trailing_spaces(buf);
       p2=find_word_start(p1+strlen("mask"));
       strip_trailing_spaces(p2);
       snprintf(maskbuf,sizeof(maskbuf),"%s",p2);
       substitute(maskbuf);
       n=strlen(maskbuf); if(n==0) goto zeromask;
       c=maskbuf[n-1]; cc=0;
       if(c=='+') cc='1'; if(c=='-') cc='0';
       if(cc!=0) memset(maskbuf+n-1,cc,sizeof(maskbuf)-n);
       else for(j=n;j<MAX_LINELEN;j++) maskbuf[j]=maskbuf[j%n];
       maskbuf[sizeof(maskbuf)-1]=0;
    }
    else zeromask: memset(maskbuf,0,sizeof(maskbuf));
    text_proc[i].routine(buf);
    buf[MAX_LINELEN]=0;strcpy(p,buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void text_common ( char *  p)

Definition at line 34 of file text.c.

{
    int i,j,n1,n2;
    _text_cut(p,"and");
    n1=strlen(t_buf[0]);n2=strlen(t_buf[1]);
    if(n2<n1) n1=n2;
    for(i=j=0;i<n1;i++) {
       if(t_buf[0][i]==t_buf[1][i] && maskbuf[i]!='0') p[j++]=t_buf[0][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_compare ( char *  p)

Definition at line 49 of file text.c.

{
    int min,max, i;
    _text_cut(p,"and");
    min=strlen(t_buf[0]); max=strlen(t_buf[1]);
    if(min>max) {
       i=min; min=max; max=i;
    }
    for(i=0; i<min; i++) {
       if(t_buf[0][i]==t_buf[1][i]) p[i]='0'; else p[i]='1';
    }
    for(; i<max; i++) p[i]='1';
    p[max]=0;
}

Here is the call graph for this function:

void text_copy ( char *  p)

Definition at line 65 of file text.c.

{
    int i, j, n;
    
    snprintf(t_buf[0],MAX_LINELEN,"%s",p);
    strip_trailing_spaces(t_buf[0]); substitute(t_buf[0]);
    n=strlen(t_buf[0]);
    for(i=j=0;i<n;i++) {
       if(maskbuf[i]!='0') p[j++]=t_buf[0][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_count ( char *  p)

Definition at line 79 of file text.c.

{
    int i, n, c;
    _text_cut(p,"in");
    n=strlen(t_buf[1]);
    for(i=c=0;i<n;i++) {
       if(strchr(t_buf[0],t_buf[1][i])!=NULL && maskbuf[i]!='0') c++;
    }
    snprintf(p,MAX_LINELEN,"%d",c);
}

Here is the call graph for this function:

void text_diff ( char *  p)

Definition at line 92 of file text.c.

{
    int i,j,n1,n2;
    _text_cut(p,"from");
    n1=strlen(t_buf[0]);n2=strlen(t_buf[1]);
    if(n2<n1) n1=n2;
    for(i=j=0;i<n1;i++) {
       if(t_buf[0][i]!=t_buf[1][i] && maskbuf[i]!='0') p[j++]=t_buf[0][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_expand ( char *  p)

Definition at line 109 of file text.c.

{
    int i,j,k,n1,n2;
    _text_cut(p,"using");
    n1=strlen(t_buf[0]);n2=strlen(t_buf[1]);
    if(n2==0) {p[0]=0; return;}
    for(i=j=k=0;i<n1 && j<MAX_LINELEN;j++,k=j%n2) {
       if(t_buf[1][k]=='0') p[j]=' ';
       else p[j]=t_buf[0][i++];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_insert ( char *  p)

Definition at line 126 of file text.c.

{
    int i,j,n1,n2;
    _text_cut(p,"into");
    n1=strlen(t_buf[0]);n2=strlen(t_buf[1]);
    for(i=j=0; i<n2 && j<n1; i++) {
       if(maskbuf[i]!='0') t_buf[1][i]=t_buf[0][j++];
    }
    snprintf(p,MAX_LINELEN,"%s",t_buf[1]);
}

Here is the call graph for this function:

void text_interact ( char *  p)

Definition at line 141 of file text.c.

{
    char *table, *dline, *tline[MAX_TLEN];
    char *p1, *p2;
    int i,j1,j2,k,l,l2,n;
    
    table=wordchr(p,"table");
    if(table==NULL) error2("syntax_error");
    *table=0; strip_trailing_spaces(p);
    table=find_word_start(table+strlen("table"));
    snprintf(t_buf[2],MAX_LINELEN,"%s",table);
    _text_cut(p,"and");
    strip_trailing_spaces(t_buf[2]); substitute(t_buf[2]);
    n=linenum(t_buf[2])-1;
    if(n>=MAX_TLEN) error2("text_bad_table");
    p2=strchr(t_buf[2],'\n'); if(p2!=NULL) *p2++=0;
    if(strlen(t_buf[2])!=n) error2("text_bad_table");
    dline=t_buf[2];
    for(i=0,p1=p2;i<n;i++,p1=p2) {
       if(p1==NULL) error2("text_bad_table");
       p2=strchr(p1,'\n'); 
       if(p2!=NULL) *p2++=0;
       if(strlen(p1)!=n) error2("text_bad_table");
       tline[i]=p1;
    }
    l=strlen(t_buf[0]); l2=strlen(t_buf[1]); if(l2<l) l=l2;
    for(i=k=0;i<l;i++) {
       if(maskbuf[i]!='0') {
           p1=strchr(dline,t_buf[0][i]);
           p2=strchr(dline,t_buf[1][i]);
           if(p1==NULL || p2==NULL) continue;
           j1=p1-dline; j2=p2-dline;
           if(j1>=n || j2>=n) continue; /* should not occur */
           p[k++]=tline[j1][j2];
       }
    }
    p[k]=0;
}

Here is the call graph for this function:

void text_mark ( char *  p)

Definition at line 182 of file text.c.

{
    int i, n;
    _text_cut(p,"in");
    n=strlen(t_buf[1]);
    for(i=0;i<n;i++) {
       if(strchr(t_buf[0],t_buf[1][i])!=NULL) p[i]='1';
       else p[i]='0';
    }
    p[i]=0;
}

Here is the call graph for this function:

void text_max ( char *  p)

Definition at line 197 of file text.c.

{
    int min,max, i, j, k;
    _text_cut(p,"and");
    min=strlen(t_buf[0]); max=strlen(t_buf[1]);
    if(min>max) {
       i=min; min=max; max=i; j=0;
    }
    else j=1;
    for(i=k=0; i<min; i++) {
       if(maskbuf[i]=='0') continue;
       if(t_buf[0][i]>t_buf[1][i]) p[k++]=t_buf[0][i];
       else p[k++]=t_buf[1][i];
    }
    for(;i<max;i++) {
       if(maskbuf[i]!='0') p[k++]=t_buf[j][i];
    }
    p[k]=0;
}

Here is the call graph for this function:

void text_min ( char *  p)

Definition at line 220 of file text.c.

{
    int min,max, i,k;
    _text_cut(p,"and");
    min=strlen(t_buf[0]); max=strlen(t_buf[1]);
    if(min>max) {
       i=min; min=max; max=i;
    }
    for(i=k=0; i<min; i++) {
       if(maskbuf[i]=='0') continue;
       if(t_buf[0][i]<t_buf[1][i]) p[k++]=t_buf[0][i];
       else p[k++]=t_buf[1][i];
    }
    p[k]=0;
}

Here is the call graph for this function:

void text_occur ( char *  p)

Definition at line 237 of file text.c.

{
    int i,j,n;
    unsigned char *pp;
    char buf[MAX_LINELEN+1];
    memset(buf,0,sizeof(buf));
    _text_cut(p,"in");
    n=strlen(t_buf[1]);
    for(i=0;i<n;i++) {
       if(maskbuf[i]=='0') continue;
       pp=strchr(t_buf[0],t_buf[1][i]);
       if(pp!=NULL) buf[pp - t_buf[0]]=1;
    }
    n=strlen(t_buf[0]);
    for(i=j=0;i<n;i++) {
       if(buf[i]) p[j++]=t_buf[0][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_remove ( char *  p)

Definition at line 258 of file text.c.

{
    int i, j, n;
    _text_cut(p,"in");
    n=strlen(t_buf[1]);
    for(i=j=0;i<n;i++) {
       if(strchr(t_buf[0],t_buf[1][i])==NULL
          && maskbuf[i]!='0') p[j++]=t_buf[1][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

void text_reorder ( char *  p)

Definition at line 271 of file text.c.

{
    int i,j,k,l,n,t;
    int list[10240];
    char buf[MAX_LINELEN+1];
    _text_cut(p,"by"); *p=0;
    n=itemnum(t_buf[1]); if(n<=0 || n>=10240) return;
    for(i=0;i<n;i++) {
        buf[0]=0; fnd_item(t_buf[1],i+1,buf);
       j=atoi(buf); if(j<=0 || j>n) return;
       list[i]=j;
    }
    t=strlen(t_buf[0]);
    for(i=l=0;l<t && i<t+n;i++) {
       j=i/n; k=j*n+list[i%n];
       if(k>t || k<=0) continue;
       p[l++]=t_buf[0][k-1];
    }
    p[l]=0;
}

Here is the call graph for this function:

void text_repeat ( char *  p)

Definition at line 293 of file text.c.

{
    int n,i,k;
    _text_cut(p,"to");
    n=strevalue(t_buf[1]); if(n>MAX_LINELEN) n=MAX_LINELEN;
    if(n<0) n=0;
    k=strlen(t_buf[0]); if(k<=0) {*p=0; return;}
    for(i=0;i<n;i++) {
       p[i]=t_buf[0][i%k];
    }
    p[i]=0;
}

Here is the call graph for this function:

void text_reverse ( char *  p)

Definition at line 307 of file text.c.

{
    int i,n;
    char buf[MAX_LINELEN+1];
    snprintf(t_buf[0],sizeof(t_buf[0]),"%s",p);
    substitute(t_buf[0]);
    n=strlen(t_buf[0]); if(n>MAX_LINELEN) n=MAX_LINELEN;
    for(i=0;i<n;i++) buf[i]=t_buf[0][n-1-i];
    buf[n]=0;
    strcpy(p,buf);
}
void text_select ( char *  p)

Definition at line 320 of file text.c.

{
    int i, j, n;
    _text_cut(p,"in");
    n=strlen(t_buf[1]);
    for(i=j=0;i<n;i++) {
       if(strchr(t_buf[0],t_buf[1][i])!=NULL
          && maskbuf[i]!='0') p[j++]=t_buf[1][i];
    }
    p[j]=0;
}

Here is the call graph for this function:

int textab_verify ( void  )

Definition at line 366 of file text.c.

                        {
    return verify_order(text_proc,TEXT_PROC_NO,sizeof(text_proc[0]));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 19 of file text.c.

unsigned char t_buf[4][MAX_LINELEN+1]

Definition at line 18 of file text.c.

struct { ... } text_proc[]