mars_dosutils-0.10
This commit is contained in:
95
tools.c
95
tools.c
@@ -48,6 +48,31 @@ int ask_user(char *p, ...)
|
||||
return(flag);
|
||||
}
|
||||
|
||||
char *xmalloc(uint size)
|
||||
{
|
||||
char *p = (size) ? (char *)malloc(size) : (char*)NULL;
|
||||
if (p == (char *)NULL && size){
|
||||
fprintf(stderr, "not enough core, need %d Bytes\n", size);
|
||||
exit(1);
|
||||
}
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *xcmalloc(uint size)
|
||||
{
|
||||
char *p = xmalloc(size);
|
||||
if (size) memset(p, 0, size);
|
||||
return(p);
|
||||
}
|
||||
|
||||
void x_x_xfree(char **p)
|
||||
{
|
||||
if (*p != (char *)NULL){
|
||||
free(*p);
|
||||
*p = (char*)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int strmaxcpy(char *dest, char *source, int len)
|
||||
/* copied max. len chars + '\0' Byte */
|
||||
{
|
||||
@@ -69,6 +94,18 @@ char *xadd_char(char *s, int c, int maxlen)
|
||||
return(s);
|
||||
}
|
||||
|
||||
static uint8 down_char(uint8 ch)
|
||||
{
|
||||
if (ch > 64 && ch < 91) return(ch + 32);
|
||||
switch(ch){
|
||||
case 142: ch = 132; break;
|
||||
case 153: ch = 148; break;
|
||||
case 154: ch = 129; break;
|
||||
default :break;
|
||||
}
|
||||
return(ch);
|
||||
}
|
||||
|
||||
static uint8 up_char(uint8 ch)
|
||||
{
|
||||
if (ch > 96 && ch < 123) return(ch - 32);
|
||||
@@ -88,6 +125,64 @@ uint8 *upstr(uint8 *s)
|
||||
return(s);
|
||||
}
|
||||
|
||||
void deb(uint8 *s)
|
||||
{
|
||||
if (!s || !*s) return;
|
||||
else {
|
||||
uint8 *p = s + strlen(s);
|
||||
while (p > s && (*--p==32 || *p==9));;
|
||||
if (*p==32 || *p==9) *p='\0';
|
||||
else *(p+1) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void leb(uint8 *s)
|
||||
{
|
||||
if (!s || !*s || (*s != 32 && *s != 9)) return;
|
||||
else {
|
||||
uint8 *p = s;
|
||||
for (;*p && *p!=32 && *p!=9;p++);;
|
||||
strcpy(s, p);
|
||||
}
|
||||
}
|
||||
|
||||
void korrpath(char *s)
|
||||
{
|
||||
if (!s) return;
|
||||
for (;*s;s++) {
|
||||
if (*s=='\\') *s='/';
|
||||
else *s=down_char(*s);
|
||||
}
|
||||
}
|
||||
|
||||
void get_path_fn(char *s, char *p, char *fn)
|
||||
{
|
||||
int j= strlen(s);
|
||||
if (p != (char *)NULL) p[0] = 0;
|
||||
if (fn != (char*) NULL) fn[0] = 0;
|
||||
if (!j) return;
|
||||
if (s[0] == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0) ) ) {
|
||||
if (p != (char *)NULL) {
|
||||
strcpy(p, s);
|
||||
strcat(p, "/");
|
||||
}
|
||||
if (fn != (char *)NULL) fn[0] = 0;
|
||||
return;
|
||||
}
|
||||
while (j--){
|
||||
if ((s[j] == '/') || (s[j] == ':') ) {
|
||||
if (fn != (char *)NULL) strcpy(fn, s+j+1);
|
||||
if (p != (char *)NULL) {
|
||||
strncpy(p, s, j+1);
|
||||
p[j+1] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (fn != (char *)NULL) strcpy(fn, s); /* no path */
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16 adr1;
|
||||
uint16 adr2;
|
||||
|
||||
Reference in New Issue
Block a user