summaryrefslogtreecommitdiffstats
path: root/src/about/about.c
blob: 60f5104e82ad716b5aae76643c2f40361a0681e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/******************************************************************************
 *	Copyright (C) 2018	Alejandro Colomar Andrés		      *
 *	SPDX-License-Identifier:	GPL-2.0-only			      *
 ******************************************************************************/


/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
#include "vision-artificial/about/about.h"

#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include "libalx/base/errno/errno_str.h"
#include "libalx/base/stdio/sprint_file.h"


/******************************************************************************
 ******* macros ***************************************************************
 ******************************************************************************/
#define BUFF_SIZE_TEXT	(0xFFFF)	/* 64 KiB */
#define BEGINNING	"\n┌──────────────────────────────────────────────────────────────────────────────┐\n"
#define ENDING		"└──────────────────────────────────────────────────────────────────────────────┘\n\n"


/******************************************************************************
 ******* enums ****************************************************************
 ******************************************************************************/


/******************************************************************************
 ******* structs / unions *****************************************************
 ******************************************************************************/


/******************************************************************************
 ******* variables ************************************************************
 ******************************************************************************/
char	share_path [FILENAME_MAX];


/******************************************************************************
 ******* static functions (prototypes) ****************************************
 ******************************************************************************/


/******************************************************************************
 ******* global functions *****************************************************
 ******************************************************************************/
void	about_init		(void)
{

	if (snprintf(share_path, FILENAME_MAX, "%s/estadistica/",
					INSTALL_SHARE_DIR)  >=  FILENAME_MAX) {
		goto err;
	}
	return;
err:
	printf("Path is too large and has been truncated\n");
	exit(EXIT_FAILURE);
}

void	snprint_share_file	(ptrdiff_t size, char buff[restrict size],
				int file)
{
	char	fname [FILENAME_MAX];

	switch (file) {
	case SHARE_COPYRIGHT:
		if (snprintf(fname, FILENAME_MAX, "%s/%s",
					share_path,
					"COPYRIGHT.txt")  >=  FILENAME_MAX) {
			goto err;
		}
		break;
	case SHARE_DISCLAIMER:
		if (snprintf(fname, FILENAME_MAX, "%s/%s",
					share_path,
					"DISCLAIMER.txt")  >=  FILENAME_MAX) {
			goto err;
		}
		break;
	case SHARE_HELP:
		if (snprintf(fname, FILENAME_MAX, "%s/%s",
					share_path,
					"HELP.txt")  >=  FILENAME_MAX) {
			goto err;
		}
		break;
	case SHARE_LICENSE:
		if (snprintf(fname, FILENAME_MAX, "%s/%s",
					share_path,
					"LICENSE.txt")  >=  FILENAME_MAX) {
			goto err;
		}
		break;
	case SHARE_USAGE:
		if (snprintf(fname, FILENAME_MAX, "%s/%s",
					share_path,
					"USAGE.txt")  >=  FILENAME_MAX) {
			goto err;
		}
		break;
	}

	if (alx_snprint_file(size, buff, fname) < 0)
		printf("%s: %s\n", errno_str[errno][0], errno_str[errno][1]);

	return;

err:
	printf("Path is too large and has been truncated\n");
	printf("File could not be shown!\n");
}

void	print_share_file	(int file)
{
	char	str [BUFF_SIZE_TEXT];

	snprint_share_file(BUFF_SIZE_TEXT, str, file);

	printf(BEGINNING);
	printf("%s", str);
	printf(ENDING);
}

void	print_version		(void)
{

	printf(""PROG_NAME" "PROG_VERSION"\n\n");
}


/******************************************************************************
 ******* static functions (definitions) ***************************************
 ******************************************************************************/


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/