Added format function, work in progress...
This commit is contained in:
parent
2045f178cc
commit
b986bae5cf
53
xtandard.c
53
xtandard.c
@ -579,19 +579,7 @@ int character_count (char * string, char this, int from, int to, char stop) {
|
||||
for (count = 0; (from != to) && (string [from] != stop); from += (int) ((to < from) ? -1 : 1)) {
|
||||
count += (int) ((string [from] == this) || (this == '\0'));
|
||||
}
|
||||
/*
|
||||
if (to < from) {
|
||||
for (count = 0; (to < from) && (string [from] != stop); --from) {
|
||||
count += (int) ((string [from] == this) || (this == '\0'));
|
||||
}
|
||||
} else if (from < to) {
|
||||
for (count = 0; (from < to) && (string [from] != stop); ++from) {
|
||||
count += (int) ((string [from] == this) || (this == '\0'));
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
@ -912,4 +900,43 @@ char * number_to_string (int number) {
|
||||
return (string);
|
||||
}
|
||||
|
||||
char * format_to_string (int number, int sign, int base, int amount, char character) {
|
||||
int i;
|
||||
|
||||
static char string [32];
|
||||
|
||||
string_delete (string, 32);
|
||||
|
||||
if (number == 0) {
|
||||
string [0] = '0';
|
||||
string [1] = '\0';
|
||||
|
||||
string_realign (string, amount, character);
|
||||
|
||||
return (string);
|
||||
}
|
||||
|
||||
if (number < 0) {
|
||||
number *= -1;
|
||||
}
|
||||
|
||||
for (i = (string [0] == '-'); number != 0; ++i) {
|
||||
string [i] = "0123456789ABCDEF" [number % base];
|
||||
number /= base;
|
||||
}
|
||||
|
||||
if (sign != 0) {
|
||||
string [i] = '-';
|
||||
++i;
|
||||
}
|
||||
|
||||
string [i] = '\0';
|
||||
|
||||
string_reverse (string);
|
||||
|
||||
string_realign (string, amount, character);
|
||||
|
||||
return (string);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
28
xtandard.h
28
xtandard.h
@ -9,10 +9,16 @@ It is distributed in the hope that it will be useful or harmful, it really depen
|
||||
#ifndef XTANDARD_HEADER
|
||||
#define XTANDARD_HEADER
|
||||
|
||||
#define SIGNAL_CONTROL (0X100)
|
||||
#define SIGNAL_SHIFT (0X200)
|
||||
#define SIGNAL_ALTERNATE (0X400)
|
||||
#define SIGNAL_SYSTEM (0X800)
|
||||
#define SIGNAL_DELETE (0X7F)
|
||||
#define SIGNAL_ARROW_UP (0X415B1B)
|
||||
#define SIGNAL_ARROW_DOWN (0X425B1B)
|
||||
#define SIGNAL_ARROW_RIGHT (0X435B1B)
|
||||
#define SIGNAL_ARROW_LEFT (0X445B1B)
|
||||
|
||||
#define SIGNAL_CONTROL (0X1000000)
|
||||
#define SIGNAL_SHIFT (0X2000000)
|
||||
#define SIGNAL_ALTERNATE (0X4000000)
|
||||
#define SIGNAL_SYSTEM (0X8000000)
|
||||
|
||||
enum {
|
||||
LOG_SUCCESS, LOG_WARNING, LOG_FAILURE, LOG_COMMENT,
|
||||
@ -37,6 +43,18 @@ enum {
|
||||
};
|
||||
|
||||
enum {
|
||||
CHARACTER_NULL, CHARACTER_START_HEADER, CHARACTER_START_TEXT, CHARACTER_END_TEXT,
|
||||
CHARACTER_END_TRANSMISSION, CHARACTER_ENQUIRY, CHARACTER_ACKNOWLEDGE, CHARACTER_BELL,
|
||||
CHARACTER_BACKSPACE, CHARACTER_TAB_HORIZONTAL, CHARACTER_LINE_FEED, CHARACTER_TAB_VERTICAL,
|
||||
CHARACTER_FORM_FEED, CHARACTER_CARRIAGE_RETURN, CHARACTER_SHIFT_OUT, CHARACTER_SHIFT_IN,
|
||||
CHARACTER_DATA_LINK_ESCAPE, CHARACTER_DEVICE_CONTROL_1, CHARACTER_DEVICE_CONTROL_2, CHARACTER_DEVICE_CONTROL_3,
|
||||
CHARACTER_DEVICE_CONTROL_4, CHARACTER_NOT_ACKNOWLEDGE, CHARACTER_SYNCHRONOUS_IDLE, CHARACTER_END_TRANSMISSION_BLOCK,
|
||||
CHARACTER_CANCEL, CHARACTER_END_MEDIUM, CHARACTER_SUBSTITUTE, CHARACTER_ESCAPE,
|
||||
CHARACTER_FILE_SEPARATOR, CHARACTER_GROUP_SEPARATOR, CHARACTER_RECORD_SEPARATOR, CHARACTER_UNIT_SEPARATOR,
|
||||
CHARACTER_COUNT
|
||||
};
|
||||
|
||||
enum {
|
||||
SIGNAL_NONE,
|
||||
SIGNAL_ANY,
|
||||
SIGNAL_A, SIGNAL_B, SIGNAL_C, SIGNAL_D, SIGNAL_E, SIGNAL_F, SIGNAL_G, SIGNAL_H,
|
||||
@ -142,4 +160,6 @@ extern char * decode_byte (int byte);
|
||||
|
||||
extern char * number_to_string (int number);
|
||||
|
||||
extern char * format_to_string (int number, int sign, int base, int amount, char character);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user