summaryrefslogtreecommitdiff
path: root/support/gnomesupport.awk
blob: 2f89ab6a39364e628b021fc3f5724beb00c462fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# This program is used to generate gnomesupport.h

# Print prologue
BEGIN {
  print "/* gnomesupport.h */";
  print "/* This is a generated file.  Please modify `gnomesupport.awk' */";
  print "";
  print "#ifndef GNOMESUPPORT_H";
  print "#define GNOMESUPPORT_H";
  print "";
  print "#include <stddef.h>		/* for size_t */";
}

# For each `#define HAVE_FOO 1', set def["HAVE_FOO"] = 1
/^\#define[ \t]/ { def[$2] = 1; }

END {
  if (!def["HAVE_VASPRINTF"] || !def["HAVE_VSNPRINTF"]) {
    print "#include <stdarg.h>";
  }

  if (!def["HAVE_SCANDIR"] || def["NEED_DECLARATION_SCANDIR"]) {
    print "#include <sys/types.h>";

    if (def["HAVE_DIRENT_H"]) {
      print "#include <dirent.h>";
      print "#define NAMLEN(dirent) strlen((dirent)->d_name)";
    } else {
      print "#define dirent direct";
      print "#define NAMLEN(dirent) (dirent)->d_namlen";
      
      if (def["HAVE_SYS_NDIR_H"])
	print "#include <sys/ndir.h>";
      if (def["HAVE_SYS_DIR_H"])
	print "#include <sys/dir.h>";
      if (def["HAVE_NDIR_H"])
	print "#include <ndir.h>";
    }
  }

  print "";
  print "#ifdef __cplusplus";
  print "extern \"C\" {";
  print "#endif /* __cplusplus */";

  if (def["NEED_DECLARATION_GETHOSTNAME"]) {
    print "";
    print "/* Get name of current host.  */";
    print "int gethostname(char */*name*/, int /*namelen*/);";
  }

  if (def["NEED_DECLARATION_SETREUID"]) {
    print "";
    print "/* Set real and effective user ID. */";
    print "int setreuid(uid_t /*ruid*/, uid_t /*euid*/);";
  }

  if (def["NEED_DECLARATION_SETREGID"]) {
    print "";
    print "/* Set real and effective group ID. */";
    print "int setregid(gid_t /*rgid*/, gid_t /*egid*/);";
  }
  
  if (def["NEED_DECLARATION_GETPAGESIZE"]) {
    print "";
    print "/* Get system page size. */";
    print "size_t getpagesize(void);";
  }
  
  if (!def["HAVE_MEMMOVE"]) {
    print "";
    print "/* Copies len bytes from src to dest. */";
    print "void * memmove (void */*dest*/, const void */*src*/, size_t /*len*/);";
  }

  if (!def["HAVE_MKSTEMP"]) {
    print "";
    print "/* Generate a unique temporary file name from TEMPLATE.";
    print "   The last six characters of TEMPLATE must be "XXXXXX";";
    print "   they are replaced with a string that makes the filename";
    print "   unique.  Returns a file descriptor open on the file for";
    print "   reading and writing.  */";
    print "int mkstemp (char */*template*/);";
  }
  
  if (!def["HAVE_SCANDIR"] || def["NEED_DECLARATION_SCANDIR"]) {
    print "";
    print "/* Scan the directory DIR, calling SELECTOR on each directory";
    print "   entry.  Entries for which SELECTOR returns nonzero are";
    print "   individually malloc'd, sorted using qsort with CMP, and";
    print "   collected in a malloc'd array in *NAMELIST.  Returns the";
    print "   number of entries selected, or -1 on error.  */";
    print "int scandir (const char */*dir*/, struct dirent ***/*namelist*/,";
    print "             int (*/*selector*/) (struct dirent *),";
    print "             int (*/*cmp*/) (const void *, const void *));";
    print "";
    print "/* Function to compare two `struct dirent's alphabetically.  */";
    print "int alphasort (const void */*a*/, const void */*b*/);";
  }
  
  if (!def["HAVE_STRERROR"]) {
    print "";
    print "/* Return a string describing the meaning of the `errno' code";
    print "   in ERRNUM.  */";
    print "extern char *strerror (int /*errnum*/);";
  }

  if (!def["HAVE_STRCASECMP"]) {
    print "";
    print "/* Compare S1 and S2, ignoring case.  */";
    print "int strcasecmp (const char */*s1*/, const char */*s2*/);";
  }

  if (!def["HAVE_STRNDUP"]) {
    print "";
    print "/* Return a malloc'd copy of at most N bytes of STRING.  The";
    print "   resultant string is terminated even if no null terminator";
    print "   appears before STRING[N].  */";
    print "char * strndup (const char */*s*/, size_t /*n*/);";
  }

  if (!def["HAVE_STRNLEN"]) {
    print "";
    print "/* Find the length of STRING, but scan at most MAXLEN";
    print "   characters.  If no '\\0' terminator is found in that many";
    print "   characters, return MAXLEN.  */";
    print "size_t strnlen (const char */*string*/, size_t /*maxlen*/);";
  }

  if (!def["HAVE_STRTOK_R"]) {
    print "";
    print "/* Divide S into tokens separated by characters in DELIM.";
    print "   Information passed between calls are stored in SAVE_PTR.  */";
    print "char * strtok_r (char */*s*/, const char */*delim*/,";
    print "                 char **/*save_ptr*/);";
  }

  if (!def["HAVE_STRTOD"]) {
    print "";
    print "/* Convert the initial portion of the string pointed to by";
    print "   nptr to double representation and return the converted value.";
    print "   If endptr is not NULL, a pointer to the character after the";
    print "   last character used in the conversion is stored in the";
    print "   location referenced by endptr. */";
    print "double strtod (const char */*nptr*/, char **/*endptr*/);";
  }

  if (!def["HAVE_STRTOL"]) {
    print "";
    print "/* Convert the initial portion of the string pointed to by";
    print "   nptr to a long integer value according to the given base.";
    print "   If endptr is not NULL, a pointer to the character after the";
    print "   last character used in the conversion is stored in the";
    print "   location referenced by endptr. */";
    print "long int strtol (const char */*nptr*/, char **/*endptr*/, int /*base*/);";
  }

  if (!def["HAVE_STRTOUL"]) {
    print "";
    print "/* Convert the initial portion of the string pointed to by";
    print "   nptr to an unsigned long integer value according to the given base.";
    print "   If endptr is not NULL, a pointer to the character after the";
    print "   last character used in the conversion is stored in the";
    print "   location referenced by endptr. */";
    print "unsigned long int strtoul (const char */*nptr*/, char **/*endptr*/,";
    print "                          int /*base*/);";
  }

  if (!def["HAVE_VASPRINTF"]) {
    print "";
    print "/* Write formatted output to a string dynamically allocated with";
    print "   `malloc'.  Store the address of the string in *PTR.  */";
    print "int vasprintf (char **/*ptr*/, const char */*format*/,";
    print "               va_list /*args*/);";
    print "int asprintf (char **/*ptr*/, const char */*format*/, ...);";
  }

  if (!def["HAVE_VSNPRINTF"]) {
    print "";
    print "/* Maximum chars of output to write is MAXLEN.  */";
    print "int vsnprintf (char */*str*/, size_t /*maxlen*/,";
    print "               char */*fmt*/, va_list /*ap*/);";
    print "int snprintf (char */*str*/, size_t /*maxlen*/,";
    print "              char */*fmt*/, ...);";
  }

  if (!def["HAVE_REALPATH"]) {
    print "";
    print "/* Return the canonical absolute name of file NAME.  A canonical name";
    print "   does not contain any `.', `..' components nor any repeated path";
    print "   separators ('/') or symlinks.  All path components must exist.";
    print "   If the canonical name is PATH_MAX chars or more, returns null with";
    print "   `errno' set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX";
    print "   chars, returns the name in RESOLVED.  If the name cannot be resolved";
    print "   and RESOLVED is non-NULL, it contains the path of the first component";
    print "   that cannot be resolved.  If the path can be resolved, RESOLVED";
    print "   holds the same value as the value returned.  */";
    print "";
    print "char *realpath (char */*path*/, char /*resolved_path*/[]);";
  }

  print "";
  print "#ifdef __cplusplus";
  print "}";
  print "#endif /* __cplusplus */";
  print "";
  print "#endif /* GNOMESUPPORT_H */";
}