40 static gerbv_instruction_t*
41 new_instruction(
void) {
42 gerbv_instruction_t* instruction;
44 instruction = (gerbv_instruction_t*)malloc(
sizeof(gerbv_instruction_t));
45 if (instruction == NULL) {
50 memset(instruction, 0,
sizeof(gerbv_instruction_t));
58 static gerbv_amacro_t*
60 gerbv_amacro_t* amacro;
62 amacro = (gerbv_amacro_t*)malloc(
sizeof(gerbv_amacro_t));
68 memset(amacro, 0,
sizeof(gerbv_amacro_t));
95 #define MATH_OP_STACK_SIZE 2
96 #define MATH_OP_PUSH(val) math_op[math_op_idx++] = val
97 #define MATH_OP_POP math_op[--math_op_idx]
98 #define MATH_OP_TOP (math_op_idx > 0) ? math_op[math_op_idx - 1] : GERBV_OPCODE_NOP
99 #define MATH_OP_EMPTY (math_op_idx == 0)
105 parse_aperture_macro(gerb_file_t* fd) {
106 gerbv_amacro_t* amacro;
107 gerbv_instruction_t* ip = NULL;
108 int primitive = 0, c, found_primitive = 0;
113 unsigned char continueLoop = 1;
116 amacro = new_amacro();
123 amacro->name = gerb_fgetstring(fd,
'*');
133 amacro->program = new_instruction();
134 ip = amacro->program;
136 while (continueLoop) {
141 if (found_primitive) {
142 ip->next = new_instruction();
146 ip->data.ival = gerb_fgetint(fd, NULL);
149 equate = gerb_fgetint(fd, NULL);
153 while (!MATH_OP_EMPTY) {
154 ip->next = new_instruction();
156 ip->opcode = MATH_OP_POP;
162 if (found_primitive) {
163 ip->next = new_instruction();
167 ip->data.ival = equate;
170 ip->data.ival = primitive;
183 if (!found_primitive) {
187 while (!MATH_OP_EMPTY) {
188 ip->next = new_instruction();
190 ip->opcode = MATH_OP_POP;
195 while ((!MATH_OP_EMPTY) && (math_op_prec(MATH_OP_TOP) >= math_op_prec(
GERBV_OPCODE_ADD))) {
196 ip->next = new_instruction();
198 ip->opcode = MATH_OP_POP;
209 while ((!MATH_OP_EMPTY) && (math_op_prec(MATH_OP_TOP) >= math_op_prec(
GERBV_OPCODE_SUB))) {
210 ip->next = new_instruction();
212 ip->opcode = MATH_OP_POP;
217 while ((!MATH_OP_EMPTY) && (math_op_prec(MATH_OP_TOP) >= math_op_prec(
GERBV_OPCODE_DIV))) {
218 ip->next = new_instruction();
220 ip->opcode = MATH_OP_POP;
227 while ((!MATH_OP_EMPTY) && (math_op_prec(MATH_OP_TOP) >= math_op_prec(
GERBV_OPCODE_MUL))) {
228 ip->next = new_instruction();
230 ip->opcode = MATH_OP_POP;
240 if (!found_primitive && (primitive == 0)) {
242 free(gerb_fgetstring(fd,
'*'));
260 if (!found_primitive) {
261 primitive = (primitive * 10) + (c -
'0');
264 (void)gerb_ungetc(fd);
265 ip->next = new_instruction();
269 ip->data.fval = gerb_fgetdouble(fd);
271 ip->data.fval = -ip->data.fval;
292 free_amacro(gerbv_amacro_t* amacro) {
293 gerbv_amacro_t * am1, *am2;
294 gerbv_instruction_t *instr1, *instr2;
297 while (am1 != NULL) {
301 instr1 = am1->program;
302 while (instr1 != NULL) {
304 instr1 = instr1->next;
319 print_program(gerbv_amacro_t* amacro) {
320 gerbv_instruction_t* ip;
322 printf(
"Macroname [%s] :\n", amacro->name);
323 for (ip = amacro->program; ip != NULL; ip = ip->next) {
324 switch (ip->opcode) {
334 default: printf(
" ERROR!\n");
break;
Aperture macro parsing header info.
Header info for the file parsing support functions.
The main header file for the libgerbv library.