Lines Matching refs:fp
164 register Find_t* fp; in findopen() local
196 if (!(fp = (Find_t*)vmnewof(vm, 0, Find_t, 1, sizeof(Encode_t) - sizeof(Code_t)))) in findopen()
198 fp->vm = vm; in findopen()
199 fp->id = lib; in findopen()
200 fp->disc = disc; in findopen()
201 fp->generate = 1; in findopen()
224 sfsprintf(fp->encode.file, sizeof(fp->encode.file), "%s/%s", path, findnames[k]); in findopen()
225 if (!eaccess(fp->encode.file, R_OK|W_OK)) in findopen()
227 path = fp->encode.file; in findopen()
230 if (strchr(findnames[k], '/') && (b = strrchr(fp->encode.file, '/'))) in findopen()
233 if (!stat(fp->encode.file, &st) && st.st_uid == uid && (st.st_mode & S_IWUSR)) in findopen()
236 path = fp->encode.file; in findopen()
246 sfsprintf(fp->encode.file, sizeof(fp->encode.file), "%s", path); in findopen()
247 path = fp->encode.file; in findopen()
253 sfsprintf(fp->encode.file, sizeof(fp->encode.file), "%s", path); in findopen()
254 if (b = strrchr(fp->encode.file, '/')) in findopen()
257 if (!stat(fp->encode.file, &st) && st.st_uid == uid && (st.st_mode & S_IWUSR)) in findopen()
260 path = fp->encode.file; in findopen()
266 else if (pathpath(fp->encode.file, path, "", PATH_REGULAR|PATH_READ|PATH_WRITE)) in findopen()
268 path = fp->encode.file; in findopen()
273 sfsprintf(fp->encode.file, sizeof(fp->encode.file), "%-.*s", b - path, path); in findopen()
274 if (pathpath(fp->encode.temp, fp->encode.file, "", PATH_EXECUTE|PATH_READ|PATH_WRITE) && in findopen()
275 !stat(fp->encode.temp, &st) && st.st_uid == uid && (st.st_mode & S_IWUSR)) in findopen()
277 sfsprintf(fp->encode.file, sizeof(fp->encode.file), "%s%s", fp->encode.temp, b); in findopen()
278 path = fp->encode.file; in findopen()
285 if (fp->disc->errorf) in findopen()
286 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: cannot locate codes", file ? file : findcodes[2]); in findopen()
289 if (fp->disc->flags & FIND_OLD) in findopen()
296 fp->method = FF_old; in findopen()
297 if (!(fp->fp = sftmp(32 * PATH_MAX))) in findopen()
299 if (fp->disc->errorf) in findopen()
300 (*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "cannot create tmp file"); in findopen()
318 if (!pathtemp(fp->encode.temp, sizeof(fp->encode.temp), p, "ff", &fd)) in findopen()
320 if (fp->disc->errorf) in findopen()
321 …(*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "%s: cannot create tmp file in this directory", … in findopen()
326 if (!(fp->fp = sfnew(NiL, NiL, (size_t)SF_UNBOUND, fd, SF_WRITE))) in findopen()
328 if (fp->disc->errorf) in findopen()
329 (*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "%s: cannot open tmp file", fp->encode.temp); in findopen()
333 if (fp->disc->flags & FIND_TYPE) in findopen()
335 fp->method = FF_typ; in findopen()
336 fp->encode.namedisc.key = offsetof(Type_t, name); in findopen()
337 fp->encode.namedisc.link = offsetof(Type_t, byname); in findopen()
338 fp->encode.indexdisc.key = offsetof(Type_t, index); in findopen()
339 fp->encode.indexdisc.size = sizeof(unsigned long); in findopen()
340 fp->encode.indexdisc.link = offsetof(Type_t, byindex); in findopen()
342 …if (!(fp->encode.namedict = dtopen(&fp->encode.namedisc, Dttree)) || !(fp->encode.indexdict = dtop… in findopen()
344 if (fp->encode.namedict) in findopen()
345 dtclose(fp->encode.namedict); in findopen()
346 if (fp->disc->errorf) in findopen()
347 (*fp->disc->errorf)(fp, fp->disc, 2, "cannot allocate type table"); in findopen()
355 tp->index = ++fp->types; in findopen()
357 dtinsert(fp->encode.namedict, tp); in findopen()
358 dtinsert(fp->encode.indexdict, tp); in findopen()
360 else if (fp->disc->flags & FIND_GNU) in findopen()
362 fp->method = FF_gnu; in findopen()
363 sfputc(fp->fp, 0); in findopen()
364 sfputr(fp->fp, FF_gnu_magic, 0); in findopen()
368 fp->method = FF_dir; in findopen()
369 sfputc(fp->fp, 0); in findopen()
370 sfputr(fp->fp, FF_dir_magic, 0); in findopen()
380 if (!(fp = (Find_t*)vmnewof(vm, 0, Find_t, 1, i))) in findopen()
385 fp->vm = vm; in findopen()
386 fp->id = lib; in findopen()
387 fp->disc = disc; in findopen()
389 fp->decode.ignorecase = 1; in findopen()
402 sfsprintf(fp->decode.path, sizeof(fp->decode.path), "%s/%s", path, findnames[k]); in findopen()
403 if (fp->fp = sfopen(NiL, fp->decode.path, "r")) in findopen()
405 path = fp->decode.path; in findopen()
409 if (fp->fp) in findopen()
412 else if (fp->fp = sfopen(NiL, path, "r")) in findopen()
416 …else if ((path = pathpath(fp->decode.path, path, "", PATH_REGULAR|PATH_READ)) && (fp->fp = sfopen(… in findopen()
419 if (!fp->fp) in findopen()
421 if (fp->disc->errorf) in findopen()
422 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: cannot locate codes", file ? file : findcodes[2]); in findopen()
425 if (fstat(sffileno(fp->fp), &st)) in findopen()
427 if (fp->disc->errorf) in findopen()
428 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: cannot stat codes", path); in findopen()
431 …if (fp->secure = ((st.st_mode & (S_IRGRP|S_IROTH)) == S_IRGRP) && st.st_gid == getegid() && getegi… in findopen()
433 fp->stamp = st.st_mtime; in findopen()
434 b = (s = fp->decode.temp) + 1; in findopen()
435 for (i = 0; i < elementsof(fp->decode.bigram1); i++) in findopen()
437 if ((j = sfgetc(fp->fp)) == EOF) in findopen()
439 if (!(*s++ = fp->decode.bigram1[i] = j) && i) in findopen()
444 if ((j = sfgetc(fp->fp)) == EOF) in findopen()
446 …if (!(*s++ = fp->decode.bigram2[i] = j) && (i || fp->decode.bigram1[0] >= '0' && fp->decode.bigram… in findopen()
453 type = (const char*)typefix(fp->decode.bigram2, sizeof(fp->decode.bigram2), type); in findopen()
454 memset(fp->decode.bigram1, 0, sizeof(fp->decode.bigram1)); in findopen()
456 fp->method = FF_typ; in findopen()
459 if (!(s = sfgetr(fp->fp, 0, 0))) in findopen()
465 FF_SET_TYPE(fp, i); in findopen()
471 fp->types = j; in findopen()
474 fp->method = FF_dir; in findopen()
476 fp->method = FF_gnu; in findopen()
479 fp->method = FF_gnu; in findopen()
480 while (j = sfgetc(fp->fp)) in findopen()
482 if (j == EOF || fp->decode.count >= sizeof(fp->decode.path)) in findopen()
484 fp->decode.path[fp->decode.count++] = j; in findopen()
489 fp->method = FF_old; in findopen()
492 if ((j = sfgetc(fp->fp)) == EOF) in findopen()
494 fp->decode.bigram2[i = -i] = j; in findopen()
496 while (++i < elementsof(fp->decode.bigram1)) in findopen()
498 if ((j = sfgetc(fp->fp)) == EOF) in findopen()
500 fp->decode.bigram1[i] = j; in findopen()
501 if ((j = sfgetc(fp->fp)) == EOF) in findopen()
503 fp->decode.bigram2[i] = j; in findopen()
505 if ((fp->decode.peek = sfgetc(fp->fp)) != FF_OFF) in findopen()
515 fp->verifyf = disc->verifyf; in findopen()
523 if (!(fp->dirs = vmnewof(fp->vm, 0, char*, 2 * k + 1, 0))) in findopen()
525 if (!(fp->lens = vmnewof(fp->vm, 0, int, 2 * k, 0))) in findopen()
528 b = fp->decode.temp; in findopen()
529 j = fp->method == FF_old || fp->method == FF_gnu; in findopen()
541 sfsprintf(b, sizeof(fp->decode.temp) - 1, "%s", s); in findopen()
542 else if (!p && !(p = getcwd(fp->decode.path, sizeof(fp->decode.path)))) in findopen()
545 sfsprintf(b, sizeof(fp->decode.temp) - 1, "%s/%s", p, s); in findopen()
549 if (!(fp->dirs[q] = vmstrdup(fp->vm, b))) in findopen()
552 (fp->dirs[q])[s - b] = 0; in findopen()
558 if (!strneq(b, fp->dirs[q - 1], s - b)) in findopen()
560 if (!(fp->dirs[q] = vmstrdup(fp->vm, b))) in findopen()
563 (fp->dirs[q])[s - b] = 0; in findopen()
567 strsort(fp->dirs, q, strcasecmp); in findopen()
569 fp->lens[i] = strlen(fp->dirs[i]); in findopen()
573 if (fp->verifyf || (disc->flags & FIND_VERIFY)) in findopen()
575 if (fp->method != FF_dir && fp->method != FF_typ) in findopen()
577 if (fp->disc->errorf) in findopen()
578 …(*fp->disc->errorf)(fp, fp->disc, 2, "%s: %s code format does not support directory verification",… in findopen()
581 fp->verify = 1; in findopen()
591 b = fp->decode.pattern; in findopen()
645 fp->decode.match = 1; in findopen()
646 …if (i = regcomp(&fp->decode.re, pattern, REG_SHELL|REG_AUGMENTED|(fp->decode.ignorecase?REG_ICASE:… in findopen()
650 regerror(i, &fp->decode.re, fp->decode.temp, sizeof(fp->decode.temp)); in findopen()
651 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: %s", pattern, fp->decode.temp); in findopen()
662 fp->decode.end = b; in findopen()
663 if (fp->decode.ignorecase) in findopen()
664 for (s = fp->decode.pattern; s <= b; s++) in findopen()
670 return fp; in findopen()
673 (*fp->disc->errorf)(fp, fp->disc, 2, "out of space"); in findopen()
676 if (!fp) in findopen()
683 if (fp->disc->errorf) in findopen()
684 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: invalid codes", path); in findopen()
686 if (!fp->generate && fp->decode.match) in findopen()
687 regfree(&fp->decode.re); in findopen()
688 if (fp->fp) in findopen()
689 sfclose(fp->fp); in findopen()
690 vmclose(fp->vm); in findopen()
700 findread(register Find_t* fp) in findread() argument
715 if (fp->generate) in findread()
717 if (fp->decode.restore) in findread()
719 *fp->decode.restore = '/'; in findread()
720 fp->decode.restore = 0; in findread()
722 ignorecase = fp->decode.ignorecase ? STR_ICASE : 0; in findread()
723 c = fp->decode.peek; in findread()
727 switch (fp->method) in findread()
731 n = sfgetl(fp->fp); in findread()
734 if ((c = sfgetc(fp->fp)) == EOF) in findread()
738 if ((c = sfgetc(fp->fp)) == EOF) in findread()
741 if ((c = sfgetc(fp->fp)) == EOF) in findread()
752 t = sfgetu(fp->fp); in findread()
753 n = sfgetl(fp->fp); in findread()
755 p = fp->decode.path + (fp->decode.count += n); in findread()
758 if ((c = sfgetc(fp->fp)) == EOF) in findread()
766 fp->decode.peek = c; in findread()
771 if (sfread(fp->fp, w, sizeof(w)) != sizeof(w)) in findread()
773 if (fp->decode.swap >= 0) in findread()
776 if (!fp->decode.swap) in findread()
795 fp->decode.swap = 1; in findread()
798 fp->decode.swap = -1; in findread()
806 fp->decode.count += c - FF_OFF; in findread()
807 for (p = fp->decode.path + fp->decode.count; (c = sfgetc(fp->fp)) > FF_ESC;) in findread()
810 *p++ = fp->decode.bigram1[c & ((1<<(CHAR_BIT-1))-1)]; in findread()
811 *p++ = fp->decode.bigram2[c & ((1<<(CHAR_BIT-1))-1)]; in findread()
819 b = fp->decode.path; in findread()
820 if (fp->decode.found) in findread()
821 fp->decode.found = 0; in findread()
823 b += fp->decode.count; in findread()
824 if (fp->dirs) in findread()
827 if (!*fp->dirs) in findread()
837 if ((n = p - fp->decode.path + 1) > (m = *fp->lens)) in findread()
839 if (!(*fp->dirs)[m]) in findread()
841 if (!strncasecmp(*fp->dirs, fp->decode.path, m)) in findread()
846 if (!(*fp->dirs)[m]) in findread()
848 …if (!(n = strcasecmp(*fp->dirs, fp->decode.path)) && (ignorecase || !strcmp(*fp->dirs, fp->decode.… in findread()
852 (*fp->dirs)[m] = '/'; in findread()
853 if ((*fp->dirs)[m - 1] != '/') in findread()
854 (*fp->dirs)[++(*fp->lens)] = '/'; in findread()
862 else if (!(*fp->dirs)[m]) in findread()
864 fp->dirs++; in findread()
865 fp->lens++; in findread()
867 if (fp->verify && (*p == '/' || t == 1)) in findread()
869 if ((n = p - fp->decode.path)) in findread()
873 if (fp->verifyf) in findread()
874 n = (*fp->verifyf)(fp, fp->decode.path, n, fp->disc); in findread()
875 else if (stat(fp->decode.path, &st)) in findread()
877 else if ((unsigned long)st.st_mtime > fp->stamp) in findread()
891 if (FF_OK_TYPE(fp, t)) in findread()
893 if (fp->decode.end) in findread()
897 if (*fp->decode.pattern == '/' && b > fp->decode.path) in findread()
900 if (*s == *fp->decode.end || ignorecase && tolower(*s) == *fp->decode.end) in findread()
903 for (e = fp->decode.end - 1, q = s - 1; *e && (*q == *e || tolower(*q) == *e); e--, q--); in findread()
905 for (e = fp->decode.end - 1, q = s - 1; *e && *q == *e; e--, q--); in findread()
908 fp->decode.found = 1; in findread()
909 …if (!fp->decode.match || strgrpmatch(fp->decode.path, fp->decode.pattern, NiL, 0, STR_MAXIMAL|STR_… in findread()
911 fp->decode.peek = c; in findread()
913 *(fp->decode.restore = p) = 0; in findread()
914 if (!fp->secure || !access(fp->decode.path, F_OK)) in findread()
915 return fp->decode.path; in findread()
921 else if (!fp->decode.match || !(n = regexec(&fp->decode.re, fp->decode.path, 0, NiL, 0))) in findread()
923 fp->decode.peek = c; in findread()
924 if (*p == '/' && p > fp->decode.path) in findread()
925 *(fp->decode.restore = p) = 0; in findread()
926 if (!fp->secure || !access(fp->decode.path, F_OK)) in findread()
927 return fp->decode.path; in findread()
931 if (fp->disc->errorf) in findread()
933 regerror(n, &fp->decode.re, fp->decode.temp, sizeof(fp->decode.temp)); in findread()
934 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: %s", fp->decode.pattern, fp->decode.temp); in findread()
948 findwrite(register Find_t* fp, const char* path, size_t len, const char* type) in findwrite() argument
958 if (!fp->generate) in findwrite()
960 if (type && fp->method == FF_dir) in findwrite()
962 len = sfsprintf(fp->encode.mark, sizeof(fp->encode.mark), "%-.*s/", len, path); in findwrite()
963 path = fp->encode.mark; in findwrite()
968 if (len < sizeof(fp->encode.path)) in findwrite()
972 len = sizeof(fp->encode.path) - 1; in findwrite()
975 p = (unsigned char*)fp->encode.path; in findwrite()
983 switch (fp->method) in findwrite()
986 d = n - fp->encode.prefix; in findwrite()
988 sfputc(fp->fp, d & 0xff); in findwrite()
991 sfputc(fp->fp, 0x80); in findwrite()
992 sfputc(fp->fp, (d >> 8) & 0xff); in findwrite()
993 sfputc(fp->fp, d & 0xff); in findwrite()
995 fp->encode.prefix = n; in findwrite()
996 sfputr(fp->fp, (char*)s, 0); in findwrite()
999 sfprintf(fp->fp, "%ld", n - fp->encode.prefix + FF_OFF); in findwrite()
1000 fp->encode.prefix = n; in findwrite()
1001 sfputc(fp->fp, ' '); in findwrite()
1008 fp->encode.code[n][*s++]++; in findwrite()
1014 sfputc(fp->fp, n); in findwrite()
1016 sfputc(fp->fp, 0); in findwrite()
1021 type = (const char*)typefix((char*)fp->encode.bigram, sizeof(fp->encode.bigram), type); in findwrite()
1022 if (x = (Type_t*)dtmatch(fp->encode.namedict, type)) in findwrite()
1028 u = x->index = ++fp->types; in findwrite()
1030 dtinsert(fp->encode.namedict, x); in findwrite()
1031 dtinsert(fp->encode.indexdict, x); in findwrite()
1036 sfputu(fp->fp, u); in findwrite()
1039 d = n - fp->encode.prefix; in findwrite()
1040 sfputl(fp->fp, d); in findwrite()
1041 fp->encode.prefix = n; in findwrite()
1042 sfputr(fp->fp, (char*)s, 0); in findwrite()
1045 memcpy(fp->encode.path, path, len); in findwrite()
1054 finddone(register Find_t* fp) in finddone() argument
1058 if (sfsync(fp->fp)) in finddone()
1060 if (fp->disc->errorf) in finddone()
1061 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: write error [sfsync]", fp->encode.file); in finddone()
1064 if (sferror(fp->fp)) in finddone()
1066 if (fp->disc->errorf) in finddone()
1067 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: write error [sferror]", fp->encode.file); in finddone()
1070 r = sfclose(fp->fp); in finddone()
1071 fp->fp = 0; in finddone()
1074 if (fp->disc->errorf) in finddone()
1075 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: write error [sfclose]", fp->encode.file); in finddone()
1086 findsync(register Find_t* fp) in findsync() argument
1098 switch (fp->method) in findsync()
1106 if (finddone(fp)) in findsync()
1108 remove(fp->encode.file); in findsync()
1109 if (rename(fp->encode.temp, fp->encode.file)) in findsync()
1111 if (fp->disc->errorf) in findsync()
1112 …(*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "%s: cannot rename from tmp file %s", fp->encode… in findsync()
1113 remove(fp->encode.temp); in findsync()
1124 fp->encode.hits[fp->encode.code[n][m]]++; in findsync()
1125 fp->encode.hits[0] = 0; in findsync()
1128 if (d = fp->encode.hits[n]) in findsync()
1130 fp->encode.hits[n] = m; in findsync()
1135 fp->encode.hits[n] = 0; in findsync()
1138 if (fp->encode.hits[fp->encode.code[n][m]]) in findsync()
1140 d = fp->encode.code[n][m]; in findsync()
1141 b = fp->encode.hits[d] - 1; in findsync()
1142 fp->encode.code[n][m] = b + FF_MAX; in findsync()
1143 if (fp->encode.hits[d]++ >= FF_MAX) in findsync()
1144 fp->encode.hits[d] = 0; in findsync()
1145 fp->encode.bigram[b *= 2] = n; in findsync()
1146 fp->encode.bigram[b + 1] = m; in findsync()
1149 fp->encode.code[n][m] = 0; in findsync()
1155 if (sfseek(fp->fp, (Sfoff_t)0, SEEK_SET)) in findsync()
1157 if (fp->disc->errorf) in findsync()
1158 (*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "cannot rewind tmp file"); in findsync()
1161 if (!(sp = sfopen(NiL, fp->encode.file, "w"))) in findsync()
1168 sfwrite(sp, fp->encode.bigram, sizeof(fp->encode.bigram)); in findsync()
1174 while (s = sfgetr(fp->fp, 0, 0)) in findsync()
1195 if (d = fp->encode.code[n][m]) in findsync()
1204 sfclose(fp->fp); in findsync()
1205 fp->fp = sp; in findsync()
1206 if (finddone(fp)) in findsync()
1210 if (finddone(fp)) in findsync()
1212 if (!(fp->fp = sfopen(NiL, fp->encode.temp, "r"))) in findsync()
1214 if (fp->disc->errorf) in findsync()
1215 (*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "%s: cannot read tmp file", fp->encode.temp); in findsync()
1216 remove(fp->encode.temp); in findsync()
1224 if (!(sp = sfopen(NiL, fp->encode.file, "w"))) in findsync()
1238 for (x = (Type_t*)dtfirst(fp->encode.indexdict); x; x = (Type_t*)dtnext(fp->encode.indexdict, x)) in findsync()
1246 if (sfmove(fp->fp, sp, SF_UNBOUND, -1) < 0 || !sfeof(fp->fp)) in findsync()
1249 if (fp->disc->errorf) in findsync()
1250 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: cannot append codes", fp->encode.file); in findsync()
1253 sfclose(fp->fp); in findsync()
1254 fp->fp = sp; in findsync()
1255 if (finddone(fp)) in findsync()
1257 remove(fp->encode.temp); in findsync()
1262 if (fp->disc->errorf) in findsync()
1263 (*fp->disc->errorf)(fp, fp->disc, 2, "%s: cannot write codes", fp->encode.file); in findsync()
1265 if (fp->fp) in findsync()
1267 sfclose(fp->fp); in findsync()
1268 fp->fp = 0; in findsync()
1270 remove(fp->encode.temp); in findsync()
1279 findclose(register Find_t* fp) in findclose() argument
1283 if (!fp) in findclose()
1285 if (fp->generate) in findclose()
1287 n = findsync(fp); in findclose()
1288 if (fp->encode.indexdict) in findclose()
1289 dtclose(fp->encode.indexdict); in findclose()
1290 if (fp->encode.namedict) in findclose()
1291 dtclose(fp->encode.namedict); in findclose()
1295 if (fp->decode.match) in findclose()
1296 regfree(&fp->decode.re); in findclose()
1299 if (fp->fp) in findclose()
1300 sfclose(fp->fp); in findclose()
1301 vmclose(fp->vm); in findclose()