mirror of
https://github.com/goplus/llgo.git
synced 2025-09-26 19:51:21 +08:00

- Consolidate _demo, _pydemo, _embdemo into single _demo directory structure - Organize demos by language: _demo/{go,py,c,embed}/ - Categorize demos based on imports: - Python library demos (py imports) → _demo/py/ - C/C++ library demos (c/cpp imports) → _demo/c/ - Go-specific demos → _demo/go/ - Embedded demos → _demo/embed/ - Move C-related demos (asm*, cabi*, cgo*, linkname, targetsbuild) from go/ to c/ - Update all path references in README.md and GitHub workflows - Improve demo organization and navigation as requested in #1256 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
145 lines
3.6 KiB
Go
145 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
_ "unsafe"
|
|
|
|
"github.com/goplus/lib/c"
|
|
)
|
|
|
|
const LLGoPackage string = "link: $(pkg-config --libs cargs);"
|
|
|
|
type Option struct {
|
|
Identifier c.Char
|
|
AccessLetters *c.Char
|
|
AccessName *c.Char
|
|
ValueName *c.Char
|
|
Description *c.Char
|
|
}
|
|
|
|
type OptionContext struct {
|
|
Options *Option
|
|
OptionCount c.SizeT
|
|
Argc c.Int
|
|
Argv **c.Char
|
|
Index c.Int
|
|
InnerIndex c.Int
|
|
ErrorIndex c.Int
|
|
ErrorLetter c.Char
|
|
ForcedEnd bool
|
|
Identifier c.Char
|
|
Value *c.Char
|
|
}
|
|
|
|
// llgo:type C
|
|
type Printer func(__llgo_arg_0 c.Pointer, __llgo_arg_1 *c.Char, __llgo_va_list ...interface{}) c.Int
|
|
|
|
// llgo:link (*OptionContext).OptionInit C.cag_option_init
|
|
func (recv_ *OptionContext) OptionInit(options *Option, option_count c.SizeT, argc c.Int, argv **c.Char) {
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionFetch C.cag_option_fetch
|
|
func (recv_ *OptionContext) OptionFetch() bool {
|
|
return false
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGetIdentifier C.cag_option_get_identifier
|
|
func (recv_ *OptionContext) OptionGetIdentifier() c.Char {
|
|
return 0
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGetValue C.cag_option_get_value
|
|
func (recv_ *OptionContext) OptionGetValue() *c.Char {
|
|
return nil
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGetIndex C.cag_option_get_index
|
|
func (recv_ *OptionContext) OptionGetIndex() c.Int {
|
|
return 0
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGetErrorIndex C.cag_option_get_error_index
|
|
func (recv_ *OptionContext) OptionGetErrorIndex() c.Int {
|
|
return 0
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGetErrorLetter C.cag_option_get_error_letter
|
|
func (recv_ *OptionContext) OptionGetErrorLetter() c.Char {
|
|
return 0
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionPrintError C.cag_option_print_error
|
|
func (recv_ *OptionContext) OptionPrintError(destination *c.FILE) {
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionPrinterError C.cag_option_printer_error
|
|
func (recv_ *OptionContext) OptionPrinterError(printer Printer, printer_ctx c.Pointer) {
|
|
}
|
|
|
|
// llgo:link (*Option).OptionPrint C.cag_option_print
|
|
func (recv_ *Option) OptionPrint(option_count c.SizeT, destination *c.FILE) {
|
|
}
|
|
|
|
// llgo:link (*Option).OptionPrinter C.cag_option_printer
|
|
func (recv_ *Option) OptionPrinter(option_count c.SizeT, printer Printer, printer_ctx c.Pointer) {
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionPrepare C.cag_option_prepare
|
|
func (recv_ *OptionContext) OptionPrepare(options *Option, option_count c.SizeT, argc c.Int, argv **c.Char) {
|
|
}
|
|
|
|
// llgo:link (*OptionContext).OptionGet C.cag_option_get
|
|
func (recv_ *OptionContext) OptionGet() c.Char {
|
|
return 0
|
|
}
|
|
|
|
func main() {
|
|
options := []Option{
|
|
{
|
|
Identifier: 'h',
|
|
AccessLetters: c.Str("h"),
|
|
AccessName: c.Str("help"),
|
|
ValueName: nil,
|
|
Description: c.Str("Show help information"),
|
|
},
|
|
{
|
|
Identifier: 'v',
|
|
AccessLetters: c.Str("v"),
|
|
AccessName: c.Str("version"),
|
|
ValueName: nil,
|
|
Description: c.Str("Show version information"),
|
|
},
|
|
}
|
|
|
|
args := os.Args
|
|
|
|
// Convert Go string array to C-style argv
|
|
argv := make([]*int8, len(args))
|
|
for i, arg := range args {
|
|
argv[i] = c.AllocaCStr(arg)
|
|
}
|
|
|
|
// Initialize option context
|
|
var context OptionContext
|
|
context.OptionInit(&options[0], uintptr(len(options)), c.Int(len(args)), &argv[0])
|
|
|
|
// Process all options
|
|
identifierFound := false
|
|
for context.OptionFetch() {
|
|
identifierFound = true
|
|
identifier := context.OptionGetIdentifier()
|
|
switch identifier {
|
|
case 'h':
|
|
fmt.Println("Help: This is a simple command-line parser demo")
|
|
case 'v':
|
|
fmt.Println("Version: 1.0.0")
|
|
}
|
|
}
|
|
|
|
// Default output if no identifier is found
|
|
if !identifierFound {
|
|
fmt.Println("Demo Command-line Tool\nIdentifier:\n\t-h: Help\n\t-v: Version")
|
|
}
|
|
}
|