Esempio n. 1
0
/*
 * Add a namespace declaration
 */
genxStatus genxAddNamespace(genxNamespace ns, utf8 prefix)
{
  if (ns->writer->sequence != SEQUENCE_START_TAG)
    return ns->writer->status = GENX_SEQUENCE_ERROR;

  return addNamespace(ns, prefix);
}
/*Initialization and Cleanup routines*/
ProvObjectPtr newProvenanceObject(const char* id)
{
    ProvPtr p_prov = newProvenanceFactory(id);
    // add new namespace
    addNamespace(p_prov, "https://github.com/INCF/ProvenanceLibrary/wiki/terms", "ni");
    //xmlNewNs(root_node, "http://incf.org/incf-schema", "incf");
    //xmlNewNs(root_node, "http://this.namespace.needs.to/be.decided", "ni");
    return((ProvObjectPtr)p_prov);
}
Esempio n. 3
0
/*
 * Write out the attributes we've been gathering up for an element.  We save
 *  them until we've gathered them all so they can be writen in canonical
 *  order.
 * Also, we end the start-tag.
 * The trick here is that we keep the attribute list properly sorted as
 *  we build it, then as each attribute is added, we fill in its value and
 *  mark the fact that it's been added, in the "provided" field.
 */
static genxStatus writeStartTag(genxWriter w)
{
  int i;
  genxAttribute * aa = (genxAttribute *) w->attributes.pointers;
  genxElement e = w->nowStarting;

  /*
   * make sure the right namespace decls are in effect;
   *  if they are these might create an error, so ignore it
   */
  if (e->ns)
    addNamespace(e->ns, NULL);
  else
    unsetDefaultNamespace(w);
  w->status = GENX_SUCCESS;

  SendCheck(w, WIDE("<"));
  if (e->ns && (e->ns->declaration != w->xmlnsEquals))
  {
    SendCheck(w, e->ns->declaration->name + STRLEN_XMLNS_COLON);
    SendCheck(w, WIDE(":"));
  }
  SendCheck(w, e->type);

  for (i = 0; i < w->attributes.count; i++)
  {
    if (aa[i]->provided)
    {
      if (aa[i]->ns && aa[i]->ns->baroque &&
	  aa[i]->ns->declaration == w->xmlnsEquals)
	return w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE;

      SendCheck(w, WIDE(" "));

      if (aa[i]->ns)
      {
	SendCheck(w, aa[i]->ns->declaration->name + STRLEN_XMLNS_COLON)
	SendCheck(w, WIDE(":"));
      }
      SendCheck(w, aa[i]->name);
      SendCheck(w, WIDE("=\""));
      SendCheck(w, aa[i]->value.buf);
      SendCheck(w, WIDE("\""));
    }
  }
  SendCheck(w, WIDE(">"));
  return GENX_SUCCESS;
}
Esempio n. 4
0
    void ZendParser::writeFiles(const set<string> &tmpSet, int &generated) {
        generated = 0;
        File fileCopy;
        for (vector<ZendParser::File>::iterator file = results->begin();
             file != results->end(); ++file) {
//				if (file->name.compare("View.php") != 0) {
//					continue;
//				}
//		if (file->name.compare("Role.php") != 0) {
//			continue;
//		}
//				if (file->name.compare("Registry.php")) {
//					continue;
//				}
//		if (file->name.compare("Exception.php")) {
//			continue;
//		}
//		if (file->name.compare("Initializer.php")) {
//			continue;
//		}
//		if (file->name.compare("Select.php")) {
//			continue;
//		}
            fileCopy = *file;
            getReader()->createDir(outputDir + "\\" + file->rootPath);
            replaceTypesBuiltIn(fileCopy);
//		cout << fileCopy.mainType << "\n";
            if (fileCopy.mainType.length() > 0) {

                addNamespace(fileCopy);
                addUsages(fileCopy, tmpSet);
                replaceTypes(fileCopy);
            }

            replaceTypesGlobal(fileCopy);

            getReader()->writeTextFile(
                    outputDir + "\\" + fileCopy.rootPath + fileCopy.name,
                    fileCopy.content);
            generated++;
        }
    }
