|
a/src/pathut.cpp |
|
b/src/pathut.cpp |
|
... |
|
... |
13 |
* along with this program; if not, write to the
|
13 |
* along with this program; if not, write to the
|
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
|
17 |
|
18 |
#ifndef TEST_PATHUT
|
|
|
19 |
#ifdef BUILDING_RECOLL
|
18 |
#ifdef BUILDING_RECOLL
|
20 |
#include "autoconfig.h"
|
19 |
#include "autoconfig.h"
|
21 |
#else
|
20 |
#else
|
22 |
#include "config.h"
|
21 |
#include "config.h"
|
23 |
#endif
|
22 |
#endif
|
|
... |
|
... |
610 |
}
|
609 |
}
|
611 |
}
|
610 |
}
|
612 |
return out;
|
611 |
return out;
|
613 |
}
|
612 |
}
|
614 |
|
613 |
|
|
|
614 |
static inline int h2d(int c) {
|
|
|
615 |
if ('0' <= c && c <= '9')
|
|
|
616 |
return c - '0';
|
|
|
617 |
else if ('A' <= c && c <= 'F')
|
|
|
618 |
return 10 + c - 'A';
|
|
|
619 |
else
|
|
|
620 |
return -1;
|
|
|
621 |
}
|
|
|
622 |
|
|
|
623 |
string url_decode(const string &in)
|
|
|
624 |
{
|
|
|
625 |
if (in.size() <= 2)
|
|
|
626 |
return in;
|
|
|
627 |
string out;
|
|
|
628 |
out.reserve(in.size());
|
|
|
629 |
const char *cp = in.c_str();
|
|
|
630 |
string::size_type i = 0;
|
|
|
631 |
for (; i < in.size() - 2; i++) {
|
|
|
632 |
if (cp[i] == '%') {
|
|
|
633 |
int d1 = h2d(cp[i+1]);
|
|
|
634 |
int d2 = h2d(cp[i+2]);
|
|
|
635 |
if (d1 != -1 && d2 != -1) {
|
|
|
636 |
out += (d1 << 4) + d2;
|
|
|
637 |
} else {
|
|
|
638 |
out += '%';
|
|
|
639 |
out += cp[i+1];
|
|
|
640 |
out += cp[i+2];
|
|
|
641 |
}
|
|
|
642 |
i += 2;
|
|
|
643 |
} else {
|
|
|
644 |
out += cp[i];
|
|
|
645 |
}
|
|
|
646 |
}
|
|
|
647 |
while (i < in.size()) {
|
|
|
648 |
out += cp[i++];
|
|
|
649 |
}
|
|
|
650 |
return out;
|
|
|
651 |
}
|
|
|
652 |
|
615 |
string url_gpath(const string& url)
|
653 |
string url_gpath(const string& url)
|
616 |
{
|
654 |
{
|
617 |
// Remove the access schema part (or whatever it's called)
|
655 |
// Remove the access schema part (or whatever it's called)
|
618 |
string::size_type colon = url.find_first_of(":");
|
656 |
string::size_type colon = url.find_first_of(":");
|
619 |
if (colon == string::npos || colon == url.size() - 1) {
|
657 |
if (colon == string::npos || colon == url.size() - 1) {
|
|
... |
|
... |
865 |
// Call funcs that need static init (not initially reentrant)
|
903 |
// Call funcs that need static init (not initially reentrant)
|
866 |
void pathut_init_mt()
|
904 |
void pathut_init_mt()
|
867 |
{
|
905 |
{
|
868 |
path_home();
|
906 |
path_home();
|
869 |
}
|
907 |
}
|
870 |
|
|
|
871 |
|
|
|
872 |
#else // TEST_PATHUT
|
|
|
873 |
#include <stdlib.h>
|
|
|
874 |
#include <iostream>
|
|
|
875 |
using namespace std;
|
|
|
876 |
|
|
|
877 |
#include "pathut.h"
|
|
|
878 |
|
|
|
879 |
void path_to_thumb(const string& _input)
|
|
|
880 |
{
|
|
|
881 |
string input(_input);
|
|
|
882 |
// Make absolute path if needed
|
|
|
883 |
if (input[0] != '/') {
|
|
|
884 |
input = path_absolute(input);
|
|
|
885 |
}
|
|
|
886 |
|
|
|
887 |
input = string("file://") + path_canon(input);
|
|
|
888 |
|
|
|
889 |
string path;
|
|
|
890 |
//path = url_encode(input, 7);
|
|
|
891 |
thumbPathForUrl(input, 7, path);
|
|
|
892 |
cout << path << endl;
|
|
|
893 |
}
|
|
|
894 |
|
|
|
895 |
const char *tstvec[] = {"", "/", "/dir", "/dir/", "/dir1/dir2",
|
|
|
896 |
"/dir1/dir2",
|
|
|
897 |
"./dir", "./dir1/", "dir", "../dir", "/dir/toto.c",
|
|
|
898 |
"/dir/.c", "/dir/toto.txt", "toto.txt1"
|
|
|
899 |
};
|
|
|
900 |
|
|
|
901 |
const string ttvec[] = {"/dir", "", "~", "~/sub", "~root", "~root/sub",
|
|
|
902 |
"~nosuch", "~nosuch/sub"
|
|
|
903 |
};
|
|
|
904 |
int nttvec = sizeof(ttvec) / sizeof(string);
|
|
|
905 |
|
|
|
906 |
const char *thisprog;
|
|
|
907 |
|
|
|
908 |
int main(int argc, const char **argv)
|
|
|
909 |
{
|
|
|
910 |
thisprog = *argv++;
|
|
|
911 |
argc--;
|
|
|
912 |
|
|
|
913 |
string s;
|
|
|
914 |
vector<string>::const_iterator it;
|
|
|
915 |
#if 0
|
|
|
916 |
for (unsigned int i = 0; i < sizeof(tstvec) / sizeof(char *); i++) {
|
|
|
917 |
cout << tstvec[i] << " Father " << path_getfather(tstvec[i]) << endl;
|
|
|
918 |
}
|
|
|
919 |
for (unsigned int i = 0; i < sizeof(tstvec) / sizeof(char *); i++) {
|
|
|
920 |
cout << tstvec[i] << " Simple " << path_getsimple(tstvec[i]) << endl;
|
|
|
921 |
}
|
|
|
922 |
for (unsigned int i = 0; i < sizeof(tstvec) / sizeof(char *); i++) {
|
|
|
923 |
cout << tstvec[i] << " Basename " <<
|
|
|
924 |
path_basename(tstvec[i], ".txt") << endl;
|
|
|
925 |
}
|
|
|
926 |
#endif
|
|
|
927 |
|
|
|
928 |
#if 0
|
|
|
929 |
for (int i = 0; i < nttvec; i++) {
|
|
|
930 |
cout << "tildexp: '" << ttvec[i] << "' -> '" <<
|
|
|
931 |
path_tildexpand(ttvec[i]) << "'" << endl;
|
|
|
932 |
}
|
|
|
933 |
#endif
|
|
|
934 |
|
|
|
935 |
#if 0
|
|
|
936 |
const string canontst[] = {"/dir1/../../..", "/////", "",
|
|
|
937 |
"/dir1/../../.././/////dir2///////",
|
|
|
938 |
"../../",
|
|
|
939 |
"../../../../../../../../../../"
|
|
|
940 |
};
|
|
|
941 |
unsigned int nttvec = sizeof(canontst) / sizeof(string);
|
|
|
942 |
for (unsigned int i = 0; i < nttvec; i++) {
|
|
|
943 |
cout << "canon: '" << canontst[i] << "' -> '" <<
|
|
|
944 |
path_canon(canontst[i]) << "'" << endl;
|
|
|
945 |
}
|
|
|
946 |
#endif
|
|
|
947 |
#if 0
|
|
|
948 |
if (argc != 2) {
|
|
|
949 |
cerr << "Usage: trpathut <dir> <pattern>" << endl;
|
|
|
950 |
exit(1);
|
|
|
951 |
}
|
|
|
952 |
string dir = *argv++;
|
|
|
953 |
argc--;
|
|
|
954 |
string pattern = *argv++;
|
|
|
955 |
argc--;
|
|
|
956 |
vector<string> matched = path_dirglob(dir, pattern);
|
|
|
957 |
for (it = matched.begin(); it != matched.end(); it++) {
|
|
|
958 |
cout << *it << endl;
|
|
|
959 |
}
|
|
|
960 |
#endif
|
|
|
961 |
|
|
|
962 |
#if 0
|
|
|
963 |
if (argc != 1) {
|
|
|
964 |
fprintf(stderr, "Usage: fsocc: trpathut <path>\n");
|
|
|
965 |
exit(1);
|
|
|
966 |
}
|
|
|
967 |
string path = *argv++;
|
|
|
968 |
argc--;
|
|
|
969 |
|
|
|
970 |
int pc;
|
|
|
971 |
long long blocks;
|
|
|
972 |
if (!fsocc(path, &pc, &blocks)) {
|
|
|
973 |
fprintf(stderr, "fsocc failed\n");
|
|
|
974 |
return 1;
|
|
|
975 |
}
|
|
|
976 |
printf("pc %d, megabytes %ld\n", pc, blocks);
|
|
|
977 |
#endif
|
|
|
978 |
|
|
|
979 |
#if 0
|
|
|
980 |
Pidfile pidfile("/tmp/pathutpidfile");
|
|
|
981 |
pid_t pid;
|
|
|
982 |
if ((pid = pidfile.open()) != 0) {
|
|
|
983 |
cerr << "open failed. reason: " << pidfile.getreason() <<
|
|
|
984 |
" return " << pid << endl;
|
|
|
985 |
exit(1);
|
|
|
986 |
}
|
|
|
987 |
pidfile.write_pid();
|
|
|
988 |
sleep(10);
|
|
|
989 |
pidfile.close();
|
|
|
990 |
pidfile.remove();
|
|
|
991 |
#endif
|
|
|
992 |
|
|
|
993 |
#if 0
|
|
|
994 |
if (argc > 1) {
|
|
|
995 |
cerr << "Usage: thumbpath <filepath>" << endl;
|
|
|
996 |
exit(1);
|
|
|
997 |
}
|
|
|
998 |
string input;
|
|
|
999 |
if (argc == 1) {
|
|
|
1000 |
input = *argv++;
|
|
|
1001 |
if (input.empty()) {
|
|
|
1002 |
cerr << "Usage: thumbpath <filepath>" << endl;
|
|
|
1003 |
exit(1);
|
|
|
1004 |
}
|
|
|
1005 |
path_to_thumb(input);
|
|
|
1006 |
} else {
|
|
|
1007 |
while (getline(cin, input)) {
|
|
|
1008 |
path_to_thumb(input);
|
|
|
1009 |
}
|
|
|
1010 |
}
|
|
|
1011 |
|
|
|
1012 |
|
|
|
1013 |
exit(0);
|
|
|
1014 |
#endif
|
|
|
1015 |
|
|
|
1016 |
#if 0
|
|
|
1017 |
if (argc != 1) {
|
|
|
1018 |
cerr << "Usage: trpathut <filename>" << endl;
|
|
|
1019 |
exit(1);
|
|
|
1020 |
}
|
|
|
1021 |
string fn = *argv++;
|
|
|
1022 |
argc--;
|
|
|
1023 |
string ext = path_suffix(fn);
|
|
|
1024 |
cout << "Suffix: [" << ext << "]" << endl;
|
|
|
1025 |
return 0;
|
|
|
1026 |
#endif
|
|
|
1027 |
|
|
|
1028 |
#if 0
|
|
|
1029 |
if (argc != 1) {
|
|
|
1030 |
cerr << "Usage: trpathut url" << endl;
|
|
|
1031 |
exit(1);
|
|
|
1032 |
}
|
|
|
1033 |
string url = *argv++;
|
|
|
1034 |
argc--;
|
|
|
1035 |
|
|
|
1036 |
cout << "File: [" << fileurltolocalpath(url) << "]\n";
|
|
|
1037 |
return 0;
|
|
|
1038 |
#endif
|
|
|
1039 |
|
|
|
1040 |
#if 1
|
|
|
1041 |
if (argc != 1) {
|
|
|
1042 |
cerr << "Usage: trpathut path" << endl;
|
|
|
1043 |
exit(1);
|
|
|
1044 |
}
|
|
|
1045 |
string path = *argv++;
|
|
|
1046 |
argc--;
|
|
|
1047 |
|
|
|
1048 |
int pc;
|
|
|
1049 |
long long avmbs;
|
|
|
1050 |
if (fsocc(path, &pc, &avmbs)) {
|
|
|
1051 |
cout << "Percent occup " << pc << " avmbs " << avmbs << endl;
|
|
|
1052 |
return 0;
|
|
|
1053 |
} else {
|
|
|
1054 |
cerr << "fsocc failed\n";
|
|
|
1055 |
return 1;
|
|
|
1056 |
}
|
|
|
1057 |
#endif
|
|
|
1058 |
|
|
|
1059 |
|
|
|
1060 |
|
|
|
1061 |
}
|
|
|
1062 |
|
|
|
1063 |
#endif // TEST_PATHUT
|
|
|
1064 |
|
|
|