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