void QHelpSearchIndexWriter::run()
{
    mutex.lock();

    if (m_cancel) {
        mutex.unlock();
        return;
    }

    const bool reindex(this->m_reindex);
    const QLatin1String key("DefaultSearchNamespaces");
    const QString collectionFile(this->m_collectionFile);
    const QString indexPath = m_indexFilesFolder;

    mutex.unlock();

    QHelpEngineCore engine(collectionFile, 0);
    if (!engine.setupData())
        return;

    if (reindex)
        engine.setCustomValue(key, QLatin1String(""));

    const QStringList registeredDocs = engine.registeredDocumentations();
    const QStringList indexedNamespaces = engine.customValue(key).toString().
        split(QLatin1String("|"), QString::SkipEmptyParts);

    emit indexingStarted();

    QStringList namespaces;
    Writer writer(indexPath);
    foreach(const QString &namespaceName, registeredDocs) {
        mutex.lock();
        if (m_cancel) {
            mutex.unlock();
            return;
        }
        mutex.unlock();

        // if indexed, continue
        namespaces.append(namespaceName);
        if (indexedNamespaces.contains(namespaceName))
            continue;

        const QList<QStringList> attributeSets =
            engine.filterAttributeSets(namespaceName);

        foreach (const QStringList &attributes, attributeSets) {
            // cleanup maybe old or unfinished files
            writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@")));
            writer.removeIndex();

            QSet<QString> documentsSet;
            const QList<QUrl> docFiles = engine.files(namespaceName, attributes);
            foreach(QUrl url, docFiles) {
                if (m_cancel)
                    return;

                // get rid of duplicated files
                if (url.hasFragment())
                    url.setFragment(QString());

                QString s = url.toString();
                if (s.endsWith(QLatin1String(".html"))
                    || s.endsWith(QLatin1String(".htm"))
                    || s.endsWith(QLatin1String(".txt")))
                    documentsSet.insert(s);
            }

            int docNum = 0;
            const QStringList documentsList(documentsSet.toList());
            foreach(const QString &url, documentsList) {
                if (m_cancel)
                    return;

                QByteArray data(engine.fileData(url));
                if (data.isEmpty())
                    continue;

                QTextStream s(data);
                QString en = QHelpGlobal::codecFromData(data);
                s.setCodec(QTextCodec::codecForName(en.toLatin1().constData()));

                QString text = s.readAll();
                if (text.isNull())
                    continue;

                QString title = QHelpGlobal::documentTitle(text);

                int j = 0;
                int i = 0;
                bool valid = true;
                const QChar *buf = text.unicode();
                QChar str[64];
                QChar c = buf[0];

                while ( j < text.length() ) {
                    if (m_cancel)
                        return;

                    if ( c == QLatin1Char('<') || c == QLatin1Char('&') ) {
                        valid = false;
                        if ( i > 1 )
                            writer.insertInIndex(QString(str,i), docNum);
                        i = 0;
                        c = buf[++j];
                        continue;
                    }
                    if ( ( c == QLatin1Char('>') || c == QLatin1Char(';') ) && !valid ) {
                        valid = true;
                        c = buf[++j];
                        continue;
                    }
                    if ( !valid ) {
                        c = buf[++j];
                        continue;
                    }
                    if ( ( c.isLetterOrNumber() || c == QLatin1Char('_') ) && i < 63 ) {
                        str[i] = c.toLower();
                        ++i;
                    } else {
                        if ( i > 1 )
                            writer.insertInIndex(QString(str,i), docNum);
                        i = 0;
                    }
                    c = buf[++j];
                }
                if ( i > 1 )
                    writer.insertInIndex(QString(str,i), docNum);

                docNum++;
                writer.insertInDocumentList(title, url);
            }

            if (writer.writeIndex()) {
                engine.setCustomValue(key, addNamespace(
                    engine.customValue(key).toString(), namespaceName));
            }

            writer.reset();
        }
Esempio n. 6
0
/* A simple example on using the provenance library
*/
int
main(int argc, char **argv, char** envp)
{
    ProvPtr p_prov = newProvenanceFactory("1");
    RecordPtr p_record = p_prov->p_record;
    IDREF id, act_id, used_id, genby_id;
    char arg[50];
    int i;

    addNamespace(p_prov, "https://github.com/INCF/ProvenanceLibrary/wiki/terms", "ni");

    // Add program information
    act_id = newActivity(p_record, NULL, "11/30/11 00:13:20.650432 EST", "11/30/11 00:13:20.650550 EST");
    addAttribute(p_record, act_id, "prov", "xsd:string", "type", "program");
    addAttribute(p_record, act_id, "ni", NULL, "name", argv[0]);
    addAttribute(p_record, act_id, "ni", NULL, "version", version);
    char * cmdline = get_cmdline(argc, argv);
    addAttribute(p_record, act_id, "ni", NULL, "cmdline", cmdline);
    free(cmdline);

    //Add all input parameters. if you use getopt this can be refined further
    for(i=1;i<argc; i++){
        id = newEntity(p_record);
	addAttribute(p_record, id, "prov", "xsd:string", "type", "input");
        sprintf(arg, "arg%d", i);
	addAttribute(p_record, id, NULL, NULL, arg, argv[i]);
	used_id = newUsedRecord(p_record, act_id, id, NULL);
	freeID(used_id);
	freeID(id);
    }

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "environment");
    // add all environment variables
    char** env;
    for (env = envp; *env != 0; env++)
    {
       char* thisEnv = *env;
       char *name;
       char* p_index = thisEnv;
       int pos = 0;
       while (thisEnv[pos++] != '=');
       name = strndup(thisEnv, pos-1);
       if (name[0] != '_')
	   addAttribute(p_record, id, "ni", "xsd:string", name, &thisEnv[pos]);
       free(name);
    }
    freeID(id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "runtime");
    // add runtime info such as walltime, cputime, host,
    freeID(id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "output:file");
    addAttribute(p_record, id, "ni", NULL, "warped_file", "/full/path/to/file");
    genby_id = newGeneratedByRecord(p_record, id, act_id, NULL);
    freeID(id);
    freeID(genby_id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "output:stat");
    addAttribute(p_record, id, "ni", NULL, "pearson_correlation_coefficient", ".234");
    genby_id = newGeneratedByRecord(p_record, id, act_id, NULL);
    freeID(id);
    freeID(genby_id);
    freeID(act_id);

    /* Test i/o manipulations */
    char *buffer;
    int bufsize;
    //print_provenance(p_prov, NULL);
    //fprintf(stdout, "==============\n");
    print_provenance(p_prov, "testprov.xml");
    dumpToMemoryBuffer(p_prov, &buffer, &bufsize);
    delProvenanceFactory(p_prov);
    p_prov = newProvenanceFactoryFromMemoryBuffer(buffer, bufsize);
    freeMemoryBuffer(buffer);
    delProvenanceFactory(p_prov);
    p_prov = newProvenanceFactoryFromFile("testprov.xml");
    ProvPtr p_prov2 = newProvenanceFactory("1");
    addProvAsAccount(p_prov2->p_record, p_prov, NULL);
    print_provenance(p_prov2, NULL);
    print_provenance(p_prov2, "testprov2.xml");
    delProvenanceFactory(p_prov);
    delProvenanceFactory(p_prov2);
    return(0);
}
Esempio n. 7
0
/*
 * Private attribute-adding code
 * most of the work here is normalizing the value, which is the same
 *  as regular normalization except for " is replaced by "&quot;"
 */
static genxStatus addAttribute(genxAttribute a, constUtf8 valuestr)
{
  utf8 lastv = (utf8) valuestr;
  genxWriter w = a->writer;

  /* if valuestr not provided, this is an xmlns with a pre-cooked value */
  if (valuestr)
  {
    startCollect(&a->value);
    while (*valuestr)
    {
      int c = genxNextUnicodeChar(&valuestr);
      
      if (c == -1)
	return w->status = GENX_BAD_UTF8;
      
      if (!isXMLChar(w, c))
	return w->status = GENX_NON_XML_CHARACTER;
      
      switch(c)
      {
      case 9:
	collectPiece(w, &a->value, "&#x9;", 5);
	break;
      case 0xa:
	collectPiece(w, &a->value, "&#xA;", 5); 
	break;
      case 0xd:
	collectPiece(w, &a->value, "&#xD;", 5); 
	break;
      case '"':
	collectPiece(w, &a->value, "&quot;", 6);
	break;
      case '<':
	collectPiece(w, &a->value, "&lt;", 4);
	break;
      case '&':
	collectPiece(w, &a->value, "&amp;", 5);
	break;
	/*
      case '>':
	collectPiece(w, &a->value, "&gt;", 4);
	break;
	*/
      default:
	collectPiece(w, &a->value, (const char *) lastv, valuestr - lastv);
	break;
      }
      lastv = (utf8) valuestr;
    }
    endCollect(&a->value);
  }

  /* now add the namespace attribute; might fail if it's bee hand-declared */
  if (a->ns)
    addNamespace(a->ns, NULL);

  if (valuestr && a->provided)
    return w->status = GENX_DUPLICATE_ATTRIBUTE;
  a->provided = 1;

  return GENX_SUCCESS;
}