0.3.2 • Published 9 years ago

cdefs v0.3.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

cdefs

Describe C function prototypes in JSON.

const char* get_name(int id) {
  // ...
}

=>

{
  "get_name": {
    "returns": "const char*",
    "arguments": [
      {
        "name": "id",
        "type": "int"
      }
    ]
  }
}

Install

$ npm install cdefs -g

Usage

from command-line

$ cdefs [-o output_file] [file1, [file2, [...]]]

Inspect ex1.c and ex2.c and print prototypes to stdout.

$ cdefs example/ex1.c example/ex2.c
{
  "ex1.c": {
    "main": {
      "returns": "int",
      "arguments": [
        {
          "name": "argc",
          "type": "int"
        },
        {
          "name": "argv",
          "type": "char**"
        }
      ]
    }
  },
  "ex2.c": {
    "test": {
      "returns": "float",
      "arguments": []
    },
    "print": {
      "returns": "void",
      "arguments": [
        {
          "name": " str",
          "type": "char*"
        }
      ]
    }
  }
}

Inspect ex2.c and save prototypes to ex2.json:

$ cdefs example/ex2.c -o ex2.json

from your module

var cdefs = require('cdefs');

Get the prototypes for ex1.c:

var fs = require('fs'),
    src = fs.readFileSync('./example/ex1.c', 'utf8'),
    prototypes = cdefs(src);

Contribute

Contributions are welcome.

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago