示例#1
0
static int processIncludes(TextPackage *package, const char *input, DFBuffer *output, const char *path, DFError **error)
{
    int ok = 1;
    const char **lines = DFStringSplit(input,"\n",0);
    for (int lineno = 0; lines[lineno] && ok; lineno++) {
        const char *line = lines[lineno];
        if (DFStringHasPrefix(line,"#include \"") && DFStringHasSuffix(line,"\"")) {
            char *inclRelPath = DFSubstring(line,10,strlen(line)-1);
            char *inclAbsPath = DFAppendPathComponent(path,inclRelPath);
            char *inclDirName = DFPathDirName(inclAbsPath);
            char *inclContent = DFStringReadFromFile(inclAbsPath,error);
            if (inclContent == NULL) {
                DFErrorFormat(error,"%s: %s",inclRelPath,DFErrorMessage(error));
                ok = 0;
            }
            else if (!processIncludes(package,inclContent,output,inclDirName,error)) {
                ok = 0;
            }
            free(inclRelPath);
            free(inclAbsPath);
            free(inclDirName);
            free(inclContent);
        }
        else {
            DFBufferFormat(output,"%s\n",line);
        }
    }
    free(lines);
    return ok;
}
示例#2
0
static char *computeDocumentRelsPath(const char *documentPath)
{
    char *documentParent = DFPathDirName(documentPath);
    char *documentFilename = DFPathBaseName(documentPath);
    char *documentRelsPath = DFFormatString("%s/_rels/%s.rels",documentParent,documentFilename);
    free(documentParent);
    free(documentFilename);
    return documentRelsPath;
}
示例#3
0
int fromPlain(const char *inFilename, const char *outFilename, DFError **error)
{
    int fromStdin = !strcmp(inFilename,"-");
    char *inStr = readString(inFilename,error);
    if (inStr == NULL)
        return 0;

    char *inPath = fromStdin ? xstrdup(".") : DFPathDirName(inFilename);
    int ok = fromPlain2(inStr,inPath,outFilename,error);
    free(inPath);
    free(inStr);
    return ok;
}
示例#4
0
TextPackage *TextPackageNewWithFile(const char *filename, DFError **error)
{
    char *contents = DFStringReadFromFile(filename,error);
    if (contents == NULL) {
        DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
        return NULL;
    }

    char *path = DFPathDirName(filename);
    TextPackage *result = TextPackageNewWithString(contents,path,error);
    free(path);
    free(contents);
    return result;
}
示例#5
0
int textPackageList(const char *filename, DFError **error)
{
    char *filePath = DFPathDirName(filename);
    char *value = DFStringReadFromFile(filename,error);
    int result = 0;
    if (value == NULL)
        DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
    else if (!textPackageListRecursive(value,filePath,error,0))
        DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
    else
        result = 1;

    free(filePath);
    free(value);
    return result;
}
示例#6
0
static int saveXMLDocument(DFStorage *storage, const char *filename, DFDocument *doc, NamespaceID defaultNS, DFError **error)
{
    char *parentPath = DFPathDirName(filename);
    int ok = 0;

    if (!DFSerializeXMLStorage(doc,defaultNS,0,storage,filename,error)) {
        DFErrorFormat(error,"serialize %s: %s",filename,DFErrorMessage(error));
        goto end;
    }

    ok = 1;

end:
    free(parentPath);
    return ok;
}
示例#7
0
int textPackageGet(const char *filename, const char *itemPath, DFError **error)
{
    char *value = DFStringReadFromFile(filename,error);
    if (value == NULL) {
        DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
        return 0;
    }

    const char **components = DFStringSplit(itemPath,"/",0);
    for (size_t i = 0; components[i]; i++) {
        const char *name = components[i];
        char *filePath = DFPathDirName(filename);
        TextPackage *package = TextPackageNewWithString(value,filePath,error);
        free(filePath);
        if (package == NULL) {
            free(value);
            free(components);
            return 0;
        }
        free(value);
        value = xstrdup(DFHashTableLookup(package->items,name));
        if (value == NULL) {
            DFErrorFormat(error,"%s: Item %s not found",filename,itemPath);
            TextPackageRelease(package);
            free(value);
            free(components);
            return 0;
        }
        TextPackageRelease(package);
    }
    free(components);

    printf("%s",value);
    free(value);
    return 1;
}