Statistiques
| Révision :

root / sollyaIntegration-4.0 / src / createObj-01.c @ 303

Historique | Voir | Annoter | Télécharger (3,37 ko)

1
/** @file createObj-01.c
2
 * CreateObj-01: create a function for an expression given on the command line.
3
 *
4
 * @author S.T.
5
 * @date 2012-11-21
6
 *
7
 */
8
/******************************************************************************/
9
/* Headers, applying the "particular to general" convention.*/
10

    
11
#include "pobyso.h"
12

    
13
/* includes of local headers */
14

    
15
/* includes of project headers */
16

    
17
/* includes of system headers */
18
#include <gmp.h>
19
#include <sollya.h>
20
#include <setjmp.h>
21
#include <string.h>
22
/* Other declarations */
23

    
24
/* Internal prototypes */
25

    
26
/* Types, constants and macros definitions */
27
#define NUM_ARGS 3
28
#define VARIABLE_NAME_STRING "x"
29
#define RADIX 10
30
/* Global variables */
31

    
32
/* Functions */
33
int
34
main(int argc, char** argv)
35
{
36
  //jmp_buf recover;
37
  pobyso_function_t functionObj     = NULL;
38
  sollya_verbosity_t curVerbLevel   = NULL;
39
  char *freeVariableName            = NULL;
40
  char *functionString              = NULL;
41
  char *initialFreeVariableName     = NULL;
42

    
43

    
44
  /* check the command line arguments */
45
  if (argc < NUM_ARGS)
46
  {
47
    fprintf(stderr,
48
            "\n\nusage: %s expressionString freeVariableName\n\n",
49
            argv[0]);
50
    fprintf(stderr,
51
            "\texpressionString: the expression to create a node from.\n");
52
    fprintf(stderr,
53
            "\t\tmust be in quotes (e. g. \"cos(x)\");\n");
54
    fprintf(stderr,
55
            "\tfreeVariableName: the name of the free variable;\n");
56
    fprintf(stderr,
57
            "\t\t(e. g. x (no quotes needed));\n");
58
    fprintf(stderr,"\n\n");
59
    return(1);
60
  }
61

    
62

    
63
  functionString    = argv[1];
64
  freeVariableName  = argv[2];
65

    
66
  /* Debug printing. */
67
  fprintf(stdout,
68
          "%s: function: %s\n", argv[0], functionString);
69
  fprintf(stdout,
70
          "%s: variable name: %s\n", argv[0], freeVariableName);
71
  fprintf(stdout, "\n");
72
  /* Initialize Sollya. */
73
  sollya_lib_init();
74

    
75
  initialFreeVariableName = sollya_lib_get_free_variable_name();
76
  if (initialFreeVariableName == NULL)
77
  {
78
    fprintf(stderr, "%s: could not get the name of the free variable. Aborting!\n",
79
                    argv[0]);
80
    sollya_lib_close();
81
    return(1);
82

    
83
  }
84

    
85
  fprintf(stderr, "%s: name of variable (before any assignment): %s\n",
86
                  argv[0],
87
                  initialFreeVariableName);
88

    
89
  /* Set the free variable name. */
90
  sollya_lib_name_free_variable(freeVariableName);
91
  if (strcmp(sollya_lib_get_free_variable_name(), freeVariableName))
92
  {
93
    fprintf(stderr, "Could not set \"%s\" as the variable name. Aborting!\n",
94
                      freeVariableName);
95
    sollya_lib_close();
96
    return(1);
97
  }
98
  /* Keep Sollya quiet. */
99
  curVerbLevel = pobyso_set_verbosity_off();
100
  /* Parse the function string. */
101
  functionObj = pobyso_parse_string(functionString);
102
  if (pobyso_is_error(functionObj))
103
  {
104
    fprintf(stderr, "%s: could not parse \"%s\". Aborting!\n", argv[0], functionString);
105
    sollya_lib_close();
106
    return(1);
107
  }
108
  //sollya_lib_fprintf(stdout, "%s: function: %b\n", argv[0], functionObj );
109
  //pobyso_autoprint(functionObj, NULL);
110

    
111
  pobyso_autoprint(functionObj, NULL);
112
  if (pobyso_is_function(functionObj))
113
  {
114
    fprintf(stdout, " is a function.\n");
115
  }
116
  else
117
  {
118
    fprintf(stdout, " is *not* a function!\n");
119
  }
120
  pobyso_autoprint(curVerbLevel, NULL);
121
  pobyso_set_verbosity_to(curVerbLevel);
122
  sollya_lib_clear_obj(curVerbLevel);
123

    
124
  sollya_lib_clear_obj(functionObj);
125

    
126
  sollya_lib_close();
127
  return(0);
128
} /* End main */