Skip to content

Commit

Permalink
Merge branch 'master' into script_workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Panquesito7 authored Aug 4, 2023
2 parents 9eda3e6 + 1302bf4 commit cc33f88
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Panquesito7 @tjgurwara99 @alexpantyukhin
44 changes: 2 additions & 42 deletions .github/workflows/awesome_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,8 @@ jobs:
# be able to catch any errors for other platforms.
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Lint modified files
shell: python
run: |
import os
import subprocess
import sys
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
with open("git_diff.txt") as in_file:
modified_files = sorted(in_file.read().splitlines())
print("{} files were modified.".format(len(modified_files)))
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
print(f"{len(cpp_files)} C++ files were modified.")
if not cpp_files:
sys.exit(0)
subprocess.run(["clang-tidy", "-p=build", "--fix", *cpp_files, "--"],
check=True, text=True, stderr=subprocess.STDOUT)
subprocess.run(["clang-format", "-i", *cpp_files],
check=True, text=True, stderr=subprocess.STDOUT)
upper_files = [file for file in cpp_files if file != file.lower()]
if upper_files:
print(f"{len(upper_files)} files contain uppercase characters:")
print("\n".join(upper_files) + "\n")
space_files = [file for file in cpp_files if " " in file or "-" in file]
if space_files:
print(f"{len(space_files)} files contain space or dash characters:")
print("\n".join(space_files) + "\n")
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1 and "project_euler" not in file and "data_structure" not in file]
if len(nodir_files) > 1:
nodir_file_bad_files = len(nodir_files) - 1
print(f"{len(nodir_files)} files are not in one and only one directory:")
print("\n".join(nodir_files) + "\n")
else:
nodir_file_bad_files = 0
bad_files = nodir_file_bad_files + len(upper_files + space_files)
if bad_files:
sys.exit(bad_files)
shell: bash
run: python3 scripts/file_linter.py
- name: Commit and push changes
run: |
git diff DIRECTORY.md
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/leetcode_directory_writer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
paths:
- "leetcode/src/**.c"
branches:
- master
jobs:
build:
if: github.repository == 'TheAlgorithms/C' # We only need this to run in our repository.
Expand All @@ -31,12 +33,13 @@ jobs:
shell: bash
run: |
git checkout -b leetcode-directory-${{ github.sha }}
git commit -m "docs: updating `leetcode/DIRECTORY.md`
git commit -m "docs: updating `leetcode/DIRECTORY.md`"
git push origin leetcode-directory-${{ github.sha }}:leetcode-directory-${{ github.sha }}
- name: Creating the pull request
shell: bash
run: |
if [[ `git status --porcelain` ]]; then
gh pr create --base ${GITHUB_REF##*/} --head leetcode-directory-${{ github.sha }} --title 'docs: updating `leetcode/DIRECTORY.md`' --body 'Updated LeetCode directory (see the diff. for changes).'
if [[ $(git log --branches --not --remotes) ]]; then
gh pr create --base ${GITHUB_REF##*/} --head leetcode-directory-${{ github.sha }} --title 'docs: updating `leetcode/DIRECTORY.md`' --body 'Updated LeetCode directory (see the diff. for changes).' || true
fi
env:
GH_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.out
.vscode/
build/
git_diff.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.22)
project(Algorithms_in_C
LANGUAGES C
VERSION 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The repository is a collection of open-source implementations of a variety of al
* The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - [C](https://en.wikipedia.org/wiki/C_(programming_language)).
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
* Each source code is atomic using standard C library [`libc`](https://en.wikipedia.org/wiki/C_standard_library) and _no external libraries_ are required for their compilation and execution. Thus the fundamentals of the algorithms can be studied in much depth.
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of two major operating systems viz., MacOS and Ubuntu (Linux) using AppleClang 14.0.0 and GNU 11.3.0 respectively.
* Strict adherence to [C11](https://en.wikipedia.org/wiki/C11_(C_standard_revision)) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
* Self-checks within programs ensure correct implementations with confidence.
* Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.
Expand Down
6 changes: 4 additions & 2 deletions client_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include(CheckIncludeFile)

if(WIN32)
check_include_file(winsock2.h WINSOCK_HEADER)
CHECK_INCLUDE_FILE(winsock2.h WINSOCK_HEADER)
else()
check_include_file(arpa/inet.h ARPA_HEADERS)
CHECK_INCLUDE_FILE(arpa/inet.h ARPA_HEADERS)
endif()

if(ARPA_HEADERS OR WINSOCK_HEADER)
Expand Down
4 changes: 2 additions & 2 deletions data_structures/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ int List_length(L list)
{
int n;
for (n = 0; list; list = list->next) n++;
return n;
return n - 1;
}

/* Convert list to array */
void **List_toArray(L list)
{
int i, n = List_length(list);
int i, n = List_length(list) + 1;
void **array = (void **)malloc((n + 1) * sizeof(*array));

for (i = 0; i < n; i++)
Expand Down
23 changes: 23 additions & 0 deletions leetcode/src/69.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//using the binary search method is one of the efficient ones for this problem statement.
int mySqrt(int x){
int start=0;
int end=x;
long long int ans=0;
while(start <= end){
long long int mid=(start+end)/2;
long long int val=mid*mid;
if( val == x){
return mid;
}
//if mid is less than the square root of the number(x) store the value of mid in ans.
if( val < x){
ans = mid;
start = mid+1;
}
//if mid is greater than the square root of the number(x) then ssign the value mid-1 to end.
if( val > x){
end = mid-1;
}
}
return ans;
}
40 changes: 40 additions & 0 deletions scripts/file_linter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import subprocess
import sys

print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
with open("git_diff.txt") as in_file:
modified_files = sorted(in_file.read().splitlines())
print("{} files were modified.".format(len(modified_files)))

cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
print(f"{len(cpp_files)} C++ files were modified.")
if not cpp_files:
sys.exit(0)
subprocess.run(["clang-tidy", "-p=build", "--fix", *cpp_files, "--"],
check=True, text=True, stderr=subprocess.STDOUT)
subprocess.run(["clang-format", "-i", *cpp_files],
check=True, text=True, stderr=subprocess.STDOUT)

upper_files = [file for file in cpp_files if file != file.lower()]
if upper_files:
print(f"{len(upper_files)} files contain uppercase characters:")
print("\n".join(upper_files) + "\n")

space_files = [file for file in cpp_files if " " in file or "-" in file]
if space_files:
print(f"{len(space_files)} files contain space or dash characters:")
print("\n".join(space_files) + "\n")

nodir_files = [file for file in cpp_files if file.count(os.sep) != 1 and "project_euler" not in file and "data_structure" not in file]
if len(nodir_files) > 1:
nodir_file_bad_files = len(nodir_files) - 1
print(f"{len(nodir_files)} files are not in one and only one directory:")
print("\n".join(nodir_files) + "\n")
else:
nodir_file_bad_files = 0
bad_files = nodir_file_bad_files + len(upper_files + space_files)

if bad_files:
sys.exit(bad_files)

0 comments on commit cc33f88

Please sign in to comment.