From 3e68853ae610fc18071d233ec2359c12a1c73b59 Mon Sep 17 00:00:00 2001 From: Albom Date: Thu, 23 Jan 2014 07:41:40 +0000 Subject: [PATCH] Shell 0.7.4. Clipboard works. Ctrl+C copies the whole command line and Ctrl+V pastes it. git-svn-id: svn://kolibrios.org@4516 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/shell/History.txt | 4 + programs/system/shell/globals.h | 2 +- .../system/shell/modules/module_command.c | 89 ++++++++++++++++--- programs/system/shell/system/kolibri.c | 15 ++++ programs/system/shell/system/kolibri.h | 3 + 5 files changed, 99 insertions(+), 14 deletions(-) diff --git a/programs/system/shell/History.txt b/programs/system/shell/History.txt index 82997e9956..5de7b9b571 100644 --- a/programs/system/shell/History.txt +++ b/programs/system/shell/History.txt @@ -1,3 +1,7 @@ +Shell 0.7.4 // 23.01.2014 // Albom +* Работа с буфером обмена (копирование Ctrl+C и вставка Ctrl+V строки целиком) + + Shell 0.7.3 // 28.11.2013 // Albom * Исправлена ошибка с символом % в истории команд diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index 4b2dd4368d..0ff62c6635 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -1,5 +1,5 @@ -#define SHELL_VERSION "0.7.3" +#define SHELL_VERSION "0.7.4" extern char PATH[256]; extern char PARAM[256]; diff --git a/programs/system/shell/modules/module_command.c b/programs/system/shell/modules/module_command.c index 2be66ba772..d50f0d49d6 100644 --- a/programs/system/shell/modules/module_command.c +++ b/programs/system/shell/modules/module_command.c @@ -35,6 +35,10 @@ unsigned cmdLen = 0; unsigned cmdPos = 0; CMD[0] = '\0'; +int clipNum; // number of clipboard slots +char* clipBuf; // clipboard buffer +char clipCopy[255+12]; + for (;;) { key = getch(); @@ -85,8 +89,67 @@ for (;;) case 9: // TAB break; + + + case 22: // Ctrl+V + clipNum = kol_clip_num(); + if (clipNum > 0) + { + clipBuf = kol_clip_get(clipNum-1); +// printf("Length: %d, Type: %d, Encoding: %d\n", (int) *clipBuf, (int)*(clipBuf+4), (int)*(clipBuf+8)); + if ( (int) *clipBuf > 0 ) // is clipboard empty? + { + if ((int)*(clipBuf+4)==0) // text? + { + if ((int)*(clipBuf+8)==1) // 866 encoding? + for (i = cmdPos; i < cmdLen; i++) + printf(" "); + for (i = cmdLen; i > 0; i--) + printf("%c %c", 8, 8); + cmdLen = 0; + cmdPos = 0; + CMD[0] = '\0'; + // strcpy_n + for (i = 0; i < 255; i++) + { + CMD[i]=*(clipBuf+12+i); + if (CMD[i]=='\0') + break; + } + + cmdPos = cmdLen = strlen(CMD); +/* + printf("Length: %d\n", cmdLen); + for (i = 0; i < cmdLen; i++) + printf("%d ", CMD[i]); +*/ + printf("%s", CMD); + + } + } + } + break; + + + case 3: // Ctrl+C + if ( cmdLen > 0 ) + { + + *clipCopy = 12 + cmdLen; + *(clipCopy+4)=0; + *(clipCopy+8)=1; + + for (i = 0; i <= cmdLen; i++) + *(clipCopy+12+i) = CMD[i]; + + kol_clip_set(12+cmdLen, clipCopy); + + } + break; + + default: if (cmdLen < 255) { @@ -96,31 +159,31 @@ for (;;) else key = toupper(key); - for (i = cmdLen+1; i > cmdPos; i--) - CMD[i] = CMD[i-1]; + for (i = cmdLen+1; i > cmdPos; i--) + CMD[i] = CMD[i-1]; CMD[cmdPos] = key; - for (i = cmdPos; i > 0; i--) - printf("%c %c", 8, 8); + for (i = cmdPos; i > 0; i--) + printf("%c %c", 8, 8); printf("%s", CMD); - for (i = 0; i < cmdLen-cmdPos; i++) - printf("%c", 8); + for (i = 0; i < cmdLen-cmdPos; i++) + printf("%c", 8); cmdPos++; - cmdLen++; + cmdLen++; } break; - } - } - else - { - key = (key>>8)&0xff; - switch (key) + } + } + else { + key = (key>>8)&0xff; + switch (key) + { case 83: // Del if (cmdPos < cmdLen) { diff --git a/programs/system/shell/system/kolibri.c b/programs/system/shell/system/kolibri.c index 9e0f52a1e9..31753d7bbb 100644 --- a/programs/system/shell/system/kolibri.c +++ b/programs/system/shell/system/kolibri.c @@ -421,3 +421,18 @@ void kol_buffer_close(char name[]) { asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name)); } + +int kol_clip_num() +{ +asm volatile ("int $0x40"::"a"(54), "b"(0)); +} + +char* kol_clip_get(int n) +{ +asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n)); +} + +int kol_clip_set(int n, char buffer[]) +{ +asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer)); +} diff --git a/programs/system/shell/system/kolibri.h b/programs/system/shell/system/kolibri.h index c7623c9fb3..a3069834e4 100644 --- a/programs/system/shell/system/kolibri.h +++ b/programs/system/shell/system/kolibri.h @@ -111,3 +111,6 @@ void kol_get_kernel_ver(char buff16b[]); int kol_kill_process(unsigned process); int kol_buffer_open(char name[], int mode, int size, char **buf); void kol_buffer_close(char name[]); +int kol_clip_num(); +char* kol_clip_get(int n); +int kol_clip_set(int n, char buffer[]);