1, support C macro: #ifndef, #ifdef, #endif for .h file, auto search .h path in the...
authoryu.dongliang <18588496441@163.com>
Sun, 21 Jun 2026 02:53:40 +0000 (10:53 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 21 Jun 2026 02:54:46 +0000 (10:54 +0800)
2, delete some un-used old files.

28 files changed:
core/scf_ast.c
core/scf_block.h
core/scf_expr_handler.c [deleted file]
core/scf_lex_word.h
core/scf_operator_handler.c [deleted file]
elf/scf_dwarf.c
elf/scf_dwarf.h
elf/scf_dwarf_def.h [deleted file]
examples/const_local.c [deleted file]
examples/hello.c
examples/hello.h [new file with mode: 0644]
lex/Makefile
lex/scf_lex.c
lex/scf_lex.h
lex/scf_macro.c [new file with mode: 0644]
native/eda/Makefile [deleted file]
native/eda/main.c [deleted file]
native/eda/scf_eda.pb-c.c [deleted file]
native/eda/scf_eda.pb-c.h [deleted file]
native/eda/scf_eda.proto [deleted file]
native/eda/scf_eda_pb.c [deleted file]
native/eda/scf_eda_pb.h [deleted file]
parse/Makefile
parse/scf_dfa_include.c
parse/scf_parse.c
parse/scf_parse.h
util/scf_string.c
util/scf_string.h

index 50eafa220c705f6d09c78dfce27dc734952bfc0d..1dc0fa4dc726557a2106a465986383110ca1468c 100644 (file)
@@ -26,6 +26,7 @@ int   scf_ast_open(scf_ast_t** past)
        if (!ast->global_relas)
                return -ENOMEM;
 
+       ast->current_block = ast->root_block;
        *past = ast;
        return 0;
 }
index 6607f88c263dc179bf8ce85efb2a21b201db6a6d..30d3fd0415df6fd6c38813a8eda837d9ad61a048 100644 (file)
@@ -9,6 +9,8 @@ struct scf_block_s {
        scf_scope_t*        scope;
 
        scf_string_t*       name;
+
+       scf_lex_t*          lex_list;
 };
 
 
@@ -28,6 +30,4 @@ scf_function_t*       scf_block_find_function(scf_block_t* b, const char* name);
 
 scf_label_t*    scf_block_find_label(scf_block_t* b, const char* name);
 
-int             _find_local_vars(scf_node_t* node, void* arg, scf_vector_t* results);
-
 #endif
diff --git a/core/scf_expr_handler.c b/core/scf_expr_handler.c
deleted file mode 100644 (file)
index 7616164..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#include"scf_ast.h"
-
index a1f0b3e4df0714fd21350153bff9ad615aaf2972..4a8010c2fb7327b2e5a31d2ff910f981592f2005 100644 (file)
@@ -60,6 +60,7 @@ enum scf_lex_words
        SCF_LEX_WORD_RA,            // >> right angle brackets
 
        SCF_LEX_WORD_KEY_SIZEOF,    // sizeof
+       SCF_LEX_WORD_KEY_TYPEOF,    // typeof
        SCF_LEX_WORD_KEY_NEW,       // create class object
        SCF_LEX_WORD_KEY_CONTAINER, // container_of
        SCF_LEX_WORD_KEY_VA_ARG,    // va_arg
@@ -84,7 +85,7 @@ enum scf_lex_words
        SCF_LEX_WORD_SPACE,                     // ' ' space
 
        // eof
-       SCF_LEX_WORD_EOF,                       // EOF
+       SCF_LEX_WORD_EOF,           // EOF
 
        // key words
        SCF_LEX_WORD_KEY_IF,            // if
@@ -96,21 +97,24 @@ enum scf_lex_words
 
        SCF_LEX_WORD_KEY_BREAK,     // break
        SCF_LEX_WORD_KEY_CONTINUE,  // continue
+       SCF_LEX_WORD_KEY_GOTO,      // goto
 
        SCF_LEX_WORD_KEY_SWITCH,        // switch
        SCF_LEX_WORD_KEY_CASE,          // case
        SCF_LEX_WORD_KEY_DEFAULT,       // default
 
-       SCF_LEX_WORD_KEY_RETURN,        // return
-
-       SCF_LEX_WORD_KEY_GOTO,          // goto
-
+       SCF_LEX_WORD_KEY_RETURN,    // return
 
        SCF_LEX_WORD_KEY_OPERATOR,  // operator
        SCF_LEX_WORD_KEY_UNDERLINE, // _ underline
 
        SCF_LEX_WORD_KEY_INCLUDE,   // #include
        SCF_LEX_WORD_KEY_DEFINE,    // #define
+       SCF_LEX_WORD_KEY_UNDEF,     // #undef
+
+       SCF_LEX_WORD_KEY_IFDEF,     // #ifdef
+       SCF_LEX_WORD_KEY_IFNDEF,    // #ifndef
+       SCF_LEX_WORD_KEY_ELIF,      // #elif
        SCF_LEX_WORD_KEY_ENDIF,     // #endif
 
        // asm key word
@@ -131,9 +135,9 @@ enum scf_lex_words
        // data types
        SCF_LEX_WORD_KEY_CHAR,          // char
 
-       SCF_LEX_WORD_KEY_INT,           // int
+       SCF_LEX_WORD_KEY_INT,       // int
        SCF_LEX_WORD_KEY_FLOAT,     // float
-       SCF_LEX_WORD_KEY_DOUBLE,        // double
+       SCF_LEX_WORD_KEY_DOUBLE,    // double
 
        SCF_LEX_WORD_KEY_INT8,      // int8_t
        SCF_LEX_WORD_KEY_INT1,      // int1_t
@@ -163,6 +167,7 @@ enum scf_lex_words
 
        // class
        SCF_LEX_WORD_KEY_CLASS,     // class
+       SCF_LEX_WORD_KEY_TYPEDEF,   // typedef
 
        SCF_LEX_WORD_KEY_CONST,     // const
        SCF_LEX_WORD_KEY_STATIC,    // static
@@ -206,6 +211,8 @@ struct scf_macro_s
 {
        int              refs;
 
+       uint8_t          def_flag:1;
+
        scf_lex_word_t*  w;
        scf_vector_t*    argv;
 
diff --git a/core/scf_operator_handler.c b/core/scf_operator_handler.c
deleted file mode 100644 (file)
index eea435e..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include"scf_operator_handler.h"
-
-scf_operator_handler_t* scf_operator_handler_alloc(int type, scf_operator_handler_pt func)
-{
-       scf_operator_handler_t* h = calloc(1, sizeof(scf_operator_handler_t));
-       assert(h);
-
-       scf_list_init(&h->list);
-
-       h->type                 = type;
-
-       h->func                 = func;
-       return h;
-}
-
-void scf_operator_handler_free(scf_operator_handler_t* h)
-{
-       if (h) {
-               free(h);
-               h = NULL;
-       }
-}
-
index c7d8771860b93e404d554923d3b848750662951f..a34bce1b162c04c7a95df484e3ff5c60657a49fc 100644 (file)
@@ -435,6 +435,37 @@ scf_dwarf_t* scf_dwarf_debug_alloc()
        return debug;
 }
 
