Skip to content

Commit

Permalink
Merge branch 'master' into tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoellendorf committed Mar 24, 2024
2 parents e98be48 + 432fe69 commit cc36d3e
Show file tree
Hide file tree
Showing 21 changed files with 682 additions and 64 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/trigger-gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: trigger-gitlab-ci
run-name: ${{ github.event_name }} triggered by ${{ github.actor }}

on:
push:
branches:
- master

jobs:
trigger-gitlab-ci:
runs-on: ubuntu-latest
steps:
- name: Trigger CI
run: curl -X POST --fail -F token=${{ secrets.trigger_gitlab_ci }} -F ref=main https://gitlab.com/api/v4/projects/54782732/trigger/pipeline
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
*.so.*
/example/iniexample
/example/parse
/example/iniwrite
/example/example.ini
# Autogenerate source file
/test/AllTests.c
/test/testrun
# Files generated by iniparser-meta
CMakeLists.txt
config.cmake.in
# CMake build directories
build*/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2000-2011 by Nicolas Devillard.
Copyright (c) 2000-2024 by Nicolas Devillard and many contributors
MIT License

Permission is hereby granted, free of charge, to any person obtaining a
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

# Iniparser 4 #

*Sept 2023: We are looking for volunteers to help us maintain this library!*

Maintaining open-source projects takes time we cannot always easily find. If you feel up to the task and already know this library well, please get in touch by email (ndevilla AT gmail) and let's figure it out!


## I - Overview

This modules offers parsing of ini files from the C level.
See a complete documentation in HTML format, from this directory
open the file html/index.html with any HTML-capable browser.
This modules offers parsing of ini files from C.
See the complete documentation in HTML format: from this directory,
open the file `html/index.html` with any HTML-capable browser.

Key features :
Key features:

