Created
July 26, 2026 07:03
-
-
Save clort81/0527ead78967a5db728ddbc6c3b010bf to your computer and use it in GitHub Desktop.
Return the full C function matching a searchkeyword.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Show the full c-fuction matching a keyword name | |
| # | |
| # Usage check | |
| if [[ -z "$1" || -z "$2" ]]; then | |
| echo "Usage: $0 <function_name> <file.c>" | |
| exit 1 | |
| fi | |
| func_name="$1" | |
| file="$2" | |
| # Use awk to find the function and print until braces balance | |
| awk -v fn="$func_name" ' | |
| $0 ~ ("\\<" fn "\\>[[:space:]]*\\(") { | |
| in_func = 1 | |
| brace_count = 0 | |
| } | |
| in_func { | |
| for (i = 1; i <= length($0); i++) { | |
| c = substr($0, i, 1) | |
| if (c == "{") brace_count++ | |
| if (c == "}") brace_count-- | |
| } | |
| if (brace_count == 0 && found_open) { | |
| exit | |
| } | |
| if (brace_count > 0) found_open = 1 | |
| } | |
| ' "$file" | |
| alias ps='ps axwwu' | |
| alias apt='apt --no-install-recommends' | |
| alias youbest="yt-dlp -f bestvideo+bestaudio --remux-video mkv" | |
| alias randpass="openssl rand -base64 24" | |
| # This might be needed for firefox wayland | |
| export MOZ_ENABLE_WAYLAND=1 | |
| #alias yousub="yt-dlp -f bestvideo+bestaudio --write-subs --sub-lang en --convert-subs=srt --remux-video mkv" | |
| alias yousub="yt-dlp -c -f bestvideo+bestaudio --write-subs --sub-lang en --convert-subs=srt" | |
| alias grimit='grim -g "$(slurp)" grim-$(date +%Y-%m-%d_%H-%m-%s).png' | |
| alias antlr4="java -jar ~/Projects/PyBDFValidate/antlr4.jar" | |
| alias df="df -h -T -x tmpfs -x squashfs" | |
| export COLORTERM=24bit | |
| export TERM=xterm-256color | |
| ##echo "]0;$$" | |
| printf '\e]0;%s\x07' "${TTY:=$(tty)} : $$" | |
| function sine_wave() { | |
| i=0 | |
| while true | |
| do | |
| SIN=$(python3 -c "from math import *;print map( lambda x: ceil(6*sin((x+$i)*pi/5)), range($(tput cols)) )" | tr -d '[]' | spark) | |
| echo -ne $SIN\\r | |
| let i=i+1 | |
| sleep 0.05 | |
| done | |
| echo | |
| } | |
| function dusize() { | |
| find . -type f -name "${1}" -exec du -ch "{}" + | |
| } | |
| function ix() { curl -n -F 'f:1=<-' http://ix.io; } | |
| #transset -i ${WINDOWID} 0.98 | |
| # ladspa forgets to set the path on install | |
| export LADSPA_PATH=/usr/lib/ladspa | |
| export XDG_RUNTIME_DIR="/run/user/1000" | |
| export LANG="en_US.UTF-8" | |
| export LC_ALL="en_US.UTF-8" | |
| export LC_CTYPE="en_US.UTF-8" | |
| export LC_TIME="en_GB.UTF-8" | |
| export LC_MEASUREMENT=metric | |
| export LLAMACPP_API_KEY=noop | |
| export OLLAMA_API_KEY=noop | |
| export LMSTUDIO_API_KEY=noop | |
| #alwaysmodmap.sh& # repeatedly xmodmap | |
| PATH="/home/plab/perl5/bin${PATH:+:${PATH}}"; export PATH; | |
| PERL5LIB="/home/plab/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB; | |
| PERL_LOCAL_LIB_ROOT="/home/plab/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; | |
| PERL_MB_OPT="--install_base \"/home/plab/perl5\""; export PERL_MB_OPT; | |
| PERL_MM_OPT="INSTALL_BASE=/home/plab/perl5"; export PERL_MM_OPT; | |
| #fuck screenblanking | |
| xset s off | |
| xset s noblank | |
| xset dpms 0 | |
| #cat ~/.fwiffo.ans | |
| #cat ~/.us.txt | |
| #cat ~/.braille.ans | |
| #cat ~/.atglb | |
| # export XDG_CONFIG_HOME="/home/plab/.config" | |
| # test override local llama build export LD_LIBRARY_PATH=/pr/Neural/LLM/llama.cpp/build/bin:$LD_LIBRARY_PATH | |
| xmodmap ~/.Xmodmap& | |
| brightnessctl s 40 | |
| cfunc() { | |
| local func_name="$1" | |
| local file="$2" | |
| if [[ -z "$func_name" || -z "$file" ]]; then | |
| echo "Usage: cfunc <function_name> <file.c>" | |
| return 1 | |
| fi | |
| # Use awk to find the function and print until braces balance | |
| awk -v fn="$func_name" ' | |
| # Match function header: handles "type name(", "type *name(", etc. | |
| # It looks for the function name followed by an opening parenthesis | |
| $0 ~ ("\\<" fn "\\>[[:space:]]*\\(") { | |
| in_func = 1 | |
| brace_count = 0 | |
| } | |
| in_func { | |
| # Count opening and closing braces in the line | |
| for (i = 1; i <= length($0); i++) { | |
| c = substr($0, i, 1) | |
| if (c == "{") brace_count++ | |
| if (c == "}") brace_count-- | |
| } | |
| # If we opened at least one brace and count returns to 0, we are done | |
| if (brace_count == 0 && found_open) { | |
| exit | |
| } | |
| if (brace_count > 0) found_open = 1 | |
| } | |
| ' "$file" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment