File: lrs.c

package info (click to toggle)
lrslib 0.73-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,888 kB
  • sloc: ansic: 20,893; sh: 279; makefile: 252; perl: 97; csh: 51
file content (119 lines) | stat: -rwxr-xr-x 2,963 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/time.h>
#include "lrsdriver.h"


int
main (int argc, char *argv[])

{
struct timeval start, end;

#ifndef MA
  gettimeofday(&start, NULL);

  lrs_main(argc,argv);    /* legacy lrs */

  gettimeofday(&end, NULL);
  fprintf(stdout,"\n*elapsed time: %ld seconds\n",
                end.tv_sec - start.tv_sec);
  return 0;
#else

/* hybrid arithmetic version of lrs   */

  lrs_restart_dat *R;
  lrs_dic *P;
  lrs_dat *Q;
  char* tmp;          /* when overflow occurs a new input file name is returned */

  char** newargv;    
  long overfl=0;     /*  =0 no overflow =1 restart overwrite =2 restart append */
#ifdef B128
  long overfl2=0;    /*  for B128 */
#endif
  int lrs_stdin=0;
  int i;

  gettimeofday(&start, NULL);

  P=NULL;
  Q=NULL;
  tmp=NULL;

  R = lrs_alloc_restart();
  if (R == NULL)
    exit(1);   


  if(argc == 1)
     lrs_stdin=1;

  tmp = malloc(PATH_MAX * sizeof (char));

  overfl=lrs1_main(argc,argv,&P,&Q,0,0,tmp,R);    /* set up, read input, no run   */    
  if(overfl==0)
     overfl=lrs1_main(argc,argv,&P,&Q,overfl,1,tmp,R);  /* run main part of code   */  
  lrs1_main(argc,argv,&P,&Q,0,2,tmp,R);              /* free memory and close      */
  if(overfl==0)
          goto byebye;
  if (overfl==-1) 
     {
       printf("\n*unrecoverable input error\n");
       exit(1);
     }

/* overflow condition triggered: a temporary file was created for restart */
/* create new argv for the remaining calls                                */

  newargv = makenewargv(&argc,argv,tmp);
  free(R->redineq);                    /* reallocated in stage 0 */

#ifdef B128
  fprintf(stderr,"\n*lrs:overflow possible: restarting with 128 bit arithmetic\n");

  overfl2=lrs2_main(argc,argv,&P,&Q,overfl,0,tmp,R);    /* set up, read input, no run   */
  if(overfl2==0)
     overfl2=lrs2_main(argc,argv,&P,&Q,overfl,1,tmp,R);  /* run main part of code   */
  lrs2_main(argc,argv,&P,&Q,overfl,2,tmp,R);              /* free memory and close      */
  if(overfl2==0)
    goto done;
  overfl=overfl2;
  free(R->redineq);                    /* reallocated in stage 0 */
#endif

/* if you change tmp file name update newargv[1] */

  fprintf(stderr,"\n*lrs:overflow possible: restarting with GMP arithmetic\n");

  lrsgmp_main(argc,newargv,&P,&Q,overfl,0,tmp,R);                                      
  lrsgmp_main(argc,newargv,&P,&Q,overfl,1,tmp,R);  
  lrsgmp_main(argc,newargv,&P,&Q,overfl,2,tmp,R);    

#ifdef B128
done:
#endif

  for(i = 0; i < argc; ++i)
        free(newargv[i]);
  free(newargv);
  
byebye:
  free(R->redineq);
  free(R->facet);
  free(R);
  if(lrs_stdin==1)    /* get rid of temporary file for stdin */
    remove(tmp);
  free(tmp);
  gettimeofday(&end, NULL);
  fprintf(stdout,"*Elapsed time: %ld seconds\n",
                end.tv_sec - start.tv_sec);
  return 0;
#endif /* hybrid version of lrs */

} /* lrs.c */