Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

pyCLIG — Command Line Interface Generator (Python port)

pyCLIG is a Python reimplementation of Harald Kirsch's clig (Command Line Interface Generator), which was originally written in TCL and last released in 2004.

Given a .cli specification file, pyCLIG generates two C source files:

  • <base>.h — struct typedef and extern declarations
  • <base>.cparseCmdline(), usage(), and supporting helpers

The generated C code is intended to be functionally equivalent to what the original clig produced.

Usage

pyclig [-o outprefix] [-t C[,man]] [-d] [--style {default,kr}] <specfile.cli>
Flag Description
-o prefix Output file prefix (default: specfile without extension)
-t TYPE Output type(s): C and/or man, comma-separated (default: C)
-d Also generate showOptionValues() debug function
--style kr Emit K&R-formatted output, equivalent to indent -kr -nut -l85 (4-space indent, function signature on one line, space before ( in control flow)

.cli file format

The spec file uses a TCL-compatible syntax. Each directive is one logical line (backslash-newline continues to the next line). Brace quoting {...}, double quoting "...", and [exec cmd] substitution are supported.

Name        <program-name>
Usage       {one-line description}
Version     [exec date +%Y-%m-%d]
Commandline <varname>
Description {Text for the DESCRIPTION section of the man page.}
Author      {Name and contact for the AUTHOR section of the man page.}
SeeAlso     {related(1), programs(1)}

Flag   -flag  varname  {description}
String -opt   varname  {description}  [-c cmin cmax] [-d default ...] [-m]
Int    -opt   varname  {description}  [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Long   -opt   varname  {description}  [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Float  -opt   varname  {description}  [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Double -opt   varname  {description}  [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Rest   varname {description}          [-c cmin cmax]

Description, Author, and SeeAlso text is inserted verbatim into the corresponding man page sections. Multi-line content can span multiple lines inside brace quoting:

Description {
This program does something useful.

A second paragraph with more detail.
}

Use oo and -oo for positive and negative infinity in -c and -r arguments. Negative numeric defaults must be quoted to prevent them from being misread as option flags: use " -1" (with a leading space inside the quotes) or {-1}.

Changes from the original clig output

The generated C code is substantially the same as the original, but with the following improvements to eliminate compiler warnings on modern toolchains:

Correctness fixes

  • isspace UBisspace((int)*end) invokes undefined behaviour when char is signed and the value is > 127. Changed to isspace((unsigned char)*end) throughout.

Compiler warning fixes (-Wall -Wextra -Wwrite-strings)

  • char varPint varP — Flag presence fields in the generated struct were char; changed to int to avoid implicit narrowing and to match the = 1 assignments more naturally.

  • const char * parameters — Helper functions that only read a string argument now take const char * instead of char *, silencing -Wwrite-strings warnings at call sites.

  • checkFloatConversion conditional — This static helper is only emitted when the spec actually uses Float or Double options, avoiding -Wunused-function warnings on specs that have only integer/string options.

  • NULL instead of (type*)0 — Pointer fields in the static struct initialiser use NULL rather than explicit zero-casts.

  • int missingMandatory — Changed from char to int.

Style improvements

  • fputs instead of fprintf(stderr, "%s", ...) in usage() — removes a redundant format-string call for string constants, and eliminates -Wformat-nonliteral warnings with strict compilers.

  • Typo fixed — "to large" / "to small" in overflow error messages corrected to "too large" / "too small".

  • No LCLint annotations/*@null*/, /*@shared*/, and similar lclint directives have been removed; they served a static-analysis tool that is no longer in common use and were syntactically surprising.

Provenance

Original clig:

  • Author: Harald Kirsch clig@geggus.net
  • License: GNU General Public License, version 2
  • Last release: 2004

pyCLIG:

  • Author: Scott Ransom (port/modernisation)
  • License: GNU General Public License, version 2 (see LICENSE)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages