1  /* do not edit automatically generated by mc from StringConvert.  */
       2  /* StringConvert.def provides functions to convert numbers to and from strings.
       3  
       4  Copyright (C) 2001-2023 Free Software Foundation, Inc.
       5  Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6  
       7  This file is part of GNU Modula-2.
       8  
       9  GNU Modula-2 is free software; you can redistribute it and/or modify
      10  it under the terms of the GNU General Public License as published by
      11  the Free Software Foundation; either version 3, or (at your option)
      12  any later version.
      13  
      14  GNU Modula-2 is distributed in the hope that it will be useful, but
      15  WITHOUT ANY WARRANTY; without even the implied warranty of
      16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17  General Public License for more details.
      18  
      19  Under Section 7 of GPL version 3, you are granted additional
      20  permissions described in the GCC Runtime Library Exception, version
      21  3.1, as published by the Free Software Foundation.
      22  
      23  You should have received a copy of the GNU General Public License and
      24  a copy of the GCC Runtime Library Exception along with this program;
      25  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      26  <http://www.gnu.org/licenses/>.  */
      27  
      28  
      29  #if !defined (_StringConvert_H)
      30  #   define _StringConvert_H
      31  
      32  #include "config.h"
      33  #include "system.h"
      34  #   ifdef __cplusplus
      35  extern "C" {
      36  #   endif
      37  #include <stdbool.h>
      38  #   if !defined (PROC_D)
      39  #      define PROC_D
      40         typedef void (*PROC_t) (void);
      41         typedef struct { PROC_t proc; } PROC;
      42  #   endif
      43  
      44  #   include "GDynamicStrings.h"
      45  
      46  #   if defined (_StringConvert_C)
      47  #      define EXTERN
      48  #   else
      49  #      define EXTERN extern
      50  #   endif
      51  
      52  
      53  /*
      54     IntegerToString - converts INTEGER, i, into a String. The field with
      55                       can be specified if non zero. Leading characters
      56                       are defined by padding and this function will
      57                       prepend a + if sign is set to TRUE.
      58                       The base allows the caller to generate binary,
      59                       octal, decimal, hexidecimal numbers.
      60                       The value of lower is only used when hexidecimal
      61                       numbers are generated and if TRUE then digits
      62                       abcdef are used, and if FALSE then ABCDEF are used.
      63  */
      64  
      65  EXTERN DynamicStrings_String StringConvert_IntegerToString (int i, unsigned int width, char padding, bool sign, unsigned int base, bool lower);
      66  
      67  /*
      68     CardinalToString - converts CARDINAL, c, into a String. The field
      69                        width can be specified if non zero. Leading
      70                        characters are defined by padding.
      71                        The base allows the caller to generate binary,
      72                        octal, decimal, hexidecimal numbers.
      73                        The value of lower is only used when hexidecimal
      74                        numbers are generated and if TRUE then digits
      75                        abcdef are used, and if FALSE then ABCDEF are used.
      76  */
      77  
      78  EXTERN DynamicStrings_String StringConvert_CardinalToString (unsigned int c, unsigned int width, char padding, unsigned int base, bool lower);
      79  
      80  /*
      81     StringToInteger - converts a string, s, of, base, into an INTEGER.
      82                       Leading white space is ignored. It stops converting
      83                       when either the string is exhausted or if an illegal
      84                       numeral is found.
      85                       The parameter found is set TRUE if a number was found.
      86  */
      87  
      88  EXTERN int StringConvert_StringToInteger (DynamicStrings_String s, unsigned int base, bool *found);
      89  
      90  /*
      91     StringToCardinal - converts a string, s, of, base, into a CARDINAL.
      92                        Leading white space is ignored. It stops converting
      93                        when either the string is exhausted or if an illegal
      94                        numeral is found.
      95                        The parameter found is set TRUE if a number was found.
      96  */
      97  
      98  EXTERN unsigned int StringConvert_StringToCardinal (DynamicStrings_String s, unsigned int base, bool *found);
      99  
     100  /*
     101     LongIntegerToString - converts LONGINT, i, into a String. The field with
     102                           can be specified if non zero. Leading characters
     103                           are defined by padding and this function will
     104                           prepend a + if sign is set to TRUE.
     105                           The base allows the caller to generate binary,
     106                           octal, decimal, hexidecimal numbers.
     107                           The value of lower is only used when hexidecimal
     108                           numbers are generated and if TRUE then digits
     109                           abcdef are used, and if FALSE then ABCDEF are used.
     110  */
     111  
     112  EXTERN DynamicStrings_String StringConvert_LongIntegerToString (long int i, unsigned int width, char padding, bool sign, unsigned int base, bool lower);
     113  
     114  /*
     115     StringToLongInteger - converts a string, s, of, base, into an LONGINT.
     116                           Leading white space is ignored. It stops converting
     117                           when either the string is exhausted or if an illegal
     118                           numeral is found.
     119                           The parameter found is set TRUE if a number was found.
     120  */
     121  
     122  EXTERN long int StringConvert_StringToLongInteger (DynamicStrings_String s, unsigned int base, bool *found);
     123  
     124  /*
     125     LongCardinalToString - converts LONGCARD, c, into a String. The field
     126                            width can be specified if non zero. Leading
     127                            characters are defined by padding.
     128                            The base allows the caller to generate binary,
     129                            octal, decimal, hexidecimal numbers.
     130                            The value of lower is only used when hexidecimal
     131                            numbers are generated and if TRUE then digits
     132                            abcdef are used, and if FALSE then ABCDEF are used.
     133  */
     134  
     135  EXTERN DynamicStrings_String StringConvert_LongCardinalToString (long unsigned int c, unsigned int width, char padding, unsigned int base, bool lower);
     136  
     137  /*
     138     StringToLongCardinal - converts a string, s, of, base, into a LONGCARD.
     139                            Leading white space is ignored. It stops converting
     140                            when either the string is exhausted or if an illegal
     141                            numeral is found.
     142                            The parameter found is set TRUE if a number was found.
     143  */
     144  
     145  EXTERN long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s, unsigned int base, bool *found);
     146  
     147  /*
     148     ShortCardinalToString - converts SHORTCARD, c, into a String. The field
     149                             width can be specified if non zero. Leading
     150                             characters are defined by padding.
     151                             The base allows the caller to generate binary,
     152                             octal, decimal, hexidecimal numbers.
     153                             The value of lower is only used when hexidecimal
     154                             numbers are generated and if TRUE then digits
     155                             abcdef are used, and if FALSE then ABCDEF are used.
     156  */
     157  
     158  EXTERN DynamicStrings_String StringConvert_ShortCardinalToString (short unsigned int c, unsigned int width, char padding, unsigned int base, bool lower);
     159  
     160  /*
     161     StringToShortCardinal - converts a string, s, of, base, into a SHORTCARD.
     162                             Leading white space is ignored. It stops converting
     163                             when either the string is exhausted or if an illegal
     164                             numeral is found.
     165                             The parameter found is set TRUE if a number was found.
     166  */
     167  
     168  EXTERN short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s, unsigned int base, bool *found);
     169  
     170  /*
     171     stoi - decimal string to INTEGER
     172  */
     173  
     174  EXTERN int StringConvert_stoi (DynamicStrings_String s);
     175  
     176  /*
     177     itos - integer to decimal string.
     178  */
     179  
     180  EXTERN DynamicStrings_String StringConvert_itos (int i, unsigned int width, char padding, bool sign);
     181  
     182  /*
     183     ctos - cardinal to decimal string.
     184  */
     185  
     186  EXTERN DynamicStrings_String StringConvert_ctos (unsigned int c, unsigned int width, char padding);
     187  
     188  /*
     189     stoc - decimal string to CARDINAL
     190  */
     191  
     192  EXTERN unsigned int StringConvert_stoc (DynamicStrings_String s);
     193  
     194  /*
     195     hstoi - hexidecimal string to INTEGER
     196  */
     197  
     198  EXTERN int StringConvert_hstoi (DynamicStrings_String s);
     199  
     200  /*
     201     ostoi - octal string to INTEGER
     202  */
     203  
     204  EXTERN int StringConvert_ostoi (DynamicStrings_String s);
     205  
     206  /*
     207     bstoi - binary string to INTEGER
     208  */
     209  
     210  EXTERN int StringConvert_bstoi (DynamicStrings_String s);
     211  
     212  /*
     213     hstoc - hexidecimal string to CARDINAL
     214  */
     215  
     216  EXTERN unsigned int StringConvert_hstoc (DynamicStrings_String s);
     217  
     218  /*
     219     ostoc - octal string to CARDINAL
     220  */
     221  
     222  EXTERN unsigned int StringConvert_ostoc (DynamicStrings_String s);
     223  
     224  /*
     225     bstoc - binary string to CARDINAL
     226  */
     227  
     228  EXTERN unsigned int StringConvert_bstoc (DynamicStrings_String s);
     229  
     230  /*
     231     StringToLongreal - returns a LONGREAL and sets found to TRUE
     232                        if a legal number is seen.
     233  */
     234  
     235  EXTERN long double StringConvert_StringToLongreal (DynamicStrings_String s, bool *found);
     236  
     237  /*
     238     LongrealToString - converts a LONGREAL number, Real, which has,
     239                        TotalWidth, and FractionWidth into a string.
     240  
     241                        So for example:
     242  
     243                        LongrealToString(1.0, 4, 2)  -> '1.00'
     244                        LongrealToString(12.3, 5, 2) -> '12.30'
     245                        LongrealToString(12.3, 6, 2) -> ' 12.30'
     246                        LongrealToString(12.3, 6, 3) -> '12.300'
     247  
     248                        if total width is too small then the fraction
     249                        becomes truncated.
     250  
     251                        LongrealToString(12.3, 5, 3) -> '12.30'
     252  
     253                        If TotalWidth is 0 then the function
     254                        will return the value of x which is converted
     255                        into as a fixed point number with exhaustive
     256                        precision.
     257  */
     258  
     259  EXTERN DynamicStrings_String StringConvert_LongrealToString (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
     260  
     261  /*
     262     stor - returns a REAL given a string.
     263  */
     264  
     265  EXTERN double StringConvert_stor (DynamicStrings_String s);
     266  
     267  /*
     268     stolr - returns a LONGREAL given a string.
     269  */
     270  
     271  EXTERN long double StringConvert_stolr (DynamicStrings_String s);
     272  
     273  /*
     274     ToSigFig - returns a floating point or base 10 integer
     275                string which is accurate to, n, significant
     276                figures.  It will return a new String
     277                and, s, will be destroyed.
     278  
     279  
     280                So:  12.345
     281  
     282                rounded to the following significant figures yields
     283  
     284                5      12.345
     285                4      12.34
     286                3      12.3
     287                2      12
     288                1      10
     289  */
     290  
     291  EXTERN DynamicStrings_String StringConvert_ToSigFig (DynamicStrings_String s, unsigned int n);
     292  
     293  /*
     294     ToDecimalPlaces - returns a floating point or base 10 integer
     295                       string which is accurate to, n, decimal
     296                       places.  It will return a new String
     297                       and, s, will be destroyed.
     298                       Decimal places yields, n, digits after
     299                       the .
     300  
     301                       So:  12.345
     302  
     303                       rounded to the following decimal places yields
     304  
     305                       5      12.34500
     306                       4      12.3450
     307                       3      12.345
     308                       2      12.34
     309                       1      12.3
     310  */
     311  
     312  EXTERN DynamicStrings_String StringConvert_ToDecimalPlaces (DynamicStrings_String s, unsigned int n);
     313  #   ifdef __cplusplus
     314  }
     315  #   endif
     316  
     317  #   undef EXTERN
     318  #endif