MCPcopy Create free account
hub / github.com/Singular/Singular / lString

Function lString

Singular/lists.cc:403–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

401}
402
403char* lString(lists l, BOOLEAN typed, int dim)
404{
405 if (l->nr == -1)
406 {
407 if (typed) return omStrDup("list()");
408 return omStrDup("");
409 }
410
411 char** slist = (char**) omAlloc((l->nr+1) * sizeof(char*));
412 int i, j, k;
413 char *s;
414 for (i=0, j = 0, k = 0; i<=l->nr; i++)
415 {
416 slist[i] = l->m[i].String(NULL, typed, dim);
417 assume(slist[i] != NULL);
418 omCheckAddr(slist[i]);
419 if (*(slist[i]) != '\0')
420 {
421 j += strlen(slist[i]);
422 k++;
423 }
424 }
425 size_t len=j+k+2+(typed ? 10 : 0) + (dim == 2 ? k : 0);
426 s = (char*) omAlloc(len);
427
428 if (typed)
429 snprintf(s, len,"list(");
430 else
431 *s = '\0';
432
433 for (i=0; i<=l->nr; i++)
434 {
435 if (*(slist[i]) != '\0')
436 {
437 strcat(s, slist[i]);
438 strcat(s, ",");
439 if (dim == 2) strcat(s, "\n");
440 }
441 omCheckAddr(s);
442 omFree(slist[i]);
443 }
444 if (k > 0) s[strlen(s) - (dim == 2 ? 2 : 1)] = '\0';
445 if (typed) strcat(s, ")");
446 omCheckAddr(s);
447 omFreeSize(slist, (l->nr+1) * sizeof(char*));
448 return s;
449}

Callers 2

StringMethod · 0.85
rComposeOrderFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected