Exemplo n.º 1
0
void recursive_print(const KArchiveDirectory *dir, const QString &path)
{
    const QStringList l = dir->entries();
    QStringList::const_iterator it = l.constBegin();
    for (; it != l.end(); ++it)
    {
        const KArchiveEntry* entry = dir->entry((*it));
        printf("mode=%07o %s %s size: %lld pos: %lld %s%s isdir=%d%s",
               entry->permissions(),
               entry->user().toLatin1().constData(),
               entry->group().toLatin1().constData(),
               entry->isDirectory() ? 0 : ((KArchiveFile*)entry)->size(),
               entry->isDirectory() ? 0 : ((KArchiveFile*)entry)->position(),
               path.toLatin1().constData(),
               (*it).toLatin1().constData(), entry->isDirectory(),
               entry->symLinkTarget().isEmpty() ? "" :
               QString(" symlink: %1").arg(
                   entry->symLinkTarget()).toLatin1().constData());

        //if (!entry->isDirectory()) printf("%d",
        //     ((KArchiveFile*)entry)->size());
        printf("\n");
        if (entry->isDirectory())
            recursive_print((KArchiveDirectory *)entry, path+(*it)+'/');
    }
}
Exemplo n.º 2
0
int main( int argc, char** argv )
{
    if (argc != 2)
    {
        printf("\n"
               " Usage :\n"
               " ./k7ziptest /path/to/existing_file.7z       tests listing an existing .7z\n" );
        return 1;
    }

    K7Zip k7z( argv[1] );

    if ( !k7z.open( QIODevice::ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[1] );
      return 1;
    }

    const KArchiveDirectory* dir = k7z.directory();

    //printf("calling recursive_print\n");
    recursive_print( dir, "" );
    //printf("recursive_print called\n");

    k7z.close();

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    if (argc != 2) {
        printf("\n"
               " Usage :\n"
               " ./ktartest /path/to/existing_file.tar.gz       tests listing an existing tar.gz\n");
        return 1;
    }

    KRcc rcc(argv[1]);

    if (!rcc.open(QIODevice::ReadOnly)) {
        printf("Could not open %s for reading\n", argv[1]);
        return 1;
    }

    const KArchiveDirectory *dir = rcc.directory();

    //printf("calling recursive_print\n");
    recursive_print(dir, "");
    //printf("recursive_print called\n");

    rcc.close();

    return 0;
}
Exemplo n.º 4
0
void recursive_print( const KArchiveDirectory * dir, const QString & path )
{
  QStringList l = dir->entries();
  l.sort();
  QStringList::ConstIterator it = l.constBegin();
  for( ; it != l.constEnd(); ++it )
  {
    const KArchiveEntry* entry = dir->entry( (*it) );
    printf("mode=%07o %s %s %s %s%s %lld isdir=%d\n", entry->permissions(), entry->datetime().toString("yyyy-MM-dd hh:mm:ss").toLatin1().constData(),
            entry->user().toLatin1().constData(), entry->group().toLatin1().constData(), path.toLatin1().constData(), (*it).toLatin1().constData(),
            entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0,
            entry->isDirectory());
    if (!entry->symLinkTarget().isEmpty()) {
        printf("  (symlink to %s)\n",qPrintable(entry->symLinkTarget()));
    }
    if (entry->isDirectory())
      recursive_print( (KArchiveDirectory *)entry, path+(*it)+'/' );
    if (entry->isFile()) {
        const KArchiveFile* f = static_cast<const KArchiveFile*>( entry );
        QByteArray arr( f->data() );
        qDebug() << "data" << arr;

        QIODevice *dev = f->createDevice();
        QByteArray contents = dev->readAll();
        qDebug() << "contents" << contents;
        delete dev;
    }
  }
}
Exemplo n.º 5
0
static bool expand_variable(std::ostream& out, std::string name,
      const RuleTable& rules, std::size_t indent,
      BindingsPtr bindings, BindingsPtr local_bindings,
      Context& context) {
   if (name.size() > 0 && local_bindings->defined(name)) {
      NodePtr node = local_bindings->get(name)->get_node();
      return recursive_print(out, node, rules, bindings, indent, context);
   } else {
      return false;
   }
}
Exemplo n.º 6
0
void recursive_print( const KTarDirectory * dir, const QString & path )
{
  QStringList l = dir->entries();
  QStringList::Iterator it = l.begin();
  for( ; it != l.end(); ++it )
  {
    const KTarEntry* entry = dir->entry( (*it) );
    printf("mode=%07o %s %s %s%s\n", entry->permissions(), entry->user().latin1(), entry->group().latin1(), path.latin1(), (*it).latin1());
    if (entry->isDirectory())
      recursive_print( (KTarDirectory *)entry, path+(*it)+"/" );
  }
}
Exemplo n.º 7
0
static int doList(const QString &fileName)
{
    KZip zip(fileName);
    if (!zip.open(QIODevice::ReadOnly)) {
        qWarning() << "Could not open" << fileName << "for reading. ZIP file doesn't exist or is invalid.";
        return 1;
    }
    const KArchiveDirectory *dir = zip.directory();
    recursive_print(dir, QString());
    zip.close();
    return 0;
}
Exemplo n.º 8
0
int main(){

    // In production code, of course, we won't hardcode this
    struct Link * link = load("data.txt");

    printf("Print as ordered by genome A\n");
    recursive_print(link, 0);

    printf("\nPrint as ordered by genome B\n");
    recursive_print(link, 1);

    printf("\nLowest position on genome A\n");
    print_link(get_minimum(link, 0));

    printf("\nLowest position on genome B\n");
    print_link(get_minimum(link, 1));

    printf("\nAll links with scores above 50\n");
    recursive_print(winnow(link, 50), 0);

    return EXIT_SUCCESS;
}
Exemplo n.º 9
0
void recursive_print( const KTarDirectory * dir, const TQString & path )
{
  TQStringList l = dir->entries();
  TQStringList::Iterator it = l.begin();
  for( ; it != l.end(); ++it )
  {
    const KTarEntry* entry = dir->entry( (*it) );
    printf("mode=%07o %s %s %s%s %d isdir=%d\n", entry->permissions(), entry->user().latin1(), entry->group().latin1(), path.latin1(), (*it).latin1(),
           entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0,
           entry->isDirectory());
    if (entry->isDirectory())
      recursive_print( (KTarDirectory *)entry, path+(*it)+"/" );
  }
}
Exemplo n.º 10
0
void recursive_print(const KArchiveDirectory *dir, const QString &path)
{
    QStringList l = dir->entries();
    l.sort();
    QStringList::ConstIterator it = l.constBegin();
    for (; it != l.constEnd(); ++it) {
        const KArchiveEntry *entry = dir->entry((*it));
        printf("mode=%07o %s %s %s%s %lld isdir=%d\n", entry->permissions(), entry->user().toLatin1().constData(), entry->group().toLatin1().constData(), path.toLatin1().constData(), (*it).toLatin1().constData(),
               entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0,
               entry->isDirectory());
        if (!entry->symLinkTarget().isEmpty()) {
            printf("  (symlink to %s)\n", qPrintable(entry->symLinkTarget()));
        }
        if (entry->isDirectory()) {
            recursive_print((KArchiveDirectory *)entry, path + (*it) + '/');
        }
    }
}
Exemplo n.º 11
0
void recursive_print(const KArchiveDirectory *dir, const QString &path)
{
    foreach (const QString &it, dir->entries()) {
        const KArchiveEntry *entry = dir->entry(it);
        printf("mode=%07o %s %s \"%s%s\" size: %lld pos: %lld isdir=%d%s", entry->permissions(),
               entry->user().toLatin1().constData(), entry->group().toLatin1().constData(),
               path.toLatin1().constData(), it.toLatin1().constData(),
               entry->isDirectory() ? 0 : (static_cast<const KArchiveFile *>(entry))->size(),
               entry->isDirectory() ? 0 : (static_cast<const KArchiveFile *>(entry))->position(),
               entry->isDirectory(),
               entry->symLinkTarget().isEmpty() ? "" : QStringLiteral(" symlink: %1").arg(entry->symLinkTarget()).toLatin1().constData());

        //    if (!entry->isDirectory()) printf("%d", (static_cast<const KArchiveFile *>(entry))->size());
        printf("\n");
        if (entry->isDirectory()) {
            recursive_print(static_cast<const KArchiveDirectory *>(entry), path + it + '/');
        }
    }
}
Exemplo n.º 12
0
Arquivo: cache.c Projeto: nshi/falcon
static void recursive_print(const trie_node_t *node, guint l)
{
	guint i = 0;
	guint len = 0;

	while (node) {
		printf("%s", trie_key(node) ? trie_key(node) : "ROOT");
		if (trie_child(node)) {
			if (trie_key(node))
				len = strlen(trie_key(node)) + 2;
			printf("->");
			recursive_print(trie_child(node), l + len);
		}
		if (trie_next(node))
			printf("\n");
		for (i = 0; i < l; i++)
			printf(" ");
		node = trie_next(node);
	}
}
Exemplo n.º 13
0
void recursive_print( const KArchiveDirectory * dir, const TQString & path )
{
  TQStringList l = dir->entries();
  TQStringList::Iterator it = l.begin();
  for( ; it != l.end(); ++it )
  {
    const KArchiveEntry* entry = dir->entry( (*it) );
    printf("mode=%07o %s %s size: %d pos: %d %s%s isdir=%d%s", entry->permissions(),
	entry->user().latin1(), entry->group().latin1(),
	entry->isDirectory() ? 0 : ((KArchiveFile*)entry)->size(),
	entry->isDirectory() ? 0 : ((KArchiveFile*)entry)->position(),
	path.latin1(), (*it).latin1(), entry->isDirectory(),
	!entry->symlink() ? "" : TQString(" symlink: %1").arg(entry->symlink()).latin1() );

//    if (!entry->isDirectory()) printf("%d", ((KArchiveFile*)entry)->size());
    printf("\n");
    if (entry->isDirectory())
      recursive_print( (KArchiveDirectory *)entry, path+(*it)+"/" );
  }
}
Exemplo n.º 14
0
void	recursive_print(int nbr, char *base, int iter_c)
{
	int		numeric_base;
	long	n;

	if (!check_valid_base(base))
		return ;
	numeric_base = ft_strlen(base);
	n = nbr;
	if (n == 0)
	{
		if (iter_c == 0)
			ft_putchar(base[0]);
		return ;
	}
	if (n < 0)
	{
		ft_putchar('-');
		n = -n;
	}
	recursive_print(n / numeric_base, base, iter_c + 1);
	ft_putchar(base[n % numeric_base]);
}
Exemplo n.º 15
0
int main( int argc, char** argv )
{
  if (argc < 3)
  {
    printf("\n"
 " Usage :\n"
 " ./kziptest list /path/to/existing_file.zip       tests listing an existing zip\n"
 " ./kziptest readwrite newfile.zip                 will create the zip, then close and reopen it.\n"
 " ./kziptest maxlength newfile.zip                 tests the maximum filename length allowed.\n"
 " ./kziptest print file.zip                        prints contents of all files.\n"
 " ./kziptest print2 file.zip filename              prints contents of one file.\n"
 " ./kziptest update file.zip filename              updates contents of one file.\n"
 " ./kziptest transfer file.zip newfile.zip         complete transfer.\n"
 " ./kziptest iodevice /path/to/existing_file.zip   tests KArchiveFile::device()\n");
    return 1;
  }
  TDEInstance instance("kziptest");
  TQString command = argv[1];
  if ( command == "list" )
  {
    KZip zip( argv[2] );

    if ( !zip.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }

    const KArchiveDirectory* dir = zip.directory();

    //printf("calling recursive_print\n");
    recursive_print( dir, "" );
    //printf("recursive_print called\n");

    zip.close();

    return 0;
  }
  else if (command == "readwrite" )
  {
    KZip zip( argv[2] );

    if ( !zip.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[2]);
      return 1;
    }

    zip.setCompression( KZip::NoCompression );
    zip.writeFile( "typeid", "", "", 19, "application/x-kword" );
    zip.setCompression( KZip::DeflateCompression );
    zip.writeFile( "empty", "weis", "users", 0, "" );
    zip.writeFile( "test1", "weis", "users", 5, "Hallo" );
    zip.writeFile( "test2", "weis", "users", 8, "Hallo Du" );
    zip.writeFile( "mydir/test3", "weis", "users", 13, "Noch so einer" );
    zip.writeFile( "my/dir/test3", "dfaure", "hackers", 29, "I don't speak German (David)" );
    zip.writeSymLink( "a_link", "mydir/test3", "leo", "leo", 0120777,
    		1000000000l, 1000000000l, 1000000000l);

#define SIZE1 100
    // Now a medium file : 100 null bytes
    char medium[ SIZE1 ];
    memset( medium, 0, SIZE1 );
    zip.writeFile( "mediumfile", "user", "group", SIZE1, medium );
    // Another one, with an absolute path
    zip.writeFile( "/dir/subdir/mediumfile2", "user", "group", SIZE1, medium );

    // Now a huge file : 20000 null bytes
    int n = 20000;
    char * huge = new char[ n ];
    memset( huge, 0, n );
    zip.writeFile( "hugefile", "user", "group", n, huge );
    delete [] huge;

    // Now a file from the harddisk
    zip.addLocalFile( ".libs/lt-kziptest", "lt-kziptest" );

    printf( "calling close\n" );

    zip.close();

    printf("-----------------------\n");

    if ( !zip.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }

    const KArchiveDirectory* dir = zip.directory();
    recursive_print(dir, "");

    const KArchiveEntry* e = dir->entry( "mydir/test3" );
    Q_ASSERT( e && e->isFile() );
    const KArchiveFile* f = (KArchiveFile*)e;

    TQByteArray arr( f->data() );
    Q_ASSERT( arr.size() == 13 );
    printf("SIZE=%i\n",arr.size() );
    TQString str( arr );
    Q_ASSERT( str == "Noch so einer" );
    printf("DATA=%s\n", str.latin1());

    e = dir->entry( "mediumfile" );
    Q_ASSERT( e && e->isFile() );
    f = (KArchiveFile*)e;
    Q_ASSERT( f->data().size() == SIZE1 );

    e = dir->entry( "hugefile" );
    Q_ASSERT( e && e->isFile() );
    f = (KArchiveFile*)e;
    Q_ASSERT( f->data().size() == 20000 );

    zip.close();

    return 0;
  }
  else if ( command == "maxlength" )
  {
    KZip zip( argv[2] );

    if ( !zip.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[2]);
      return 1;
    }
    // Generate long filenames of each possible length bigger than 98...
    for (int i = 98; i < 500 ; i++ )
    {
      TQString str, num;
      str.fill( 'a', i-10 );
      num.setNum( i );
      num = num.rightJustify( 10, '0' );
      zip.writeFile( str+num, "testu", "testg", 3, "hum" );
    }
    // Result of this test : it fails at 482 (instead of 154 previously).
    // Ok, I think we can do with that :)
    zip.close();
    printf("Now run 'unzip -l %s'\n", argv[2]);
    return 0;
  }
  else if ( command == "iodevice" )
  {
    KZip zip( argv[2] );
    if ( !zip.open( IO_ReadOnly ) )
      return 1;
    const KArchiveDirectory* dir = zip.directory();
    assert(dir);
    const KArchiveEntry* entry = dir->entry( "my/dir/test3" );
    if ( entry && entry->isFile() )
    {
        TQIODevice *dev = static_cast<const KZipFileEntry *>(entry)->device();
        if ( dev ) {
            TQByteArray contents = dev->readAll();
            printf("contents='%s'\n", TQCString(contents, contents.size()+1).data());
        }
    } else
        printf("entry=%p - not found if 0, otherwise not a file\n", (void*)entry);
    return 0;
  }
  else if (command == "print" )
  {
    KZip zip( argv[2] );
    kdDebug() << "Opening zip file" << endl;
    if ( !zip.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }
    const KArchiveDirectory* dir = zip.directory();
    kdDebug() << "Listing toplevel of zip file" << endl;
    TQStringList l = dir->entries();
    TQStringList::Iterator it = l.begin();
    for( ; it != l.end(); ++it )
    {
        const KArchiveEntry* e = dir->entry( (*it) );
	kdDebug() << "Printing " << (*it) << endl;
	if (e->isFile())
	{
    	    Q_ASSERT( e && e->isFile() );
    	    const KArchiveFile* f = (KArchiveFile*)e;

    	    TQByteArray arr( f->data() );
    	    printf("SIZE=%i\n",arr.size() );
    	    TQString str( arr );
    	    printf("DATA=%s\n", str.latin1());
	}
    }
    zip.close();
    return 0;
  }
  else if (command == "print2" )
  {
    if (argc != 4)
    {
        printf("usage: kziptest print2 archivename filename");
	return 1;
    }
    KZip zip( argv[2] );
    if ( !zip.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }
    const KArchiveDirectory* dir = zip.directory();
    const KArchiveEntry* e = dir->entry( argv[3] );
    Q_ASSERT( e && e->isFile() );
    const KArchiveFile* f = (KArchiveFile*)e;

    TQByteArray arr( f->data() );
    printf("SIZE=%i\n",arr.size() );
    TQString str( arr );
//    printf("DATA=%s\n", str.latin1());
    printf("%s", str.latin1());
    zip.close();

    return 0;

  }
  else if (command == "update" )
  {
    if (argc != 4)
    {
        printf("usage: kziptest update archivename filename");
       return 1;
    }
    KZip zip( argv[2] );
    if ( !zip.open( IO_ReadWrite ) )
    {
      printf("Could not open %s for read/write\n", argv[2] );
      return 1;
    }
    const KArchiveEntry* e = zip.directory()->entry( argv[3] );
//    Q_ASSERT( e && e->isFile() );
//    const KArchiveFile* f = (KArchiveFile*)e;

//    TQCString data( "This is some new data that goes into " );
  //  data += argv[3];
    TQFile f ( argv[3] );
    if (!f.open( IO_ReadOnly )) 
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }
    	
    TQDataStream s( &f );
    
    
