Added more functions...
This commit is contained in:
parent
67170c507e
commit
5e27b78e2b
169
xtandard.c
169
xtandard.c
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include "xtandard.h"
|
#include "xtandard.h"
|
||||||
|
|
||||||
|
char * program_name = NULL;
|
||||||
|
char * program_mode = NULL;
|
||||||
|
char * program_license = NULL;
|
||||||
|
|
||||||
int argument_count = 0;
|
int argument_count = 0;
|
||||||
char * * argument_nick = NULL;
|
char * * argument_nick = NULL;
|
||||||
char * * argument_name = NULL;
|
char * * argument_name = NULL;
|
||||||
@ -195,6 +199,107 @@ void argument_delete (void) {
|
|||||||
argument_function = deallocate (argument_function);
|
argument_function = deallocate (argument_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int file_open (char * name, int mode) {
|
||||||
|
int descriptor = -1;
|
||||||
|
|
||||||
|
fatal_failure (name == NULL, "file_open: Failed to open file, name is null pointer.");
|
||||||
|
|
||||||
|
descriptor = open (name, mode);
|
||||||
|
|
||||||
|
fatal_failure (descriptor == -1, "file_open: Failed to open file, function open returned invalid descriptor.");
|
||||||
|
|
||||||
|
return (descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
int file_close (int file) {
|
||||||
|
fatal_failure (file == -1, "file_close: Failed to close file, invalid file descriptor.");
|
||||||
|
fatal_failure (close (file) == -1, "file_close: Failed to close file, function close returned invalid code.");
|
||||||
|
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_read (int file, void * data, int size) {
|
||||||
|
fatal_failure (file == -1, "file_read: Failed to read from file, invalid descriptor.");
|
||||||
|
fatal_failure (data == NULL, "file_read: Failed to read from file, data is null pointer.");
|
||||||
|
fatal_failure (size == 0, "file_read: Failed to read from file, size is zero.");
|
||||||
|
|
||||||
|
(void) read (file, data, (unsigned long int) size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_write (int file, void * data, int size) {
|
||||||
|
fatal_failure (file == -1, "file_write: Failed to write to file, invalid descriptor.");
|
||||||
|
fatal_failure (data == NULL, "file_write: Failed to write to file, data is null pointer.");
|
||||||
|
fatal_failure (size == 0, "file_write: Failed to write to file, size is zero.");
|
||||||
|
|
||||||
|
(void) write (file, data, (unsigned long int) size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int file_seek (int file, int whence) {
|
||||||
|
fatal_failure (file == -1, "file_seek: Failed to seek in file, invalid descriptor.");
|
||||||
|
|
||||||
|
return ((int) lseek (file, 0, whence));
|
||||||
|
}
|
||||||
|
|
||||||
|
int file_size (int file) {
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
fatal_failure (file == -1, "file_size: Failed to get size of file, invalid descriptor.");
|
||||||
|
|
||||||
|
size = lseek (file, 0, SEEK_END);
|
||||||
|
(void) lseek (file, 0, SEEK_SET);
|
||||||
|
|
||||||
|
fatal_failure (size == -1, "file_size: Failed to get size of file, invalid file size.");
|
||||||
|
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int file_type (char * name) {
|
||||||
|
char * file_type_data [FILE_TYPE_COUNT] = {
|
||||||
|
".txt", ".s", ".fasm", ".gasm", ".nasm", ".yasm", ".c", ".h",
|
||||||
|
".adb", ".ads", ".cpp", ".hpp"
|
||||||
|
};
|
||||||
|
|
||||||
|
int type = 0;
|
||||||
|
|
||||||
|
while (* name != '.') {
|
||||||
|
++name;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (type = 0; type != FILE_TYPE_COUNT; ++type) {
|
||||||
|
if (string_compare (name, file_type_data [type]) != 0) {
|
||||||
|
return (type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char * file_import (char * name) {
|
||||||
|
int file = -1;
|
||||||
|
int size = -1;
|
||||||
|
char * data = NULL;
|
||||||
|
|
||||||
|
fatal_failure (name == NULL, "file_import: Failed to import file, name is null pointer.");
|
||||||
|
fatal_failure (data != NULL, "file_import: Failed to import file, data is not null pointer.");
|
||||||
|
|
||||||
|
file = file_open (name, O_RDONLY);
|
||||||
|
size = file_size (file) + 1;
|
||||||
|
data = allocate (size);
|
||||||
|
|
||||||
|
file_read (file, data, size - 1);
|
||||||
|
|
||||||
|
data [size - 1] = '\0';
|
||||||
|
|
||||||
|
file = file_close (file);
|
||||||
|
|
||||||
|
return (data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_export (char * name, void * data) {
|
||||||
|
(void) name;
|
||||||
|
(void) data;
|
||||||
|
}
|
||||||
|
|
||||||
void file_list_import (char * name) {
|
void file_list_import (char * name) {
|
||||||
fatal_failure (name == NULL, "file_list_import: Failed to import file, name is null pointer.");
|
fatal_failure (name == NULL, "file_list_import: Failed to import file, name is null pointer.");
|
||||||
|
|
||||||
@ -257,70 +362,6 @@ void file_list_delete (void) {
|
|||||||
file_list_data = deallocate (file_list_data);
|
file_list_data = deallocate (file_list_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_open (char * name, int mode) {
|
|
||||||
int descriptor = -1;
|
|
||||||
|
|
||||||
fatal_failure (name == NULL, "file_open: Failed to open file, name is null pointer.");
|
|
||||||
|
|
||||||
descriptor = open (name, mode);
|
|
||||||
|
|
||||||
fatal_failure (descriptor == -1, "file_open: Failed to open file, function open returned invalid descriptor.");
|
|
||||||
|
|
||||||
return (descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
int file_close (int file) {
|
|
||||||
fatal_failure (file == -1, "file_close: Failed to close file, invalid file descriptor.");
|
|
||||||
fatal_failure (close (file) == -1, "file_close: Failed to close file, function close returned invalid code.");
|
|
||||||
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void file_read (int file, void * data, int size) {
|
|
||||||
fatal_failure (file == -1, "file_read: Failed to read from file, invalid descriptor.");
|
|
||||||
fatal_failure (data == NULL, "file_read: Failed to read from file, data is null pointer.");
|
|
||||||
fatal_failure (size == 0, "file_read: Failed to read from file, size is zero.");
|
|
||||||
|
|
||||||
(void) read (file, data, (unsigned long int) size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void file_write (int file, void * data, int size) {
|
|
||||||
fatal_failure (file == -1, "file_write: Failed to write to file, invalid descriptor.");
|
|
||||||
fatal_failure (data == NULL, "file_write: Failed to write to file, data is null pointer.");
|
|
||||||
fatal_failure (size == 0, "file_write: Failed to write to file, size is zero.");
|
|
||||||
|
|
||||||
(void) write (file, data, (unsigned long int) size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int file_seek (int file, int whence) {
|
|
||||||
fatal_failure (file == -1, "file_seek: Failed to seek in file, invalid descriptor.");
|
|
||||||
|
|
||||||
return ((int) lseek (file, 0, whence));
|
|
||||||
}
|
|
||||||
|
|
||||||
int file_size (int file) {
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
fatal_failure (file == -1, "file_size: Failed to get size of file, invalid descriptor.");
|
|
||||||
|
|
||||||
size = lseek (file, 0, SEEK_END);
|
|
||||||
(void) lseek (file, 0, SEEK_SET);
|
|
||||||
|
|
||||||
fatal_failure (size == -1, "file_size: Failed to get size of file, invalid file size.");
|
|
||||||
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void file_import (char * name, void * data) {
|
|
||||||
(void) name;
|
|
||||||
(void) data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void file_export (char * name, void * data) {
|
|
||||||
(void) name;
|
|
||||||
(void) data;
|
|
||||||
}
|
|
||||||
|
|
||||||
int character_is_uppercase (char character) {
|
int character_is_uppercase (char character) {
|
||||||
return ((int) ((character >= 'A') && (character <= 'Z')));
|
return ((int) ((character >= 'A') && (character <= 'Z')));
|
||||||
}
|
}
|
||||||
|
23
xtandard.h
23
xtandard.h
@ -37,6 +37,26 @@ enum {
|
|||||||
COLOUR_COUNT
|
COLOUR_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
FILE_TYPE_TEXT,
|
||||||
|
FILE_TYPE_COMMON_ASSEMBLY,
|
||||||
|
FILE_TYPE_FLAT_ASSEMBLY,
|
||||||
|
FILE_TYPE_GNU_ASSEMBLY,
|
||||||
|
FILE_TYPE_NETWIDE_ASSEMBLY,
|
||||||
|
FILE_TYPE_YET_ANOTHER_ASSEMBLY,
|
||||||
|
FILE_TYPE_C_SOURCE,
|
||||||
|
FILE_TYPE_C_HEADER,
|
||||||
|
FILE_TYPE_ADA_BODY,
|
||||||
|
FILE_TYPE_ADA_SPECIFICATION,
|
||||||
|
FILE_TYPE_CPP_SOURCE,
|
||||||
|
FILE_TYPE_CPP_HEADER,
|
||||||
|
FILE_TYPE_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char * program_name;
|
||||||
|
extern char * program_mode;
|
||||||
|
extern char * program_license;
|
||||||
|
|
||||||
extern int argument_count;
|
extern int argument_count;
|
||||||
extern char * * argument_nick;
|
extern char * * argument_nick;
|
||||||
extern char * * argument_name;
|
extern char * * argument_name;
|
||||||
@ -73,7 +93,8 @@ extern void file_read (int, void *, int);
|
|||||||
extern void file_write (int, void *, int);
|
extern void file_write (int, void *, int);
|
||||||
extern int file_seek (int, int);
|
extern int file_seek (int, int);
|
||||||
extern int file_size (int);
|
extern int file_size (int);
|
||||||
extern void file_import (char *, void *);
|
extern int file_type (char *);
|
||||||
|
extern char * file_import (char *);
|
||||||
extern void file_export (char *, void *);
|
extern void file_export (char *, void *);
|
||||||
|
|
||||||
extern void file_list_import (char *);
|
extern void file_list_import (char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user