From 9beb3927c5e025cccff2f6882fe9e69a822b2791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A8=D0=B8=D1=88?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Wed, 29 Apr 2026 16:54:16 +0000 Subject: [PATCH] Initial commit --- .gitignore | 93 +++++++++++++++++++++++++++++ .vscode/extensions.json | 5 ++ .vscode/launch.json | 33 ++++++++++ .vscode/settings.json | 26 ++++++++ .vscode/tasks.json | 38 ++++++++++++ README.md | 16 +++++ main.c | 129 ++++++++++++++++++++++++++++++++++++++++ main.h | 6 ++ makefile | 28 +++++++++ 9 files changed, 374 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 README.md create mode 100644 main.c create mode 100644 main.h create mode 100644 makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29456a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,93 @@ +# Exclude binaries from porject root +* +!/**/ +!*.* +![Mm]akefile + +# Temporary exclude test datasets +/test/ + +# ---> C +# Prerequisites +*.d +# Object files +*.o +*.ko +*.obj +*.elf +# Linker output +*.ilk +*.map +*.exp +# Precompiled Headers +*.gch +*.pch +# Libraries +*.lib +*.a +*.la +*.lo +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf +# ---> C++ +# Prerequisites +*.d +# Compiled Object files +*.slo +*.lo +*.o +*.obj +# Precompiled Headers +*.gch +*.pch +# Compiled Dynamic libraries +*.so +*.dylib +*.dll +# Fortran module files +*.mod +*.smod +# Compiled Static libraries +*.lai +*.la +*.a +*.lib +# Executables +*.exe +*.out +*.app +# ---> VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets +# Local History for Visual Studio Code +.history/ +# Built Visual Studio Code Extensions +*.vsix + diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..fd9b2c0 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ae3947c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/app", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7e5c2c8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "files.associations": { + "*.am": "makefile", + "*.ac": "makefile", + "*.c": "c", + "*.h": "c", + "*.cpp": "cpp", + "*.hpp": "cpp" + }, + "makefile.launchConfigurations": [ + { + "cwd": "${workspaceFolder}", + "binaryPath": "${workspaceFolder}/app", + "binaryArgs": [] + } + ], + "editor.rulers": [ + { + "column": 80 + }, + { + "column": 120, + "color": "#9f0af5" + } + ], +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..215b0f9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,38 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "detail": "Task generated by Debugger." + }, + { + "label": "make", + "type": "shell", + "command": "make", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b46dd51 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Header + +Description + +## Сборка проекта + +Для сборки программы достаточно вызвать команду `make`, находясь в каталоге проекта. + +```shell +$ cd $project_path +$ make +``` + +В Visual Studio Code команда сборки может быть вызвана комбинацией клавиш: `Ctrl + Shift + B`. + +Также, сборка автоматически выполняется при запуске отладки проекта, к примеру, при нажатии клавиши `F5` или выполнения команды запуска из интерфейса. diff --git a/main.c b/main.c new file mode 100644 index 0000000..9efb20d --- /dev/null +++ b/main.c @@ -0,0 +1,129 @@ +#include "main.h" + +#include +#include +#include +#include +#include // Получение опций командной строки +#include +#include +#include +#include +#include +#include + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +const char *program_name = NULL; +static int exit_status; +static int d_opt = 0; + +static int print(const void *buf, size_t count) +{ + int fd_std_out = fcntl(STDOUT_FILENO, F_DUPFD, 0); + write(fd_std_out, buf, count); + close(fd_std_out); +} + +static void test_sleep() +{ + int err = 0; + err = sleep(3); + printf("Err: %d\n", err); + assert(err == 0); +} + +static void set_program_name(const char *argv0) +{ + program_name = argv0; +} + +static void usage(int status) +{ + const char const msg_usage_fmt[] = "Usage: %s [OPTION]... [FILE]...\n"; + const char const msg_help[] = "\ +Program nothin to do while, this is just dirty example.\n\ +Arguments\n\ + --h display this help and exit\n"; + + char * restrict msg_buf; + size_t size; + + // Allocate enough memory on function stack for usage message + size = strlen(program_name) + sizeof(msg_usage_fmt) - 2; + msg_buf = alloca(size); + + size = snprintf(msg_buf, size, msg_usage_fmt, program_name); + write(STDOUT_FILENO, msg_buf, sizeof(msg_buf[0]) * size); + + // Print usage help message + write(STDOUT_FILENO, msg_help, sizeof(msg_help)); +} + +static int decode_switches(int argc, char **argv) +{ + int c; + + while (1) + { + c = getopt(argc, argv, "h"); + if (c == -1) + break; + + switch (c) + { + case 'h': + usage(EXIT_SUCCESS); + break; + + default: + break; + } + } + + return optind; +} + +static void close_stdout(void) +{ + close(STDOUT_FILENO); +} + +int main(int argc, char *argv[]) +{ + int fd_std_out; + int i; + + const size_t msg_maxlen = 255; + char msg[msg_maxlen + 1]; + + set_program_name(argv[0]); + setlocale(LC_ALL, ""); + atexit(close_stdout); + + exit_status = EXIT_SUCCESS; + + i = decode_switches (argc, argv); + printf("Обработано аргументов: %d\n", i); + + const char const msg_fmt_argv_handled[] = "Обработано аргументов: %d\n"; + size_t size; + size = snprintf(msg, msg_maxlen, msg_fmt_argv_handled, i); + write(STDOUT_FILENO, msg, sizeof(msg[0]) * size); + + // Duplicate descriptor + fd_std_out = fcntl(STDOUT_FILENO, F_DUPFD, 0); + assert(fd_std_out != -1); + + const char const msg_example[] = "Функциональность приложения не реализована\n"; + write(STDERR_FILENO, msg_example, sizeof(msg_example)-1); + + /*{ + const char const * err_str = "WARN\n"; + write(STDOUT_FILENO, err_str, sizeof(err_str)); + }*/ + + close(fd_std_out); + + return exit_status; +} diff --git a/main.h b/main.h new file mode 100644 index 0000000..167d622 --- /dev/null +++ b/main.h @@ -0,0 +1,6 @@ +#ifndef APP_MAIN_H +#define APP_MAIN_H + + + +#endif /* APP_MAIN_H */ \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..4cbcff8 --- /dev/null +++ b/makefile @@ -0,0 +1,28 @@ +TARGET = $(basename $(notdir $(PWD))) +TARGET = app +OBJECTS = main.o + +VPATH = src + +CFLAGS += -g +#CFLAGS += -fdiagnostics-color=always +#LDLIBS=-lstdc++ + +#OBJECTS := $(addprefix obj/, $(OBJECTS)) + +.SUFFIXES: +.SUFFIXES: .out .a .ln .o .c .cc .C .cpp .m .s .S .sym .def .h + +.PHONY: all clean test + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ + +clean: + $(RM) $(OBJECTS) $(TARGET) + +test: + @echo $(TARGET) + @echo $(OBJECTS)