Esempio n. 1
0
static rc_t add_to_pi_ref( pi_ref * pr, window * w, PlacementIterator *pi )
{
    rc_t rc = 0;
    pi_window * pw = find_pi_window( &pr->pi_windows, w );

    if ( pw == NULL )
        rc = make_pi_window( &pw, &pr->pi_windows, w );
    if ( rc == 0 )
        rc = add_to_pi_window( pw, pi );

    if ( rc == 0 )
    {
        /* keep track of the outer window... */
        if ( DLListHead( &pr->pi_windows ) == NULL )
        {
            /* first window ?*/
            pr->outer.first = w->first;
            pr->outer.len = w->len;
        }
        else
        {
            if ( w->first < pr->outer.first )
                pr->outer.first = w->first;
            if ( w->first + w->len > pr->outer.first + pr->outer.len )
                pr->outer.len = ( ( w->first + w->len ) - pr->outer.first ) + 1;
        }
    }
    else if ( ( pw != NULL )&&( GetRCState( rc ) == rcDone ) )
    {
        /* add_to_pi_window() was not successful because iterator has no
           alignments int the requested window, that means we have to delete
           the window if it is empty */
        if ( pw->count == 0 )
        {
            /* first we have to take the pw out of the pr->pi_windows - list...
               it was pushed at the tail of it, so we pop it from there */
            DLListPopTail( &pr->pi_windows );
            /* because it is empty ( count == 0 ) we can just free it now */
            free( pw );
        }
    }
    return rc;
}
Esempio n. 2
0
static
rc_t run_kar_test( const char * archive )
{
    rc_t rc;
    const KDirectory * din;

    rc = open_file_as_dir (archive, &din);
    if (rc == 0)
    {
        list_adata adata;

        adata.max_loc = adata.max_size = 0;
        adata.filter = pnamesFilter;
        adata.fdata = NULL;
        adata.has_zombies = false;
        DLListInit (&adata.list);
        /* find all directory entries */
        rc = step_through_dir ( din, ".", pnamesFilter, NULL, list_action, &adata );

        /* "sort" the file entries if requested */
        if (rc == 0)
        {
        }
        if (rc == 0)
        {
            const char * LineFormatFile = "%c%s %*lu %*lu %*s %s";
            const char * LineFormatEFile = "%c%s %*lu %*c %*s %s";
            const char * LineFormatDir = "%c%s %*c %*c %*s %s";
            const char * LineFormatTxt = "%c%s %-*s %-*s %-*s %s";
            /* 18446744073709551615 is max 64bit unsigned so 20 characters + 1 */
            char zwidth_buffer [32];
            size_t zwidth, lwidth;
            union u
            {
                DLNode * node;
                list_item * item;
            } ptr;

            rc = string_printf (zwidth_buffer, sizeof zwidth_buffer, & zwidth, "%lu", adata.max_size);
            rc = string_printf (zwidth_buffer, sizeof zwidth_buffer, & lwidth, "%lu", adata.max_size);
            if (long_list)
            { 
                /* need to use time_t not Ktime_t here since we are calling system functions */
                time_t t = time(NULL);
                struct tm * ts = localtime (&t);
                int dwidth = strftime (zwidth_buffer, sizeof (zwidth_buffer), "%Y-%m-%d %H:%M:%S", ts);

                KOutMsg (LineFormatTxt,
                         'T',"ypeAccess",
                         (uint32_t)zwidth, "Size",
                         (uint32_t)lwidth, "Offset",
                         (uint32_t)dwidth, "ModDateTime",
                         "Path Name\n");
            }
            for (ptr.node = DLListPopTail(&adata.list); 
                 ptr.node != NULL;
                 ptr.node = DLListPopTail(&adata.list))
            {
                if (long_list)
                {
                    struct tm * ts;
                    char t;
                    char a[10];
                    char d[20];
                    size_t dwidth;
                    time_t lt;

                    lt = ptr.item->mtime;
                    ts = localtime (&lt);
                    dwidth = strftime (d, sizeof (d), "%Y-%m-%d %H:%M:%S", ts);
                    access_to_string (a, ptr.item->access);
                    if (ptr.item->type & kptAlias)
                        t = 'l';
                    else if (ptr.item->type == kptDir)
                        t = 'd';
                    else
                        t = '-';
                    if ((ptr.item->type & ~kptAlias) == kptZombieFile)
                        KOutMsg(LineFormatFile,
                                t, "TRUNCATED",
                                (uint32_t)zwidth, ptr.item->size,
                                ( uint32_t )lwidth, ptr.item->loc,
                                ( uint32_t )dwidth, d, ptr.item->path);
                    else if ((ptr.item->type & ~kptAlias) == kptFile)
                    {
                        if (ptr.item->size == 0)
                            KOutMsg(LineFormatEFile,
                                    t, a,
                                    ( uint32_t )zwidth, ptr.item->size,
                                    ( uint32_t )lwidth, '-',
                                    ( uint32_t )dwidth, d, ptr.item->path);
                        else
                            KOutMsg(LineFormatFile,
                                    t, a,
                                    ( uint32_t )zwidth, ptr.item->size,
                                    ( uint32_t )lwidth, ptr.item->loc,
                                    ( uint32_t )dwidth, d, ptr.item->path);
                    }
                    else
                        KOutMsg(LineFormatDir,
                                t, a,
                                ( uint32_t )zwidth, '-',
                                ( uint32_t )lwidth, '-',
                                ( uint32_t )dwidth, d, ptr.item->path);
                    if (ptr.item->type & kptAlias)
                        KOutMsg (" -> %s\n", ptr.item->link);
                    else
                        KOutMsg ("\n");
                }
                else
                {
                    KOutMsg ("%s\n",ptr.item->path);
                }
            }
        }
        KDirectoryRelease (din);
    }
    return rc;
}