GithubHelp home page GithubHelp logo

risknu / c_rcnf Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 32 KB

rcnf - Fast library for working with environment variables

License: Apache License 2.0

C 62.17% Python 31.81% CMake 6.03%
clang ctypes-wrapper environment-variables library python

c_rcnf's Introduction

Fast library for working with environment variables

This library provides functionality for working with environment variables, including fast addition and removal, as well as a convenient error handling system (or rather, its absence). The library is written in pure C using only built-in libraries. It is also equipped with a flexible lexer and supports both Windows and Unix systems, including MacOS and FreeBSD.

There is also a Python wrapper written using the built-in ctypes library for Python version 3.11 and above.

Features

Everything is written in C11, and the library does not depend on external modules, using only built-in modules.

Usage Examples

Since the library is designed to work with both C and Python, the usage examples are almost identical because it's just an adaptation from C to Python.

Working with environment variables

Python

from rcnf import get_env, unset_env, set_env
print(get_env("VAR_NAME")) # get
print(unset_env("VAR_NAME")) # remove
print(set_env("VAR_NAME", "VAR_VALUE")) # add

C

int main() {
    printf("%s\n", get_env("VAR_NAME")); // get (returns char*)
    printf("%s\n", unset_env("VAR_NAME")); // remove (returns int)
    printf("%s\n", set_env("VAR_NAME", "VAR_VALUE")); // add (returns int)
    return 0;
}

Reading from a file

Python

from rcnf import extract_from, extract_from_file, read_file
print(extract_from("NAME=ABC\n")) # extract from string 
print(extract_from_file("<file_path>")) # extract from file
print(read_file("<file_path>")) # read file

C

int main() {
    map_array get_from_string = extract_from("NAME=ABC\n"); // extract from string
    map_array get_from_file = extract_from_file("<file_path>"); // extract from file
    char* file_string = read_file("<file_path>"); // read file

    return 0;
}

map_array is a simple structure that contains lists keys, values, and their length (count), which can be compared to dict in Python.

To get a dict from an object of the map_array class in Python, you can use the class method to_dict() or the function map_to(<...>).

License

The project is distributed under the Apache License 2.0.

c_rcnf's People

Contributors

risknu avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.