Back to index

wims  3.65+svn20090927
matrix.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Subroutines to process matrices */
00019        /* messages: inconsistent_columns  */
00020 
00021        /* Translate error-laden raw matrix input into a standard form. */
00022 void rawmatrix(char *p)
00023 {
00024     char *p1;
00025     char lbuf[MAX_LINELEN+1], obuf[MAX_LINELEN+1];
00026     int n, i, c=0, change=0;
00027 
00028     obuf[0]=0;
00029     p1=find_word_start(p); if(p1>p) strcpy(p,p1);
00030     strip_enclosing_par(p); strip_trailing_spaces(p);
00031     if(*p==0) return;
00032     rows2lines(p); n=linenum(p);
00033     if(itemnum(p)<=1 && wordnum(p)>=2*n) change=1;
00034     for(i=1;i<=n;i++) {
00035        fnd_line(p,i,lbuf);
00036        p1=find_word_start(lbuf); if(p1>lbuf) strcpy(lbuf,p1);
00037        strip_enclosing_par(lbuf);
00038        if(lbuf[0]==0) continue;
00039               /* Uniformize column separator to comma */
00040        if(change) words2items(lbuf);
00041        rawmath(lbuf);
00042        if(i==1) {
00043            strcpy(obuf,lbuf);
00044            c=itemnum(lbuf);
00045        }
00046        else {
00047            if(strlen(obuf)+strlen(lbuf)>=MAX_LINELEN-1)
00048              user_error("cmd_output_too_long");
00049            if(c!=itemnum(lbuf)) {
00050               force_setvar("wims_warn_rawmatrix","inconsistent_columns"); 
00051               return;
00052            }
00053            snprintf(obuf+strlen(obuf),sizeof(obuf)-strlen(obuf),
00054                    "\n%s",lbuf);
00055        }
00056     }
00057     strcpy(p,obuf);
00058 }
00059