format
This commit is contained in:
parent
c47a574a10
commit
85bc36e5b1
8 changed files with 42 additions and 18 deletions
21
.clang-format
Normal file
21
.clang-format
Normal 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
3
format.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
DIRS="include src"
|
||||
clang-format --verbose -i `find $DIRS -name "*.c" -or -name "*.h"`
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
12
src/file.c
12
src/file.c
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue