Small config for V2.0
This commit is contained in:
parent
1ef0b23e0d
commit
1234eb4dbf
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
Temporary/
|
Temporary/
|
||||||
|
.vscode/
|
||||||
|
Configuration/install_path.h
|
||||||
@ -1 +0,0 @@
|
|||||||
int l123(void) { return 0; }
|
|
||||||
70
Application/argsconfig.c
Normal file
70
Application/argsconfig.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* argsconfig.c
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__ARGSCONFIG_C__)
|
||||||
|
#define __ARGSCONFIG_C__
|
||||||
|
|
||||||
|
#include "../Library/argsconfig.h"
|
||||||
|
|
||||||
|
void projmr_argsconfig_help(void) {
|
||||||
|
puts(
|
||||||
|
"Projmr V2.0" PBREAK
|
||||||
|
PLINER "Simple manager for your C-projects" PENDLN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
int projmr_argsconifg_parse(int argc, char** argv) {
|
||||||
|
unsigned int i = 1;
|
||||||
|
char* name = (char*)NULL;
|
||||||
|
|
||||||
|
while (i < (unsigned int)argc) {
|
||||||
|
char* str = argv[i];
|
||||||
|
if (str[0] == '-') {
|
||||||
|
unsigned char use_external = 0;
|
||||||
|
if (str[1] == '-') use_external = 1;
|
||||||
|
switch (str[1 + use_external]) {
|
||||||
|
case 'h':
|
||||||
|
projmr_argsconfig_help();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
default:
|
||||||
|
projmr_error_log("Unknown token!");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
name = str;
|
||||||
|
}
|
||||||
|
i ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
return projmr_run_creating(name);
|
||||||
|
} else {
|
||||||
|
projmr_error_log("Please specify the name of the project!");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ARGSCONFIG_C__ */
|
||||||
68
Application/creating.c
Normal file
68
Application/creating.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* creating.c
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__CREATING_C__)
|
||||||
|
#define __CREATING_C__
|
||||||
|
|
||||||
|
#include "../Library/creating.h"
|
||||||
|
|
||||||
|
static FILE* projmr_parse_line_and_open(char* buf) {
|
||||||
|
if (buf[0] == '/') {
|
||||||
|
buf ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int projmr_run_creating(char* name) {
|
||||||
|
projmr_info_log("Creating project...");
|
||||||
|
char buf[PROJMR_FILE_BUFFER_SIZE] = "\0";
|
||||||
|
FILE* fp = projmr_open_project_file(PROJMR_CONFIG_FILE_NAME, "r");
|
||||||
|
if (fp) {
|
||||||
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
|
size_t len = strlen(buf);
|
||||||
|
if (len > 0 && buf[len - 1] != '\n') {
|
||||||
|
projmr_warning_log(
|
||||||
|
"The line was not read "
|
||||||
|
"completely (perhaps th"
|
||||||
|
"e last line in the fil"
|
||||||
|
"e does not end with \""
|
||||||
|
"\n\")" VOID_LINE_DETECT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
FILE* ld = projmr_parse_line_and_open(buf);
|
||||||
|
if (ld) {
|
||||||
|
|
||||||
|
fclose(ld);
|
||||||
|
} else {
|
||||||
|
projmr_error_log("Cannot load file from config!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
projmr_error_log("Cannot load config!");
|
||||||
|
}
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __CREATING_C__ */
|
||||||
70
Application/logger.c
Normal file
70
Application/logger.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* logger.c
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__LOGGER_C__)
|
||||||
|
#define __LOGGER_C__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../Library/project.h"
|
||||||
|
|
||||||
|
void __CREATE_SPECIF__(error_log) (const char* _err) {
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"\033[1m"
|
||||||
|
__STRING_PROJECT_NAME__
|
||||||
|
": \033[91m%s\033[0m\n",
|
||||||
|
_err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __CREATE_SPECIF__(warning_log) (const char* _err) {
|
||||||
|
printf(
|
||||||
|
"\033[1m"
|
||||||
|
__STRING_PROJECT_NAME__
|
||||||
|
": \033[35m%s\033[0m\n",
|
||||||
|
_err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __CREATE_SPECIF__(success_log) (const char* _err) {
|
||||||
|
printf(
|
||||||
|
"\033[1m"
|
||||||
|
__STRING_PROJECT_NAME__
|
||||||
|
": \033[32m%s\033[0m\n",
|
||||||
|
_err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __CREATE_SPECIF__(info_log) (const char* _err) {
|
||||||
|
printf(
|
||||||
|
"\033[1m"
|
||||||
|
__STRING_PROJECT_NAME__
|
||||||
|
": \033[36m%s\033[0m\n",
|
||||||
|
_err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __LOGGER_C__ */
|
||||||
50
Application/project.c
Normal file
50
Application/project.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* project.c
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__PROJECT_C__)
|
||||||
|
#define __PROJECT_C__
|
||||||
|
|
||||||
|
#include "../Library/project.h"
|
||||||
|
|
||||||
|
FILE* __CREATE_SPECIF__(open_project_file) (const char* name, const char* mode) {
|
||||||
|
char* f = (char*)malloc(
|
||||||
|
sizeof(char) *
|
||||||
|
(strlen(name) +
|
||||||
|
strlen(__PROJMR_INSTALL_PATH__))
|
||||||
|
);
|
||||||
|
strcpy(f, __PROJMR_INSTALL_PATH__);
|
||||||
|
strcat(f, "/");
|
||||||
|
strcat(f, name);
|
||||||
|
FILE* fp = fopen(f, mode);
|
||||||
|
free(f);
|
||||||
|
if (fp == NULL) {
|
||||||
|
fp = fopen(name, mode);
|
||||||
|
if (fp == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __PROJECT_C__ */
|
||||||
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "../Library/argsconfig.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
return 0;
|
return projmr_argsconifg_parse(argc, argv);
|
||||||
}
|
}
|
||||||
|
|||||||
40
Library/argsconfig.h
Normal file
40
Library/argsconfig.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* argsconfig.h
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__ARGSCONFIG_H__)
|
||||||
|
#define __ARGSCONFIG_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../Library/logger.h"
|
||||||
|
#include "../Library/creating.h"
|
||||||
|
|
||||||
|
#define PLINER " "
|
||||||
|
#define PBREAK "\n"
|
||||||
|
#define PENDLN "\0"
|
||||||
|
|
||||||
|
int projmr_argsconifg_parse(int argc, char** argv);
|
||||||
|
|
||||||
|
#endif /* __ARGSCONFIG_H__ */
|
||||||
43
Library/creating.h
Normal file
43
Library/creating.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* creating.h
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__CREATING_H__)
|
||||||
|
#define __CREATING_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../Library/logger.h"
|
||||||
|
|
||||||
|
#define VOID_LINE_DETECT
|
||||||
|
|
||||||
|
#define PROJMR_TEMPLATES_PATH "Templates"
|
||||||
|
#define PROJMR_CATALOG_NEW "/"
|
||||||
|
|
||||||
|
#define PROJMR_CONFIG_FILE_NAME "meta.cue"
|
||||||
|
#define PROJMR_FILE_BUFFER_SIZE 1024
|
||||||
|
|
||||||
|
int projmr_run_creating(char* name);
|
||||||
|
|
||||||
|
#endif /* __CREATING_H__ */
|
||||||
38
Library/logger.h
Normal file
38
Library/logger.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* logger.h
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__LOGGER_H__)
|
||||||
|
#define __LOGGER_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../Library/project.h"
|
||||||
|
|
||||||
|
void __CREATE_SPECIF__(error_log) (const char* _err);
|
||||||
|
void __CREATE_SPECIF__(warning_log) (const char* _err);
|
||||||
|
void __CREATE_SPECIF__(success_log) (const char* _err);
|
||||||
|
void __CREATE_SPECIF__(info_log) (const char* _err);
|
||||||
|
|
||||||
|
#endif /* __LOGGER_H__ */
|
||||||
77
Library/project.h
Normal file
77
Library/project.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* project.h
|
||||||
|
*
|
||||||
|
* Copyright 2025
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__PROJECT_H__)
|
||||||
|
#define __PROJECT_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../Configuration/install_path.h"
|
||||||
|
|
||||||
|
#if !defined(__PROJMR_INSTALL_PATH__)
|
||||||
|
#error Cannot find __PROJMR_INSTALL_PATH__!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__PROJECT_NAME__)
|
||||||
|
#undef __PROJECT_NAME__
|
||||||
|
#endif /* __PROJECT_NAME__ */
|
||||||
|
|
||||||
|
#if defined(__STRING_PROJECT_NAME__)
|
||||||
|
#undef __STRING_PROJECT_NAME__
|
||||||
|
#endif /* __STRING_PROJECT_NAME__ */
|
||||||
|
|
||||||
|
#if defined(__INLINE_CREATE_SPECIF)
|
||||||
|
#undef __INLINE_CREATE_SPECIF
|
||||||
|
#endif /* __INLINE_CREATE_SPECIF */
|
||||||
|
|
||||||
|
#if defined(__CREATE_SPECIF__)
|
||||||
|
#undef __CREATE_SPECIF__
|
||||||
|
#endif /* __CREATE_SPECIF__ */
|
||||||
|
|
||||||
|
#if defined(__CONCAT__)
|
||||||
|
#undef __CONCAT__
|
||||||
|
#endif /* __CONCAT__ */
|
||||||
|
|
||||||
|
#if defined(__STRING__)
|
||||||
|
#undef __STRING__
|
||||||
|
#endif /* __STRING__ */
|
||||||
|
|
||||||
|
#if defined(__CNT__)
|
||||||
|
#undef __CNT__
|
||||||
|
#endif /* __CNT__ */
|
||||||
|
|
||||||
|
#define __CNT__(a,b) a##b
|
||||||
|
#define __STRING__(c) #c
|
||||||
|
#define __CONCAT__(a, b) __CNT__(a, b)
|
||||||
|
#define __PROJECT_NAME__ projmr
|
||||||
|
#define __STRING_PROJECT_NAME__ __STRING__(__PROJECT_NAME__)
|
||||||
|
#define __INLINE_CREATE_SPECIF(name) __CONCAT__(_, name)
|
||||||
|
#define __CREATE_SPECIF__(name) \
|
||||||
|
__CONCAT__(__PROJECT_NAME__, __INLINE_CREATE_SPECIF(name))
|
||||||
|
|
||||||
|
FILE* __CREATE_SPECIF__(open_project_file) (const char* name, const char* mode);
|
||||||
|
|
||||||
|
#endif /* __PROJECT_H__ */
|
||||||
270
Library/projmr.h
270
Library/projmr.h
@ -1,270 +0,0 @@
|
|||||||
/*
|
|
||||||
* projmr.h
|
|
||||||
*
|
|
||||||
* Copyright 2025
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if (!defined(__LIB_projmr_H_))
|
|
||||||
#define __LIB_projmr_H_
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define projmr_VERSION "0.1"
|
|
||||||
|
|
||||||
#define Makefile "Makefile"
|
|
||||||
#define LICENSE "LICENSE"
|
|
||||||
|
|
||||||
char* __YDSJS_user_home = NULL;
|
|
||||||
char* __YDSJS_files_dir = "/.projmr/project_files/";
|
|
||||||
|
|
||||||
static void projmr_error(char* _err) {
|
|
||||||
printf("\033[1mprojmr: \033[91m%s\033[0m\n", _err);
|
|
||||||
}
|
|
||||||
|
|
||||||
void __attach_project_mode(void) {
|
|
||||||
__YDSJS_user_home = getenv("HOME");
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* __open_project_file(char* name, char* mode) {
|
|
||||||
if (strlen(name) >= 32) return NULL;
|
|
||||||
char* file_text_name = malloc(strlen(__YDSJS_user_home) + strlen(__YDSJS_files_dir) + 34);
|
|
||||||
strcpy(file_text_name, __YDSJS_user_home);
|
|
||||||
strcat(file_text_name, __YDSJS_files_dir);
|
|
||||||
strcat(file_text_name, name);
|
|
||||||
FILE* fp = fopen(file_text_name, mode);
|
|
||||||
free(file_text_name);
|
|
||||||
return fp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __create_makefile(char* name) {
|
|
||||||
FILE* makefile = fopen(Makefile, "w");
|
|
||||||
FILE* make_text = __open_project_file("make_license.txt", "r");
|
|
||||||
if (makefile == NULL || make_text == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
time_t mytime = time(NULL);
|
|
||||||
struct tm *now = localtime(&mytime);
|
|
||||||
int year = now->tm_year + 1900;
|
|
||||||
|
|
||||||
fprintf(makefile,
|
|
||||||
"#" "\n"
|
|
||||||
"# Makefile" "\n"
|
|
||||||
"# " "\n"
|
|
||||||
"# Copyright %d\n", year
|
|
||||||
);
|
|
||||||
int c;
|
|
||||||
while ((c = getc(make_text)) != EOF) {
|
|
||||||
fputc(c, makefile);
|
|
||||||
}
|
|
||||||
fclose(make_text);
|
|
||||||
make_text = __open_project_file("make_structure.txt", "r");
|
|
||||||
if (make_text == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
fprintf(makefile, "\nPROJECT_NAME=%s\n\n", name);
|
|
||||||
while ((c = getc(make_text)) != EOF) {
|
|
||||||
fputc(c, makefile);
|
|
||||||
}
|
|
||||||
fclose(make_text);
|
|
||||||
fclose(makefile);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __create_license(void) {
|
|
||||||
FILE* lic = __open_project_file("project_license.txt", "r");
|
|
||||||
FILE* wrt = fopen(LICENSE, "w");
|
|
||||||
if (lic == NULL || wrt == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
int c;
|
|
||||||
while ((c = getc(lic)) != EOF) {
|
|
||||||
fputc(c, wrt);
|
|
||||||
}
|
|
||||||
fclose(lic);
|
|
||||||
fclose(wrt);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __create_project_folder(void) {
|
|
||||||
if (mkdir("project_files", S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
|
|
||||||
puts("\033[1mprojmr: \033[35mWarning: The project already exists!\033[0m");
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
};
|
|
||||||
FILE* fp = fopen("project_files/example.txt", "w");
|
|
||||||
if (fp == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
fputs("Lorem ipsum dolor sit amet, consectetur " "\n"
|
|
||||||
"adipiscing elit, sed do eiusmod tempor incididunt ut " "\n"
|
|
||||||
"labore et dolore magna aliqua. Ut enim ad minim veniam, " "\n"
|
|
||||||
"quis nostrud exercitation ullamco laboris nisi ut " "\n"
|
|
||||||
"aliquip ex ea commodo consequat. Duis aute irure dolor " "\n"
|
|
||||||
"in reprehenderit in voluptate velit esse cillum dolore " "\n"
|
|
||||||
"eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " "\n"
|
|
||||||
"sunt in culpa qui officia deserunt mollit anim id est laborum" "\n", fp);
|
|
||||||
fclose(fp);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __create_config(char* name) {
|
|
||||||
FILE* make_text = __open_project_file("make_license.txt", "r");
|
|
||||||
FILE* conf = fopen("project.ini", "w");
|
|
||||||
if (conf == NULL || make_text == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
time_t mytime = time(NULL);
|
|
||||||
struct tm *now = localtime(&mytime);
|
|
||||||
int year = now->tm_year + 1900;
|
|
||||||
fprintf(conf,
|
|
||||||
"#" "\n"
|
|
||||||
"# project.ini" "\n"
|
|
||||||
"# " "\n"
|
|
||||||
"# Copyright %d\n", year
|
|
||||||
);
|
|
||||||
int c;
|
|
||||||
while ((c = getc(make_text)) != EOF) {
|
|
||||||
fputc(c, conf);
|
|
||||||
}
|
|
||||||
fprintf(conf, "\n[%d.%d.%d-%d:%d:%d]\n", now->tm_mday, now->tm_mon + 1, now->tm_year + 1900, now->tm_hour, now->tm_min, now->tm_sec);
|
|
||||||
fprintf(conf, "name=%s\n", name);
|
|
||||||
srand((unsigned long)(void*)name);
|
|
||||||
fprintf(conf, "id=%lu\n", (unsigned long int)rand());
|
|
||||||
fputs("project_files_count=1\n", conf);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __create_main(char* name) {
|
|
||||||
char file_name[35];
|
|
||||||
strcpy(file_name, name);
|
|
||||||
strcat(file_name, ".c");
|
|
||||||
FILE* main = fopen(file_name, "w");
|
|
||||||
FILE* main_ex = __open_project_file("project_main.txt", "r");
|
|
||||||
if (main == NULL || main_ex == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
time_t mytime = time(NULL);
|
|
||||||
struct tm *now = localtime(&mytime);
|
|
||||||
int year = now->tm_year + 1900;
|
|
||||||
fprintf(
|
|
||||||
main,
|
|
||||||
"/*" "\n"
|
|
||||||
" * %s" "\n"
|
|
||||||
" * " "\n"
|
|
||||||
" * Copyright %d " "\n",
|
|
||||||
file_name, year
|
|
||||||
);
|
|
||||||
int c;
|
|
||||||
while ((c = getc(main_ex)) != EOF) {
|
|
||||||
if (c != '%') fputc(c, main);
|
|
||||||
else fputs(name, main);
|
|
||||||
}
|
|
||||||
file_name[strlen(file_name) - 1] = 'h';
|
|
||||||
fclose(main);
|
|
||||||
fclose(main_ex);
|
|
||||||
main = fopen(file_name, "w");
|
|
||||||
main_ex = __open_project_file("project_lib.txt", "r");
|
|
||||||
if (main == NULL || main_ex == NULL) {
|
|
||||||
projmr_error("File error!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
fprintf(
|
|
||||||
main,
|
|
||||||
"/*" "\n"
|
|
||||||
" * %s" "\n"
|
|
||||||
" * " "\n"
|
|
||||||
" * Copyright %d " "\n",
|
|
||||||
file_name, year
|
|
||||||
);
|
|
||||||
unsigned int line = 1;
|
|
||||||
while ((c = getc(main_ex)) != EOF) {
|
|
||||||
if (c != '%' || line == 28) if (c != '@') fputc(c, main);
|
|
||||||
else fputs(name, main);
|
|
||||||
else fputs(name, main);
|
|
||||||
if (c == '\n') line ++;
|
|
||||||
}
|
|
||||||
fclose(main);
|
|
||||||
fclose(main_ex);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int __create_project(char* name) {
|
|
||||||
int ret = 0;
|
|
||||||
__attach_project_mode();
|
|
||||||
if (strlen(name) >= 32) {
|
|
||||||
projmr_error("The name cannot be longer than 31 characters.");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
ret += __create_makefile(name);
|
|
||||||
ret += __create_project_folder();
|
|
||||||
ret += __create_license();
|
|
||||||
ret += __create_main(name);
|
|
||||||
ret += __create_config(name);
|
|
||||||
if (ret != EXIT_SUCCESS) return EXIT_FAILURE;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int _lib_projmr_main(int argc, char** argv) {
|
|
||||||
size_t pos = 1;
|
|
||||||
char* project_name = NULL;
|
|
||||||
while (pos != argc) {
|
|
||||||
char* str = argv[pos];
|
|
||||||
if (str[0] == '-') {
|
|
||||||
unsigned char pos_loc = 0;
|
|
||||||
if (str[1] == '-') pos_loc ++;
|
|
||||||
switch (str[1 + pos_loc]) {
|
|
||||||
case 'h':
|
|
||||||
puts(
|
|
||||||
"Simple project manager witch GNU GPL V3" "\n"
|
|
||||||
" " "projmr NAME [--help / --version]" "\0"
|
|
||||||
);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
puts(projmr_VERSION);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
projmr_error("Unknown option!");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
project_name = str;
|
|
||||||
}
|
|
||||||
pos ++;
|
|
||||||
}
|
|
||||||
if (project_name == NULL) {
|
|
||||||
projmr_error("Error! Call \"projmr --help\" for more information.");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
return __create_project(project_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
36
Makefile
36
Makefile
@ -31,8 +31,8 @@ CC=gcc
|
|||||||
# Compiler flags
|
# Compiler flags
|
||||||
CFLAGS= -Wall -Wextra
|
CFLAGS= -Wall -Wextra
|
||||||
|
|
||||||
# Options
|
# Run flags (passed through environment variables)
|
||||||
OPTIONS= -O2 $(CFLAGS) -ansi
|
RFLAGS=
|
||||||
|
|
||||||
# Binary file link name
|
# Binary file link name
|
||||||
OUTPUT_LINK=$(PROJECT_NAME)
|
OUTPUT_LINK=$(PROJECT_NAME)
|
||||||
@ -63,6 +63,9 @@ LINK_CREATE=ln
|
|||||||
# Parametr for create softlink
|
# Parametr for create softlink
|
||||||
LINK_SOFT= -s
|
LINK_SOFT= -s
|
||||||
|
|
||||||
|
# Options
|
||||||
|
OPTIONS=$(CFLAGS)
|
||||||
|
|
||||||
# Create soft link
|
# Create soft link
|
||||||
CREATE_SOFT_LINK=$(LINK_CREATE) $(LINK_SOFT)
|
CREATE_SOFT_LINK=$(LINK_CREATE) $(LINK_SOFT)
|
||||||
|
|
||||||
@ -103,13 +106,20 @@ TOKEN=install_pkg
|
|||||||
# Templater
|
# Templater
|
||||||
TEMPLATER=projmr
|
TEMPLATER=projmr
|
||||||
|
|
||||||
|
# Configuration directory
|
||||||
|
CONFIGURATION=Configuration
|
||||||
|
|
||||||
# Path to install
|
# Path to install
|
||||||
PROJMR_SPECIFID_INSTALL_PATH=/etc/$(TEMPLATER)_$(TOKEN)/$(PROJECT_NAME)
|
PROJMR_SPECIFID_INSTALL_PATH=/etc/$(TEMPLATER)_$(TOKEN)/$(PROJECT_NAME)
|
||||||
|
|
||||||
.PHONY: clean install uninstall
|
# Directory for libs
|
||||||
|
INSTALLED=Installed
|
||||||
|
|
||||||
|
.PHONY: clean install uninstall run mkconfig all
|
||||||
|
|
||||||
$(OUTPUT_LINK): $(OBJECTS)
|
$(OUTPUT_LINK): $(OBJECTS)
|
||||||
@mkdir -p $(TEMPORARY)
|
@echo 'mkconfig $(CONFIGURATION) $(TEMPLATES) $(LIBRARY) $(TEMPORARY) $(APPLICATION)'
|
||||||
|
@$(MAKE) mkconfig > /dev/null
|
||||||
touch .gitignore
|
touch .gitignore
|
||||||
grep $(TEMPORARY)/ .gitignore || echo $(TEMPORARY)/ > .gitignore
|
grep $(TEMPORARY)/ .gitignore || echo $(TEMPORARY)/ > .gitignore
|
||||||
$(CC) $(OBJECTS) -o $(OUTPUT_NAME)
|
$(CC) $(OBJECTS) -o $(OUTPUT_NAME)
|
||||||
@ -122,10 +132,27 @@ $(TEMPORARY)/%.o: $(APPLICATION)/%.c
|
|||||||
|
|
||||||
all: $(OUTPUT_LINK)
|
all: $(OUTPUT_LINK)
|
||||||
|
|
||||||
|
run: all
|
||||||
|
./$(OUTPUT_LINK) $(RFLAGS) $(FLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(REMOVE_CMD) $(FOR_REMOVE_DIR) $(TEMPORARY)/*
|
$(REMOVE_CMD) $(FOR_REMOVE_DIR) $(TEMPORARY)/*
|
||||||
$(REMOVE_CMD) $(FOR_REMOVE_FILE) $(OUTPUT_LINK)
|
$(REMOVE_CMD) $(FOR_REMOVE_FILE) $(OUTPUT_LINK)
|
||||||
|
|
||||||
|
mkconfig:
|
||||||
|
mkdir -p $(CONFIGURATION)
|
||||||
|
mkdir -p $(TEMPLATES)
|
||||||
|
mkdir -p $(LIBRARY)
|
||||||
|
mkdir -p $(TEMPORARY)
|
||||||
|
mkdir -p $(APPLICATION)
|
||||||
|
mkdir -p $(INSTALLED)
|
||||||
|
touch $(CONFIGURATION)/install_path.h
|
||||||
|
echo '#if defined(__PROJMR_INSTALL_PATH__)' > $(CONFIGURATION)/install_path.h
|
||||||
|
echo '#undef __PROJMR_INSTALL_PATH__' >> $(CONFIGURATION)/install_path.h
|
||||||
|
echo '#endif' >> $(CONFIGURATION)/install_path.h
|
||||||
|
echo '#define __PROJMR_INSTALL_PATH__ ' '"$(PROJMR_SPECIFID_INSTALL_PATH)"' '\n' \
|
||||||
|
>> $(CONFIGURATION)/install_path.h
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
if test -d $(PROJMR_SPECIFID_INSTALL_PATH); then \
|
if test -d $(PROJMR_SPECIFID_INSTALL_PATH); then \
|
||||||
echo "[ INSTALL ERROR ] The program is already installed!"; \
|
echo "[ INSTALL ERROR ] The program is already installed!"; \
|
||||||
@ -141,4 +168,3 @@ install: all
|
|||||||
uninstall:
|
uninstall:
|
||||||
$(REMOVE_CMD) $(FOR_REMOVE_FILE) $(INSTALL_NAME)
|
$(REMOVE_CMD) $(FOR_REMOVE_FILE) $(INSTALL_NAME)
|
||||||
$(REMOVE_CMD) $(FOR_REMOVE_DIR) $(PROJMR_SPECIFID_INSTALL_PATH)
|
$(REMOVE_CMD) $(FOR_REMOVE_DIR) $(PROJMR_SPECIFID_INSTALL_PATH)
|
||||||
|
|
||||||
|
|||||||
2
Templates/meta.cue
Normal file
2
Templates/meta.cue
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/Application/{name}.c
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user