# -*- tcl -*- # Maintenance Instruction: leave the 999999.xxx.x as is and use punkshell 'dev make' or bin/punkmake to update from -buildversion.txt # module template: punkshell/src/decktemplates/vendor/punk/modules/template_module-0.0.2.tm # # Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. # Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # (C) 2024 # # @@ Meta Begin # Application punk::aliascore 999999.0a1.0 # Meta platform tcl # Meta license # @@ Meta End # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # doctools header # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[manpage_begin punkshell_module_punk::aliascore 0 999999.0a1.0] #[copyright "2024"] #[titledesc {punkshell command aliases}] [comment {-- Name section and table of contents description --}] #[moddesc {-}] [comment {-- Description at end of page heading --}] #[require punk::aliascore] #[keywords module alias] #[description] #[para] - # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section Overview] #[para] overview of punk::aliascore #[subsection Concepts] #[para] - # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Requirements # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[subsection dependencies] #[para] packages used by punk::aliascore #[list_begin itemized] package require Tcl 8.6- #*** !doctools #[item] [package {Tcl 8.6}] # #package require frobz # #*** !doctools # #[item] [package {frobz}] #*** !doctools #[list_end] # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section API] # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # oo::class namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #tcl::namespace::eval punk::aliascore::class { # #*** !doctools # #[subsection {Namespace punk::aliascore::class}] # #[para] class definitions # if {[info commands [namespace current]::interface_sample1] eq ""} { # #*** !doctools # #[list_begin enumerated] # # # oo::class create interface_sample1 { # # #*** !doctools # # #[enum] CLASS [class interface_sample1] # # #[list_begin definitions] # # # method test {arg1} { # # #*** !doctools # # #[call class::interface_sample1 [method test] [arg arg1]] # # #[para] test method # # puts "test: $arg1" # # } # # # #*** !doctools # # #[list_end] [comment {-- end definitions interface_sample1}] # # } # # #*** !doctools # #[list_end] [comment {--- end class enumeration ---}] # } #} # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # Base namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ tcl::namespace::eval punk::aliascore { tcl::namespace::export {[a-z]*} ;# Convention: export all lowercase variable aliases #use absolute ns ie must be prefixed with :: #single element commands are imported if source command already exists, otherwise aliased. multi element commands are aliased #functions must be in export list of their source namespace set aliases [tcl::dict::create\ val ::punk::pipe::val\ aliases ::punk::lib::aliases\ alias ::punk::lib::alias\ tstr ::punk::lib::tstr\ list_as_lines ::punk::lib::list_as_lines\ lines_as_list ::punk::lib::lines_as_list\ linelist ::punk::lib::linelist\ linesort ::punk::lib::linesort\ pdict ::punk::lib::pdict\ plist {::punk::lib::pdict -roottype list}\ showlist {::punk::lib::showdict -roottype list}\ rehash ::punk::rehash\ showdict ::punk::lib::showdict\ ansistrip ::punk::ansi::ansistrip\ stripansi ::punk::ansi::ansistrip\ ansiwrap ::punk::ansi::ansiwrap\ colour ::punk::console::colour\ ansi ::punk::console::ansi\ color ::punk::console::colour\ a? ::punk::console::code_a?\ A? {::punk::console::code_a? forcecolor}\ a+ ::punk::console::code_a+\ A+ {::punk::console::code_a+ forcecolour}\ a ::punk::console::code_a\ A {::punk::console::code_a forcecolour}\ smcup ::punk::console::enable_alt_screen\ rmcup ::punk::console::disable_alt_screen\ ] #*** !doctools #[subsection {Namespace punk::aliascore}] #[para] Core API functions for punk::aliascore #[list_begin definitions] #proc sample1 {p1 n args} { # #*** !doctools # #[call [fun sample1] [arg p1] [arg n] [opt {option value...}]] # #[para]Description of sample1 # #[para] Arguments: # # [list_begin arguments] # # [arg_def tring p1] A description of string argument p1. # # [arg_def integer n] A description of integer argument n. # # [list_end] # return "ok" #} #todo - options as to whether we should raise an error if collisions found, undo aliases etc? proc init {args} { set defaults {-force 0} set opts [dict merge $defaults $args] set opt_force [dict get $opts -force] #we never override existing aliases to ::repl::interp* even if -force = 1 #(these are our safebase aliases) set ignore_pattern "::repl::interp*" set ignore_aliases [list] variable aliases set existing [list] set conflicts [list] foreach {a cmd} $aliases { if {[tcl::info::commands ::$a] ne ""} { lappend existing $a set existing_alias [interp alias "" $a] if {$existing_alias ne ""} { set existing_target $existing_alias if {[string match $ignore_pattern $existing_target]} { #don't consider it a conflict - will use ignore_aliases to exclude it below lappend ignore_aliases $a continue } } else { if {[catch {tcl::namespace::origin $a} existing_command]} { set existing_command "" } set existing_target $existing_command } if {$existing_target ne $cmd} { #command exists in global ns but doesn't match our defined aliases/imports lappend conflicts $a } } } if {!$opt_force && [llength $conflicts]} { error "punk::aliascore::init declined to create any aliases or imports because -force == 0 and conflicts found:$conflicts" } set tempns ::temp_[info cmdcount] ;#temp ns for renames dict for {a cmd} $aliases { #puts "aliascore $a -> $cmd" if {$a in $ignore_aliases} { continue } if {[llength $cmd] > 1} { interp alias {} $a {} {*}$cmd } else { if {[tcl::info::commands $cmd] ne ""} { #todo - ensure exported? noclobber? if {[tcl::namespace::tail $a] eq [tcl::namespace::tail $cmd]} { #puts stderr "importing $cmd" tcl::namespace::eval :: [list namespace import $cmd] } else { #target command name differs from exported name #e.g stripansi -> punk::ansi::ansistrip #import and rename #puts stderr "importing $cmd (with rename to ::$a)" tcl::namespace::eval $tempns [list namespace import $cmd] catch {rename ${tempns}::[namespace tail $cmd] ::$a} } } else { interp alias {} $a {} {*}$cmd } } } #tcl::namespace::delete $tempns return [dict create aliases [dict keys $aliases] unchanged $ignore_aliases changed $conflicts] } #*** !doctools #[list_end] [comment {--- end definitions namespace punk::aliascore ---}] } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #interp alias {} list_as_lines {} punk::lib::list_as_lines #interp alias {} lines_as_list {} punk::lib::lines_as_list #interp alias {} ansistrip {} punk::ansi::ansistrip ;#review #interp alias {} linelist {} punk::lib::linelist ;#critical for = assignment features #interp alias {} linesort {} punk::lib::linesort # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # Secondary API namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ namespace eval punk::aliascore::lib { namespace export {[a-z]*} ;# Convention: export all lowercase namespace path [namespace parent] #*** !doctools #[subsection {Namespace punk::aliascore::lib}] #[para] Secondary functions that are part of the API #[list_begin definitions] #proc utility1 {p1 args} { # #*** !doctools # #[call lib::[fun utility1] [arg p1] [opt {?option value...?}]] # #[para]Description of utility1 # return 1 #} #*** !doctools #[list_end] [comment {--- end definitions namespace punk::aliascore::lib ---}] } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section Internal] namespace eval punk::aliascore::system { #*** !doctools #[subsection {Namespace punk::aliascore::system}] #[para] Internal functions that are not part of the API } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Ready package provide punk::aliascore [namespace eval punk::aliascore { variable pkg punk::aliascore variable version set version 999999.0a1.0 }] return #*** !doctools #[manpage_end]