123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- char *
- scm_c_oldfmt (char *from, int n)
- {
- #ifdef HAVE_SCM_SIMPLE_FORMAT
- return from;
- #else
- static struct { int n; char *from; char *to; } *strings;
- static int size = 0;
- static int n_strings = 0;
- char *to;
- int i;
-
- for (i = 0; i < n_strings; ++i)
- if (n == strings[i].n && strncmp (from, strings[i].from, n) == 0)
- return strings[i].to;
-
- if (n_strings == size)
- {
- if (size == 0)
- {
- size = 10;
- strings = scm_must_malloc (size * sizeof (*strings), s_oldfmt);
- }
- else
- {
- int oldsize = size;
- size = 3 * oldsize / 2;
- strings = scm_must_realloc (strings,
- oldsize * sizeof (*strings),
- size * sizeof (*strings),
- s_oldfmt);
- }
- }
- strings[n_strings].n = n;
- strings[n_strings].from = strncpy (scm_must_malloc (n, s_oldfmt), from, n);
- to = strings[n_strings].to = scm_must_malloc (n + 1, s_oldfmt);
- n_strings++;
- for (i = 0; i < n; ++i)
- {
- if (from[i] == '~' && ++i < n)
- {
- if (from[i] == 'A')
- {
- to[i - 1] = '%';
- to[i] = 's';
- }
- else if (from[i] == 'S')
- {
- to[i - 1] = '%';
- to[i] = 'S';
- }
- else
- {
- to[i - 1] = '~';
- to[i] = from[i];
- }
- continue;
- }
- to[i] = from[i];
- }
- to[i] = '\0';
-
- return to;
- #endif
- }
- char *
- scm_c_oldfmt0 (char *s)
- {
- #ifdef HAVE_SCM_SIMPLE_FORMAT
- return s;
- #else
- return scm_c_oldfmt (s, strlen (s));
- #endif
- }
- SCM_PROC (s_oldfmt, "oldfmt", 1, 0, 0, scm_oldfmt);
- SCM
- scm_oldfmt (SCM s)
- {
- #ifdef HAVE_SCM_SIMPLE_FORMAT
- return s;
- #else
- int n;
- SCM_ASSERT (SCM_NIMP (s) && SCM_STRINGP (s), s, 1, s_oldfmt);
- n = SCM_LENGTH (s);
- return scm_return_first (scm_makfromstr (scm_c_oldfmt (SCM_ROCHARS (s), n),
- n,
- 0),
- s);
- #endif
- }
|