Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is to exceed 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - gp - gp.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.0 lcov report (development 23699-13b23c56a) Lines: 287 349 82.2 %
Date: 2019-03-21 05:44:05 Functions: 26 31 83.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /**                                                               **/
      16             : /**                        PARI CALCULATOR                        **/
      17             : /**                                                               **/
      18             : /*******************************************************************/
      19             : #ifdef _WIN32
      20             : #  include "../systems/mingw/pwinver.h"
      21             : #  include <windows.h>
      22             : #  include "../systems/mingw/mingw.h"
      23             : #endif
      24             : #include "pari.h"
      25             : #include "paripriv.h"
      26             : #include "gp.h"
      27             : 
      28             : static jmp_buf *env;
      29             : static pari_stack s_env;
      30             : void (*cb_gp_output)(GEN z) = NULL;
      31             : void (*cb_pari_end_output)(void) = NULL;
      32             : 
      33             : static void
      34           0 : gp_ask_confirm(const char *s)
      35             : {
      36           0 :   err_printf(s);
      37           0 :   err_printf(". OK ? (^C if not)\n");
      38           0 :   pari_hit_return();
      39           0 : }
      40             : 
      41             : /* numerr < 0: after changing PARI stack size
      42             :  * numerr > 0: normal error, including SIGINT */
      43             : static void
      44        9606 : gp_err_recover(long numerr)
      45             : {
      46        9606 :   longjmp(env[s_env.n-1], numerr);
      47             : }
      48             : 
      49             : /* numerr >= 0 */
      50             : static void
      51        9294 : gp_pre_recover(long numerr)
      52             : {
      53        9294 :   out_puts(pariErr, "\n"); pariErr->flush();
      54        9294 :   gp_err_recover(numerr);
      55           0 : }
      56             : 
      57             : static void
      58       97385 : reset_ctrlc(void)
      59             : {
      60             : #if defined(_WIN32) || defined(__CYGWIN32__)
      61             :   win32ctrlc = 0;
      62             : #endif
      63       97385 : }
      64             : 
      65             : static int
      66       60910 : is_silent(char *s) { return s[strlen(s) - 1] == ';'; }
      67             : 
      68             : static int stdin_isatty = 0;
      69             : static int
      70        1609 : is_interactive(void)
      71        1609 : { return pari_infile == stdin && stdin_isatty; }
      72             : 
      73             : /*******************************************************************/
      74             : /**                                                               **/
      75             : /**                        INITIALIZATION                         **/
      76             : /**                                                               **/
      77             : /*******************************************************************/
      78             : static void
      79           2 : print_shortversion(void)
      80             : {
      81           2 :   const ulong mask = (1UL<<PARI_VERSION_SHIFT) - 1;
      82           2 :   ulong n = paricfg_version_code, major, minor, patch;
      83             : 
      84           2 :   patch = n & mask; n >>= PARI_VERSION_SHIFT;
      85           2 :   minor = n & mask; n >>= PARI_VERSION_SHIFT;
      86           2 :   major = n;
      87           2 :   printf("%lu.%lu.%lu\n", major,minor,patch); exit(0);
      88             : }
      89             : 
      90             : static void
      91           2 : usage(char *s)
      92             : {
      93           2 :   printf("### Usage: %s [options] [GP files]\n", s);
      94           2 :   printf("Available options:\n");
      95           2 :   printf("  [-f,--fast]\t\tFast start: do not read .gprc\n");
      96           2 :   printf("  [-q,--quiet]\t\tQuiet mode: do not print banner and history numbers\n");
      97           2 :   printf("  [-s stacksize]\tStart with the PARI stack of given size (in bytes)\n");
      98           2 :   printf("  [--default key=val]\tExecute default(key,val) on startup\n");
      99           2 :   printf("  [--emacs]\t\tRun as if in Emacs shell\n");
     100           2 :   printf("  [--help]\t\tPrint this message\n");
     101           2 :   printf("  [--test]\t\tTest mode. No history, wrap long lines (bench only)\n");
     102           2 :   printf("  [--texmacs]\t\tRun as if using TeXmacs frontend\n");
     103           2 :   printf("  [--version]\t\tOutput version info and exit\n");
     104           2 :   printf("  [--version-short]\tOutput version number and exit\n\n");
     105           2 :   exit(0);
     106             : }
     107             : 
     108             : static void
     109           2 : gp_head(void)
     110             : {
     111           2 :   pari_print_version();
     112           2 :   pari_putc('\n');
     113           2 :   pari_center("Copyright (C) 2000-2019 The PARI Group");
     114           2 :   pari_putc('\n');
     115           2 :   print_text("PARI/GP is free software, covered by the GNU General Public \
     116             : License, and comes WITHOUT ANY WARRANTY WHATSOEVER.");
     117           2 :   pari_puts("\nType ? for help, \\q to quit.\n");
     118           2 :   pari_printf("Type ?%d for how to get moral"
     119             :               " (and possibly technical) support.\n", pari_community());
     120           2 :   if (pari_mainstack->vsize)
     121           0 :     pari_printf("\nparisizemax = %lu, primelimit = %lu",
     122           0 :                 pari_mainstack->vsize,GP_DATA->primelimit);
     123             :   else
     124           4 :     pari_printf("\nparisize = %lu, primelimit = %lu",
     125           4 :                 pari_mainstack->rsize,GP_DATA->primelimit);
     126           2 :   if (pari_mt_nbthreads > 1)
     127           0 :     pari_printf(", nbthreads = %lu", pari_mt_nbthreads);
     128           2 :   pari_putc('\n');
     129           2 : }
     130             : 
     131             : static char *
     132           0 : read_arg(long *nread, char *t, long argc, char **argv)
     133             : {
     134           0 :   long i = *nread;
     135           0 :   if (isdigit((int)*t)) return t;
     136           0 :   if (*t || i==argc) usage(argv[0]);
     137           0 :   *nread = i+1; return argv[i];
     138             : }
     139             : 
     140             : static char *
     141           0 : read_arg_equal(long *nread, char *t, long argc, char **argv)
     142             : {
     143           0 :   long i = *nread;
     144           0 :   if (*t=='=' && isdigit((int)t[1])) return t+1;
     145           0 :   if (*t || i==argc) usage(argv[0]);
     146           0 :   *nread = i+1; return argv[i];
     147             : }
     148             : 
     149             : static void
     150           4 : init_trivial_stack(void)
     151             : {
     152           4 :   const size_t s = 2048;
     153           4 :   pari_mainstack->size = s;
     154           4 :   pari_mainstack->bot = (pari_sp)pari_malloc(s);
     155           4 :   avma = pari_mainstack->top = pari_mainstack->bot + s;
     156           4 : }
     157             : 
     158             : static void
     159           4 : free_trivial_stack(void)
     160             : {
     161           4 :   free((void*)pari_mainstack->bot);
     162           4 : }
     163             : 
     164             : typedef struct { char *key, *val; } pair_t;
     165             : /* If ab of the form key=val, record pair in new stack entry
     166             :  * P[n].key must be freed by caller to avoid memory leak */
     167             : static void
     168           6 : record_default(pari_stack *s_P, char *ab)
     169             : {
     170           6 :   pair_t *P = (pair_t*)*pari_stack_base(s_P);
     171             :   char *k, *v;
     172             :   long n;
     173           6 :   ab = pari_strdup(ab);
     174           6 :   parse_key_val(ab, &k, &v);
     175           6 :   n = pari_stack_new(s_P);
     176           6 :   P[n].key = k;
     177           6 :   P[n].val = v;
     178           6 : }
     179             : static void
     180        1566 : read_opt(pari_stack *p_A, long argc, char **argv)
     181             : {
     182             :   pair_t *P;
     183             :   pari_stack s_P; /* key / value to record default() settings */
     184        1566 :   char *b = NULL, *p = NULL, *s = NULL;
     185        1566 :   ulong f = GP_DATA->flags;
     186        1566 :   long i = 1, initrc = 1;
     187             : 
     188             :   (void)&p; (void)&b; (void)&s; /* -Wall gcc-2.95 */
     189             : 
     190        1566 :   pari_stack_init(&s_P,sizeof(*P),(void**)&P);
     191        1566 :   pari_stack_alloc(&s_P, 64);
     192        1566 :   pari_outfile = stderr;
     193        6246 :   while (i < argc)
     194             :   {
     195        3122 :     char *t = argv[i];
     196             : 
     197        3122 :     if (*t++ != '-') break;
     198        3122 :     i++;
     199             : START:
     200        3122 :     switch(*t++)
     201             :     {
     202           0 :       case 'p': p = read_arg(&i,t,argc,argv); break;
     203           0 :       case 's': s = read_arg(&i,t,argc,argv); break;
     204             :       case 'e':
     205           0 :         f |= gpd_EMACS; if (*t) goto START;
     206           0 :         break;
     207             :       case 'q':
     208        1552 :         f |= gpd_QUIET; if (*t) goto START;
     209        1552 :         break;
     210             :       case 't':
     211           0 :         f |= gpd_TEST; if (*t) goto START;
     212           0 :         break;
     213             :       case 'f':
     214          13 :         initrc = 0; if (*t) goto START;
     215          13 :         break;
     216             :       case 'D':
     217           4 :         if (*t || i == argc) usage(argv[0]);
     218           4 :         record_default(&s_P, argv[i++]);
     219           4 :         break;
     220             :       case '-':
     221        1553 :         if (strcmp(t, "version-short") == 0) { print_shortversion(); exit(0); }
     222        1551 :         if (strcmp(t, "version") == 0) {
     223           4 :           init_trivial_stack(); pari_print_version();
     224           4 :           free_trivial_stack(); exit(0);
     225             :         }
     226        1547 :         if (strcmp(t, "default") == 0) {
     227           2 :           if (i == argc) usage(argv[0]);
     228           2 :           record_default(&s_P, argv[i++]);
     229           2 :           break;
     230             :         }
     231        1545 :         if (strcmp(t, "texmacs") == 0) { f |= gpd_TEXMACS; break; }
     232        1545 :         if (strcmp(t, "emacs") == 0) { f |= gpd_EMACS; break; }
     233        1545 :         if (strcmp(t, "test") == 0) { f |= gpd_TEST; initrc = 0; break; }
     234           6 :         if (strcmp(t, "quiet") == 0) { f |= gpd_QUIET; break; }
     235           4 :         if (strcmp(t, "fast") == 0) { initrc = 0; break; }
     236           2 :         if (strncmp(t, "primelimit",10) == 0) {p = read_arg_equal(&i,t+10,argc,argv); break; }
     237           2 :         if (strncmp(t, "stacksize",9) == 0) {s = read_arg_equal(&i,t+9,argc,argv); break; }
     238             :        /* fall through */
     239             :       default:
     240           2 :         usage(argv[0]);
     241             :     }
     242             :   }
     243        1558 :   if (f & gpd_TEST) stdin_isatty = 0;
     244        1558 :   GP_DATA->flags = f;
     245             : #ifdef READLINE
     246        1558 :   GP_DATA->use_readline = stdin_isatty;
     247             : #endif
     248        1558 :   if (!is_interactive()) GP_DATA->breakloop = 0;
     249        1558 :   if (initrc) gp_initrc(p_A);
     250        1558 :   for ( ; i < argc; i++) pari_stack_pushp(p_A, pari_strdup(argv[i]));
     251             : 
     252             :   /* override the values from gprc */
     253        1558 :   if (p) (void)sd_primelimit(p, d_INITRC);
     254        1558 :   if (s) (void)sd_parisize(s, d_INITRC);
     255        1562 :   for (i = 0; i < s_P.n; i++) {
     256           6 :     setdefault(P[i].key, P[i].val, d_INITRC);
     257           4 :     free((void*)P[i].key);
     258             :   }
     259        1556 :   pari_stack_delete(&s_P);
     260        1556 :   pari_outfile = stdout;
     261        1556 : }
     262             : 
     263             : /*******************************************************************/
     264             : /**                                                               **/
     265             : /**                            TEST MODE                          **/
     266             : /**                                                               **/
     267             : /*******************************************************************/
     268             : static int
     269      181899 : test_is_interactive(void) { return 0; }
     270             : 
     271             : static void
     272       41431 : test_output(GEN z) { init_linewrap(76); gen_output(z); }
     273             : void
     274        1539 : init_test(void)
     275             : {
     276        1539 :   disable_color = 1;
     277        1539 :   init_linewrap(76);
     278        1539 :   pari_errfile = stdout;
     279        1539 :   cb_gp_output = test_output;
     280        1539 :   cb_pari_is_interactive = test_is_interactive;
     281        1539 : }
     282             : 
     283             : /*******************************************************************/
     284             : /**                                                               **/
     285             : /**                   FORMAT GP OUTPUT                            **/
     286             : /**                                                               **/
     287             : /*******************************************************************/
     288             :     /* REGULAR */
     289             : static void
     290           4 : normal_output(GEN z, long n)
     291             : {
     292           4 :   long l = 0;
     293             :   char *s;
     294             :   /* history number */
     295           4 :   if (n)
     296             :   {
     297             :     char buf[64];
     298           4 :     if (!(GP_DATA->flags & gpd_QUIET))
     299             :     {
     300           2 :       term_color(c_HIST);
     301           2 :       sprintf(buf, "%%%ld = ", n);
     302           2 :       pari_puts(buf);
     303           2 :       l = strlen(buf);
     304             :     }
     305             :   }
     306             :   /* output */
     307           4 :   term_color(c_OUTPUT);
     308           4 :   s = GENtostr(z);
     309           4 :   if (GP_DATA->lim_lines)
     310           2 :     lim_lines_output(s, l, GP_DATA->lim_lines);
     311             :   else
     312           2 :     pari_puts(s);
     313           4 :   pari_free(s);
     314           4 :   term_color(c_NONE); pari_putc('\n');
     315           4 : }
     316             : 
     317             : static void
     318       41435 : gp_output(GEN z)
     319             : {
     320       41435 :   if (cb_gp_output) { cb_gp_output(z); return; }
     321           4 :   if (GP_DATA->fmt->prettyp == f_PRETTY)
     322           0 :   { if (tex2mail_output(z, GP_DATA->hist->total)) return; }
     323           4 :   normal_output(z, GP_DATA->hist->total);
     324           4 :   pari_flush();
     325             : }
     326             : 
     327             : static GEN
     328        1556 : gp_main_loop(long ismain)
     329             : {
     330        1556 :   VOLATILE GEN z = gnil;
     331        1556 :   VOLATILE long t = 0, r = 0;
     332        1556 :   VOLATILE pari_sp av = avma;
     333             :   filtre_t F;
     334        1556 :   Buffer *b = filtered_buffer(&F);
     335             :   struct gp_context rec;
     336             :   long er;
     337        1556 :   if ((er = setjmp(env[s_env.n-1])))
     338             :   { /* recover: jump from error [ > 0 ] or allocatemem [ -1 ] */
     339        9583 :     if (er > 0) { /* true error */
     340        9285 :       if (!(GP_DATA->recover)) exit(1);
     341        9285 :       gp_context_restore(&rec);
     342             :       /* true error not from main instance, let caller sort it out */
     343        9285 :       if (!ismain) { kill_buffers_upto_including(b); return NULL; }
     344             :     } else { /* allocatemem */
     345         298 :       tmp_restore(rec.file.file);
     346         298 :       gp_context_save(&rec);
     347             :     }
     348        9583 :     set_avma(av = pari_mainstack->top);
     349        9583 :     parivstack_reset();
     350        9583 :     kill_buffers_upto(b);
     351        9583 :     pari_alarm(0);
     352             :   }
     353             :   for(;;)
     354             :   {
     355      186421 :     gp_context_save(&rec);
     356       98780 :     if (! gp_read_line(&F, NULL))
     357             :     {
     358        1556 :       if (popinfile()) gp_quit(0);
     359           0 :       if (ismain) continue;
     360           0 :       pop_buffer(); return z;
     361             :     }
     362       97224 :     if (ismain)
     363             :     {
     364       97224 :       reset_ctrlc();
     365       97224 :       timer_start(GP_DATA->T);
     366       97224 :       walltimer_start(GP_DATA->Tw);
     367       97224 :       pari_set_last_newline(1);
     368             :     }
     369       97224 :     if (gp_meta(b->buf,ismain)) continue;
     370       82350 :     z = pari_compile_str(b->buf);
     371       82287 :     z = closure_evalres(z);
     372       72767 :     if (!ismain) continue;
     373             : 
     374       72767 :     t = timer_delay(GP_DATA->T);
     375       72767 :     r = walltimer_delay(GP_DATA->Tw);
     376       72767 :     if (!pari_last_was_newline()) pari_putc('\n');
     377       72767 :     pari_alarm(0);
     378       72767 :     if (t && GP_DATA->chrono)
     379             :     {
     380           0 :       if (pari_mt_nbthreads==1)
     381             :       {
     382           0 :         pari_puts("time = ");
     383           0 :         pari_puts(gp_format_time(t));
     384             :       }
     385             :       else
     386             :       {
     387           0 :         pari_puts("cpu time = ");
     388           0 :         pari_puts(gp_format_time(t));
     389           0 :         pari_puts(", real time = ");
     390           0 :         pari_puts(gp_format_time(r));
     391             :       }
     392           0 :       pari_puts(".\n");
     393             :     }
     394       72767 :     if (GP_DATA->simplify) z = simplify_shallow(z);
     395       72767 :     pari_add_hist(z, t, r);
     396       72767 :     if (z != gnil && ! is_silent(b->buf) ) gp_output(z);
     397       72767 :     set_avma(av);
     398       72767 :     parivstack_reset();
     399             :   }
     400             : }
     401             : 
     402             : /* as gp_read_file, before running the main gp instance */
     403             : static void
     404           0 : read_main(const char *s)
     405             : {
     406             :   GEN z;
     407           0 :   if (setjmp(env[s_env.n-1]))
     408           0 :     z = NULL;
     409             :   else {
     410           0 :     FILE *f = switchin(s);
     411           0 :     if (file_is_binary(f)) {
     412           0 :       z = readbin(s,f, NULL);
     413           0 :       popinfile();
     414             :     }
     415           0 :     else z = gp_main_loop(0);
     416             :   }
     417           0 :   if (!z) err_printf("... skipping file '%s'\n", s);
     418           0 :   set_avma(pari_mainstack->top);
     419           0 : }
     420             : 
     421             : static const char *
     422          63 : break_loop_prompt(long n)
     423             : {
     424          63 :   const char *s = (n==1)? "break> ": stack_sprintf("break[%ld]> ", n);
     425          63 :   return gp_format_prompt(s);
     426             : }
     427             : 
     428             : static long frame_level=0, dbg_level = 0;
     429             : 
     430             : static int
     431          63 : break_loop(int numerr)
     432             : {
     433             :   filtre_t F;
     434             :   Buffer *b;
     435          63 :   int sigint = numerr<0, go_on = sigint;
     436             :   struct gp_context rec1, rec2;
     437             :   const char *prompt, *msg;
     438          63 :   long nenv, oldframe_level = frame_level;
     439             :   pari_sp av;
     440             : 
     441          63 :   if (numerr == e_SYNTAX) return 0;
     442          63 :   if (numerr == e_STACK) { evalstate_clone(); set_avma(pari_mainstack->top); }
     443          63 :   gp_context_save(&rec1);
     444             : 
     445          63 :   b = filtered_buffer(&F);
     446          63 :   nenv=pari_stack_new(&s_env);
     447          63 :   prompt = break_loop_prompt(s_env.n-1);
     448          63 :   iferr_env = NULL;
     449          63 :   dbg_level = 0;
     450          63 :   frame_level = closure_context(oldframe_level, dbg_level);
     451          63 :   pari_infile = newfile(stdin, "stdin", mf_IN)->file;
     452          63 :   term_color(c_ERR); pari_putc('\n');
     453          63 :   if (sigint)
     454           7 :     msg = "Break loop: <Return> to continue; 'break' to go back to GP prompt";
     455             :   else
     456          56 :     msg = "Break loop: type 'break' to go back to GP prompt";
     457          63 :   print_errcontext(pariOut, msg, NULL, NULL);
     458          63 :   term_color(c_NONE);
     459          63 :   av = avma;
     460             :   for(;;)
     461          84 :   {
     462             :     GEN x;
     463             :     long er, br_status;
     464         147 :     set_avma(av);
     465         147 :     gp_context_save(&rec2);
     466         147 :     if ((er=setjmp(env[nenv])))
     467             :     {
     468          28 :       if (er < 0)
     469             :       {
     470           7 :         s_env.n = 1;
     471           7 :         frame_level = oldframe_level;
     472           7 :         longjmp(env[s_env.n-1], er);
     473             :       }
     474          21 :       gp_context_restore(&rec2);
     475          21 :       iferr_env = NULL;
     476          21 :       closure_err(dbg_level);
     477          21 :       compilestate_restore(&rec1.eval.comp);
     478          21 :       (void) closure_context(oldframe_level, dbg_level);
     479          21 :       pari_infile = newfile(stdin, "stdin", mf_IN)->file;
     480             :     }
     481         168 :     term_color(c_NONE);
     482         168 :     if (!gp_read_line(&F, prompt))
     483           0 :       br_status = br_BREAK; /* EOF */
     484             :     else
     485             :     {
     486             :       /* Empty input ? Continue if entry on sigint (exit debugger frame) */
     487         168 :       if (! *(b->buf) && sigint) break;
     488         161 :       reset_ctrlc();
     489         161 :       if (gp_meta(b->buf,0)) continue;
     490         161 :       x = pari_compile_str(b->buf);
     491         161 :       x = closure_evalbrk(x, &br_status);
     492             :     }
     493         133 :     switch (br_status)
     494             :     {
     495             :       case br_NEXT: case br_MULTINEXT:
     496           0 :         popinfile(); /* exit frame. Don't exit debugger if s_env.n > 2 */
     497          49 :         go_on = 0; goto BR_EXIT;
     498             :       case br_BREAK: case br_RETURN:
     499          49 :         killallfiles(); /* completely exit the debugger */
     500          49 :         go_on = 0; goto BR_EXIT;
     501             :     }
     502          84 :     if (x!=gnil && !is_silent(b->buf)) { term_color(c_OUTPUT); gen_output(x); }
     503             :   }
     504             : BR_EXIT:
     505          56 :   s_env.n=nenv;
     506          56 :   frame_level = oldframe_level;
     507          56 :   gp_context_restore(&rec1);
     508          56 :   pop_buffer(); return go_on;
     509             : }
     510             : 
     511             : #ifdef __CYGWIN32__
     512             : void
     513             : cyg_environment(int argc, char ** argv)
     514             : {
     515             :   char *ti_dirs = getenv("TERMINFO_DIRS");
     516             :   char *argv0, *p;
     517             :   char *newdir;
     518             :   long n;
     519             : 
     520             :   if (!argc || !argv) return;
     521             :   argv0 = *argv;
     522             :   if (!argv0 || !*argv0) return;
     523             :   p = strrchr(argv0, '/');
     524             :   if (!p)
     525             :     p = argv0 = "";
     526             :   else
     527             :     p++;
     528             :   n = p - argv0;
     529             :   if (ti_dirs)
     530             :   {
     531             :     n += 14 + strlen(ti_dirs) + 1 + 8 + 1;
     532             :     newdir = malloc(n);
     533             :     if (!newdir) return;
     534             :     snprintf(newdir, n-8, "TERMINFO_DIRS=%s:%s", ti_dirs, argv0);
     535             :   }
     536             :   else
     537             :   {
     538             :     n += 14 + 8 + 1;
     539             :     newdir = malloc(n);
     540             :     if (!newdir) return;
     541             :     snprintf(newdir, n-8, "TERMINFO_DIRS=%s", argv0);
     542             :   }
     543             :   strcpy(newdir+n-9,"terminfo");
     544             :   putenv(newdir);
     545             : }
     546             : #endif
     547             : 
     548             : int
     549        1566 : main(int argc, char **argv)
     550             : {
     551             :   char **A;
     552             :   pari_stack s_A;
     553             : 
     554        1566 :   GP_DATA = default_gp_data();
     555        1566 :   pari_stack_init(&s_env, sizeof(*env), (void**)&env);
     556        1566 :   (void)pari_stack_new(&s_env);
     557             : 
     558        1566 :   if (setjmp(env[s_env.n-1]))
     559             :   {
     560           2 :     puts("### Errors on startup, exiting...\n\n");
     561           2 :     exit(1);
     562             :   }
     563             : #ifdef __CYGWIN32__
     564             :   cyg_environment(argc, argv);
     565             : #endif
     566        1566 :   stdin_isatty = pari_stdin_isatty();
     567        1566 :   pari_init_defaults();
     568        1566 :   pari_library_path = DL_DFLT_NAME;
     569        1566 :   pari_stack_init(&s_A,sizeof(*A),(void**)&A);
     570        1566 :   pari_init_opts(1000000 * sizeof(long), 0, INIT_SIGm | INIT_noPRIMEm | INIT_noIMTm);
     571        1566 :   cb_pari_err_recover = gp_err_recover;
     572        1566 :   cb_pari_pre_recover = gp_pre_recover;
     573        1566 :   cb_pari_break_loop = break_loop;
     574        1566 :   cb_pari_is_interactive = is_interactive;
     575             : 
     576        1566 :   read_opt(&s_A, argc,argv);
     577        1556 :   pari_init_primes(GP_DATA->primelimit);
     578             : #ifdef SIGALRM
     579        1556 :   (void)os_signal(SIGALRM,gp_alarm_handler);
     580             : #endif
     581        1556 :   pari_add_module(functions_gp);
     582             : 
     583        1556 :   pari_set_plot_engine(gp_get_plot);
     584        1556 :   cb_pari_quit = gp_quit;
     585        1556 :   cb_pari_whatnow = whatnow;
     586        1556 :   cb_pari_sigint = gp_sigint_fun;
     587        1556 :   cb_pari_handle_exception = gp_handle_exception;
     588        1556 :   cb_pari_ask_confirm = gp_ask_confirm;
     589        1556 :   pari_init_paths();
     590        1556 :   pari_mt_init(); /* MPI: will not return on slaves (pari_MPI_rank = 0) */
     591             : #ifdef _WIN32
     592             :   if (stdin_isatty) win32_set_codepage();
     593             : #endif
     594             : #ifdef READLINE
     595        1556 :   init_readline();
     596             : #endif
     597        1556 :   if (GP_DATA->flags & gpd_EMACS) init_emacs();
     598        1556 :   if (GP_DATA->flags & gpd_TEXMACS) init_texmacs();
     599             : 
     600        1556 :   timer_start(GP_DATA->T);
     601        1556 :   if (!(GP_DATA->flags & gpd_QUIET)) gp_head();
     602        1556 :   if (GP_DATA->flags & gpd_TEST) init_test();
     603        1556 :   if (s_A.n)
     604             :   {
     605           0 :     FILE *l = pari_logfile;
     606             :     long i;
     607           0 :     pari_logfile = NULL;
     608           0 :     for (i = 0; i < s_A.n; pari_free(A[i]),i++) read_main(A[i]);
     609             :     /* Reading one of the input files above can set pari_logfile.
     610             :      * Don't restore in that case. */
     611           0 :     if (!pari_logfile) pari_logfile = l;
     612             :   }
     613        1556 :   pari_stack_delete(&s_A);
     614        1556 :   (void)gp_main_loop(1);
     615           0 :   gp_quit(0);
     616             :   return 0; /* LCOV_EXCL_LINE */
     617             : }
     618             : 
     619             : void
     620           7 : pari_breakpoint(void)
     621             : {
     622           7 :   if (!pari_last_was_newline()) pari_putc('\n');
     623           7 :   closure_err(0);
     624           7 :   if (cb_pari_break_loop && cb_pari_break_loop(-1)) return;
     625           0 :   cb_pari_err_recover(e_MISC);
     626             : }
     627             : 
     628             : void
     629           0 : dbg_down(long k)
     630             : {
     631           0 :   if (k<0) k=0;
     632           0 :   dbg_level -= k;
     633           0 :   if (dbg_level<0) dbg_level=0;
     634           0 :   gp_err_recover(e_NONE);
     635           0 : }
     636             : 
     637             : GEN
     638           7 : dbg_err(void) { GEN E = pari_err_last(); return E? gcopy(E):gnil; }
     639             : 
     640             : void
     641          14 : dbg_up(long k)
     642             : {
     643          14 :   if (k<0) k=0;
     644          14 :   dbg_level += k;
     645          14 :   if (dbg_level>frame_level) dbg_level=frame_level;
     646          14 :   gp_err_recover(e_NONE);
     647           0 : }
     648             : 
     649             : void
     650        1556 : gp_quit(long code)
     651             : {
     652        1556 :   pari_kill_plot_engine();
     653        1556 :   pari_close();
     654        1556 :   kill_buffers_upto(NULL);
     655        1556 :   if (!(GP_DATA->flags & gpd_QUIET)) pari_puts("Goodbye!\n");
     656        1556 :   if (cb_pari_end_output) cb_pari_end_output();
     657        1556 :   exit(code);
     658             : }
     659             : 
     660             : void
     661          35 : whatnow0(char *s) { whatnow(pariOut, s,0); }
     662             : 
     663             : #include "gp_init.h"

Generated by: LCOV version 1.13