Changeset 03b2b2c in mainline


Ignore:
Timestamp:
2012-06-24T17:32:30Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0d1a8fd
Parents:
da0fef6
Message:

Bithenge: add working but useless script parser.

Location:
uspace/app/bithenge
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/Makefile

    rda0fef6 r03b2b2c  
    3737        file.c \
    3838        print.c \
     39        script.c \
    3940        source.c \
    4041        test.c \
  • uspace/app/bithenge/Makefile.linux

    rda0fef6 r03b2b2c  
    3636        file.c \
    3737        print.c \
     38        script.c \
    3839        source.c \
    3940        test.c \
  • uspace/app/bithenge/helenos/os.h

    rda0fef6 r03b2b2c  
    3232#include <bool.h>
    3333#include <byteorder.h>
     34#include <errno.h>
    3435#include <macros.h>
    3536#include <mem.h>
  • uspace/app/bithenge/linux/os.h

    rda0fef6 r03b2b2c  
    8585}
    8686
     87static inline char *str_ndup(const char *s, size_t max_len)
     88{
     89        return strndup(s, max_len);
     90}
     91
    8792static inline const char *str_error(int e)
    8893{
  • uspace/app/bithenge/test.c

    rda0fef6 r03b2b2c  
    4242#include "source.h"
    4343#include "print.h"
     44#include "script.h"
     45#include "transform.h"
    4446#include "tree.h"
    4547
    4648int main(int argc, char *argv[])
    4749{
    48         if (argc < 2) {
     50        int rc;
     51        if (argc < 3) {
    4952                // {True: {}, -1351: "\"false\"", "true": False, 0: b"..."}
    5053                const char data[] = "'Twas brillig, and the slithy toves";
     
    6669                bithenge_node_destroy(node);
    6770        } else {
    68                 bithenge_node_t *node;
    69                 int rc = bithenge_node_from_source(&node, argv[1]);
     71                bithenge_transform_t *transform;
     72                rc = bithenge_parse_script(argv[1], &transform);
     73                if (rc != EOK) {
     74                        printf("Error parsing script: %s\n", str_error(rc));
     75                        return 1;
     76                }
     77
     78                bithenge_node_t *node, *node2;
     79                int rc = bithenge_node_from_source(&node, argv[2]);
    7080                if (rc != EOK) {
    7181                        printf("Error creating node from source: %s\n", str_error(rc));
    7282                        return 1;
    7383                }
    74                 rc = bithenge_print_node(BITHENGE_PRINT_PYTHON, node);
     84
     85                rc = bithenge_transform_apply(transform, node, &node2);
     86                if (rc != EOK) {
     87                        printf("Error applying transform: %s\n", str_error(rc));
     88                        return 1;
     89                }
     90
     91                bithenge_node_destroy(node);
     92                bithenge_transform_dec_ref(transform);
     93
     94                rc = bithenge_print_node(BITHENGE_PRINT_PYTHON, node2);
    7595                if (rc != EOK) {
    7696                        printf("Error printing node: %s\n", str_error(rc));
     
    7898                }
    7999                printf("\n");
    80                 bithenge_node_destroy(node);
    81100        }
    82101
  • uspace/app/bithenge/transform.h

    rda0fef6 r03b2b2c  
    3838#define BITHENGE_TRANSFORM_H_
    3939
     40#include "blob.h"
    4041#include "tree.h"
    4142
     
    104105
    105106/** Decrement a transform's reference count.
    106  * @param xform The transform to dereference.
     107 * @param xform The transform to dereference, or NULL.
    107108 * @return EOK on success or an error code from errno.h. */
    108109static inline int bithenge_transform_dec_ref(bithenge_transform_t *xform)
    109110{
    110         assert(xform);
     111        if (!xform)
     112                return EOK;
    111113        assert(xform->ops);
    112114        if (--xform->refs == 0)
Note: See TracChangeset for help on using the changeset viewer.