.. generate_api
authorVolker Birk <vb@pep-project.org>
Thu, 07 Feb 2019 15:30:58 +0100
branchgenerate_api
changeset 32838d5c4788a20a
parent 3262 62cdcfe4da1e
child 3286 14ce4525b352
..
api/basic_api.yml2
api/gen_c_header.ysl2
api/to_c.ysl2
     1.1 --- a/api/basic_api.yml2	Tue Feb 05 22:20:23 2019 +0100
     1.2 +++ b/api/basic_api.yml2	Thu Feb 07 15:30:58 2019 +0100
     1.3 @@ -9,14 +9,13 @@
     1.4  
     1.5  type ISO639_1 extends string size=2 > a-z
     1.6  
     1.7 -type Hex extends string > a-f0-9
     1.8 +type hex extends string > a-f0-9
     1.9  
    1.10 -type hash extends hex min=16, max=128,
    1.11 -    doc="32bit Key ID to SHA512 in hex";
    1.12 +type hash doc="32bit Key ID to SHA512 in hex"
    1.13 +    extends hex min=16, max=128;
    1.14  
    1.15 -type TID extends binary size=16,
    1.16 -    doc="UUID version 4 variant 1";
    1.17 -
    1.18 +type TID doc="UUID version 4 variant 1"
    1.19 +    extends binary size=16;
    1.20  
    1.21  enum comm_type {
    1.22      hex unknown 0;
    1.23 @@ -87,11 +86,11 @@
    1.24  
    1.25  struct identity {
    1.26      
    1.27 -    field string address;
    1.28 -    field hash fpr;
    1.29 -    field string user_id;
    1.30 -    field string username;
    1.31 -    field ISO639_1 lang;
    1.32 +    field string address doc="SMTP address or URI";
    1.33 +    field hash fpr doc="fingerprint of key being used as ID";
    1.34 +    field string user_id doc="ID for person or entity in M2M case";
    1.35 +    field string username doc="descriptive string";
    1.36 +    field ISO639_1 lang doc="two-digit language code or null bytes";
    1.37  
    1.38      flags {
    1.39          flag not_for_sync 0x0001
     2.1 --- a/api/gen_c_header.ysl2	Tue Feb 05 22:20:23 2019 +0100
     2.2 +++ b/api/gen_c_header.ysl2	Thu Feb 07 15:30:58 2019 +0100
     2.3 @@ -34,7 +34,7 @@
     2.4      #endif
     2.5  
     2.6      ||
     2.7 -    apply "doc|enum|struct", 0;
     2.8 +    apply "doc|type|enum|struct", 0;
     2.9      ||
    2.10  
    2.11      #ifdef __cplusplus
    2.12 @@ -44,6 +44,12 @@
    2.13      ||
    2.14      }
    2.15  
    2.16 +    template "type" {
    2.17 +        if "@doc" | // «@doc»
    2.18 +        | typedef «func:basetype(@name)» «@name»;
    2.19 +        |
    2.20 +    }
    2.21 +
    2.22      template "struct" {
    2.23      ||
    2.24      typedef struct _«func:name()» {
    2.25 @@ -55,7 +61,11 @@
    2.26      ||
    2.27      }
    2.28  
    2.29 -    template "field" | «@type» «@name»;
    2.30 +    template "field" {
    2.31 +        if "@doc" | // «@doc»
    2.32 +        | «func:c-type(@type)» «@name»;
    2.33 +        |
    2.34 +    }
    2.35  
    2.36      template "enum" {
    2.37      ||
     3.1 --- a/api/to_c.ysl2	Tue Feb 05 22:20:23 2019 +0100
     3.2 +++ b/api/to_c.ysl2	Thu Feb 07 15:30:58 2019 +0100
     3.3 @@ -31,3 +31,24 @@
     3.4      result call "name" with "abbr", "$abbr";
     3.5  }
     3.6  
     3.7 +def "func:basetype" {
     3.8 +    param "type";
     3.9 +    const "definition", "//type[@name=$type]";
    3.10 +    choose {
    3.11 +        when "$definition/extends"
    3.12 +            result "func:c-type($definition/extends/@type)";
    3.13 +        otherwise
    3.14 +            result "func:c-type($type)";
    3.15 +    }
    3.16 +}
    3.17 +
    3.18 +def "func:c-type" {
    3.19 +    param "dsltype";
    3.20 +    choose {
    3.21 +        when "$dsltype = 'string' or $dsltype = 'binary'"
    3.22 +            result "'char *'";
    3.23 +        otherwise
    3.24 +            result "$dsltype";
    3.25 +    }
    3.26 +}
    3.27 +