| 153 | // |
| 154 | |
| 155 | char * // O - Found path or NULL |
| 156 | ppdcSource::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); |
nothing calls this directly
no test coverage detected