forked from KolibriOS/kolibrios
kolibri-libc:
- Added shell apis(shell_api.h) - Added functions for working with a named shared memory area(ksys.h). - Fixed itoa git-svn-id: svn://kolibrios.org@8629 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7d923337f0
commit
781f3f0fab
@ -1,18 +1,22 @@
|
|||||||
KGCC = ../linuxtools/kgcc
|
KGCC = ../linuxtools/kgcc
|
||||||
KLD = ../linuxtools/kld
|
KLD = ../linuxtools/kld
|
||||||
KPACK = kpack
|
KPACK = kpack
|
||||||
KTCC=../../../programs/develop/ktcc/trunk/bin/kos32-tcc
|
KTCC=../../../programs/develop/ktcc/trunk/bin/kos32-tcc
|
||||||
KTCC_FLAGS = -nostdlib -I$(KLIBC)/source/include -L$(KLIBC)/lib $(KLIBC)/lib/crt0.o
|
KTCC_FLAGS = -nostdlib -stack=1048576 -I$(KLIBC)/source/include -L$(KLIBC)/lib $(KLIBC)/lib/crt0.o
|
||||||
|
|
||||||
|
ifndef NAME
|
||||||
|
NAME = basic_gui
|
||||||
|
endif
|
||||||
|
|
||||||
static_kgcc:
|
static_kgcc:
|
||||||
$(KGCC) basic_gui.c
|
$(KGCC) $(NAME).c
|
||||||
$(KLD) basic_gui.o -o basic_gui -lc
|
$(KLD) $(NAME).o -o $(NAME) -lc
|
||||||
$(KPACK) basic_gui
|
$(KPACK) $(NAME)
|
||||||
|
|
||||||
static_tcc:
|
static_tcc:
|
||||||
$(KTCC) $(KTCC_FLAGS) basic_gui.c -o basic_gui -lc
|
$(KTCC) $(KTCC_FLAGS) $(NAME).c -o $(NAME) -lc
|
||||||
$(KPACK) basic_gui
|
$(KPACK) $(NAME)
|
||||||
|
|
||||||
dynamic_tcc:
|
dynamic_tcc:
|
||||||
$(KTCC) $(KTCC_FLAGS) -D_DYNAMIC basic_gui.c -o basic_gui_dyn -lc.obj
|
$(KTCC) $(KTCC_FLAGS) -D_DYNAMIC $(NAME).c -o $(NAME)_dyn -lc.obj
|
||||||
$(KPACK) basic_gui_dyn
|
$(KPACK) $(NAME)_dyn
|
||||||
|
19
contrib/kolibri-libc/samples/shell_io.c
Normal file
19
contrib/kolibri-libc/samples/shell_io.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <shell_api.h>
|
||||||
|
#include <ksys.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char string[256];
|
||||||
|
shell_cls();
|
||||||
|
shell_puts("This is a test console application for Shell\n\r");
|
||||||
|
shell_puts("Type a string (255 symbols max): ");
|
||||||
|
shell_gets(string);
|
||||||
|
shell_puts("You typed:\n\r");
|
||||||
|
shell_puts(string);
|
||||||
|
shell_puts("Press any key: ");
|
||||||
|
string[0] = shell_getc();
|
||||||
|
shell_puts("\n\rYou pressed: ");
|
||||||
|
shell_putc(string[0]);
|
||||||
|
shell_exit();
|
||||||
|
}
|
@ -9,7 +9,7 @@ LIBC.A = $(LIB_DIR)/libc.a
|
|||||||
LIBC.OBJ = $(LIB_DIR)/libc.obj
|
LIBC.OBJ = $(LIB_DIR)/libc.obj
|
||||||
|
|
||||||
CFLAGS = -I$(INCLUDE) -m32 -nostdinc -nostdlib -DGNUC -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie
|
CFLAGS = -I$(INCLUDE) -m32 -nostdinc -nostdlib -DGNUC -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie
|
||||||
DIRS := string stdlib stdio sys math ctype exports setjmp
|
DIRS := string stdlib stdio sys math ctype exports setjmp shell_api
|
||||||
|
|
||||||
cfiles := $(foreach dir,$(DIRS),$(patsubst %.c, %.o, $(wildcard $(dir)/*.c)))
|
cfiles := $(foreach dir,$(DIRS),$(patsubst %.c, %.o, $(wildcard $(dir)/*.c)))
|
||||||
asmfiles := $(foreach dir,$(DIRS),$(patsubst %.s, %.o, $(wildcard $(dir)/*.s)))
|
asmfiles := $(foreach dir,$(DIRS),$(patsubst %.s, %.o, $(wildcard $(dir)/*.s)))
|
||||||
@ -47,7 +47,7 @@ clean:
|
|||||||
|
|
||||||
shared: $(cfiles) $(asmfiles)
|
shared: $(cfiles) $(asmfiles)
|
||||||
$(CLINK) $^
|
$(CLINK) $^
|
||||||
$(KPACK) a.out.obj
|
#$(KPACK) a.out.obj
|
||||||
mv a.out.obj $(LIBC.OBJ)
|
mv a.out.obj $(LIBC.OBJ)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
@ -189,15 +189,19 @@ enum KSYS_MOUSE_POS{
|
|||||||
KSYS_MOUSE_WINDOW_POS = 1
|
KSYS_MOUSE_WINDOW_POS = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum KSYS_SHM_MODE{
|
||||||
|
KSYS_SHM_OPEN = 0x00,
|
||||||
|
KSYS_SHM_OPEN_ALWAYS = 0x04,
|
||||||
|
KSYS_SHM_CREATE = 0x08,
|
||||||
|
KSYS_SHM_READ = 0x00,
|
||||||
|
KSYS_SHM_WRITE = 0x01,
|
||||||
|
};
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
int _ksys_strcmp(const char * s1, const char * s2 )
|
int _ksys_strcmp(const char * s1, const char * s2 )
|
||||||
{
|
{
|
||||||
while ((*s1) && (*s1 == *s2)){
|
while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; }
|
||||||
++s1;
|
return(*(unsigned char*)s1 - *(unsigned char *)s2);
|
||||||
++s2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions for working with the graphical interface
|
// Functions for working with the graphical interface
|
||||||
@ -360,6 +364,7 @@ ksys_pos_t _ksys_get_mouse_pos(int origin)
|
|||||||
"rol $16, %%eax"
|
"rol $16, %%eax"
|
||||||
:"=a"(val)
|
:"=a"(val)
|
||||||
:"a"(37),"b"(origin)
|
:"a"(37),"b"(origin)
|
||||||
|
:"memory"
|
||||||
);
|
);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -918,7 +923,8 @@ int not_optimized _ksys_file_rename(const char *name, const char *new_name)
|
|||||||
|
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
int not_optimized _ksys_exec(char *app_name, char *args){
|
int not_optimized _ksys_exec(char *app_name, char *args)
|
||||||
|
{
|
||||||
ksys70_t file_op;
|
ksys70_t file_op;
|
||||||
file_op.p00 = 7;
|
file_op.p00 = 7;
|
||||||
file_op.p04dw = 0;
|
file_op.p04dw = 0;
|
||||||
@ -933,4 +939,28 @@ int not_optimized _ksys_exec(char *app_name, char *args){
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Working with a named shared memory area. */
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int _ksys_shm_open(char *name, int mode, int size, char **new_shm)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40"
|
||||||
|
:"=a"(*new_shm), "=d"(error)
|
||||||
|
:"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)
|
||||||
|
);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void _ksys_shm_close(char *shm_name)
|
||||||
|
{
|
||||||
|
asm_inline(
|
||||||
|
"int $0x40":
|
||||||
|
:"a"(68), "b"(23), "c"(shm_name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _KSYS_H_
|
#endif // _KSYS_H_
|
13
contrib/kolibri-libc/source/include/shell_api.h
Normal file
13
contrib/kolibri-libc/source/include/shell_api.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef _SHELL_API_H_
|
||||||
|
#define _SHELL_API_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
extern void _FUNC(shell_puts)(const char *s);
|
||||||
|
extern void _FUNC(shell_putc)(char c);
|
||||||
|
extern char _FUNC(shell_getc)();
|
||||||
|
extern void _FUNC(shell_gets)(char *str);
|
||||||
|
extern void _FUNC(shell_cls)();
|
||||||
|
extern void _FUNC(shell_exit)();
|
||||||
|
|
||||||
|
#endif
|
@ -14,7 +14,7 @@
|
|||||||
extern int _FUNC(atoi)(const char *s);
|
extern int _FUNC(atoi)(const char *s);
|
||||||
extern long _FUNC(atol)(const char *);
|
extern long _FUNC(atol)(const char *);
|
||||||
extern long long _FUNC(atoll)(const char *);
|
extern long long _FUNC(atoll)(const char *);
|
||||||
//char* itoa)(int n, char* s);
|
extern void _FUNC(itoa)(int n, char* s);
|
||||||
|
|
||||||
extern int _FUNC(abs)(int);
|
extern int _FUNC(abs)(int);
|
||||||
extern long _FUNC(labs)(long);
|
extern long _FUNC(labs)(long);
|
||||||
|
21
contrib/kolibri-libc/source/shell_api/shell.h
Normal file
21
contrib/kolibri-libc/source/shell_api/shell.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
#include <ksys.h>
|
||||||
|
|
||||||
|
#define SHELL_OK 0
|
||||||
|
#define SHELL_EXIT 1
|
||||||
|
#define SHELL_PUTC 2
|
||||||
|
#define SHELL_PUTS 3
|
||||||
|
#define SHELL_GETC 4
|
||||||
|
#define SHELL_GETS 5
|
||||||
|
#define SHELL_CLS 6
|
||||||
|
|
||||||
|
extern char __shell_shm_name[32];
|
||||||
|
extern char *__shell_shm;
|
||||||
|
extern int __shell_is_init;
|
||||||
|
extern int __shell_init();
|
||||||
|
extern void __shell_wait();
|
||||||
|
|
||||||
|
#define SHELL_WAIT() while (*__shell_shm) _ksys_delay(5)
|
||||||
|
|
||||||
|
|
||||||
|
|
8
contrib/kolibri-libc/source/shell_api/shell_cls.c
Normal file
8
contrib/kolibri-libc/source/shell_api/shell_cls.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
|
||||||
|
void shell_cls()
|
||||||
|
{
|
||||||
|
__shell_init();
|
||||||
|
*__shell_shm = SHELL_CLS;
|
||||||
|
SHELL_WAIT();
|
||||||
|
}
|
11
contrib/kolibri-libc/source/shell_api/shell_exit.c
Normal file
11
contrib/kolibri-libc/source/shell_api/shell_exit.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
#include "ksys.h"
|
||||||
|
|
||||||
|
void shell_exit()
|
||||||
|
{
|
||||||
|
if(__shell_is_init){
|
||||||
|
*__shell_shm = SHELL_EXIT;
|
||||||
|
SHELL_WAIT();
|
||||||
|
_ksys_shm_close(__shell_shm_name);
|
||||||
|
}
|
||||||
|
}
|
9
contrib/kolibri-libc/source/shell_api/shell_getc.c
Normal file
9
contrib/kolibri-libc/source/shell_api/shell_getc.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
|
||||||
|
char shell_getc()
|
||||||
|
{
|
||||||
|
__shell_init();
|
||||||
|
*__shell_shm = SHELL_GETC;
|
||||||
|
SHELL_WAIT();
|
||||||
|
return *(__shell_shm+1);
|
||||||
|
}
|
9
contrib/kolibri-libc/source/shell_api/shell_gets.c
Normal file
9
contrib/kolibri-libc/source/shell_api/shell_gets.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
|
||||||
|
void shell_gets(char *str)
|
||||||
|
{
|
||||||
|
__shell_init();
|
||||||
|
*__shell_shm = SHELL_GETS;
|
||||||
|
SHELL_WAIT();
|
||||||
|
strcpy(str, __shell_shm+1);
|
||||||
|
}
|
37
contrib/kolibri-libc/source/shell_api/shell_init.c
Normal file
37
contrib/kolibri-libc/source/shell_api/shell_init.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <ksys.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char __shell_shm_name[32];
|
||||||
|
char*__shell_shm=NULL;
|
||||||
|
int __shell_is_init=0;
|
||||||
|
|
||||||
|
int __shell_shm_init()
|
||||||
|
{
|
||||||
|
__shell_is_init=1;
|
||||||
|
ksys_proc_table_t *proc_info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t));
|
||||||
|
if(proc_info == NULL){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
unsigned PID;
|
||||||
|
|
||||||
|
_ksys_process_info(proc_info, -1);
|
||||||
|
PID = proc_info->pid;
|
||||||
|
free(proc_info);
|
||||||
|
|
||||||
|
itoa(PID, __shell_shm_name);
|
||||||
|
strcat(__shell_shm_name, "-SHELL");
|
||||||
|
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, 1024*16, &__shell_shm);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __shell_init()
|
||||||
|
{
|
||||||
|
if(__shell_is_init){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(__shell_shm_init()){
|
||||||
|
debug_printf("Shell problems detected!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
9
contrib/kolibri-libc/source/shell_api/shell_putc.c
Normal file
9
contrib/kolibri-libc/source/shell_api/shell_putc.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
|
||||||
|
void shell_putc(char c)
|
||||||
|
{
|
||||||
|
__shell_init();
|
||||||
|
*__shell_shm = SHELL_PUTC;
|
||||||
|
*(__shell_shm+1) = c;
|
||||||
|
SHELL_WAIT();
|
||||||
|
}
|
10
contrib/kolibri-libc/source/shell_api/shell_puts.c
Normal file
10
contrib/kolibri-libc/source/shell_api/shell_puts.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "shell.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
void shell_puts(const char *str)
|
||||||
|
{
|
||||||
|
__shell_init();
|
||||||
|
*__shell_shm = SHELL_PUTS;
|
||||||
|
strcpy(__shell_shm+1, str);
|
||||||
|
SHELL_WAIT();
|
||||||
|
}
|
@ -1,20 +1,42 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
/*
|
#include <ksys.h>
|
||||||
char* itoa(int n, char* s)
|
|
||||||
|
char *__reverse(char *str)
|
||||||
{
|
{
|
||||||
int sign;
|
char tmp, *src, *dst;
|
||||||
char *ptr;
|
size_t len;
|
||||||
ptr = s;
|
if (str != NULL){
|
||||||
|
len = strlen (str);
|
||||||
if(n == (int)0x80000000)
|
if (len > 1) {
|
||||||
return strcpy(s, "-2147483648"); // overflowed -n
|
src = str;
|
||||||
|
dst = src + len - 1;
|
||||||
if ((sign = n) < 0) n = -n;
|
while (src < dst) {
|
||||||
do {
|
tmp = *src;
|
||||||
*ptr++ = n % 10 + '0';
|
*src++ = *dst;
|
||||||
} while ((n = n / 10) > 0);
|
*dst-- = tmp;
|
||||||
if (sign < 0) *ptr++ = '-';
|
}
|
||||||
*ptr = '\0';
|
}
|
||||||
return strrev(s);
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
/* itoa from K&R */
|
||||||
|
void itoa(int n, char s[])
|
||||||
|
{
|
||||||
|
int i, sign;
|
||||||
|
|
||||||
|
if ((sign = n) < 0) /* record sign */
|
||||||
|
n = -n; /* make n positive */
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
do { /* generate digits in reverse order */
|
||||||
|
s[i++] = n % 10 + '0'; /* get next digit */
|
||||||
|
} while ((n /= 10) > 0); /* delete it */
|
||||||
|
|
||||||
|
if (sign < 0)
|
||||||
|
s[i++] = '-';
|
||||||
|
|
||||||
|
__reverse(s);
|
||||||
|
s[i] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user