source: git/Singular/mpsr_Get.cc @ 9c756f

spielwiese
Last change on this file since 9c756f was eea2b0, checked in by Olaf Bachmann <obachman@…>, 26 years ago
1998-04-16 Olaf Bachmann <obachman@mathematik.uni-kl.de> * mpsr_PutPoly.cc: Took out normalization of rational numbers before they are put -- might have side effects * extra.cc: added system("--option") which returns value of option; in debug mode: system("OptionValues") lists all option values * sing_mp.cc: use long option names for MP link options * MPtcp:launch: Uses find_exec as default application * tesths.cc: New (handling of) command line options (long options, usage of getopt_long): Parse more than one argument script, etc .. * added getopt.[c,h]for parsing of command lines * mod2.h.in, configure.in: Got rid off str* tests git-svn-id: file:///usr/local/Singular/svn/trunk@1387 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 23.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/* $Id: mpsr_Get.cc,v 1.16 1998-04-16 16:10:21 obachman Exp $ */
6/***************************************************************
7 *
8 * File:       mpsr_Get.cc
9 * Purpose:    definition of the main Get routine(s)
10 * Author:     Olaf Bachmann (10/95)
11 *
12 * Change History (most recent first):
13 *
14 ***************************************************************/
15
16#include "mod2.h"
17
18#ifdef HAVE_MPSR
19
20
21#include"mpsr_Get.h"
22#include"mpsr_Tok.h"
23
24#include "tok.h"
25#include "longrat.h"
26#include "ring.h"
27#include "intvec.h"
28#include "ideals.h"
29#include "matpol.h"
30#include "lists.h"
31#include "sing_mp.h"
32
33#include <limits.h>
34
35
36/***************************************************************
37 *
38 * prototypes
39 *
40 ***************************************************************/
41static mpsr_Status_t GetIntVecLeftv(MP_Link_pt link, MPT_Node_pt node,
42                                  mpsr_leftv mlv);
43static mpsr_Status_t GetIntMatLeftv(MP_Link_pt link, MPT_Node_pt node,
44                                  mpsr_leftv mlv);
45static mpsr_Status_t GetRingLeftv(MP_Link_pt link, MPT_Node_pt node,
46                                mpsr_leftv mlv);
47static mpsr_Status_t GetPolyLeftv(MP_Link_pt link, MPT_Node_pt node,
48                                mpsr_leftv mlv);
49static mpsr_Status_t GetPolyVectorLeftv(MP_Link_pt link, MPT_Node_pt node,
50                                      mpsr_leftv mlv);
51static mpsr_Status_t GetIdealLeftv(MP_Link_pt link, MPT_Node_pt node,
52                                 mpsr_leftv mlv);
53static mpsr_Status_t GetModuleLeftv(MP_Link_pt link, MPT_Node_pt node,
54                                  mpsr_leftv mlv);
55static mpsr_Status_t GetMatrixLeftv(MP_Link_pt link, MPT_Node_pt node,
56                                  mpsr_leftv mlv);
57static mpsr_Status_t GetMapLeftv(MP_Link_pt link, MPT_Node_pt node,
58                               mpsr_leftv mlv);
59static mpsr_Status_t GetCopCommandLeftv(MP_Link_pt link, MPT_Node_pt node,
60                                      mpsr_leftv mlv, short quote);
61
62/***************************************************************
63 *
64 * Inlines
65 *
66 ***************************************************************/
67
68//
69// Predicates which examine nodes for primitive Singular types
70//
71#define fr(cond)    if (! (cond)) return FALSE
72
73inline BOOLEAN IsIntVecNode(MPT_Node_pt node)
74{
75  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseVector));
76
77  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
78  return tree != NULL && NodeCheck(tree->node, MP_CommonMetaType,
79                                   MP_ProtoDict, MP_CmtProtoIMP_Sint32);
80}
81
82inline BOOLEAN IsIntMatNode(MPT_Node_pt node)
83{
84  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseMatrix));
85
86  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
87  return tree != NULL && NodeCheck(tree->node, MP_CommonMetaType,
88                                   MP_ProtoDict, MP_CmtProtoIMP_Sint32);
89}
90
91inline BOOLEAN IsRingNode(MPT_Node_pt node, ring &r)
92{
93  BOOLEAN mv;
94  return
95    NodeCheck(node, MP_PolyDict, MP_CopPolyRing) &&
96    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
97}
98
99inline BOOLEAN IsPolyNode(MPT_Node_pt node, ring &r)
100{
101  BOOLEAN mv;
102 
103  //for the timne being, we only accept DDP's
104  return
105    NodeCheck(node, MP_PolyDict, MP_CopPolyDenseDistPoly) &&
106    MPT_FindAnnot(node, MP_PolyDict, MP_AnnotPolyModuleVector) == NULL &&
107    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
108}
109
110inline BOOLEAN IsPolyVectorNode(MPT_Node_pt node, ring &r)
111{
112  BOOLEAN mv;
113 
114  //for the timne being, we only accept DDP's
115  return
116    NodeCheck(node, MP_PolyDict, MP_CopPolyDenseDistPoly) &&
117    MPT_FindAnnot(node, MP_PolyDict, MP_AnnotPolyModuleVector) != NULL &&
118    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
119}
120
121inline BOOLEAN IsIdealNode(MPT_Node_pt node, ring &r)
122{
123  fr(NodeCheck(node, MP_PolyDict, MP_CopPolyIdeal));
124  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
125  fr(tree != NULL);
126  node = tree->node;
127  return
128    node->type == MP_CommonMetaOperatorType &&
129    node->numchild == 0 &&
130    IsPolyNode(node, r);
131}
132
133inline BOOLEAN IsModuleNode(MPT_Node_pt node, ring &r)
134{
135  fr(NodeCheck(node, MP_PolyDict, MP_CopPolyModule));
136  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
137  fr(tree != NULL);
138  node = tree->node;
139  return
140    node->type == MP_CommonMetaOperatorType &&
141    node->numchild == 0 &&
142    IsPolyVectorNode(node, r);
143}
144
145inline BOOLEAN IsMatrixNode(MPT_Node_pt node, ring &r)
146{
147  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseMatrix));
148  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
149  fr(tree != NULL);
150  node = tree->node;
151  return
152    node->type == MP_CommonMetaOperatorType &&
153    node->numchild == 0 &&
154    IsPolyNode(node, r);
155}
156
157inline BOOLEAN IsQuitNode(MPT_Node_pt node)
158{
159  return NodeCheck(node, MP_MpDict, MP_CopMpEndSession);
160}
161
162//
163// Init*Leftv functions
164//
165inline void InitIntLeftv(mpsr_leftv mlv, int i)
166{
167  mlv->lv = mpsr_InitLeftv(INT_CMD, (void *) i);
168}
169
170inline void InitApIntLeftv(mpsr_leftv mlv, mpz_ptr apint)
171{
172  number n = (number) Alloc(sizeof(rnumber));
173#ifdef LDEBUG
174    n->debug=123456;
175#endif
176  mlv->r = mpsr_rDefault(0);
177  n->s = 3;
178  memcpy(&(n->z), apint, sizeof(MP_INT));
179  n = nlInit(n);
180  Free(apint, sizeof(MP_INT));
181  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
182}
183
184inline void InitReal32Leftv(mpsr_leftv mlv, MPT_Arg_t r32)
185{
186  number n = (number) r32;
187//  n = Real32_2_Number(r32);
188
189  mlv->r = mpsr_rDefault(-1);
190  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
191}
192 
193inline void InitIdentifierLeftv(mpsr_leftv mlv, char *name, short quote)
194{
195  int pos;
196 
197  if (quote <= 0)
198  {
199    idhdl h = mpsr_FindIdhdl(name, mlv->r);
200
201    if (h != NULL)
202    {
203      mlv->lv = mpsr_InitLeftv(IDHDL, (void *) h);
204    }
205    else
206    {
207      poly p;
208     
209      pos = mpsr_rDefault(0, name, mlv->r);
210      mpsr_SetCurrRing(mlv->r, TRUE);
211      p = pOne();
212      pSetExp(p,pos+1, 1);
213      pSetm(p);
214      mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
215    }
216    FreeL(name);
217  }
218  else
219  {
220    mlv->lv = mpsr_InitLeftv(DEF_CMD, NULL);
221    mlv->lv->name = name;
222  }
223}
224
225/* primitive mpsr_Get*Leftv functions */
226
227inline mpsr_Status_t mpsr_GetIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
228{
229  mpsr_assume(MP_IsFixedIntegerType(node->type));
230  mlv->lv = mpsr_InitLeftv(INT_CMD, node->nvalue);
231  return mpsr_Success;
232}
233
234inline mpsr_Status_t mpsr_GetReal32Leftv(MPT_Node_pt node, mpsr_leftv mlv) 
235{
236  mpsr_assume(node->type == MP_Real32Type);
237  InitReal32Leftv(mlv, node->nvalue);
238  return mpsr_Success;
239}
240
241inline mpsr_Status_t mpsr_GetApIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
242{
243  InitApIntLeftv(mlv, (mpz_ptr)  node->nvalue);
244  node->nvalue = NULL;
245  return mpsr_Success;
246}
247
248inline mpsr_Status_t mpsr_GetIdentifierLeftv(MPT_Node_pt node, mpsr_leftv mlv,
249                                             short quote)
250{
251  mpsr_assume(MP_IsIdType(node->type));
252  char *id;
253  MPT_Annot_pt proc_annot = MPT_FindAnnot(node, MP_SingularDict,
254                                          MP_AnnotSingularProcDef);
255
256  if (node->type == MP_CommonGreekIdentifierType ||
257      node->type == MP_CommonGreekIdentifierType)
258  {
259    id  = (char *) AllocL(2*sizeof(char));
260    id[1] = '\0';
261    id[0] = MP_UINT8_T(node->nvalue);
262  }
263  else
264  {
265    id = MP_STRING_T(node->nvalue);
266    node->nvalue = NULL;
267  }
268 
269  InitIdentifierLeftv(mlv, id, quote);
270
271  if (proc_annot != NULL) mlv->lv->rtyp = PROC_CMD;
272   
273  return mpsr_Success;
274}
275
276inline mpsr_Status_t mpsr_GetStringLeftv(MPT_Node_pt node, mpsr_leftv mlv)
277{
278  mpsr_assume(node->type == MP_StringType);
279  mlv->lv = mpsr_InitLeftv(STRING_CMD, MP_STRING_T(node->nvalue));
280  node->nvalue = NULL;
281  return mpsr_Success;
282}
283
284inline mpsr_Status_t GetQuitLeftv(mpsr_leftv mlv)
285{
286  mlv->lv = mpsr_InitLeftv(STRING_CMD, (void *) mstrdup(MPSR_QUIT_STRING));
287  return mpsr_Success;
288}
289
290/***************************************************************
291 *
292 * The top-level routine for getting a message
293 *
294 ***************************************************************/
295mpsr_Status_t mpsr_GetMsg(MP_Link_pt link, leftv &lv)
296{
297  mpsr_sleftv mlv, mlv1;
298  mpsr_Status_t status = mpsr_Success;
299  mlv.lv = NULL;
300  mlv.r = NULL;
301  mlv1.lv = NULL;
302  mlv1.r = NULL;
303
304  status = (MP_InitMsg(link) == MP_Success ? mpsr_Success : mpsr_MP_Failure);
305 
306  if (status == mpsr_Success && ! MP_TestEofMsg(link))
307    status = mpsr_GetLeftv(link, &mlv, 0);
308  else
309  {
310    lv = mpsr_InitLeftv(NONE, NULL);
311    return status;
312  }
313
314  // handle more than one leftv (ie. chains of leftv's)
315  while (status == mpsr_Success && ! MP_TestEofMsg(link))
316  {
317    // Get next leftv
318    status = mpsr_GetLeftv(link, &mlv1, 0);
319    if (status == mpsr_Success)
320      status = mpsr_MergeLeftv(&mlv, &mlv1);
321  }
322
323  if (status == mpsr_Success)
324  {
325    // Now mlv is our leftv -- check whether r has an ordering set
326    if (mlv.r != NULL && mlv.r->order[0] == ringorder_unspec)
327    {
328      ring r = rCopy(mlv.r);
329      r->order[0] = ringorder_lp;
330      mpsr_rSetOrdSgn(r);
331      mpsr_MapLeftv(mlv.lv, mlv.r, r);
332      rKill(mlv.r);
333      mlv.r = r;
334    }
335    mpsr_SetCurrRingHdl(mlv.r);
336
337    lv = mlv.lv;
338  }
339  else lv = mpsr_InitLeftv(NONE, NULL); 
340 
341  return status;
342}
343
344/***************************************************************
345 *
346 * Top-level routine for getting a mpsr_leftv
347 *
348 ***************************************************************/
349
350// if quote > 0, then identifiers are not tried to be resolved, or
351// converted into a ring variable
352mpsr_Status_t mpsr_GetLeftv(MP_Link_pt link, mpsr_leftv mlv, short quote)
353{
354  MPT_Node_pt node = NULL;
355  MP_NodeType_t type;
356  mlv->r = NULL;
357  mlv->lv = NULL;
358
359  mpt_failr(MPT_GetNode(link, &node));
360
361  type = node->type;
362
363  if (MP_IsFixedIntegerType(type))
364    failr(mpsr_GetIntLeftv(node, mlv));
365  else if (MP_IsIdType(type))
366    failr(mpsr_GetIdentifierLeftv(node, mlv, quote));
367  else
368  {
369    switch (node->type)
370    {
371        case MP_ApIntType:
372          failr(mpsr_GetApIntLeftv(node, mlv));
373          break;       
374
375        case MP_StringType:
376          failr(mpsr_GetStringLeftv(node, mlv));
377          break;       
378
379        case MP_Real32Type:
380          failr(mpsr_GetReal32Leftv(node, mlv));
381          break;       
382       
383        case MP_CommonOperatorType:
384          failr(mpsr_GetCommonOperatorLeftv(link, node, mlv, quote));
385          break;       
386
387        case MP_OperatorType:
388          failr(mpsr_GetOperatorLeftv(link, node, mlv, quote));
389          break;       
390
391        default:
392          MPT_DeleteNode(node);
393          return mpsr_SetError(mpsr_UnknownMPNodeType);
394    }
395  }
396 
397  // everything was ok
398  MPT_DeleteNode(node);
399  return mpsr_Success;
400}
401
402/***************************************************************
403 *
404 * mpsr_Get*Leftv
405 *
406 ***************************************************************/
407mpsr_Status_t mpsr_GetCommonOperatorLeftv(MP_Link_pt link,
408                                        MPT_Node_pt node,
409                                        mpsr_leftv mlv,
410                                        short quote)
411{
412  mpsr_assume(node->type == MP_CommonOperatorType);
413
414  // Check for Singular data types
415  // IntVec
416  if (IsIntVecNode(node))
417    return GetIntVecLeftv(link, node, mlv);
418  // IntMat
419  else if (IsIntMatNode(node))
420    return GetIntMatLeftv(link, node, mlv);
421  // Ring
422  else if (IsRingNode(node, mlv->r))
423    return GetRingLeftv(link, node, mlv);
424  // Poly
425  else if (IsPolyNode(node, mlv->r))
426    return GetPolyLeftv(link, node, mlv);
427  // PolyVector
428  else if (IsPolyVectorNode(node, mlv->r))
429    return GetPolyVectorLeftv(link, node, mlv);
430  // Ideal
431  else if (IsIdealNode(node, mlv->r))
432    return GetIdealLeftv(link, node, mlv);
433  // Module
434  else if (IsModuleNode(node, mlv->r))
435    return GetModuleLeftv(link, node, mlv);
436  // Matrix
437  else if (IsMatrixNode(node, mlv->r))
438    return GetMatrixLeftv(link, node, mlv);
439  else if (IsQuitNode(node))
440    return GetQuitLeftv(mlv);
441  // Map
442  else
443    // now it should be a command (which handles Proc, Map and List
444    // seperately)
445    return GetCopCommandLeftv(link, node, mlv, quote);
446}
447
448mpsr_Status_t mpsr_GetOperatorLeftv(MP_Link_pt link,
449                                  MPT_Node_pt node,
450                                  mpsr_leftv mlv,
451                                  short quote)
452{
453  mpsr_assume(node->type == MP_OperatorType);
454  MP_NumChild_t nc = node->numchild, i;
455  mpsr_sleftv smlv1, *mlv1 = &smlv1;
456 
457
458  if (MPT_GetProtoTypespec(node) != NULL)
459    return mpsr_SetError(mpsr_CanNotHandlePrototype);
460
461  if (nc > 0)
462  {
463    failr(mpsr_GetLeftv(link, mlv, quote));
464    for (i=1; i<nc; i++)
465    {
466      failr(mpsr_GetLeftv(link, mlv1, quote));
467      failr(mpsr_MergeLeftv(mlv, mlv1));
468    }
469  }
470 
471  command cmd = (command) Alloc0(sizeof(sip_command));
472  cmd->op = PROC_CMD;
473  cmd->arg1.rtyp = STRING_CMD;
474  cmd->arg1.data = (void *) mstrdup(MP_STRING_T(node->nvalue));
475
476  if (node->numchild > 0)
477  {
478    cmd->argc = 2;
479    memcpy(&(cmd->arg2), mlv->lv, sizeof(sleftv));
480    Free(mlv->lv, sizeof(sleftv));
481  }
482  else cmd->argc = 1;
483
484  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
485  return mpsr_Success;
486}
487 
488/***************************************************************
489 *
490 * Get*Leftv routines
491 *
492 ***************************************************************/
493//
494// Get*Leftv routines
495//
496static mpsr_Status_t GetIntVecLeftv(MP_Link_pt link, MPT_Node_pt node,
497                                  mpsr_leftv mlv)
498{
499  intvec *iv = new intvec(node->numchild);
500  int *v = iv->ivGetVec();
501
502  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
503  mlv->lv = mpsr_InitLeftv(INTVEC_CMD, (void *) iv);
504  return mpsr_Success;
505}
506
507static mpsr_Status_t GetIntMatLeftv(MP_Link_pt link, MPT_Node_pt node,
508                                  mpsr_leftv mlv)
509{
510  intvec *iv;
511  int row = node->numchild, col = 1, *v;
512  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
513                                     MP_AnnotMatrixDimension);
514  if (annot != NULL &&
515      annot->value != NULL &&
516      annot->value->node->numchild == 2 &&
517      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
518                MP_CopBasicList))
519  {
520    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
521    if (tarray[0]->node->type == MP_Uint32Type &&
522        tarray[1]->node->type == MP_Uint32Type)
523    {
524      row = MP_UINT32_T(tarray[0]->node->nvalue);
525      col = MP_UINT32_T(tarray[1]->node->nvalue);
526    }
527  }
528
529  iv = new intvec(row, col, 0);
530  v = iv->ivGetVec();
531  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
532  mlv->lv = mpsr_InitLeftv(INTMAT_CMD, (void *) iv);
533  return mpsr_Success;
534} 
535
536static mpsr_Status_t GetRingLeftv(MP_Link_pt link, MPT_Node_pt node,
537                                mpsr_leftv mlv)
538{
539  mpsr_assume(mlv->r != NULL);
540
541  if (node->numchild != 0) mpt_failr(MPT_SkipArgs(link, node));
542
543  mlv->lv = mpsr_InitLeftv(((mlv->r->qideal != NULL) ? (short) QRING_CMD :
544                            (short) RING_CMD),
545                           (void *) mlv->r);
546  mlv->r = NULL;
547  return mpsr_Success;
548}
549
550static mpsr_Status_t GetPolyLeftv(MP_Link_pt link, MPT_Node_pt node,
551                                mpsr_leftv mlv)
552{
553  poly p;
554
555  mpsr_assume(mlv->r != NULL);
556 
557  failr(mpsr_GetPoly(link, p, node->numchild, mlv->r));
558  mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
559  return mpsr_Success;
560}
561
562static mpsr_Status_t GetPolyVectorLeftv(MP_Link_pt link, MPT_Node_pt node,
563                                      mpsr_leftv mlv)
564{
565  poly p;
566
567  mpsr_assume(mlv->r != NULL);
568 
569  failr(mpsr_GetPolyVector(link, p, node->numchild, mlv->r));
570  mlv->lv = mpsr_InitLeftv(VECTOR_CMD, (void *) p);
571  return mpsr_Success;
572}
573
574static mpsr_Status_t GetIdealLeftv(MP_Link_pt link, MPT_Node_pt node,
575                                 mpsr_leftv mlv)
576{
577  MP_NumChild_t nc = node->numchild, i;
578  ring r = mlv->r;
579  MP_Uint32_t nmon;
580
581  mpsr_assume(r != NULL);
582  ideal id = idInit(nc,1);
583  for (i=0; i<nc; i++)
584  {
585    mp_failr(IMP_GetUint32(link, &nmon));
586    failr(mpsr_GetPoly(link, id->m[i], nmon, r));
587  }
588 
589  mlv->lv = mpsr_InitLeftv(IDEAL_CMD, (void *) id);
590  return mpsr_Success;
591}
592
593static mpsr_Status_t GetModuleLeftv(MP_Link_pt link, MPT_Node_pt node,
594                                  mpsr_leftv mlv)
595{
596  MP_NumChild_t nc = node->numchild, i;
597  ring r = mlv->r;
598  MP_Uint32_t nmon;
599
600  mpsr_assume(r != NULL);
601  ideal id = idInit(nc,1);
602  for (i=0; i<nc; i++)
603  {
604    mp_failr(IMP_GetUint32(link, &nmon));
605    failr(mpsr_GetPolyVector(link, id->m[i], nmon, r));
606  }
607
608  mlv->lv = mpsr_InitLeftv(MODUL_CMD, (void *) id);
609  return mpsr_Success;
610}
611
612static mpsr_Status_t GetMatrixLeftv(MP_Link_pt link, MPT_Node_pt node,
613                                  mpsr_leftv mlv)
614{
615  MP_NumChild_t nc = node->numchild, row = nc, col = 1, i;
616  matrix mp;
617  MP_Uint32_t nmon;
618  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
619                                     MP_AnnotMatrixDimension);
620  if (annot != NULL &&
621      annot->value != NULL &&
622      annot->value->node->numchild == 2 &&
623      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
624               MP_CopBasicList))
625  {
626    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
627    if (tarray[0]->node->type == MP_Uint32Type &&
628        tarray[1]->node->type == MP_Uint32Type)
629    {
630      row = MP_UINT32_T(tarray[0]->node->nvalue);
631      col = MP_UINT32_T(tarray[1]->node->nvalue);
632    }
633  }
634
635  mpsr_assume(mlv->r != NULL);
636  mp = mpNew(row, col);
637  for (i=0; i<nc; i++)
638  {
639    mp_failr(IMP_GetUint32(link, &nmon));
640    failr(mpsr_GetPoly(link, mp->m[i], nmon, mlv->r));
641  }
642
643  mlv->lv = mpsr_InitLeftv(MATRIX_CMD, (void *) mp);
644  return mpsr_Success;
645}
646
647static mpsr_Status_t GetMapLeftv(MP_Link_pt link, MPT_Node_pt node,
648                               mpsr_leftv mlv)
649{
650  mpsr_sleftv smlv1, smlv2, *mlv1 = &smlv1, *mlv2 = &smlv2;
651
652  if (node->numchild != 3)
653    return mpsr_SetError(mpsr_WrongNumofArgs);
654 
655  failr(mpsr_GetLeftv(link, mlv, 0));
656  failr(mpsr_GetLeftv(link, mlv1, 0));
657  failr(mpsr_GetLeftv(link, mlv2, 0));
658
659  if (mlv->lv->rtyp != RING_CMD ||
660      mlv1->lv->rtyp != STRING_CMD ||
661      mlv2->lv->rtyp != IDEAL_CMD)
662    return mpsr_SetError(mpsr_WrongArgumentType);
663
664  ring r = (ring) mlv->lv->data, r2;
665  char *name = (char *) mlv1->lv->data;
666  ideal id = (ideal) mlv2->lv->data;
667
668  idhdl h = mpsr_FindIdhdl(name, r2);
669  if (h == NULL || IDTYP(h) != RING_CMD || ! mpsr_RingEqual(IDRING(h), r))
670  {
671    h = mpsr_InitIdhdl(RING_CMD, r, name);
672    h->next = idroot;
673    idroot = h;
674  }
675
676  map m = (map) Alloc0(sizeof(sip_smap));
677  m->preimage = mstrdup(name);
678  m->m = id->m;
679  m->nrows = id->nrows;
680  m->ncols = id->ncols;
681
682  Free(mlv->lv, sizeof(sleftv));
683
684  FreeL(mlv1->lv->data);
685  Free(mlv1->lv, sizeof(sleftv));
686 
687  Free(id, sizeof(sip_sideal));
688  Free(mlv2->lv, sizeof(sleftv));
689
690  mlv->r = mlv2->r;
691  mlv->lv = mpsr_InitLeftv(MAP_CMD, (void *) m);
692
693  return mpsr_Success;
694}
695
696 
697static mpsr_Status_t GetCopCommandLeftv(MP_Link_pt link, MPT_Node_pt node,
698                                        mpsr_leftv mlv, short quote)
699{
700  short tok;
701  MP_NumChild_t nc = node->numchild, i;
702  mpsr_sleftv smlv1, *mlv1 = &smlv1;
703  MPT_Tree_pt typespec;
704 
705 
706  failr(mpsr_mp2tok(node->dict, MP_COMMON_T(node->nvalue), &tok));
707
708  if ((typespec = MPT_GetProtoTypespec(node)) &&
709      MPT_IsTrueProtoTypeSpec(typespec))
710    return mpsr_SetError(mpsr_CanNotHandlePrototype);
711
712  if (tok == MAP_CMD) return GetMapLeftv(link, node, mlv);
713 
714  if (nc > 0)
715  {
716    if (tok == '=') failr(mpsr_GetLeftv(link, mlv, quote + 1));
717    else failr(mpsr_GetLeftv(link, mlv, quote));
718  }
719
720  for (i=1; i<nc; i++)
721  {
722    failr(mpsr_GetLeftv(link, mlv1, quote));
723    failr(mpsr_MergeLeftv(mlv, mlv1));
724  }
725
726  command cmd = (command) Alloc0(sizeof(sip_command));
727  cmd->op = tok;
728  cmd->argc = nc;
729
730  // check that associative operators are binary
731  if (nc > 2 && (tok == '+' || tok == '*'))
732  {
733    leftv lv = mlv->lv, lv2;
734    command c = cmd, c2;
735
736    for (i=2; i<nc; i++)
737    {
738      c->op = tok;
739      c->argc = 2;
740      memcpy(&(c->arg1), lv, sizeof(sleftv));
741      c->arg1.next = NULL;
742
743      c2 = (command) Alloc0(sizeof(sip_command));
744      c->arg2.data = (void *) c2;
745      c->arg2.rtyp = COMMAND;
746      c = c2;
747      lv2 = lv->next;
748      Free(lv, sizeof(sleftv));
749      lv = lv2;
750    }
751    c->op = tok;
752    c->argc = 2;
753    memcpy(&(c->arg1), lv, sizeof(sleftv));
754    c->arg1.next = NULL;
755    memcpy(&(c->arg2), lv->next, sizeof(sleftv));
756    Free(lv->next, sizeof(sleftv));
757    Free(lv, sizeof(sleftv));
758  }
759  else if (nc >= 1)
760  {
761    memcpy(&(cmd->arg1), mlv->lv, sizeof(sleftv));
762    if (nc <= 3)
763    {
764      (cmd->arg1).next = NULL;
765      if (nc >= 2)
766      {
767        memcpy(&(cmd->arg2), mlv->lv->next, sizeof(sleftv));
768        (cmd->arg2).next = NULL;
769
770        if (nc == 3)
771        {
772          memcpy(&(cmd->arg3), mlv->lv->next->next, sizeof(sleftv));
773          Free(mlv->lv->next->next, sizeof(sleftv));
774        }
775        Free(mlv->lv->next, sizeof(sleftv));
776      }
777    }
778    Free(mlv->lv, sizeof(sleftv));
779  }
780
781  // Now we perform some tree manipulations
782  if (nc == 0 && tok == LIST_CMD)
783    // Here we work around a Singular bug: It can not handle lists of 0 args
784    // so we construct them explicitely
785  {
786    lists l = (lists) Alloc(sizeof(slists));
787    l->Init(0);
788    mlv->lv = mpsr_InitLeftv(LIST_CMD, (void *) l);
789    return mpsr_Success;
790  }
791  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
792  return mpsr_Success;
793}
794
795 
796/***************************************************************
797 *
798 * The routine for Getting External Data
799 *
800 ***************************************************************/
801
802// this is all the data we want to have in directly when MPT_GetTree
803// is called, i.e. when the value of annots is read
804MPT_Status_t mpsr_GetExternalData(MP_Link_pt link,
805                                  MPT_Arg_t *odata,
806                                  MPT_Node_pt node)
807{
808  *odata = NULL;
809 
810  if (node->type == MP_CommonOperatorType)
811  {
812    mpsr_sleftv mlv;
813    mpsr_Status_t status;
814
815    // we would like to get polys and ideals directly
816    if (IsPolyNode(node, mlv.r))
817      status = GetPolyLeftv(link, node, &mlv);
818    // Ideal
819    else if (IsIdealNode(node, mlv.r))
820      status = GetIdealLeftv(link, node, &mlv);
821    else
822      return MPT_NotExternalData;
823
824    if (status == mpsr_Success)
825    {
826      mpsr_leftv mmlv = (mpsr_leftv) Alloc0(sizeof(mpsr_sleftv));
827      memcpy(mmlv, &mlv, sizeof(mpsr_sleftv));
828      *odata = (MPT_ExternalData_t) mmlv;
829      return MPT_Success;
830    }
831    else
832      return MPT_Failure;
833  }
834  else
835    return MPT_NotExternalData;
836}
837
838   
839/***************************************************************
840 * 
841 * A routine which gets the previous dump of Singular
842 *
843 ***************************************************************/
844
845mpsr_Status_t mpsr_GetDump(MP_Link_pt link)
846{
847  mpsr_sleftv mlv;
848  mpsr_Status_t status = mpsr_Success;
849
850  status = (MP_InitMsg(link) == MP_Success ? mpsr_Success : mpsr_MP_Failure);
851  while ((status == mpsr_Success) && (! MP_TestEofMsg(link)))
852  {
853    status=mpsr_GetLeftv(link, &mlv, 0);
854
855    if (status == mpsr_Success)
856    {
857#ifdef MPSR_DEBUG
858      command cmd = (command) mlv.lv->data;
859      fprintf(stdout, "Dump got %s \n", cmd->arg1.name);
860      fflush(stdout);
861#endif     
862      mpsr_SetCurrRingHdl(mlv.r);
863      if (mlv.lv != NULL)
864      {
865        mlv.lv->Eval();
866        mlv.lv->CleanUp();
867        Free(mlv.lv, sizeof(sleftv));
868      }
869    }
870    else
871      mpsr_PrintError(status);
872  }
873  return status;
874}
875#endif
Note: See TracBrowser for help on using the repository browser.