Added libshell for TCC
git-svn-id: svn://kolibrios.org@9207 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8918a376d9
commit
d38b3890d2
BIN
programs/develop/ktcc/trunk/bin/lib/libshell.a
Normal file
BIN
programs/develop/ktcc/trunk/bin/lib/libshell.a
Normal file
Binary file not shown.
26
programs/develop/ktcc/trunk/lib/libshell/Makefile
Normal file
26
programs/develop/ktcc/trunk/lib/libshell/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
CC = kos32-tcc
|
||||
AR = ar
|
||||
CFLAGS = -c -I../../libc.obj/include
|
||||
|
||||
LIB = libshell.a
|
||||
|
||||
OBJS = \
|
||||
shell_exit.o \
|
||||
shell_puts.o \
|
||||
shell_get_pid.o \
|
||||
shell_ping.o \
|
||||
shell_getc.o \
|
||||
shell_cls.o \
|
||||
shell_init.o \
|
||||
shell_gets.o \
|
||||
shell_printf.o \
|
||||
shell_putc.o
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
$(AR) -crs $@ $(OBJS)
|
||||
|
||||
%.o : %.c Makefile
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS) $(LIB)
|
@ -0,0 +1 @@
|
||||
-I../../libc.obj/include
|
8
programs/develop/ktcc/trunk/lib/libshell/shell_cls.c
Normal file
8
programs/develop/ktcc/trunk/lib/libshell/shell_cls.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <shell_api.h>
|
||||
|
||||
void shell_cls()
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_CLS;
|
||||
__SHELL_WAIT();
|
||||
}
|
11
programs/develop/ktcc/trunk/lib/libshell/shell_exit.c
Normal file
11
programs/develop/ktcc/trunk/lib/libshell/shell_exit.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <shell_api.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
void shell_exit()
|
||||
{
|
||||
if(__shell_is_init){
|
||||
*__shell_shm = SHELL_EXIT;
|
||||
__SHELL_WAIT();
|
||||
_ksys_shm_close(__shell_shm_name);
|
||||
}
|
||||
}
|
12
programs/develop/ktcc/trunk/lib/libshell/shell_get_pid.c
Normal file
12
programs/develop/ktcc/trunk/lib/libshell/shell_get_pid.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <shell_api.h>
|
||||
#include <string.h>
|
||||
|
||||
unsigned shell_get_pid()
|
||||
{
|
||||
unsigned pid;
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PID;
|
||||
__SHELL_WAIT();
|
||||
memcpy(&pid, __shell_shm+1, sizeof(unsigned));
|
||||
return pid;
|
||||
}
|
9
programs/develop/ktcc/trunk/lib/libshell/shell_getc.c
Normal file
9
programs/develop/ktcc/trunk/lib/libshell/shell_getc.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include "shell_api.h"
|
||||
|
||||
char shell_getc()
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_GETC;
|
||||
__SHELL_WAIT();
|
||||
return *(__shell_shm+1);
|
||||
}
|
10
programs/develop/ktcc/trunk/lib/libshell/shell_gets.c
Normal file
10
programs/develop/ktcc/trunk/lib/libshell/shell_gets.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <shell_api.h>
|
||||
#include <string.h>
|
||||
|
||||
void shell_gets(char *str, int n)
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_GETS;
|
||||
__SHELL_WAIT();
|
||||
strncpy(str, __shell_shm+1, n);
|
||||
}
|
44
programs/develop/ktcc/trunk/lib/libshell/shell_init.c
Normal file
44
programs/develop/ktcc/trunk/lib/libshell/shell_init.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <sys/ksys.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <shell_api.h>
|
||||
|
||||
char app_name[13];
|
||||
char __shell_shm_name[32];
|
||||
char*__shell_shm=NULL;
|
||||
int __shell_is_init=0;
|
||||
|
||||
int __shell_shm_init()
|
||||
{
|
||||
__shell_is_init=1;
|
||||
ksys_thread_t *proc_info = (ksys_thread_t*)malloc(sizeof(ksys_thread_t));
|
||||
if(proc_info == NULL){
|
||||
return -1;
|
||||
}
|
||||
unsigned PID;
|
||||
|
||||
_ksys_thread_info(proc_info, -1);
|
||||
PID = proc_info->pid;
|
||||
strncpy(app_name, proc_info->name, 12);
|
||||
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, SHELL_SHM_MAX, &__shell_shm);
|
||||
}
|
||||
|
||||
void __shell_init()
|
||||
{
|
||||
if(!__shell_is_init){
|
||||
if(__shell_shm_init()){
|
||||
debug_printf("%s: shell problems detected!\n", app_name);
|
||||
_ksys_exit();
|
||||
}
|
||||
|
||||
if(!shell_ping()){
|
||||
debug_printf("%s: no shell found!\n", app_name);
|
||||
_ksys_exit();
|
||||
}
|
||||
}
|
||||
}
|
13
programs/develop/ktcc/trunk/lib/libshell/shell_ping.c
Normal file
13
programs/develop/ktcc/trunk/lib/libshell/shell_ping.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <shell_api.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
int shell_ping()
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PING;
|
||||
_ksys_delay(10);
|
||||
if(*__shell_shm==SHELL_OK){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
12
programs/develop/ktcc/trunk/lib/libshell/shell_printf.c
Normal file
12
programs/develop/ktcc/trunk/lib/libshell/shell_printf.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <shell_api.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void shell_printf(const char *format,...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
*__shell_shm=SHELL_PUTS;
|
||||
vsnprintf(__shell_shm+1, SHELL_SHM_MAX, format, ap);
|
||||
va_end(ap);
|
||||
__SHELL_WAIT();
|
||||
}
|
9
programs/develop/ktcc/trunk/lib/libshell/shell_putc.c
Normal file
9
programs/develop/ktcc/trunk/lib/libshell/shell_putc.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <shell_api.h>
|
||||
|
||||
void shell_putc(char c)
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PUTC;
|
||||
*(__shell_shm+1) = c;
|
||||
__SHELL_WAIT();
|
||||
}
|
10
programs/develop/ktcc/trunk/lib/libshell/shell_puts.c
Normal file
10
programs/develop/ktcc/trunk/lib/libshell/shell_puts.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <shell_api.h>
|
||||
#include <string.h>
|
||||
|
||||
void shell_puts(const char *str)
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PUTS;
|
||||
strcpy(__shell_shm+1, str);
|
||||
__SHELL_WAIT();
|
||||
}
|
37
programs/develop/ktcc/trunk/libc.obj/include/shell_api.h
Normal file
37
programs/develop/ktcc/trunk/libc.obj/include/shell_api.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef _SHELL_API_H_
|
||||
#define _SHELL_API_H_
|
||||
|
||||
#include <sys/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
|
||||
#define SHELL_PID 7
|
||||
#define SHELL_PING 8
|
||||
|
||||
#define SHELL_SHM_MAX 1024*16
|
||||
|
||||
extern char __shell_shm_name[32];
|
||||
extern char *__shell_shm;
|
||||
extern int __shell_is_init;
|
||||
extern void __shell_init();
|
||||
|
||||
#define __SHELL_WAIT() while (*__shell_shm) _ksys_delay(5)
|
||||
|
||||
extern int shell_ping();
|
||||
extern unsigned shell_get_pid();
|
||||
extern void shell_exit();
|
||||
|
||||
extern char shell_getc();
|
||||
extern void shell_gets(char *str, int n);
|
||||
|
||||
extern void shell_putc(char c);
|
||||
extern void shell_puts(const char *str);
|
||||
extern void shell_printf(const char *format,...);
|
||||
|
||||
extern void shell_cls();
|
||||
#endif
|
@ -1,4 +1,3 @@
|
||||
|
||||
KTCC=kos32-tcc
|
||||
FASM= fasm
|
||||
KPACK = kpack
|
||||
@ -22,9 +21,10 @@ clayer/dialog.kex \
|
||||
clayer/msgbox.kex \
|
||||
clayer/boxlib.kex \
|
||||
thread_work.kex \
|
||||
sdltest.kex
|
||||
sdltest.kex \
|
||||
shell_test.kex
|
||||
|
||||
LIBS= -lSDL -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj
|
||||
LIBS= -lSDL -lshell -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
|
@ -18,3 +18,4 @@ cp /kolibrios/develop/tcc/samples/clayer/logo.png /tmp0/1/tcc_samples/logo.png
|
||||
/kolibrios/develop/tcc/tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj
|
||||
/kolibrios/develop/tcc/tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj
|
||||
/kolibrios/develop/tcc/tcc -I/kolibrios/develop/tcc/include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj
|
||||
/kolibrios/develop/tcc/tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell -ltcc -lc.obj
|
||||
|
20
programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c
Normal file
20
programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include "../include/shell_api.h"
|
||||
|
||||
char string[256];
|
||||
|
||||
int main(){
|
||||
shell_cls();
|
||||
shell_printf("SHELL PID=%d\n\r", shell_get_pid());
|
||||
|
||||
shell_puts("This is a test console application for Shell\n\r");
|
||||
shell_puts("Type a string (255 symbols max): ");
|
||||
|
||||
shell_gets(string, 255);
|
||||
shell_printf("You typed: %s\n\r", string);
|
||||
|
||||
shell_puts("Press any key: ");
|
||||
string[0] = shell_getc();
|
||||
shell_printf("\n\rYou pressed: %c", string[0]);
|
||||
shell_exit();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user