cleanup: Big pile of whitespace fixes, all at once.
[u/mdw/catacomb] / field-parse.c
1 /* -*-c-*-
2 *
3 * $Id: field-parse.c,v 1.4 2004/04/08 01:36:15 mdw Exp $
4 *
5 * Parse field descriptions
6 *
7 * (c) 2004 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Header files ------------------------------------------------------*/
31
32 #include "field.h"
33
34 /*----- Main code ---------------------------------------------------------*/
35
36 /* --- @field_parse@ --- *
37 *
38 * Arguments: @qd_parse *qd@ = parser context
39 *
40 * Returns: Field pointer if OK, or null.
41 *
42 * Use: Parses a field description, which has the form
43 *
44 * * `prime', `niceprime' or `binpoly'
45 * * an optional `:'
46 * * the field modulus
47 */
48
49 field *field_parse(qd_parse *qd)
50 {
51 field *f = 0;
52 mp *m = MP_NEW, *b = MP_NEW;
53
54 switch (qd_enum(qd, "prime,niceprime,binpoly,binnorm")) {
55 case 0:
56 qd_delim(qd, ':');
57 if ((m = qd_getmp(qd)) == 0) goto done;
58 f = field_prime(m);
59 break;
60 case 1:
61 qd_delim(qd, ':');
62 if ((m = qd_getmp(qd)) == 0) goto done;
63 f = field_niceprime(m);
64 break;
65 case 2:
66 qd_delim(qd, ':');
67 if ((m = qd_getmp(qd)) == 0) goto done;
68 f = field_binpoly(m);
69 break;
70 case 3:
71 qd_delim(qd, ':');
72 if ((m = qd_getmp(qd)) == 0) goto done;
73 qd_delim(qd, ',');
74 if ((b = qd_getmp(qd)) == 0) goto done;
75 f = field_binnorm(m, b);
76 break;
77 default:
78 goto done;
79 }
80 if (!f) qd->e = "bad field parameters";
81 done:
82 mp_drop(m);
83 mp_drop(b);
84 return (f);
85 }
86
87 /*----- That's all, folks -------------------------------------------------*/