Add D30V options
[official-gcc.git] / gcc / f / sts.c
blob63bf77aea77a4b0e9e4afae755b20f5efbcba90e
1 /* sts.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
5 This file is part of GNU Fortran.
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
22 Related Modules:
23 None (despite the name, it doesn't really depend on ffest*)
25 Description:
26 Provides an arbitrary-length string facility for the limited needs of
27 GNU Fortran FORMAT statement generation.
29 Modifications:
32 /* Include files. */
34 #include "proj.h"
35 #include "sts.h"
36 #include "com.h"
37 #include "malloc.h"
39 /* Externals defined here. */
42 /* Simple definitions and enumerations. */
45 /* Internal typedefs. */
48 /* Private include files. */
51 /* Internal structure definitions. */
54 /* Static objects accessed by functions in this module. */
57 /* Static functions (internal). */
60 /* Internal macros. */
63 /* ffests_kill -- Kill a varying-length string
65 ffests s;
66 ffests_kill(s);
68 The storage associated with the string <s> is freed. */
70 void
71 ffests_kill (ffests s)
73 if (s->text_ != NULL)
74 malloc_kill_ksr (s->pool_, s->text_, s->max_);
77 /* ffests_new -- Make a varying-length string
79 ffests s;
80 ffests_new(s,malloc_pool_image(),0);
82 The string is initialized to hold, in this case, 0 characters, and
83 current and future heap manipulations to hold the string will use
84 the image pool. */
86 void
87 ffests_new (ffests s, mallocPool pool, ffestsLength size)
89 s->pool_ = pool;
90 s->len_ = 0;
91 s->max_ = size;
93 if (size == 0)
94 s->text_ = NULL;
95 else
96 s->text_ = malloc_new_ksr (pool, "ffests", size);
99 /* ffests_printf -- printf ("...%ld...",(long)) to a string
101 ffests s;
102 ffests_printf (s,"...%ld...",1);
104 Like printf, but into a string. */
106 void
107 ffests_printf (ffests s, const char *ctl, ...)
109 char *string;
110 va_list ap;
112 va_start (ap, ctl);
113 if (vasprintf (&string, ctl, ap) == 0)
114 abort ();
115 va_end (ap);
116 ffests_puts (s, string);
117 free (string);
120 /* ffests_putc -- Put a single character into string
122 ffests s;
123 ffests_putc(s,'*'); */
125 void
126 ffests_putc (ffests s, char c)
128 ffests_puttext (s, &c, 1);
131 /* ffests_puts -- Put a zero-terminated (C-style) string into string
133 ffests s;
134 ffests_puts(s,"append me"); */
136 void
137 ffests_puts (ffests s, const char *string)
139 ffests_puttext (s, string, strlen (string));
142 /* ffests_puttext -- Put a number of characters into string
144 ffests s;
145 ffests_puttext(s,"hi there",8);
147 The string need not be 0-terminated, because the passed length is used,
148 and may be 0. */
150 void
151 ffests_puttext (ffests s, const char *text, ffestsLength length)
153 ffestsLength newlen;
154 ffestsLength newmax;
156 if (length <= 0)
157 return;
159 newlen = s->len_ + length;
160 if (newlen > s->max_)
162 if (s->text_ == NULL)
164 s->max_ = 40;
165 s->text_ = malloc_new_ksr (s->pool_, "ffests", s->max_);
167 else
169 newmax = s->max_ << 1;
170 while (newmax < newlen)
171 newmax <<= 1;
172 s->text_ = malloc_resize_ksr (s->pool_, s->text_, newmax, s->max_);
173 s->max_ = newmax;
177 memcpy (s->text_ + s->len_, text, length);
178 s->len_ = newlen;