root / sollyaIntegration-4.0 / src / createObj-01.c
Historique | Voir | Annoter | Télécharger (3,37 ko)
1 | 34 | storres | /** @file createObj-01.c
|
---|---|---|---|
2 | 34 | storres | * CreateObj-01: create a function for an expression given on the command line.
|
3 | 34 | storres | *
|
4 | 34 | storres | * @author S.T.
|
5 | 34 | storres | * @date 2012-11-21
|
6 | 34 | storres | *
|
7 | 34 | storres | */
|
8 | 34 | storres | /******************************************************************************/
|
9 | 34 | storres | /* Headers, applying the "particular to general" convention.*/
|
10 | 34 | storres | |
11 | 36 | storres | #include "pobyso.h" |
12 | 34 | storres | |
13 | 34 | storres | /* includes of local headers */
|
14 | 34 | storres | |
15 | 34 | storres | /* includes of project headers */
|
16 | 34 | storres | |
17 | 34 | storres | /* includes of system headers */
|
18 | 34 | storres | #include <gmp.h> |
19 | 34 | storres | #include <sollya.h> |
20 | 34 | storres | #include <setjmp.h> |
21 | 34 | storres | #include <string.h> |
22 | 34 | storres | /* Other declarations */
|
23 | 34 | storres | |
24 | 34 | storres | /* Internal prototypes */
|
25 | 34 | storres | |
26 | 34 | storres | /* Types, constants and macros definitions */
|
27 | 34 | storres | #define NUM_ARGS 3 |
28 | 34 | storres | #define VARIABLE_NAME_STRING "x" |
29 | 34 | storres | #define RADIX 10 |
30 | 34 | storres | /* Global variables */
|
31 | 34 | storres | |
32 | 34 | storres | /* Functions */
|
33 | 34 | storres | int
|
34 | 34 | storres | main(int argc, char** argv) |
35 | 34 | storres | { |
36 | 34 | storres | //jmp_buf recover;
|
37 | 129 | storres | pobyso_function_t functionObj = NULL;
|
38 | 129 | storres | sollya_verbosity_t curVerbLevel = NULL;
|
39 | 129 | storres | char *freeVariableName = NULL; |
40 | 129 | storres | char *functionString = NULL; |
41 | 129 | storres | char *initialFreeVariableName = NULL; |
42 | 34 | storres | |
43 | 34 | storres | |
44 | 34 | storres | /* check the command line arguments */
|
45 | 34 | storres | if (argc < NUM_ARGS)
|
46 | 34 | storres | { |
47 | 34 | storres | fprintf(stderr, |
48 | 34 | storres | "\n\nusage: %s expressionString freeVariableName\n\n",
|
49 | 34 | storres | argv[0]);
|
50 | 34 | storres | fprintf(stderr, |
51 | 34 | storres | "\texpressionString: the expression to create a node from.\n");
|
52 | 34 | storres | fprintf(stderr, |
53 | 34 | storres | "\t\tmust be in quotes (e. g. \"cos(x)\");\n");
|
54 | 34 | storres | fprintf(stderr, |
55 | 34 | storres | "\tfreeVariableName: the name of the free variable;\n");
|
56 | 34 | storres | fprintf(stderr, |
57 | 34 | storres | "\t\t(e. g. x (no quotes needed));\n");
|
58 | 34 | storres | fprintf(stderr,"\n\n");
|
59 | 34 | storres | return(1); |
60 | 34 | storres | } |
61 | 34 | storres | |
62 | 34 | storres | |
63 | 34 | storres | functionString = argv[1];
|
64 | 34 | storres | freeVariableName = argv[2];
|
65 | 34 | storres | |
66 | 34 | storres | /* Debug printing. */
|
67 | 34 | storres | fprintf(stdout, |
68 | 34 | storres | "%s: function: %s\n", argv[0], functionString); |
69 | 34 | storres | fprintf(stdout, |
70 | 34 | storres | "%s: variable name: %s\n", argv[0], freeVariableName); |
71 | 34 | storres | fprintf(stdout, "\n");
|
72 | 34 | storres | /* Initialize Sollya. */
|
73 | 34 | storres | sollya_lib_init(); |
74 | 34 | storres | |
75 | 34 | storres | initialFreeVariableName = sollya_lib_get_free_variable_name(); |
76 | 34 | storres | if (initialFreeVariableName == NULL) |
77 | 34 | storres | { |
78 | 34 | storres | fprintf(stderr, "%s: could not get the name of the free variable. Aborting!\n",
|
79 | 34 | storres | argv[0]);
|
80 | 34 | storres | sollya_lib_close(); |
81 | 34 | storres | return(1); |
82 | 34 | storres | |
83 | 34 | storres | } |
84 | 34 | storres | |
85 | 34 | storres | fprintf(stderr, "%s: name of variable (before any assignment): %s\n",
|
86 | 34 | storres | argv[0],
|
87 | 34 | storres | initialFreeVariableName); |
88 | 34 | storres | |
89 | 34 | storres | /* Set the free variable name. */
|
90 | 34 | storres | sollya_lib_name_free_variable(freeVariableName); |
91 | 34 | storres | if (strcmp(sollya_lib_get_free_variable_name(), freeVariableName))
|
92 | 34 | storres | { |
93 | 34 | storres | fprintf(stderr, "Could not set \"%s\" as the variable name. Aborting!\n",
|
94 | 34 | storres | freeVariableName); |
95 | 34 | storres | sollya_lib_close(); |
96 | 34 | storres | return(1); |
97 | 34 | storres | } |
98 | 129 | storres | /* Keep Sollya quiet. */
|
99 | 129 | storres | curVerbLevel = pobyso_set_verbosity_off(); |
100 | 34 | storres | /* Parse the function string. */
|
101 | 34 | storres | functionObj = pobyso_parse_string(functionString); |
102 | 129 | storres | if (pobyso_is_error(functionObj))
|
103 | 34 | storres | { |
104 | 34 | storres | fprintf(stderr, "%s: could not parse \"%s\". Aborting!\n", argv[0], functionString); |
105 | 34 | storres | sollya_lib_close(); |
106 | 34 | storres | return(1); |
107 | 34 | storres | } |
108 | 129 | storres | //sollya_lib_fprintf(stdout, "%s: function: %b\n", argv[0], functionObj );
|
109 | 129 | storres | //pobyso_autoprint(functionObj, NULL);
|
110 | 34 | storres | |
111 | 129 | storres | pobyso_autoprint(functionObj, NULL);
|
112 | 129 | storres | if (pobyso_is_function(functionObj))
|
113 | 34 | storres | { |
114 | 34 | storres | fprintf(stdout, " is a function.\n");
|
115 | 34 | storres | } |
116 | 129 | storres | else
|
117 | 129 | storres | { |
118 | 129 | storres | fprintf(stdout, " is *not* a function!\n");
|
119 | 129 | storres | } |
120 | 34 | storres | pobyso_autoprint(curVerbLevel, NULL);
|
121 | 34 | storres | pobyso_set_verbosity_to(curVerbLevel); |
122 | 34 | storres | sollya_lib_clear_obj(curVerbLevel); |
123 | 34 | storres | |
124 | 129 | storres | sollya_lib_clear_obj(functionObj); |
125 | 34 | storres | |
126 | 34 | storres | sollya_lib_close(); |
127 | 34 | storres | return(0); |
128 | 34 | storres | } /* End main */ |