Initial commit
This commit is contained in:
commit
9beb3927c5
93
.gitignore
vendored
Normal file
93
.gitignore
vendored
Normal file
@ -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
|
||||||
|
|
||||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
33
.vscode/launch.json
vendored
Normal file
33
.vscode/launch.json
vendored
Normal file
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
38
.vscode/tasks.json
vendored
Normal file
38
.vscode/tasks.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
16
README.md
Normal file
16
README.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Header
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
## Сборка проекта
|
||||||
|
|
||||||
|
Для сборки программы достаточно вызвать команду `make`, находясь в каталоге проекта.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ cd $project_path
|
||||||
|
$ make
|
||||||
|
```
|
||||||
|
|
||||||
|
В Visual Studio Code команда сборки может быть вызвана комбинацией клавиш: `Ctrl + Shift + B`.
|
||||||
|
|
||||||
|
Также, сборка автоматически выполняется при запуске отладки проекта, к примеру, при нажатии клавиши `F5` или выполнения команды запуска из интерфейса.
|
||||||
129
main.c
Normal file
129
main.c
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <getopt.h> // Получение опций командной строки
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
6
main.h
Normal file
6
main.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef APP_MAIN_H
|
||||||
|
#define APP_MAIN_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* APP_MAIN_H */
|
||||||
28
makefile
Normal file
28
makefile
Normal file
@ -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)
|
||||||
Loading…
Reference in New Issue
Block a user