示例#1
0
GDir::GDir(char *name, GBool doStatA) {
    path = new GooString(name);
    doStat = doStatA;
#if defined(WIN32)
    GooString *tmp;

    tmp = path->copy();
    tmp->append("/*.*");
    hnd = FindFirstFile(tmp->getCString(), &ffd);
    delete tmp;
#elif defined(ACORN)
#elif defined(MACOS)
#else
    dir = opendir(name);
#ifdef VMS
    needParent = strchr(name, '[') != NULL;
#endif
#endif
}
示例#2
0
void GDir::rewind() {
#ifdef WIN32
    GooString *tmp;

    if (hnd != INVALID_HANDLE_VALUE)
        FindClose(hnd);
    tmp = path->copy();
    tmp->append("/*.*");
    hnd = FindFirstFile(tmp->getCString(), &ffd);
    delete tmp;
#elif defined(ACORN)
#elif defined(MACOS)
#else
    if (dir)
        rewinddir(dir);
#ifdef VMS
    needParent = strchr(path->getCString(), '[') != NULL;
#endif
#endif
}
示例#3
0
static char *
unicode_to_char (Unicode *unicode,
		 int      len)
{
  static UnicodeMap *uMap = NULL;

  if (uMap == NULL) {
    GooString *enc = new GooString ("UTF-8");
    uMap = globalParams->getUnicodeMap (enc);
    uMap->incRefCnt ();
    delete enc;
  }

  GooString gstr;
  char buf[8]; /* 8 is enough for mapping an unicode char to a string */
  int i, n;

  for (i = 0; i < len; ++i) {
    n = uMap->mapUnicode (unicode[i], buf, sizeof (buf));
    gstr.append (buf, n);
  }

  return strdup (gstr.getCString ());
}
示例#4
0
GooString *appendToPath(GooString *path, char *fileName) {
#if defined(VMS)
    //---------- VMS ----------
    //~ this should handle everything necessary for file
    //~ requesters, but it's certainly not complete
    char *p0, *p1, *p2;
    char *q1;

    p0 = path->getCString();
    p1 = p0 + path->getLength() - 1;
    if (!strcmp(fileName, "-")) {
        if (*p1 == ']') {
            for (p2 = p1; p2 > p0 && *p2 != '.' && *p2 != '['; --p2) ;
            if (*p2 == '[')
                ++p2;
            path->del(p2 - p0, p1 - p2);
        } else if (*p1 == ':') {
            path->append("[-]");
        } else {
            path->clear();
            path->append("[-]");
        }
    } else if ((q1 = strrchr(fileName, '.')) && !strncmp(q1, ".DIR;", 5)) {
        if (*p1 == ']') {
            path->insert(p1 - p0, '.');
            path->insert(p1 - p0 + 1, fileName, q1 - fileName);
        } else if (*p1 == ':') {
            path->append('[');
            path->append(']');
            path->append(fileName, q1 - fileName);
        } else {
            path->clear();
            path->append(fileName, q1 - fileName);
        }
    } else {
        if (*p1 != ']' && *p1 != ':')
            path->clear();
        path->append(fileName);
    }
    return path;

#elif defined(WIN32)
    //---------- Win32 ----------
    GooString *tmp;
    char buf[256];
    char *fp;

    tmp = new GooString(path);
    tmp->append('/');
    tmp->append(fileName);
    GetFullPathName(tmp->getCString(), sizeof(buf), buf, &fp);
    delete tmp;
    path->clear();
    path->append(buf);
    return path;

#elif defined(ACORN)
    //---------- RISCOS ----------
    char *p;
    int i;

    path->append(".");
    i = path->getLength();
    path->append(fileName);
    for (p = path->getCString() + i; *p; ++p) {
        if (*p == '/') {
            *p = '.';
        } else if (*p == '.') {
            *p = '/';
        }
    }
    return path;

#elif defined(MACOS)
    //---------- MacOS ----------
    char *p;
    int i;

    path->append(":");
    i = path->getLength();
    path->append(fileName);
    for (p = path->getCString() + i; *p; ++p) {
        if (*p == '/') {
            *p = ':';
        } else if (*p == '.') {
            *p = ':';
        }
    }
    return path;

#elif defined(__EMX__)
    //---------- OS/2+EMX ----------
    int i;

    // appending "." does nothing
    if (!strcmp(fileName, "."))
        return path;

    // appending ".." goes up one directory
    if (!strcmp(fileName, "..")) {
        for (i = path->getLength() - 2; i >= 0; --i) {
            if (path->getChar(i) == '/' || path->getChar(i) == '\\' ||
                    path->getChar(i) == ':')
                break;
        }
        if (i <= 0) {
            if (path->getChar(0) == '/' || path->getChar(0) == '\\') {
                path->del(1, path->getLength() - 1);
            } else if (path->getLength() >= 2 && path->getChar(1) == ':') {
                path->del(2, path->getLength() - 2);
            } else {
                path->clear();
                path->append("..");
            }
        } else {
            if (path->getChar(i-1) == ':')
                ++i;
            path->del(i, path->getLength() - i);
        }
        return path;
    }

    // otherwise, append "/" and new path component
    if (path->getLength() > 0 &&
            path->getChar(path->getLength() - 1) != '/' &&
            path->getChar(path->getLength() - 1) != '\\')
        path->append('/');
    path->append(fileName);
    return path;

#else
    //---------- Unix ----------
    int i;

    // appending "." does nothing
    if (!strcmp(fileName, "."))
        return path;

    // appending ".." goes up one directory
    if (!strcmp(fileName, "..")) {
        for (i = path->getLength() - 2; i >= 0; --i) {
            if (path->getChar(i) == '/')
                break;
        }
        if (i <= 0) {
            if (path->getChar(0) == '/') {
                path->del(1, path->getLength() - 1);
            } else {
                path->clear();
                path->append("..");
            }
        } else {
            path->del(i, path->getLength() - i);
        }
        return path;
    }

    // otherwise, append "/" and new path component
    if (path->getLength() > 0 &&
            path->getChar(path->getLength() - 1) != '/')
        path->append('/');
    path->append(fileName);
    return path;
#endif
}