- Small : around 1500 sloc inside 4 files (2 .c and 2 .h)
- Portable : no dependancies, written in `-ansi -pedantic` C89
- Fully reintrant : easy to make it thread-safe (just surround
- Fully re-entrant : easy to make it thread-safe (just surround
library calls by mutex)

## II - Building project
Expand All @@ -23,20 +27,22 @@ A simple `make` at the root of the project should be enough to get the static

You should consider trying the following rules too :

- `make check` : run the unitary tests

- `make check` : run unit tests
- `make example` : compile the example, run it with `./example/iniexample`

For installation and packaging see [iniparser-meta](https://gitlab.com/iniparser/iniparser-meta).

## III - License

This software is released under MIT License.
See LICENSE for full informations
See LICENSE for more details

## IV - Versions

Current version is 4.1. Version 4.0 introduces breaking changes in the api.
Older versions 3.1 and 3.2 with the legacy api are available as tags.


## V - FAQ

See [FAQ-en.md](FAQ-en.md) in this directory for answers to Frequently Asked Questions.
Expand Down
5 changes: 4 additions & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ RM ?= rm -f

default: all

all: iniexample parse
all: iniexample iniwrite parse

iniexample: iniexample.c
$(CC) $(CFLAGS) -o iniexample iniexample.c -I../src -L.. -liniparser

iniwrite: iniwrite.c
$(CC) $(CFLAGS) -o iniwrite iniwrite.c -I../src -L.. -liniparser

parse: parse.c
$(CC) $(CFLAGS) -o parse parse.c -I../src -L.. -liniparser

Expand Down
1 change: 0 additions & 1 deletion example/iniexample.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "iniparser.h"

Expand Down
77 changes: 77 additions & 0 deletions example/iniwrite.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "iniparser.h"

void create_empty_ini_file(void)
{
FILE *ini;

if ((ini = fopen("example.ini", "w")) == NULL) {
fprintf(stderr, "iniparser: cannot create example.ini\n");
return;
}

fclose(ini);
}

int write_to_ini(const char *ini_name)
{
void *dictionary;
FILE *ini_file;
int ret = 0;

if (!ini_name) {
fprintf(stderr, "Invalid argurment\n");
return -1;
}

dictionary = iniparser_load(ini_name);

if (!dictionary) {
fprintf(stderr, "cannot parse file: %s\n", ini_name);
return -1;
}

/* set section */
ret = iniparser_set(dictionary, "Pizza", NULL);

if (ret < 0) {
fprintf(stderr, "cannot set section in: %s\n", ini_name);
ret = -1;
goto free_dict;
}

/* set key/value pair */
ret = iniparser_set(dictionary, "Pizza:Cheese", "TRUE");

if (ret < 0) {
fprintf(stderr, "cannot set key/value in: %s\n", ini_name);
ret = -1;
goto free_dict;
}

ini_file = fopen(ini_name, "w+");

if (!ini_file) {
fprintf(stderr, "iniparser: cannot create example.ini\n");
ret = -1;
goto free_dict;
}

iniparser_dump_ini(dictionary, ini_file);
fclose(ini_file);
free_dict:
iniparser_freedict(dictionary);
return ret;
}

int main(int argc, char *argv[])
{
int ret;

if (argc < 2) {
create_empty_ini_file();
ret = write_to_ini("example.ini");
} else
ret = write_to_ini(argv[1]);

return ret ;
}
1 change: 0 additions & 1 deletion example/parse.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "iniparser.h"

Expand Down
22 changes: 9 additions & 13 deletions src/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/** Maximum value size for integers and doubles. */
#define MAXVALSZ 1024

/** Minimal allocated number of entries in a dictionary */
#define DICTMINSZ 128

/** Invalid key token */
#define DICT_INVALID_KEY ((char*)-1)

/*---------------------------------------------------------------------------
Private functions
---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -140,7 +133,7 @@ unsigned dictionary_hash(const char * key)
/**
@brief Create a new dictionary object.
@param size Optional initial size of the dictionary.
@return 1 newly allocated dictionary objet.
@return 1 newly allocated dictionary object.
This function allocates a new dictionary object of given size and returns
it. If you do not know in advance (roughly) the number of entries in the
Expand Down Expand Up @@ -176,7 +169,7 @@ dictionary * dictionary_new(size_t size)
/*--------------------------------------------------------------------------*/
void dictionary_del(dictionary * d)
{
ssize_t i ;
size_t i ;

if (d==NULL) return ;
for (i=0 ; i<d->size ; i++) {
Expand Down Expand Up @@ -209,7 +202,10 @@ void dictionary_del(dictionary * d)
const char * dictionary_get(const dictionary * d, const char * key, const char * def)
{
unsigned hash ;
ssize_t i ;
size_t i ;

if(d == NULL || key == NULL)
return def ;

hash = dictionary_hash(key);
for (i=0 ; i<d->size ; i++) {
Expand Down Expand Up @@ -254,7 +250,7 @@ const char * dictionary_get(const dictionary * d, const char * key, const char *
/*--------------------------------------------------------------------------*/
int dictionary_set(dictionary * d, const char * key, const char * val)
{
ssize_t i ;
size_t i ;
unsigned hash ;

if (d==NULL || key==NULL) return -1 ;
Expand Down Expand Up @@ -314,7 +310,7 @@ int dictionary_set(dictionary * d, const char * key, const char * val)
void dictionary_unset(dictionary * d, const char * key)
{
unsigned hash ;
ssize_t i ;
size_t i ;

if (key == NULL || d == NULL) {
return;
Expand Down Expand Up @@ -362,7 +358,7 @@ void dictionary_unset(dictionary * d, const char * key)
/*--------------------------------------------------------------------------*/
void dictionary_dump(const dictionary * d, FILE * out)
{
ssize_t i ;
size_t i ;

if (d==NULL || out==NULL) return ;
if (d->n<1) {
Expand Down
9 changes: 3 additions & 6 deletions src/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
---------------------------------------------------------------------------*/

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

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,8 +40,8 @@ extern "C" {
*/
/*-------------------------------------------------------------------------*/
typedef struct _dictionary_ {
int n ; /** Number of entries in dictionary */
ssize_t size ; /** Storage size */
unsigned n ; /** Number of entries in dictionary */
size_t size ; /** Storage size */
char ** val ; /** List of string values */
char ** key ; /** List of string keys */
unsigned * hash ; /** List of hash values for keys */
Expand Down Expand Up @@ -73,7 +70,7 @@ unsigned dictionary_hash(const char * key);
/**
@brief Create a new dictionary object.
@param size Optional initial size of the dictionary.
@return 1 newly allocated dictionary objet.
@return 1 newly allocated dictionary object.
This function allocates a new dictionary object of given size and returns
it. If you do not know in advance (roughly) the number of entries in the
Expand Down
Loading

0 comments on commit cc36d3e

Please sign in to comment.