Browse Source

..

generate_api
Volker Birk 3 years ago
parent
commit
8d93803536
3 changed files with 43 additions and 13 deletions
  1. +10
    -11
      api/basic_api.yml2
  2. +12
    -2
      api/gen_c_header.ysl2
  3. +21
    -0
      api/to_c.ysl2

+ 10
- 11
api/basic_api.yml2 View File

@ -9,14 +9,13 @@
type ISO639_1 extends string size=2 > a-z
type Hex extends string > a-f0-9
type hex extends string > a-f0-9
type hash extends hex min=16, max=128,
doc="32bit Key ID to SHA512 in hex";
type TID extends binary size=16,
doc="UUID version 4 variant 1";
type hash doc="32bit Key ID to SHA512 in hex"
extends hex min=16, max=128;
type TID doc="UUID version 4 variant 1"
extends binary size=16;
enum comm_type {
hex unknown 0;
@ -87,11 +86,11 @@ enum comm_type {
struct identity {
field string address;
field hash fpr;
field string user_id;
field string username;
field ISO639_1 lang;
field string address doc="SMTP address or URI";
field hash fpr doc="fingerprint of key being used as ID";
field string user_id doc="ID for person or entity in M2M case";
field string username doc="descriptive string";
field ISO639_1 lang doc="two-digit language code or null bytes";
flags {
flag not_for_sync 0x0001


+ 12
- 2
api/gen_c_header.ysl2 View File

@ -34,7 +34,7 @@ tstylesheet {
#endif
||
apply "doc|enum|struct", 0;
apply "doc|type|enum|struct", 0;
||
#ifdef __cplusplus
@ -44,6 +44,12 @@ tstylesheet {
||
}
template "type" {
if "@doc" | // «@doc»
| typedef «func:basetype(@name)» «@name»;
|
}
template "struct" {
||
typedef struct _«func:name()» {
@ -55,7 +61,11 @@ tstylesheet {
||
}
template "field" | «@type» «@name»;
template "field" {
if "@doc" | // «@doc»
| «func:c-type(@type)» «@name»;
|
}
template "enum" {
||


+ 21
- 0
api/to_c.ysl2 View File

@ -31,3 +31,24 @@ def "func:name" {
result call "name" with "abbr", "$abbr";
}
def "func:basetype" {
param "type";
const "definition", "//type[@name=$type]";
choose {
when "$definition/extends"
result "func:c-type($definition/extends/@type)";
otherwise
result "func:c-type($type)";
}
}
def "func:c-type" {
param "dsltype";
choose {
when "$dsltype = 'string' or $dsltype = 'binary'"
result "'char *'";
otherwise
result "$dsltype";
}
}

Loading…
Cancel
Save