+int _find_debug_file(const void* v0, const void* v1)
+{
+       const scf_string_t* s0 = v0;
+       const scf_string_t* s1 = v1;
+
+       if (s0->len < s1->len)
+               return -1;
+       else if (s0->len > s1->len)
+               return 1;
+
+       return strcmp(s0->data, s1->data);
+}
+
+int scf_dwarf_add_file_name(scf_dwarf_t* debug, const scf_string_t* fname)
+{
+       if (scf_vector_find_cmp(debug->file_names, fname, _find_debug_file))
+               return 0;
+
+       scf_string_t* s = scf_string_clone(fname);
+       if (!s)
+               return -ENOMEM;
+
+       int ret = scf_vector_add(debug->file_names, s);
+       if (ret < 0) {
+               scf_string_free(s);
+               return ret;
+       }
+
+       return 0;
+}
+
 void scf_dwarf_debug_free (scf_dwarf_t* debug)
 {
        if (debug) {
index 08675bc50f4182b1c7acdf3d28483fb7cb0c349f..c68066320fc5305094c9cc01d9d75a09bf5b87a6 100644 (file)
@@ -441,4 +441,8 @@ const char* scf_dwarf_find_tag (const uint32_t type);
 const char* scf_dwarf_find_form(const uint32_t type);
 const char* scf_dwarf_find_attribute(const uint32_t type);
 
+int scf_dwarf_add_file_name(scf_dwarf_t* debug, const scf_string_t* fname);
+
+int _find_debug_file(const void* v0, const void* v1);
+
 #endif
diff --git a/elf/scf_dwarf_def.h b/elf/scf_dwarf_def.h
deleted file mode 100644 (file)
index 1845978..0000000
+++ /dev/null
@@ -1,446 +0,0 @@
-#ifndef SCF_DWARF_DEF_H
-#define SCF_DWARF_DEF_H
-
-#include"scf_list.h"
-#include"scf_vector.h"
-#include"scf_string.h"
-
-typedef int8_t    scf_dwarf_sbyte_t;
-typedef uint8_t   scf_dwarf_ubyte_t;
-typedef uint16_t  scf_dwarf_uhalf_t;
-typedef int32_t   scf_dwarf_sword_t;
-typedef uint32_t  scf_dwarf_uword_t;
-
-typedef struct    scf_dwarf_line_machine_s        scf_dwarf_line_machine_t;
-typedef struct    scf_dwarf_line_prologue_s       scf_dwarf_line_prologue_t;
-typedef struct    scf_dwarf_line_filename_s       scf_dwarf_line_filename_t;
-typedef struct    scf_dwarf_line_result_s         scf_dwarf_line_result_t;
-
-typedef struct    scf_dwarf_abbrev_declaration_s  scf_dwarf_abbrev_declaration_t;
-typedef struct    scf_dwarf_abbrev_attribute_s    scf_dwarf_abbrev_attribute_t;
-
-typedef struct    scf_dwarf_info_header_s         scf_dwarf_info_header_t;
-typedef struct    scf_dwarf_info_entry_s          scf_dwarf_info_entry_t;
-typedef struct    scf_dwarf_info_attr_s           scf_dwarf_info_attr_t;
-typedef struct    scf_dwarf_attr_block_s          scf_dwarf_attr_block_t;
-typedef struct    scf_dwarf_attr_ref_s            scf_dwarf_attr_ref_t;
-
-typedef struct    scf_dwarf_debug_s               scf_dwarf_debug_t;
-
-// dwarf line standard opcodes
-#define DW_LNS_copy              1
-#define DW_LNS_advance_pc        2
-#define DW_LNS_advance_line      3
-#define DW_LNS_set_file          4
-#define DW_LNS_set_column        5
-#define DW_LNS_negate_stmt       6
-#define DW_LNS_set_basic_block   7
-#define DW_LNS_const_add_pc      8
-#define DW_LNS_fixed_advance_pc  9
-
-// dwarf line extended opcodes
-#define DW_LNE_end_sequence      1
-#define DW_LNE_set_address       2
-#define DW_LNE_define_file       3
-
-// dwarf tags
-#define DW_TAG_array_type             0x01
-#define DW_TAG_class_type             0x02
-#define DW_TAG_entry_point            0x03
-#define DW_TAG_enumeration_type       0x04
-#define DW_TAG_formal_parameter       0x05
-
-#define DW_TAG_imported_declaration   0x08
-
-#define DW_TAG_label                  0x0a
-#define DW_TAG_lexical_block          0x0b
-
-#define DW_TAG_member                 0x0d
-
-#define DW_TAG_pointer_type           0x0f
-
-#define DW_TAG_reference_type         0x10
-#define DW_TAG_compile_unit           0x11
-#define DW_TAG_string_type            0x12
-#define DW_TAG_structure_type         0x13
-
-#define DW_TAG_subroutine_type        0x15
-#define DW_TAG_typedef                0x16
-#define DW_TAG_union_type             0x17
-#define DW_TAG_unspecified_parameters 0x18
-#define DW_TAG_variant                0x19
-#define DW_TAG_common_block           0x1a
-#define DW_TAG_common_inclusion       0x1b
-#define DW_TAG_inheritance            0x1c
-#define DW_TAG_inlined_subroutine     0x1d
-#define DW_TAG_module                 0x1e
-#define DW_TAG_ptr_to_member_type     0x1f
-
-#define DW_TAG_set_type               0x20
-#define DW_TAG_subrange_type          0x21
-#define DW_TAG_with_stmt              0x22
-#define DW_TAG_access_declaration     0x23
-#define DW_TAG_base_type              0x24
-#define DW_TAG_catch_block            0x25
-#define DW_TAG_const_type             0x26
-#define DW_TAG_constant               0x27
-#define DW_TAG_enumerator             0x28
-#define DW_TAG_file_type              0x29
-#define DW_TAG_friend                 0x2a
-#define DW_TAG_namelist               0x2b
-#define DW_TAG_namelist_item          0x2c
-#define DW_TAG_packed_type            0x2d
-#define DW_TAG_subprogram             0x2e
-#define DW_TAG_template_type_param    0x2f
-
-#define DW_TAG_template_value_param   0x30
-#define DW_TAG_thrown_type            0x31
-#define DW_TAG_try_block              0x32
-#define DW_TAG_variant_part           0x33
-#define DW_TAG_variable               0x34
-#define DW_TAG_volatile_type          0x35
-#define DW_TAG_dwarf_procedure        0x36
-#define DW_TAG_restrict_type          0x37
-#define DW_TAG_interface_type         0x38
-#define DW_TAG_namespace              0x39
-#define DW_TAG_imported_module        0x3a
-#define DW_TAG_unspecified_type       0x3b
-#define DW_TAG_partial_unit           0x3c
-#define DW_TAG_imported_unit          0x3d
-
-#define DW_TAG_condition              0x3f
-#define DW_TAG_shared_type            0x40
-#define DW_TAG_type_unit              0x41
-#define DW_TAG_rvalue_reference_type  0x42
-#define DW_TAG_template_alias         0x43
-#define DW_TAG_lo_user                0x4080
-#define DW_TAG_hi_user                0xffff
-
-#define DW_CHILDREN_no                0
-#define DW_CHILDREN_yes               1
-
-// dwarf attributes
-#define DW_AT_sibling                 0x01
-#define DW_AT_location                0x02
-#define DW_AT_name                    0x03
-
-#define DW_AT_ordering                0x09
-
-#define DW_AT_byte_size               0x0b
-#define DW_AT_bit_offset              0x0c
-#define DW_AT_bit_size                0x0d
-
-#define DW_AT_stmt_list               0x10
-#define DW_AT_low_pc                  0x11
-#define DW_AT_high_pc                 0x12
-#define DW_AT_language                0x13
-
-#define DW_AT_discr                   0x15
-#define DW_AT_discr_value             0x16
-#define DW_AT_visibility              0x17
-#define DW_AT_import                  0x18
-#define DW_AT_string_length           0x19
-#define DW_AT_common_reference        0x1a
-#define DW_AT_comp_dir                0x1b
-#define DW_AT_const_value             0x1c
-#define DW_AT_containing_type         0x1d
-#define DW_AT_default_value           0x1e
-
-#define DW_AT_inline                  0x20
-#define DW_AT_is_optional             0x21
-#define DW_AT_lower_bound             0x22
-
-#define DW_AT_producer                0x25
-
-#define DW_AT_prototyped              0x27
-
-#define DW_AT_return_addr             0x2a
-#define DW_AT_start_scope             0x2c
-#define DW_AT_stride_size             0x2e
-#define DW_AT_upper_bound             0x2f
-
-#define DW_AT_abstract_origin         0x31
-#define DW_AT_accessibility           0x32
-#define DW_AT_address_class           0x33
-#define DW_AT_artificial              0x34
-#define DW_AT_base_types              0x35
-#define DW_AT_calling_convention      0x36
-#define DW_AT_count                   0x37
-#define DW_AT_data_member_location    0x38
-#define DW_AT_decl_column             0x39
-#define DW_AT_decl_file               0x3a
-#define DW_AT_decl_line               0x3b
-#define DW_AT_declaration             0x3c
-#define DW_AT_discr_list              0x3d
-#define DW_AT_encoding                0x3e
-#define DW_AT_external                0x3f
-#define DW_AT_frame_base              0x40
-#define DW_AT_friend                  0x41
-#define DW_AT_identifier_case         0x42
-#define DW_AT_macro_info              0x43
-#define DW_AT_namelist_item           0x44
-#define DW_AT_priority                0x45
-#define DW_AT_segment                 0x46
-#define DW_AT_specification           0x47
-#define DW_AT_static_link             0x48
-#define DW_AT_type                    0x49
-#define DW_AT_use_location            0x4a
-#define DW_AT_variable_parameter      0x4b
-#define DW_AT_virtuality              0x4c
-#define DW_AT_vtable_elem_location    0x4d
-
-#define DW_AT_lo_user                 0x2000
-#define DW_AT_GNU_all_call_sites      0x2117
-#define DW_AT_hi_user                 0x3fff
-
-#define DW_ATE_address                0x1
-#define DW_ATE_boolean                0x2
-#define DW_ATE_complex_float          0x3
-#define DW_ATE_float                  0x4
-#define DW_ATE_signed                 0x5
-#define DW_ATE_signed_char            0x6
-#define DW_ATE_unsigned               0x7
-#define DW_ATE_unsigned_char          0x8
-#define DW_ATE_lo_user                0x80
-#define DW_ATE_hi_user                0xff
-
-// dwarf forms
-#define DW_FORM_addr                  0x01
-#define DW_FORM_block2                0x03
-#define DW_FORM_block4                0x04
-#define DW_FORM_data2                 0x05
-#define DW_FORM_data4                 0x06
-#define DW_FORM_data8                 0x07
-#define DW_FORM_string                0x08
-#define DW_FORM_block                 0x09
-#define DW_FORM_block1                0x0a
-#define DW_FORM_data1                 0x0b
-#define DW_FORM_flag                  0x0c
-#define DW_FORM_sdata                 0x0d
-#define DW_FORM_strp                  0x0e
-#define DW_FORM_udata                 0x0f
-#define DW_FORM_ref_addr              0x10
-#define DW_FORM_ref1                  0x11
-#define DW_FORM_ref2                  0x12
-#define DW_FORM_ref4                  0x13
-#define DW_FORM_ref8                  0x14
-#define DW_FORM_ref_udata             0x15
-#define DW_FORM_indirect              0x16
-#define DW_FORM_sec_offset            0x17
-#define DW_FORM_exprloc               0x18
-#define DW_FORM_flag_present          0x19
-#define DW_FORM_ref_sig8              0x20
-
-#define DW_OP_fbreg                   0x91
-#define DW_OP_call_frame_cfa          0x9c
-
-struct scf_dwarf_info_header_s
-{
-       scf_dwarf_uword_t  length;
-       scf_dwarf_uhalf_t  version;
-       scf_dwarf_uword_t  offset;
-       scf_dwarf_ubyte_t  address_size;
-};
-
-struct scf_dwarf_info_entry_s
-{
-       scf_dwarf_uword_t  code;
-
-       uint64_t           cu_byte_offset;
-
-       scf_vector_t*      attributes;
-
-       int                type;
-       int                nb_pointers;
-};
-
-struct scf_dwarf_attr_ref_s
-{
-       scf_dwarf_info_attr_t*  iattr;
-
-       scf_dwarf_info_entry_t* ie;
-       scf_dwarf_info_entry_t* ref_entry;
-
-       uint64_t                offset;
-       size_t                  size;
-};
-
-struct scf_dwarf_info_attr_s
-{
-       scf_dwarf_uword_t       name;
-       scf_dwarf_uword_t       form;
-
-       scf_dwarf_info_entry_t* ref_entry;
-
-       uintptr_t               block_ref;
-       uint64_t                block_ref8;
-
-       union {
-               scf_dwarf_uword_t   block_length;
-
-               uintptr_t           address;
-               uint8_t             const1;
-               uint16_t            const2;
-               uint32_t            const4;
-               uint64_t            const8;
-               scf_dwarf_sword_t   sdata;
-               scf_dwarf_uword_t   udata;
-
-               scf_dwarf_ubyte_t   flag;
-
-               scf_dwarf_uword_t   lineptr;
-               scf_dwarf_uword_t   exprloc;
-
-               uintptr_t           ref;
-               uint64_t            ref8;
-
-               scf_dwarf_uword_t   str_offset;
-       };
-
-       scf_string_t*           data;
-};
-
-struct scf_dwarf_abbrev_attribute_s
-{
-       scf_dwarf_uword_t  name;
-       scf_dwarf_uword_t  form;
-};
-
-struct scf_dwarf_abbrev_declaration_s
-{
-       scf_dwarf_uword_t  code;
-       scf_dwarf_uword_t  tag;
-       scf_dwarf_ubyte_t  has_children;
-
-       scf_vector_t*      attributes;
-
-       scf_vector_t*      childs;
-
-       scf_dwarf_abbrev_declaration_t* parent;
-
-       uint32_t           visited_flag:1;
-};
-
-struct scf_dwarf_line_result_s
-{
-       uintptr_t          address;
-
-       scf_string_t*      file_name;
-       scf_dwarf_uword_t  line;
-       scf_dwarf_uword_t  column;
-
-       scf_dwarf_ubyte_t  is_stmt     :1;
-       scf_dwarf_ubyte_t  basic_block :1;
-       scf_dwarf_ubyte_t  end_sequence:1;
-};
-
-struct scf_dwarf_line_filename_s
-{
-       scf_dwarf_ubyte_t* name;
-       scf_dwarf_uword_t  dir_index;
-       scf_dwarf_uword_t  time_modified;
-       scf_dwarf_uword_t  length;
-};
-
-struct scf_dwarf_line_prologue_s
-{
-       scf_dwarf_uword_t      total_length;
-       scf_dwarf_uhalf_t      version;
-       scf_dwarf_uword_t      prologue_length;
-
-       scf_dwarf_ubyte_t      minimum_instruction_length;
-
-       scf_dwarf_ubyte_t      default_is_stmt;
-
-       scf_dwarf_sbyte_t      line_base;
-       scf_dwarf_ubyte_t      line_range;
-
-       scf_dwarf_ubyte_t      opcode_base;
-       scf_dwarf_ubyte_t*     standard_opcode_lengths;
-    scf_dwarf_ubyte_t*     include_directories;
-    scf_vector_t*          file_names;
-};
-
-struct scf_dwarf_line_machine_s
-{
-       // registers
-       uintptr_t           address;
-
-       scf_dwarf_uword_t   file;
-       scf_dwarf_uword_t   line;
-       scf_dwarf_uword_t   column;
-
-       scf_dwarf_ubyte_t   is_stmt     :1;
-       scf_dwarf_ubyte_t   basic_block :1;
-       scf_dwarf_ubyte_t   end_sequence:1;
-
-       scf_dwarf_line_prologue_t* prologue;
-};
-
-struct scf_dwarf_debug_s
-{
-       char*               arch;
-
-       scf_vector_t*       base_types;
-       scf_vector_t*       struct_types;
-
-       scf_vector_t*       lines;
-       scf_vector_t*       infos;
-       scf_vector_t*       abbrevs;
-       scf_string_t*       str;
-
-       scf_string_t*       debug_line;
-       scf_string_t*       debug_info;
-       scf_string_t*       debug_abbrev;
-
-       scf_vector_t*       line_relas;
-       scf_vector_t*       info_relas;
-       scf_vector_t*       file_names;
-};
-
-scf_dwarf_debug_t*               scf_dwarf_debug_alloc();
-void                             scf_dwarf_debug_free  (scf_dwarf_debug_t* debug);
-int                              scf_dwarf_debug_encode(scf_dwarf_debug_t* debug);
-
-int scf_dwarf_abbrev_add_cu (scf_vector_t* abbrevs);
-int scf_dwarf_abbrev_add_var(scf_vector_t* abbrevs);
-
-int scf_dwarf_abbrev_add_subprogram  (scf_vector_t* abbrevs);
-int scf_dwarf_abbrev_add_struct_type (scf_vector_t* abbrevs);
-int scf_dwarf_abbrev_add_member_var  (scf_vector_t* abbrevs);
-int scf_dwarf_abbrev_add_base_type   (scf_vector_t* abbrevs);
-int scf_dwarf_abbrev_add_pointer_type(scf_vector_t* abbrevs);
-
-scf_dwarf_info_entry_t*          scf_dwarf_info_entry_alloc();
-void                             scf_dwarf_info_entry_free(scf_dwarf_info_entry_t* ie);
-void                             scf_dwarf_info_attr_free(scf_dwarf_info_attr_t* attr);
-
-int scf_dwarf_info_fill_attr(scf_dwarf_info_attr_t* iattr, uint8_t* data, size_t len);
-
-scf_dwarf_line_machine_t*        scf_dwarf_line_machine_alloc();
-void                             scf_dwarf_line_machine_print(scf_dwarf_line_machine_t* lm);
-int                              scf_dwarf_line_machine_fill(scf_dwarf_line_machine_t* lm, scf_vector_t* file_names);
-void                             scf_dwarf_line_machine_free (scf_dwarf_line_machine_t* lm);
-void                             scf_dwarf_line_filename_free(scf_dwarf_line_filename_t* f);
-
-scf_dwarf_abbrev_declaration_t*  scf_dwarf_abbrev_declaration_alloc();
-void                             scf_dwarf_abbrev_declaration_free(scf_dwarf_abbrev_declaration_t* d);
-
-int scf_dwarf_line_decode(scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, const char*   debug_line, size_t debug_line_size);
-int scf_dwarf_line_encode(scf_dwarf_debug_t* debug, scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, scf_string_t* debug_line);
-
-int scf_dwarf_abbrev_decode(scf_vector_t* abbrev_results, const char*   debug_abbrev, size_t debug_abbrev_size);
-int scf_dwarf_abbrev_encode(scf_vector_t* abbrev_results, scf_string_t* debug_abbrev);
-
-int scf_dwarf_info_decode(scf_vector_t* infos, scf_vector_t* abbrevs, scf_string_t* debug_str, const char*   debug_info, size_t debug_info_size, scf_dwarf_info_header_t* header);
-int scf_dwarf_info_encode(scf_dwarf_debug_t* debug, scf_dwarf_info_header_t* header);
-
-void scf_dwarf_abbrev_print(scf_vector_t* abbrev_results);
-void scf_dwarf_info_print  (scf_vector_t* infos);
-
-const char* scf_dwarf_find_tag (const uint32_t type);
-const char* scf_dwarf_find_form(const uint32_t type);
-const char* scf_dwarf_find_attribute(const uint32_t type);
-
-#endif
-
diff --git a/examples/const_local.c b/examples/const_local.c
deleted file mode 100644 (file)
index 6ddf9e4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-int printf(const char* fmt, ...);
-
-int main()
-{
-       const int i = 123;
-
-       printf("%d\n", i);
-
-       return 0;
-}
index 4ce1a4cb79848c18294cfbfbcae902ea047c2bc2..52b0cd96925bc98baaacee6933dbea933591bdfc 100644 (file)
@@ -1,9 +1,7 @@
-
-int printf(const char* fmt, ...);
+#include"hello.h"
 
 int main()
 {
        printf("hello world\n");
        return 0;
 }
-
diff --git a/examples/hello.h b/examples/hello.h
new file mode 100644 (file)
index 0000000..281333b
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef HELLO_H
+#define HELLO_H
+int printf(const char* fmt, ...);
+#endif
index f9dcda9ecca7491c4527b19670198c36cd0b7ca2..f6b9436ac2f09af42b650872dc07cd64d4324e12 100644 (file)
@@ -1,6 +1,7 @@
 CFILES += ../util/scf_string.c
 CFILES += scf_lex.c
 CFILES += scf_lex_util.c
+CFILES += scf_macro.c
 CFILES += ../core/scf_lex_word.c
 CFILES += scf_lex_test.c
 
index 7ef03b991eecfcc9cccfc4558dff4d2e11613f73..148ec60054c8d669c1ffb5b48bdacd4a5041f734 100644 (file)
@@ -4,6 +4,14 @@ static scf_key_word_t  key_words[] =
 {
        {"if",        SCF_LEX_WORD_KEY_IF},
        {"else",      SCF_LEX_WORD_KEY_ELSE},
+
+       {"include",   SCF_LEX_WORD_KEY_INCLUDE},
+       {"define",    SCF_LEX_WORD_KEY_DEFINE},
+       {"undef",     SCF_LEX_WORD_KEY_UNDEF},
+
+       {"ifdef",     SCF_LEX_WORD_KEY_IFDEF},
+       {"ifndef",    SCF_LEX_WORD_KEY_IFNDEF},
+       {"elif",      SCF_LEX_WORD_KEY_ELIF},
        {"endif",     SCF_LEX_WORD_KEY_ENDIF},
 
        {"for",       SCF_LEX_WORD_KEY_FOR},
@@ -12,6 +20,7 @@ static scf_key_word_t  key_words[] =
 
        {"break",     SCF_LEX_WORD_KEY_BREAK},
        {"continue",  SCF_LEX_WORD_KEY_CONTINUE},
+       {"goto",      SCF_LEX_WORD_KEY_GOTO},
 
        {"switch",    SCF_LEX_WORD_KEY_SWITCH},
        {"case",      SCF_LEX_WORD_KEY_CASE},
@@ -19,12 +28,10 @@ static scf_key_word_t  key_words[] =
 
        {"return",    SCF_LEX_WORD_KEY_RETURN},
 
-       {"goto",      SCF_LEX_WORD_KEY_GOTO},
-
        {"sizeof",    SCF_LEX_WORD_KEY_SIZEOF},
+       {"typeof",    SCF_LEX_WORD_KEY_TYPEOF},
 
        {"new",       SCF_LEX_WORD_KEY_NEW},
-
        {"operator",  SCF_LEX_WORD_KEY_OPERATOR},
 
        {"_",         SCF_LEX_WORD_KEY_UNDERLINE},
@@ -65,6 +72,7 @@ static scf_key_word_t  key_words[] =
        {"container", SCF_LEX_WORD_KEY_CONTAINER},
 
        {"class",     SCF_LEX_WORD_KEY_CLASS},
+       {"typedef",   SCF_LEX_WORD_KEY_TYPEDEF},
 
        {"const",     SCF_LEX_WORD_KEY_CONST},
        {"static",    SCF_LEX_WORD_KEY_STATIC},
@@ -72,9 +80,7 @@ static scf_key_word_t  key_words[] =
        {"inline",    SCF_LEX_WORD_KEY_INLINE},
 
        {"async",     SCF_LEX_WORD_KEY_ASYNC},
-
-       {"include",   SCF_LEX_WORD_KEY_INCLUDE},
-       {"define",    SCF_LEX_WORD_KEY_DEFINE},
+       {"await",     SCF_LEX_WORD_KEY_AWAIT},
 
        {"enum",      SCF_LEX_WORD_KEY_ENUM},
        {"union",     SCF_LEX_WORD_KEY_UNION},
@@ -679,8 +685,7 @@ int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                        || '\r' == c->c || '\t' == c->c
                        || ' '  == c->c || '\\' == c->c) {
 
-               if ('\n' == c->c)
-               {
+               if ('\n' == c->c) {
                        if (SCF_UTF8_LF == c->flag || lex->asm_flag)
                        {
                                w       = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_LF);
@@ -956,522 +961,6 @@ int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
        return -1;
 }
 
-static int __parse_macro_argv(scf_lex_t* lex, scf_macro_t* m)
-{
-       scf_lex_word_t* w = NULL;
-       scf_lex_word_t* w2;
-
-       int comma = 0;
-       int id    = 0;
-
-       while (1) {
-               int ret = __lex_pop_word(lex, &w);
-               if (ret < 0)
-                       return ret;
-
-               if (!comma) {
-                       if (SCF_LEX_WORD_RP == w->type) {
-                               scf_lex_word_free(w);
-                               break;
-                       }
-
-                       if (SCF_LEX_WORD_COMMA == w->type) {
-                               scf_lex_word_free(w);
-                               w = NULL;
-
-                               if (!id) {
-                                       scf_loge("an identity is needed before ',' in file: %s, line: %d\n", w->file->data, w->line);
-                                       return -1;
-                               }
-
-                               id    = 0;
-                               comma = 1;
-                               continue;
-                       }
-               }
-
-               if (!scf_lex_is_identity(w)) {
-                       scf_loge("macro arg '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
-                       scf_lex_word_free(w);
-                       return -1;
-               }
-
-               if (id) {
-                       scf_loge("',' is needed before macro arg '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
-                       scf_lex_word_free(w);
-                       return -1;
-               }
-
-               int i;
-               for (i = 0; i < m->argv->size; i++) {
-                       w2 =        m->argv->data[i];
-
-                       if (!scf_string_cmp(w2->text, w->text)) {
-                               scf_loge("macro has same args '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
-                               scf_lex_word_free(w);
-                               return -1;
-                       }
-               }
-
-               scf_logw("macro '%s' arg: %s\n", m->w->text->data, w->text->data);
-
-               ret = scf_vector_add(m->argv, w);
-               if (ret < 0) {
-                       scf_lex_word_free(w);
-                       return ret;
-               }
-               w = NULL;
-
-               id    = 1;
-               comma = 0;
-       }
-
-       return 0;
-}
-
-static int __parse_macro_define(scf_lex_t* lex)
-{
-       scf_lex_word_t** pp;
-       scf_lex_word_t*  w = NULL;
-       scf_macro_t*     m;
-       scf_macro_t*     m0;
-
-       int ret = __lex_pop_word(lex, &w);
-       if (ret < 0)
-               return ret;
-
-       if (!scf_lex_is_identity(w)) {
-               scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
-               scf_lex_word_free(w);
-               return -1;
-       }
-
-       m = scf_macro_alloc(w);
-       if (!m) {
-               scf_lex_word_free(w);
-               return -ENOMEM;
-       }
-
-       w   = NULL;
-       ret = __lex_pop_word(lex, &w);
-       if (ret < 0) {
-               scf_macro_free(m);
-               return ret;
-       }
-
-       pp = &m->text_list;
-
-       if (SCF_LEX_WORD_LP == w->type) {
-               scf_lex_word_free(w);
-               w = NULL;
-
-               m->argv = scf_vector_alloc();
-               if (!m->argv) {
-                       scf_macro_free(m);
-                       return -ENOMEM;
-               }
-
-               ret = __parse_macro_argv(lex, m);
-               if (ret < 0) {
-                       scf_macro_free(m);
-                       return ret;
-               }
-       } else {
-               *pp =  w;
-               pp  = &w->next;
-               w   = NULL;
-       }
-
-       while (1) {
-               ret = __lex_pop_word(lex, &w);
-               if (ret < 0) {
-                       scf_macro_free(m);
-                       return ret;
-               }
-
-               if (SCF_LEX_WORD_LF == w->type) {
-                       scf_lex_word_free(w);
-                       w = NULL;
-                       break;
-               }
-
-               *pp =  w;
-               pp  = &w->next;
-               w   = NULL;
-       }
-
-       if (!lex->macros) {
-               lex->macros = scf_vector_alloc();
-               if (!lex->macros)
-                       return -ENOMEM;
-
-       } else {
-               int i;
-               for (i = lex->macros->size - 1; i >= 0; i--) {
-                       m0 = lex->macros->data[i];
-
-                       if (!scf_string_cmp(m->w->text, m0->w->text)) {
-                               scf_logw("macro '%s' defined before in file: %s, line: %d\n",
-                                               m0->w->text->data, m0->w->file->data, m0->w->line);
-                               break;
-                       }
-               }
-       }
-
-       ret = scf_vector_add(lex->macros, m);
-       if (ret < 0) {
-               scf_macro_free(m);
-               return ret;
-       }
-
-       return 0;
-}
-
-static int __fill_macro_argv(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use, scf_vector_t* argv)
-{
-       scf_lex_word_t** pp;
-       scf_lex_word_t*  w = NULL;
-
-       int ret = __lex_pop_word(lex, &w);
-       if (ret < 0)
-               return ret;
-
-       if (SCF_LEX_WORD_LP != w->type) {
-               scf_loge("macro '%s' needs args, file: %s, line: %d\n", m->w->text->data, w->file->data, w->line);
-               scf_lex_word_free(w);
-               return -1;
-       }
-
-       scf_lex_word_free(w);
-       w = NULL;
-
-       int n_lps = 0;
-       int n_rps = 0;
-       int i;
-
-       pp = NULL;
-
-       while (1) {
-               ret = __lex_pop_word(lex, &w);
-               if (ret < 0)
-                       return ret;
-
-               if (SCF_LEX_WORD_COMMA == w->type) {
-                       if (!pp) {
-                               scf_loge("unexpected ',' in macro '%s', file: %s, line: %d\n", m->w->text->data, w->file->data, w->line);
-
-                               scf_lex_word_free(w);
-                               ret = -1;
-                               goto error;
-                       }
-
-                       scf_lex_word_free(w);
-                       w  = NULL;
-
-                       if (n_rps == n_lps)
-                               pp = NULL;
-                       continue;
-
-               } else if (SCF_LEX_WORD_LP == w->type)
-                       n_lps++;
-               else if (SCF_LEX_WORD_RP == w->type) {
-                       n_rps++;
-
-                       if (n_rps > n_lps) {
-                               scf_lex_word_free(w);
-                               w = NULL;
-                               break;
-                       }
-               }
-
-               w->next = NULL;
-
-               if (pp)
-                       *pp = w;
-               else {
-                       ret = scf_vector_add(argv, w);
-                       if (ret < 0) {
-                               scf_lex_word_free(w);
-                               goto error;
-                       }
-               }
-
-               pp = &w->next;
-               w  = NULL;
-       }
-
-       if (m->argv->size != argv->size) {
-               scf_loge("macro '%s' needs %d args, but in fact give %d args,  file: %s, line: %d\n",
-                               m->w->text->data, m->argv->size, argv->size, use->file->data, use->line);
-               ret = -1;
-               goto error;
-       }
-
-       return 0;
-
-error:
-       for (i = 0; i < argv->size; i++) {
-               w  =        argv->data[i];
-               scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free);
-       }
-
-       argv->size = 0;
-       return ret;
-}
-
-static int __convert_str(scf_lex_word_t* h)
-{
-       scf_lex_word_t* w;
-       scf_string_t*   s;
-
-       if (h->type != SCF_LEX_WORD_CONST_STRING) {
-               h->type  = SCF_LEX_WORD_CONST_STRING;
-
-               h->data.s = scf_string_clone(h->text);
-               if (!h->data.s)
-                       return -ENOMEM;
-       }
-
-       while ( h->next) {
-               w = h->next;
-
-               if (SCF_LEX_WORD_CONST_STRING != w->type)
-                       s = w->text;
-               else
-                       s = w->data.s;
-
-               int ret = scf_string_cat(h->data.s, s);
-               if (ret < 0)
-                       return ret;
-
-               ret = scf_string_cat(h->text, w->text);
-               if (ret < 0)
-                       return ret;
-
-               h->next = w->next;
-
-               scf_lex_word_free(w);
-               w = NULL;
-       }
-
-       scf_logw("h: '%s', file: %s, line: %d\n", h->data.s->data, h->file->data, h->line);
-       return 0;
-}
-
-static scf_macro_t* __find_macro(scf_lex_t* lex, scf_lex_word_t* w)
-{
-       if (!lex->macros)
-               return NULL;
-
-       scf_macro_t* m;
-       int i;
-
-       for (i = lex->macros->size - 1; i >= 0; i--) {
-               m  = lex->macros->data[i];
-
-               if (!scf_string_cmp(m->w->text, w->text))
-                       return m;
-       }
-
-       return NULL;
-}
-
-static int __use_macro(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use)
-{
-       scf_lex_word_t** pp;
-       scf_lex_word_t*  p;
-       scf_lex_word_t*  h;
-       scf_lex_word_t*  w;
-       scf_lex_word_t*  prev;
-       scf_vector_t*    argv = NULL;
-
-       if (m->argv) {
-               argv = scf_vector_alloc();
-               if (!argv)
-                       return -ENOMEM;
-
-               int ret = __fill_macro_argv(lex, m, use, argv);
-               if (ret < 0) {
-                       scf_vector_free(argv);
-                       return ret;
-               }
-       }
-
-       h  = NULL;
-       pp = &h;
-
-       int ret  = 0;
-       int hash = 0;
-       int i;
-
-       for (p = m->text_list; p; p = p->next) {
-
-               if (SCF_LEX_WORD_HASH == p->type) {
-                       hash = 1;
-                       continue;
-               }
-
-               scf_logd("p: '%s', line: %d, hash: %d\n", p->text->data, p->line, hash);
-
-               if (m->argv) {
-                       assert(argv);
-                       assert(argv->size >= m->argv->size);
-
-                       for (i = 0; i < m->argv->size; i++) {
-                               w  =        m->argv->data[i];
-
-                               if (!scf_string_cmp(w->text, p->text))
-                                       break;
-                       }
-
-                       if (i < m->argv->size) {
-                               scf_lex_word_t** tmp = pp;
-
-                               for (w = argv->data[i]; w; w = w->next) {
-
-                                       *pp = scf_lex_word_clone(w);
-                                       if (!*pp) {
-                                               ret = -ENOMEM;
-                                               goto error;
-                                       }
-
-                                       if (!strcmp((*pp)->text->data, "__LINE__"))
-                                               (*pp)->data.u64 = use->line;
-
-                                       pp = &(*pp)->next;
-                               }
-
-                               if (1 == hash) {
-                                       ret = __convert_str(*tmp);
-                                       if (ret < 0)
-                                               goto error;
-
-                                       pp = &(*tmp)->next;
-                               }
-
-                               hash = 0;
-                               continue;
-                       }
-               }
-
-               *pp = scf_lex_word_clone(p);
-               if (!*pp) {
-                       ret = -ENOMEM;
-                       goto error;
-               }
-
-               if (!strcmp((*pp)->text->data, "__LINE__"))
-                       (*pp)->data.u64 = use->line;
-
-               pp = &(*pp)->next;
-
-               hash = 0;
-       }
-
-error:
-       if (argv) {
-               for (i = 0; i < argv->size; i++) {
-                       w  =        argv->data[i];
-
-                       if (w)
-                               scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free);
-               }
-
-               scf_vector_free(argv);
-               argv = NULL;
-       }
-
-       if (ret < 0) {
-               scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
-               return ret;
-       }
-
-#if 0
-       w = h;
-       while (w) {
-               scf_logi("---------- %s, line: %d\n", w->text->data, w->line);
-               w = w->next;
-       }
-#endif
-       *pp            = lex->word_list;
-       lex->word_list = h;
-       return 0;
-}
-
-static int __use_hash2(scf_lex_t* lex, scf_lex_word_t* prev)
-{
-       scf_lex_word_t* after = NULL;
-
-       int ret = __lex_pop_word(lex, &after);
-       if (ret < 0)
-               return ret;
-
-       switch (after->type) {
-
-               case SCF_LEX_WORD_ID:
-                       ret = scf_string_cat(prev->text, after->text);
-                       break;
-
-               default:
-                       ret = -1;
-                       scf_loge("needs identity after '##', file: %s, line: %d\n", after->file->data, after->line);
-                       break;
-       };
-
-       scf_lex_word_free(after);
-       return ret;
-}
-
-int __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp)
-{
-       scf_lex_word_t* w1 = NULL;
-       scf_lex_word_t* w  = *pp;
-       scf_macro_t*    m;
-
-       *pp = NULL;
-
-       while (SCF_LEX_WORD_ID == w->type) {
-
-               m = __find_macro(lex, w);
-               if (m) {
-                       int ret = __use_macro(lex, m, w);
-
-                       scf_lex_word_free(w);
-                       w = NULL;
-                       if (ret < 0)
-                               return ret;
-
-                       ret = __lex_pop_word(lex, &w);
-                       if (ret < 0)
-                               return ret;
-                       continue;
-               }
-
-               int ret = __lex_pop_word(lex, &w1);
-               if (ret < 0) {
-                       scf_lex_word_free(w);
-                       return ret;
-               }
-
-               if (SCF_LEX_WORD_HASH2 != w1->type) {
-                       scf_lex_push_word(lex, w1);
-                       break;
-               }
-
-               scf_lex_word_free(w1);
-               w1 = NULL;
-
-               ret = __use_hash2(lex, w);
-               if (ret < 0) {
-                       scf_lex_word_free(w);
-                       return ret;
-               }
-       }
-
-       *pp = w;
-       return 0;
-}
-
 int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
 {
        if (!lex || !lex->fp || !pword)
@@ -1496,6 +985,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                switch (w1->type) {
                        case SCF_LEX_WORD_KEY_INCLUDE:
                        case SCF_LEX_WORD_KEY_IF:
+                       case SCF_LEX_WORD_KEY_ELIF:
                        case SCF_LEX_WORD_KEY_ELSE:
                        case SCF_LEX_WORD_KEY_ENDIF:
 
@@ -1504,8 +994,19 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                                return 0;
                                break;
 
+                       case SCF_LEX_WORD_KEY_IFNDEF:
+                               ret = __parse_macro_ifdef(lex, 0);
+                               break;
+                       case SCF_LEX_WORD_KEY_IFDEF:
+                               ret = __parse_macro_ifdef(lex, 1);
+                               break;
+
                        case SCF_LEX_WORD_KEY_DEFINE:
-                               ret = __parse_macro_define(lex);
+                               ret = __parse_macro_define(lex, 1);
+                               break;
+
+                       case SCF_LEX_WORD_KEY_UNDEF:
+                               ret = __parse_macro_define(lex, 0);
                                break;
 
                        default:
@@ -1516,7 +1017,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                                }
 
                                scf_loge("unknown macro '%s', file: %s, line: %d\n", w1->text->data, w1->file->data, w1->line);
-                               ret = -1;
+                               ret = -EINVAL;
                                break;
                };
 
index d875be62014f74a1a2eafb5131c2a725594830c1..386ab3abe218d3de150aa7d082842c5f9a9f055a 100644 (file)
@@ -61,6 +61,10 @@ void scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t*   word);
 int  scf_lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
 
 int    __lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
+int    __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp);
+
+int    __parse_macro_define(scf_lex_t* lex, int def_flag);
+int    __parse_macro_ifdef (scf_lex_t* lex, int def_flag);
 
 int _lex_number_base_16(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
 int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
diff --git a/lex/scf_macro.c b/lex/scf_macro.c
new file mode 100644 (file)
index 0000000..b8c1a71
--- /dev/null
@@ -0,0 +1,756 @@
+#include"scf_lex.h"
+
+static int __macro_drop_to_LF(scf_lex_t* lex)
+{
+       scf_lex_word_t* w = NULL;
+       int type;
+
+       do {
+               int ret = __lex_pop_word(lex, &w);
+               if (ret < 0)
+                       return ret;
+
+               type = w->type;
+               scf_lex_word_free(w);
+               w = NULL;
+
+       } while (SCF_LEX_WORD_LF != type);
+
+       return 0;
+}
+
+static int __macro_drop_to(scf_lex_t* lex, scf_lex_word_t** pw1, scf_lex_word_t** pw2)
+{
+       scf_lex_word_t* w1 = NULL;
+       scf_lex_word_t* w2 = NULL;
+
+       int n_if = 1;
+
+       while (1) {
+               if (!w1) {
+                       int ret = __lex_pop_word(lex, &w1);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               if (SCF_LEX_WORD_HASH != w1->type) {
+                       scf_lex_word_free(w1);
+                       w1 = NULL;
+                       continue;
+               }
+
+               int ret = __lex_pop_word(lex, &w2);
+               if (ret < 0) {
+                       scf_lex_word_free(w1);
+                       return ret;
+               }
+
+               switch (w2->type)
+               {
+                       case SCF_LEX_WORD_KEY_IF:
+                       case SCF_LEX_WORD_KEY_IFDEF:
+                       case SCF_LEX_WORD_KEY_IFNDEF:
+                               n_if++;
+                               break;
+
+                       case SCF_LEX_WORD_KEY_ELIF:
+                       case SCF_LEX_WORD_KEY_ELSE:
+                               if (n_if <= 1)
+                                       goto end;
+                               break;
+
+                       case SCF_LEX_WORD_KEY_ENDIF:
+                               if (0 == --n_if)
+                                       goto end;
+                               break;
+               };
+
+               scf_lex_word_free(w1);
+               w1 = w2;
+       }
+
+end:
+       *pw1 = w1;
+       *pw2 = w2;
+       return 0;
+}
+
+static int __macro_pop_to(scf_lex_t* lex, scf_lex_word_t** h, scf_lex_word_t** pw1, scf_lex_word_t** pw2)
+{
+       scf_lex_word_t* w1 = NULL;
+       scf_lex_word_t* w2 = NULL;
+
+       int n_if = 1;
+
+       while (1) {
+               if (!w1) {
+                       int ret = __lex_pop_word(lex, &w1);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               if (SCF_LEX_WORD_HASH != w1->type) {
+                       w1->next = *h;
+                       *h = w1;
+                       w1 = NULL;
+                       continue;
+               }
+
+               int ret = __lex_pop_word(lex, &w2);
+               if (ret < 0) {
+                       scf_lex_word_free(w1);
+                       return ret;
+               }
+
+               switch (w2->type)
+               {
+                       case SCF_LEX_WORD_KEY_IF:
+                       case SCF_LEX_WORD_KEY_IFDEF:
+                       case SCF_LEX_WORD_KEY_IFNDEF:
+                               n_if++;
+                               break;
+
+                       case SCF_LEX_WORD_KEY_ELIF:
+                       case SCF_LEX_WORD_KEY_ELSE:
+                               if (n_if <= 1)
+                                       goto end;
+                               break;
+
+                       case SCF_LEX_WORD_KEY_ENDIF:
+                               if (0 == --n_if)
+                                       goto end;
+                               break;
+               };
+
+               w1->next = *h;
+               *h = w1;
+               w1 = w2;
+       }
+
+end:
+       *pw1 = w1;
+       *pw2 = w2;
+       return 0;
+}
+
+static int __parse_macro_argv(scf_lex_t* lex, scf_macro_t* m)
+{
+       scf_lex_word_t* w = NULL;
+       scf_lex_word_t* w2;
+
+       int comma = 0;
+       int id    = 0;
+
+       while (1) {
+               int ret = __lex_pop_word(lex, &w);
+               if (ret < 0)
+                       return ret;
+
+               if (!comma) {
+                       if (SCF_LEX_WORD_RP == w->type) {
+                               scf_lex_word_free(w);
+                               break;
+                       }
+
+                       if (SCF_LEX_WORD_COMMA == w->type) {
+                               scf_lex_word_free(w);
+                               w = NULL;
+
+                               if (!id) {
+                                       scf_loge("an identity is needed before ',' in file: %s, line: %d\n", w->file->data, w->line);
+                                       return -EINVAL;
+                               }
+
+                               id    = 0;
+                               comma = 1;
+                               continue;
+                       }
+               }
+
+               if (!scf_lex_is_identity(w)) {
+                       scf_loge("macro arg '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                       scf_lex_word_free(w);
+                       return -EINVAL;
+               }
+
+               if (id) {
+                       scf_loge("',' is needed before macro arg '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                       scf_lex_word_free(w);
+                       return -EINVAL;
+               }
+
+               int i;
+               for (i = 0; i < m->argv->size; i++) {
+                       w2 =        m->argv->data[i];
+
+                       if (!scf_string_cmp(w2->text, w->text)) {
+                               scf_loge("macro has same args '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                               scf_lex_word_free(w);
+                               return -EINVAL;
+                       }
+               }
+
+               scf_logw("macro '%s' arg: %s\n", m->w->text->data, w->text->data);
+
+               ret = scf_vector_add(m->argv, w);
+               if (ret < 0) {
+                       scf_lex_word_free(w);
+                       return ret;
+               }
+               w = NULL;
+
+               id    = 1;
+               comma = 0;
+       }
+
+       return 0;
+}
+
+int __parse_macro_define(scf_lex_t* lex, int def_flag)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  w = NULL;
+       scf_macro_t*     m;
+       scf_macro_t*     m0;
+
+       int ret = __lex_pop_word(lex, &w);
+       if (ret < 0)
+               return ret;
+
+       if (!scf_lex_is_identity(w)) {
+               scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+               scf_lex_word_free(w);
+               return -EINVAL;
+       }
+
+       m = scf_macro_alloc(w);
+       if (!m) {
+               scf_lex_word_free(w);
+               return -ENOMEM;
+       }
+
+       w   = NULL;
+       ret = __lex_pop_word(lex, &w);
+       if (ret < 0) {
+               scf_macro_free(m);
+               return ret;
+       }
+
+       if (SCF_LEX_WORD_LP == w->type) {
+               scf_lex_word_free(w);
+               w = NULL;
+
+               m->argv = scf_vector_alloc();
+               if (!m->argv) {
+                       scf_macro_free(m);
+                       return -ENOMEM;
+               }
+
+               ret = __parse_macro_argv(lex, m);
+               if (ret < 0) {
+                       scf_macro_free(m);
+                       return ret;
+               }
+       }
+
+       pp = &m->text_list;
+
+       while (1) {
+               if (w) {
+                       scf_logw("w: '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+
+                       if (SCF_LEX_WORD_LF == w->type) {
+                               scf_lex_word_free(w);
+                               w = NULL;
+                               break;
+                       }
+
+                       *pp =  w;
+                        pp = &w->next;
+                        w  = NULL;
+               }
+
+               ret = __lex_pop_word(lex, &w);
+               if (ret < 0) {
+                       scf_macro_free(m);
+                       return ret;
+               }
+       }
+
+       if (lex->macros) {
+               int i;
+               for (i = lex->macros->size - 1; i >= 0; i--) {
+                       m0 = lex->macros->data[i];
+
+                       if (!scf_string_cmp(m->w->text, m0->w->text)) {
+                               scf_logw("macro '%s' defined before in file: %s, line: %d\n",
+                                               m0->w->text->data, m0->w->file->data, m0->w->line);
+                               break;
+                       }
+               }
+       } else {
+               lex->macros = scf_vector_alloc();
+               if (!lex->macros)
+                       return -ENOMEM;
+       }
+
+       ret = scf_vector_add(lex->macros, m);
+       if (ret < 0) {
+               scf_macro_free(m);
+               return ret;
+       }
+
+       m->def_flag = def_flag;
+
+       scf_logw("macro '%s', def_flag: %d, file: %s, line: %d\n",
+                       m->w->text->data, m->def_flag, m->w->file->data, m->w->line);
+       return 0;
+}
+
+int __parse_macro_ifdef(scf_lex_t* lex, int def_flag)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  w = NULL;
+       scf_macro_t*     m;
+
+       int ret = __lex_pop_word(lex, &w);
+       if (ret < 0)
+               return ret;
+
+       if (!scf_lex_is_identity(w)) {
+               scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+               scf_lex_word_free(w);
+               return -EINVAL;
+       }
+
+       ret = __macro_drop_to_LF(lex);
+       if (ret < 0)
+               return ret;
+
+       int found = 0;
+       int i;
+
+       if (lex->macros) {
+               for (i = lex->macros->size - 1; i >= 0; i--) {
+                       m  = lex->macros->data[i];
+
+                       if (m->def_flag && !scf_string_cmp(m->w->text, w->text)) {
+                               found = 1;
+                               break;
+                       }
+               }
+       }
+
+       scf_logw("macro '%s', found: %d, def_flag: %d, file: %s, line: %d\n",
+                       w->text->data, found, def_flag, w->file->data, w->line);
+
+       scf_lex_word_t*  h  = NULL;
+       scf_lex_word_t*  w1 = NULL;
+       scf_lex_word_t*  w2 = NULL;
+
+       if (found != def_flag) {
+               ret = __macro_drop_to(lex, &w1, &w2);
+               if (ret < 0)
+                       return ret;
+
+               if (SCF_LEX_WORD_KEY_ENDIF == w2->type) {
+                       scf_lex_word_free(w2);
+                       scf_lex_word_free(w1);
+
+                       return __macro_drop_to_LF(lex);
+               }
+
+               scf_lex_push_word(lex, w2);
+               scf_lex_push_word(lex, w1);
+               return 0;
+       }
+
+       ret = __macro_pop_to(lex, &h, &w1, &w2);
+       if (ret < 0) {
+               scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
+               return ret;
+       }
+
+       int type = w2->type;
+
+       scf_lex_word_free(w2);
+       scf_lex_word_free(w1);
+       w1 = NULL;
+       w2 = NULL;
+
+       while (SCF_LEX_WORD_KEY_ENDIF != type) {
+
+               ret = __macro_drop_to(lex, &w1, &w2);
+               if (ret < 0) {
+                       scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
+                       return ret;
+               }
+
+               type = w2->type;
+
+               scf_lex_word_free(w2);
+               scf_lex_word_free(w1);
+               w1 = NULL;
+               w2 = NULL;
+       }
+
+       ret = __macro_drop_to_LF(lex);
+       if (ret < 0) {
+               scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
+               return ret;
+       }
+
+       while (h) {
+               w1 = h;
+               h  = h->next;
+
+               scf_lex_push_word(lex, w1);
+       }
+
+       return 0;
+}
+
+static int __fill_macro_argv(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use, scf_vector_t* argv)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  w = NULL;
+
+       int ret = __lex_pop_word(lex, &w);
+       if (ret < 0)
+               return ret;
+
+       if (SCF_LEX_WORD_LP != w->type) {
+               scf_loge("macro '%s' needs args, file: %s, line: %d\n", m->w->text->data, w->file->data, w->line);
+               scf_lex_word_free(w);
+               return -1;
+       }
+
+       scf_lex_word_free(w);
+       w = NULL;
+
+       int n_lps = 0;
+       int n_rps = 0;
+       int i;
+
+       pp = NULL;
+
+       while (1) {
+               ret = __lex_pop_word(lex, &w);
+               if (ret < 0)
+                       return ret;
+
+               if (SCF_LEX_WORD_COMMA == w->type) {
+                       if (!pp) {
+                               scf_loge("unexpected ',' in macro '%s', file: %s, line: %d\n", m->w->text->data, w->file->data, w->line);
+
+                               scf_lex_word_free(w);
+                               ret = -1;
+                               goto error;
+                       }
+
+                       scf_lex_word_free(w);
+                       w  = NULL;
+
+                       if (n_rps == n_lps)
+                               pp = NULL;
+                       continue;
+
+               } else if (SCF_LEX_WORD_LP == w->type)
+                       n_lps++;
+               else if (SCF_LEX_WORD_RP == w->type) {
+                       n_rps++;
+
+                       if (n_rps > n_lps) {
+                               scf_lex_word_free(w);
+                               w = NULL;
+                               break;
+                       }
+               }
+
+               w->next = NULL;
+
+               if (pp)
+                       *pp = w;
+               else {
+                       ret = scf_vector_add(argv, w);
+                       if (ret < 0) {
+                               scf_lex_word_free(w);
+                               goto error;
+                       }
+               }
+
+               pp = &w->next;
+               w  = NULL;
+       }
+
+       if (m->argv->size != argv->size) {
+               scf_loge("macro '%s' needs %d args, but in fact give %d args,  file: %s, line: %d\n",
+                               m->w->text->data, m->argv->size, argv->size, use->file->data, use->line);
+               ret = -1;
+               goto error;
+       }
+
+       return 0;
+
+error:
+       for (i = 0; i < argv->size; i++) {
+               w  =        argv->data[i];
+               scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free);
+       }
+
+       argv->size = 0;
+       return ret;
+}
+
+static int __convert_str(scf_lex_word_t* h)
+{
+       scf_lex_word_t* w;
+       scf_string_t*   s;
+
+       if (h->type != SCF_LEX_WORD_CONST_STRING) {
+               h->type  = SCF_LEX_WORD_CONST_STRING;
+
+               h->data.s = scf_string_clone(h->text);
+               if (!h->data.s)
+                       return -ENOMEM;
+       }
+
+       while ( h->next) {
+               w = h->next;
+
+               if (SCF_LEX_WORD_CONST_STRING != w->type)
+                       s = w->text;
+               else
+                       s = w->data.s;
+
+               int ret = scf_string_cat(h->data.s, s);
+               if (ret < 0)
+                       return ret;
+
+               ret = scf_string_cat(h->text, w->text);
+               if (ret < 0)
+                       return ret;
+
+               h->next = w->next;
+
+               scf_lex_word_free(w);
+               w = NULL;
+       }
+
+       scf_logw("h: '%s', file: %s, line: %d\n", h->data.s->data, h->file->data, h->line);
+       return 0;
+}
+
+static scf_macro_t* __find_macro(scf_lex_t* lex, scf_lex_word_t* w)
+{
+       if (!lex->macros)
+               return NULL;
+
+       scf_macro_t* m;
+       int i;
+
+       for (i = lex->macros->size - 1; i >= 0; i--) {
+               m  = lex->macros->data[i];
+
+               if (!scf_string_cmp(m->w->text, w->text))
+                       return m;
+       }
+
+       return NULL;
+}
+
+static int __use_macro(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  p;
+       scf_lex_word_t*  h;
+       scf_lex_word_t*  w;
+       scf_lex_word_t*  prev;
+       scf_vector_t*    argv = NULL;
+
+       if (m->argv) {
+               argv = scf_vector_alloc();
+               if (!argv)
+                       return -ENOMEM;
+
+               int ret = __fill_macro_argv(lex, m, use, argv);
+               if (ret < 0) {
+                       scf_vector_free(argv);
+                       return ret;
+               }
+       }
+
+       h  = NULL;
+       pp = &h;
+
+       int ret  = 0;
+       int hash = 0;
+       int i;
+
+       for (p = m->text_list; p; p = p->next) {
+
+               if (SCF_LEX_WORD_HASH == p->type) {
+                       hash = 1;
+                       continue;
+               }
+
+               scf_logd("p: '%s', line: %d, hash: %d\n", p->text->data, p->line, hash);
+
+               if (m->argv) {
+                       assert(argv);
+                       assert(argv->size >= m->argv->size);
+
+                       for (i = 0; i < m->argv->size; i++) {
+                               w  =        m->argv->data[i];
+
+                               if (!scf_string_cmp(w->text, p->text))
+                                       break;
+                       }
+
+                       if (i < m->argv->size) {
+                               scf_lex_word_t** tmp = pp;
+
+                               for (w = argv->data[i]; w; w = w->next) {
+
+                                       *pp = scf_lex_word_clone(w);
+                                       if (!*pp) {
+                                               ret = -ENOMEM;
+                                               goto error;
+                                       }
+
+                                       if (!strcmp((*pp)->text->data, "__LINE__"))
+                                               (*pp)->data.u64 = use->line;
+
+                                       pp = &(*pp)->next;
+                               }
+
+                               if (1 == hash) {
+                                       ret = __convert_str(*tmp);
+                                       if (ret < 0)
+                                               goto error;
+
+                                       pp = &(*tmp)->next;
+                               }
+
+                               hash = 0;
+                               continue;
+                       }
+               }
+
+               *pp = scf_lex_word_clone(p);
+               if (!*pp) {
+                       ret = -ENOMEM;
+                       goto error;
+               }
+
+               if (!strcmp((*pp)->text->data, "__LINE__"))
+                       (*pp)->data.u64 = use->line;
+
+               pp = &(*pp)->next;
+
+               hash = 0;
+       }
+
+error:
+       if (argv) {
+               for (i = 0; i < argv->size; i++) {
+                       w  =        argv->data[i];
+
+                       if (w)
+                               scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free);
+               }
+
+               scf_vector_free(argv);
+               argv = NULL;
+       }
+
+       if (ret < 0) {
+               scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
+               return ret;
+       }
+
+#if 0
+       w = h;
+       while (w) {
+               scf_logi("---------- %s, line: %d\n", w->text->data, w->line);
+               w = w->next;
+       }
+#endif
+       *pp            = lex->word_list;
+       lex->word_list = h;
+       return 0;
+}
+
+static int __use_hash2(scf_lex_t* lex, scf_lex_word_t* prev)
+{
+       scf_lex_word_t* after = NULL;
+
+       int ret = __lex_pop_word(lex, &after);
+       if (ret < 0)
+               return ret;
+
+       switch (after->type) {
+
+               case SCF_LEX_WORD_ID:
+                       ret = scf_string_cat(prev->text, after->text);
+                       break;
+
+               default:
+                       ret = -1;
+                       scf_loge("needs identity after '##', file: %s, line: %d\n", after->file->data, after->line);
+                       break;
+       };
+
+       scf_lex_word_free(after);
+       return ret;
+}
+
+int __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp)
+{
+       scf_lex_word_t* w1 = NULL;
+       scf_lex_word_t* w  = *pp;
+       scf_macro_t*    m;
+
+       *pp = NULL;
+
+       while (SCF_LEX_WORD_ID == w->type) {
+
+               m = __find_macro(lex, w);
+               if (m) {
+                       int ret = __use_macro(lex, m, w);
+
+                       scf_lex_word_free(w);
+                       w = NULL;
+                       if (ret < 0)
+                               return ret;
+
+                       ret = __lex_pop_word(lex, &w);
+                       if (ret < 0)
+                               return ret;
+                       continue;
+               }
+
+               int ret = __lex_pop_word(lex, &w1);
+               if (ret < 0) {
+                       scf_lex_word_free(w);
+                       return ret;
+               }
+
+               if (SCF_LEX_WORD_HASH2 != w1->type) {
+                       scf_lex_push_word(lex, w1);
+                       break;
+               }
+
+               scf_lex_word_free(w1);
+               w1 = NULL;
+
+               ret = __use_hash2(lex, w);
+               if (ret < 0) {
+                       scf_lex_word_free(w);
+                       return ret;
+               }
+       }
+
+       *pp = w;
+       return 0;
+}
diff --git a/native/eda/Makefile b/native/eda/Makefile
deleted file mode 100644 (file)
index 4875440..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CFILES += main.c
-CFILES += scf_eda.pb-c.c
-CFILES += scf_eda_pb.c
-
-CFLAGS += -g
-CFLAGS += -I./
-CFLAGS += -I../../util
-
-LDFLAGS += -lprotobuf-c
-
-all:
-       gcc $(CFLAGS) $(CFILES) $(LDFLAGS)
-
-clean:
-       rm *.o
diff --git a/native/eda/main.c b/native/eda/main.c
deleted file mode 100644 (file)
index b758323..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include"scf_eda_pb.h"
-#include"scf_def.h"
-
-
-int main()
-{
-       ScfEcomponent* r      = scf_ecomponent__alloc(SCF_EDA_None);
-       ScfEcomponent* d0     = scf_ecomponent__alloc(SCF_EDA_None);
-       ScfEcomponent* d1     = scf_ecomponent__alloc(SCF_EDA_None);
-
-       ScfEpin*       rp0    = scf_epin__alloc();
-       ScfEpin*       rp1    = scf_epin__alloc();
-
-       ScfEpin*       d0p0   = scf_epin__alloc();
-       ScfEpin*       d0p1   = scf_epin__alloc();
-
-       ScfEpin*       d1p0   = scf_epin__alloc();
-       ScfEpin*       d1p1   = scf_epin__alloc();
-
-       ScfEpin*       rps[]  = {rp0,  rp1};
-       ScfEpin*       d0ps[] = {d0p0, d0p1};
-       ScfEpin*       d1ps[] = {d1p0, d1p1};
-
-       int64_t c[] = {1, 2};
-       int64_t b[] = {0, 2};
-       int64_t a[] = {0, 1};
-
-       scf_epin__add_component(rp1, 1, SCF_EDA_Diode_NEG);
-       scf_epin__add_component(rp1, 2, SCF_EDA_Diode_NEG);
-
-       scf_epin__add_component(d0p1, 0, 0);
-       scf_epin__add_component(d0p1, 2, SCF_EDA_Diode_NEG);
-
-       scf_epin__add_component(d1p1, 0, 0);
-       scf_epin__add_component(d1p1, 1, SCF_EDA_Diode_NEG);
-
-       r->id      = 0;
-       r->type    = SCF_EDA_Resistor;
-       scf_ecomponent__add_pin(r, rp0);
-       scf_ecomponent__add_pin(r, rp1);
-
-       d0->id     = 1;
-       d0->type   = SCF_EDA_Diode;
-       scf_ecomponent__add_pin(d0, d0p0);
-       scf_ecomponent__add_pin(d0, d0p1);
-
-       d1->id     = 2;
-       d1->type   = SCF_EDA_Diode;
-       scf_ecomponent__add_pin(d1, d1p0);
-       scf_ecomponent__add_pin(d1, d1p1);
-
-       ScfEfunction* f = scf_efunction__alloc("test");
-       scf_efunction__add_component(f, r);
-       scf_efunction__add_component(f, d0);
-       scf_efunction__add_component(f, d1);
-
-       ScfEboard* board = scf_eboard__alloc();
-       scf_eboard__add_function(board, f);
-
-       size_t rlen  = scf_ecomponent__get_packed_size(r);
-       size_t d0len = scf_ecomponent__get_packed_size(d0);
-       size_t d1len = scf_ecomponent__get_packed_size(d1);
-       size_t flen  = scf_efunction__get_packed_size(f);
-       size_t blen  = scf_eboard__get_packed_size(board);
-
-       printf("rlen: %ld, d0len: %ld, d1len: %ld, flen: %ld, blen: %ld\n", rlen, d0len, d1len, flen, blen);
-
-       uint8_t pb[1024];
-
-       scf_eboard__pack(board, pb);
-
-       ScfEboard* p = scf_eboard__unpack(NULL, blen, pb);
-
-       printf("p: %p\n", p);
-       size_t i;
-       size_t j;
-       size_t k;
-       size_t l;
-
-       for (i = 0; i < p->n_functions; i++) {
-               ScfEfunction* pf = p->functions[i];
-
-               printf("f: %s\n", pf->name);
-
-               for (l = 0; l < pf->n_components; l++) {
-                       ScfEcomponent* pc = pf->components[l];
-
-                       printf("i: %ld, pc: %p, id: %ld, cid: %ld, n_pins: %ld\n", i, pc, pc->id, pc->type, pc->n_pins);
-
-                       for (j = 0; j < pc->n_pins; j++) {
-                               ScfEpin* pp = pc->pins[j];
-
-                               printf("j: %ld, pp: %p, n_tos: %ld, cid: %ld, pid: %ld\n", j, pp, pp->n_tos, pp->cid, pp->id);
-
-                               for (k = 0; k + 1 < pp->n_tos; k += 2) {
-                                       printf("k: %ld, cid: %ld, pid: %ld\n", k, pp->tos[k], pp->tos[k + 1]);
-                               }
-                       }
-                       printf("\n");
-               }
-               printf("\n\n");
-       }
-
-       scf_eboard__free(board);
-
-       scf_eboard__free_unpacked(p, NULL);
-       return 0;
-}
diff --git a/native/eda/scf_eda.pb-c.c b/native/eda/scf_eda.pb-c.c
deleted file mode 100644 (file)
index 8a55620..0000000
+++ /dev/null
@@ -1,1499 +0,0 @@
-/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
-/* Generated from: scf_eda.proto */
-
-/* Do not generate deprecated warnings for self */
-#ifndef PROTOBUF_C__NO_DEPRECATED
-#define PROTOBUF_C__NO_DEPRECATED
-#endif
-
-#include "scf_eda.pb-c.h"
-void   scf_line__init
-                     (ScfLine         *message)
-{
-  static ScfLine init_value = SCF_LINE__INIT;
-  *message = init_value;
-}
-size_t scf_line__get_packed_size
-                     (const ScfLine *message)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_line__pack
-                     (const ScfLine *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_line__pack_to_buffer
-                     (const ScfLine *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfLine *
-       scf_line__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfLine *)
-     protobuf_c_message_unpack (&scf_line__descriptor,
-                                allocator, len, data);
-}
-void   scf_line__free_unpacked
-                     (ScfLine *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_epin__init
-                     (ScfEpin         *message)
-{
-  static ScfEpin init_value = SCF_EPIN__INIT;
-  *message = init_value;
-}
-size_t scf_epin__get_packed_size
-                     (const ScfEpin *message)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_epin__pack
-                     (const ScfEpin *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_epin__pack_to_buffer
-                     (const ScfEpin *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEpin *
-       scf_epin__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEpin *)
-     protobuf_c_message_unpack (&scf_epin__descriptor,
-                                allocator, len, data);
-}
-void   scf_epin__free_unpacked
-                     (ScfEpin *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_econn__init
-                     (ScfEconn         *message)
-{
-  static ScfEconn init_value = SCF_ECONN__INIT;
-  *message = init_value;
-}
-size_t scf_econn__get_packed_size
-                     (const ScfEconn *message)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_econn__pack
-                     (const ScfEconn *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_econn__pack_to_buffer
-                     (const ScfEconn *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEconn *
-       scf_econn__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEconn *)
-     protobuf_c_message_unpack (&scf_econn__descriptor,
-                                allocator, len, data);
-}
-void   scf_econn__free_unpacked
-                     (ScfEconn *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_eline__init
-                     (ScfEline         *message)
-{
-  static ScfEline init_value = SCF_ELINE__INIT;
-  *message = init_value;
-}
-size_t scf_eline__get_packed_size
-                     (const ScfEline *message)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_eline__pack
-                     (const ScfEline *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEline *
-       scf_eline__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEline *)
-     protobuf_c_message_unpack (&scf_eline__descriptor,
-                                allocator, len, data);
-}
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_ecomponent__init
-                     (ScfEcomponent         *message)
-{
-  static ScfEcomponent init_value = SCF_ECOMPONENT__INIT;
-  *message = init_value;
-}
-size_t scf_ecomponent__get_packed_size
-                     (const ScfEcomponent *message)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_ecomponent__pack
-                     (const ScfEcomponent *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_ecomponent__pack_to_buffer
-                     (const ScfEcomponent *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEcomponent *
-       scf_ecomponent__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEcomponent *)
-     protobuf_c_message_unpack (&scf_ecomponent__descriptor,
-                                allocator, len, data);
-}
-void   scf_ecomponent__free_unpacked
-                     (ScfEcomponent *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_efunction__init
-                     (ScfEfunction         *message)
-{
-  static ScfEfunction init_value = SCF_EFUNCTION__INIT;
-  *message = init_value;
-}
-size_t scf_efunction__get_packed_size
-                     (const ScfEfunction *message)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_efunction__pack
-                     (const ScfEfunction *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_efunction__pack_to_buffer
-                     (const ScfEfunction *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEfunction *
-       scf_efunction__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEfunction *)
-     protobuf_c_message_unpack (&scf_efunction__descriptor,
-                                allocator, len, data);
-}
-void   scf_efunction__free_unpacked
-                     (ScfEfunction *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_eboard__init
-                     (ScfEboard         *message)
-{
-  static ScfEboard init_value = SCF_EBOARD__INIT;
-  *message = init_value;
-}
-size_t scf_eboard__get_packed_size
-                     (const ScfEboard *message)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_eboard__pack
-                     (const ScfEboard *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_eboard__pack_to_buffer
-                     (const ScfEboard *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEboard *
-       scf_eboard__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEboard *)
-     protobuf_c_message_unpack (&scf_eboard__descriptor,
-                                allocator, len, data);
-}
-void   scf_eboard__free_unpacked
-                     (ScfEboard *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-static const ProtobufCFieldDescriptor scf_line__field_descriptors[4] =
-{
-  {
-    "x0",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, x0),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y0",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, y0),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x1",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, x1),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y1",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, y1),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_line__field_indices_by_name[] = {
-  0,   /* field[0] = x0 */
-  2,   /* field[2] = x1 */
-  1,   /* field[1] = y0 */
-  3,   /* field[3] = y1 */
-};
-static const ProtobufCIntRange scf_line__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 4 }
-};
-const ProtobufCMessageDescriptor scf_line__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_line",
-  "ScfLine",
-  "ScfLine",
-  "",
-  sizeof(ScfLine),
-  4,
-  scf_line__field_descriptors,
-  scf_line__field_indices_by_name,
-  1,  scf_line__number_ranges,
-  (ProtobufCMessageInit) scf_line__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_epin__field_descriptors[30] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "cid",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, cid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lid",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "flags",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, flags),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "tos",
-    5,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEpin, n_tos),
-    offsetof(ScfEpin, tos),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "c_lid",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, c_lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "r",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, r),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jr",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uF",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, uf),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uH",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, uh),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "hfe",
-    15,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, hfe),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "dr",
-    16,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, dr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jdr",
-    17,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jdr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "sr",
-    18,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, sr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jsr",
-    19,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jsr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pr",
-    20,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, pr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jpr",
-    21,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jpr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "path",
-    22,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, path),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    23,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    24,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "n_diodes",
-    25,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, n_diodes),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "l_pos",
-    26,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, l_pos),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    27,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pflag",
-    28,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, pflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vconst",
-    29,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, vconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "aconst",
-    30,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, aconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_epin__field_indices_by_name[] = {
-  8,   /* field[8] = a */
-  29,   /* field[29] = aconst */
-  5,   /* field[5] = c_lid */
-  1,   /* field[1] = cid */
-  15,   /* field[15] = dr */
-  3,   /* field[3] = flags */
-  14,   /* field[14] = hfe */
-  0,   /* field[0] = id */
-  9,   /* field[9] = ja */
-  16,   /* field[16] = jdr */
-  20,   /* field[20] = jpr */
-  11,   /* field[11] = jr */
-  18,   /* field[18] = jsr */
-  7,   /* field[7] = jv */
-  25,   /* field[25] = l_pos */
-  2,   /* field[2] = lid */
-  24,   /* field[24] = n_diodes */
-  21,   /* field[21] = path */
-  27,   /* field[27] = pflag */
-  19,   /* field[19] = pr */
-  10,   /* field[10] = r */
-  17,   /* field[17] = sr */
-  4,   /* field[4] = tos */
-  12,   /* field[12] = uF */
-  13,   /* field[13] = uH */
-  6,   /* field[6] = v */
-  28,   /* field[28] = vconst */
-  26,   /* field[26] = vflag */
-  22,   /* field[22] = x */
-  23,   /* field[23] = y */
-};
-static const ProtobufCIntRange scf_epin__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 30 }
-};
-const ProtobufCMessageDescriptor scf_epin__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_epin",
-  "ScfEpin",
-  "ScfEpin",
-  "",
-  sizeof(ScfEpin),
-  30,
-  scf_epin__field_descriptors,
-  scf_epin__field_indices_by_name,
-  1,  scf_epin__number_ranges,
-  (ProtobufCMessageInit) scf_epin__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_econn__field_descriptors[2] =
-{
-  {
-    "lid",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEconn, lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "cids",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEconn, n_cids),
-    offsetof(ScfEconn, cids),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_econn__field_indices_by_name[] = {
-  1,   /* field[1] = cids */
-  0,   /* field[0] = lid */
-};
-static const ProtobufCIntRange scf_econn__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 2 }
-};
-const ProtobufCMessageDescriptor scf_econn__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_econn",
-  "ScfEconn",
-  "ScfEconn",
-  "",
-  sizeof(ScfEconn),
-  2,
-  scf_econn__field_descriptors,
-  scf_econn__field_indices_by_name,
-  1,  scf_econn__number_ranges,
-  (ProtobufCMessageInit) scf_econn__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_eline__field_descriptors[14] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pins",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEline, n_pins),
-    offsetof(ScfEline, pins),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "c_pins",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, c_pins),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "flags",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, flags),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "color",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, color),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "conns",
-    6,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEline, n_conns),
-    offsetof(ScfEline, conns),
-    &scf_econn__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lines",
-    7,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEline, n_lines),
-    offsetof(ScfEline, lines),
-    &scf_line__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vconst",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, vconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "aconst",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, aconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_eline__field_indices_by_name[] = {
-  9,   /* field[9] = a */
-  12,   /* field[12] = aconst */
-  2,   /* field[2] = c_pins */
-  4,   /* field[4] = color */
-  5,   /* field[5] = conns */
-  3,   /* field[3] = flags */
-  0,   /* field[0] = id */
-  10,   /* field[10] = ja */
-  8,   /* field[8] = jv */
-  6,   /* field[6] = lines */
-  1,   /* field[1] = pins */
-  7,   /* field[7] = v */
-  11,   /* field[11] = vconst */
-  13,   /* field[13] = vflag */
-};
-static const ProtobufCIntRange scf_eline__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 14 }
-};
-const ProtobufCMessageDescriptor scf_eline__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_eline",
-  "ScfEline",
-  "ScfEline",
-  "",
-  sizeof(ScfEline),
-  14,
-  scf_eline__field_descriptors,
-  scf_eline__field_indices_by_name,
-  1,  scf_eline__number_ranges,
-  (ProtobufCMessageInit) scf_eline__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_ecomponent__field_descriptors[20] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "type",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, type),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "model",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, model),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pins",
-    4,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEcomponent, n_pins),
-    offsetof(ScfEcomponent, pins),
-    &scf_epin__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "r",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, r),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jr",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, jr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uF",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, uf),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uH",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, uh),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "color",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, color),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "status",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, status),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    15,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    16,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "w",
-    17,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, w),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "h",
-    18,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, h),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    19,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lock",
-    20,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, lock),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_ecomponent__field_indices_by_name[] = {
-  6,   /* field[6] = a */
-  12,   /* field[12] = color */
-  17,   /* field[17] = h */
-  0,   /* field[0] = id */
-  7,   /* field[7] = ja */
-  9,   /* field[9] = jr */
-  5,   /* field[5] = jv */
-  19,   /* field[19] = lock */
-  2,   /* field[2] = model */
-  3,   /* field[3] = pins */
-  8,   /* field[8] = r */
-  13,   /* field[13] = status */
-  1,   /* field[1] = type */
-  10,   /* field[10] = uF */
-  11,   /* field[11] = uH */
-  4,   /* field[4] = v */
-  18,   /* field[18] = vflag */
-  16,   /* field[16] = w */
-  14,   /* field[14] = x */
-  15,   /* field[15] = y */
-};
-static const ProtobufCIntRange scf_ecomponent__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 20 }
-};
-const ProtobufCMessageDescriptor scf_ecomponent__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_ecomponent",
-  "ScfEcomponent",
-  "ScfEcomponent",
-  "",
-  sizeof(ScfEcomponent),
-  20,
-  scf_ecomponent__field_descriptors,
-  scf_ecomponent__field_indices_by_name,
-  1,  scf_ecomponent__number_ranges,
-  (ProtobufCMessageInit) scf_ecomponent__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[7] =
-{
-  {
-    "name",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_STRING,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, name),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "components",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEfunction, n_components),
-    offsetof(ScfEfunction, components),
-    &scf_ecomponent__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "elines",
-    3,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEfunction, n_elines),
-    offsetof(ScfEfunction, elines),
-    &scf_eline__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "w",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, w),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "h",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, h),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_efunction__field_indices_by_name[] = {
-  1,   /* field[1] = components */
-  2,   /* field[2] = elines */
-  6,   /* field[6] = h */
-  0,   /* field[0] = name */
-  5,   /* field[5] = w */
-  3,   /* field[3] = x */
-  4,   /* field[4] = y */
-};
-static const ProtobufCIntRange scf_efunction__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 7 }
-};
-const ProtobufCMessageDescriptor scf_efunction__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_efunction",
-  "ScfEfunction",
-  "ScfEfunction",
-  "",
-  sizeof(ScfEfunction),
-  7,
-  scf_efunction__field_descriptors,
-  scf_efunction__field_indices_by_name,
-  1,  scf_efunction__number_ranges,
-  (ProtobufCMessageInit) scf_efunction__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_eboard__field_descriptors[1] =
-{
-  {
-    "functions",
-    1,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEboard, n_functions),
-    offsetof(ScfEboard, functions),
-    &scf_efunction__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_eboard__field_indices_by_name[] = {
-  0,   /* field[0] = functions */
-};
-static const ProtobufCIntRange scf_eboard__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 1 }
-};
-const ProtobufCMessageDescriptor scf_eboard__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_eboard",
-  "ScfEboard",
-  "ScfEboard",
-  "",
-  sizeof(ScfEboard),
-  1,
-  scf_eboard__field_descriptors,
-  scf_eboard__field_indices_by_name,
-  1,  scf_eboard__number_ranges,
-  (ProtobufCMessageInit) scf_eboard__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
diff --git a/native/eda/scf_eda.pb-c.h b/native/eda/scf_eda.pb-c.h
deleted file mode 100644 (file)
index 750c4cc..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
-/* Generated from: scf_eda.proto */
-
-#ifndef PROTOBUF_C_scf_5feda_2eproto__INCLUDED
-#define PROTOBUF_C_scf_5feda_2eproto__INCLUDED
-
-#include <protobuf-c/protobuf-c.h>
-
-PROTOBUF_C__BEGIN_DECLS
-
-#if PROTOBUF_C_VERSION_NUMBER < 1000000
-# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
-#elif 1002001 < PROTOBUF_C_MIN_COMPILER_VERSION
-# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
-#endif
-
-
-typedef struct _ScfLine ScfLine;
-typedef struct _ScfEpin ScfEpin;
-typedef struct _ScfEconn ScfEconn;
-typedef struct _ScfEline ScfEline;
-typedef struct _ScfEcomponent ScfEcomponent;
-typedef struct _ScfEfunction ScfEfunction;
-typedef struct _ScfEboard ScfEboard;
-
-
-/* --- enums --- */
-
-
-/* --- messages --- */
-
-struct  _ScfLine
-{
-  ProtobufCMessage base;
-  int32_t x0;
-  int32_t y0;
-  int32_t x1;
-  int32_t y1;
-};
-#define SCF_LINE__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_line__descriptor) \
-    , 0, 0, 0, 0 }
-
-
-struct  _ScfEpin
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  uint64_t cid;
-  uint64_t lid;
-  uint64_t flags;
-  size_t n_tos;
-  uint64_t *tos;
-  uint64_t c_lid;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  double r;
-  double jr;
-  double uf;
-  double uh;
-  double hfe;
-  double dr;
-  double jdr;
-  double sr;
-  double jsr;
-  double pr;
-  double jpr;
-  uint64_t path;
-  int32_t x;
-  int32_t y;
-  int32_t n_diodes;
-  int32_t l_pos;
-  protobuf_c_boolean vflag;
-  protobuf_c_boolean pflag;
-  protobuf_c_boolean vconst;
-  protobuf_c_boolean aconst;
-};
-#define SCF_EPIN__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_epin__descriptor) \
-    , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEconn
-{
-  ProtobufCMessage base;
-  uint64_t lid;
-  size_t n_cids;
-  uint64_t *cids;
-};
-#define SCF_ECONN__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_econn__descriptor) \
-    , 0, 0,NULL }
-
-
-struct  _ScfEline
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  size_t n_pins;
-  uint64_t *pins;
-  uint64_t c_pins;
-  uint64_t flags;
-  int64_t color;
-  size_t n_conns;
-  ScfEconn **conns;
-  size_t n_lines;
-  ScfLine **lines;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  protobuf_c_boolean vconst;
-  protobuf_c_boolean aconst;
-  protobuf_c_boolean vflag;
-};
-#define SCF_ELINE__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_eline__descriptor) \
-    , 0, 0,NULL, 0, 0, 0, 0,NULL, 0,NULL, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEcomponent
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  uint64_t type;
-  uint64_t model;
-  size_t n_pins;
-  ScfEpin **pins;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  double r;
-  double jr;
-  double uf;
-  double uh;
-  int64_t color;
-  int32_t status;
-  int32_t x;
-  int32_t y;
-  int32_t w;
-  int32_t h;
-  protobuf_c_boolean vflag;
-  protobuf_c_boolean lock;
-};
-#define SCF_ECOMPONENT__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_ecomponent__descriptor) \
-    , 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEfunction
-{
-  ProtobufCMessage base;
-  char *name;
-  size_t n_components;
-  ScfEcomponent **components;
-  size_t n_elines;
-  ScfEline **elines;
-  int32_t x;
-  int32_t y;
-  int32_t w;
-  int32_t h;
-};
-#define SCF_EFUNCTION__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_efunction__descriptor) \
-    , NULL, 0,NULL, 0,NULL, 0, 0, 0, 0 }
-
-
-struct  _ScfEboard
-{
-  ProtobufCMessage base;
-  size_t n_functions;
-  ScfEfunction **functions;
-};
-#define SCF_EBOARD__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_eboard__descriptor) \
-    , 0,NULL }
-
-
-/* ScfLine methods */
-void   scf_line__init
-                     (ScfLine         *message);
-size_t scf_line__get_packed_size
-                     (const ScfLine   *message);
-size_t scf_line__pack
-                     (const ScfLine   *message,
-                      uint8_t             *out);
-size_t scf_line__pack_to_buffer
-                     (const ScfLine   *message,
-                      ProtobufCBuffer     *buffer);
-ScfLine *
-       scf_line__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_line__free_unpacked
-                     (ScfLine *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEpin methods */
-void   scf_epin__init
-                     (ScfEpin         *message);
-size_t scf_epin__get_packed_size
-                     (const ScfEpin   *message);
-size_t scf_epin__pack
-                     (const ScfEpin   *message,
-                      uint8_t             *out);
-size_t scf_epin__pack_to_buffer
-                     (const ScfEpin   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEpin *
-       scf_epin__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_epin__free_unpacked
-                     (ScfEpin *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEconn methods */
-void   scf_econn__init
-                     (ScfEconn         *message);
-size_t scf_econn__get_packed_size
-                     (const ScfEconn   *message);
-size_t scf_econn__pack
-                     (const ScfEconn   *message,
-                      uint8_t             *out);
-size_t scf_econn__pack_to_buffer
-                     (const ScfEconn   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEconn *
-       scf_econn__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_econn__free_unpacked
-                     (ScfEconn *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEline methods */
-void   scf_eline__init
-                     (ScfEline         *message);
-size_t scf_eline__get_packed_size
-                     (const ScfEline   *message);
-size_t scf_eline__pack
-                     (const ScfEline   *message,
-                      uint8_t             *out);
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEline *
-       scf_eline__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEcomponent methods */
-void   scf_ecomponent__init
-                     (ScfEcomponent         *message);
-size_t scf_ecomponent__get_packed_size
-                     (const ScfEcomponent   *message);
-size_t scf_ecomponent__pack
-                     (const ScfEcomponent   *message,
-                      uint8_t             *out);
-size_t scf_ecomponent__pack_to_buffer
-                     (const ScfEcomponent   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEcomponent *
-       scf_ecomponent__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_ecomponent__free_unpacked
-                     (ScfEcomponent *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEfunction methods */
-void   scf_efunction__init
-                     (ScfEfunction         *message);
-size_t scf_efunction__get_packed_size
-                     (const ScfEfunction   *message);
-size_t scf_efunction__pack
-                     (const ScfEfunction   *message,
-                      uint8_t             *out);
-size_t scf_efunction__pack_to_buffer
-                     (const ScfEfunction   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEfunction *
-       scf_efunction__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_efunction__free_unpacked
-                     (ScfEfunction *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEboard methods */
-void   scf_eboard__init
-                     (ScfEboard         *message);
-size_t scf_eboard__get_packed_size
-                     (const ScfEboard   *message);
-size_t scf_eboard__pack
-                     (const ScfEboard   *message,
-                      uint8_t             *out);
-size_t scf_eboard__pack_to_buffer
-                     (const ScfEboard   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEboard *
-       scf_eboard__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_eboard__free_unpacked
-                     (ScfEboard *message,
-                      ProtobufCAllocator *allocator);
-/* --- per-message closures --- */
-
-typedef void (*ScfLine_Closure)
-                 (const ScfLine *message,
-                  void *closure_data);
-typedef void (*ScfEpin_Closure)
-                 (const ScfEpin *message,
-                  void *closure_data);
-typedef void (*ScfEconn_Closure)
-                 (const ScfEconn *message,
-                  void *closure_data);
-typedef void (*ScfEline_Closure)
-                 (const ScfEline *message,
-                  void *closure_data);
-typedef void (*ScfEcomponent_Closure)
-                 (const ScfEcomponent *message,
-                  void *closure_data);
-typedef void (*ScfEfunction_Closure)
-                 (const ScfEfunction *message,
-                  void *closure_data);
-typedef void (*ScfEboard_Closure)
-                 (const ScfEboard *message,
-                  void *closure_data);
-
-/* --- services --- */
-
-
-/* --- descriptors --- */
-
-extern const ProtobufCMessageDescriptor scf_line__descriptor;
-extern const ProtobufCMessageDescriptor scf_epin__descriptor;
-extern const ProtobufCMessageDescriptor scf_econn__descriptor;
-extern const ProtobufCMessageDescriptor scf_eline__descriptor;
-extern const ProtobufCMessageDescriptor scf_ecomponent__descriptor;
-extern const ProtobufCMessageDescriptor scf_efunction__descriptor;
-extern const ProtobufCMessageDescriptor scf_eboard__descriptor;
-
-PROTOBUF_C__END_DECLS
-
-
-#endif  /* PROTOBUF_C_scf_5feda_2eproto__INCLUDED */
diff --git a/native/eda/scf_eda.proto b/native/eda/scf_eda.proto
deleted file mode 100644 (file)
index 9e1174a..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-syntax="proto2";
-
-message scf_line
-{
-       required int32 x0 = 1;
-       required int32 y0 = 2;
-       required int32 x1 = 3;
-       required int32 y1 = 4;
-}
-
-message scf_epin
-{
-       required uint64    id    = 1;
-       required uint64    cid   = 2;
-       required uint64    lid   = 3;
-       required uint64    flags = 4;
-       repeated uint64    tos   = 5;
-       required uint64    c_lid = 6;
-
-       required double    v     = 7;
-       required double    jv    = 8;
-       required double    a     = 9;
-       required double    ja    = 10;
-
-       required double    r     = 11;
-       required double    jr    = 12;
-       required double    uF    = 13;
-       required double    uH    = 14;
-       required double    hfe   = 15;
-
-       required double    dr    = 16;
-       required double    jdr   = 17;
-
-       required double    sr    = 18;
-       required double    jsr   = 19;
-
-       required double    pr    = 20;
-       required double    jpr   = 21;
-
-       required uint64    path  = 22;
-
-       required int32     x     = 23;
-       required int32     y     = 24;
-
-       required int32     n_diodes = 25;
-       required int32     l_pos = 26;
-
-       required bool      vflag = 27;
-       required bool      pflag = 28;
-
-       required bool      vconst = 29;
-       required bool      aconst = 30;
-}
-
-message scf_econn
-{
-       required uint64    lid   = 1;
-       repeated uint64    cids  = 2;
-}
-
-message scf_eline
-{
-       required uint64    id     = 1;
-       repeated uint64    pins   = 2;
-       required uint64    c_pins = 3;
-       required uint64    flags  = 4;
-       required int64     color  = 5;
-
-       repeated scf_econn conns  = 6;
-       repeated scf_line  lines  = 7;
-
-       required double    v      = 8;
-       required double    jv     = 9;
-       required double    a      = 10;
-       required double    ja     = 11;
-       required bool      vconst = 12;
-       required bool      aconst = 13;
-
-       required bool      vflag  = 14;
-}
-
-message scf_ecomponent
-{
-       required uint64    id     = 1;
-       required uint64    type   = 2;
-       required uint64    model  = 3;
-       repeated scf_epin  pins   = 4;
-
-       required double    v      = 5;
-       required double    jv     = 6;
-       required double    a      = 7;
-       required double    ja     = 8;
-
-       required double    r      = 9;
-       required double    jr     = 10;
-       required double    uF     = 11;
-       required double    uH     = 12;
-
-       required int64     color  = 13;
-       required int32     status = 14;
-
-       required int32     x      = 15;
-       required int32     y      = 16;
-       required int32     w      = 17;
-       required int32     h      = 18;
-
-       required bool      vflag  = 19;
-       required bool      lock   = 20;
-}
-
-message scf_efunction
-{
-       required string         name       = 1;
-       repeated scf_ecomponent components = 2;
-       repeated scf_eline      elines     = 3;
-
-       required int32    x    = 4;
-       required int32    y    = 5;
-       required int32    w    = 6;
-       required int32    h    = 7;
-}
-
-message scf_eboard
-{
-       repeated scf_efunction functions = 1;
-}
diff --git a/native/eda/scf_eda_pb.c b/native/eda/scf_eda_pb.c
deleted file mode 100644 (file)
index 5433001..0000000
+++ /dev/null
@@ -1,703 +0,0 @@
-#include "scf_eda_pb.h"
-#include "scf_def.h"
-
-static int component_pins[SCF_EDA_Components_NB] =
-{
-       0, // None
-       SCF_EDA_Battery_NB, // SCF_EDA_Battery
-
-       2, // SCF_EDA_Resistor
-       2, // SCF_EDA_Capacitor
-       2, // SCF_EDA_Inductor
-
-       SCF_EDA_Diode_NB,
-       SCF_EDA_NPN_NB,
-       SCF_EDA_PNP_NB,
-};
-
-static scf_edata_t  component_datas[] =
-{
-       {SCF_EDA_None,       0,                   0,  0, 0,         0, 0,    0,    0, 0},
-       {SCF_EDA_Battery,    0, SCF_EDA_Battery_POS,  0, 0,         0, 0,    0,    0, 0},
-
-       {SCF_EDA_Resistor,   0,                   0,  0, 0, 10 * 1000, 0,    0,    0, 0},
-       {SCF_EDA_Capacitor,  0,                   0,  0, 0,      1e12, 0,  0.1,    0, 0},
-       {SCF_EDA_Inductor,   0,                   0,  0, 0,         0, 0,    0, 1000, 0},
-};
-
-static scf_edata_t  pin_datas[] =
-{
-       {SCF_EDA_None,  0,                 0, 0, 0,   0, 0, 0, 0, 0},
-
-       {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0, 0},
-
-       {SCF_EDA_NPN,   0, SCF_EDA_NPN_B,     0, 0, 750, 0, 0, 0, 0},
-       {SCF_EDA_NPN,   0, SCF_EDA_NPN_C,     0, 0,  10, 0, 0, 0, 150},
-
-       {SCF_EDA_PNP,   0, SCF_EDA_PNP_B,     0, 0, 750, 0, 0, 0, 0},
-       {SCF_EDA_PNP,   0, SCF_EDA_PNP_C,     0, 0,  10, 0, 0, 0, 150},
-};
-
-static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid)
-{
-       scf_edata_t* ed;
-
-       int i;
-       for (i = 0; i < sizeof(pin_datas) / sizeof(pin_datas[0]); i++) {
-               ed =              &pin_datas[i];
-
-               if (ed->type == type && ed->model == model && ed->pid == pid)
-                       return ed;
-       }
-
-       return NULL;
-}
-
-static scf_edata_t* _component_find_data(const uint64_t type, const uint64_t model)
-{
-       scf_edata_t* ed;
-
-       int i;
-       for (i = 0; i < sizeof(component_datas) / sizeof(component_datas[0]); i++) {
-               ed =              &component_datas[i];
-
-               if (ed->type == type && ed->model == model)
-                       return ed;
-       }
-
-       return NULL;
-}
-
-ScfEconn* scf_econn__alloc()
-{
-       ScfEconn* ec = malloc(sizeof(ScfEconn));
-       if (!ec)
-               return NULL;
-
-       scf_econn__init(ec);
-       return ec;
-}
-
-int scf_econn__add_cid(ScfEconn* ec, uint64_t cid)
-{
-       if (!ec)
-               return -EINVAL;
-
-       for (size_t i = 0; i < ec->n_cids; i++) {
-
-               if (ec->cids[i] == cid)
-                       return 0;
-       }
-
-       uint64_t* p = realloc(ec->cids, sizeof(uint64_t) * (ec->n_cids + 1));
-       if (!p)
-               return -ENOMEM;
-
-       ec->cids = p;
-       ec->cids[ec->n_cids++] = cid;
-       return 0;
-}
-
-int scf_econn__del_cid(ScfEconn* ec, uint64_t cid)
-{
-       if (!ec)
-               return -EINVAL;
-
-       uint64_t* p;
-       size_t    i;
-       size_t    j;
-
-       for (i = 0; i < ec->n_cids; i++) {
-
-               if (ec->cids[i] == cid) {
-
-                       for (j = i + 1;  j  < ec->n_cids; j++)
-                               ec->cids[j - 1] = ec->cids[j];
-
-                       ec->n_cids--;
-
-                       p = realloc(ec->cids, sizeof(uint64_t) * ec->n_cids);
-                       if (p)
-                               ec->cids = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_econn__free(ScfEconn* ec)
-{
-       if (ec) {
-               if (ec->cids)
-                       free(ec->cids);
-
-               free(ec);
-       }
-}
-
-ScfEline* scf_eline__alloc()
-{
-       ScfEline* l = malloc(sizeof(ScfEline));
-       if (!l)
-               return NULL;
-
-       scf_eline__init(l);
-       return l;
-}
-
-int scf_eline__add_line(ScfEline* el, ScfLine*  l)
-{
-       if (!el || !l)
-               return -EINVAL;
-
-       for (size_t i = 0; i < el->n_lines; i++) {
-
-               if (el->lines[i] == l)
-                       return 0;
-
-               if (el->lines[i]->x0 == l->x0
-                && el->lines[i]->y0 == l->y0
-                && el->lines[i]->x1 == l->x1
-                && el->lines[i]->y1 == l->y1)
-                       return 0;
-       }
-
-       void* p = realloc(el->lines, sizeof(ScfLine*) * (el->n_lines + 1));
-       if (!p)
-               return -ENOMEM;
-
-       el->lines = p;
-       el->lines[el->n_lines++] = l;
-       return 0;
-}
-
-int scf_eline__del_line(ScfEline* el, ScfLine*  l)
-{
-       if (!el || !l)
-               return -EINVAL;
-
-       void*   p;
-       size_t  i;
-       size_t  j;
-
-       for (i = 0; i < el->n_lines; i++) {
-
-               if (el->lines[i]->x0 == l->x0
-                && el->lines[i]->y0 == l->y0
-                && el->lines[i]->x1 == l->x1
-                && el->lines[i]->y1 == l->y1) {
-
-                       for (j = i + 1;  j  < el->n_lines; j++)
-                               el->lines[j - 1] = el->lines[j];
-
-                       el->n_lines--;
-
-                       p = realloc(el->lines, sizeof(ScfLine*) * el->n_lines);
-                       if (p)
-                               el->lines = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-int scf_eline__add_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
-{
-       if (!el)
-               return -EINVAL;
-
-       for (size_t i = 0; i + 1 < el->n_pins; i += 2) {
-
-               if (el->pins[i] == cid && el->pins[i + 1] == pid)
-                       return 0;
-       }
-
-       uint64_t* p = realloc(el->pins, sizeof(uint64_t) * (el->n_pins + 2));
-       if (!p)
-               return -ENOMEM;
-
-       el->pins = p;
-       el->pins[el->n_pins++] = cid;
-       el->pins[el->n_pins++] = pid;
-       return 0;
-}
-
-int scf_eline__del_pin(ScfEline* el, uint64_t  cid, uint64_t pid)
-{
-       if (!el)
-               return -EINVAL;
-
-       uint64_t* p;
-       size_t    i;
-       size_t    j;
-
-       for (i = 0; i + 1 < el->n_pins; i += 2) {
-
-               if (el->pins[i] == cid && el->pins[i + 1] == pid) {
-
-                       for (j = i + 2;  j  < el->n_pins; j++)
-                               el->pins[j - 2] = el->pins[j];
-
-                       el->n_pins -= 2;
-
-                       p = realloc(el->pins, sizeof(uint64_t) * el->n_pins);
-                       if (p)
-                               el->pins = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-int scf_eline__add_conn(ScfEline* el, ScfEconn* ec)
-{
-       if (!el || !ec)
-               return -EINVAL;
-
-       for (size_t i = 0; i < el->n_conns; i++) {
-
-               if (el->conns[i] == ec)
-                       return 0;
-       }
-
-       void* p = realloc(el->conns, sizeof(ScfEconn*) * (el->n_conns + 1));
-       if (!p)
-               return -ENOMEM;
-
-       el->conns = p;
-       el->conns[el->n_conns++] = ec;
-       return 0;
-}
-
-int scf_eline__del_conn(ScfEline* el, ScfEconn* ec)
-{
-       if (!el || !ec)
-               return -EINVAL;
-
-       void*   p;
-       size_t  i;
-       size_t  j;
-
-       for (i = 0; i < el->n_conns; i++) {
-
-               if (el->conns[i] == ec) {
-
-                       for (j = i + 1;  j  < el->n_conns; j++)
-                               el->conns[j - 1] = el->conns[j];
-
-                       el->n_conns--;
-
-                       p = realloc(el->conns, sizeof(ScfEconn*) * el->n_conns);
-                       if (p)
-                               el->conns = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_eline__free(ScfEline* l)
-{
-       if (l) {
-               size_t i;
-
-               if (l->pins)
-                       free(l->pins);
-
-               if (l->conns) {
-                       for (i = 0; i < l->n_conns; i++)
-                               scf_econn__free(l->conns[i]);
-
-                       free(l->conns);
-               }
-
-               if (l->lines) {
-                       for (i = 0; i < l->n_lines; i++)
-                               free(l->lines[i]);
-
-                       free(l->lines);
-               }
-
-               free(l);
-       }
-}
-
-ScfEpin* scf_epin__alloc()
-{
-       ScfEpin* pin = malloc(sizeof(ScfEpin));
-       if (!pin)
-               return NULL;
-
-       scf_epin__init(pin);
-       return pin;
-}
-
-int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
-{
-       if (!pin)
-               return -EINVAL;
-
-       for (size_t i = 0; i + 1 < pin->n_tos; i += 2) {
-
-               if (pin->tos[i] == cid && pin->tos[i + 1] == pid)
-                       return 0;
-       }
-
-       uint64_t* p = realloc(pin->tos, sizeof(uint64_t) * (pin->n_tos + 2));
-       if (!p)
-               return -ENOMEM;
-
-       pin->tos = p;
-       pin->tos[pin->n_tos++] = cid;
-       pin->tos[pin->n_tos++] = pid;
-       return 0;
-}
-
-int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
-{
-       if (!pin)
-               return -EINVAL;
-
-       uint64_t* p;
-       size_t    i;
-       size_t    j;
-
-       for (i = 0; i + 1 < pin->n_tos; i += 2) {
-
-               if (pin->tos[i] == cid && pin->tos[i + 1] == pid) {
-
-                       for (j = i + 2;  j  < pin->n_tos; j++)
-                               pin->tos[j - 2] = pin->tos[j];
-
-                       pin->n_tos -= 2;
-
-                       p = realloc(pin->tos, sizeof(uint64_t) * pin->n_tos);
-                       if (p)
-                               pin->tos = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_epin__free(ScfEpin* pin)
-{
-       if (pin) {
-               scf_logd("pin: %p\n", pin);
-
-               if (pin->tos)
-                       free(pin->tos);
-               free(pin);
-       }
-}
-
-ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
-{
-       ScfEcomponent* c;
-       scf_edata_t*   ed;
-
-       if (type >= SCF_EDA_Components_NB)
-               return NULL;
-
-       c = malloc(sizeof(ScfEcomponent));
-       if (!c)
-               return NULL;
-
-       scf_ecomponent__init(c);
-
-       c->type = type;
-
-       ed = _component_find_data(c->type, c->model);
-       if (ed) {
-               c->v  = ed->v;
-               c->a  = ed->a;
-               c->r  = ed->r;
-               c->jr = ed->jr;
-               c->uf = ed->uf;
-               c->uh = ed->uh;
-       }
-
-       int i;
-       for (i = 0; i < component_pins[type]; i++) {
-
-               ScfEpin* pin = scf_epin__alloc();
-               if (!pin) {
-                       scf_ecomponent__free(c);
-                       return NULL;
-               }
-
-               pin->id = i;
-
-               if (scf_ecomponent__add_pin(c, pin) < 0) {
-                       scf_ecomponent__free(c);
-                       scf_epin__free(pin);
-                       return NULL;
-               }
-
-               ed = _pin_find_data(c->type, c->model, pin->id);
-               if (ed) {
-                       pin->v   = ed->v;
-                       pin->a   = ed->a;
-                       pin->r   = ed->r;
-                       pin->jr  = ed->jr;
-                       pin->uf  = ed->uf;
-                       pin->uh  = ed->uh;
-                       pin->hfe = ed->hfe;
-               }
-       }
-
-       return c;
-}
-
-int scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin)
-{
-       if (!c || !pin)
-               return -EINVAL;
-
-       void* p = realloc(c->pins, sizeof(ScfEpin*) * (c->n_pins + 1));
-       if (!p)
-               return -ENOMEM;
-
-       c->pins = p;
-       c->pins[c->n_pins++] = pin;
-       return 0;
-}
-
-int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin)
-{
-       if (!c)
-               return -EINVAL;
-
-       size_t   i;
-       size_t   j;
-       void*    p;
-
-       for (i = 0; i < c->n_pins; i++) {
-
-               if (c->pins[i] == pin) {
-
-                       for (j = i + 1; j  < c->n_pins; j++)
-                               c->pins[j - 1] = c->pins[j];
-
-                       c->n_pins--;
-
-                       p = realloc(c->pins, sizeof(ScfEpin*) * c->n_pins);
-                       if (p)
-                               c->pins = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_ecomponent__free(ScfEcomponent* c)
-{
-       if (c) {
-               scf_logd("c: %ld\n", c->id);
-
-               if (c->pins) {
-                       size_t i;
-
-                       for (i = 0; i < c->n_pins; i++)
-                               scf_epin__free(c->pins[i]);
-
-                       free(c->pins);
-               }
-
-               free(c);
-       }
-}
-
-ScfEfunction*  scf_efunction__alloc(const char* name)
-{
-       ScfEfunction* f = malloc(sizeof(ScfEfunction));
-       if (!f)
-               return NULL;
-
-       scf_efunction__init(f);
-
-       f->name = strdup(name);
-       if (!f->name) {
-               free(f);
-               return NULL;
-       }
-
-       return f;
-}
-
-int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c)
-{
-       if (!f || !c)
-               return -EINVAL;
-
-       void* p = realloc(f->components, sizeof(ScfEcomponent*) * (f->n_components + 1));
-       if (!p)
-               return -ENOMEM;
-
-       f->components = p;
-       f->components[f->n_components++] = c;
-       return 0;
-}
-
-int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c)
-{
-       if (!f || !c)
-               return -EINVAL;
-
-       size_t   i;
-       size_t   j;
-       void*    p;
-
-       for (i = 0; i < f->n_components; i++) {
-
-               if (f->components[i] == c) {
-
-                       for (j = i + 1;  j < f->n_components; j++)
-                               f->components[j - 1] = f->components[j];
-
-                       f->n_components--;
-
-                       p = realloc(f->components, sizeof(ScfEcomponent*) * f->n_components);
-                       if (p)
-                               f->components = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-int scf_efunction__add_eline(ScfEfunction* f, ScfEline* el)
-{
-       if (!f || !el)
-               return -EINVAL;
-
-       void* p = realloc(f->elines, sizeof(ScfEline*) * (f->n_elines + 1));
-       if (!p)
-               return -ENOMEM;
-
-       f->elines = p;
-       f->elines[f->n_elines++] = el;
-       return 0;
-}
-
-int scf_efunction__del_eline(ScfEfunction* f, ScfEline* el)
-{
-       if (!f || !el)
-               return -EINVAL;
-
-       size_t   i;
-       size_t   j;
-       void*    p;
-
-       for (i = 0; i < f->n_elines; i++) {
-
-               if (f->elines[i] == el) {
-
-                       for (j = i + 1;  j < f->n_elines; j++)
-                               f->elines[j - 1] = f->elines[j];
-
-                       f->n_elines--;
-
-                       p = realloc(f->elines, sizeof(ScfEline*) * f->n_elines);
-                       if (p)
-                               f->elines = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_efunction__free(ScfEfunction* f)
-{
-       if (f) {
-               scf_logd("f: %s\n", f->name);
-
-               if (f->components) {
-                       size_t i;
-
-                       for (i = 0; i < f->n_components; i++)
-                               scf_ecomponent__free(f->components[i]);
-
-                       free(f->components);
-               }
-
-               free(f->name);
-               free(f);
-       }
-}
-
-ScfEboard* scf_eboard__alloc()
-{
-       ScfEboard* b = malloc(sizeof(ScfEboard));
-       if (!b)
-               return NULL;
-
-       scf_eboard__init(b);
-       return b;
-}
-
-int scf_eboard__add_function(ScfEboard* b, ScfEfunction* f)
-{
-       if (!b || !f)
-               return -EINVAL;
-
-       void* p = realloc(b->functions, sizeof(ScfEfunction*) * (b->n_functions + 1));
-       if (!p)
-               return -ENOMEM;
-
-       b->functions = p;
-       b->functions[b->n_functions++] = f;
-       return 0;
-}
-
-int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f)
-{
-       if (!b)
-               return -EINVAL;
-
-       size_t   i;
-       size_t   j;
-       void*    p;
-
-       for (i = 0; i < b->n_functions; i++) {
-
-               if (b->functions[i] == f) {
-
-                       for (j = i + 1;  j < b->n_functions; j++)
-                               b->functions[j - 1] = b->functions[j];
-
-                       b->n_functions--;
-
-                       p = realloc(b->functions, sizeof(ScfEfunction*) * b->n_functions);
-                       if (p)
-                               b->functions = p;
-                       return 0;
-               }
-       }
-
-       return -EINVAL;
-}
-
-void scf_eboard__free(ScfEboard* b)
-{
-       if (b) {
-               if (b->functions) {
-                       size_t i;
-
-                       for (i = 0; i < b->n_functions; i++)
-                               scf_efunction__free(b->functions[i]);
-
-                       free(b->functions);
-               }
-
-               free(b);
-       }
-}
diff --git a/native/eda/scf_eda_pb.h b/native/eda/scf_eda_pb.h
deleted file mode 100644 (file)
index 5fdb4ba..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-#ifndef SCF_EDA_PB_H
-#define SCF_EDA_PB_H
-
-#include "scf_eda.pb-c.h"
-
-enum {
-       SCF_EDA_None,
-       SCF_EDA_Battery,
-
-       SCF_EDA_Resistor,
-       SCF_EDA_Capacitor,
-       SCF_EDA_Inductor,
-
-       SCF_EDA_Diode,
-       SCF_EDA_NPN,
-       SCF_EDA_PNP,
-
-       SCF_EDA_Components_NB,
-};
-
-#define SCF_EDA_PIN_NONE  0
-#define SCF_EDA_PIN_IN    1
-#define SCF_EDA_PIN_OUT   2
-#define SCF_EDA_PIN_POS   4
-#define SCF_EDA_PIN_NEG   8
-#define SCF_EDA_PIN_CF   16
-
-#define SCF_EDA_V_INIT   -10001001.0
-#define SCF_EDA_V_MIN    -10000000.0
-#define SCF_EDA_V_MAX     10000000.0
-
-#define SCF_EDA_V_Diode_ON  0.69
-#define SCF_EDA_V_Diode_OFF 0.70
-
-enum {
-       SCF_EDA_Battery_NEG,
-       SCF_EDA_Battery_POS,
-       SCF_EDA_Battery_NB,
-};
-
-enum {
-       SCF_EDA_Diode_NEG,
-       SCF_EDA_Diode_POS,
-       SCF_EDA_Diode_NB,
-};
-
-enum {
-       SCF_EDA_Status_ON,
-       SCF_EDA_Status_OFF,
-       SCF_EDA_Path_OFF,
-       SCF_EDA_Path_TO,
-};
-
-enum {
-       SCF_EDA_NPN_B,
-       SCF_EDA_NPN_E,
-       SCF_EDA_NPN_C,
-       SCF_EDA_NPN_NB,
-};
-
-enum {
-       SCF_EDA_PNP_B,
-       SCF_EDA_PNP_E,
-       SCF_EDA_PNP_C,
-       SCF_EDA_PNP_NB,
-};
-
-typedef struct {
-       uint64_t  type;
-       uint64_t  model;
-       uint64_t  pid;
-
-       double    v;
-       double    a;
-       double    r;
-       double    jr;
-       double    uf;
-       double    uh;
-       double    hfe;
-} scf_edata_t;
-
-
-ScfEconn*      scf_econn__alloc();
-int            scf_econn__add_cid(ScfEconn* ec, uint64_t  cid);
-int            scf_econn__del_cid(ScfEconn* ec, uint64_t  cid);
-void           scf_econn__free(ScfEconn* ec);
-
-ScfEline*      scf_eline__alloc();
-int            scf_eline__add_line(ScfEline* el, ScfLine*  l);
-int            scf_eline__del_line(ScfEline* el, ScfLine*  l);
-
-int            scf_eline__add_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
-int            scf_eline__del_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
-
-int            scf_eline__add_conn(ScfEline* el, ScfEconn* ec);
-int            scf_eline__del_conn(ScfEline* el, ScfEconn* ec);
-void           scf_eline__free    (ScfEline* el);
-
-ScfEpin*       scf_epin__alloc();
-int            scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
-int            scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
-void           scf_epin__free         (ScfEpin* pin);
-
-ScfEcomponent* scf_ecomponent__alloc  (uint64_t type);
-int            scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin);
-int            scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin);
-void           scf_ecomponent__free   (ScfEcomponent* c);
-
-ScfEfunction*  scf_efunction__alloc        (const   char* name);
-int            scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c);
-int            scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c);
-
-int            scf_efunction__add_eline    (ScfEfunction* f, ScfEline* el);
-int            scf_efunction__del_eline    (ScfEfunction* f, ScfEline* el);
-void           scf_efunction__free         (ScfEfunction* f);
-
-ScfEboard*     scf_eboard__alloc();
-int            scf_eboard__add_function(ScfEboard* b, ScfEfunction* f);
-int            scf_eboard__del_function(ScfEboard* b, ScfEfunction* f);
-void           scf_eboard__free        (ScfEboard* b);
-
-#define EDA_INST_ADD_COMPONENT(_ef, _c, _type) \
-       do { \
-               _c = scf_ecomponent__alloc(_type); \
-               if (!_c) \
-                       return -ENOMEM; \
-               \
-               (_c)->id = (_ef)->n_components; \
-               \
-               int ret = scf_efunction__add_component(_ef, _c); \
-               if (ret < 0) { \
-                       scf_ecomponent__free(_c); \
-                       _c = NULL; \
-                       return ret; \
-               } \
-               \
-               for (size_t i = 0;  i < (_c)->n_pins; i++) \
-                       (_c)->pins[i]->cid = (_c)->id; \
-       } while (0)
-
-#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \
-       do { \
-               int ret = scf_epin__add_component((_pin), _cid, _pid); \
-               if (ret < 0) \
-                       return ret; \
-       } while (0)
-
-#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \
-       do { \
-               int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \
-               if (ret < 0) \
-                       return ret; \
-               \
-               ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \
-               if (ret < 0) \
-                       return ret; \
-       } while (0)
-
-#define EDA_PIN_ADD_PIN_EF(_ef, _p0, _p1) \
-       EDA_PIN_ADD_PIN((_ef)->components[(_p0)->cid], (_p0)->id, (_ef)->components[(_p1)->cid], (_p1)->id)
-
-#endif
index 064f5931903b08eee893c9157c1d9ca09fd6d958..971151c8464ae06b1dc330755b71a7dcc5daca3c 100644 (file)
@@ -2,6 +2,7 @@ CFILES += ../util/scf_string.c
 CFILES += ../util/scf_graph.c
 CFILES += ../lex/scf_lex.c
 CFILES += ../lex/scf_lex_util.c
+CFILES += ../lex/scf_macro.c
 
 CFILES += scf_parse_util.c
 CFILES += scf_parse.c
index c25e7482d0a7f59a5b5fab9425075cfbf39d9da1..d16dad94a1fe8999a1a595b715940e38ceb12c08 100644 (file)
@@ -22,18 +22,27 @@ static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        scf_block_t*     cur    = parse->ast->current_block;
 
        assert(w->data.s);
-       scf_logd("include '%s', line %d\n", w->data.s->data, w->line);
+
+       uint8_t* path = NULL;
+
+       int ret = scf_file_path(&path, lex->file, w->data.s);
+       if (ret < 0)
+               return ret;
+
+       if (!path)
+               path = w->data.s->data;
+
+       scf_logi("include '%s' (real path: %s) at file: %s, line:%d\n", w->data.s->data, path, w->file->data, w->line);
 
        parse->lex = NULL;
-       parse->ast->current_block = parse->ast->root_block;
 
-       int ret = scf_parse_file(parse, w->data.s->data);
+       ret = scf_parse_file(parse, path);
        if (ret < 0) {
-               scf_loge("parse file '%s' failed, 'include' line: %d\n", w->data.s->data, w->line);
+               scf_loge("parse file '%s' failed, 'include' line: %d\n", path, w->line);
                goto error;
        }
 
-       if (parse->lex != lex && parse->lex->macros) { // copy macros
+       if (parse->lex && parse->lex != lex && parse->lex->macros) { // copy macros
 
                if (!lex->macros) {
                        lex->macros = scf_vector_clone(parse->lex->macros);
@@ -58,6 +67,9 @@ static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
        ret = SCF_DFA_NEXT_WORD;
 error:
+       if (path != w->data.s->data)
+               free(path);
+
        parse->lex = lex;
        parse->ast->current_block = cur;
        return ret;
index 6e1151951339ad96515dbcdb8a096d7c0fea2e8b..a768b6b542d9da269ba36dd0707902c3998613dd 100644 (file)
@@ -105,30 +105,33 @@ int scf_parse_file(scf_parse_t* parse, const char* path)
        if (!parse || !path)
                return -EINVAL;
 
-       scf_lex_t* lex = parse->lex_list;
+       scf_ast_t*    ast = parse->ast;
+       scf_block_t*  cur = ast->current_block;
+       scf_block_t*  old = cur;
+       scf_lex_t*    lex;
 
+       while (!cur->node.file_flag && !cur->node.root_flag)
+               cur =      ( scf_block_t* ) cur->node.parent;
+
+       lex = cur->lex_list;
        while (lex) {
                if (!strcmp(lex->file->data, path))
-                       break;
+                       return 0;
 
                lex = lex->next;
        }
 
-       if (lex) {
-               parse->lex = lex;
-               return 0;
-       }
-
        if (scf_lex_open(&parse->lex, path, NULL) < 0)
                return -1;
 
-       scf_ast_add_file_block(parse->ast, path);
+       if (cur == ast->root_block)
+               scf_ast_add_file_block(ast, path);
 
-       parse->lex->next = parse->lex_list;
-       parse->lex_list  = parse->lex;
+       parse->lex->next = cur->lex_list;
+       cur->lex_list    = parse->lex;
 
-       dfa_data_t*       d = parse->dfa_data;
-       scf_lex_word_t*   w = NULL;
+       dfa_data_t*      d = parse->dfa_data;
+       scf_lex_word_t*  w = NULL;
 
        int ret = 0;
 
@@ -167,6 +170,8 @@ int scf_parse_file(scf_parse_t* parse, const char* path)
 
        fclose(parse->lex->fp);
        parse->lex->fp = NULL;
+
+       ast->current_block = old;
        return ret;
 }
 
@@ -1796,7 +1801,7 @@ int scf_parse_compile_functions(scf_parse_t* parse, scf_vector_t* functions)
                }
 
                assert(scf_list_empty(&h));
-               scf_basic_block_print_list(&f->basic_block_list_head);
+//             scf_basic_block_print_list(&f->basic_block_list_head);
        }
 
        int ret = scf_optimize(parse->ast, functions);
@@ -1899,7 +1904,8 @@ error:
 static int _add_debug_file_names(scf_parse_t* parse)
 {
        scf_block_t* root = parse->ast->root_block;
-       scf_block_t* b    = NULL;
+       scf_block_t* b;
+       scf_lex_t*   lex;
 
        int ret;
        int i;
@@ -1911,19 +1917,22 @@ static int _add_debug_file_names(scf_parse_t* parse)
                        continue;
 
                ret = scf_symtab_add_sym(parse->symtab, b->name->data, 0, 0, SHN_ABS, ELF64_ST_INFO(STB_LOCAL, STT_FILE));
-               if (ret < 0) {
-                       scf_loge("\n");
+               if (ret < 0)
                        return ret;
-               }
 
-               scf_string_t* file_str = scf_string_clone(b->name);
-               if (!file_str)
-                       return -ENOMEM;
-
-               ret = scf_vector_add(parse->debug->file_names, file_str);
-               if (ret < 0) {
-                       scf_string_free(file_str);
+               ret = scf_dwarf_add_file_name(parse->debug, b->name);
+               if (ret < 0)
                        return ret;
+
+               for (lex = b->lex_list; lex; lex = lex->next)
+               {
+                       ret = scf_symtab_add_sym(parse->symtab, lex->file->data, 0, 0, SHN_ABS, ELF64_ST_INFO(STB_LOCAL, STT_FILE));
+                       if (ret < 0)
+                               return ret;
+
+                       ret = scf_dwarf_add_file_name(parse->debug, lex->file);
+                       if (ret < 0)
+                               return ret;
                }
        }
 
index 32ac1818268257e56bab5a07fc27025a3a2d78b4..458e6911e604156b81ecda03899f37805c7a5e8a 100644 (file)
@@ -21,9 +21,7 @@ typedef struct dfa_data_s    dfa_data_t;
 
 struct scf_parse_s
 {
-       scf_lex_t*         lex_list;
        scf_lex_t*         lex;
-
        scf_ast_t*         ast;
 
        scf_dfa_t*         dfa;
index c73f9a24471c81f3215cbb6c841e5c697353734f..a1afd013dc1d71d49b1939c67f34d3139327dc1e 100644 (file)
@@ -20,7 +20,7 @@ scf_string_t* scf_string_alloc()
        return s;
 }
 
-scf_string_t* scf_string_clone(scf_string_t* s)
+scf_string_t* scf_string_clone(const scf_string_t* s)
 {
        if (!s)
                return NULL;
@@ -397,6 +397,40 @@ int scf_utf8_len(const uint8_t* str, size_t* len)
        return c;
 }
 
+int scf_file_path(uint8_t** path, const scf_string_t* base, const scf_string_t* file)
+{
+       if ('/' == file->data[0] || '~' == file->data[0])
+               return 0;
+
+       int i;
+       int j;
+       for (i = base->len - 1; i >= 0; i--) {
+               if ('/' == base->data[i])
+                       break;
+       }
+
+       if (i < 0)
+               return 0;
+
+       for (j = file->len - 1; j >= 0; j--) {
+               if ('/' == file->data[j])
+                       break;
+       }
+
+       if (j == i && (j <= 0 || !strncmp(base->data, file->data, j)))
+               return 0;
+
+       uint8_t* p = malloc(i + 1 + file->len + 1);
+       if (!p)
+               return -ENOMEM;
+
+       memcpy(p,         base->data, i + 1);
+       memcpy(p + i + 1, file->data, file->len + 1);
+
+       *path = p;
+       return 0;
+}
+
 #if 0
 int main(int argc, char* argv[])
 {
index 082d2b5adf77ecbf58525bb0606516a53b43aa0d..dcf1af4627f3dfe4895200c98649b7d1a0985564 100644 (file)
@@ -12,7 +12,7 @@ typedef struct {
 
 scf_string_t*  scf_string_alloc();
 
-scf_string_t*  scf_string_clone(scf_string_t* s);
+scf_string_t*  scf_string_clone(const scf_string_t* s);
 
 scf_string_t*  scf_string_cstr(const char* str);
 
@@ -46,4 +46,6 @@ int             scf_string_match_kmp_cstr_len(const scf_string_t* T, const uint8
 int             scf_string_get_offset(scf_string_t* str, const char* data, size_t len);
 
 int             scf_utf8_len(const uint8_t* str, size_t* len);
+
+int             scf_file_path(uint8_t** path, const scf_string_t* base, const scf_string_t* file);
 #endif