798abb8545e30b443da0983ee2541f9fa4aa746e
[calc.git] / parser.c
1 #include <malloc.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include "debug.h"
7
8 #include "parser.h"
9
10 /* global variables */
11
12 double answer = 0;
13
14 #define STORAGE_SIZE 10
15 double storage[STORAGE_SIZE] = {0};
16
17 /* compare codes */
18
19 int codecmp (char *ref, char *str)
20 {
21 int sig;
22
23 while (*ref != '\0') {
24 if (*ref == '\t') {
25 sig = (*str == '.') ? -1 : ((*str >= '0') && (*str <= '9'));
26 } else {
27 sig = *str - *ref;
28 }
29 if (sig != 0) {
30 return (sig > 0) ? 1 : -1;
31 }
32 str++;
33 ref++;
34 }
35
36 return 0;
37 }
38
39 /* allocate new element */
40
41 element_t *newelement (func_t function, int nbops, int prio)
42 {
43 element_t *new = (element_t *) calloc (1, sizeof (element_t));
44 if (new == NULL) {
45 VERBOSE (ERROR, fprintf (stderr, "can't allocate memory\n"));
46 return NULL;
47 }
48 new->ops = (element_t **) calloc (1, sizeof (element_t *));
49 if (new->ops == NULL) {
50 free (new);
51 VERBOSE (ERROR, fprintf (stderr, "can't allocate memory\n"));
52 return NULL;
53 }
54 new->func = function;
55 new->nbops = nbops;
56 new->prio = prio;
57
58 return new;
59 }
60
61 /* desallocate element */
62
63 void delelement (element_t *root)
64 {
65 if ((root != NULL) && (root != ERROR_OP)) {
66 int i;
67 for (i = 0; i < root->nbops; i++) {
68 if ((root->ops[i] != NULL) && (root->ops[i] != ERROR_OP)) {
69 delelement (root->ops[i]);
70 }
71 }
72 if (root->nbops) {
73 free (root->ops);
74 }
75 free (root);
76 }
77 }
78
79 /* duplicate element */
80
81 element_t *dupelement (element_t *root)
82 {
83 element_t *tmp = NULL;
84 int i;
85
86 if ((root == NULL) || (root == ERROR_OP)) {
87 return root;
88 }
89 tmp = newelement (root->func, root->nbops, root->prio);
90 if (tmp == NULL) {
91 return ERROR_OP;
92 }
93 tmp->value = root->value;
94 for (i = 0; i < root->nbops; i++) {
95 tmp->ops[i] = dupelement (root->ops[i]);
96 if (tmp->ops[i] == ERROR_OP) {
97 delelement (tmp);
98 return ERROR_OP;
99 }
100 }
101 return tmp;
102 }
103
104 /* functions */
105
106 #define NB_OPERATORS 14
107 keyword_t operators[NB_OPERATORS] = {
108 { "+\t", Add, 2, 1, 1},
109 { "-\t", Sub, 2, 1, 1},
110 { "*", Mul, 2, 1, 2},
111 { "/", Div, 2, 1, 2},
112 { "%", Mod, 2, 1, 3},
113 { "^", Pow, 2, 1, 4},
114 { "==", Equal, 2, 2, -1},
115 { "!=", Diff, 2, 2, -1},
116 { ">=", Ge, 2, 2, -1},
117 { "<=", Le, 2, 2, -1},
118 { ">", Gt, 2, 1, -1},
119 { "<", Lt, 2, 1, -1},
120 { "&", And, 2, 1, -2},
121 { "|", Or, 2, 1, -2}
122 };
123
124 #define NB_FUNCTIONS 17
125 keyword_t functions[NB_FUNCTIONS] = {
126 { "sqrt", Sqr, 1, 4, 5},
127 { "pow", Pow, 2, 3, 5},
128 { "cos", Cos, 1, 3, 5},
129 { "sin", Sin, 1, 3, 5},
130 { "atan", Atan, 1, 4, 5},
131 { "exp", Exp, 1, 3, 5},
132 { "log", Log, 1, 3, 5},
133 { "sto", Store, 2, 3, 5},
134 { "rcl", Recall, 1, 3, 5},
135 { "inc", Inc, 1, 3, 5},
136 { "dec", Dec, 1, 3, 5},
137 { "disp", Disp, 0, 4, 9},
138 { "quit", Quit, 0, 4, 9},
139 { "help", Help, 0, 4, 9},
140 { "!", Not, 1, 1, 6},
141 { "cond", Cond, 3, 4, 5},
142 { "whl", While, 2, 3, 5}
143 };
144
145 #define NB_CONSTANTS 3
146 keyword_t constants[NB_CONSTANTS] = {
147 { "ans", Ans, 0, 3, 5},
148 { "e", E, 0, 1, 5},
149 { "pi", Pi, 0, 2, 5}
150 };
151
152 /* subparser function */
153
154 element_t *subparser (element_t **proot, char **pstr, func_t func, int nbops, int prio)
155 {
156 element_t *new = newelement (func, nbops, prio);
157 if (new == NULL) {
158 return ERROR_OP;
159 }
160 new->ops[0] = *proot;
161 new->ops[1] = parser (*pstr, pstr, new->prio);
162 if ((new->ops[1] == NULL) || ((new->ops[1] != ERROR_OP) && (new->ops[1]->prio == 9))) {
163 delelement (new->ops[1]);
164 new->ops[1] = ERROR_OP;
165 }
166 if (new->ops[1] == ERROR_OP) {
167 delelement (new);
168 *proot = NULL;
169 return ERROR_OP;
170 }
171 *proot = newelement (Val, 1, 5);
172 if (*proot == NULL) {
173 delelement (new);
174 return ERROR_OP;
175 }
176 (*proot)->ops[0] = new;
177
178 return *proot;
179 }
180
181 /* parser function */
182
183 element_t *parser (char *str, char **next, int prio)
184 {
185 element_t *root = NULL;
186 int i;
187
188 VERBOSE (DEBUG, fprintf (stdout, "Starting parsing\n"));
189
190 /* main loop */
191 while (*str != '\0') {
192 int found = 0;
193 element_t *new = NULL;
194 VERBOSE (INFO, fprintf (stdout, "Processing: %s\n", str));
195
196 /* skip spaces and tabs */
197
198 if ((*str == ' ') || (*str == '\t')) {
199 str++;
200 continue;
201 }
202
203 /* check for open brace */
204
205 if (*str == '{') {
206 VERBOSE (DEBUG, fprintf (stdout, "start processing brace\n"));
207 element_t *prog = newelement (Prog, 0, 5);
208 if (prog == NULL) {
209 delelement (root);
210 return ERROR_OP;
211 }
212 if (root == NULL) {
213 root = prog;
214 } else {
215 for (i = 0; i < root->nbops; i++) {
216 if (root->ops[i] == NULL) {
217 root->ops[i] = prog;
218 found = 1;
219 }
220 }
221 if (!found) {
222 delelement (prog);
223 delelement (root);
224 return ERROR_OP;
225 }
226 }
227
228 do {
229 found = 0;
230 new = parser (str + 1, &str, 0);
231 if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
232 delelement (new);
233 new = ERROR_OP;
234 }
235 if ((new == NULL) || (new == ERROR_OP)) {
236 delelement (root);
237 return ERROR_OP;
238 }
239 element_t *prognew = newelement (Prog, prog->nbops + 1, 5);
240 for (i = 0; i < prog->nbops; i++) {
241 prognew->ops[i] = prog->ops[i];
242 }
243 prog->ops[prog->nbops] = new;
244 delelement (prog);
245 prog = prognew;
246 } while (*str == ',');
247
248 if (*str != '}') {
249 delelement (root);
250 return ERROR_OP;
251 }
252 str++;
253 VERBOSE (DEBUG, fprintf (stdout, "stop processing brace\n"));
254 continue;
255 }
256
257 /* check for open bracket */
258
259 if (*str == '(') {
260 VERBOSE (DEBUG, fprintf (stdout, "start processing bracket\n"));
261 if (root) {
262 do {
263 found = 0;
264 new = parser (str + 1, &str, 0);
265 if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
266 delelement (new);
267 new = ERROR_OP;
268 }
269 if ((new == NULL) || (new == ERROR_OP)) {
270 delelement (root);
271 return ERROR_OP;
272 }
273 for (i = 0; i < root->nbops; i++) {
274 if (root->ops[i] == NULL) {
275 root->ops[i] = new;
276 found = 1;
277 break;
278 }
279 }
280 if (!found) {
281 delelement (new);
282 delelement (root);
283 return ERROR_OP;
284 }
285 } while (*str == ',');
286 } else {
287 root = newelement (Val, 1, 5);
288 if (root == NULL) {
289 return ERROR_OP;
290 }
291 new = parser (str + 1, &str, 0);
292 if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
293 delelement (new);
294 new = ERROR_OP;
295 }
296 if ((new == NULL) || (new == ERROR_OP) || (*str == ',')) {
297 delelement (new);
298 delelement (root);
299 return ERROR_OP;
300 }
301 root->ops[0] = new;
302 }
303 if (*str != ')') {
304 delelement (root);
305 return ERROR_OP;
306 }
307 str++;
308 VERBOSE (DEBUG, fprintf (stdout, "stop processing bracket\n"));
309 continue;
310 }
311
312 /* check for closing bracket, closing brace or koma */
313
314 if ((*str == ')') || (*str == '}') || (*str == ',')) {
315 if (next != NULL) {
316 *next = str;
317 }
318 return root;
319 }
320
321 /* look for operators */
322
323 for (i = 0; i < NB_OPERATORS; i++) {
324 keyword_t *operator = operators + i;
325 if (codecmp (operator->keyword, str) == 0) {
326 VERBOSE (DEBUG, fprintf (stdout, "start processing operator\n"));
327 if (root) {
328 if ((prio) && (prio > operator->prio)) {
329 VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n"));
330 *next = str;
331 return root;
332 }
333 str += operator->offset;
334 VERBOSE (INFO, fprintf (stdout, "Oper: %d\n", operator->func));
335 if (subparser (&root, &str, operator->func, operator->nbops, operator->prio) == ERROR_OP) {
336 delelement (root);
337 return ERROR_OP;
338 }
339 } else if (*str == '-') {
340 new = newelement (Sig, 1, 9);
341 if (new == NULL) {
342 return ERROR_OP;
343 }
344 root = new;
345 } else {
346 return ERROR_OP;
347 }
348 found = 1;
349 VERBOSE (DEBUG, fprintf (stdout, "stop processing operator\n"));
350 break;
351 }
352 }
353 if (found) {
354 continue;
355 }
356
357 /* look for functions */
358
359 for (i = 0; i < NB_FUNCTIONS; i++) {
360 keyword_t *function = functions + i;
361 if (codecmp (function->keyword, str) == 0) {
362 VERBOSE (DEBUG, fprintf (stdout, "start processing function\n"));
363 if (root == NULL) {
364 VERBOSE (INFO, fprintf (stdout, "Func: %d\n", function->func));
365 new = newelement (function->func, function->nbops, function->prio);
366 if (new == NULL) {
367 return ERROR_OP;
368 }
369 root = new;
370 } else {
371 delelement (root);
372 return ERROR_OP;
373 }
374 str += function->offset;
375 found = 1;
376 VERBOSE (DEBUG, fprintf (stdout, "stop processing function\n"));
377 break;
378 }
379 }
380 if (found) {
381 continue;
382 }
383
384 /* look for constant */
385
386 for (i = 0; i < NB_CONSTANTS; i++) {
387 keyword_t *constant = constants + i;
388 if (codecmp (constant->keyword, str) == 0) {
389 VERBOSE (DEBUG, fprintf (stdout, "start processing constant\n"));
390 if (root == NULL) {
391 VERBOSE (INFO, fprintf (stdout, "Const: %d\n", constant->func));
392 new = newelement (constant->func, constant->nbops, constant->prio);
393 if (new == NULL) {
394 return ERROR_OP;
395 }
396 root = new;
397 } else {
398 delelement (root);
399 return ERROR_OP;
400 }
401 str += constant->offset;
402 found = 1;
403 VERBOSE (DEBUG, fprintf (stdout, "stop processing constant\n"));
404 break;
405 }
406 }
407 if (found) {
408 continue;
409 }
410
411 /* look for number */
412
413 if (((*str >= '0') && (*str <= '9')) ||
414 (*str == '.') || (*str == '+') || (*str == '-')) {
415 VERBOSE (DEBUG, fprintf (stdout, "start processing value\n"));
416 char *pt;
417 double value = strtod (str, &pt);
418 VERBOSE (INFO, fprintf (stdout, "Value: %f\n", value));
419 if (str != pt) {
420 if ((root == NULL) || (root->prio == 6)) {
421 new = newelement (Val, 1, 5);
422 if (new == NULL) {
423 return ERROR_OP;
424 }
425 new->value = value;
426 if (root == NULL) {
427 root = new;
428 } else {
429 for (i = 0; i < root->nbops; i++) {
430 if (root->ops[i] == NULL) {
431 root->ops[i] = new;
432 found = 1;
433 break;
434 }
435 }
436 if (!found) {
437 delelement (new);
438 delelement (root);
439 return ERROR_OP;
440 }
441 }
442 str = pt;
443 } else if ((*str == '+') || (*str == '-')) {
444 if ((prio) && (prio > 1)) {
445 VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n"));
446 *next = str;
447 return root;
448 }
449 if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) {
450 delelement (root);
451 return ERROR_OP;
452 }
453 } else {
454 delelement (root);
455 return ERROR_OP;
456 }
457 found = 1;
458 }
459 VERBOSE (DEBUG, fprintf (stdout, "stop processing value\n"));
460 }
461
462 /* error */
463
464 if (!found) {
465 delelement (root);
466 return ERROR_OP;
467 }
468
469 }
470
471 if (next != NULL) {
472 *next = str;
473 }
474
475 return root;
476 }
477
478 /* print element tree */
479
480 void print_element (element_t *root, int level)
481 {
482 char *func = NULL;
483 int i;
484
485 if ((root == NULL) || (root == ERROR_OP)) {
486 return;
487 }
488
489 for (i = 0; i < level; i++) {
490 fprintf (stdout, " ");
491 }
492
493 switch (root->func) {
494 case Val: func = "Value"; break;
495 case Sig: func = "Sign"; break;
496 case Add: func = "Addition"; break;
497 case Sub: func = "Subtraction"; break;
498 case Mul: func = "Multiplication"; break;
499 case Div: func = "Division"; break;
500 case Mod: func = "Modulo"; break;
501 case Pow: func = "Power"; break;
502 case Sqr: func = "Square Root"; break;
503 case Cos: func = "Cosine"; break;
504 case Sin: func = "Sine"; break;
505 case Atan: func = "Arc Tangent"; break;
506 case Log: func = "Logarithm"; break;
507 case Exp: func = "Exponantial"; break;
508 case Store: func = "Store"; break;
509 case Recall: func = "Recall"; break;
510 case Inc: func = "Increase"; break;
511 case Dec: func = "Decrease"; break;
512 case Disp: func = "Display"; break;
513 case Quit: func = "Quit"; break;
514 case Help: func = "Help"; break;
515 case Ans: func = "Ans"; break;
516 case Pi: func = "Pi"; break;
517 case E: func = "E"; break;
518 case Equal: func = "Equal"; break;
519 case Diff: func = "Different"; break;
520 case Ge: func = "Greater or equal"; break;
521 case Le: func = "Lesser or equal"; break;
522 case Gt: func = "Greater"; break;
523 case Lt: func = "Lesser"; break;
524 case And: func = "And"; break;
525 case Or: func = "Or"; break;
526 case Not: func = "Not"; break;
527 case Cond: func = "Condition"; break;
528 case While: func = "While"; break;
529 case Prog: func = "Program"; break;
530 }
531
532 fprintf (stdout, "Function: %s\n", func);
533
534 if ((root->func == Val) && (root->ops[0] == NULL)) {
535 for (i = 0; i < level; i++) {
536 fprintf (stdout, " ");
537 }
538 fprintf (stdout, "value: %f\n", root->value);
539 } else {
540 for (i = 0; i < root->nbops; i++) {
541 print_element (root->ops[i], level + 1);
542 }
543 }
544 }
545
546 /* storage functions */
547
548 double store (int index, double value)
549 {
550 if ((index > 0) && (index <= STORAGE_SIZE)) {
551 storage[index - 1] = value;
552 } else {
553 VERBOSE (WARNING, fprintf (stdout, "invalid index (%d) [1, %d]\n", index, STORAGE_SIZE));
554 }
555 return value;
556 }
557
558 double recall (int index)
559 {
560 if ((index > 0) && (index <= STORAGE_SIZE)) {
561 return storage[index - 1];
562 } else {
563 VERBOSE (WARNING, fprintf (stdout, "invalid index (%d) [1, %d]\n", index, STORAGE_SIZE));
564 }
565 return 0;
566 }
567
568 double increase (int index)
569 {
570 if ((index > 0) && (index <= STORAGE_SIZE)) {
571 return storage[index - 1]++;
572 } else {
573 VERBOSE (WARNING, fprintf (stdout, "invalid index (%d) [1, %d]\n", index, STORAGE_SIZE));
574 }
575 return 0;
576 }
577
578 double decrease (int index)
579 {
580 if ((index > 0) && (index <= STORAGE_SIZE)) {
581 return storage[index - 1]--;
582 } else {
583 VERBOSE (WARNING, fprintf (stdout, "invalid index (%d) [1, %d]\n", index, STORAGE_SIZE));
584 }
585 return 0;
586 }
587
588 void display (void)
589 {
590 int i;
591 fprintf (stdout, "storage:");
592 for (i = 0; i < STORAGE_SIZE; i++) {
593 fprintf (stdout, " %g", storage[i]);
594 }
595 fprintf (stdout, "\n");
596 }
597
598 /* While do function */
599
600 double while_do (element_t *cond, element_t *action)
601 {
602 double ret = 0;
603 element_t *temp = NULL;
604
605 VERBOSE (DEBUG, fprintf (stdout, "starting while loop\n"));
606 if (cond == NULL) {
607 return ret;
608 }
609 while (1) {
610 VERBOSE (DEBUG, fprintf (stdout, "loop...\n"));
611
612 temp = dupelement (cond);
613 if (!evaluate_element (temp, 0)) {
614 break;
615 }
616 if (action) {
617 temp = dupelement (action);
618 ret = evaluate_element (temp, 0);
619 }
620 }
621
622 VERBOSE (DEBUG, fprintf (stdout, "ending while loop\n"));
623
624 return ret;
625 }
626
627 /* program function */
628
629 double program_do (element_t **prog, int nbcalls)
630 {
631 double ret = 0;
632 int i;
633 for (i = 0; i < nbcalls; i++) {
634 ret = evaluate_element (prog[i], 0);
635 prog[i] = NULL;
636 }
637 return ret;
638 }
639
640 /* quit function */
641
642 void quit (void)
643 {
644 fprintf (stdout, "bye\n");
645 exit (0);
646 }
647
648 /* help message */
649
650 void help (void)
651 {
652 fprintf (stdout, "calc is a simple calculator\n\n");
653 fprintf (stdout, "supported operators:");
654 fprintf (stdout, " + - * / %% ^\n");
655 fprintf (stdout, "camparison operators:");
656 fprintf (stdout, " == != >= <= > <\n");
657 fprintf (stdout, "logical operators:");
658 fprintf (stdout, " & | !\n");
659 fprintf (stdout, "supported functions:");
660 fprintf (stdout, " pow sqrt cos sin atan log exp\n");
661 fprintf (stdout, "storage functions:");
662 fprintf (stdout, " sto rcl inc dec\n");
663 fprintf (stdout, "conditional functions:");
664 fprintf (stdout, " cond\n");
665 fprintf (stdout, "miscellaneous functions:");
666 fprintf (stdout, " quit help\n");
667 fprintf (stdout, "supported constants:");
668 fprintf (stdout, " e pi\n");
669 }
670
671 /* evaluate element tree */
672
673 #define MASK_SUB 0x1
674 #define MASK_DIV 0x2
675
676 double evaluate_element (element_t *root, char mask)
677 {
678 double op0 = 0, op1 = 0;
679 char nextmask = mask;
680
681 if ((root == NULL) || (root == ERROR_OP)) {
682 VERBOSE (WARNING, fprintf (stdout, "error while evaluating\n"));
683 return 0;
684 }
685
686 /* mask to manage sub operator sub and div */
687 switch (root->func) {
688 case Add:
689 nextmask &= ~MASK_SUB;
690 nextmask &= ~MASK_DIV;
691 break;
692 case Sub:
693 nextmask |= MASK_SUB;
694 nextmask &= ~MASK_DIV;
695 break;
696 case Mul:
697 nextmask &= ~MASK_DIV;
698 break;
699 case Div:
700 nextmask |= MASK_DIV;
701 break;
702 default:
703 nextmask = mask;
704 }
705
706 switch (root->func) {
707 case Val:
708 case Sig:
709 op0 = (root->ops[0]) ? evaluate_element (root->ops[0], nextmask) : root->value;
710 break;
711 case Add:
712 case Sub:
713 case Mul:
714 case Div:
715 case Mod:
716 case Pow:
717 case Store:
718 case Equal:
719 case Diff:
720 case Ge:
721 case Le:
722 case Gt:
723 case Lt:
724 case And:
725 case Or:
726 if (root->ops[1]) {
727 op1 = evaluate_element (root->ops[1], nextmask);
728 } else if (root->func != Store) {
729 VERBOSE (WARNING, fprintf (stdout, "error while evaluating (op[1])\n"));
730 return 0;
731 }
732 /* fallthrough */
733 case Sqr:
734 case Cos:
735 case Sin:
736 case Atan:
737 case Log:
738 case Exp:
739 case Recall:
740 case Inc:
741 case Dec:
742 case Not:
743 case Cond:
744 if (root->ops[0]) {
745 op0 = evaluate_element (root->ops[0], 0);
746 } else {
747 VERBOSE (WARNING, fprintf (stdout, "error while evaluating (op[0])\n"));
748 return 0;
749 }
750 break;
751 case Disp:
752 case Quit:
753 case Help:
754 case Ans:
755 case Pi:
756 case E:
757 case Prog:
758 break;
759 case While:
760 if (root->ops[0] == NULL) {
761 VERBOSE (WARNING, fprintf (stdout, "error while evaluating (op[0])\n"));
762 return 0;
763 }
764 break;
765 }
766
767 switch (root->func) {
768 case Val: return op0;
769 case Sig: return -op0;
770 case Add: return ((mask & MASK_SUB) == 0) ? op0 + op1 : op0 - op1;
771 case Sub: return ((mask & MASK_SUB) == 0) ? op0 - op1 : op0 + op1;
772 case Mul: return ((mask & MASK_DIV) == 0) ? op0 * op1 : op0 / op1;
773 case Div: return ((mask & MASK_DIV) == 0) ? op0 / op1 : op0 * op1;
774 case Mod: return fmod (op0, op1);
775 case Pow: return pow (op0, op1);
776 case Sqr: return sqrt (op0);
777 case Cos: return cos (op0);
778 case Sin: return sin (op0);
779 case Atan: return atan (op0);
780 case Log: return log (op0);
781 case Exp: return exp (op0);
782 case Store: return store ((int)op0, (op1) ? op1 : answer);
783 case Recall: return recall ((int)op0);
784 case Inc: return increase ((int)op0);
785 case Dec: return decrease ((int)op0);
786 case Disp: display (); break;
787 case Quit: quit (); break;
788 case Help: help (); break;
789 case Ans: return answer;
790 case Pi: return M_PI;
791 case E: return M_E;
792 case Equal: return op0 == op1;
793 case Diff: return op0 != op1;
794 case Ge: return op0 >= op1;
795 case Le: return op0 <= op1;
796 case Gt: return op0 > op1;
797 case Lt: return op0 < op1;
798 case And: return (op0 != 0) && (op1 != 0);
799 case Or: return (op0 != 0) || (op1 != 0);
800 case Not: return (op0 == 0);
801 case Cond:
802 if ((op0) && (root->ops[1])) {
803 return evaluate_element (root->ops[1], 0);
804 } else if ((!op0) && (root->ops[2])) {
805 return evaluate_element (root->ops[2], 0);
806 } else {
807 return 0;
808 }
809 case While: return while_do (root->ops[0], root->ops[1]);
810 case Prog: return program_do (root->ops, root->nbops);
811 }
812
813 return 0;
814 }
815
816 /* vim: set ts=4 sw=4 et: */