Automation

This commit is contained in:
pudepiedj 2023-10-05 17:30:48 +01:00
parent 275d56e99e
commit 297b7b6301
2 changed files with 52 additions and 4 deletions

View file

@ -5,6 +5,7 @@
#include <list> #include <list>
#include <string> #include <string>
#include <bitset> #include <bitset>
#include <vector>
int main() { int main() {
std::map<std::string, int> dict; std::map<std::string, int> dict;
@ -91,10 +92,10 @@ int main() {
// Now we try to use the appcode to select from the help available // 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 // app1 has only -h and -f so 0b00011; app2 has only -h and -n so 0b00101
int app1code = 0b01011; int app1code = 0b0001011;
int app2code = 0b10101; 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) { if (app1code != 0) {
for (const auto& kvp : bitdict) { for (const auto& kvp : bitdict) {
if ((app1code & std::stoi(kvp.first)) != 0) { if ((app1code & std::stoi(kvp.first)) != 0) {
@ -108,7 +109,7 @@ int main() {
printf("\n"); 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) { if (app2code != 0) {
for (const auto& kvp : bitdict) { for (const auto& kvp : bitdict) {
if ((app2code & std::stoi(kvp.first)) != 0) { if ((app2code & std::stoi(kvp.first)) != 0) {
@ -122,5 +123,22 @@ int main() {
printf("\n"); printf("\n");
} }
// This is more like the general way to do it
std::vector<int> 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; return 0;
} }

View file

@ -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<arg>-[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)