示例#1
0
extern int main (int argc, char** argv)
{
	int i;
	for (i = 1  ;  argv [i] != NULL  ;  ++i)
	{
		const char *const arg = argv [i];
		if (arg [0] == '-')
		{
			int j;
			if (arg [1] == '\0')
			{
					File = stdin;
					FileName = "stdin";
			}
			else for (j = 1  ;  arg [j] != '\0'  ;  ++j) switch (arg [j])
			{
				case 'c':  PrintClass      = 1;  break;
				case 'r':  PrintReferences = 1;  break;
				case 's':  SelfReferences  = 1;  break;
				case 'd':  Debug           = 1;  break;
				default:
					fprintf (errout, "%s: unknown option: %c\n", argv [0], arg [1]);
					fprintf (errout, Usage, argv [0]);
					exit (1);
					break;
			}
		}
		else if (File != NULL)
		{
			fprintf (errout, Usage, argv [0]);
			exit (1);
		}
		else
		{
			FileName = arg;
			File = fopen (FileName, "r");
			if (File == NULL)
			{
				perror (argv [0]);
				exit (1);
			}
		}
	}
	if (! PrintClass)
		PrintReferences = 1;
	if (File == NULL)
	{
		fprintf (errout, Usage, argv [0]);
		exit (1);
	}
	else
	{
		findReferences ();
		fclose (File);
	}
	return 0;
}
QFileInfoList GameControllerAttachment::findReferences(const QDomElement &node) const
{
	QFileInfoList references;	
	if (node.tagName() == "Sound3D" && node.hasAttribute("file"))
	{
		QFileInfo file(node.attribute("file"));
		references.append(file);
	}
	if( node.tagName() == "StaticAnimation" && node.hasAttribute("file"))
	{
		QFileInfo file(node.attribute("file"));
		references.append(file);
	}
	QDomNodeList children = node.childNodes();
	for (int i=0; i<children.size(); ++i)
		references << findReferences(children.at(i).toElement());
	return references;
}
示例#3
0
static void collect(WordPackage *package, DFHashTable *referencedIds)
{
    findReferences(referencedIds,package->document->docNode);

    OPCRelationshipSet *relationships = package->documentPart->relationships;
    const char **allIds = OPCRelationshipSetAllIds(relationships);
    for (int i = 0; allIds[i]; i++) {
        const char *rId = allIds[i];
        // FIXME: We should check all targets of all relationships in the package to determine
        // the set of referenced files, and only delete the file if there are no more references
        // to it.
        OPCRelationship *rel = OPCRelationshipSetLookupById(relationships,rId);
        if (rel->needsRemoveCheck && (DFHashTableLookup(referencedIds,rel->rId) == NULL)) {
            if (!rel->external)
                DFStorageDelete(package->opc->storage,rel->target,NULL);
            OPCRelationshipSetRemove(relationships,rel);
        }
    }
    free(allIds);
}
示例#4
0
static void findReferences(DFHashTable *referencedIds, DFNode *node)
{
    if (node->tag >= MIN_ELEMENT_TAG) {
        switch (node->tag) {
            case WORD_HYPERLINK: {
                const char *rId = DFGetAttribute(node,OREL_ID);
                if (rId != NULL)
                    DFHashTableAdd(referencedIds,rId,"");
                break;
            }
            case DML_MAIN_BLIP: {
                const char *rId = DFGetAttribute(node,OREL_EMBED);
                if (rId != NULL)
                    DFHashTableAdd(referencedIds,rId,"");
                break;
            }
        }
    }

    for (DFNode *child = node->first; child != NULL; child = child->next)
        findReferences(referencedIds,child);
}
示例#5
0
void Word_setupBookmarkLinks(WordPutData *put)
{
    DFHashTable *referencesById = findReferences(put->conv->html);
    const char **sortedIds = DFHashTableCopyKeys(referencesById);
    DFSortStringsCaseSensitive(sortedIds);
    for (int idIndex = 0; sortedIds[idIndex]; idIndex++) {
        const char *targetId = sortedIds[idIndex];
        DFArray *references = DFHashTableLookup(referencesById,targetId);
        DFNode *targetElem = DFElementForIdAttr(put->conv->html,targetId);
        if (targetElem == NULL)
            continue;

        // The following is only relevant for figures and tables
        int refText = 0;
        int refLabelNum = 0;
        int refCaptionText = 0;

        for (int refIndex = 0; refIndex < DFArrayCount(references); refIndex++) {
            DFNode *a = DFArrayItemAt(references,refIndex);
            const char *className = DFGetAttribute(a,HTML_CLASS);
            if (DFStringEquals(className,DFRefTextClass))
                refText = 1;
            else if (DFStringEquals(className,DFRefLabelNumClass))
                refLabelNum = 1;
            else if (DFStringEquals(className,DFRefCaptionTextClass))
                refCaptionText = 1;
        }

        DFNode *concrete = WordConverterGetConcrete(put,targetElem);
        switch (targetElem->tag) {
            case HTML_H1:
            case HTML_H2:
            case HTML_H3:
            case HTML_H4:
            case HTML_H5:
            case HTML_H6: {
                const char *bookmarkId = NULL;
                const char *bookmarkName = NULL;
                DFNode *bookmarkElem = NULL;
                if ((concrete != NULL) && (concrete->tag == WORD_P)) {

                    // FIXME: We only want to consider the bookmark to be the headings "correct"
                    // bookmark in the case where it contains all of the heading's content, though
                    // excluding other bookmarks that might come before or after it.

                    // If you have the cursor inside a heading bookmark when you save the document,
                    // word puts a bookmark called _GoBack there, and we of course don't want to
                    // confuse that with the actual heading's bookmark (if any).

                    // For now as a temporary hack we just explicitly filter out _GoBack; but there
                    // needs to be a more general fix, as there may be other bookmarks that end up
                    // in the heading.

                    for (DFNode *child = concrete->first; child != NULL; child = child->next) {
                        if ((child->tag == WORD_BOOKMARK) &&
                            !DFStringEquals(DFGetAttribute(child,WORD_NAME),"_GoBack")) {
                            bookmarkElem = child;
                            bookmarkId = DFGetAttribute(bookmarkElem,WORD_ID);
                            bookmarkName = DFGetAttribute(bookmarkElem,WORD_NAME);
                            break;
                        }
                    }
                }

                if ((bookmarkElem == NULL) || (bookmarkId == NULL) || (bookmarkName == NULL)) {
                    // New bookmark
                    WordBookmark *bookmark = WordObjectsAddBookmark(put->conv->objects);
                    bookmarkId =bookmark->bookmarkId;
                    bookmarkName = bookmark->bookmarkName;
                }

                DFNode *bookmarkSpan = DFCreateElement(put->conv->package->document,HTML_SPAN);
                DFSetAttribute(bookmarkSpan,HTML_CLASS,DFBookmarkClass);

                if (bookmarkElem != NULL) {
                    // FIXME: Not covered by tests
                    DFFormatAttribute(bookmarkSpan,HTML_ID,"%s%u",put->conv->idPrefix,bookmarkElem->seqNo);
                }

                DFSetAttribute(bookmarkSpan,WORD_NAME,bookmarkName);
                DFSetAttribute(bookmarkSpan,WORD_ID,bookmarkId);

                while (targetElem->first != NULL)
                    DFAppendChild(bookmarkSpan,targetElem->first);
                DFAppendChild(targetElem,bookmarkSpan);

                break;
            }
            case HTML_TABLE:
            case HTML_FIGURE: {
                WordCaption *caption = WordObjectsCaptionForTarget(put->conv->objects,targetElem);
                if (caption == NULL)
                    break;

                assert(caption->element != NULL);
                assert((caption->number == NULL) || (caption->number->parent == caption->element));
                assert((caption->contentStart == NULL) || (caption->contentStart->parent == caption->element));

                // Note: caption.number may be null (i.e. if the caption is unnumbered)
                //       caption.contentStart may be null (if there is no text in the caption)

                WordBookmark *captionTextBookmark = NULL;
                WordBookmark *labelNumBookmark = NULL;
                WordBookmark *textBookmark = NULL;

                if (!refCaptionText && !refLabelNum && !refText)
                    refText = 1;

                if (refCaptionText) {
                    captionTextBookmark = createBookmark(put->conv);
                    DFNode *nnext;
                    for (DFNode *n = caption->contentStart; n != NULL; n = nnext) {
                        nnext = n->next;
                        DFAppendChild(captionTextBookmark->element,n);
                    }
                    DFAppendChild(caption->element,captionTextBookmark->element);
                }
                if (refLabelNum && (caption->number != NULL)) {
                    labelNumBookmark = createBookmark(put->conv);
                    DFNode *numberNext = caption->number->next;
                    DFNode *nnext;
                    for (DFNode *n = caption->element->first; (n != NULL) && (n != numberNext); n = nnext) {
                        nnext = n->next;
                        DFAppendChild(labelNumBookmark->element,n);
                    }
                    DFInsertBefore(caption->element,labelNumBookmark->element,caption->element->first);
                }
                if (refText) {
                    textBookmark = createBookmark(put->conv);
                    DFNode *nnext;
                    for (DFNode *n = caption->element->first; n != NULL; n = nnext) {
                        nnext = n->next;
                        DFAppendChild(textBookmark->element,n);
                    }
                    DFAppendChild(caption->element,textBookmark->element);
                }

                caption->captionTextBookmark = captionTextBookmark;
                caption->labelNumBookmark = labelNumBookmark;
                caption->textBookmark = textBookmark;

                break;
            }
        }
    }
    free(sortedIds);
    DFHashTableRelease(referencesById);
}