source: git/Singular/ipprint.cc @ 82716e

spielwiese
Last change on this file since 82716e was 057e93c, checked in by Hans Schönemann <hannes@…>, 26 years ago
* Fri Feb 27 15:02:10 MET 1998 hannes new input scheme: many modifications to febase.h, febase.inc, febase.cc, scanner.l, grammar.y, iplib.cc, ipshell.{h,cc} git-svn-id: file:///usr/local/Singular/svn/trunk@1183 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ipprint.cc,v 1.6 1998-02-27 14:06:19 Singular Exp $ */
5/*
6* ABSTRACT: interpreter: printing
7*/
8
9#include "mod2.h"
10#include "tok.h"
11#include "ipid.h"
12#include "mmemory.h"
13#include "febase.h"
14#include "polys.h"
15#include "matpol.h"
16#include "subexpr.h"
17#include "intvec.h"
18#include "ipshell.h"
19#include "ipprint.h"
20
21/*2
22* print for: int, string, poly, vector, ideal
23*/
24BOOLEAN jjPRINT_GEN(leftv res, leftv u)
25{
26  char *s=u->String();
27  PrintS(s);
28  PrintLn();
29  FreeL((ADDRESS)s);
30  return FALSE;
31}
32
33/*2
34* print for: list
35*/
36BOOLEAN jjPRINT_LIST(leftv res, leftv u)
37{
38  u->Print();
39  return FALSE;
40}
41
42/*2
43* print for: intvec
44*/
45BOOLEAN jjPRINT_INTVEC(leftv res, leftv u)
46{
47  intvec *v=(intvec *)u->Data();
48  v->show();
49  PrintLn();
50  return FALSE;
51}
52
53/*2
54* print for: intmat
55*/
56BOOLEAN jjPRINT_INTMAT(leftv res, leftv u)
57{
58  intvec *v=(intvec *)u->Data();
59  int i,j;
60  for(i=0;i<v->rows();i++)
61  {
62    for(j=0;j<v->cols();j++)
63    {
64      Print(" %5d",IMATELEM(*v,i+1,j+1));
65    }
66    PrintLn();
67  }
68  return FALSE;
69}
70
71/*2
72* internal print for: matrix
73*/
74void jjPRINT_MA0(matrix m, const char *name)
75{
76  if (MATCOLS(m)>0)
77  {
78    char **s=(char **)Alloc(MATCOLS(m)*MATROWS(m)*sizeof(char*));
79    char *ss;
80    int *l=(int *)Alloc0(MATCOLS(m)*sizeof(int));
81    int i,j,k;
82    int vl=max(colmax/MATCOLS(m),8);
83
84    /* make enough space for the "largest" name*/
85    ss=(char *)AllocL(14+strlen(name));
86    sprintf(ss,"%s[%d,%d]",name,MATCOLS(m),MATROWS(m));
87    vl=max(vl,strlen(ss));
88    FreeL(ss);
89
90    /* convert all polys to string */
91    i=MATCOLS(m)*MATROWS(m)-1;
92    ss=pString(m->m[i]);
93    if ((int)strlen(ss)>colmax) s[i]=NULL;
94    else                        s[i]=mstrdup(ss);
95    for(i--;i>=0;i--)
96    {
97      pString(m->m[i]);
98      ss=StringAppend(",");
99      if ((int)strlen(ss)>colmax) s[i]=NULL;
100      else                        s[i]=mstrdup(ss);
101    }
102    /* look up the width of all columns, put it in l[col_nr] */
103    /* insert names for very long entries */
104    for(i=MATROWS(m)-1;i>=0;i--)
105    {
106      for(j=MATCOLS(m)-1;j>=0;j--)
107      {
108        if (s[i*MATCOLS(m)+j]==NULL)
109        {
110          ss=(char *)AllocL(14+strlen(name));
111          s[i*MATCOLS(m)+j]=ss;
112          ss[0]='\0';
113          sprintf(ss,"%s[%d,%d]",name,i+1,j+1);
114          if ((i!=MATROWS(m)-1) || (j!=MATCOLS(m)-1))
115          {
116            strcat(ss,",");
117            vl=max(vl,strlen(ss));
118          }
119        }
120        k=strlen(s[i*MATCOLS(m)+j]);
121        if (k>l[j]) l[j]=k;
122      }
123    }
124    /* does it fit on a line ? */
125    int maxlen=0;
126    for(j=MATCOLS(m)-1;j>=0;j--)
127    {
128      maxlen+=l[j];
129    }
130    if (maxlen>colmax)
131    {
132      /* NO, it does not fit, so retry: */
133      /* look up the width of all columns, clear very long entriess */
134      /* put length in l[col_nr] */
135      /* insert names for cleared entries */
136      for(j=MATCOLS(m)-1;j>=0;j--)
137      {
138        for(i=MATROWS(m)-1;i>=0;i--)
139        {
140          k=strlen(s[i*MATCOLS(m)+j]);
141          if (/*strlen(s[i*MATCOLS(m)+j])*/ k > vl)
142          {
143            FreeL((ADDRESS)s[i*MATCOLS(m)+j]);
144            ss=(char *)AllocL(14+strlen(name));
145            s[i*MATCOLS(m)+j]=ss;
146            ss[0]='\0';
147            sprintf(ss,"%s[%d,%d]",name,i+1,j+1);
148            if ((i!=MATROWS(m)-1) || (j!=MATCOLS(m)-1))
149            {
150              strcat(ss,",");
151            }
152            l[j]=strlen(s[i*MATCOLS(m)+j]);
153            if (l[j]>vl)
154            {
155#ifdef TEST
156              PrintS("pagewidth too small in print(matrix)\n");
157#endif
158              vl=l[j]; /* make large names fit*/
159            }
160            i=MATROWS(m);
161          }
162          else
163          {
164            if (k>l[j]) l[j]=k;
165          }
166        }
167      }
168    }
169    /*output of the matrix*/
170    for(i=0;i<MATROWS(m);i++)
171    {
172      k=l[0];
173      Print("%-*.*s",l[0],l[0],s[i*MATCOLS(m)]);
174      FreeL(s[i*MATCOLS(m)]);
175      for(j=1;j<MATCOLS(m);j++)
176      {
177        if (k+l[j]>colmax)
178        {
179          PrintS("\n  ");
180          k=2;
181        }
182        k+=l[j];
183        Print("%-*.*s",l[j],l[j],s[i*MATCOLS(m)+j]);
184        FreeL(s[i*MATCOLS(m)+j]);
185      }
186      PrintLn();
187    }
188    /* clean up */
189    Free((ADDRESS)s,MATCOLS(m)*MATROWS(m)*sizeof(char*));
190    Free((ADDRESS)l,MATCOLS(m)*sizeof(int));
191  }
192}
193
194/*2
195* print for: matrix
196*/
197BOOLEAN jjPRINT_MA(leftv res, leftv u)
198{
199  matrix m=(matrix)u->Data();
200  jjPRINT_MA0(m,u->Name());
201  return FALSE;
202}
203
204/*2
205* print for: vector
206*/
207BOOLEAN jjPRINT_V(leftv res, leftv u)
208{
209  polyset m=NULL;
210  int l,j;
211  /*convert into an array of the components*/
212  pVec2Polys((poly)u->Data(), &m, &l);
213  /*output*/
214  PrintS("[");
215  j=0;
216  loop
217  {
218    PrintS(pString(m[j]));
219    j++;
220    if (j<l) PrintS(",");
221    else
222    {
223      PrintS("]\n");
224      break;
225    }
226  }
227  /* clean up */
228  for(j=l-1;j>=0;j--) pDelete(&m[j]);
229  Free((ADDRESS)m,l*sizeof(poly));
230  return FALSE;
231}
232
233/*2
234* dbprint
235*/
236BOOLEAN jjDBPRINT(leftv res, leftv u)
237{
238  BOOLEAN print=(printlevel>myynest);
239  if ((u->next!=NULL)&&(u->Typ()==INT_CMD))
240  {
241    print=((int)u->Data()>0);
242    u=u->next;
243  }
244  if (print)
245  {
246    BOOLEAN r=FALSE;
247    leftv h=u;
248    leftv hh;
249    while (h!=NULL)
250    {
251      hh=h->next;
252      h->next=NULL;
253      if (iiExprArith1(res,h,PRINT_CMD)) return TRUE;
254      h->next=hh;
255      h=hh;
256    }
257  }
258  return FALSE;
259}
260
261/*2
262* print(...,"format")
263*/
264BOOLEAN jjPRINT_FORMAT(leftv res, leftv u, leftv v)
265{
266/* ==================== betti ======================================== */
267  if ((u->Typ()==INTMAT_CMD)&&(strcmp((char *)v->Data(),"betti")==0))
268  {
269    int i,j;
270    intvec * betti=(intvec *)u->Data();
271    // head line --------------------------------------------------------
272    PrintS("      "); // 6 spaces for no. and :
273    for(j=0;j<betti->cols();j++) Print(" %5d",j); // 6 spaces pro column
274    PrintS("\n------"); // 6 spaces for no. and :
275    for(j=0;j<betti->cols();j++) PrintS("------"); // 6 spaces pro column
276    PrintLn();
277    // the table --------------------------------------------------------
278    for(i=0;i<betti->rows();i++)
279    {
280      Print("%5d:",i);
281      for(j=1;j<=betti->cols();j++)
282      {
283        Print(" %5d",IMATELEM(*betti,i+1,j));
284      }
285      PrintLn();
286    }
287    // sum --------------------------------------------------------------
288    PrintS("------"); // 6 spaces for no. and :
289    for(j=0;j<betti->cols();j++) PrintS("------"); // 6 spaces pro column
290    PrintS("\ntotal:");
291    for(j=0;j<betti->cols();j++)
292    {
293      int s=0;
294      for(i=0;i<betti->rows();i++)
295      {
296        s+=IMATELEM(*betti,i+1,j+1);
297      }
298      Print(" %5d",s); // 6 spaces pro column
299    }
300    PrintLn();
301    return FALSE;
302  }
303/* ======================== end betti ================================= */
304
305  return jjPRINT_GEN(res,u);
306}
Note: See TracBrowser for help on using the repository browser.