This commit is contained in:
Nishi 2025-11-17 18:20:56 +09:00
commit 85bc36e5b1
Signed by: nishi
GPG key ID: 27EF69B208EB9343
8 changed files with 42 additions and 18 deletions

21
.clang-format Normal file
View file

@ -0,0 +1,21 @@
---
# $Id: .clang-format 567 2025-11-02 00:00:24Z nishi $
Language: Cpp
UseTab: Always
TabWidth: 8
AlignConsecutiveAssignments:
Enabled: true
AlignConsecutiveDeclarations:
Enabled: true
IndentWidth: 8
PointerAlignment: Left
ColumnLimit: 0
AllowShortIfStatementsOnASingleLine: Always
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
AllowShortLoopsOnASingleLine: true
SpaceBeforeParens: Never
AlignEscapedNewlines: DontAlign
SortIncludes: false
AllowShortEnumsOnASingleLine: false
#IndentPPDirectives: AfterHash

3
format.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
DIRS="include src"
clang-format --verbose -i `find $DIRS -name "*.c" -or -name "*.h"`

View file

@ -7,7 +7,7 @@
extern "C" {
#endif
void MDEDirectoryScan(const char* path, void(*call)(const char* name, int dir, void* user), void* user);
void MDEDirectoryScan(const char* path, void (*call)(const char* name, int dir, void* user), void* user);
#ifdef __cplusplus
}

View file

@ -7,7 +7,7 @@
extern "C" {
#endif
void MDEUsersList(void(*call)(const char* name, void* user), void* user);
void MDEUsersList(void (*call)(const char* name, void* user), void* user);
#ifdef __cplusplus
}

View file

@ -5,12 +5,12 @@
#include <dirent.h>
#include <sys/stat.h>
void MDEDirectoryScan(const char* path, void(*call)(const char* name, int dir, void* user), void* user){
void MDEDirectoryScan(const char* path, void (*call)(const char* name, int dir, void* user), void* user) {
DIR* dir = opendir(path);
if(dir != NULL){
if(dir != NULL) {
struct dirent* d;
while((d = readdir(dir)) != NULL){
char* p;
while((d = readdir(dir)) != NULL) {
char* p;
struct stat s;
if(strcmp(d->d_name, "..") == 0 || strcmp(d->d_name, ".") == 0) continue;
@ -19,10 +19,10 @@ void MDEDirectoryScan(const char* path, void(*call)(const char* name, int dir, v
if(path[strlen(path) - 1] != '/') strcat(p, "/");
strcat(p, d->d_name);
if(stat(p, &s) == 0){
if(stat(p, &s) == 0) {
call(p, S_ISDIR(s.st_mode) ? 1 : 0, user);
}
free(p);
}
closedir(dir);

View file

@ -2,21 +2,21 @@
#include <stdio.h>
void MDEFileCopy(const char* src, const char* dst){
char buffer[4096];
void MDEFileCopy(const char* src, const char* dst) {
char buffer[4096];
FILE* in;
FILE* out;
int r;
int r;
if((in = fopen(src, "rb")) == NULL) return;
if((out = fopen(dst, "wb")) == NULL){
if((out = fopen(dst, "wb")) == NULL) {
fclose(in);
return;
}
do{
do {
r = fread(buffer, 1, sizeof(buffer), in);
fwrite(buffer, 1, r, out);
}while(r == sizeof(buffer));
} while(r == sizeof(buffer));
fclose(in);
fclose(out);

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
char* MDEStringDuplicate(const char* src){
char* MDEStringDuplicate(const char* src) {
char* s = malloc(strlen(src) + 1);
strcpy(s, src);

View file

@ -3,11 +3,11 @@
#include <pwd.h>
void MDEUsersList(void(*call)(const char* name, void* user), void* user){
void MDEUsersList(void (*call)(const char* name, void* user), void* user) {
struct passwd* pwd;
setpwent();
while((pwd = getpwent()) != NULL){
while((pwd = getpwent()) != NULL) {
char* dir;
char* shell;
@ -26,7 +26,7 @@ void MDEUsersList(void(*call)(const char* name, void* user), void* user){
shell++;
if(strcmp(shell, "nologin") == 0) continue;
dir = strrchr(pwd->pw_dir, '/');
if(dir == NULL) break;
dir++;