Monday, February 09, 2026

Search Source Files for Matching Key Phrases

 
##
# search all sources for pattern string
# returns a tagged list, those matching, and those not-matching
##
proc checkAllSources { {pattern USE_DOC_VAR} } {

    package require fileutil
    
    set FILES [fileutil::findByPattern ../src *.c] 
    
    foreach w [gnocl::widgets] {
        foreach f $FILES { 
            if { [string first /$w.c $f] != -1 } { 
                set fp [open $f r]
                set DATA [read $fp]
                close $fp

                if { [string first $pattern $DATA] != -1 } { 
                    lappend yes $f 
                } else {
                    lappend no $f
                    
                }
            }     
        }
    }
    return "yes {$yes} no {$no}"
}

puts [join [dict get [checkAllSources gnoclGetDocumentationVarArgs] yes] \n]

Sunday, January 25, 2026

Using a Simple C While-Loop to Step Throught Option Arrays

Sometimes its necessary to run through a GnoclOption array. As such arrays are always NULL terminated, a simple while loop solves the problem.


gint idx = 0; 

while ( tagOptions[idx++].optName != NULL )  {

g_print ( "*%d %s\n", idx, tagOptions[idx].optName );

if ( strcmp ( tagOptions[idx].optName, "-myOption" ) ) == 0 ) {

GNOCL_DEBUG_MSG ( "got it!" )

break;

 }

 

As can be seem in the above example, a GnoclOption array is an array of structures. 

 

If just the array size is needed, then simply use the macro GNOCL_TOTAL_OPTIONS(option) to return the length, less the NULL, of course.

The macro ARRAY_SIZE(x) will provide the overall size of an array, including any NULL termination.