432c4e18 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: field-parse.c,v 1.1 2004/03/27 17:54:11 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 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: field-parse.c,v $ |
33 | * Revision 1.1 2004/03/27 17:54:11 mdw |
34 | * Standard curves and curve checking. |
35 | * |
36 | */ |
37 | |
38 | /*----- Header files ------------------------------------------------------*/ |
39 | |
40 | #include "field.h" |
41 | |
42 | /*----- Main code ---------------------------------------------------------*/ |
43 | |
44 | /* --- @field_parse@ --- * |
45 | * |
46 | * Arguments: @qd_parse *qd@ = parser context |
47 | * |
48 | * Returns: Field pointer if OK, or null. |
49 | * |
50 | * Use: Parses a field description, which has the form |
51 | * |
52 | * * `prime', `niceprime' or `binpoly' |
53 | * * an optional `:' |
54 | * * the field modulus |
55 | */ |
56 | |
57 | field *field_parse(qd_parse *qd) |
58 | { |
59 | field *f; |
60 | mp *m = MP_NEW; |
61 | |
62 | switch (qd_enum(qd, "prime,niceprime,binpoly")) { |
63 | case 0: |
64 | qd_delim(qd, ':'); |
65 | if ((m = qd_getmp(qd)) == 0) return (0); |
66 | f = field_prime(m); |
67 | break; |
68 | case 1: |
69 | qd_delim(qd, ':'); |
70 | if ((m = qd_getmp(qd)) == 0) return (0); |
71 | f = field_niceprime(m); |
72 | break; |
73 | case 2: |
74 | qd_delim(qd, ':'); |
75 | if ((m = qd_getmp(qd)) == 0) return (0); |
76 | f = field_binpoly(m); |
77 | break; |
78 | default: |
79 | f = 0; |
80 | break; |
81 | } |
82 | mp_drop(m); |
83 | return (f); |
84 | } |
85 | |
86 | /*----- That's all, folks -------------------------------------------------*/ |