-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetPrototypes.py
executable file
·73 lines (66 loc) · 2.93 KB
/
getPrototypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
import os
import subprocess
import shutil
def is_git_repo(path):
try:
subprocess.check_output(["git", "rev-parse", "--is-inside-work-tree"], cwd=path)
repo_root = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=path)
repo_root = os.path.normpath(repo_root.decode('utf-8').strip())
return 'alx-low_level_programming'in repo_root
except subprocess.CalledProcessError:
return False
# List of functions to search for
functions = [
"int _putchar(char c);",
"int _islower(int c);",
"int _isalpha(int c);",
"int _abs(int n);",
"int _isupper(int c);",
"int _isdigit(int c);",
"int _strlen(char *s);",
"void _puts(char *s);",
"char *_strcpy(char *dest, char *src);",
"int _atoi(char *s);",
"char *_strcat(char *dest, char *src);",
"char *_strncat(char *dest, char *src, int n);",
"char *_strncpy(char *dest, char *src, int n);",
"int _strcmp(char *s1, char *s2);",
"char *_memset(char *s, char b, unsigned int n);",
"char *_memcpy(char *dest, char *src, unsigned int n);",
"char *_strchr(char *s, char c);",
"unsigned int _strspn(char *s, char *accept);",
"char *_strpbrk(char *s, char *accept);",
"char *_strstr(char *haystack, char *needle);"
]
while True:
directory = os.getcwd()
if is_git_repo(directory):
print("You are in alx-low_level_programming repo\n{}".format(directory))
# Directory to copy the files to
dest_directory = os.path.join(directory, "0x18-dynamic_libraries")
# Create the destination directory if it doesn't exist
if not os.path.exists(dest_directory):
print("Directory: 0x18-dynamic_libraries not found!")
os.makedirs(dest_directory)
print("Directory: 0x18-dynamic_libraries created.")
parrent_dir = os.path.abspath('..')
for folder, subfolders, files in os.walk(parrent_dir):
if folder != parrent_dir:
for filename in files:
if filename.endswith(".c") != filename.endswith("main.c") :
print("File Name: ", filename)
print(f"Path: ", os.path.join(folder, filename))
with open(os.path.join(folder, filename)) as file:
content = file.read()
# Check if the file contains any of the functions
for function in functions:
if function in content:
print(f"{filename} contains {function}")
# Copy the file to the destination directory
# shutil.copy(os.path.join(directory, filename), dest_directory)
# print("No prototype files found!")
break
else:
print("You are not in alx-low_level_programming repo\n{}".format(directory))
exit()