//    zip.writeFile( argv[3], "", "", data.size(), data.data() );
    zip.writeFile( argv[3], "", "", f.size(), f.readAll() );
    zip.close();

    return 0;

  }
  else if (command == "transfer" )
  {
    if (argc != 4)
    {
        printf("usage: kziptest transfer sourcefile destfile");
	return 1;
    }
    KZip zip1( argv[2] );
    KZip zip2( argv[3] );
    if ( !zip1.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }
    if ( !zip2.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[3] );
      return 1;
    }
    const KArchiveDirectory* dir1 = zip1.directory();

    recursive_transfer(dir1, "", &zip2 );

    zip1.close();
    zip2.close();

/*
    zip.writeFile( "empty", "weis", "users", 0, "" );
    zip.writeFile( "test1", "weis", "users", 5, "Hallo" );
    zip.writeFile( "test2", "weis", "users", 8, "Hallo Du" );
    zip.writeFile( "mydir/test3", "weis", "users", 13, "Noch so einer" );
    zip.writeFile( "my/dir/test3", "dfaure", "hackers", 29, "I don't speak German (David)" );

#define SIZE1 100
    // Now a medium file : 100 null bytes
    char medium[ SIZE1 ];
    memset( medium, 0, SIZE1 );
    zip.writeFile( "mediumfile", "user", "group", SIZE1, medium );
    // Another one, with an absolute path
    zip.writeFile( "/dir/subdir/mediumfile2", "user", "group", SIZE1, medium );

    // Now a huge file : 20000 null bytes
    int n = 20000;
    char * huge = new char[ n ];
    memset( huge, 0, n );
    zip.writeFile( "hugefile", "user", "group", n, huge );
    delete [] huge;

    zip.close();

    printf("-----------------------\n");

    if ( !zip.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }

    const KArchiveDirectory* dir = zip.directory();
    recursive_print(dir, "");

    const KArchiveEntry* e = dir->entry( "mydir/test3" );
    Q_ASSERT( e && e->isFile() );
    const KArchiveFile* f = (KArchiveFile*)e;

    TQByteArray arr( f->data() );
    printf("SIZE=%i\n",arr.size() );
    TQString str( arr );
    printf("DATA=%s\n", str.latin1());

    zip.close();

    return 0;





    const KArchiveEntry* e = dir1->entry( argv[3] );
    Q_ASSERT( e && e->isFile() );
    const KArchiveFile* f = (KArchiveFile*)e;

    TQByteArray arr( f->data() );
//    printf("SIZE=%i\n",arr.size() );
    TQString str( arr );
//    printf("DATA=%s\n", str.latin1());
    printf("%s", str.latin1());
    zip.close();

*/
    return 0;

  }
  else
    printf("Unknown command\n");
}
Exemplo n.º 16
0
int main( int argc, char** argv )
{
  if (argc < 3)
  {
    usage();
    return 1;
  }
  KInstance instance("ktartest");

  QString command = argv[1];
  kdDebug() << "main: command=" << command << endl;
  if ( command == "list" )
  {
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[1] );
      return 1;
    }

    const KTarDirectory* dir = tar.directory();

    //printf("calling recursive_print\n");
    recursive_print( dir, "" );
    //printf("recursive_print called\n");

    tar.close();

    return 0;
  }
  else if ( command == "get" )
  {
    if ( argc != 4 )
    {
        usage();
        return 1;
    }

    KTarGz tar( argv[2] );

    if ( !tar.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[1] );
      return 1;
    }

    const KTarDirectory* dir = tar.directory();

    const KTarEntry* e = dir->entry( argv[3] );
    Q_ASSERT( e && e->isFile() );
    const KTarFile* f = (KTarFile*)e;

    QByteArray arr( f->data() );
    printf("SIZE=%i\n",arr.size() );
    QString str( arr );
    printf("DATA=%s\n", str.latin1());

    /*
    // This is what KGzipDev::readAll could do, if QIODevice::readAll was virtual....
    QByteArray array(1024);
    int n;
    while ( ( n = dev.readBlock( array.data(), array.size() ) ) )
    {
        kdDebug() << "readBlock returned " << n << endl << endl;
        QCString s(array,n+1); // Terminate with 0 before printing
        printf("%s", s.data());
    }
    dev.close();
    */


    tar.close();
  }
  else if (command == "readwrite" )
  {
    kdDebug() << " --- readwrite --- " << endl;
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[1]);
      return 1;
    }

    tar.writeFile( "empty", "weis", "users", 0, "" );
    tar.writeFile( "test1", "weis", "users", 5, "Hallo" );
    tar.writeFile( "test2", "weis", "users", 8, "Hallo Du" );
    tar.writeFile( "mydir/test3", "weis", "users", 13, "Noch so einer" );
    tar.writeFile( "my/dir/test3", "dfaure", "hackers", 29, "I don't speak German (David)" );

