### Argtable3 Command-Line Usage Example Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_getting_started.md Demonstrates expected command-line interface for a utility program using argtable3. Shows help output format with available options, flags, and argument descriptions. ```shell $ util.exe --help Usage: util.exe [-v] [--help] [--version] [--level=] [-o myfile] []... Demonstrate command-line parsing in argtable3. --help display this help and exit --version display version information and exit --level= foo value -v, --verbose verbose output -o myfile output file input files ``` -------------------------------- ### Build Project with vcpkg Argtable3 Source: https://github.com/argtable/argtable3/blob/master/README.md Provides shell commands to create a build directory, configure the project with CMake using vcpkg for Argtable3, and compile the executable. Requires a configured vcpkg environment and CMake setup. Assumes a Windows static triplet example; may vary on other platforms. ```bash $ mkdir build $ cd build $ cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static $ cmake --build . ``` -------------------------------- ### Install Argtable3 with vcpkg for all projects Source: https://github.com/argtable/argtable3/blob/master/README.md Installs Argtable3 using vcpkg, making it available system-wide. This method involves cloning vcpkg, installing the package, and configuring CMake at build time via the command line, avoiding hardcoding paths in CMakeLists.txt. ```bash $ vcpkg install argtable3:x64-windows-static $ mkdir build $ cd build $ cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake $ cmake --build . ``` -------------------------------- ### Install Argtable3 System-Wide with vcpkg Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_installation.md Installs Argtable3 globally using vcpkg for all projects. Requires specifying the target triplet for static libraries. Assumes vcpkg is available in PATH. ```bash $ vcpkg install argtable3:x64-windows-static ``` -------------------------------- ### Integrate Argtable3 Using vcpkg Source: https://github.com/argtable/argtable3/blob/master/README.md Demonstrates adding Argtable3 as a dependency in a vcpkg manifest for a single project, ensuring version compatibility and local installation. Involved files include the JSON manifest and CMake integration script for static linking and toolchain setup. Limitations include requiring vcpkg submodule and specific triplets for static builds. ```json {"name": "demo", "version": "0.0.1", "dependencies": [ { "name": "argtable3", "version>=": "3.2.1" } ], "builtin-baseline": "92b42c4c680defe94f1665a847d04ded890f372e" } ``` ```cmake cmake_minimum_required(VERSION 3.18) set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/deps/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file") project(versionstest) add_executable(main main.cpp) find_package(Argtable3 CONFIG REQUIRED) target_link_libraries(main PRIVATE argtable3::argtable3) if(VCPKG_TARGET_TRIPLET STREQUAL "x64-windows-static") set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$,Debug,>") endif() ``` -------------------------------- ### Building Argtable3 Programs Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_getting_started.md Build commands for compiling programs that use argtable3 library. Includes commands for Microsoft Visual C++ (cl.exe) and GCC/MinGW/Cygwin compilers. Links the source file with argtable3.c. ```shell C:\> cl.exe util.c argtable3.c ``` ```shell $ gcc util.c argtable3.c ``` -------------------------------- ### Argtable3 C Implementation Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_getting_started.md Complete C implementation using argtable3 library for command-line parsing. Includes argument definitions for help, version, level, verbose, output file, and input files. Handles help display priority, error reporting, and proper memory cleanup. ```c #include "argtable3.h" #include #include /* global arg_xxx structs */ arg_lit_t *verb, *help, *version; arg_int_t *level; arg_file_t *o, *file; arg_end_t *end; int main(int argc, char *argv[]) { /* the global arg_xxx structs are initialised within the argtable */ void *argtable[] = { help = arg_litn(NULL, "help", 0, 1, "display this help and exit"), version = arg_litn(NULL, "version", 0, 1, "display version info and exit"), level = arg_intn(NULL, "level", "", 0, 1, "foo value"), verb = arg_litn("v", "verbose", 0, 1, "verbose output"), o = arg_filen("o", NULL, "myfile", 0, 1, "output file"), file = arg_filen(NULL, NULL, "", 1, 100, "input files"), end = arg_end(20), }; int exitcode = 0; char progname[] = "util.exe"; int nerrors = arg_parse(argc, argv, argtable); /* special case: '--help' takes precedence over error reporting */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("Demonstrate command-line parsing in argtable3.\n\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); exitcode = 0; goto exit; } /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); exitcode = 1; goto exit; } exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return exitcode; } ``` -------------------------------- ### Setup Python Virtual Environment and Install Meson Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md Creates a Python virtual environment and installs the Meson build system. The virtual environment isolates dependencies and ensures consistent build environment across different systems. ```bash python -m venv .venv .venv\Scripts\activate # On Windows # or source .venv/bin/activate # On Linux/macOS pip install meson ``` -------------------------------- ### Generate Local Argtable3 Documentation (Shell) Source: https://github.com/argtable/argtable3/blob/master/README.md Builds HTML documentation using Docker via Makefile. Requires Docker installed; run from repository root; outputs HTML files in docs/build/html; no inputs needed beyond repo presence; limited to environments with Docker support. ```shell make docs ``` -------------------------------- ### CMake Integration with vcpkg for Argtable3 Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_installation.md Integrates vcpkg with CMake to link Argtable3 in a C++ project. Sets toolchain file and links the static library. Includes MSVC runtime configuration for static builds. ```cmake cmake_minimum_required(VERSION 3.18) set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/deps/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file") project(versionstest) add_executable(main main.cpp) find_package(Argtable3 CONFIG REQUIRED) target_link_libraries(main PRIVATE argtable3::argtable3) if(VCPKG_TARGET_TRIPLET STREQUAL "x64-windows-static") set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() ``` -------------------------------- ### Add Argtable3 Dependency to vcpkg Manifest Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_installation.md Adds Argtable3 as a dependency in the vcpkg.json manifest file. Requires a valid version number and baseline commit. Used for managing project-specific dependencies with vcpkg. ```json { "name": "demo", "version": "0.0.1", "dependencies": [ { "name": "argtable3", "version>=": "3.2.1" } ], "builtin-baseline": "92b42c4c680defe94f1665a847d04ded890f372e" } ``` -------------------------------- ### Generate and Install Pkg-Config File Source: https://github.com/argtable/argtable3/blob/master/CMakeLists.txt Configures and installs project.pc file from template for pkg-config usage in libdir. Uses @ONLY substitution; depends on PackagingTemplatesDir. Inputs: template file; outputs: installed .pc file. ```cmake set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc") configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) install(FILES "${PKG_CONFIG_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) ``` -------------------------------- ### Basic CMake Build for Argtable3 in Debug Mode (Shell) Source: https://github.com/argtable/argtable3/blob/master/README.md This snippet demonstrates building Argtable3 using CMake in Debug configuration, followed by building and testing. It requires CMake installed and generates a static library by default. Inputs are source directory and build type; outputs are built binaries in the build directory; limited to single configuration per build directory. ```shell cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build --config Debug ctest --test-dir build -C Debug ``` -------------------------------- ### Integrate Argtable3 dependency with Conan and CMake Source: https://github.com/argtable/argtable3/blob/master/README.md Manages Argtable3 as a dependency using Conan and integrates it with CMake. A conanfile.txt specifies the requirement and generators, Conan installs the package and generates CMake integration files. CMake then uses find_package and target_link_libraries to use Argtable3. ```text [requires] argtable3/3.3.1 [generators] CMakeDeps CMakeToolchain ``` ```bash conan install . --output-folder=build --build=missing -s build_type=Release ``` ```cmake # CMakeLists.txt cmake_minimum_required (VERSION 3.15) project(demo C) # Find the package configuration files generated by Conan find_package(Argtable3 REQUIRED) add_executable(main main.c) # Link the imported target provided by Conan target_link_libraries(main PRIVATE argtable3::argtable3) ``` ```bash # From your project root cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release cmake --build build ``` -------------------------------- ### Checkout and Build Tagged Version of Argtable3 (Shell) Source: https://github.com/argtable/argtable3/blob/master/README.md Uses Makefile to list and checkout a specific tagged version, then builds it with CMake in Debug mode including tests. Requires Git and CMake; inputs are tag name like v3.3.1; outputs built version in .archive subdirectory; supports multiple configurations via separate build dirs. ```shell make taglist Available TAGs: ... v3.3.1 ... make co TAG=v3.3.1 cd .archive/argtable-v3.3.1 cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build --config Debug ctest --test-dir build -C Debug ``` -------------------------------- ### Install Argtable3 Targets with CMake Source: https://github.com/argtable/argtable3/blob/master/src/CMakeLists.txt This snippet demonstrates how to install the argtable3 library targets using CMake. It specifies destinations for runtime libraries, static libraries, archives, and public headers. This ensures the library is properly installed on the target system. ```cmake install(TARGETS argtable3 EXPORT ${ARGTABLE3_PACKAGE_NAME}Config RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### CMake Configuration without Toolchain File in Source Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_installation.md Configures CMake without hardcoding the toolchain file path. Suitable when developers have vcpkg installed in different locations. The toolchain file is specified via command line. ```bash $ mkdir build $ cd build $ cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake $ cmake --build . ``` -------------------------------- ### Multi-Command Application in C Source: https://context7.com/argtable/argtable3/llms.txt Demonstrates building a multi-command application using Argtable3. This example registers 'help', 'version', and 'list' subcommands, providing a structure for complex command-line interfaces. Error handling and argument parsing are included. ```c #include "argtable3.h" #include #include // Handler for \"help\" subcommand int cmd_help_proc(int argc, char* argv[], arg_dstr_t res, void* ctx) { arg_dstr_catf(res, "Available commands:\n"); arg_dstr_catf(res, " help - Show this help message\n"); arg_dstr_catf(res, " version - Show version information\n"); arg_dstr_catf(res, " list - List all items\n"); return 0; } // Handler for \"version\" subcommand int cmd_version_proc(int argc, char* argv[], arg_dstr_t res, void* ctx) { arg_dstr_catf(res, "myapp version 1.0.0\n"); return 0; } // Handler for \"list\" subcommand with its own arguments int cmd_list_proc(int argc, char* argv[], arg_dstr_t res, void* ctx) { struct arg_lit *verbose = arg_lit0(\"v\", \"verbose\", \"verbose output\"); struct arg_str *filter = arg_str0(\"f\", \"filter\", "", \"filter pattern\"); struct arg_end *end = arg_end(20); void* argtable[] = {verbose, filter, end}; if (arg_nullcheck(argtable) != 0) { arg_dstr_catf(res, "insufficient memory\n"); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors_ds(res, end, "list"); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } arg_dstr_catf(res, "Listing items"); if (verbose->count > 0) { arg_dstr_catf(res, " (verbose mode)"); } if (filter->count > 0) { arg_dstr_catf(res, " with filter: %s", filter->sval[0]); } arg_dstr_catf(res, "\n"); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } int main(int argc, char* argv[]) { // Set application metadata arg_set_module_name("myapp"); arg_set_module_version(1, 0, 0, "stable"); // Initialize command subsystem arg_cmd_init(); // Register subcommands arg_cmd_register("help", cmd_help_proc, "Show help message", NULL); arg_cmd_register("version", cmd_version_proc, "Show version information", NULL); arg_cmd_register("list", cmd_list_proc, "List all items", NULL); arg_dstr_t res = arg_dstr_create(); // Show help if no subcommand provided if (argc == 1) { arg_make_get_help_msg(res); printf("%s", arg_dstr_cstr(res)); arg_dstr_destroy(res); arg_cmd_uninit(); return 0; } // Dispatch to the appropriate subcommand int rv = arg_cmd_dispatch(argv[1], argc, argv, res); printf("%s", arg_dstr_cstr(res)); arg_dstr_destroy(res); arg_cmd_uninit(); return rv; } ``` -------------------------------- ### Install Ninja Build System Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md Installs Ninja as the build backend for Meson. Ninja is required for executing build steps efficiently and provides fast compilation times compared to other build systems. ```bash pip install ninja ``` -------------------------------- ### Complex Multi-Option Parsing with Help using argtable3 in C Source: https://context7.com/argtable/argtable3/llms.txt This example handles multiple options like --all, --recursive, --color with optional values, and file arguments, using arg_rem for custom help text. It generates usage and glossary on --help, and processes options to print states. Depends on argtable3; inputs are command-line options and files; outputs option confirmations and file lists; limitations include fixed default for --color and error handling via arg_print_errors. ```c #include "argtable3.h" #include int main(int argc, char **argv) { // Complex ls-like command with many options struct arg_lit *a = arg_lit0("a", "all", "do not hide entries starting with ."); struct arg_lit *recurse = arg_lit0("R", "recursive", "list subdirectories recursively"); struct arg_str *color = arg_str0(NULL, "color", "WHEN", "control whether color is used"); struct arg_rem *rem1 = arg_rem(NULL, " WHEN may be 'never', 'always', or 'auto'"); struct arg_int *tabsize = arg_int0("T", "tabsize", "COLS", "assume tab stops at each COLS"); struct arg_lit *help = arg_lit0(NULL, "help", "display this help and exit"); struct arg_file *files = arg_filen(NULL, NULL, "FILE", 0, argc+2, NULL); struct arg_end *end = arg_end(20); void* argtable[] = {a, recurse, color, rem1, tabsize, help, files, end}; const char* progname = "ls"; if (arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // Allow optional argument values for --color color->hdr.flag |= ARG_HASOPTVALUE; color->sval[0] = "always"; int nerrors = arg_parse(argc, argv, argtable); if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("List information about the FILE(s).\n\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } if (nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // Process options if (a->count > 0) printf("Show all files\n"); if (recurse->count > 0) printf("Recursive mode\n"); if (color->count > 0) printf("Color mode: %s\n", color->sval[0]); if (tabsize->count > 0) printf("Tab size: %d\n", tabsize->ival[0]); for (int i = 0; i < files->count; i++) { printf("File: %s\n", files->filename[i]); } arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } ``` -------------------------------- ### Install CMake Configuration with CMake Source: https://github.com/argtable/argtable3/blob/master/src/CMakeLists.txt This code snippet shows how to install the CMake configuration files for argtable3. It leverages `CMakePackageConfigHelpers` to create and install the configuration version file, ensuring proper package integration. ```cmake install(EXPORT ${ARGTABLE3_PACKAGE_NAME}Config NAMESPACE ${ARGTABLE3_PROJECT_NAME}:: DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR} ) ``` ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake" VERSION ${ARGTABLE3_VERSION} COMPATIBILITY SameMajorVersion ) ``` ```cmake install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake" DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR} ) ``` -------------------------------- ### Install Conan with pip Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_conan.md Instructions on how to install Conan package manager using pip within a virtual environment. This is used to manage dependencies and build packages. Requires Python and pip to be installed beforehand. ```bash python -m venv .venv .venv/Scripts/activate # On Windows # or source .venv/bin/activate # On Linux/macOS pip install conan ``` -------------------------------- ### Add Argtable3 dependency using Meson WrapDB Source: https://github.com/argtable/argtable3/blob/master/README.md Integrates Argtable3 as a dependency in a Meson build system project. It involves adding Argtable3's wrap file to the project's subprojects directory and declaring the dependency in the meson.build file. Meson handles downloading and building the dependency automatically. ```bash $ meson wrap install argtable3 ``` ```meson # meson.build project('demo', 'c', version: '0.0.1') # Find the argtable3 dependency. Meson will find it in the subprojects # directory via the .wrap file. argtable3_dep = dependency('argtable3', version: '>=3.3.1') executable( 'main', 'main.c', dependencies: [argtable3_dep] ) ``` ```bash meson setup build meson compile -C build ``` -------------------------------- ### Add Subdirectories for Library, Examples, and Tests Source: https://github.com/argtable/argtable3/blob/master/CMakeLists.txt Adds src subdirectory for library build; conditionally adds examples and tests based on ARGTABLE3_ENABLE_* flags, enabling testing for tests. Depends on subdir CMakeLists; outputs: built targets in subdirs. Limitations: tests require enable flag. ```cmake add_subdirectory(src) if(ARGTABLE3_ENABLE_EXAMPLES) add_subdirectory(examples) endif() if(ARGTABLE3_ENABLE_TESTS) enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### Configure CPack Packaging and Resources Source: https://github.com/argtable/argtable3/blob/master/CMakeLists.txt Sets packaging templates directory and CPack resource files for license and readme. Installs license and readme during packaging; depends on CPack module. Limitations: uses current source dir for templates. ```cmake set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") ``` -------------------------------- ### CMake Build with Shared Libraries Enabled (Shell) Source: https://github.com/argtable/argtable3/blob/master/README.md Configures and builds Argtable3 with dynamic (shared) libraries instead of static ones, using Debug mode. Depends on CMake; set BUILD_SHARED_LIBS to ON explicitly as default is OFF. Produces shared library outputs; suitable for single configuration builds. ```shell cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON .. ``` -------------------------------- ### Set Install Directories based on OS with CMake Source: https://github.com/argtable/argtable3/blob/master/src/CMakeLists.txt This code determines the installation directory based on the operating system (UNIX, MSYS, MINGW, PSP, or WIN32) and sets the ARGTABLE3_INSTALL_CMAKEDIR variable accordingly. ```cmake if(UNIX OR MSYS OR MINGW OR PSP) set(ARGTABLE3_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/argtable3) elseif(WIN32) set(ARGTABLE3_INSTALL_CMAKEDIR "cmake") endif() ``` -------------------------------- ### Validate Arguments Using Regular Expressions in C Source: https://context7.com/argtable/argtable3/llms.txt Demonstrates argument validation using regular expressions with argtable3. The example accepts 1-10 email addresses via the --email flag and validates them against a regex pattern for email format validation. Shows built-in regex validation, error handling, and iteration through validated results. ```c #include "argtable3.h" #include int main(int argc, char **argv) { // Accept email addresses matching a regex pattern struct arg_rex *emails = arg_rexn(NULL, "email", "^[^@]+@[^@]+\\.[^@]+$", "", 1, 10, 0, "Email addresses"); struct arg_end *end = arg_end(20); void* argtable[] = {emails, end}; const char* progname = "emailvalidator"; if (arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // All emails have been validated against the regex for (int i = 0; i < emails->count; i++) { printf("Valid email[%d]: %s\n", i, emails->sval[i]); } arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } ``` -------------------------------- ### Add source to conandata.yml Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_conan.md Example of adding a new source entry to the conandata.yml file. Shows how to incorporate source URL and SHA256 hash. ```yaml sources: # ... existing versions ... "3.3.0": url: "https://github.com/argtable/argtable3/releases/download/v3.3.0.116da6c/argtable-v3.3.0.116da6c.tar.gz" sha256: "21d653eaab4b9dede76ceb0cb4e8878cf5cadb48ef9180c6a4d1a5cef1549e65" ``` -------------------------------- ### Add version to config.yml Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_conan.md Example of adding a new version entry to the config.yml file, mapping it to the appropriate recipe folder. This tells Conan where to find the build recipe ```yaml versions: # ... existing versions ... "3.3.0": folder: "all" # Or whatever folder the latest recipe is in ``` -------------------------------- ### Cleanup Build Directory for Argtable3 (Shell) Source: https://github.com/argtable/argtable3/blob/master/README.md Removes the entire build directory to clean up after a CMake build. No dependencies beyond basic shell; inputs are the build path; outputs a cleaned workspace; use instead of make clean for complete removal. ```shell rm -rf build ``` -------------------------------- ### Integer and String Argument Parsing in Argtable3 Source: https://context7.com/argtable/argtable3/llms.txt This example shows parsing integer (-k), multiple strings (-D), and file (-o) arguments with defaults and multi-occurrence support. It handles validation, error printing, and value access post-parsing. Requires argtable3.h and stdio.h; processes argc/argv as inputs; outputs parsed values for use in the program; limited by max occurrences defined in arg_strn. ```c #include "argtable3.h" #include int main(int argc, char **argv) { // Define arguments: -k , -D (multiple), -o struct arg_int *repeat = arg_int0("k", "scalar", NULL, "define scalar value k (default is 3)"); struct arg_str *defines = arg_strn("D", "define", "MACRO", 0, argc+2, "macro definitions"); struct arg_file *outfile = arg_file0("o", NULL, "", "output file (default is \"-\")"); struct arg_end *end = arg_end(20); void* argtable[] = {repeat, defines, outfile, end}; const char* progname = "myprog"; if (arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // Set default values before parsing repeat->ival[0] = 3; outfile->filename[0] = "-"; int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // Access parsed values printf("scalar k=%d\n", repeat->ival[0]); printf("output is \"%s\"\n", outfile->filename[0]); for (int i = 0; i < defines->count; i++) { printf("user defined macro \"%s\"\n", defines->sval[i]); } arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } ``` -------------------------------- ### Parse Double-Precision Floating Point Arguments in C Source: https://context7.com/argtable/argtable3/llms.txt Demonstrates how to parse multiple double-precision floating point arguments using argtable3. The example accepts 1-10 values via -v/--value flags and an optional threshold via -t/--threshold flag. Shows memory validation, error handling, and basic arithmetic operations on parsed values. ```c #include "argtable3.h" #include int main(int argc, char **argv) { // Accept multiple double values with -v or --value struct arg_dbl *values = arg_dbln("v", "value", "", 1, 10, "Input values"); struct arg_dbl *thresh = arg_dbl0("t", "threshold", "", "Threshold value"); struct arg_end *end = arg_end(20); void* argtable[] = {values, thresh, end}; const char* progname = "calculator"; if (arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } // Calculate sum of values double sum = 0.0; for (int i = 0; i < values->count; i++) { printf("Value[%d]: %f\n", i, values->dval[i]); sum += values->dval[i]; } printf("Sum: %f\n", sum); if (thresh->count > 0) { printf("Threshold: %f\n", thresh->dval[0]); if (sum > thresh->dval[0]) { printf("Sum exceeds threshold!\n"); } } arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } ``` -------------------------------- ### Parse Date Arguments with Format Validation in C Source: https://context7.com/argtable/argtable3/llms.txt Shows how to parse date arguments with custom format specifications using argtable3. The example accepts a single date argument in YYYY-MM-DD format via the --date flag. Demonstrates format validation, parsing into struct tm, and extraction of date components including day of week and day of year. ```c #include "argtable3.h" #include #include int main(int argc, char **argv) { // Accept date in YYYY-MM-DD format struct arg_date *date = arg_date1(NULL, "date", "%Y-%m-%d", "", "Date in YYYY-MM-DD format"); struct arg_end *end = arg_end(20); void* argtable[] = {date, end}; const char* progname = "dateutil"; if (arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 1; } if (date->count > 0) { struct tm *parsed_date = &date->tmval[0]; printf("Parsed date: %04d-%02d-%02d\n", parsed_date->tm_year + 1900, parsed_date->tm_mon + 1, parsed_date->tm_mday); printf("Day of week: %d\n", parsed_date->tm_wday); printf("Day of year: %d\n", parsed_date->tm_yday); } arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; } ``` -------------------------------- ### Basic Command-Line Parsing with Argtable3 Source: https://github.com/argtable/argtable3/blob/master/docs/source/index.md Demonstrates core Argtable3 functionality by implementing a command-line parser for a utility program. Shows declaration of argument structures, initialization of argument table, parsing logic, help message generation, error handling, and proper resource cleanup. Supports flags like --help, --version, --level, --verbose, -o option, and positional file arguments. ```c #include "argtable3.h" /* global arg_xxx structs */ struct arg_lit *verb, *help, *version; struct arg_int *level; struct arg_file *o, *file; struct arg_end *end; int main(int argc, char *argv[]) { /* the global arg_xxx structs are initialised within the argtable */ void *argtable[] = { help = arg_litn(NULL, "help", 0, 1, "display this help and exit"), version = arg_litn(NULL, "version", 0, 1, "display version info and exit"), level = arg_intn(NULL, "level", "", 0, 1, "foo value"), verb = arg_litn("v", "verbose", 0, 1, "verbose output"), o = arg_filen("o", NULL, "myfile", 0, 1, "output file"), file = arg_filen(NULL, NULL, "", 1, 100, "input files"), end = arg_end(20), }; int exitcode = 0; char progname[] = "util.exe"; int nerrors; nerrors = arg_parse(argc,argv,argtable); /* special case: '--help' takes precedence over error reporting */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("Demonstrate command-line parsing in argtable3.\n\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); exitcode = 0; goto exit; } /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); exitcode = 1; goto exit; } exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return exitcode; } ``` -------------------------------- ### Create Project Directory (Bash) Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md Commands to create a new directory for the test project and navigate into it. This sets up the workspace for the subsequent steps. ```bash mkdir ~/meson-test-app cd ~/meson-test-app ``` -------------------------------- ### Bootstrap vcpkg - Batch Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_vcpkg.md This command bootstraps the vcpkg instance on Windows. The -disableMetrics flag disables usage metrics. ```batch .\bootstrap-vcpkg.bat -disableMetrics ``` -------------------------------- ### Bootstrap vcpkg - Bash Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_vcpkg.md This command bootstraps the vcpkg instance on Linux/macOS. The -disableMetrics flag disables usage metrics. ```bash ./bootstrap-vcpkg.sh -disableMetrics ``` -------------------------------- ### Format Manifest File - Bash Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_vcpkg.md This command ensures the vcpkg.json file is correctly formatted. ```bash ./vcpkg format-manifest ports/argtable3/vcpkg.json ``` -------------------------------- ### Sample C Program with Argtable3 (C) Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md A simple C program that demonstrates the use of Argtable3 for command-line argument parsing. It includes basic help functionality and error handling. ```c // sample.c #include #include "argtable3.h" int main(int argc, char *argv[]) { struct arg_lit *help = arg_lit0("h", "help", "display this help and exit"); struct arg_end *end = arg_end(20); void *argtable[] = {help, end}; int nerrors = arg_parse(argc, argv, argtable); if (help->count > 0) { printf("Usage: %s", argv[0]); arg_print_syntax(stdout, argtable, "\n"); printf("\nSuccessfully tested local argtable3 wrap!\n"); arg_free(argtable); return 0; } if (nerrors > 0) { arg_print_errors(stdout, end, argv[0]); return 1; } printf("Test successful. Try running with --help.\n"); arg_free(argtable); return 0; } ``` -------------------------------- ### Add Version and Calculate Hash - Bash Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_vcpkg.md This command automates updating the version database and calculating the SHA512 hash for the argtable3 port. ```bash ./vcpkg x-add-version argtable3 ``` -------------------------------- ### arg_print_glossary Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_api_output.md Creates detailed glossaries of command-line arguments. Supports multiple formatting styles. ```APIDOC ## arg_print_glossary ### Description Generates a detailed glossary of all command-line arguments. ### Method FUNCTION ### Parameters #### Function Parameters - **fp** (FILE*) - Required - Output file stream - **argtable** (struct arg_*) - Required - Array of argument definitions - **format** (const char*) - Optional - Formatting string ### Response Prints argument glossary to the specified file stream. ``` -------------------------------- ### Dynamic String Utilities in C Source: https://context7.com/argtable/argtable3/llms.txt Demonstrates the usage of Argtable3's dynamic string utility for constructing strings efficiently. This includes appending content, using formatted output, resetting the string for reuse, and proper cleanup. ```c #include "argtable3.h" #include int main(void) { // Create a dynamic string arg_dstr_t dstr = arg_dstr_create(); // Append various content arg_dstr_cat(dstr, "Hello, "); arg_dstr_cat(dstr, "World!"); arg_dstr_catf(dstr, " The answer is %d.\n", 42); // Get the C string and print it printf("%s", arg_dstr_cstr(dstr)); // Reset the string for reuse arg_dstr_reset(dstr); arg_dstr_catf(dstr, "New content: %s\n", "test"); printf("%s", arg_dstr_cstr(dstr)); // Clean up arg_dstr_destroy(dstr); return 0; } ``` -------------------------------- ### Configure Meson Build Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md Bash command to configure a Meson build with static library and debug settings. Output shows Meson detecting and using the local subproject. ```bash meson setup build-static-debug -Ddefault_library=static -Db_vscrt=mtd --buildtype=debug ``` -------------------------------- ### Read and Configure Project Version from Tag File Source: https://github.com/argtable/argtable3/blob/master/CMakeLists.txt Reads version from 'version.tag' file, skips leading 'v', parses with safe_parse_semver, and sets PROJECT_VERSION_* variables including full and abbreviated versions. Defaults to 0.0.0 if file missing; assumes file existence check. Limitations: skips first character assuming 'v' prefix. ```cmake get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE) set(VERSION_TAG "0.0.0") # Default version if no tag file exists. if(EXISTS "${VERSION_TAG_PATH}") file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character. endif() safe_parse_semver("${VERSION_TAG}") set(PROJECT_VERSION_MAJOR ${SEMVER_MAJOR}) set(PROJECT_VERSION_MINOR ${SEMVER_MINOR}) set(PROJECT_VERSION_PATCH ${SEMVER_PATCH}) set(PROJECT_VERSION_PRERELEASE ${SEMVER_PRERELEASE}) set(PROJECT_VERSION_BUILD ${SEMVER_BUILD}) set(PROJECT_VERSION_TWEAK 0) set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}") set(ARGTABLE3_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(ARGTABLE3_FULL_VERSION "${VERSION_TAG}") ``` -------------------------------- ### Clone vcpkg Repository - Bash Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_vcpkg.md This command clones the forked vcpkg repository to your local machine. Replace YOUR_USERNAME with your GitHub username. ```bash git clone https://github.com/YOUR_USERNAME/vcpkg.git cd vcpkg ``` -------------------------------- ### Compile Project with Meson Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_dev_meson.md Bash command to compile the project using the configured Meson build directory. Verifies the build process completes successfully. ```bash meson compile -C build-static-debug ``` -------------------------------- ### arg_print_syntax Source: https://github.com/argtable/argtable3/blob/master/docs/source/arg_api_output.md Generates concise usage syntax for commands. Provides a compact overview of command structure. ```APIDOC ## arg_print_syntax ### Description Prints a concise syntax description of the command-line interface. ### Method FUNCTION ### Parameters #### Function Parameters - **fp** (FILE*) - Required - Output file stream - **argtable** (struct arg_*) - Required - Array of argument definitions ### Response Prints command syntax to the specified file stream. ``` -------------------------------- ### CPack Configuration in CMake Source: https://github.com/argtable/argtable3/blob/master/CMakeLists.txt This CMake script configures CPack for packaging the argtable3 library, setting general package metadata such as name, version, vendor, and homepage. It includes platform-specific settings for Debian (e.g., maintainer, section, depends on libc6-dev) and RPM (e.g., group, release), with suggestions for tools like cmake and pkg-config. Inputs are project variables like ARGTABLE3_VERSION; outputs are generated packages; limitations include reliance on upstream project settings and CPack generators like DEB, RPM, NSIS. ```cmake # Packaging (CPack) configuration ################################################################################ set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") set(CPACK_PACKAGE_VERSION "${ARGTABLE3_VERSION}") set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}") set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}") set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev") set(CPACK_DEBIAN_PACKAGE_SECTION "devel") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev") set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}") set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel") set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}") set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") set(CPACK_RPM_PACKAGE_URL "${CPACK_PACKAGE_HOMEPAGE_URL}") set(CPACK_RPM_PACKAGE_RELEASE 1) set(CPACK_DEB_COMPONENT_INSTALL ON) set(CPACK_RPM_COMPONENT_INSTALL ON) set(CPACK_NSIS_COMPONENT_INSTALL ON) set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") ################################################################################ # Enable CPack ################################################################################ include(CPack) ```