~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty

« back to all changes in this revision

Viewing changes to build/source/texk/kpathsea/fn.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* fn.c: arbitrarily long filenames (or just strings).
 
2
 
 
3
   Copyright 2001, 2005 Olaf Weber.
 
4
   Copyright 1993 Karl Berry.
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Lesser General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
   This library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Lesser General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Lesser General Public
 
17
   License along with this library; if not, write to the Free Software
 
18
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
*/
 
21
 
 
22
#include <kpathsea/config.h>
 
23
 
 
24
#include <kpathsea/fn.h>
 
25
 
 
26
 
 
27
/* /usr/local/lib/texmf/fonts/public/cm/pk/ljfour/cmr10.300pk is 58
 
28
   chars, so ASCII `K' seems a good choice. */
 
29
#define CHUNK_SIZE 75
 
30
 
 
31
 
 
32
fn_type
 
33
fn_init P1H(void)
 
34
{
 
35
  fn_type ret;
 
36
  
 
37
  FN_ALLOCATED (ret) = FN_LENGTH (ret) = 0;
 
38
  FN_STRING (ret) = NULL;
 
39
  
 
40
  return ret;
 
41
}
 
42
 
 
43
 
 
44
fn_type
 
45
fn_copy0 P2C(const_string, s,  unsigned, len)
 
46
{
 
47
  fn_type ret;
 
48
  
 
49
  FN_ALLOCATED (ret) = CHUNK_SIZE > len ? CHUNK_SIZE : len + 1;
 
50
  FN_STRING (ret) = (string)xmalloc (FN_ALLOCATED (ret));
 
51
  
 
52
  strncpy (FN_STRING (ret), s, len);
 
53
  FN_STRING (ret)[len] = 0;
 
54
  FN_LENGTH (ret) = len + 1;
 
55
  
 
56
  return ret;
 
57
}
 
58
 
 
59
/* Don't think we ever try to free something that might usefully be
 
60
   empty, so give fatal error if nothing allocated.  */
 
61
 
 
62
void
 
63
fn_free P1C(fn_type *, f)
 
64
{
 
65
  assert (FN_STRING (*f) != NULL);
 
66
  free (FN_STRING (*f));
 
67
  FN_STRING (*f) = NULL;
 
68
  FN_ALLOCATED (*f) = 0;
 
69
  FN_LENGTH (*f) = 0;
 
70
}
 
71
 
 
72
/* An arithmetic increase seems more reasonable than geometric.  We
 
73
   don't increase the length member since it may be more convenient for
 
74
   the caller to add than subtract when appending the stuff that will
 
75
   presumably follow.  */
 
76
 
 
77
static void
 
78
grow P2C(fn_type *, f,  unsigned, len)
 
79
{
 
80
  while (FN_LENGTH (*f) + len > FN_ALLOCATED (*f))
 
81
    {
 
82
      FN_ALLOCATED (*f) += CHUNK_SIZE;
 
83
      XRETALLOC (FN_STRING (*f), FN_ALLOCATED (*f), char);
 
84
    }
 
85
}
 
86
 
 
87
 
 
88
void
 
89
fn_1grow P2C(fn_type *, f,  char, c)
 
90
{
 
91
  grow (f, 1);
 
92
  FN_STRING (*f)[FN_LENGTH (*f)] = c;
 
93
  FN_LENGTH (*f)++;
 
94
}
 
95
 
 
96
 
 
97
void
 
98
fn_grow P3C(fn_type *, f,  const_string, source,  unsigned, len)
 
99
{
 
100
  grow (f, len);
 
101
  strncpy (FN_STRING (*f) + FN_LENGTH (*f), source, len);
 
102
  FN_LENGTH (*f) += len;
 
103
}
 
104
 
 
105
 
 
106
void
 
107
fn_str_grow P2C(fn_type *, f,  const_string, s)
 
108
{
 
109
  unsigned more_len = strlen (s);
 
110
  grow (f, more_len);
 
111
  strcat (FN_STRING (*f), s);
 
112
  FN_LENGTH (*f) += more_len;
 
113
}
 
114
 
 
115
 
 
116
void
 
117
fn_shrink_to P2C(fn_type *, f,  unsigned, loc)
 
118
{
 
119
  assert (FN_LENGTH (*f) > loc);
 
120
  FN_STRING (*f)[loc] = 0;
 
121
  FN_LENGTH (*f) = loc + 1;
 
122
}