#define SIZE1 100
    // Now a medium file : 100 null bytes
    char medium[ SIZE1 ];
    memset( medium, 0, SIZE1 );
    tar.writeFile( "mediumfile", "user", "group", SIZE1, medium );
    // Another one, with an absolute path
    tar.writeFile( "/dir/subdir/mediumfile2", "user", "group", SIZE1, medium );

    // Now a huge file : 20000 null bytes
    int n = 20000;
    char * huge = new char[ n ];
    memset( huge, 0, n );
    tar.writeFile( "hugefile", "user", "group", n, huge );
    delete [] huge;

    tar.close();

    printf("-----------------------\n");

    if ( !tar.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[1] );
      return 1;
    }

    const KTarDirectory* dir = tar.directory();
    recursive_print(dir, "");

    const KTarEntry* e = dir->entry( "mydir/test3" );
    Q_ASSERT( e && e->isFile() );
    const KTarFile* f = (KTarFile*)e;

    QByteArray arr( f->data() );
    printf("SIZE=%i\n",arr.size() );
    QString str( arr );
    printf("DATA=%s\n", str.latin1());

    tar.close();

    return 0;
  }
  else if ( command == "maxlength" )
  {
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[1]);
      return 1;
    }
    // Generate long filenames of each possible length bigger than 98...
    for (int i = 98; i < 500 ; i++ )
    {
      QString str, num;
      str.fill( 'a', i-10 );
      num.setNum( i );
      num = num.rightJustify( 10, '0' );
      tar.writeFile( str+num, "testu", "testg", 3, "hum" );
    }
    // Result of this test : it fails at 482 (instead of 154 previously).
    // Ok, I think we can do with that :)
    tar.close();
    printf("Now run 'tar tvzf %s'\n", argv[2]);
    return 0;
  }
  else if ( command == "bytearray" )
  {
    QFile file( argv[2] );
    if ( !file.open( IO_ReadOnly ) )
      return 1;
    KTarGz tar( &file );
    tar.open( IO_ReadOnly );
    const KTarDirectory* dir = tar.directory();
    recursive_print( dir, "" );
    return 0;
  }
  else
    printf("Unknown command\n");
}
Exemplo n.º 17
0
static bool recursive_print(std::ostream& out, const NodePtr root,
	 const RuleTable& rules, BindingsPtr bindings,
	 std::size_t indent,
	 Context& context) {
   if (root->is_leaf()) {
      return !!(out << root->get_token().get_literal());
   } else {
      Arity arity(root->size());
      Operator op = root->get_op();
      BindingsPtr local_bindings;
      RuleTable::print_iterator it, end;
      int found = 0;
      for (it = rules.reversed_find(op, arity, end); it != end; ++it) {
	 ++found;
	 local_bindings = std::make_shared<Bindings>(bindings);
	 if (matches(root, it->second->get_tree_expression(),
	       local_bindings, context)) break;
      }
      if (it == end) {
	 // try wildcard rules
	 for (it = rules.reversed_find(op, Arity(), end);
	       it != end; ++it) {
	    ++found;
	    local_bindings = std::make_shared<Bindings>(bindings);
	    if (matches(root, it->second->get_tree_expression(),
		  local_bindings, context)) break;
	 }
	 if (it == end) {
	    std::ostringstream os;
	    if (found > 0) {
	       os << "no matching ";
	    } else {
	       os << "no ";
	    }
	    os << "rule found for '" << op.get_name() << "' with " <<
	       root->size() << " parameters";
	    throw Exception(root->get_location(), os.str());
	 }
      }
      context.descend(root);
      const NodePtr& node = it->second->get_rhs();
      std::size_t add_indent = 0;
      for (std::size_t pi = 0; pi < node->size(); ++pi) {
	 const NodePtr& subnode = node->get_operand(pi);
	 if (subnode->is_leaf()) {
	    Token t = subnode->get_token();
	    switch (t.get_tokenval()) {
	       case parser::token::TEXT_LITERAL: {
		     expand_text(out, t, indent);
		     int new_indent = get_indent(t.get_text());
		     if (new_indent >= 0) add_indent = new_indent;
		     break;
		  }
	       case parser::token::VARIABLE:
		  if (!expand_variable(out, t.get_text(), rules,
			indent + add_indent,
			bindings, local_bindings, context)) {
		     std::ostringstream os;
		     os << "undefined variable in replacement text: " <<
			t.get_text();
		     throw Exception(subnode->get_location(), os.str());
		  }
		  break;
	       default:
		  assert(false); std::abort();
	    }
	 } else if (subnode->get_op() == Op::print_expression_listvar) {
	    std::string varname =
	       subnode->get_operand(0)->get_token().get_text();
	    if (!local_bindings->defined(varname)) {
	       std::ostringstream os;
	       os << "undefined variable in replacement list: " <<
		  varname;
	       throw Exception(subnode->get_location(), os.str());
	    }
	    AttributePtr list = local_bindings->get(varname);
	    if (list->get_type() != Attribute::list) {
	       std::ostringstream os;
	       os << "list expected: " << varname;
	       throw Exception(subnode->get_location(), os.str());
	    }
	    if (list->size() > 0) {
	       recursive_print(out, list->get_value(0)->get_node(),
		  rules, bindings, indent + add_indent, context);
	    }
	    for (std::size_t i = 1; i < list->size(); ++i) {
	       if (subnode->size() == 2) {
		  Token t = subnode->get_operand(1)->get_token();
		  expand_text(out, t, indent);
		  int new_indent = get_indent(t.get_text());
		  if (new_indent >= 0) add_indent = new_indent;
	       }
	       recursive_print(out, list->get_value(i)->get_node(),
		  rules, bindings, indent + add_indent, context);
	    }
	 } else {
	    assert(subnode->get_op() == Op::expression);
	    Expression expr(subnode, local_bindings);
	    if (!recursive_print(out, expr.convert_to_node(),
		  rules, bindings, indent, context)) {
	       return false;
	    }
	 }
      }
   }
   context.ascend();
   return true;
}
Exemplo n.º 18
0
int main( int argc, char** argv )
{
  if (argc != 3)
  {
    printf("\n"
 " Usage :\n"
 " ./ktartest list /path/to/existing_file.tar.gz       tests listing an existing tar.gz\n"
 " ./ktartest readwrite newfile.tar.gz                 will create the tar.gz, then close and reopen it.\n"
 " ./ktartest maxlength newfile.tar.gz                 tests the maximum filename length allowed.\n"
 " ./ktartest iodevice /path/to/existing_file.tar.gz   tests KArchiveFile::device()\n");
    return 1;
  }
  TDEInstance instance("ktartest");
  TQString command = argv[1];
  if ( command == "list" )
  {
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[2] );
      return 1;
    }

    const KTarDirectory* dir = tar.directory();

    //printf("calling recursive_print\n");
    recursive_print( dir, "" );
    //printf("recursive_print called\n");

    tar.close();

    return 0;
  }
  else if (command == "readwrite" )
  {
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[1]);
      return 1;
    }

    tar.writeFile( "empty", "weis", "users", 0, "" );
    tar.writeFile( "test1", "weis", "users", 5, "Hallo" );
    tar.writeFile( "test2", "weis", "users", 8, "Hallo Du" );
    tar.writeFile( "mydir/test3", "weis", "users", 13, "Noch so einer" );
    tar.writeFile( "my/dir/test3", "dfaure", "hackers", 29, "I don't speak German (David)" );

