Parcourir la source

File list support...

master
Ognjen Milan Robovic il y a 8 mois
Parent
révision
ad6bff8b1d
2 fichiers modifiés avec 90 ajouts et 11 suppressions
  1. +77
    -10
      xtandard.c
  2. +13
    -1
      xtandard.h

+ 77
- 10
xtandard.c Voir le fichier

@@ -16,6 +16,13 @@ char * * argument_nick = NULL;
char * * argument_name = NULL;
void (* * argument_function) (void) = NULL;

int file_list_active = 0;
int file_list_count = 0;
int * file_list_mark = NULL;
int * file_list_size = NULL;
char * * file_list_name = NULL;
char * * file_list_data = NULL;

void in (void * data, int size) {
fatal_failure (data == NULL, "in: Failed to read from standard input, data is null pointer.");
fatal_failure (size == 0, "in: Failed to read from standard input, size is zero.");
@@ -174,6 +181,62 @@ void argument_delete (void) {
argument_function = deallocate (argument_function);
}

void file_list_import (char * name) {
++file_list_count;

file_list_active = file_list_count - 1;

file_list_mark = reallocate (file_list_mark, (int) sizeof (* file_list_mark) * file_list_count);
file_list_size = reallocate (file_list_size, (int) sizeof (* file_list_size) * file_list_count);
file_list_name = reallocate (file_list_name, (int) sizeof (* file_list_name) * file_list_count);
file_list_data = reallocate (file_list_data, (int) sizeof (* file_list_data) * file_list_count);

file_list_mark [file_list_count - 1] = -1;
file_list_size [file_list_count - 1] = -1;
file_list_name [file_list_count - 1] = NULL;
file_list_data [file_list_count - 1] = NULL;

file_list_name [file_list_count - 1] = allocate (string_length (name) + 1);

(void) string_copy_limit (file_list_name [file_list_count - 1], name, string_length (name) + 1);

file_list_mark [file_list_count - 1] = open (name, O_RDONLY);

file_list_size [file_list_count - 1] = (int) lseek (file_list_mark [file_list_count - 1], 0, SEEK_END) + 1;

(void) lseek (file_list_mark [file_list_count - 1], 0, SEEK_SET);

file_list_data [file_list_count - 1] = allocate (file_list_size [file_list_count - 1]);

(void) read (file_list_mark [file_list_count - 1], file_list_data [file_list_count - 1], (unsigned long int) (file_list_size [file_list_count - 1] - 1));

close (file_list_mark [file_list_count - 1]);

file_list_data [file_list_count - 1] [file_list_size [file_list_count - 1] - 1] = '\0';
}

void file_list_export (char * name) {
file_list_mark [file_list_active] = open (name, O_WRONLY | O_CREAT | O_TRUNC);

(void) write (file_list_mark [file_list_active], file_list_data [file_list_active], (unsigned long int) file_list_size [file_list_active]);

close (file_list_mark [file_list_active]);
}

void file_list_delete (void) {
int i;

for (i = 0; i != file_list_count; ++i) {
file_list_name [i] = deallocate (file_list_name [i]);
file_list_data [i] = deallocate (file_list_data [i]);
}

file_list_mark = deallocate (file_list_mark);
file_list_size = deallocate (file_list_size);
file_list_name = deallocate (file_list_name);
file_list_data = deallocate (file_list_data);
}

int file_open (char * name, int mode) {
int descriptor = -1;

@@ -249,10 +312,6 @@ int string_length (char * string) {
return (length);
}

void string_delete (char * string) {
string [0] = '\0';
}

void string_reverse (char * string) {
int i = 0;
int length = 0;
@@ -266,6 +325,17 @@ void string_reverse (char * string) {
}
}

void string_delete (char * string, int length) {
int i;

fatal_failure (string == NULL, "string_delete: String is null.");
fatal_failure (length == 0, "string_delete: String length is zero.");

for (i = 0; i != length; ++i) {
string [i] = '\0';
}
}

int string_compare (char * string_0, char * string_1) {
int i = 0;

@@ -317,7 +387,7 @@ int string_compare_limit (char * string_0, char * string_1, int limit) {
fatal_failure (string_0 == NULL, "string_compare_limit: Destination string is null.");
fatal_failure (string_1 == NULL, "string_compare_limit: Source string is null.");

for (i = 0; (string_0 [i] != '\0') && (string_1 [i] != '\0') && (i != limit); ++i) {
for (i = 0; i != limit; ++i) {
if (string_0 [i] != string_1 [i]) {
return (0);
}
@@ -327,8 +397,7 @@ int string_compare_limit (char * string_0, char * string_1, int limit) {
}

void string_copy_limit (char * string_0, char * string_1, int limit) {
int i = 0;
int length = 0;
int i = 0;

fatal_failure (string_0 == NULL, "string_copy_limit: Destination string is null.");
fatal_failure (string_1 == NULL, "string_copy_limit: Source string is null.");
@@ -337,9 +406,7 @@ void string_copy_limit (char * string_0, char * string_1, int limit) {
return;
}

length = string_length (string_1);

for (i = 0; (i != length) && (i != limit); ++i) {
for (i = 0; i != limit; ++i) {
string_0 [i] = string_1 [i];
}
}


+ 13
- 1
xtandard.h Voir le fichier

@@ -40,6 +40,13 @@ extern char * * argument_nick;
extern char * * argument_name;
extern void (* * argument_function) (void);

extern int file_list_active;
extern int file_list_count;
extern int * file_list_mark;
extern int * file_list_size;
extern char * * file_list_name;
extern char * * file_list_data;

extern void in (void *, int);
extern void out (void *, int);

@@ -67,10 +74,15 @@ extern int file_close (int);
extern void file_import (char *, void *);
extern void file_export (char *, void *);

extern void file_list_import (char *);
extern void file_list_export (char *);
extern void file_list_delete (void);

extern int string_length (char *);
extern void string_delete (char *);
extern void string_reverse (char *);

extern void string_delete (char *, int);

extern int string_compare (char *, char *);
extern void string_copy (char *, char *);
extern void string_concatenate (char *, char *);


Chargement…
Annuler
Enregistrer