Ready for Gera
parent
7ab6cbb099
commit
c604be20f1
|
@ -1,3 +1,6 @@
|
|||
{
|
||||
"makefile.extensionOutputFolder": "./.vscode"
|
||||
"makefile.extensionOutputFolder": "./.vscode",
|
||||
"files.associations": {
|
||||
"config.h": "c"
|
||||
}
|
||||
}
|
19
config.h
19
config.h
|
@ -15,13 +15,6 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
// input console checking
|
||||
#define HELP_CONSOLE_OPTION_1 "-h"
|
||||
#define HELP_CONSOLE_OPTION_2 "--help"
|
||||
#define GENKEY_CONSOLE_OPTION "genkey"
|
||||
#define SIGNATURE_CONSOLE_OPTION "sign"
|
||||
#define CHECK_CONSOLE_OPTION "check"
|
||||
#define ENCRYPT_CONSOLE_OPTION "encrypt"
|
||||
#define DECRYPT_CONSOLE_OPTION "decrypt"
|
||||
|
||||
// boolean
|
||||
#define BOOL int
|
||||
|
@ -34,7 +27,8 @@
|
|||
/// <summary>
|
||||
/// Error codes
|
||||
/// </summary>
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
NO_ARGUMENTS_FAILURE,
|
||||
|
@ -45,14 +39,19 @@ typedef enum {
|
|||
FILENAME_SYMBOL_FAILURE,
|
||||
FILENAME_ENDING_FAILURE,
|
||||
FORMAT_FAILURE,
|
||||
EXISTING_NAME_FAILURE,
|
||||
DEBUG_EXIT_CODE = 100
|
||||
} ERROR_CODE;
|
||||
|
||||
// fast funcs
|
||||
#define swap(a,b); b = a+b; a = b-a; b = b-a;
|
||||
#define swap(a, b) \
|
||||
; \
|
||||
b = a + b; \
|
||||
a = b - a; \
|
||||
b = b - a;
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
#define max(a,b) (a>b)? a : b
|
||||
#define max(a, b) (a > b) ? a : b
|
||||
#endif
|
||||
|
||||
#endif // !CONFIG_H
|
76
main.c
76
main.c
|
@ -1,48 +1,62 @@
|
|||
#include "structs.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
File new_file;
|
||||
Folder new_folder;
|
||||
createFile("file1", "hehe", &new_file);
|
||||
createFolder("root", &new_folder);
|
||||
printf("%s\n", new_file.creation_time);
|
||||
printf("%s\n", new_file.filename);
|
||||
printf("%s\n", new_file.extension);
|
||||
|
||||
|
||||
|
||||
printf("\n%s\n", new_folder.creation_time);
|
||||
printf("%s\n", new_folder.filename);
|
||||
printf("%d\n", new_folder.folders_count_cur);
|
||||
printf("%d\n", new_folder.files_count_cur);
|
||||
printf("%d\n", new_folder.files_count_max);
|
||||
printf("%d\n", new_folder.folders_count_max);
|
||||
|
||||
printf("%d\n", new_folder.exists_into);
|
||||
|
||||
|
||||
|
||||
printf("\n%d\n", addFolder("sos", &new_folder));
|
||||
printf("%d\n", new_folder.exists_into);
|
||||
/*printf("%d\n", new_folder.exists_into);
|
||||
printf("%d\n", new_folder.folders_count_cur);
|
||||
printf("%d\n", new_folder.files_count_cur);
|
||||
printf("%d\n", new_folder.files_count_max);
|
||||
printf("%d\n", new_folder.folders_count_max);
|
||||
printf("%s\n", new_folder.folders[0].creation_time);
|
||||
printf("%s\n", new_folder.folders[0].filename);
|
||||
|
||||
|
||||
printf("\n%d\n", addFolder("sos2", &new_folder));
|
||||
printf("%d\n", new_folder.exists_into);
|
||||
printf("%d\n", new_folder.folders_count_cur);
|
||||
printf("%d\n", new_folder.files_count_cur);
|
||||
printf("%d\n", new_folder.files_count_max);
|
||||
printf("%d\n", new_folder.folders_count_max);
|
||||
printf("%s\n", new_folder.folders[1].creation_time);
|
||||
printf("%s\n", new_folder.folders[1].filename);
|
||||
*/
|
||||
|
||||
printf("%-*d%-*d%-*d\n", 10, 1376513765, 10, 123, 10, 1874);
|
||||
printf("\n%d\n", addFolder("sos2", &new_folder));
|
||||
// printf("%d\n", new_folder.exists_into);
|
||||
// printf("%d\n", new_folder.folders_count_cur);
|
||||
// printf("%d\n", new_folder.files_count_cur);
|
||||
// printf("%d\n", new_folder.files_count_max);
|
||||
// printf("%d\n", new_folder.folders_count_max);
|
||||
printf("%s\n", new_folder.folders[1].creation_time);
|
||||
// printf("%s\n", new_folder.folders[1].filename);
|
||||
|
||||
// char name[10];
|
||||
// for (i = 0; i < 400; i++)
|
||||
// {
|
||||
// sprintf(name, "%d", i);
|
||||
// if (i % 2)
|
||||
// {
|
||||
// printf("\ni = %d : %d\n", i, addFile(name, "test", &new_folder));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// printf("\ni = %d : %d\n", i, addFolder(name, &new_folder));
|
||||
// }
|
||||
// printf("%d\n", new_folder.exists_into);
|
||||
// printf("%d\n", new_folder.folders_count_cur);
|
||||
// printf("%d\n", new_folder.folders_count_max);
|
||||
// printf("%d\n", new_folder.files_count_cur);
|
||||
// printf("%d\n", new_folder.files_count_max);
|
||||
// }
|
||||
|
||||
addFile("file1", "hehe", &new_folder);
|
||||
addFile("file1", "hehe", &new_folder);
|
||||
addFile("file1", "huh", &new_folder);
|
||||
addFile("trash", "hehe", &new_folder);
|
||||
addFile("AvadaBlyad Kedavra", "huy", &new_folder);
|
||||
addFile("Ya v svoyom poznanii nastolko preispolnilsya", "budtobi3", &new_folder);
|
||||
addFolder("Uh suka so smislam", &new_folder);
|
||||
addFolder("Ya v svoyom poznanii nastolko preispolnilsya", &new_folder);
|
||||
addFolder("Ya v svoyom poznanii nastolko preispolnilsya", &new_folder);
|
||||
|
||||
// printf("%-*d%-*d%-*d\n", 10, 1376513765, 10, 123, 10, 1874);
|
||||
|
||||
print_list(&new_folder, 1);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
264
structs.c
264
structs.c
|
@ -1,70 +1,99 @@
|
|||
#include "structs.h"
|
||||
|
||||
int check_name(char* name)
|
||||
int check_name(char *name)
|
||||
{
|
||||
int strln = strlen(name);
|
||||
int i;
|
||||
char* symb;
|
||||
char *symb;
|
||||
|
||||
if(strln > filename_lenth)
|
||||
if (strln > filename_lenth)
|
||||
return FILENAME_LENGTH_FAILURE;
|
||||
|
||||
for(i = 0; i < strln; i ++)
|
||||
|
||||
for (i = 0; i < strln; i++)
|
||||
{
|
||||
symb = strchr(right_symb, name[i]);
|
||||
if(symb == 0)
|
||||
symb = strchr(right_symb_name, name[i]);
|
||||
if (symb == 0)
|
||||
return FILENAME_SYMBOL_FAILURE;
|
||||
}
|
||||
|
||||
if(name[strln-1] == '.')
|
||||
if (name[strln - 1] == '.')
|
||||
return FILENAME_ENDING_FAILURE;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int createFile(char* file_name, char* extension, File* file)
|
||||
int check_ext(char *ext)
|
||||
{
|
||||
int strln = strlen(ext);
|
||||
int i;
|
||||
char *symb;
|
||||
|
||||
if (strln > extinsion_lenth)
|
||||
return FILENAME_LENGTH_FAILURE;
|
||||
|
||||
for (i = 0; i < strln; i++)
|
||||
{
|
||||
symb = strchr(right_symb_ext, ext[i]);
|
||||
if (symb == 0)
|
||||
return FILENAME_SYMBOL_FAILURE;
|
||||
}
|
||||
|
||||
if (ext[strln - 1] == '.')
|
||||
return FILENAME_ENDING_FAILURE;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int createFile(char *file_name, char *extension, File *file)
|
||||
{
|
||||
ERROR_CODE errno;
|
||||
time_t time_now;
|
||||
struct tm* time_info;
|
||||
File result = {"\0","\0","\0"};
|
||||
struct tm *time_info;
|
||||
File result = {"\0", "\0", "\0"};
|
||||
|
||||
time(&time_now);
|
||||
time_info = localtime(&time_now);
|
||||
|
||||
strftime (result.creation_time,creation_time_length,"%T %D",time_info);
|
||||
strftime(result.creation_time, creation_time_length, "%T %D", time_info);
|
||||
strftime(result.creation_date, creation_time_length, "%D ", time_info);
|
||||
|
||||
if((errno = check_name(file_name)) != SUCCESS)
|
||||
if ((errno = check_name(file_name)) != SUCCESS)
|
||||
return errno;
|
||||
|
||||
|
||||
if ((errno = check_ext(extension)) != SUCCESS)
|
||||
return errno;
|
||||
|
||||
strcpy(result.filename, file_name);
|
||||
|
||||
strcpy(result.extension, extension);
|
||||
|
||||
*file = result;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int createFolder(char* folder_name, Folder* folder)
|
||||
int createFolder(char *folder_name, Folder *folder)
|
||||
{
|
||||
ERROR_CODE errno;
|
||||
time_t time_now;
|
||||
struct tm* time_info;
|
||||
Folder result = {0, 0, 1, 1, 0, "\0","\0"};
|
||||
|
||||
if((errno = check_name(folder_name)) != SUCCESS)
|
||||
struct tm *time_info;
|
||||
Folder result = {0, 0, 1, 1, 0, "\0", "\0"};
|
||||
|
||||
if ((errno = check_name(folder_name)) != SUCCESS)
|
||||
return errno;
|
||||
|
||||
|
||||
strcpy(result.filename, folder_name);
|
||||
|
||||
time(&time_now);
|
||||
time_info = localtime(&time_now);
|
||||
|
||||
strftime (result.creation_time,creation_time_length,"%T %D",time_info);
|
||||
strftime(result.creation_time, creation_time_length, "%T %D", time_info);
|
||||
strftime(result.creation_date, creation_time_length, "%D ", time_info);
|
||||
|
||||
result.files = (File*) malloc(sizeof(File));
|
||||
result.folders = (Folder*) malloc(sizeof(Folder));
|
||||
result.files = (File *)malloc(sizeof(File));
|
||||
result.folders = (Folder *)malloc(sizeof(Folder));
|
||||
|
||||
if(result.files == NULL || result.folders == NULL)
|
||||
if (result.files == NULL || result.folders == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
|
||||
*folder = result;
|
||||
|
@ -72,87 +101,130 @@ int createFolder(char* folder_name, Folder* folder)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
int addFolder(char* folder_name, Folder* fld)
|
||||
int addFolder(char *folder_name, Folder *fld)
|
||||
{
|
||||
int errno, i;
|
||||
Folder newFolder;
|
||||
Folder* buffer;
|
||||
|
||||
errno = createFolder(folder_name, &newFolder);
|
||||
if(errno != SUCCESS)
|
||||
return errno;
|
||||
|
||||
fld->folders[fld->folders_count_cur] = newFolder;
|
||||
fld->exists_into++;
|
||||
fld->folders_count_cur++;
|
||||
|
||||
if(fld->folders_count_cur == fld->folders_count_max)
|
||||
if (fld->exists_into < MAX_EXIST_OBJ)
|
||||
{
|
||||
fld->folders_count_max <<= 1;
|
||||
buffer = (Folder*)malloc(sizeof(Folder) * (fld->folders_count_cur));
|
||||
if(buffer == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->folders_count_cur; ++i)
|
||||
{
|
||||
buffer[i] = fld->folders[i];
|
||||
}
|
||||
free(fld->folders);
|
||||
fld->folders = (Folder*)malloc(sizeof(Folder) * (fld->folders_count_max));
|
||||
if(fld->folders == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->folders_count_cur; ++i)
|
||||
{
|
||||
fld->folders[i] = buffer[i];
|
||||
}
|
||||
free(buffer);
|
||||
int errno, i;
|
||||
Folder newFolder;
|
||||
Folder *buffer;
|
||||
|
||||
for (i = 0; i < fld->folders_count_cur; i++)
|
||||
{
|
||||
if (!strcmp(folder_name, fld->folders[i].filename))
|
||||
return EXISTING_NAME_FAILURE;
|
||||
}
|
||||
|
||||
errno = createFolder(folder_name, &newFolder);
|
||||
if (errno != SUCCESS)
|
||||
return errno;
|
||||
|
||||
fld->folders[fld->folders_count_cur] = newFolder;
|
||||
fld->exists_into++;
|
||||
fld->folders_count_cur++;
|
||||
|
||||
if (fld->folders_count_cur == fld->folders_count_max)
|
||||
{
|
||||
fld->folders_count_max <<= 1;
|
||||
buffer = (Folder *)malloc(sizeof(Folder) * (fld->folders_count_cur));
|
||||
if (buffer == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->folders_count_cur; ++i)
|
||||
{
|
||||
buffer[i] = fld->folders[i];
|
||||
}
|
||||
free(fld->folders);
|
||||
fld->folders = (Folder *)malloc(sizeof(Folder) * (fld->folders_count_max));
|
||||
if (fld->folders == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->folders_count_cur; ++i)
|
||||
{
|
||||
fld->folders[i] = buffer[i];
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
fld->folders[fld->folders_count_cur].parent = fld;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
fld->folders[fld->folders_count_cur].parent = fld;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int addFile(char* file_name, char* extension, Folder* fld)
|
||||
int addFile(char *file_name, char *extension, Folder *fld)
|
||||
{
|
||||
int errno, i;
|
||||
File newFile;
|
||||
File* buffer;
|
||||
|
||||
errno = createFile(file_name, extension, &newFile);
|
||||
if(errno != SUCCESS)
|
||||
return errno;
|
||||
|
||||
fld->files[fld->files_count_cur] = newFile;
|
||||
fld->exists_into++;
|
||||
fld->files_count_cur++;
|
||||
|
||||
if(fld->files_count_cur == fld->files_count_max)
|
||||
if (fld->exists_into < MAX_EXIST_OBJ)
|
||||
{
|
||||
fld->files_count_max <<= 1;
|
||||
buffer = (File*)malloc(sizeof(File) * (fld->files_count_cur));
|
||||
if(buffer == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->files_count_cur; ++i)
|
||||
{
|
||||
buffer[i] = fld->files[i];
|
||||
}
|
||||
free(fld->files);
|
||||
fld->files = (File*)malloc(sizeof(File) * (fld->files_count_max));
|
||||
if(fld->files == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->files_count_cur; ++i)
|
||||
{
|
||||
fld->files[i] = buffer[i];
|
||||
}
|
||||
free(buffer);
|
||||
int errno, i;
|
||||
File newFile;
|
||||
File *buffer;
|
||||
|
||||
for (i = 0; i < fld->files_count_cur; i++)
|
||||
{
|
||||
if (!strcmp(extension, fld->files[i].extension) && !strcmp(file_name, fld->files[i].filename))
|
||||
return EXISTING_NAME_FAILURE;
|
||||
}
|
||||
|
||||
errno = createFile(file_name, extension, &newFile);
|
||||
if (errno != SUCCESS)
|
||||
return errno;
|
||||
|
||||
fld->files[fld->files_count_cur] = newFile;
|
||||
fld->exists_into++;
|
||||
fld->files_count_cur++;
|
||||
|
||||
if (fld->files_count_cur == fld->files_count_max)
|
||||
{
|
||||
fld->files_count_max <<= 1;
|
||||
buffer = (File *)malloc(sizeof(File) * (fld->files_count_cur));
|
||||
if (buffer == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->files_count_cur; ++i)
|
||||
{
|
||||
buffer[i] = fld->files[i];
|
||||
}
|
||||
free(fld->files);
|
||||
fld->files = (File *)malloc(sizeof(File) * (fld->files_count_max));
|
||||
if (fld->files == NULL)
|
||||
return MEMORY_ALLOCATION_FAILURE;
|
||||
for (i = 0; i < fld->files_count_cur; ++i)
|
||||
{
|
||||
fld->files[i] = buffer[i];
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
fld->files[fld->files_count_cur].parent = fld;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
fld->files[fld->files_count_cur].parent = fld;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int print_list(Folder* fld)
|
||||
int print_list(Folder *fld, int mode)
|
||||
{
|
||||
|
||||
int i; // iterator
|
||||
|
||||
if (mode == 0) // simple
|
||||
{
|
||||
printf("Files:\n");
|
||||
for (i = 0; i < fld->files_count_cur; i++)
|
||||
printf("%*s.%-*s\n", filename_lenth, fld->files[i].filename, extinsion_lenth, fld->files[i].extension);
|
||||
printf("Folders:\n");
|
||||
for (i = 0; i < fld->folders_count_cur; i++)
|
||||
printf("%*s\n", filename_lenth, fld->folders[i].filename);
|
||||
}
|
||||
if (mode == 1) // not simple
|
||||
{
|
||||
printf("┌──────────┬──────────┬────────────────────────────────────────────────────┬────────────┐\n");
|
||||
printf("│ Time │ Date │ Filenames │ Extension │\n");
|
||||
printf("├──────────┼──────────┼────────────────────────────────────────────────────┼────────────┤\n");
|
||||
|
||||
for (i = 0; i < fld->files_count_cur; i++)
|
||||
printf("│ %s│ %s│ %*s │ %*s │\n", fld->files[i].creation_time, fld->files[i].creation_date, filename_lenth, fld->files[i].filename, extinsion_lenth, fld->files[i].extension);
|
||||
printf("├──────────┼──────────┼────────────────────────────────────────────────────┼────────────┘\n");
|
||||
printf("│ Time │ Date │ Foldernames │\n");
|
||||
printf("├──────────┼──────────┼────────────────────────────────────────────────────┤\n");
|
||||
for (i = 0; i < fld->folders_count_cur; i++)
|
||||
printf("│ %s│ %s│ %*s │\n", fld->folders[i].creation_time, fld->folders[i].creation_date, filename_lenth, fld->folders[i].filename);
|
||||
printf("└──────────┴──────────┴────────────────────────────────────────────────────┘\n");
|
||||
}
|
||||
}
|
||||
|
|
55
structs.h
55
structs.h
|
@ -3,38 +3,47 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
static const char right_symb[] = " qwertyuiop[]{}asdfghjkl;zxcvbnm,.?!@~`#№$%^&()+-0123456789";
|
||||
#define MAX_EXIST_OBJ 255
|
||||
|
||||
static const char right_symb_name[] = " QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiop[]{}asdfghjkl;zxcvbnm,.?!@~`#№$%^&()+-0123456789";
|
||||
static const char right_symb_ext[] = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789";
|
||||
|
||||
#define extinsion_lenth 10
|
||||
#define filename_lenth 50
|
||||
#define creation_time_length 17
|
||||
|
||||
typedef struct _File{
|
||||
char creation_time[creation_time_length+1];
|
||||
char filename[filename_lenth+1];
|
||||
char extension[extinsion_lenth+1];
|
||||
struct _Folder* parent;
|
||||
}File;
|
||||
typedef struct _File
|
||||
{
|
||||
char creation_time[creation_time_length + 1];
|
||||
char creation_date[creation_time_length + 1];
|
||||
char filename[filename_lenth + 1];
|
||||
char extension[extinsion_lenth + 1];
|
||||
struct _Folder *parent;
|
||||
} File;
|
||||
|
||||
int createFile(char* file_name, char* extension, File* file);
|
||||
int createFile(char *file_name, char *extension, File *file);
|
||||
|
||||
typedef struct _Folder{
|
||||
uint8_t files_count_cur;
|
||||
uint8_t folders_count_cur;
|
||||
uint8_t files_count_max;
|
||||
uint8_t folders_count_max;
|
||||
uint8_t exists_into;
|
||||
char creation_time[creation_time_length+1];
|
||||
char filename[filename_lenth+1];
|
||||
File* files;
|
||||
struct _Folder* folders;
|
||||
struct _Folder* parent;
|
||||
}Folder;
|
||||
typedef struct _Folder
|
||||
{
|
||||
uint16_t files_count_cur;
|
||||
uint16_t folders_count_cur;
|
||||
uint16_t files_count_max;
|
||||
uint16_t folders_count_max;
|
||||
uint16_t exists_into;
|
||||
char creation_time[creation_time_length + 1];
|
||||
char creation_date[creation_time_length + 1];
|
||||
char filename[filename_lenth + 1];
|
||||
File *files;
|
||||
struct _Folder *folders;
|
||||
struct _Folder *parent;
|
||||
} Folder;
|
||||
|
||||
int createFolder(char* folder_name, Folder* folder);
|
||||
int createFolder(char *folder_name, Folder *folder);
|
||||
|
||||
int addFolder(char* folder_name, Folder* fld);
|
||||
int addFolder(char *folder_name, Folder *fld);
|
||||
|
||||
int addFile(char* file_name, char* extension, Folder* fld);
|
||||
int addFile(char *file_name, char *extension, Folder *fld);
|
||||
|
||||
int print_list(Folder *fld, int mode);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue