Changeset 5c925ce in mainline for uspace/app/bithenge/print.c


Ignore:
Timestamp:
2012-06-07T17:00:12Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8375d0eb
Parents:
5f679702
Message:

Bithenge: make blobs a type of node

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/print.c

    r5f679702 r5c925ce  
    3737#include <errno.h>
    3838#include <stdio.h>
     39#include "blob.h"
    3940#include "print.h"
    4041#include "tree.h"
     
    120121}
    121122
     123static int print_blob(bithenge_print_type_t type, bithenge_node_t *node)
     124{
     125        bithenge_blob_t *blob = bithenge_node_as_blob(node);
     126        aoff64_t pos = 0;
     127        char buffer[1024];
     128        aoff64_t size = sizeof(buffer);
     129        int rc;
     130        printf(type == BITHENGE_PRINT_PYTHON ? "b\"" : "\"");
     131        do {
     132                rc = bithenge_blob_read(blob, pos, buffer, &size);
     133                if (rc != EOK)
     134                        return rc;
     135                for (aoff64_t i = 0; i < size; i++)
     136                        printf("\\x%02x", buffer[i]);
     137                pos += size;
     138        } while (size == sizeof(buffer));
     139        printf("\"");
     140        return EOK;
     141}
     142
    122143int bithenge_print_node(bithenge_print_type_t type, bithenge_node_t *tree)
    123144{
     
    133154        case BITHENGE_NODE_STRING:
    134155                return print_string(type, tree);
     156        case BITHENGE_NODE_BLOB:
     157                return print_blob(type, tree);
    135158        }
    136159        return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.