cdefs

0.3.2 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i cdefs

Weekly Downloads

0

Version

0.3.2

License

MIT

Last publish

Collaborators

  • mateogianolio