Skip to content

Commit

Permalink
git subrepo clone https://github.com/pcercuei/libini.git deps/libini
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "deps/libini"
  merged:   "e2215436"
upstream:
  origin:   "https://github.com/pcercuei/libini.git"
  branch:   "master"
  commit:   "e2215436"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
  • Loading branch information
pcercuei committed Mar 21, 2022
1 parent 5bc8021 commit a5c9cf5
Show file tree
Hide file tree
Showing 12 changed files with 1,166 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deps/libini/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
python/setup.py
12 changes: 12 additions & 0 deletions deps/libini/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/pcercuei/libini.git
branch = master
commit = e22154361dfc63778a1ca4f153f085c5236ed8f7
parent = 1af7eab6e37f80f7cf469c9e86e0e1cd4524b1ba
method = merge
cmdver = 0.4.3
42 changes: 42 additions & 0 deletions deps/libini/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.1.0)
project(libini LANGUAGES C VERSION 0.1)

include(GNUInstallDirs)

set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE PATH "Installation directory for pkgconfig (.pc) files")

set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
if (NOT BUILD_SHARED_LIBS)
set(INI_STATIC_CFLAGS -Dlibini_STATIC)
endif (NOT BUILD_SHARED_LIBS)

set(LIBINI_PC ${CMAKE_CURRENT_BINARY_DIR}/libini.pc)
configure_file(libini.pc.cmakein ${LIBINI_PC} @ONLY)
install(FILES ${LIBINI_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")

set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py)
configure_file(python/setup.py.cmakein ${SETUP_PY} @ONLY)

set(LIBINI_CFILES libini.c)
set(LIBINI_HEADERS ini.h)

if (CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()

add_library(ini ${LIBINI_CFILES} ${LIBINI_HEADERS})
set_target_properties(ini PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER ${LIBINI_HEADERS}
)

target_compile_definitions(ini PUBLIC ${INI_STATIC_CFLAGS})

install(TARGETS ini
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
502 changes: 502 additions & 0 deletions deps/libini/LICENSE.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions deps/libini/example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


TARGET = test

CC = $(CROSS_COMPILE)gcc
CFLAGS = -Wall -O2
LDFLAGS = -lini

OBJS = test.o

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

clean:
rm -f $(OBJS) $(TARGET)
72 changes: 72 additions & 0 deletions deps/libini/example/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

#include <alloca.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <ini.h>

int main(int argc, char **argv)
{
struct INI *ini;

if (argc < 2) {
printf("USAGE: test [INI_FILE]...\n");
return EXIT_SUCCESS;
}

ini = ini_open(argv[1]);
if (!ini)
return EXIT_FAILURE;
printf("INI file opened.\n");

while (1) {
const char *buf;
char *name;
size_t name_len;
int res = ini_next_section(ini, &buf, &name_len);
if (!res) {
printf("End of file.\n");
break;
}
if (res < 0) {
printf("ERROR: code %i\n", res);
goto error;
}

name = alloca(name_len + 1);
name[name_len] = '\0';
memcpy(name, buf, name_len);
printf("Opening section: \'%s\'\n", name);

while (1) {
const char *buf2;
char *key, *value;
size_t key_len, value_len;
res = ini_read_pair(ini, &buf, &key_len, &buf2, &value_len);
if (!res) {
printf("No more data.\n");
break;
}
if (res < 0) {
printf("ERROR: code %i\n", res);
goto error;
}

key = alloca(key_len + 1);
key[key_len] = '\0';
memcpy(key, buf, key_len);
value = alloca(value_len + 1);
value[value_len] = '\0';
memcpy(value, buf2, value_len);
printf("Reading key: \'%s\' value: \'%s\'\n", key, value);
}
}

ini_close(ini);
return EXIT_SUCCESS;

error:
ini_close(ini);
return EXIT_FAILURE;
}
37 changes: 37 additions & 0 deletions deps/libini/example/test.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

[Desktop Entry]

# Name of the application
Name = Foo

# Short description about the application
Comment = Foo's bar
# Executable. Append ' %f' if a file is required,
# e.g. 'foo %f' to load 'foo' with a file.
Exec = test.elf %f
# Set to 'true' if the application has to be launched inside a terminal.
Terminal = false
# Type of the link: always set to 'Applications'
Type = Application
# Whether or not the menu should notify that the application is being launched.
StartupNotify = true
# Name of the icon, WITHOUT EXTENSION, that should
# be assignated to this application.
Icon = nx
# List of categories on which the application should appear.
# A semicolon should separe the categories, and you must leave one
# semicolon at the end of the list.
Categories = games;
# Alternative actions for this link
Actions = Test;
[Action Test]
Test = This is a test.
93 changes: 93 additions & 0 deletions deps/libini/ini.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* libini - Library to read INI configuration files
*
* Copyright (C) 2014 Paul Cercueil <paul@crapouillou.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/

#ifndef __INI_H
#define __INI_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
# ifdef ini_EXPORTS
# define __api __declspec(dllexport)
# elif !defined(libini_STATIC)
# define __api __declspec(dllimport)
# else
# define __api
# endif
#elif __GNUC__ >= 4
# define __api __attribute__((visibility ("default")))
#else
# define __api
#endif

#include <stdlib.h>

struct INI;

__api struct INI *ini_open(const char *file);
__api struct INI *ini_open_mem(const char *buf, size_t len);

__api void ini_close(struct INI *ini);

/* Jump to the next section.
* if 'name' is set, the pointer passed as argument
* points to the name of the section. 'name_len' is set to the length
* of the char array.
* XXX: the pointer will be invalid as soon as ini_close() is called.
*
* Returns:
* -EIO if an error occurred while reading the file,
* 0 if no more section can be found,
* 1 otherwise.
*/
__api int ini_next_section(struct INI *ini,
const char **name, size_t *name_len);

/* Read a key/value pair.
* 'key' and 'value' must be valid pointers. The pointers passed as arguments
* will point to the key and value read. 'key_len' and 'value_len' are
* set to the length of their respective char arrays.
* XXX: the pointers will be invalid as soon as ini_close() is called.
*
* Returns:
* -EIO if an error occurred while reading the file,
* 0 if no more key/value pairs can be found,
* 1 otherwise.
*/
__api int ini_read_pair(struct INI *ini,
const char **key, size_t *key_len,
const char **value, size_t *value_len);

/* Set the read head to a specified offset. */
__api void ini_set_read_pointer(struct INI *ini, const char *pointer);

/* Get the number of the line that contains the specified address.
*
* Returns:
* -EINVAL if the pointer points outside the INI string,
* The line number otherwise.
*/
__api int ini_get_line_number(struct INI *ini, const char *pointer);

#ifdef __cplusplus
}
#endif

#undef __api

#endif /* __INI_H */
Loading

0 comments on commit a5c9cf5

Please sign in to comment.