Readme: | # libgargp for MorphOS
Version : 1.0 Date : 2025-10-11 Author : Digitally
# Description
libargp is a GNU argument parsing library ported to MorphOS with full -noixemul support. This allows MorphOS developers to use the powerful argp API for command-line argument parsing.
# Features
- Full argp-standalone 1.3 functionality - Compiled with -noixemul for native compatibility - Compatible with SDL2 and other native MorphOD libraries - Automatic --help and --version generation - Clean argument parsing with minimal code
# Installation
1. Copy libargp.a to gg/lib/ 2. Copy argp.h to gg/include
# Usage
Include argp.h in your program: #include <argp.h> Compile with -largp and -noixemul gcc -o myprogram myprogram.c -noixemul -largp # Example
See example.c for a complete working example # Technical details
- mempcpy() implementation (GNU extension) - getpid() implementation using MorphOS Task - struct group renamed argp_group to avoid conflits - all standard string functions (memset, memmove, strlen, ..)
# Requirements
- MorphOS 3.19 or later - GCC Compiler - -noixemul flag required for compilation # Licence
This is based on argp-standalone 1.3, which is derived from glibc Licensed under LGPL 2.1 or later # Credits
- Original argp from GNU C Library (glibc) - argp-standalone by Niels M�ller - MorphOS port patches by Digitally
# Contact
digitallytechno@proton.me ### Version 1.0 (2025-10-11) - Initial MorphOS port - Full -noixemul support - All GNU extensions implemented # Example
/* * Simple example of using argp on MorphOS * Compile with gcc -o example example.c -noixemul -largp */ #include <argp.h> #include <stdio.h> #include <stdlib.h> const char *argp_program_version = "example 1.0"; const char *argp_program_bug_address = "<your@email.com>"; static char doc[] = "Example program using argp on MorphOS"; static char args_doc[] = "[FILE]"; static struct argp_option options[] = { { "verbose", 'v', 0, 0, "Produce verbose output" }, { "quiet", 'q', 0, 0, "Don't produce any output" }, { "output", 'o', FILE, 0, "Output to FILE instead of standard output" }, { 0 } } struct arguments { char *input_file; char *output_file; int verbose; int quiet; } static error_t parseopt(int key, char *arg, struct argp_state *state) { struct arguments *arguments = state->input; switch(key) { case 'v': arguments->verbose = 1; break; case 'q': arguments->quiet = 1; break; case 'o': arguments->output_file = arg; break; case ARGP_KEY_ARG: if(state->arg_num >= 1) argp_usage(state); arguments->input_file = arg; break; case ARGP_KEY_END: if(state->arg_num < 1) argp_usage(state); break; default: return(ARGP_ERR_UNKNOWN); } return(0); } static struct argp argp = { options, parse_opt, args_doc, doc }; int main(int argc, char **argv) { struct arguments arguments; arguments.input_file = NULL; arguments.output_file = "-"; arguments.verbose = 0; arguments.quiet = 0; argp_parse(&argp, argc, argv, 0, 0, &arguments); if(!arguments.quiet) { printf("input_file: %s\n", arguments.input_file); printf("output_file: %s\n", arguments.output_file); if(arguments.verbose) printf("Verbose mode enabled\n"); } return(0); }
/* makefile */ CC = gcc CFLAGS = -noixemul -O2 -Wall LIBS = -largp example: example.c $(CC) $(CFLAGS) -o example example.c $(LIBS) clean: rm -f example
/* test example */ example --help ######## REMEMBER TO ALWAYS WITH -noixemul FLAG ##################
|