summaryrefslogtreecommitdiffstats
path: root/src/fs.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-06 15:42:04 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-06 15:42:04 +0000
commit232dbc756390d30a86ae6de0cc84600eddb1c0b2 (patch)
treee4aadbb4076392bcaf30cce6329dc715375a98d7 /src/fs.c
parent550bda3e54a0895e027fee14860f14171a357ac9 (diff)
downloadlibrcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.gz
librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.bz2
librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.xz
librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.zip
Recode FS Fixes
Diffstat (limited to 'src/fs.c')
-rw-r--r--src/fs.c75
1 files changed, 55 insertions, 20 deletions
diff --git a/src/fs.c b/src/fs.c
index 5064b6f..9c79dc4 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -64,29 +64,45 @@ static char *rccCheckFile(const char *prefix, const char *name) {
}
/* Converts: 'filename' to 'prefix/name' using 'fspath' */
-int rccFS0(const char *fspath, const char *filename, char **prefix, char **name) {
+int rccFS0(rcc_context ctx, const char *fspath, const char *filename, char **prefix, char **name) {
FILE *mtab;
struct mntent *fsentry;
- const char *tmp;
+ const char *tmp = NULL;
+ size_t len;
if (fspath) {
- tmp = strstr(filename, fspath);
- if (tmp) tmp = filename + strlen(fspath);
+ len = strlen(fspath);
+ if (!len) return 1;
+
+ if (!strncmp(filename, fspath, len)) tmp = filename + strlen(fspath);
} else {
- mtab = setmntent(_PATH_MNTTAB, "r");
+ /* only required with non-english mount directories */
+ len = strlen(ctx->lastprefix);
+ if ((len)&&(!strncmp(filename, ctx->lastprefix, len))) {
+ tmp = filename + len;
+ }
+
+ if (tmp) mtab = NULL;
+ else mtab = setmntent(_PATH_MNTTAB, "r");
if (mtab) {
while (!feof(mtab)) {
fsentry = getmntent(mtab);
if ((fsentry)&&(fsentry->mnt_dir)) {
- tmp = strstr(filename, fsentry->mnt_dir);
- if (tmp) tmp = filename + strlen(fsentry->mnt_dir);
+ len = strlen(fsentry->mnt_dir);
+ if (len) {
+ if (!strncmp(filename, fsentry->mnt_dir, len)) {
+ tmp = filename + len;
+ if (len<RCC_MAX_PREFIX_CHARS) strcpy(ctx->lastprefix, fsentry->mnt_dir);
+ break;
+ }
+ }
}
}
endmntent(mtab);
}
}
- if (!tmp) tmp = filename;
+ if (!tmp) return 1;
*name = strdup(tmp);
*prefix = strndup(filename, (tmp-filename));
@@ -100,7 +116,13 @@ int rccFS0(const char *fspath, const char *filename, char **prefix, char **name)
return 0;
}
-/* Normalizes 'prefix/name' using 'fspath' */
+/* Normalizes 'prefix/name' using 'fspath'
+returns:
+ -1 Error
+ 0 Okey
+ bit 1 Exact Match
+ bit 2 Memory cleanup isn't required
+*/
int rccFS1(rcc_context ctx, const char *fspath, char **prefix, char **name) {
int err;
int prefix_size;
@@ -122,17 +144,27 @@ int rccFS1(rcc_context ctx, const char *fspath, char **prefix, char **name) {
// Checking without recoding in case of autodetection
if (rccGetOption(ctx, RCC_AUTODETECT_FS_NAMES)) {
if (rccIsFile(result)) {
- if ((path)&&(filename)) *name = result;
- else if (filename) *name = strdup(filename);
- else *name = strdup(path);
- return 1;
+ *prefix = NULL;
+ *name = result;
+
+ if ((path)&&(filename)) return 1;
+ return 3;
}
}
+
+ puts("--");
+ if (rccFS0(ctx, fspath, result, prefix, name)) {
+ *prefix = NULL;
+ *name = result;
+
+ if ((path)&&(filename)) return 0;
+ return 2;
+ }
+ puts("++");
- err = rccFS0(fspath, result, prefix, name);
- if ((path)&&(filename)) free(name);
+ if ((path)&&(filename)) free(result);
- return err;
+ return 0;
}
/* Checks if 'prefix/name' is accessible using 'icnv' recoding. In case of
@@ -142,12 +174,15 @@ const char *rccFS2(rcc_context ctx, iconv_t icnv, const char *prefix, const char
if (icnv == (iconv_t)-1) return NULL;
if (icnv == (iconv_t)-2) {
- strcpy(ctx->tmpbuffer, name);
+ puts("-1");
+ strncpy(ctx->tmpbuffer, name, RCC_MAX_STRING_CHARS);
+ ctx->tmpbuffer[RCC_MAX_STRING_CHARS] = 0;
} else {
+ puts("-2");
err = rccIConv(ctx, icnv, name, 0);
if (err<=0) return NULL;
}
-
+ puts("ok");
return rccCheckFile(prefix, ctx->tmpbuffer);
}
@@ -167,7 +202,7 @@ const char *rccFS3(rcc_context ctx, rcc_language_id language_id, rcc_class_id cl
result = rccFS2(ctx, ctx->iconv_to[class_id], prefix, name);
if (result) {
- if ((icnv != (iconv_t)-1)||(icnv != (iconv_t)-2)) iconv_close(icnv);
+ if ((icnv != (iconv_t)-1)&&(icnv != (iconv_t)-2)) iconv_close(icnv);
ctx->fsiconv = (iconv_t)-1;
return result;
}
@@ -181,7 +216,7 @@ const char *rccFS3(rcc_context ctx, rcc_language_id language_id, rcc_class_id cl
if ((icnv != (iconv_t)-1)&&(icnv != (iconv_t)-2)) iconv_close(icnv);
- if (strcmp(charset, "UTF-8")&&strcmp(charset, "UTF8")) icnv = (iconv_t)-2;
+ if ((!strcmp(charset, "UTF-8"))||(!strcmp(charset, "UTF8"))) icnv = (iconv_t)-2;
else icnv = iconv_open(charset, "UTF-8");
result = rccFS2(ctx, icnv, prefix, name);