opt_find 871 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. #
  3. # opt_find
  4. # Find one or more Marlin options - Configuration lines starting with #define
  5. #
  6. MYNAME=$(basename $0)
  7. [[ $# == 0 ]] && ONE="-h" || ONE=$1
  8. COMM="(//\\s*)?" ; TYPE=""
  9. case "$ONE" in
  10. -d|--disabled )
  11. shift ; COMM="(//\\s*)" ; TYPE="disabled " ;;
  12. -e|--enabled )
  13. shift ; COMM="" ; TYPE="enabled " ;;
  14. -h|--help )
  15. echo "$MYNAME [-d|--disabled|-e|--enabled] STRING ... Find matching Marlin configuration options."
  16. echo ; shift ;;
  17. -* )
  18. echo "Unknown option $ONE" ; shift ;;
  19. esac
  20. while [[ $# > 0 ]]; do
  21. DID=0
  22. for FN in Configuration Configuration_adv; do
  23. FOUND=$( grep -HEn "^\s*${COMM}#define\s+[A-Z0-9_]*${1}" "Marlin/$FN.h" 2>/dev/null )
  24. [[ -n "$FOUND" ]] && { echo "$FOUND" ; DID=1 ; }
  25. done
  26. ((DID)) || { echo "ERROR: ${MYNAME} - No ${TYPE}match for ${1}" ; exit 9; }
  27. shift
  28. echo
  29. done