#define SIZE1 100
    // Now a medium file : 100 null bytes
    char medium[ SIZE1 ];
    memset( medium, 0, SIZE1 );
    tar.writeFile( "mediumfile", "user", "group", SIZE1, medium );
    // Another one, with an absolute path
    tar.writeFile( "/dir/subdir/mediumfile2", "user", "group", SIZE1, medium );

    // Now a huge file : 20000 null bytes
    int n = 20000;
    char * huge = new char[ n ];
    memset( huge, 0, n );
    tar.writeFile( "hugefile", "user", "group", n, huge );
    delete [] huge;

    tar.close();

    printf("-----------------------\n");

    if ( !tar.open( IO_ReadOnly ) )
    {
      printf("Could not open %s for reading\n", argv[1] );
      return 1;
    }

    const KTarDirectory* dir = tar.directory();
    recursive_print(dir, "");

    const KTarEntry* e = dir->entry( "mydir/test3" );
    Q_ASSERT( e && e->isFile() );
    const KTarFile* f = (KTarFile*)e;

    TQByteArray arr( f->data() );
    printf("SIZE=%i\n",arr.size() );
    TQString str( arr );
    printf("DATA=%s\n", str.latin1());

    tar.close();

    return 0;
  }
  else if ( command == "maxlength" )
  {
    KTarGz tar( argv[2] );

    if ( !tar.open( IO_WriteOnly ) )
    {
      printf("Could not open %s for writing\n", argv[1]);
      return 1;
    }
    // Generate long filenames of each possible length bigger than 98...
    // Also exceed 512 byte block size limit to see how well the ././@LongLink
    // implementation fares
    for (int i = 98; i < 514 ; i++ )
    {
      TQString str, num;
      str.fill( 'a', i-10 );
      num.setNum( i );
      num = num.rightJustify( 10, '0' );
      tar.writeFile( str+num, "testu", "testg", 3, "hum" );
    }
    // Result of this test : works perfectly now (failed at 482 formerly and
    // before that at 154).
    tar.close();
    printf("Now run 'tar tvzf %s'\n", argv[2]);
    return 0;
  }
  else if ( command == "iodevice" )
  {
    KTarGz tar( argv[2] );
    if ( !tar.open( IO_ReadOnly ) )
      return 1;
    const KTarDirectory* dir = tar.directory();
    assert(dir);
    const KTarEntry* entry = dir->entry( "my/dir/test3" );
    if ( entry && entry->isFile() )
    {
        TQIODevice *dev = static_cast<const KTarFile *>(entry)->device();
        TQByteArray contents = dev->readAll();
        printf("contents='%s'\n", TQCString(contents, contents.size()+1 ).data());
    } else
        printf("entry=%p - not found if 0, otherwise not a file\n", (void*)entry);
    return 0;
  }
  else
    printf("Unknown command\n");
}
Exemplo n.º 19
0
bool print(std::ostream& out, const NodePtr root,
      const RuleTable& rules) {
   Context context;
   return recursive_print(out, root, rules,
      create_default_bindings(root), 0, context);
}
Exemplo n.º 20
0
bool print(std::ostream& out, const NodePtr root,
      const RuleTable& rules, BindingsPtr bindings) {
   Context context;
   return recursive_print(out, root, rules, bindings, 0, context);
}
Exemplo n.º 21
0
void	ft_putnbr_base(int nbr, char *base)
{
	recursive_print(nbr, base, 0);
}
Exemplo n.º 22
0
Arquivo: cache.c Projeto: nshi/falcon
void falcon_cache_print(const falcon_cache_t *cache)
{
	recursive_print(cache->objects, 6);
}