MCPcopy Create free account
hub / github.com/OpenPrinting/cups / find_include

Method find_include

ppdc/ppdc-source.cxx:155–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153//
154
155char * // O - Found path or NULL
156ppdcSource::find_include(
157 const char *f, // I - Include filename
158 const char *base, // I - Current directory
159 char *n, // I - Path buffer
160 int nlen) // I - Path buffer length
161{
162 ppdcString *dir; // Include directory
163 char temp[1024], // Temporary path
164 *ptr; // Pointer to end of path
165
166
167 // Range check input...
168 if (!f || !*f || !n || nlen < 2)
169 return (0);
170
171 // Check the first character to see if we have <name> or "name"...
172 if (*f == '<')
173 {
174 // Remove the surrounding <> from the name...
175 strlcpy(temp, f + 1, sizeof(temp));
176 ptr = temp + strlen(temp) - 1;
177
178 if (*ptr != '>')
179 {
180 _cupsLangPrintf(stderr,
181 _("ppdc: Invalid #include/#po filename \"%s\"."), n);
182 return (0);
183 }
184
185 *ptr = '\0';
186 f = temp;
187 }
188 else
189 {
190 // Check for the local file relative to the current directory...
191 if (base && *base && f[0] != '/')
192 snprintf(n, (size_t)nlen, "%s/%s", base, f);
193 else
194 strlcpy(n, f, (size_t)nlen);
195
196 if (!access(n, 0))
197 return (n);
198 else if (*f == '/')
199 {
200 // Absolute path that doesn't exist...
201 return (0);
202 }
203 }
204
205 // Search the include directories, if any...
206 if (includes)
207 {
208 for (dir = (ppdcString *)includes->first(); dir; dir = (ppdcString *)includes->next())
209 {
210 snprintf(n, (size_t)nlen, "%s/%s", dir->value, f);
211 if (!access(n, 0))
212 return (n);

Callers

nothing calls this directly

Calls 4

_cupsLangPrintfFunction · 0.85
_cupsGlobalsFunction · 0.85
firstMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected