3 * $Id: mptext.h,v 1.2 1999/12/10 23:29:48 mdw Exp $
5 * Textual representation of multiprecision numbers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 1999/12/10 23:29:48 mdw
34 * Change header file guard names.
36 * Revision 1.1 1999/11/17 18:02:16 mdw
37 * New multiprecision integer arithmetic suite.
41 #ifndef CATACOMB_MPTEXT_H
42 #define CATACOMB_MPTEXT_H
48 /*----- Header files ------------------------------------------------------*/
54 /*----- Data structures ---------------------------------------------------*/
56 typedef struct mptext_ops
{
57 int (*get
)(void */
*p*/
);
58 void (*unget
)(int /*ch*/, void */
*p*/
);
59 int (*put
)(char */
*s*/
, size_t /*len*/, void */
*p*/
);
62 /*----- Functions provided ------------------------------------------------*/
64 /* --- @mp_read@ --- *
66 * Arguments: @mp *m@ = destination multiprecision number
67 * @int radix@ = base to assume for data (or zero to guess)
68 * @const mptext_ops *ops@ = pointer to operations block
69 * @void *p@ = data for the operations block
71 * Returns: The integer read, or zero if it didn't work.
73 * Use: Reads an integer from some source. If the @radix@ is
74 * specified, the number is assumed to be given in that radix,
75 * with the letters `a' (either upper- or lower-case) upwards
76 * standing for digits greater than 9. Otherwise, base 10 is
77 * assumed unless the number starts with `0' (octal), `0x' (hex)
78 * or `nnn_' (base `nnn'). An arbitrary amount of whitespace
79 * before the number is ignored.
82 extern mp
*mp_read(mp */
*m*/
, int /*radix*/,
83 const mptext_ops */
*ops*/
, void */
*p*/
);
85 /* --- @mp_write@ --- *
87 * Arguments: @mp *m@ = pointer to a multi-precision integer
88 * @int radix@ = radix to use when writing the number out
89 * @const mptext_ops *ops@ = pointer to an operations block
90 * @void *p@ = data for the operations block
92 * Returns: Zero if it worked, nonzero otherwise.
94 * Use: Writes a large integer in textual form.
97 extern int mp_write(mp */
*m*/
, int /*radix*/,
98 const mptext_ops */
*ops*/
, void */
*p*/
);
100 /*----- File I/O ----------------------------------------------------------*/
104 /* --- Operations table --- *
106 * The @mptext_fileops@ expect the pointer argument to be a @FILE *@.
109 extern const mptext_ops mptext_fileops
;
111 /* --- Convenience functions --- */
113 extern mp
*mp_readfile(mp */
*m*/
, FILE */
*fp*/
, int /*radix*/);
114 extern int mp_writefile(mp */
*m*/
, FILE */
*fp*/
, int /*radix*/);
116 /*----- String I/O --------------------------------------------------------*/
118 /* --- Context format --- */
120 typedef struct mptext_stringctx
{
125 /* --- Operations table --- */
127 extern const mptext_ops mptext_stringops
;
129 /* --- Convenience functions --- */
131 extern mp
*mp_readstring(mp */
*m*/
, const char */
*p*/
, char **/
*end*/
,
133 extern int mp_writestring(mp */
*m*/
, char */
*p*/
, size_t /*sz*/,
136 /*----- Dynamic string I/O ------------------------------------------------*/
138 #include <mLib/dstr.h>
140 /* --- Context format --- */
142 typedef struct mptext_dstrctx
{
147 /* --- Operations table --- */
149 extern const mptext_ops mptext_dstrops
;
151 /* --- Convenience functions --- */
153 extern mp
*mp_readdstr(mp */
*m*/
, dstr */
*d*/
, size_t */
*off*/
,
155 extern int mp_writedstr(mp */
*m*/
, dstr */
*d*/
, int /*radix*/);
157 /*----- That's all, folks -------------------------------------------------*/