upload Backy by JohnXenox, trying to Autobuild
git-svn-id: svn://kolibrios.org@7883 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
dd92e74f77
commit
f3e6a74f6b
63
programs/develop/backy/Backy-lib.h
Normal file
63
programs/develop/backy/Backy-lib.h
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
#ifndef __jxl_Date_get_h__
|
||||
#define __jxl_Date_get_h__
|
||||
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short int uint16_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef char int8_t;
|
||||
typedef short int int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
|
||||
static inline uint32_t getDate(void)
|
||||
{
|
||||
uint32_t date;
|
||||
__asm__ __volatile__("int $0x40":"=a"(date):"a"(29));
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline uint32_t getTime(void)
|
||||
{
|
||||
uint32_t time;
|
||||
__asm__ __volatile__("int $0x40":"=a"(time):"a"(3));
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline void *openFile(uint32_t *length, const uint8_t *path)
|
||||
{
|
||||
uint8_t *fd;
|
||||
|
||||
__asm__ __volatile__ ("int $0x40":"=a"(fd), "=d"(*length):"a" (68), "b"(27),"c"(path));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline int32_t saveFile(uint32_t nbytes, uint8_t *data, uint32_t enc, uint8_t *path)
|
||||
{
|
||||
int32_t val;
|
||||
|
||||
uint8_t dt[28]; // basic information structure.
|
||||
|
||||
(uint32_t) dt[0] = 2; // subfunction number.
|
||||
(uint32_t) dt[4] = 0; // reserved.
|
||||
(uint32_t) dt[8] = 0; // reserved.
|
||||
(uint32_t) dt[12] = nbytes; // number of bytes to write.
|
||||
(uint8_t *) dt[16] = data; // pointer to data.
|
||||
(uint32_t) dt[20] = enc; // string encoding (0 = default, 1 = cp866, 2 = UTF-16LE, 3 = UTF-8).
|
||||
(uint8_t *) dt[24] = path; // pointer to path.
|
||||
|
||||
__asm__ __volatile__("int $0x40":"=a"(val):"a"(80), "b"(&dt));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
352
programs/develop/backy/Backy.c
Normal file
352
programs/develop/backy/Backy.c
Normal file
@ -0,0 +1,352 @@
|
||||
|
||||
/*
|
||||
Author: JohnXenox.
|
||||
Description: The program for backing up a file.
|
||||
|
||||
Works from command line, only!
|
||||
*/
|
||||
|
||||
#define CREATION_DATE "2020.05.07"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Backy-lib.h"
|
||||
|
||||
int date = 0;
|
||||
int time = 0;
|
||||
|
||||
char years = 0;
|
||||
char months = 0;
|
||||
char days = 0;
|
||||
|
||||
char hours = 0;
|
||||
char minutes = 0;
|
||||
char seconds = 0;
|
||||
|
||||
char *data = 0;
|
||||
int length = 0;
|
||||
|
||||
char path_in[4096] = {0};
|
||||
char path_out[4096] = {0};
|
||||
|
||||
char num[3] = {0};
|
||||
|
||||
char full_date[25] = {0};
|
||||
char ext[] = ".bak";
|
||||
|
||||
char flag = 0;
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
// ============================================================ //
|
||||
// preprocessing arguments from the command line. ============= //
|
||||
//
|
||||
// 0 argument - name of the programme.
|
||||
// 1 argument - path to the file with name that need to be backup.
|
||||
// 2 argument - the key (-o).
|
||||
// 3 argument - path to the output directory without the name of the file.
|
||||
|
||||
// printf("Number of args: %d\n", argc);
|
||||
// printf("Argv 0: %s\n", argv[0]);
|
||||
// sprintf("Argv 1: %s\n\n", argv[1]);
|
||||
|
||||
|
||||
// ============================================================ //
|
||||
// preprocess the command line arguments. ===================== //
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
// if found the key "-o", then copy output path into the array "path_out".
|
||||
if (*argv[i] == '-') // && (*(argv[i] + 1) == 'o'))
|
||||
{
|
||||
// printf("Key -o is found!\n");
|
||||
|
||||
i++;
|
||||
|
||||
flag = 1;
|
||||
|
||||
if (i <= argc)
|
||||
{
|
||||
// copying of a current path into the array "path_out".
|
||||
strcpy(path_out, argv[i]);
|
||||
|
||||
// printf("Path output is copyed!\n");
|
||||
|
||||
i++;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if inut path is found, then copy it into the array "path_in".
|
||||
if (*argv[i] == '/')
|
||||
{
|
||||
flag = 2;
|
||||
|
||||
// copying of a current path into the buffer.
|
||||
strcpy(path_in, argv[i]);
|
||||
|
||||
if (flag != 1)
|
||||
{
|
||||
int idx = strlen(path_in);
|
||||
while (path_in[idx] != '/')
|
||||
{
|
||||
idx--;
|
||||
}
|
||||
|
||||
strncpy(path_out, path_in, idx);
|
||||
}
|
||||
|
||||
// printf("Path input is copyed!\n");
|
||||
}
|
||||
|
||||
// if found characters.
|
||||
if ( (*argv[i] > '0') && (*argv[i] < '9') || \
|
||||
(*argv[i] > 'A') && (*argv[i] < 'Z') || \
|
||||
(*argv[i] > 'a') && (*argv[i] < 'z') )
|
||||
{
|
||||
flag = 3;
|
||||
|
||||
strcpy(path_in, argv[0]);
|
||||
// printf("Arg 0 is copyed!\n");
|
||||
|
||||
int idx = strlen(path_in);
|
||||
|
||||
while (path_in[idx] != '/')
|
||||
{
|
||||
path_in[idx] = 0;
|
||||
idx--;
|
||||
}
|
||||
|
||||
idx++;
|
||||
strcpy(path_out, path_in);
|
||||
strcpy(&path_in[idx], argv[1]);
|
||||
// printf("Arg 1 is added!\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// if not found the flag, then copy path from "path_in" into "path_out".
|
||||
if ((flag == 0) && (flag != 2) && (flag != 3))
|
||||
{
|
||||
// copying the input path into the output path,
|
||||
strcpy(path_out, path_in);
|
||||
//printf("Path input is copyed into the path output!\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//con_init_console_dll_param(-1, 23, -1, 23, "Backy");
|
||||
|
||||
printf("\n Name: Backy");
|
||||
printf("\n Date: %s", CREATION_DATE);
|
||||
printf("\n Description: The programme for backing up a file.\n");
|
||||
printf("\n Author: JohnXenox\n");
|
||||
|
||||
printf("\n Usage: backy <path1> <-o path2>\n");
|
||||
printf(" path1 - path to a file to be backuped.\n");
|
||||
printf(" -o path2 - path to the output directory without the name of a file.\n\n");
|
||||
|
||||
printf(" Examples:\n");
|
||||
printf(" backy test.c\n");
|
||||
printf(" backy test.c -o /tmp0/1/\n");
|
||||
printf(" backy /hd0/1/test.c\n");
|
||||
printf(" backy /hd0/1/test.c -o /tmp0/1/\n");
|
||||
|
||||
exit(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//printf("Path_in: %s\n", path_in);
|
||||
//printf("Path_out: %s\n", path_out);
|
||||
|
||||
|
||||
// ============================================================ //
|
||||
// getting the time in BCD. =================================== //
|
||||
|
||||
time = getTime(); // time = 0x00SSMMHH.
|
||||
|
||||
hours = (char)time;
|
||||
minutes = (char)(time >> 8);
|
||||
seconds = (char)(time >> 16);
|
||||
|
||||
// ============================================================ //
|
||||
// getting the date in BCD. =================================== //
|
||||
|
||||
date = getDate(); // date = 0x00DDMMYY.
|
||||
|
||||
years = (char)date;
|
||||
months = (char)(date >> 8);
|
||||
days = (char)(date >> 16);
|
||||
|
||||
// ============================================================ //
|
||||
// fills the array with the date in ASCII. ==================== //
|
||||
|
||||
char ofs = 0;
|
||||
char *dta = 0;
|
||||
|
||||
for (char i = 0; i < 3; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
dta = &years;
|
||||
full_date[ofs] = '2';
|
||||
ofs++;
|
||||
full_date[ofs] = '0';
|
||||
ofs++;
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
dta = &months;
|
||||
}
|
||||
if (i == 2)
|
||||
{
|
||||
dta = &days;
|
||||
}
|
||||
|
||||
|
||||
itoab(*dta, num, 16);
|
||||
|
||||
if (num[1] == 0)
|
||||
{
|
||||
full_date[ofs] = '0';
|
||||
ofs++;
|
||||
full_date[ofs] = num[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
full_date[ofs] = num[0];
|
||||
ofs++;
|
||||
full_date[ofs] = num[1];
|
||||
}
|
||||
|
||||
ofs++;
|
||||
|
||||
if (i != 2)
|
||||
{
|
||||
full_date[ofs] = '.';
|
||||
ofs++;
|
||||
}
|
||||
}
|
||||
|
||||
full_date[ofs] = '_';
|
||||
ofs++;
|
||||
|
||||
// ============================================================ //
|
||||
// fills the array with the time in ASCII. ==================== //
|
||||
|
||||
ofs = 11;
|
||||
dta = 0;
|
||||
|
||||
for (char i = 0; i < 3; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
dta = &hours;
|
||||
if (i == 1)
|
||||
dta = &minutes;
|
||||
if (i == 2)
|
||||
dta = &seconds;
|
||||
|
||||
itoab(*dta, num, 16);
|
||||
|
||||
if (num[1] == 0)
|
||||
{
|
||||
full_date[ofs] = '0';
|
||||
ofs++;
|
||||
full_date[ofs] = num[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
full_date[ofs] = num[0];
|
||||
ofs++;
|
||||
full_date[ofs] = num[1];
|
||||
}
|
||||
|
||||
ofs++;
|
||||
|
||||
if (i < 2)
|
||||
{
|
||||
full_date[ofs] = '.';
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// full_date[ofs] = '_';
|
||||
//}
|
||||
|
||||
ofs++;
|
||||
}
|
||||
|
||||
// ============================================================ //
|
||||
// adding the name of the input file to the output path. ====== //
|
||||
|
||||
// searching the end of the path string.
|
||||
int i = 0;
|
||||
int y = 0;
|
||||
|
||||
// searching for zero terminator in the input path.
|
||||
while (path_in[i] != 0)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
// searching for slash in the input path.
|
||||
while (path_in[i] != '/')
|
||||
{
|
||||
i--;
|
||||
}
|
||||
|
||||
// searching for zero terminator in the output path.
|
||||
while (path_out[y] != 0)
|
||||
{
|
||||
y++;
|
||||
}
|
||||
|
||||
// searching for slash in the output path.
|
||||
if (path_out[y - 1] == '/')
|
||||
{
|
||||
y--;
|
||||
}
|
||||
|
||||
// copying the input name of the file into the output path,
|
||||
strcpy(&path_out[y], &path_in[i]);
|
||||
|
||||
// ============================================================ //
|
||||
// adding the extension and full date to the path. ============ //
|
||||
|
||||
i = 0;
|
||||
|
||||
// searching for zero terminator in the output path.
|
||||
while (path_out[i] != 0)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
path_out[i] = '_';
|
||||
i++;
|
||||
|
||||
// adding full date.
|
||||
strcpy(&path_out[i], full_date);
|
||||
|
||||
i += strlen(full_date);
|
||||
|
||||
// adding the extension to path.
|
||||
strncpy(&path_out[i], ext, 4);
|
||||
|
||||
//printf("Path_in: %s\n", path_in);
|
||||
//printf("Path_out: %s\n", path_out);
|
||||
|
||||
data = openFile(&length, path_in);
|
||||
|
||||
saveFile(length, data, 0, path_out);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
BIN
programs/develop/backy/Backy.png
Normal file
BIN
programs/develop/backy/Backy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
3
programs/develop/backy/Build.sh
Normal file
3
programs/develop/backy/Build.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#SHS
|
||||
tcc Backy.c -o Backy -lck
|
||||
exit
|
6
programs/develop/backy/Tupfile.lua
Normal file
6
programs/develop/backy/Tupfile.lua
Normal file
@ -0,0 +1,6 @@
|
||||
if tup.getconfig('NO_GCC') ~= "" then return end
|
||||
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR")
|
||||
tup.include(HELPERDIR .. "/use_gcc.lua")
|
||||
tup.include(HELPERDIR .. "/use_menuetlibc.lua")
|
||||
compile_gcc{"Backy.c"}
|
||||
link_gcc("Backy")
|
BIN
programs/develop/backy/backy
Normal file
BIN
programs/develop/backy/backy
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user