You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
Go to file
alex 15a2b6d823 Squashed 'lib/ini/' content from commit 2b11e8fe
git-subtree-dir: lib/ini
git-subtree-split: 2b11e8fef86d0eefb225156e695be1c1d5c35cbc
12 months ago
.github Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
example Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
src Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
.gitattributes Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
.gitignore Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
LICENCE Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
README.md Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago
build.zig Squashed 'lib/ini/' content from commit 2b11e8fe 12 months ago

README.md

INI parser library

This is a very simple ini-parser library that provides:

  • Raw record reading
  • Leading/trailing whitespace removal
  • comments based on ; and #
  • Zig API
  • C API

Usage example

Zig

const std = @import("std");
const ini = @import("ini");

pub fn main() !void {
    const file = try std.fs.cwd().openFile("example.ini", .{});
    defer file.close();

    var parser = ini.parse(std.testing.allocator, file.reader());
    defer parser.deinit();

    var writer = std.io.getStdOut().writer();

    while (try parser.next()) |record| {
        switch (record) {
            .section => |heading| try writer.print("[{s}]\n", .{heading}),
            .property => |kv| try writer.print("{s} = {s}\n", .{ kv.key, kv.value }),
            .enumeration => |value| try writer.print("{s}\n", .{value}),
        }
    }
}

C

#include <ini.h>

#include <stdio.h>
#include <stdbool.h>

int main() {
  FILE * f = fopen("example.ini", "rb");
  if(!f)
    return 1;
  
  struct ini_Parser parser;
  ini_create_file(&parser, f);

  struct ini_Record record;
  while(true)
  {
    enum ini_Error error = ini_next(&parser, &record);
    if(error != INI_SUCCESS)
      goto cleanup;
    
    switch(record.type) {
      case INI_RECORD_NUL: goto done;
      case INI_RECORD_SECTION:
        printf("[%s]\n", record.section);
        break;
      case INI_RECORD_PROPERTY:
        printf("%s = %s\n", record.property.key, record.property.value);
        break;
      case INI_RECORD_ENUMERATION:
        printf("%s\n", record.enumeration);
        break;
    }

  }
done:

cleanup:
  ini_destroy(&parser);
  fclose(f);
  return 0;
}