diff --git a/examples/cmap-example/cmap-example.cpp b/examples/cmap-example/cmap-example.cpp index bc4e5ce7c..b2a7b2735 100644 --- a/examples/cmap-example/cmap-example.cpp +++ b/examples/cmap-example/cmap-example.cpp @@ -5,6 +5,7 @@ #include #include #include +#include int main() { std::map dict; @@ -91,10 +92,10 @@ int main() { // Now we try to use the appcode to select from the help available // app1 has only -h and -f so 0b00011; app2 has only -h and -n so 0b00101 - int app1code = 0b01011; - int app2code = 0b10101; + int app1code = 0b0001011; + int app2code = 0b0010111; - printf("\nNow processing app with only -h, -t and -f and appcode %3d\n", app1code); + printf("\nNow processing app with only -h, -t and -f implemented and appcode %3d\n", app1code); if (app1code != 0) { for (const auto& kvp : bitdict) { if ((app1code & std::stoi(kvp.first)) != 0) { @@ -108,7 +109,7 @@ int main() { printf("\n"); } - printf("\nNow processing app with only -h, -m, -n and appcode %3d\n", app2code); + printf("\nNow processing app with only -h, -f, -m and -n implemented and appcode %3d\n", app2code); if (app2code != 0) { for (const auto& kvp : bitdict) { if ((app2code & std::stoi(kvp.first)) != 0) { @@ -122,5 +123,22 @@ int main() { printf("\n"); } + // This is more like the general way to do it + std::vector appcodes = {2, 5, 11, 17, 23, 31}; + for (size_t i = 0; i < appcodes.size(); ++i) { + int x = appcodes[i]; + if (x != 0) { + for (const auto& kvp : bitdict) { + if ((x & std::stoi(kvp.first)) != 0) { + printf("Appcode %3d %s ", x, kvp.first.c_str()); + for (const auto& element : kvp.second) { + printf(" %5s", element.c_str()); + } + printf("\n"); + } + } + printf("\n"); + } + } return 0; } \ No newline at end of file diff --git a/examples/cmap-example/find_implemented_args.py b/examples/cmap-example/find_implemented_args.py new file mode 100644 index 000000000..8d745c822 --- /dev/null +++ b/examples/cmap-example/find_implemented_args.py @@ -0,0 +1,30 @@ +import os +import re + +def find_arguments(directory): + arguments = {} + + # Get a list of all .cpp files in the specified directory + cpp_files = [filename for filename in os.listdir(directory) if filename.endswith('.cpp')] + + # Read each .cpp file and search for the specified expressions + for filename in cpp_files: + with open(os.path.join(directory, filename), 'r') as file: + content = file.read() + + # Search for the expressions using regular expressions + matches = re.findall(r'argv\s*\[\s*i\s*\]\s*==\s*([\'"])(?P-[a-zA-Z]+|\-\-[a-zA-Z]+[a-zA-Z0-9-]*)\1', content) + + # Add the found arguments to the dictionary + arguments[filename] = [match[1] for match in matches] + + return arguments + + +# Specify the directory you want to search for cpp files +directory = '/Users/edsilm2/llama.cpp/examples' + +# Call the function and print the result +result = find_arguments(directory) +for filename, arguments in result.items(): + print(filename, arguments) \ No newline at end of file