Skip to content

Commit

Permalink
moved to CPM
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Feb 8, 2022
1 parent 3c56d7b commit 31259bb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "libyaml"]
path = libyaml
url = https://github.com/yaml/libyaml.git
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@

cmake_minimum_required(VERSION 3.4)
project (FORTRAN_YAML_C VERSION 0.1.0 LANGUAGES C Fortran)
cmake_minimum_required(VERSION "3.14")
project (FORTRAN_YAML_C VERSION 0.1.1 LANGUAGES C Fortran)

include(FortranCInterface)
FortranCInterface_VERIFY()

add_subdirectory(libyaml EXCLUDE_FROM_ALL)
include(cmake/CPM.cmake)
CPMAddPackage(
NAME libyaml
VERSION 0.2.5
GITHUB_REPOSITORY "yaml/libyaml"
GIT_TAG "0.2.5"
EXCLUDE_FROM_ALL ON
)

add_library(fortran-yaml-c yaml_types.f90 fortran_yaml_c.f90 libyaml_interface.c)
target_link_libraries(fortran-yaml-c yaml)
target_include_directories(fortran-yaml-c PUBLIC libyaml/include)

add_executable(test_yaml test_yaml.f90)
target_link_libraries(test_yaml fortran-yaml-c)
Expand Down
21 changes: 21 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(CPM_DOWNLOAD_VERSION 0.34.3)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})
1 change: 0 additions & 1 deletion libyaml
Submodule libyaml deleted from acd6f6
39 changes: 19 additions & 20 deletions libyaml_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,58 +62,57 @@ TypeNode* read_value(yaml_document_t *document_p, yaml_node_t *node)
{
yaml_node_t *next_node_p;
TypeNode *mynode;

switch (node->type) {
switch (node->type) {
case YAML_NO_NODE:
mynode = create_TypeNode();
mynode = create_TypeNode();
mynode->type = 4;
break;
case YAML_SCALAR_NODE:
break;
case YAML_SCALAR_NODE:
mynode = create_TypeNode();
mynode->type = 3;
mynode->string = (char*) malloc(STRING_LENGTH * sizeof(char));
set_string((char *)node->data.scalar.value, mynode->string);
break;
case YAML_SEQUENCE_NODE:
break;
case YAML_SEQUENCE_NODE:
mynode = create_TypeNode();
mynode->type = 2;
mynode->first_listitem = create_TypeNode();

yaml_node_item_t *i_node;
yaml_node_item_t *i_node;
TypeNode *listitem = mynode->first_listitem;
for (i_node = node->data.sequence.items.start; i_node < node->data.sequence.items.top; i_node++) {
next_node_p = yaml_document_get_node(document_p, *i_node);
listitem->node = read_value(document_p, next_node_p);
for (i_node = node->data.sequence.items.start; i_node < node->data.sequence.items.top; i_node++) {
next_node_p = yaml_document_get_node(document_p, *i_node);
listitem->node = read_value(document_p, next_node_p);
if (i_node < node->data.sequence.items.top - 1){
listitem->next_listitem = create_TypeNode();
listitem = listitem->next_listitem;
}
}
break;
case YAML_MAPPING_NODE:
break;
case YAML_MAPPING_NODE:

mynode = create_TypeNode();
mynode = create_TypeNode();

mynode->type = 1;
mynode->first_keyvaluepair = create_TypeNode();

TypeNode *keyvaluepair = mynode->first_keyvaluepair;
yaml_node_pair_t *i_node_p;
for (i_node_p = node->data.mapping.pairs.start; i_node_p < node->data.mapping.pairs.top; i_node_p++) {
yaml_node_pair_t *i_node_p;
for (i_node_p = node->data.mapping.pairs.start; i_node_p < node->data.mapping.pairs.top; i_node_p++) {

keyvaluepair->key = (char*) malloc(STRING_LENGTH * sizeof(char));
next_node_p = yaml_document_get_node(document_p, i_node_p->key);
// strcpy(keyvaluepair->key, next_node_p->data.scalar.value);
set_string((char *)next_node_p->data.scalar.value, keyvaluepair->key);

next_node_p = yaml_document_get_node(document_p, i_node_p->value);
keyvaluepair->value = read_value(document_p, next_node_p);
next_node_p = yaml_document_get_node(document_p, i_node_p->value);
keyvaluepair->value = read_value(document_p, next_node_p);

if (i_node_p < node->data.mapping.pairs.top - 1){
keyvaluepair->next_keyvaluepair = create_TypeNode();
keyvaluepair = keyvaluepair->next_keyvaluepair;
}
}
}
break;
}
return mynode;
Expand Down Expand Up @@ -199,7 +198,7 @@ TypeNode* LoadFile_c(const char *file_name, char *error)
}

root = read_value(&document, yaml_document_get_root_node(&document));
yaml_document_delete(&document);
yaml_document_delete(&document);
yaml_parser_delete(&parser);
fclose(file);

Expand Down

0 comments on commit 31259bb

Please sign in to comment.