Giter VIP home page Giter VIP logo

sadve's Introduction

SADVE

Extract value of C defines directly from command line

Prerequisites

  • cmake - required for both building and using
  • bash - min. version 4.0
  • compiler that can be picked up by cmake (also for using, not only building)

Installation

git clone https://github.com/v3l0c1r4pt0r/sadve.git
cd sadve
mkdir -p build && cd build
cmake ..
make
sudo make install

Usage

To get value of define AF_INET, defined in header sys/socket.h, one can call:

sadve -d AF_INET sys/socket.h

Then to learn size of structure sockaddr as defined in sys/socket.h, use:

sadve -s sockaddr sys/socket.h

Full help text:

Usage: /usr/local/bin/sadve [--dec|--hex|--format=F] -d|-s|-u|-t|-e SYMBOL HEADER
       /usr/local/bin/sadve [--dec|--hex|--format=F] -o STRUCT.FIELD HEADER
       /usr/local/bin/sadve -h
        -d, --define    Print final value of preprocessor macro
        -s, --struct    Print total length of struct
        -u, --union     Print total length of union
        -t, --type      Print total length of type
        -e, --enum      Print total length of enum
        -o, --offset    Print offset of field in structure
        -I DIR          Appends DIR to search path of include files
            --dec       Print value in decimal form (default)
            --hex       Print value in hexadecimal form
            --format=F  Print value in F form, where F is format string as in
                          printf(3)
            --debug     Debug sadve itself
        -h, --help      Print this help message and exit
        SYMBOL          Symbol which value is to be examined
        HEADER          Header where symbol is defined

License

The program is licensed under GNU GPL v3.

sadve's People

Contributors

v3l0c1r4pt0r avatar

Watchers

 avatar  avatar

sadve's Issues

Allow access to substructures in offset computation

When structure has other structure included and one wants to get offset of a field that is not at the beginning of this inner structure, it is not possible to do that directly.

There is however a workaround: count offset of substructure, then count offset of field in this inner structure.

Syntax of offsetof() should allow to that directly, but currently parsing of struct.field does not allow that, because of a bug that results in:

offsetof(struct outer.inner, inner.field)

in case of a call:

sadve -so outer.inner.field header.h

cmake failure because of CMakeCache.txt mismatch

In very rare cases, after some modifications to template build system it is possible to encounter following error:

$ sadve --hex --define WDIOC_GETSTATUS linux/watchdog.h
CMake Error: The current CMakeCache.txt directory <HOME>/.cache/sadve/simple/CMakeCache.txt is different than the directory <HOME>/.cache/sadve/define where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source "/usr/local/share/sadve/simple/CMakeLists.txt" does not match the source "<SOURCE>/sadve/in/define/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.

As we can expect it to happen from time to time, it would be nice to handle the situation automagically, as user does not have to know cmake is even invoked under the hood.

Allow using dot as path for includes

When using -I switch in gcc, it is common to add -I. to search for headers in current directory. Same behavior should be supported by sadve. Currently it expects headers to be in temporary build directory.

Allow including more than one header file

Sometimes headers might not include all of their dependencies, but instead count on user to do so. Number of positional parameters might be unlimited and all but first could be names of headers

Allow passing define values

Some headers might define something based on some conditions. It would be nice to be able to manipulate these conditions. User should be allowed to use -D flag like in gcc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.