SHELL 0.8.2

- big refactoring, now uses libc.obj
- added kfetch command

git-svn-id: svn://kolibrios.org@8827 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad) 2021-06-12 21:34:41 +00:00
parent 112c948922
commit 68cf3e4293
59 changed files with 1617 additions and 2317 deletions

View File

@ -1,17 +0,0 @@
all:
fasm start.asm start.o
kos32-gcc -c -fno-builtin shell.c
kos32-gcc -c -fno-builtin system/kolibri.c
kos32-gcc -c -fno-builtin system/stdlib.c
kos32-gcc -c -fno-builtin system/string.c
kos32-gcc -c -fno-builtin system/ctype.c
kos32-ld -nostdlib -T kolibri.ld -o shell start.o kolibri.o stdlib.o string.o ctype.o shell.o
kos32-objcopy shell -O binary
clean:
rm -f *.o
rm -f bin/rus/shell
rm -f bin/eng/shell
install:
cp shell $(DIR)

View File

@ -1,228 +1,267 @@
Shell 0.8.2 // 13.06.2021 // rgimad
* use libj.obj instead of built-in "libc"
* big refactoring:
- fix indentation
- string constants moved to locale/.../globals.h files
* add new command - kfetch
it is like neofetch for KolibriOS
prints logo and main system information.
* other fixes
Shell 0.8.1 // 14.04.2020 - 01.04.2021 // rgimad, turbocat, Kenshin
rgimad:
* fixed bug with ctrl+v
* added navigation in current string by Home, End
* directory highlighting in ls command output
* Now for incorrect scripts (which doesnt start with #SHS) shell says
that they are incorrect, not "File not found".
Also, translated comments from russian to english in two files.
* added mv command
* added ren command
* now ls works also with relative pathes
* fixed bug in strrchr
* fixed bug with cd ../
* fixed cd . and cd ./ behavior
* added output redirection to file (> >>) for echo command
e.g. echo "<html>">123.txt ; echo a b c >> y.txt
turbocat:
* Added new API: SC_GET_PID
* Fixed data type pid - unsigned int.
* Fixed cmd_ps output pid;
* Added new SC_PING api
* Renamed from SC_GET_PID to SC_PID
* added pkill command
Kenshin:
* shell.inc now suports sc_ping & sc_pid functions
* update docs
Shell 0.7.7 // 06.02.2017 // Leency
* help ⥯¥àì ¢ë¢®¤¨â ᯨ᮪ ª®¬¬ ­¤ ¢ âਠª®«®­ª¨
* ps ⥯¥àì ¢ë¢®¤¨â à §¬¥à Ž‡“, ¨á¯®«ì§ã¥¬ë© ¯à®æ¥áᮬ
* ls ⥯¥àì ¢ë¢®¤¨â ¢á¥ ä ©«ë ­¥ ¢ ®¤­ã,   ¢ ­¥áª®«ìª® ª®«®­®ª
à §¬¥à ª®«®­®ª à áç¨â뢠¥âáï ¨áå®¤ï ¨§ á ¬®£® ¤«¨­­®£® ¨¬¥­¨ ä ©«  ¢ ¯ ¯ª¥
áâ àë© ¢ë¢®¤ ᯨ᪮¬ ¯® ¯à¥¦­¥¬ã ¤®áâ㯥­ ç¥à¥§ ª«îç '-1'
* help теперь выводит список комманд в три колонки
* ps теперь выводит размер ОЗУ, используемый процессом
* ls теперь выводит все файлы не в одну, а в несколько колонок
размер колонок расчитывается исходя из самого длинного имени файла в папке
старый вывод списком по прежнему доступен через ключ '-1'
Shell 0.7.6 // 06.02.2017 // Siemargl
* ” ©«®¢ë¥ ®¯¥à æ¨¨ ¨á¯®«ì§ãîâ 64-bit à §¬¥àë ä ©«®¢.
cp <file> <dest> ⥯¥àì ¯®­¨¬ ¥â, ¥á«¨ <dest> - ª â «®£
cp ¨á¯®«ì§ã¥â ¡ãä¥à 1Œ¡, ¨«¨ ­¥ ¡®«¥¥ ¯®«®¢¨­ë ᢮¡®¤­®© ¯ ¬ïâ¨
* Файловые операции используют 64-bit размеры файлов.
cp <file> <dest> теперь понимает, если <dest> - каталог
cp использует буфер 1Мб, или не более половины свободной памяти
Shell 0.7.5 // 06.01.2017 // Siemargl
* Œ¥«ª¨¥ ¡ £ä¨ªáë, ¨§¬¥­¥­  «®£¨ª  ®¡à ¡®âª¨ áâ५®ª ¢¢¥àå/¢­¨§, çâ®¡ë ª ª ã ¢á¥å
„®¡ ¢«¥­  ª®¬ ­¤  waitfor ¨ ¢ à¨ ­â ps á ¯ à ¬¥â஬
* Мелкие багфиксы, изменена логика обработки стрелок вверх/вниз, чтобы как у всех
Добавлена команда waitfor и вариант ps с параметром
Shell 0.7.4 // 23.01.2014 // Albom
* <20> ¡®â  á ¡ãä¥à®¬ ®¡¬¥­  (ª®¯¨à®¢ ­¨¥ Ctrl+C ¨ ¢áâ ¢ª  Ctrl+V áâப¨ 楫¨ª®¬)
* Работа с буфером обмена (копирование Ctrl+C и вставка Ctrl+V строки целиком)
Shell 0.7.3 // 28.11.2013 // Albom
* ˆá¯à ¢«¥­  ®è¨¡ª  á ᨬ¢®«®¬ % ¢ ¨áâ®à¨¨ ª®¬ ­¤
* Исправлена ошибка с символом % в истории команд
Shell 0.7.2 // 26.10.2013 // Albom
* ” ©« .shell ¯¥à¥­¥á¥­ ¢ /sys/settings/
* ˆá¯à ¢«¥­  ª®¬ ­¤  "cd .."
* Файл .shell перенесен в /sys/settings/
* Исправлена команда "cd .."
Shell 0.7.1 // 19.10.2013 // Albom
* ˆá¯à ¢«¥­  ®è¨¡ª , á¢ï§ ­­ ï á § ¢¨á ­¨¥¬ ¯à¨ ¯®¯ë⪥ ç⥭¨ï ¯ãá⮩ ¨áâ®à¨¨ ª®¬ ­¤ (¯® ª« ¢¨è ¬ Up ¨ Down)
* Исправлена ошибка, связанная с зависанием при попытке чтения пустой истории команд (по клавишам Up и Down)
Shell 0.7.0 // 13.10.2013 // Albom
* <20>¥à¥à ¡®â ­ ¬®¤ã«ì ¢¢®¤  ª®¬ ­¤ë (¤®¡ ¢«¥­  ®¡à ¡®âª  ª« ¢¨è "¢«¥¢®", "¢¯à ¢®", Del)
* Œ¥«ª¨¥ ¨á¯à ¢«¥­¨ï
* Переработан модуль ввода команды (добавлена обработка клавиш "влево", "вправо", Del)
* Мелкие исправления
Shell 0.6.4 // 09.10.2013 // Leency
* <EFBFBD>®¤¤¥à¦ª  ®â­®á¨â¥«ì­ëå ¯ã⥩ ¢ áªà¨¯â å
* Поддержка относительных путей в скриптах
Shell 0.6.3 // 20.09.2013 // Albom
* msvc-style  âਡãâë ¤«ï ®âª«î祭¨ï ¢ëà ¢­¨¢ ­¨ï ¢ áâàãªâãà å (ᯠᨡ® CleverMouse ¨ Kirakishou!)
* msvc-style атрибуты для отключения выравнивания в структурах (спасибо CleverMouse и Kirakishou!)
Shell 0.6.2 // 24.02.2013 // Albom
* „®¡ ¢«¥­  ®¡à ¡®âª  ã¯à ¢«ïîé¨å ᨬ¢®«®¢ (\n, \t, \", \', \\, \?)
* Œ¥«ª¨¥ ¨á¯à ¢«¥­¨ï
* Добавлена обработка управляющих символов (\n, \t, \", \', \\, \?)
* Мелкие исправления
Shell 0.6.1 // 17.02.2013 // Albom
* <EFBFBD>à®áâ ï ®¡à ¡®âª  ®è¨¡®ª ¢­ãâ७­¨å ª®¬ ­¤
* Š®¬ ­¤  killall âà ­áä®à¬¨à®¢ ­  ¢ ¯ à ¬¥âà all ª®¬ ­¤ë kill
* ˆ§¬¥­¥­  ª®¤¨à®¢ª  ä ©«  History.txt á 1251 ­  866
* Простая обработка ошибок внутренних команд
* Команда killall трансформирована в параметр all команды kill
* Изменена кодировка файла History.txt с 1251 на 866
Shell 0.6 // 16.02.2013 // Albom
+ „®¡ ¢«¥­  ¢®§¬®¦­®áâì § ¯ã᪠âì ¯à®£à ¬¬ë, ¨¬¥­  ª®â®àëå ¨«¨ ¯ãâì ª ª®â®àë¬ á®¤¥à¦ â ¯à®¡¥«ë. ˆ¬ï ¯à®£à ¬¬ë (¢®§¬®¦­® á ¯ãâñ¬ ª ­¥©) ¤«ï í⮣® ­¥®¡å®¤¨¬® § ª«îç âì ¢ ª ¢ë窨. .¥. ­ ª®­¥æ-â® ¬®¦­® § ¯ãáâ¨âì ¯à®£à ¬¬ã ¨§ /rd/1/File managers, ­¥ ¯¥à¥å®¤ï ¢ ­¥ñ
+ „®¡ ¢«¥­  äã­ªæ¨ï à §¤¥«¥­¨ï áâப®¢®© ¯¥à¥¬¥­­®© ­  int argc, char* argv[], çâ® ®§­ ç ¥â ¢®§¬®¦­®áâì ã«ãç襭¨ï ª®¬ ­¤ (®¡à ¡®âª  ­¥áª®«ìª¨å ¯ à ¬¥â஢)
+ „®¡ ¢«¥­  ª®¬ ­¤  cp (ª®¯¨à®¢ ­¨¥ ä ©« ). <20>ਭ¨¬ ¥â ®¡ï§ â¥«ì­® ¤¢  ¯ à ¬¥âà  - ¨¬ï ä ©« -¨áâ®ç­¨ª  ¨ ¨¬ï ä ©« -१ã«ìâ â . ˆ¬¥­  ¬®£ãâ ¡ëâì ªà âª¨¬¨ (¢ ⥪ã饬 ª â «®£¥), â ª ¨ á ¯®«­ë¬ ¯ãâñ¬ (¤®«¦­ë ­ ç¨­ âìáï á /). Ž£à ­¨ç¥­¨¥ ­  à §¬¥à ä ©«  - 4 ƒ¡ ©â 
* ˆá¯à ¢«¥­  ª®¤¨à®¢ª  ¢ á®®¡é¥­¨¨ ®¡ ®è¨¡ª¥ ¢ ª®­á®«ì­®¬ ¯à¨«®¦¥­¨¨
* Š« ¢¨è¨ ¨áâ®à¨¨ (¢¢¥àå ¨ ¢­¨§) ¯®¬¥­ï­ë ¬¥¦¤ã ᮡ®©
* Š®«¨ç¥á⢮ ª®¬ ­¤ ¢ ¨áâ®à¨¨ 㢥«¨ç¥­® á ¯ï⨠¤® ¤¥áïâ¨
* “¬¥­ì襭® ª®«¨ç¥á⢮ ¯à¥¤ã¯à¥¦¤¥­¨© ¯à¨ ª®¬¯¨«ï樨
* Š®¬ ­¤  ccpuid ¯à¥®¡à §®¢ ­  ¢ ¯ à ¬¥âà cpu ª®¬ ­¤ë ver
* ˆá¯à ¢«¥­¨ï ¢ ¯ ª¥â­ëå ä ©« å ᡮન
+ „®¡ ¢«¥­ ¯à¨¬¥à ª®­á®«ì­®£® ¯à¨«®¦¥­¨ï ­   áᥬ¡«¥à¥ ¨ ¯ ª¥â­ë© ä ©« ¤«ï ¥£® ᡮન
+ Добавлена возможность запускать программы, имена которых или путь к которым содержат пробелы. Имя программы (возможно с путём к ней) для этого необходимо заключать в кавычки. Т.е. наконец-то можно запустить программу из /rd/1/File managers, не переходя в неё
+ Добавлена функция разделения строковой переменной на int argc, char* argv[], что означает возможность улучшения команд (обработка нескольких параметров)
+ Добавлена команда cp (копирование файла). Принимает обязательно два параметра - имя файла-источника и имя файла-результата. Имена могут быть краткими (в текущем каталоге), так и с полным путём (должны начинаться с /). Ограничение на размер файла - 4 Гбайта
* Исправлена кодировка в сообщении об ошибке в консольном приложении
* Клавиши истории (вверх и вниз) поменяны между собой
* Количество команд в истории увеличено с пяти до десяти
* Уменьшено количество предупреждений при компиляции
* Команда ccpuid преобразована в параметр cpu команды ver
* Исправления в пакетных файлах сборки
+ Добавлен пример консольного приложения на ассемблере и пакетный файл для его сборки
Shell 0.5.4 // 04.06.2012 // Albom
=======================================
* ˆá¯à ¢«¥­ ¨­â¥àä¥©á ¨á¯®«­ï¥¬ëå ª®­á®«ì­ëå ¯à¨«®¦¥­¨©. ’¥¯¥àì ®­¨ ¤®«¦­ë ᮧ¤ ¢ âì ¡ãä¥à á ¨¬¥­¥¬ pid-SHELL, £¤¥ pid - ¨¤¥­â¨ä¨ª â®à ¯à®æ¥áá  ¡¥§ § £« ¢­ëå ­ã«¥©
* <EFBFBD>¥¨­ª à­¨à®¢ ­ë ª®¬ ­¤ë ccpuid, free, killall
+ „®¡ ¢«¥­  ª®¬ ­¤  history
* Исправлен интерфейс исполняемых консольных приложений. Теперь они должны создавать буфер с именем pid-SHELL, где pid - идентификатор процесса без заглавных нулей
* Реинкарнированы команды ccpuid, free, killall
+ Добавлена команда history
Shell 0.5.3 // 19.04.2012 // Albom
=======================================
* ˆá¯à ¢«¥­¨¥ ¢ ª®¬ ­¤¥ pwd
* Исправление в команде pwd
Shell 0.5.2 // 16.04.2012 // Albom
=======================================
* ˆá¯à ¢«¥­¨¥ ¢ ª®¬ ­¤¥ ls
* <EFBFBD>¥§­ ç¨â¥«ì­ë¥ ¤à㣨¥ ¨á¯à ¢«¥­¨ï
* Исправление в команде ls
* Незначительные другие исправления
Shell 0.5.1 // 15.04.2012 // Albom
=======================================
* <EFBFBD>¥ª®â®àë¥ ­¥§­ ç¨â¥«ì­ë¥ ¨á¯à ¢«¥­¨ï
* Некоторые незначительные исправления
Shell 0.5 // 23.03.2012 // Albom
=======================================
* „®¡ ¢«¥­  ¯®¤¤¥à¦ª  ª®­á®«ì­ëå ¯à¨«®¦¥­¨©, ª®â®àë¥ ®¡é îâáï á 襫«®¬ ç¥à¥§ ¨¬¥­®¢ ­­ãî ®¡« áâì
* Добавлена поддержка консольных приложений, которые общаются с шеллом через именованную область
Shell 0.4.6 // 30.01.2011 // Albom
=======================================
* ‚६¥­­® 㤠«¥­ë ª®¬ ­¤ë killall ¨ ccpuid (çâ®¡ë ¢¥à­ãâì, ­¥®¡å®¤¨¬® à áª®¬¬¥­â¨à®¢ âì 2 áâà®çª¨)
* ˆá¯à ¢«¥­¨ï ¢ ⥪á⮢ëå áâப å
* Временно удалены команды killall и ccpuid (чтобы вернуть, необходимо раскомментировать 2 строчки)
* Исправления в текстовых строках
Shell 0.4.52 // 25.10.2010 // Pterox
=======================================
* „®¡ ¢«¥­  ª®¬ ­¤  "killall" - 㡨¢ ¥â ¢á¥ ¯à®æ¥ááë ªà®¬¥ OS/IDLE.
* ”¨ªáë
* Добавлена команда "killall" - убивает все процессы кроме OS/IDLE.
* Фиксы
Shell 0.4.51 // 21.10.2010 // Pterox
=======================================
* Š®¬ ­¤  "turnoff" ¯¥à¥¨¬¥­®¢ ­  ¢ "shutdown", "kerver" 㤠«¥­  - ⥯¥àì ¥ñ § ¬¥­ï¥â "ver kernel"; 䨪áë.
* Команда "turnoff" переименована в "shutdown", "kerver" удалена - теперь её заменяет "ver kernel"; фиксы.
Shell 0.4.5 // 19.10.2010 // Pterox
=======================================
<EFBFBD>ணࠬ¬  ⥯¥àì ¬­®£®ï§ëª®¢ ï ( ­£«¨©áª¨©, ¨ àãá᪨© ï§ëª). <20>ணࠬ¬  ¯®«­®áâìî àãá¨ä¨æ¨à®¢ ­­ .
* Š®¬ ­¤  "free" ¯¥à¥¨¬¥­®¢ ­  ¢ "memory" - ¤«ï â®ç­®áâ¨.
* „®¡ ¢«¥­ë ª®¬ ­¤ë turnoff (¢ëª«îç¨âì ª®¬¯ìîâ¥à), kerver (¢¥àá¨ï ï¤à  KolibriOS), uptime; reboot ⥯¥àì ¬®¦¥â ¯¥à¥§ £à㦠âì ï¤à® ("reboot kernel")
Программа теперь многоязыковая (английский, и русский язык). Программа полностью русифицированна.
* Команда "free" переименована в "memory" - для точности.
* Добавлены команды turnoff (выключить компьютер), kerver (версия ядра KolibriOS), uptime; reboot теперь может перезагружать ядро ("reboot kernel")
Shell 0.4.4 // 20.08.2010 // Albom
=======================================
1) 襫« ª®à४⭮ § ¢¥àè ¥âáï ¯à¨ § ªàë⨨ ®ª­ 
2) ¨á¯à ¢«¥­® ¥éñ 2 ®è¨¡ª¨
3) ¤®¡ ¢«¥­ë 2 ª®¬ ­¤ë:
* sleep - ¦¤ âì. ¯ à ¬¥âà - ¢à¥¬ï ¢ á®âëå ç áâïå ᥪ㭤ë. ⮫쪮 楫®¥ ç¨á«®.
* ccpuid - ¢ë¢®¤ ¢ ª®­á®«ì ¨­ä®à¬ æ¨¨ (¯®ª  áªã¤­®) ® ¯à®æ¥áá®à¥. ¯®«ì§ë ¬ «®, ­® ¤ ¢­® å®â¥« á ª®¬ ­¤®© cpuid à §®¡à âìáï (¢ á«¥¤ãî饬 ᥬ¥áâॠ¡ã¤ã áâ㤥­â ¬ ªãàá ç¨â âì, ¢ª«î稫 à §¡®à ª®¬ ­¤ë ¢ ¯à®£à ¬¬ã).
1) шелл корректно завершается при закрытии окна
2) исправлено ещё 2 ошибки
3) добавлены 2 команды:
* sleep - ждать. параметр - время в сотых частях секунды. только целое число.
* ccpuid - вывод в консоль информации (пока скудно) о процессоре. пользы мало, но давно хотел с командой cpuid разобраться (в следующем семестре буду студентам курс читать, включил разбор команды в программу).
¥áâì ¬­®£® ¨¤¥©. ­¥ª®â®àë¥ «¥£ª® ॠ«¨§ãîâáï, ­¥ª®â®àë¥ á«®¦­¥¥. ¥á«¨ ¨­â¥à¥á­®:
1) ¤®¡ ¢¨âì ¯¥à¥¬¥­­ãî (®¤­ã!), ¢ ª®â®àãî ¡ã¤¥â १ã«ìâ â ¢ ⥪á⮢®© ä®à¬¥ (­¥ â® çâ® ¢®§¢à é ¥â äã­ªæ¨ï) § ¯¨á뢠âìáï. á ­¥© ¬®¦­® ¡ã¤¥â à ¡®â âì ¨§ ª®¬ ­¤­®© áâப¨
2) ¢­¥¤à¨âì ¯à®áâãî á⥪®¢ãî ¬ è¨­ã ¤«ï ¢ëç¨á«¥­¨© á ¢¥é¥á⢥­­ë¬¨ ç¨á« ¬¨
есть много идей. некоторые легко реализуются, некоторые сложнее. если интересно:
1) добавить переменную (одну!), в которую будет результат в текстовой форме (не то что возвращает функция) записываться. с ней можно будет работать из командной строки
2) внедрить простую стековую машину для вычислений с вещественными числами
Shell 0.4.3 // 20.08.2010 // Albom
=======================================
* ‘¬¥áì ¢¥àᨩ 0.4.1 ¨ 0.4.2. ’¥¯¥àì ¢  à娢¥ ¢á¥ ¨á室­ë¥ ä ©«ë, ­¥®¡å®¤¨¬ë¥ ¤«ï ª®¬¯¨«ï樨 (à ­ìè¥ ¨á¯®«ì§®¢ «¨áì ®¡ê¥ªâ­¨ª¨ á ¬®¨¬¨ ®¡ñà⪠¬¨, ¨á室­¨ª¨ ï á 襫«®¬ ­¥ ¢ëª« ¤ë¢ «)
* Смесь версий 0.4.1 и 0.4.2. Теперь в архиве все исходные файлы, необходимые для компиляции (раньше использовались объектники с моими обёртками, исходники я с шеллом не выкладывал)
Shell 0.4.2 // 28.08.2009 // diamond
=======================================
* „®¡ ¢¨« ª®à४⭮¥ § ¢¥à襭¨¥ à ¡®âë ¯à¨ § ªàë⨨ ®ª­  ª®­á®«¨, à ¡®â ¥â ⮫쪮 ­ ç¨­ ï á ¯®á«¥¤­¥© ­  ¤ ­­ë© ¬®¬¥­â ¢¥àᨥ© ¡¨¡«¨®â¥ª¨ («¥¦¨â ­  svn, ¢ª«î祭  ¢ ­®ç­ãî á¡®àªã). <20>¥à¥ª®¬¯¨«¨à®¢ « ¢ VS2008 á LTCG, ¥éñ ¯®è ¬ ­¨« á ®¯â¨¬¨§ æ¨¥© ¯® à §¬¥àã
* Добавил корректное завершение работы при закрытии окна консоли, работает только начиная с последней на данный момент версией библиотеки (лежит на svn, включена в ночную сборку). Перекомпилировал в VS2008 с LTCG, ещё пошаманил с оптимизацией по размеру
Shell 0.4.1 // 16.03.2009 // Albom
=======================================
* ¢¥àá¨ï á ¨á¯à ¢«¥­­ë¬¨ ®è¨¡ª ¬¨.
* à ¡®â ¥â ª®¬ ­¤  alias, ¤®¡ ¢«¥­  ª®¬ ­¤  clear.
* версия с исправленными ошибками.
* работает команда alias, добавлена команда clear.
Shell 0.4 // 12.08.2008 // Albom
=======================================
1) <EFBFBD> ¡®â ¥â á奬  ¯á¥¢¤®­¨¬®¢ (¤® 256 ª®¬ ­¤)
- ¯à®á¬®âà ¯® ª®¬ ­¤¥ alias (¡¥§ ¯ à ¬¥â஢)
- ¤®¡ ¢«¥­¨¥ ¯á¥¢¤®­¨¬  ª®¬ ­¤ë á ª« ¢¨ âãàë ¨«¨ ¢ áªà¨¯â¥ (¢ ⮬ ç¨á«¥ ¨ .shell): alias ­®¢ ï ª®¬ ­¤  = áâ à ï ª®¬ ­¤ 
- ª®¬ ­¤ë ॣ¨áâ஧ ¢¨á¨¬ë¥, ¯®í⮬㠯®ª«®­­¨ª ¬ „Ž‘ ¯à¨¤ñâáï ¢­¥á⨠¢ .shell áâப¨ â ª®£® ¢¨¤ 
1) Работает схема псевдонимов (до 256 команд)
- просмотр по команде alias (без параметров)
- добавление псевдонима команды с клавиатуры или в скрипте (в том числе и .shell): alias новая команда = старая команда
- команды регистрозависимые, поэтому поклонникам ДОС придётся внести в .shell строки такого вида
alias dir = ls
alias DIR = ls
alias Dir = ls
alias DIr = ls
¨ â.¤.
- ¢áâ஥­­ë¥ ª®¬ ­¤ë ¯¥à¥­ §¢ âì ­¥¢®§¬®¦­®, ­ ¯à¨¬¥à, ¡¥áá¬ëá«¥­­  ª®¬ ­¤ :
и т.д.
- встроенные команды переназвать невозможно, например, бессмысленна команда:
alias ls=somecommand
- ¯à¨ ®â« ¤ª¥ ¯®«ãç « áâà ­­ãî ¨­ä®à¬ æ¨î, ­® â ª ª ª ã ¬¥­ï ¢áñ à ¡®â ¥â, â® ¯®ª  ¨§¬¥­¥­¨© ¢­®á¨âì ­¥ ¯« ­¨àãî
- при отладке получал странную информацию, но так как у меня всё работает, то пока изменений вносить не планирую
2) ’¥¯¥àì 襫« ¬®¦­® § ¯ã᪠âì á ¯ à ¬¥â஬ (¨§ á ¬®£® ᥡï, ­ ¯à¨¬¥à)
- ᨭ⠪á¨á:
shell ª®¬ ­¤ 
- ¯à¨¬¥à:
2) Теперь шелл можно запускать с параметром (из самого себя, например)
- синтаксис:
shell команда
- пример:
shell /sys/somescript
- ¯à¨ í⮬ .shell ­¥ § ¯ã᪠¥âáï
- при этом .shell не запускается
3) <EFBFBD>¥ «¨§®¢ ­  ª®¬ ­¤  more
- ¯à®á¬®âà ⥪á⮢ëå ¨ ¡¨­ à­ëå ä ©«®¢ (¢à®¤¥ ¡ë § ¤ ç  ¯à®áâ ï, ­® ¯à¨è«®áì ¯®¢®§¨âìáï á ã¯à ¢«ïî騬¨ ᨬ¢®« ¬¨)
- ®ç¥­ì ­¥ ४®¬¥­¤ã¥âáï ¯à®á¬ âਢ âì ¡®«ì訥 ä ©«ë
3) Реализована команда more
- просмотр текстовых и бинарных файлов (вроде бы задача простая, но пришлось повозиться с управляющими символами)
- очень не рекомендуется просматривать большие файлы
Shell 0.3 // 07.08.2008 // Albom
=======================================
1) ‚®§¬®¦­®áâì § ¯ã᪠ áªà¨¯â®¢
* ª ¦¤ ï áâப  ¤®«¦­  ¯à¥¤áâ ¢«ï¥â ᮡ®© ª®¬ ­¤ã
* áâப®© áç¨â ¥âáï ­ ¡®à ᨬ¢®«®¢, ª®â®àë© § ª ­ç¨¢ ¥âáï CR+LF (Windows) ¨«¨ LF(UNIX) ¨«¨ CR(Mac)
* ¥á«¨ áâப  ­ ç¨­ ¥âáï á #, â® ¢áï áâப  (â.¥. ª®¬¬¥­â à¨©) ¨£­®à¨àã¥âáï
* áªà¨¯â ¤®«¦¥­ ­ ç¨â âìáï á #SHS
* ¯à¨ § ¯ã᪥ 襫«   ¢â®¬ â¨ç¥áª¨ § ¯ã᪠¥âáï áªà¨¯â .shell
1) Возможность запуска скриптов
* каждая строка должна представляет собой команду
* строкой считается набор символов, который заканчивается CR+LF (Windows) или LF(UNIX) или CR(Mac)
* если строка начинается с #, то вся строка (т.е. комментарий) игнорируется
* скрипт должен начитаться с #SHS
* при запуске шелла автоматически запускается скрипт .shell
2) ˆáâ®à¨ï ¨§ 5 (¬®¦­® ¨§¬¥­¨âì ¯à¨ ª®¬¯¨«ï樨) ¢¢¥¤ñ­­ëå ª®¬ ­¤
* ¯¥à¥¬¥é¥­¨¥ ¯® ¨áâ®à¨¨ - UP/DOWN
2) История из 5 (можно изменить при компиляции) введённых команд
* перемещение по истории - UP/DOWN
3) Š®¬ ­¤  alias, ª®â®à ï ¯®§¢®«ï¥â ¢¢®¤¨âì ᨭ®­¨¬ë ¤«ï ª®¬ ­¤
* ¤® 256 (¬®¦­® ¨§¬¥­¨âì ¯à¨ ª®¬¯¨«ï樨) ᨭ®­¨¬®¢
* ¯®ª  à ¡®â ¥â ⮫쪮 ¤®¡ ¢«¥­¨¥ ¨ ¯à®á¬®âà ᨭ®­¨¬®¢,   ®âà ¡®âª  ¯®ª  ­¥ ॠ«¨§®¢ ­ 
3) Команда alias, которая позволяет вводить синонимы для команд
* до 256 (можно изменить при компиляции) синонимов
* пока работает только добавление и просмотр синонимов, а отработка пока не реализована
Shell 0.2 // 04.08.2008 // Albom
=======================================
* ¤®¡ ¢¨« ­®¢ë¥ ä㭪樨
* ­ ¯¨á « ᮡá⢥­­ãî ¯à®æ¥¤ãàã ¢¢®¤  ª®¬ ­¤ë
* добавил новые функции
* написал собственную процедуру ввода команды
Shell 0.11 // 01.08.2008 // Albom
=======================================
* „®¡ ¢¨« ª®¬ ­¤ë free ¨ reboot, ¢­ñá ­¥ª®â®àë¥ ¨§¬¥­¥­¨ï, ¨á¯à ¢¨« ­ ©¤¥­­ë¥ ®è¨¡ª¨
* Добавил команды free и reboot, внёс некоторые изменения, исправил найденные ошибки
Shell 0.1 // 29.07.2008 // Albom
=======================================
* <EFBFBD>¥ «¨§®¢ ­ë (­¥ ¯®«­®áâìî) ª®¬ ­¤ë: about, cd, date, echo, exit, help, kill, ls, ps, pwd, ver
* <EFBFBD>ਠ§ ¯ã᪥ ¯à®£à ¬¬ë (¥á«¨ ­¥ 㪠§ ­ ¯®«­ë© ¯ãâì) ®­  ¨é¥âáï ¢ ª â «®£¥ /rd/1 ¨ ⥪ã饬 ª â «®£¥
* Реализованы (не полностью) команды: about, cd, date, echo, exit, help, kill, ls, ps, pwd, ver
* При запуске программы (если не указан полный путь) она ищется в каталоге /rd/1 и текущем каталоге
Shell 0.02 // 27.07.2008 // Albom
=======================================
* <EFBFBD>¥ «¨§®¢ « ª®¬ ­¤ë:
exit - ¢ë室
ls (á ¯ à ¬¥â஬ ¨ ¡¥§) - ¢ë¢®¤ ᯨ᪠ ¤¨à¥ªâ®à¨¨
pwd - ⥪ã騩 ª â «®£
ps - ᯨ᮪ ¯à®æ¥áᮢ ¨ ¨å PID
kill - § ¢¥àè¨âì ¯à®æ¥áá ¯® PID
help (á ¯ à ¬¥â஬ ¨ ¡¥§) - ¯®¬®éì
* Реализовал команды:
exit - выход
ls (с параметром и без) - вывод списка директории
pwd - текущий каталог
ps - список процессов и их PID
kill - завершить процесс по PID
help (с параметром и без) - помощь
Shell 0.01 // 27.07.2008 // Albom
=======================================
* <EFBFBD>¥è¨« ­ ¯¨á âì ä㭪樮­ «ì­ë© 襫« ­  ‘¨ á ¨á¯®«ì§®¢ ­¨¥¬ console.obj
* <EFBFBD>®ª  ᤥ« « äã­ªæ¨î ®â¤¥«¥­¨ï ª®¬ ­¤ë ¨ ¯ à ¬¥â஢,   â ª¦¥ ॠ«¨§®¢ « ª®¬ ­¤ë help (¯®ª  ¡¥§ ¯ à ¬¥â஢), ver ¨ exit
* Решил написать функциональный шелл на Си с использованием console.obj
* Пока сделал функцию отделения команды и параметров, а также реализовал команды help (пока без параметров), ver и exit

View File

@ -1,26 +1,10 @@
if tup.getconfig("NO_FASM") ~= "" or tup.getconfig("NO_GCC") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_gcc.lua")
LDFLAGS = LDFLAGS .. " -T kolibri.ld"
-- compile shell
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
if tup.getconfig("NO_TCC") ~= "" then return end
if tup.getconfig("TUP_PLATFORM") == "win32"
-- on win32 '#' is not a special character, but backslash and quotes would be printed as is
then tup.rule('echo #define ' .. C_LANG .. ' 1 > %o', {"lang.h"})
-- on unix '#' should be escaped
else tup.rule('echo "#define" ' .. C_LANG .. ' 1 > %o', {"lang.h"})
end
tup.append_table(OBJS, tup.rule("start.asm", "fasm %f %o", "start.o"))
compile_gcc{"shell.c", "system/kolibri.c", "system/stdlib.c", "system/string.c", "system/ctype.c", extra_inputs = {"lang.h"}}
link_gcc("shell")
TCC="kos32-tcc"
CFLAGS = "-I../../develop/ktcc/trunk/libc.obj/include"
LDFLAGS = "-nostdlib ../../develop/ktcc/trunk/bin/lib/crt0.o -L../../develop/ktcc/trunk/bin/lib"
-- compile ASM test
tup.rule("test.asm", "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "asmtest")
-- compile C test
OBJS = {"start.o", "kolibri.o", "stdlib.o", "string.o", "ctype.o"} -- remove shell.o
compile_gcc{"test.c"}
link_gcc("ctest")
LIBS = "-ltcc -lc.obj"
COMMAND=string.format("%s %s %s %s %s", TCC, CFLAGS, LDFLAGS , "%f -o %o", LIBS)
tup.rule("shell.c", COMMAND .. tup.getconfig("KPACK_CMD"), "shell")

View File

@ -8,9 +8,36 @@
#include "system/boolean.h"
#include "system/kolibri.h"
#include "system/stdlib.h"
#include "system/string.h"
#include "system/ctype.h"
//#include "system/stdlib.h"
//#include "system/string.h"
//#include "system/ctype.h"
//#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/ksys.h>
//--------
int strnicmp(const char* string1, const char* string2, unsigned count)
{
int pc = 0;
while (1)
{
if (toupper(*string1)<toupper(*string2))
return -1;
if (toupper(*string1)>toupper(*string2))
return 1;
if (*string1=='\0' || pc == count)
return 0;
string1++;
string2++;
pc++;
}
}
//--------
extern int _FUNC(sprintf)(char* buffer, const char* format, ...);
#include "globals.h"
#include "prototypes.h"
@ -18,7 +45,31 @@
// from main file (shell.c). TODO - in future move to library
void get_file_dir_loc(char *filepath, char *dir_path);
#include "system/console.c"
//#include "system/console.c"
#include <conio.h>
#define con_exit (*con_exit)
#define con_set_title (*con_set_title)
#define con_write_asciiz (*con_write_asciiz)
#define con_write_string (*con_write_string)
#define con_printf (*con_printf)
#define con_get_flags (*con_get_flags)
#define con_set_flags (*con_set_flags)
#define con_get_font_height (*con_get_font_height)
#define con_get_cursor_height (*con_get_cursor_height)
#define con_set_cursor_height (*con_set_cursor_height)
#define con_getch (*con_getch)
#define con_getch2 (*con_getch2)
#define con_kbhit (*con_kbhit)
#define con_gets (*con_gets)
#define con_gets2_callback (* con_gets2_callback)
#define con_gets2 (*con_gets2)
#define con_cls (*con_cls)
#define con_get_cursor_pos (*con_get_cursor_pos)
#define con_set_cursor_pos (*con_set_cursor_pos)
#define printf con_printf
#define gets con_gets
#define getch con_getch2
#include "cmd/cmd_about.c"
#include "cmd/cmd_help.c"
@ -45,6 +96,7 @@ void get_file_dir_loc(char *filepath, char *dir_path);
#include "cmd/cmd_shutdown.c"
#include "cmd/cmd_uptime.c"
#include "cmd/cmd_history.c"
#include "cmd/cmd_kfetch.c"
#include "cmd/cmd_cp.c"
#include "cmd/cmd_mv.c"
#include "cmd/cmd_ren.c"
@ -58,6 +110,5 @@ void get_file_dir_loc(char *filepath, char *dir_path);
#include "modules/module_alias.c"
#include "modules/module_parameters.c"
typedef unsigned int size_t;
//typedef unsigned int size_t;
/// ===========================================================

2
programs/system/shell/build.sh Executable file
View File

@ -0,0 +1,2 @@
../../develop/ktcc/trunk/source/kos32-tcc -I../../develop/ktcc/trunk/libc.obj/include -nostdlib ../../develop/ktcc/trunk/bin/lib/crt0.o -L../../develop/ktcc/trunk/bin/lib shell.c system/kolibri.c -o shell -ltcc -lc.obj
../../other/kpack/linux/kpack shell

View File

@ -1,10 +1,6 @@
int cmd_about(char param[])
{
char message[] = {"Shell %s\n\r"};
printf(message, SHELL_VERSION);
return TRUE;
int cmd_about(char param[]) {
printf(CMD_ABOUT_MSG, SHELL_VERSION);
return TRUE;
}

View File

@ -1,20 +1,17 @@
int cmd_alias(char arg[])
{
int cmd_alias(char arg[]) {
int result;
int result;
if (NULL == arg || '\0' == arg[0])
{
alias_list();
return TRUE;
if (NULL == arg || '\0' == arg[0]) {
alias_list();
return TRUE;
}
result = alias_check(arg);
result = alias_check(arg);
if ( ( 0 != result ) && ( -1 != result ) )
alias_add(arg);
if ( ( 0 != result ) && ( -1 != result ) )
alias_add(arg);
return TRUE;
return TRUE;
}

View File

@ -1,58 +1,47 @@
int cmd_cd(char dir[])
{
char temp[256];
unsigned result;
char temp[256];
unsigned result;
if (NULL == dir)
{
#if LANG_ENG
printf(" cd <directory>\n\r");
#elif LANG_RUS
printf(" cd <¤¨ŕĽŞâŽŕ¨ď>\n\r");
#endif
return TRUE;
}
if ( 0 == strcmp(dir, ".") || 0 == strcmp(dir, "./") )
return TRUE;
if ( ( 0 == strcmp(dir, "..") || 0 == strcmp(dir, "../") ) && ( 0 != strcmp(cur_dir, "/")) )
{
cur_dir[strlen(cur_dir)-1]='\0';
dir_truncate(cur_dir);
set_cwd(cur_dir);
return TRUE;
}
if ( '/' == dir[0])
{
if ( dir_check(dir) )
{
strcpy(cur_dir, dir);
set_cwd(cur_dir);
if (NULL == dir) {
printf(CMD_CD_USAGE);
return TRUE;
}
return FALSE;
}
else
{
strcpy(temp, cur_dir);
if (cur_dir[strlen(cur_dir)-1] != '/')
strcat(temp, "/");
strcat(temp, dir);
if ( dir_check(temp) )
{
strcpy(cur_dir, temp);
set_cwd(cur_dir);
if ( 0 == strcmp(dir, ".") || 0 == strcmp(dir, "./") )
return TRUE;
if ( ( 0 == strcmp(dir, "..") || 0 == strcmp(dir, "../") ) && ( 0 != strcmp(cur_dir, "/")) ) {
cur_dir[strlen(cur_dir)-1]='\0';
dir_truncate(cur_dir);
set_cwd(cur_dir);
return TRUE;
}
if ( '/' == dir[0]) {
if ( dir_check(dir) )
{
strcpy(cur_dir, dir);
set_cwd(cur_dir);
return TRUE;
}
return FALSE;
}
else {
strcpy(temp, cur_dir);
if (cur_dir[strlen(cur_dir)-1] != '/')
strcat(temp, "/");
strcat(temp, dir);
if ( dir_check(temp) ) {
strcpy(cur_dir, temp);
set_cwd(cur_dir);
return TRUE;
}
return FALSE;
return FALSE;
}
}

View File

@ -1,7 +1,6 @@
int cmd_clear(char param[])
{
con_cls();
return TRUE;
int cmd_clear(char param[]) {
con_cls();
return TRUE;
}

View File

@ -19,11 +19,7 @@ int cmd_cp(char param[])
if (argc != 2)
{
#if LANG_ENG
printf(" cp <file_in> <file_out>\n\r");
#elif LANG_RUS
printf(" cp <¨áâ®ç­¨ª> <१ã«ìâ â>\n\r");
#endif
printf(CMD_CP_USAGE);
parameters_free(argc, argv);
return TRUE;
}

View File

@ -1,32 +1,22 @@
int cmd_date(char param[])
{
unsigned date;
unsigned time;
unsigned date;
unsigned time;
date = kol_system_date_get();
#if LANG_ENG
printf(" Date [dd.mm.yy]: %x%x.%x%x.%x%x",
#elif LANG_RUS
printf(" „ â  [¤¤.¬¬.££]: %x%x.%x%x.%x%x",
#endif
(date&0xf00000)>>20, (date&0xf0000)>>16, // day
(date&0xf000)>>12, (date&0xf00)>>8, //month
(date&0xf0)>>4, (date&0xf) ); // year
date = kol_system_date_get();
printf(CMD_DATE_DATE_FMT,
(date&0xf00000)>>20, (date&0xf0000)>>16, // day
(date&0xf000)>>12, (date&0xf00)>>8, //month
(date&0xf0)>>4, (date&0xf) ); // year
time = kol_system_time_get();
time = kol_system_time_get();
printf(CMD_DATE_TIME_FMT,
(time&0xf0)>>4, (time&0xf), // hours
(time&0xf000)>>12, (time&0xf00)>>8, // minutes
(time&0xf00000)>>20, (time&0xf0000)>>16 ); // seconds
#if LANG_ENG
printf("\n\r Time [hh:mm:ss]: %x%x:%x%x:%x%x\n\r",
#elif LANG_RUS
printf("\n\r ‚६ï [çç:¬¬:áá]: %x%x:%x%x:%x%x\n\r",
#endif
(time&0xf0)>>4, (time&0xf), // hours
(time&0xf000)>>12, (time&0xf00)>>8, // minutes
(time&0xf00000)>>20, (time&0xf0000)>>16 ); // seconds
return TRUE;
return TRUE;
}

View File

@ -1,9 +1,9 @@
int cmd_exit(char param[])
{
free(ALIASES);
_exit(1);
kol_exit();
return TRUE;
free(ALIASES);
con_exit(1);
kol_exit();
return TRUE;
}

View File

@ -1,19 +1,15 @@
int cmd_memory(char param[])
{
unsigned total, free, used;
unsigned total, free, used;
total = kol_system_mem();
free = kol_system_memfree();
used = total - free;
total = kol_system_mem();
free = kol_system_memfree();
used = total - free;
#if LANG_ENG
printf (" Total [kB / MB / %%]: %-7d / %-5d / 100\n\r Free [kB / MB / %%]: %-7d / %-5d / %d\n\r Used [kB / MB / %%]: %-7d / %-5d / %d\n\r",
#elif LANG_RUS
printf (" ‚ᥣ® [Š<> / Œ<> / %%]: %-7d / %-5d / 100\n\r ‘¢®¡®¤­® [Š<> / Œ<> / %%]: %-7d / %-5d / %d\n\r ˆá¯®«ì§ã¥âáï [Š<> / Œ<> / %%]: %-7d / %-5d / %d\n\r",
#endif
printf (CMD_FREE_FMT,
total, total/1024, free, free/1024, (free*100)/total, used, total/1024-free/1024, 100-(free*100)/total );
return TRUE;
return TRUE;
}

View File

@ -1,46 +1,30 @@
int cmd_help(char cmd[])
{
int cmd_help(char cmd[]) {
int i;
int i;
#if LANG_ENG
char available[]={" %d commands available:\n\r"};
#elif LANG_RUS
char available[]={" Š®«¨ç¥á⢮ ¤®áâ㯭ëå ª®¬ ­¤: %d\n\r"};
#endif
if ( !strlen(cmd) )
{
int columns_max=3;
printf (available, NUM_OF_CMD);
for (i = 0; i < NUM_OF_CMD; i++)
{
printf(" %-12s", COMMANDS[i].name);
if ((i) && ((i+1)%columns_max == 0)) printf("\n\r");
if ( !strlen(cmd) ) {
int columns_max=3;
printf (CMD_HELP_AVAIL, NUM_OF_CMD);
for (i = 0; i < NUM_OF_CMD; i++) {
printf(" %-12s", COMMANDS[i].name);
if ((i) && ((i+1)%columns_max == 0)) printf("\n\r");
}
if ((i)%columns_max != 0) printf("\n\r");
return TRUE;
}
if ((i)%columns_max != 0) printf("\n\r");
return TRUE;
}
else
{
for (i=0; i<NUM_OF_CMD; i++)
if ( !strcmp(cmd, COMMANDS[i].name) )
{
printf(COMMANDS[i].help);
return TRUE;
else {
for (i=0; i<NUM_OF_CMD; i++)
if ( !strcmp(cmd, COMMANDS[i].name) ) {
printf(COMMANDS[i].help);
return TRUE;
}
#if LANG_ENG
printf (" Command \'%s\' not found.\n\r", cmd);
#elif LANG_RUS
printf (" Š®¬ ­¤  \'%s\' ­¥ ­ ©¤¥­ .\n\r", cmd);
#endif
printf (available, NUM_OF_CMD);
for (i = 0; i < NUM_OF_CMD; i++)
printf(" %s\n\r", COMMANDS[i].name);
}
printf (CMD_HELP_CMD_NOT_FOUND, cmd);
printf (CMD_HELP_AVAIL, NUM_OF_CMD);
for (i = 0; i < NUM_OF_CMD; i++)
printf(" %s\n\r", COMMANDS[i].name);
}
return FALSE;
return FALSE;
}

View File

@ -1,14 +1,9 @@
int cmd_history(char arg[])
{
int i;
for (i = CMD_HISTORY_NUM_REAL - 1; i >= 0; i--)
{
printf("%s\n", CMD_HISTORY[i]);
int cmd_history(char arg[]) {
int i;
for (i = CMD_HISTORY_NUM_REAL - 1; i >= 0; i--) {
printf("%s\n", CMD_HISTORY[i]);
}
return TRUE;
return TRUE;
}

View File

@ -1,106 +0,0 @@
/* turbocat2001 */
#if LANG_ENG
#define HELP "info <object_name>\n"
#define FILE_NOT_FOUND "Object '%s' not found!\n"
#define OBJECT_INFO "Object '%s' information:\n\n"
#define TYPE "Type: "
#define DIR "'Folder'"
#define PART "'Part'"
#define FILE "'File'"
#define CREATED "Created: %02d.%02d.%02d %02d:%02d:%02d\n"
#define MODIFID "Modified: %02d.%02d.%02d %02d:%02d:%02d\n"
#define DATE_TIME " Date Time\n"
#define ATTRIB "Attributes: "
#define RO "'Read only' "
#define HIDDEN "'Hidden' "
#define SYS "'System' "
#define NOT_ARCHIV "'Not archived' "
#define FILE_SIZE "\nFile size: %u KB (%u B)\n"
#elif LANG_RUS
#define HELP "info <¨¬ï_®¡ê¥ªâ >\n"
#define FILE_NOT_FOUND "Ž¡ê¥ªâ '%s' ­¥ ­ ©¤¥­!\n"
#define OBJECT_INFO "ˆ­ä®à¬ æ¨ï ®¡ ®¡ê¥ªâ¥ '%s':\n\n"
#define TYPE "’¨¯: "
#define DIR "'<27> ¯ª '"
#define PART "'’®¬'"
#define FILE "'” ©«'"
#define CREATED "‘®§¤ ­: %02d.%02d.%02d %02d:%02d:%02d\n"
#define MODIFID "ˆ§¬¥­ñ­: %02d.%02d.%02d %02d:%02d:%02d\n"
#define DATE_TIME " „ â  ‚६ï\n"
#define ATTRIB "€âਡãâë: "
#define RO "'’®«ìª® ¤«ï ç⥭¨ï' "
#define HIDDEN "'‘ªàëâë©' "
#define SYS "'‘¨á⥬­ë©' "
#define NOT_ARCHIV "'<27>¥  à娢­ë©' "
#define FILE_SIZE "\n<> §¬¥à ä ©« : %u K<> (%u <20>)\n"
#endif
int cmd_info(char param[])
{
byte is_dir=0, is_part=0; // Folder or part?
char* argv[100];
if(1 != parameters_prepare(param, argv)) //get number of parameters
{
printf(HELP);
return TRUE;
}
FS_struct_BDVK *info=NULL; // BDVK struct define
info=get_bdvk(argv[0]); // Get file info (BDVK)
if(info==NULL)
{
printf(FILE_NOT_FOUND, argv[0]);
return TRUE;
}
printf(OBJECT_INFO, argv[0]);
printf(TYPE);
if (info->attrib & (1 << 4))
{
printf(DIR);
is_dir=1;
}
else if (info->attrib & (1 << 3))
{
printf(PART);
is_part=1;
}
else
{
printf(FILE);
}
printf("\n\n");
printf(DATE_TIME); // Show date and time
printf(CREATED, info->c_date.d, info->c_date.m, info->c_date.y, info->c_time.h, info->c_time.m, info->c_time.s);
printf(MODIFID, info->m_date.d, info->m_date.m, info->m_date.y, info->m_time.h, info->m_time.m, info->m_time.s);
printf("\n");
printf(ATTRIB); // Show Attributes
if (info->attrib & (1 << 0))
{
printf(RO);
}
if (info->attrib & (1 << 1))
{
printf(HIDDEN);
}
if (info->attrib & (1 << 2))
{
printf(SYS);
}
if (info->attrib & (1 << 5))
{
printf(NOT_ARCHIV);
}
printf("\n");
if (!is_dir && (info->size)>=0 && !is_part) // If dir or part then not show file size
{
printf(FILE_SIZE, info->size/1024, info->size);
}
return TRUE;
}

View File

@ -0,0 +1,53 @@
void get_str_meminfo(char *str) {
unsigned mem_all_mib = kol_system_mem() / 1024;
unsigned mem_free_mib = kol_system_memfree() / 1024;
sprintf(str, "%uMiB / %uMiB", mem_all_mib - mem_free_mib, mem_all_mib);
}
int cmd_kfetch(char param[]) {
char *str_krnl_ver = malloc(64);
get_str_kernel_version(str_krnl_ver, "%d.%d.%d.%d. SVN-rev.: %d");
char *str_uptime = malloc(64);
get_str_uptime(str_uptime, "%d day(s), %d:%d:%d.%d");
char *str_resolution = malloc(24);
ksys_pos_t resol = _ksys_screen_size();
sprintf(str_resolution, "%u x %u", resol.x + 1, resol.y + 1);
char *str_cpu_info = malloc(16);
get_str_cpu_info(str_cpu_info);
char *str_meminfo = malloc(24);
get_str_meminfo(str_meminfo);
printf(/*"\033[0;34;40m \033[0m\n\r"*/
/*"\033[0;34;40m \033[0m\n\r"*/
/*"\033[0;34;40m \033[0m\n\r"*/
"\033[0;34;40m .\033[0;31;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m t\033[0;1;30;40m@\033[0;34;40m.\033[0;31;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m ;8\033[0;1;30;40m8\033[0;34;40m8\033[0;1;30;40m8\033[0;32;40m.\033[0;34;40m.\033[0;32;40m \033[0;34;40m \033[0;31;40m.\033[0;34;40mS\033[0;1;30;46m88\033[0;1;35;47m8\033[0;35;44mX\033[0;34;40m;\033[0;32;40m.:\033[0;5;30;40mX\033[0;1;30;46mX8\033[0;34;40m8\033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m t\033[0;5;36;40m8\033[0;5;36;46m@ \033[0;5;37;46m%%\033[0;5;37;47m.\033[0;5;37;46m@\033[0;34;46m8\033[0;31;40mt\033[0;34;40m.\033[0;32;40m.\033[0;34;40m \033[0;31;40m \033[0;1;30;40m8\033[0;1;36;46m%%\033[0;5;37;46m8\033[0;5;1;35;44m8\033[0;1;34;45m8\033[0;30;44m8\033[0;32;40m;;\033[0;5;36;40m8\033[0;37;46m@\033[0;5;37;44m8\033[0;5;35;44m:\033[0;1;30;45m8\033[0;5;34;40m8\033[0m\n\r"
"\033[0;34;40m@\033[0;5;35;40m8\033[0;1;30;44m8\033[0;5;35;40m8\033[0;35;44m8\033[0;1;30;45m@\033[0;35;44m8\033[0;1;30;45m8\033[0;34;45m8\033[0;1;30;45m8\033[0;1;34;45m8\033[0;1;37;47mt\033[0;5;37;46m@\033[0;1;30;46m8S\033[0;5;37;46m8X\033[0;5;36;46m.t\033[0;1;30;44m8\033[0;31;40m \033[0;32;40m \033[0;34;40m:\033[0;5;36;40m8\033[0;1;30;46m@\033[0;1;34;47m8\033[0;5;37;45m8\033[0;5;35;44m \033[0;1;30;45m8\033[0;1;30;46m88\033[0;36;47m@\033[0;5;37;44m8\033[0;5;35;44m \033[0;5;35;45m;\033[0;5;35;44m.\033[0;37;45m8\033[0;1;30;44mX\033[0;32;40m \033[0m %s\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;32;40m \033[0;34;40m.\033[0;32;40m.\033[0;34;40m;S@\033[0;5;30;40m8\033[0;33;41m8\033[0;1;33;43m;\033[0;5;33;43m \033[0;1;33;47m8\033[0;5;33;43m \033[0;1;33;43mt\033[0;36;47m8\033[0;5;36;46m \033[0;1;36;46m%%\033[0;5;34;40m8\033[0;1;30;46m%%8\033[0;5;37;46mX\033[0;5;36;46m%%\033[0;5;35;45m.\033[0;5;36;44m.\033[0;37;46m8\033[0;1;34;47m@\033[0;1;36;47mX\033[0;5;1;35;44m8\033[0;5;37;44m8\033[0;5;1;34;45m8\033[0;1;35;45m:\033[0;1;34;47m8\033[0;1;30;45m8\033[0;5;34;40m8\033[0;31;40m: \033[0m %s%s\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m.::\033[0;34;40m.\033[0;31;40m;\033[0;1;30;43m8\033[0;5;1;33;41m8\033[0;5;33;43m \033[0;5;33;41m \033[0;5;37;43mX\033[0;5;36;46m8:\033[0;1;36;46mS.\033[0;5;36;46m;@\033[0;1;34;45m88\033[0;1;34;46m8\033[0;1;37;47m.\033[0;5;1;34;45m8\033[0;5;37;45m8\033[0;5;1;34;45m8\033[0;1;35;47m8\033[0;5;1;35;44m8\033[0;5;35;44m \033[0;35;47m8\033[0;35;44m%%\033[0;34;40m;. \033[0;31;40m \033[0m %s%s\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;32;40m \033[0;34;40m .\033[0;31;40m;\033[0;1;30;41m@\033[0;5;31;41mS\033[0;5;33;41m \033[0;5;1;31;43m8\033[0;1;30;43m8\033[0;5;36;46m88\033[0;5;37;46mX\033[0;1;36;47m@\033[0;1;36;46mS\033[0;1;34;47m@\033[0;1;35;47m@\033[0;5;37;44m8\033[0;5;1;34;45m8\033[0;5;35;44m;\033[0;1;34;45m8\033[0;5;35;44m;\033[0;35;47m8\033[0;5;1;35;44m8\033[0;1;30;45m8\033[0;5;35;40m8\033[0;34;40m%%\033[0;32;40m \033[0;34;40m \033[0;31;40m \033[0m %s%s\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m:\033[0;5;33;40mS\033[0;1;32;46m8\033[0;37;43mS\033[0;1;32;47m8\033[0;37;46mS\033[0;5;37;42m8\033[0;5;36;46mX\033[0;36;47m8\033[0;1;30;46m8\033[0;5;35;44mX\033[0;1;34;45m88\033[0;1;30;45m8\033[0;37;45m@\033[0;1;34;45m8\033[0;1;30;45m8\033[0;1;30;44m@\033[0;34;40m8\033[0;32;40m%%\033[0;34;40m; \033[0;32;40m \033[0;34;40m \033[0;31;40m \033[0m %s%s\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m .\033[0;32;40m.@\033[0;1;36;46m%%\033[0;5;36;42m;\033[0;1;33;47mX\033[0;5;37;46m8\033[0;5;37;42m8\033[0;5;33;43m \033[0;5;36;46m8\033[0;1;34;46m8\033[0;1;30;45m8\033[0;34;45m8\033[0;1;30;45m8\033[0;5;34;44m.\033[0;1;30;45m8\033[0;5;34;40m@\033[0;34;40mS:\033[0;32;40m;\033[0;34;40m: \033[0;32;40m \033[0m %s%s\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;34;40m.\033[0;31;40m;\033[0;5;36;40m8\033[0;1;36;46mt\033[0;5;36;42m.\033[0;1;33;47m@\033[0;5;36;42m \033[0;1;36;46m@X\033[0;5;36;46mX\033[0;1;36;46mS\033[0;1;30;46mX\033[0;5;34;44m8\033[0;5;35;40m;\033[0;1;30;44mS\033[0;34;40m \033[0;32;40m.\033[0;34;40m.\033[0;31;40m \033[0;34;40m \033[0;32;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m .\033[0;1;30;40mX\033[0;1;30;46m@\033[0;1;36;46m%%\033[0;5;36;42mt\033[0;5;37;43m@\033[0;1;32;47m8\033[0;5;36;46m;\033[0;1;36;46m%%S\033[0;1;30;46m@t\033[0;5;36;40m8\033[0;34;40m. \033[0;31;40m \033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m :;\033[0;5;32;40m8\033[0;1;30;46mS\033[0;32;46m8\033[0;5;32;42m.\033[0;1;32;43m8\033[0;5;37;42m88\033[0;1;36;46mX\033[0;1;30;46m.\033[0;5;36;40mX\033[0;30;44m8\033[0;31;40m:\033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;31;40m \033[0;34;40m \033[0;32;40m;\033[0;5;32;40m8\033[0;5;36;40m8\033[0;32;46m8\033[0;5;36;40mt \033[0;1;30;46m8\033[0;5;35;44m8\033[0;37;45m@\033[0;5;35;44m%%\033[0;5;35;40m8\033[0;32;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;32;40m \033[0;31;40m \033[0;34;40m .\033[0;31;40m \033[0;5;34;40mX\033[0;1;30;45m8\033[0;34;45m8\033[0;1;30;45m8\033[0;5;34;44m8\033[0;1;30;45m8\033[0;1;35;47m8\033[0;5;36;44m8\033[0;1;30;40m8\033[0;31;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;31;40m \033[0;30;44m8\033[0;1;34;45m88\033[0;1;30;45m8\033[0;5;35;44m%%\033[0;1;34;45m8\033[0;5;35;44m;\033[0;5;37;45m8\033[0;34;45m@\033[0;34;40m@\033[0;32;40m.\033[0;31;40m.\033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;32;40m \033[0;34;40m \033[0;31;40m :\033[0;5;35;40m8\033[0;1;34;45m8\033[0;1;30;45m8\033[0;5;35;44m%%\033[0;37;45m@\033[0;5;35;44m:\033[0;5;35;45mS\033[0;5;35;44m%%\033[0;35;47m8\033[0;1;30;44m8\033[0;31;40m.\033[0;34;40m.\033[0;32;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;30;44m8\033[0;1;34;45m888\033[0;5;37;45m@\033[0;35;47m8\033[0;5;35;44mt\033[0;35;47m8\033[0;5;35;44mt\033[0;5;35;45m;\033[0;30;44m8\033[0;32;40m;\033[0;31;40m \033[0;32;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;31;40m.\033[0;1;30;40m8\033[0;5;37;45m@\033[0;5;35;44m:\033[0;1;30;45m8\033[0;5;34;44m \033[0;5;35;45m \033[0;1;34;44m8\033[0;1;35;45m.\033[0;5;34;40mX\033[0;34;40m@\033[0;32;40mS\033[0;31;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;31;40m \033[0;34;40m.;\033[0;1;30;40m8\033[0;1;30;44m8\033[0;34;40m8\033[0;5;34;40m8\033[0;32;40m%%\033[0;34;40m8;\033[0;32;40m;\033[0;31;40m.\033[0;32;40m \033[0;31;40m \033[0;34;40m \033[0m\n\r"
"\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;32;40m .\033[0;31;40m .:\033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m \033[0;32;40m \033[0;34;40m \033[0m\n\r",
"\033[0;36mOS\033[0m: KolibriOS", "\033[0;36mKernel\033[0m: ", str_krnl_ver, "\033[0;36mUptime\033[0m: ", str_uptime, "\033[0;36mResolution\033[0m: ", str_resolution, "\033[0;36mCPU\033[0m: ", str_cpu_info, "\033[0;36mMemory\033[0m: ", str_meminfo);
free(str_krnl_ver);
free(str_uptime);
free(str_resolution);
free(str_cpu_info);
free(str_meminfo);
return TRUE;
}

View File

@ -1,36 +1,29 @@
int cmd_kill(char param[])
{
unsigned process;
int result;
int i;
unsigned process;
int result;
int i;
if ( strlen(param) == 0 )
{
printf(" kill <PID>\n\r");
return TRUE;
if ( strlen(param) == 0 ) {
printf(CMD_KILL_USAGE);
return TRUE;
}
if (!strcmp(param, "all"))
{
for (i = 2;i<256;i++)
{
kol_kill_process(i);
if (!strcmp(param, "all")) {
for (i = 2;i<256;i++) {
kol_kill_process(i);
}
return TRUE;
}
else
{
process = _atoi(param);
if ( 0 != process )
{
result = kol_process_kill_pid(process);
if (result < 0)
return FALSE;
else
return TRUE;
return TRUE;
}
else {
process = atoi(param);
if ( 0 != process ) {
result = kol_process_kill_pid(process);
if (result < 0)
return FALSE;
else
return TRUE;
}
}

View File

@ -1,127 +1,126 @@
int cmd_ls(char dir[])
{
int cmd_ls(char dir[]) {
kol_struct70 k70;
unsigned *n;
unsigned num_of_file; // number of files in directory
unsigned *t;
unsigned type_of_file; // check is this a file or a folder
int i, result;
char tmp[FILENAME_MAX];
kol_struct70 k70;
unsigned *n;
unsigned num_of_file; // number of files in directory
unsigned *t;
unsigned type_of_file; // check is this a file or a folder
int i, result;
char tmp[FILENAME_MAX];
bool single_column_mode = FALSE;
bool single_column_mode = FALSE;
k70.p00 = 1;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 2; // just for test exist & read number of entries
k70.p16 = (unsigned) malloc(32+k70.p12*560);
k70.p20 = 0;
k70.p00 = 1;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 2; // just for test exist & read number of entries
k70.p16 = (unsigned) malloc(32+k70.p12*560);
k70.p20 = 0;
if (!strnicmp(dir,"-1",1))
{
single_column_mode = TRUE;
dir += 3;
}
if ( !strlen(dir) ) // if argument is empty, list current directory
k70.p21 = cur_dir;
else
{
if (dir[0] != '/') // if given directory is relative path, then append cur_dir on left side
{
strcpy(tmp, cur_dir);
if (tmp[strlen(tmp)-1] != '/')
{
strcat(tmp, "/"); // add slash
}
strcat(tmp, dir);
k70.p21 = tmp;
} else // if given directory is an absolute path
{
k70.p21 = dir;
}
}
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) ) // check does the directory exists
{
free( (void*) k70.p16);
return FALSE;
}
n = (unsigned*) (k70.p16+8);
num_of_file = *n;
// now read full directory
k70.p12 = num_of_file;
free( (void*) k70.p16);
k70.p16 = (unsigned) malloc(32+k70.p12*560);
if ( !k70.p16 )
return FALSE;
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) )
{
free( (void*) k70.p16);
return FALSE;
}
// if there was '-1' param, then show single column mode
// otherwise show files in several columns
if (single_column_mode == TRUE)
{
_SINGLE_COLUMN_MODE:
for (i = 0; i < num_of_file; i++)
{
printf (" %s", k70.p16+32+40+(264+40)*i);
t = (unsigned*) (k70.p16+32+(264+40)*i);
type_of_file = *t;
if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) )
printf ("/");
printf ("\n\r");
}
}
else
{
int longest_name_len = 0;
int console_window_width = 78; //need to get this value from console.obj if it's possible
for (i = 0; i < num_of_file; i++)
if (!strnicmp(dir,"-1",1))
{
int current_name_len;
current_name_len = strlen( (char*)k70.p16+32+40+(264+40)*i);
if (current_name_len > longest_name_len) longest_name_len = current_name_len;
single_column_mode = TRUE;
dir += 3;
}
longest_name_len+=2; //consider space separator and '/' symbol for folders
int columns_max = console_window_width / longest_name_len;
if (longest_name_len >= console_window_width) goto _SINGLE_COLUMN_MODE; //there was too long filename
for (i = 0; i < num_of_file; i++)
if ( !strlen(dir) ) // if argument is empty, list current directory
k70.p21 = cur_dir;
else
{
if (dir[0] != '/') // if given directory is relative path, then append cur_dir on left side
{
char cur_file[2048];
strncpy(cur_file, (char*)k70.p16+32+40+(304)*i, sizeof(cur_file)-2);
strcpy(tmp, cur_dir);
if (tmp[strlen(tmp)-1] != '/')
{
strcat(tmp, "/"); // add slash
}
strcat(tmp, dir);
k70.p21 = tmp;
} else // if given directory is an absolute path
{
k70.p21 = dir;
}
}
t = (unsigned*) (k70.p16+32+(304)*i);
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) ) // check does the directory exists
{
free( (void*) k70.p16);
return FALSE;
}
n = (unsigned*) (k70.p16+8);
num_of_file = *n;
// now read full directory
k70.p12 = num_of_file;
free( (void*) k70.p16);
k70.p16 = (unsigned) malloc(32+k70.p12*560);
if ( !k70.p16 )
return FALSE;
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) )
{
free( (void*) k70.p16);
return FALSE;
}
// if there was '-1' param, then show single column mode
// otherwise show files in several columns
if (single_column_mode == TRUE)
{
_SINGLE_COLUMN_MODE:
for (i = 0; i < num_of_file; i++)
{
printf (" %s", k70.p16+32+40+(264+40)*i);
t = (unsigned*) (k70.p16+32+(264+40)*i);
type_of_file = *t;
int is_folder = 0;
if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) { is_folder = 1; strcat(cur_file, "/"); }
if (is_folder) { printf("\033[0;36m"); } // set cyan for folder
printf ("%*s", -longest_name_len, cur_file);
if (is_folder) { printf("\033[0m"); } // is had been set, reset
if ((i>0) && ((i+1)%columns_max == 0)) printf ("\n\r");
if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) )
printf ("/");
printf ("\n\r");
}
if ((i)%columns_max != 0) printf("\n\r");
}
free((void*)k70.p16);
return TRUE;
}
else
{
int longest_name_len = 0;
int console_window_width = 78; //need to get this value from console.obj if it's possible
for (i = 0; i < num_of_file; i++)
{
int current_name_len;
current_name_len = strlen( (char*)k70.p16+32+40+(264+40)*i);
if (current_name_len > longest_name_len) longest_name_len = current_name_len;
}
longest_name_len+=2; //consider space separator and '/' symbol for folders
int columns_max = console_window_width / longest_name_len;
if (longest_name_len >= console_window_width) goto _SINGLE_COLUMN_MODE; //there was too long filename
for (i = 0; i < num_of_file; i++)
{
char cur_file[2048];
strncpy(cur_file, (char*)k70.p16+32+40+(304)*i, sizeof(cur_file)-2);
t = (unsigned*) (k70.p16+32+(304)*i);
type_of_file = *t;
int is_folder = 0;
if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) { is_folder = 1; strcat(cur_file, "/"); }
if (is_folder) { printf("\033[0;36m"); } // set cyan for folder
printf ("%*s", -longest_name_len, cur_file);
if (is_folder) { printf("\033[0m"); } // is had been set, reset
if ((i>0) && ((i+1)%columns_max == 0)) printf ("\n\r");
}
if ((i)%columns_max != 0) printf("\n\r");
}
free((void*)k70.p16);
return TRUE;
}

View File

@ -1,51 +1,41 @@
int cmd_mkdir(char dir[])
{
int cmd_mkdir(char dir[]) {
char temp[FILENAME_MAX];
kol_struct70 k70;
unsigned result;
char temp[FILENAME_MAX];
kol_struct70 k70;
unsigned result;
if (NULL == dir)
{
#if LANG_ENG
printf(" mkdir <directory>\n\r");
#elif LANG_RUS
printf(" mkdir <¤¨à¥ªâ®à¨ï>\n\r");
#endif
return TRUE;
if (NULL == dir) {
printf(CMD_MKDIR_USAGE);
return TRUE;
}
if ( 0 == strcmp(dir, ".") || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) )
{
return FALSE;
if ( 0 == strcmp(dir, ".") || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) ) {
return FALSE;
}
k70.p00 = 9;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p00 = 9;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
if ( '/' == dir[0])
k70.p21 = dir;
else
{
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, dir);
k70.p21 = temp;
if ( '/' == dir[0])
k70.p21 = dir;
else {
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, dir);
k70.p21 = temp;
}
result = kol_file_70(&k70);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
return FALSE;
if (0 == result)
return TRUE;
else
return FALSE;
}

View File

@ -1,98 +1,92 @@
int cmd_more(char file[])
{
int cmd_more(char file[]) {
kol_struct70 k70;
kol_struct_BDVK bdvk;
unsigned result, i;
unsigned long long filesize, pos;
char buf[81]; //¡ãä¥à
char temp[FILENAME_MAX];
unsigned flags;
kol_struct70 k70;
kol_struct_BDVK bdvk;
unsigned result, i;
unsigned long long filesize, pos;
char buf[81]; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char temp[FILENAME_MAX];
unsigned flags;
if (strlen(file)<1)
{
#if LANG_ENG
printf (" more <filename>\n\r");
#elif LANG_RUS
printf (" more <¨¬ï ä ©« >\n\r");
#endif
return TRUE;
if (strlen(file)<1) {
printf (CMD_MORE_USAGE);
return TRUE;
}
if ( '/' == file[0])
{
strcpy(temp, file);
if ( !file_check(temp) )
if ( '/' == file[0])
{
file_not_found(file);
return FALSE;
}
}
else
{
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
strcpy(temp, file);
if ( !file_check(temp) )
if ( !file_check(temp) )
{
file_not_found(file);
return FALSE;
}
}
else
{
file_not_found(file);
return FALSE;
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
if ( !file_check(temp) )
{
file_not_found(file);
return FALSE;
}
}
}
k70.p00 = 5;
k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = temp;
result = kol_file_70(&k70); // ¯®«ãç ¥¬ ¨­ä®à¬ æ¨î ® ä ©«¥
if ( 0 != result )
return FALSE;
filesize = bdvk.p32; // ¯®«ãç ¥¬ à §¬¥à ä ©« 
buf[80]=0;
flags = con_get_flags();
for (pos=0;pos<filesize;pos+=80)
{
memset(buf, 0, 80);
k70.p00 = 0;
k70.p04 = pos;
// k70.p08 = 0; // bug for over 4Gb files, but "more" is unusable there
k70.p12 = 80;
k70.p16 = (unsigned) buf;
k70.p00 = 5;
k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = temp;
result = kol_file_70(&k70); // ç⥭¨¥ 80 ᨬ¢®«®¢
for (i=0; i<80; i++)
{
if (27 == buf[i])
con_set_flags(flags|0x100);
else con_set_flags(flags);
printf ("%c", buf[i]);
}
result = kol_file_70(&k70); // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><E0ACA0> <20><><E4A0A9>
if ( 0 != result )
{
con_set_flags(flags);
printf ("\n\r");
return TRUE;
}
return FALSE;
}
con_set_flags(flags);
printf ("\n\r");
return TRUE;
filesize = bdvk.p32; // <20><><EFBFBD><EFBFBD><EFBFBD><><E0A0A7><EFBFBD><><E4A0A9>
buf[80]=0;
flags = con_get_flags();
for (pos=0;pos<filesize;pos+=80)
{
memset(buf, 0, 80);
k70.p00 = 0;
k70.p04 = pos;
// k70.p08 = 0; // bug for over 4Gb files, but "more" is unusable there
k70.p12 = 80;
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = temp;
result = kol_file_70(&k70); // <20><EFBFBD><E2A5AD> 80 ᨬ<><E1A8AC><EFBFBD><EFBFBD><EFBFBD>
for (i=0; i<80; i++)
{
if (27 == buf[i])
con_set_flags(flags|0x100);
else con_set_flags(flags);
printf ("%c", buf[i]);
}
if ( 0 != result )
{
con_set_flags(flags);
printf ("\n\r");
return TRUE;
}
}
con_set_flags(flags);
printf ("\n\r");
return TRUE;
}

View File

@ -24,11 +24,7 @@ int cmd_mv(char param[])
if (argc != 2)
{
#if LANG_ENG
printf(" mv <file_in> <file_out>\n\r");
#elif LANG_RUS
printf(" mv <¨áâ®ç­¨ª> <१ã«ìâ â>\n\r");
#endif
printf(CMD_MV_USAGE);
parameters_free(argc, argv);
return TRUE;
}

View File

@ -1,40 +1,28 @@
int cmd_pkill(char param[])
{
int i=1, n=0; int process_count=0;
char *buf1k=NULL;
int i = 1, n = 0; int process_count = 0;
char *buf1k = NULL;
unsigned PID=0;
#ifdef LANG_RUS
#define PKILL_HELP " pkill <¨¬ï_¯à®æ¥áá >\n\r"
#define PKILL_KILL " PID: %u - 㡨â\n"
#define PKILL_NOT_KILL " PID: %u - ­¥ 㡨â\n"
#define PKILL_NOT_FOUND " <20>à®æ¥áᮢ á â ª¨¬ ¨¬¥­¥¬ ­¥ ­ ©¤¥­®!\n"
#else
#define PKILL_HELP " pkill <process_name>\n\r"
#define PKILL_KILL " PID: %u - killed\n"
#define PKILL_NOT_KILL " PID: %u - not killed\n"
#define PKILL_NOT_FOUND " No processes with this name were found!\n"
#endif
if(!strlen(param)){
printf(PKILL_HELP);
printf(CMD_PKILL_HELP);
return TRUE;
}
buf1k = malloc(1024);
if(buf1k==NULL){
if (buf1k == NULL){
return FALSE;
}
while(i!=n){
while (i != n) {
n = kol_process_info(i, buf1k);
if(!strnicmp(buf1k+10, param, 10)){
memcpy(&PID, buf1k+30 ,sizeof(unsigned));
if(kol_process_kill_pid(PID)){
printf(PKILL_NOT_KILL, PID);
printf(CMD_PKILL_NOT_KILL, PID);
}else{
printf(PKILL_KILL, PID);
printf(CMD_PKILL_KILL, PID);
}
process_count++;
}
@ -42,7 +30,7 @@ int cmd_pkill(char param[])
}
if(!process_count){
printf(PKILL_NOT_FOUND);
printf(CMD_PKILL_NOT_FOUND);
}
free(buf1k);

View File

@ -2,43 +2,39 @@
int cmd_ps(char param[])
{
int i, n, sel;
char *buf1k;
unsigned PID;
short STATE;
int i, n, sel;
char *buf1k;
unsigned PID;
short STATE;
buf1k = malloc(1024);
if (NULL == buf1k)
return FALSE;
buf1k = malloc(1024);
if (NULL == buf1k)
return FALSE;
sel = param && strlen(param) > 0;
sel = param && strlen(param) > 0;
printf (" PID NAME RAM KB\n\r", PID, buf1k+10);
printf (" PID NAME RAM KB\n\r", PID, buf1k+10);
for (i = 1;;i++)
{
n = kol_process_info(i, buf1k);
memcpy(&PID, buf1k+30 ,sizeof(unsigned));
STATE = *(buf1k+50);
if (9 != STATE)
{
if (!sel || 0 == strnicmp(param, buf1k+10, 10))
{
printf (" %7u %11s %d\n\r", PID, buf1k+10, (*(int*)(buf1k+26)+1)/1024);
if (sel)
{
for (i = 1;;i++) {
n = kol_process_info(i, buf1k);
memcpy(&PID, buf1k+30 ,sizeof(unsigned));
STATE = *(buf1k+50);
if (9 != STATE) {
if (!sel || 0 == strnicmp(param, buf1k+10, 10)) {
printf (" %7u %11s %d\n\r", PID, buf1k+10, (*(int*)(buf1k+26)+1)/1024);
if (sel) {
LAST_PID = PID;
int cpu_tck = kol_system_cpufreq() / 100;
printf (" CPU %d%% RAM %d\n\r", *(int*)buf1k / cpu_tck , *(int*)(buf1k+26)+1);
}
}
}
if (i == n)
break;
if (i == n)
break;
}
free(buf1k);
return TRUE;
free(buf1k);
return TRUE;
}

View File

@ -1,7 +1,6 @@
int cmd_pwd(char param[])
{
printf (" %s%c\n\r", cur_dir, cur_dir[strlen(cur_dir)-1]=='/'?' ':'/' );
return TRUE;
int cmd_pwd(char param[]) {
printf (" %s%c\n\r", cur_dir, cur_dir[strlen(cur_dir)-1]=='/'?' ':'/' );
return TRUE;
}

View File

@ -1,10 +1,9 @@
int cmd_reboot(char param[])
{
if (!strcmp(param, "kernel"))
kol_system_end(4);
else
kol_system_end(3);
return TRUE;
int cmd_reboot(char param[]) {
if (!strcmp(param, "kernel"))
kol_system_end(4);
else
kol_system_end(3);
return TRUE;
}

View File

@ -1,6 +1,5 @@
int cmd_ren(char param[])
{
int cmd_ren(char param[]) {
char* argv[100];
int argc;
/*
@ -9,19 +8,14 @@ int cmd_ren(char param[])
*/
argc = parameters_prepare(param, argv);
if (argc != 2)
{
#if LANG_ENG
printf(" ren <file> <new_name>\n\r");
#elif LANG_RUS
printf(" ren <ä ©«> <­®¢®¥_¨¬ï>\n\r");
#endif
if (argc != 2) {
printf(CMD_REN_USAGE);
parameters_free(argc, argv);
return TRUE;
}
char *x;
if (x = strrchr(argv[1], '/') != 0) // argv[1] must be file name, not path
{
//char *x;
// argv[1] must be file name, not path
if (strrchr(argv[1], '/') != NULL) {
//printf("%d %s", x, argv[1]);
return FALSE;
}

View File

@ -1,57 +1,51 @@
int cmd_rm(char file[])
{
int cmd_rm(char file[]) {
kol_struct70 k70;
char temp[FILENAME_MAX];
unsigned result;
kol_struct70 k70;
char temp[FILENAME_MAX];
unsigned result;
if (NULL == file || strlen(file) == 0)
{
#if LANG_ENG
printf (" rm <filename>\n\r");
#elif LANG_RUS
printf (" rm <¨¬ï ä ©« >\n\r");
#endif
return TRUE;
if (NULL == file || strlen(file) == 0) {
printf (CMD_RM_USAGE);
return TRUE;
}
if ( '/' == file[0])
{
strcpy(temp, file);
if ( !file_check(temp) )
if ( '/' == file[0])
{
return FALSE;
}
}
else
{
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
strcpy(temp, file);
if ( !file_check(temp) )
if ( !file_check(temp) )
{
return FALSE;
}
}
else
{
return FALSE;
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
if ( !file_check(temp) )
{
return FALSE;
}
}
}
k70.p00 = 8;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = temp;
k70.p00 = 8;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = temp;
result = kol_file_70(&k70);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
return FALSE;
if (0 == result)
return TRUE;
else
return FALSE;
}

View File

@ -1,53 +1,44 @@
int cmd_rmdir(char dir[])
{
int cmd_rmdir(char dir[]) {
char temp[FILENAME_MAX];
kol_struct70 k70;
unsigned result;
char temp[FILENAME_MAX];
kol_struct70 k70;
unsigned result;
if (NULL == dir || strlen(dir) == 0)
{
#if LANG_ENG
printf(" rmdir <directory>\n\r");
#elif LANG_RUS
printf(" rmdir <¤¨à¥ªâ®à¨ï>\n\r");
#endif
return TRUE;
if (NULL == dir || strlen(dir) == 0) {
printf(CMD_RMDIR_USAGE);
return TRUE;
}
if ( ( 0 == strcmp(dir, ".") ) || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) )
{
return FALSE;
if ( ( 0 == strcmp(dir, ".") ) || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) ) {
return FALSE;
}
k70.p00 = 8;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p00 = 8;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
if ( '/' == dir[0])
k70.p21 = dir;
else
{
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, dir);
k70.p21 = temp;
if ( '/' == dir[0])
k70.p21 = dir;
else {
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, dir);
k70.p21 = temp;
}
if ( !dir_check(temp) )
return FALSE;
if ( !dir_check(temp) )
return FALSE;
result = kol_file_70(&k70);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
return FALSE;
if (0 == result)
return TRUE;
else
return FALSE;
}

View File

@ -1,7 +1,6 @@
int cmd_shutdown(char param[])
{
kol_system_end(2);
return TRUE;
int cmd_shutdown(char param[]) {
kol_system_end(2);
return TRUE;
}

View File

@ -1,20 +1,12 @@
int cmd_sleep(char param[])
{
int delay;
if (!strlen(param))
{
#if LANG_ENG
printf(" sleep <time in the 1/100 of second>\n\r");
#elif LANG_RUS
printf(" sleep <¨­â¥à¢ « ¢ á®âëå ¤®«ïx ᥪ㭤ë>\n\r");
#endif
return TRUE;
int cmd_sleep(char param[]) {
int delay;
if (!strlen(param)) {
printf(CMD_SLEEP_USAGE);
return TRUE;
}
delay = _atoi(param);
kol_sleep((unsigned)delay);
return TRUE;
delay = atoi(param);
kol_sleep((unsigned)delay);
return TRUE;
}

View File

@ -1,61 +1,51 @@
int cmd_touch(char file[])
{
kol_struct70 k70;
char temp[FILENAME_MAX];
unsigned result;
kol_struct70 k70;
char temp[FILENAME_MAX];
unsigned result;
if (NULL == file || strlen(file) == 0)
{
#if LANG_ENG
printf(" touch <filename>\n\r");
#elif LANG_RUS
printf(" touch <¨¬ï ä ©« >\n\r");
#endif
return TRUE;
if (NULL == file || strlen(file) == 0) {
printf(CMD_TOUCH_USAGE);
return TRUE;
}
if ( ( 0 == strcmp(file, ".") ) || ( 0 == strcmp(file, "..") ) || ( 0 == strcmp(cur_dir, "/")) )
{
return FALSE;
if ( ( 0 == strcmp(file, ".") ) || ( 0 == strcmp(file, "..") ) || ( 0 == strcmp(cur_dir, "/")) ) {
return FALSE;
}
if ( '/' == file[0])
{
strcpy(temp, file);
if ( '/' == file[0]) {
strcpy(temp, file);
if ( !file_check(temp) )
k70.p00 = 2;
if ( !file_check(temp) )
k70.p00 = 2;
else
k70.p00 = 3;
} else {
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
if ( !file_check(temp) )
k70.p00 = 2;
else
k70.p00 = 3;
}
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = temp;
//printf("try to touch [%s], fn70(%d)\n\r", temp, k70.p00);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
k70.p00 = 3;
}
else
{
strcpy(temp, cur_dir);
if (temp[strlen(temp)-1] != '/')
strcat(temp, "/"); // add slash
strcat(temp, file);
if ( !file_check(temp) )
k70.p00 = 2;
else
k70.p00 = 3;
}
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = temp;
//printf("try to touch [%s], fn70(%d)\n\r", temp, k70.p00);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
return FALSE;
return FALSE;
}

View File

@ -1,20 +1,20 @@
int cmd_uptime(char param[])
{
unsigned time_tick, up_days, up_hours, up_minutes, up_seconds, up_millisecs;
void get_str_uptime(char *str, const char *fmt) {
unsigned time_tick, up_days, up_hours, up_minutes, up_seconds, up_millisecs;
time_tick = kol_time_tick();
up_days = (time_tick/(24*60*60*100));
up_hours = (time_tick/(60*60*100))%24;
up_minutes = (time_tick/(60*100))%60;
up_seconds = (time_tick/100)%60;
up_millisecs = (time_tick*10)%100;
time_tick = kol_time_tick();
up_days = (time_tick/(24*60*60*100));
up_hours = (time_tick/(60*60*100))%24;
up_minutes = (time_tick/(60*100))%60;
up_seconds = (time_tick/100)%60;
up_millisecs = (time_tick*10)%100;
#if LANG_ENG
printf (" Uptime: %d day(s), %d:%d:%d.%d\n\r", up_days, up_hours, up_minutes, up_seconds, up_millisecs);
#elif LANG_RUS
printf (" Uptime: %d ¤­¥©, %d:%d:%d.%d\n\r", up_days, up_hours, up_minutes, up_seconds, up_millisecs);
#endif
return TRUE;
sprintf (str, fmt, up_days, up_hours, up_minutes, up_seconds, up_millisecs);
}
int cmd_uptime(char param[]) {
get_str_uptime(tmpstr, CMD_UPTIME_FMT);
printf(tmpstr);
return TRUE;
}

View File

@ -1,45 +1,31 @@
int cmd_ver(char param[])
{
void get_str_kernel_version(char *str, const char *fmt) {
char *kvbuf;
char *vA, *vB, *vC, *vD;
unsigned *Rev;
if (!strcmp(param, "kernel"))
{
char *kvbuf;
char *vA, *vB, *vC, *vD;
unsigned *Rev;
kvbuf = malloc(16);
kol_get_kernel_ver(kvbuf);
vA = kvbuf+0;
vB = kvbuf+1;
vC = kvbuf+2;
vD = kvbuf+3;
Rev = (unsigned*)(kvbuf + 5);
kvbuf = malloc(16);
kol_get_kernel_ver(kvbuf);
vA = kvbuf+0;
vB = kvbuf+1;
vC = kvbuf+2;
vD = kvbuf+3;
Rev = (unsigned*)(kvbuf + 5);
sprintf (str, fmt, *vA, *vB, *vC, *vD, *Rev);
#if LANG_ENG
printf (" KolibriOS v%d.%d.%d.%d. Kernel SVN-rev.: %d\n\r", *vA, *vB, *vC, *vD, *Rev);
#elif LANG_RUS
printf (" KolibriOS v%d.%d.%d.%d. SVN-ॢ. ï¤à : %d\n\r", *vA, *vB, *vC, *vD, *Rev);
#endif
free(kvbuf);
}
free(kvbuf);
void get_str_cpu_info(char *str) {
unsigned a, b, c, d;
return TRUE;
}
if (!strcmp(param, "cpu"))
{
unsigned a, b, c, d;
char str[13];
str[12] = '\0';
asm ("cpuid" :
"=a" (a),
"=b" (b),
"=c" (c),
"=d" (d):
"a"(0));
asm ("cpuid" :
"=a" (a),
"=b" (b),
"=c" (c),
"=d" (d):
"a"(0));
str[0] = (b&0x000000ff) >> 0;
str[1] = (b&0x0000ff00) >> 8;
@ -55,13 +41,24 @@ if (!strcmp(param, "cpu"))
str[9] = (c&0x0000ff00) >> 8;
str[10] = (c&0x00ff0000) >> 16;
str[11] = (c&0xff000000) >> 24;
printf("%s\n\r", str);
return TRUE;
}
printf (" Shell v%s\n\r", SHELL_VERSION);
return TRUE;
str[12] = '\0';
}
int cmd_ver(char param[]) {
if (!strcmp(param, "kernel")) {
get_str_kernel_version(tmpstr, CMD_VER_FMT1);
printf(tmpstr);
return TRUE;
}
if (!strcmp(param, "cpu")) {
char str[13];
get_str_cpu_info(str);
printf("%s\n\r", str);
return TRUE;
}
printf (" Shell v%s\n\r", SHELL_VERSION);
return TRUE;
}

View File

@ -1,52 +1,42 @@
int cmd_waitfor(char param[])
// waits for LASTPID or pid in param
{
/* waits for LASTPID or pid in param */
int cmd_waitfor(char param[]) {
int i, n, sel, sel_pid;
char *buf1k;
unsigned PID;
short STATE;
int i, n, sel, sel_pid;
char *buf1k;
unsigned PID;
short STATE;
sel = param && strlen(param) > 0;
sel_pid = LAST_PID;
if (sel)
{
sel_pid = _atoi(param);
sel = param && strlen(param) > 0;
sel_pid = LAST_PID;
if (sel) {
sel_pid = atoi(param);
}
if (0 == sel_pid)
return FALSE;
if (0 == sel_pid) return FALSE;
#if LANG_ENG
printf(" Awaing finish PID %d\n\r", sel_pid);
#elif LANG_RUS
printf(" Ž¦¨¤ ¥¬ § ¢¥à襭¨ï PID %d\n\r", sel_pid);
#endif
printf(CMD_WAITFOR_FMT, sel_pid);
buf1k = malloc(1024);
if (NULL == buf1k)
return FALSE;
buf1k = malloc(1024);
if (NULL == buf1k)
return FALSE;
while(1)
{
for (i = 1;;i++)
{
n = kol_process_info(i, buf1k);
PID = *(buf1k+30);
STATE = *(buf1k+50);
if (PID == sel_pid)
if(9 == STATE)
while(1) {
for (i = 1;;i++) {
n = kol_process_info(i, buf1k);
PID = *(buf1k+30);
STATE = *(buf1k+50);
if (PID == sel_pid)
if(9 == STATE)
goto exit_normal;
else break;
if (i == n)
goto exit_normal;
else break;
if (i == n)
goto exit_normal;
}
kol_sleep(10); // 100ms
kol_sleep(10); // 100ms
}
exit_normal:
free(buf1k);
return TRUE;
exit_normal:
free(buf1k);
return TRUE;
}

View File

@ -1,15 +0,0 @@
@echo off
echo #define LANG_ENG 1 > lang.h
fasm start.asm start.o
gcc -c -fno-builtin shell.c
gcc -c -fno-builtin system/kolibri.c
gcc -c -fno-builtin system/stdlib.c
gcc -c -fno-builtin system/string.c
gcc -c -fno-builtin system/ctype.c
ld -nostdlib -T kolibri.ld -o shell start.o kolibri.o stdlib.o string.o ctype.o shell.o
objcopy shell -O binary
erase lang.h start.o shell.o kolibri.o stdlib.o string.o
kpack shell
move shell bin\eng\
copy locale\eng\.shell bin\eng\
pause

View File

@ -1,15 +0,0 @@
@echo off
echo #define LANG_RUS 1 > lang.h
fasm start.asm start.o
gcc -c -fno-builtin shell.c
gcc -c -fno-builtin system/kolibri.c
gcc -c -fno-builtin system/stdlib.c
gcc -c -fno-builtin system/string.c
gcc -c -fno-builtin system/ctype.c
ld -nostdlib -T kolibri.ld -o shell start.o kolibri.o stdlib.o string.o ctype.o shell.o
objcopy shell -O binary
erase lang.h start.o shell.o kolibri.o stdlib.o string.o ctype.o
kpack shell
move shell bin\rus\
copy locale\rus\.shell bin\rus\
pause

View File

@ -1,14 +0,0 @@
@echo off
fasm start.asm start.o
gcc -c -fno-builtin test.c
gcc -c -fno-builtin system/kolibri.c
gcc -c -fno-builtin system/stdlib.c
gcc -c -fno-builtin system/string.c
gcc -c -fno-builtin system/ctype.c
ld -nostdlib -T kolibri.ld -o test start.o kolibri.o stdlib.o string.o ctype.o test.o
objcopy test -O binary
erase start.o kolibri.o stdlib.o string.o ctype.o test.o
kpack test
copy test bin\eng\
move test bin\rus\
pause

View File

@ -1,6 +0,0 @@
@echo off
fasm test.asm test_asm
kpack test_asm
copy test_asm bin\eng\
move test_asm bin\rus\
pause

View File

@ -1,8 +1,9 @@
#define SHELL_VERSION "0.8.1"
#define SHELL_VERSION "0.8.2"
extern char PATH[256];
extern char PARAM[256];
char cmdline[256];
char tmpstr[64];
char title[64];
char cur_dir[FILENAME_MAX];
@ -67,6 +68,7 @@ int cmd_shutdown(char arg[]);
int cmd_uptime(char param[]);
int cmd_killall(char process_name[]);
int cmd_history(char arg[]);
int cmd_kfetch(char param[]);
int cmd_cp(char param[]);
int cmd_mv(char param[]);
int cmd_ren(char param[]);

View File

@ -14,6 +14,7 @@ const command_t COMMANDS[]=
{"free", " Displays total, free and used memory\n\r", &cmd_memory},
{"help", " Gives help on commands. Usage:\n\r help ;it lists all builtins\n\r help <command> ;help on command\n\r", &cmd_help},
{"history", " Lists used commands\n\r", &cmd_history},
{"kfetch", " Prints logo and information about system.\n\r", &cmd_kfetch},
{"kill", " Stops a running process. Usage:\n\r kill <PID of process>\n\r kill all\n\r", &cmd_kill},
{"pkill", " Kills all processes by name. Usage:\n\r pkill <process_name>\n\r", &cmd_pkill},
{"ls", " Lists the files in a directory. Usage:\n\r ls ;lists the files in current directory\n\r ls <directory> ;lists the files at specified folder\n\r ls -1 ;lists the files in a single column\n\r", &cmd_ls},
@ -32,3 +33,35 @@ const command_t COMMANDS[]=
{"waitfor", " Stops console waiting while process finish. Usage:\n\r waitfor ;waiting previous started executable LASTPID\n\r waitfor <PID>;awaiting PID finish\n\r", &cmd_waitfor},
};
#define CMD_ABOUT_MSG "Shell %s\n\r"
#define CMD_CD_USAGE " cd <directory>\n\r"
#define CMD_CP_USAGE " cp <file_in> <file_out>\n\r"
#define CMD_DATE_DATE_FMT " Date [dd.mm.yy]: %x%x.%x%x.%x%x"
#define CMD_DATE_TIME_FMT "\n\r Time [hh:mm:ss]: %x%x:%x%x:%x%x\n\r"
#define CMD_FREE_FMT " Total [kB / MB / %%]: %-7d / %-5d / 100\n\r Free [kB / MB / %%]: %-7d / %-5d / %d\n\r Used [kB / MB / %%]: %-7d / %-5d / %d\n\r"
#define CMD_HELP_AVAIL " %d commands available:\n\r"
#define CMD_HELP_CMD_NOT_FOUND " Command \'%s\' not found.\n\r"
#define CMD_KILL_USAGE " kill <PID>\n\r"
#define CMD_MKDIR_USAGE " mkdir <directory>\n\r"
#define CMD_MORE_USAGE " more <filename>\n\r"
#define CMD_MV_USAGE " mv <file_in> <file_out>\n\r"
#define CMD_PKILL_HELP " pkill <process_name>\n\r"
#define CMD_PKILL_KILL " PID: %u - killed\n"
#define CMD_PKILL_NOT_KILL " PID: %u - not killed\n"
#define CMD_PKILL_NOT_FOUND " No processes with this name were found!\n"
#define CMD_REN_USAGE " ren <file> <new_name>\n\r"
#define CMD_RM_USAGE " rm <filename>\n\r"
#define CMD_RMDIR_USAGE " rmdir <directory>\n\r"
#define CMD_SLEEP_USAGE " sleep <time in the 1/100 of second>\n\r"
#define CMD_TOUCH_USAGE " touch <filename>\n\r"
#define CMD_UPTIME_FMT " Uptime: %d day(s), %d:%d:%d.%d\n\r"
#define CMD_VER_FMT1 " KolibriOS v%d.%d.%d.%d. Kernel SVN-rev.: %d\n\r"
#define CMD_WAITFOR_FMT " Awaing finish PID %d\n\r"
#define EXEC_STARTED_FMT " '%s' started. PID = %d\n\r"
#define EXEC_SCRIPT_ERROR_FMT "Error in '%s' : script must start with #SHS line\n\r"
#define UNKNOWN_CMD_ERROR " Error!\n\r"
#define CON_APP_ERROR " Error in console application.\n\r"
#define FILE_NOT_FOUND_ERROR " File '%s' not found.\n\r"

View File

@ -1,34 +1,67 @@
/* WARNING: SAVE ONLY IN CP866 ENCODING! */
const command_t COMMANDS[]=
{
{"about", " ‚뢮¤¨â ¨­ä®à¬ æ¨î ® ¯à®£à ¬¬¥ Shell\n\r", &cmd_about},
{"alias", " <20>®ª §ë¢ ¥â ¨ ¯®§¢®«ï¥â ¨§¬¥­¨âì ᯨ᮪ ᨭ®­¨¬®¢ ª®¬ ­¤\n\r", &cmd_alias},
{"cd", " ˆ§¬¥­ï¥â ⥪ãéãî ¤¥à¨ªâ®à¨î. ˆá¯®«ì§®¢ ­¨¥:\n\r cd <¤¨à¥ªâ®à¨ï>\n\r", &cmd_cd},
{"clear", " Žç¨é ¥â íªà ­\n\r", &cmd_clear},
{"cp", " Š®¯¨àã¥â ä ©«\n\r", &cmd_cp},
{"mv", " <20>¥à¥¬¥é ¥â ä ©«\n\r", &cmd_mv},
{"ren", " <20>¥à¥¨¬¥­®¢ë¢ ¥â ä ©«\n\r", &cmd_ren},
{"date", " <20>®ª §ë¢ ¥â ⥪ãéãî ¤ âã ¨ ¢à¥¬ï\n\r", &cmd_date},
{"echo", " ‚뢮¤¨â ¤ ­­ë¥ ­  íªà ­. ˆá¯®«ì§®¢ ­¨¥:\n\r echo <¤ ­­ë¥>\n\r", &cmd_echo},
{"exit", " ‡ ¢¥à襭¨¥ à ¡®âë Shell\n\r", &cmd_exit},
{"free", " <20>®ª §ë¢ ¥â ®¡êñ¬ ®¯¥à â¨¢­®© ¯ ¬ïâ¨: ¢á¥©, ᢮¡®¤­®© ¨ ¨á¯®«ì§ã¥¬®©\n\r", &cmd_memory},
{"help", " ‘¯à ¢ª  ¯® ª®¬ ­¤ ¬. ˆá¯®«ì§®¢ ­¨¥:\n\r help ;ᯨ᮪ ¢á¥å ª®¬ ­¤\n\r help <ª®¬ ­¤ > ;á¯à ¢ª  ¯® ª®¬ ­¤¥\n\r", &cmd_help},
{"history", " ‘¯¨á®ª ¨á¯®«ì§®¢ ­­ëå ª®¬ ­¤\n\r", &cmd_history},
{"kill", " “¡¨¢ ¥â ¯à®æ¥áá. ˆá¯®«ì§®¢ ­¨¥:\n\r kill <PID ¯à®æ¥áá >\n\r kill all\n\r", &cmd_kill},
{"pkill", " “¡¨¢ ¥â ¢á¥ ¯à®æ¥ááë ¯® ¨¬¥­¨. ˆá¯®«ì§®¢ ­¨¥:\n\r pkill <¨¬ï_¯à®æ¥áá >\n\r", &cmd_pkill},
{"ls", " ‚뢮¤¨â ᯨ᮪ ä ©«®¢. ˆá¯®«ì§®¢ ­¨¥:\n\r ls ;ᯨ᮪ ä ©«®¢ ¢ ⥪ã饬 ª â «®£¥\n\r ls <¤¨à¥ªâ®à¨ï> ;ᯨ᮪ ä ©«®¢ ¨§ § ¤ ­­®© ¤¨à¥ªâ®à¨¨\n\r", &cmd_ls},
{"mkdir", " ‘®§¤ ¥â ª â «®£. ˆá¯®«ì§®¢ ­¨¥:\n\r mkdir <¨¬ï ¯ ¯ª¨> ;ᮧ¤ âì ¯ ¯ªã ¢ ⥪ã饬 ª â «®£¥\n\r mkdir <¯ãâì><¨¬ï ¯ ¯ª¨> ;ᮧ¤ âì ¯ ¯ªã ¯® 㪠§ ­­®¬ã ¯ãâ¨\n\r", &cmd_mkdir},
{"more", " ‚뢮¤¨â ᮤ¥à¦¨¬®¥ ä ©«  ­  íªà ­. ˆá¯®«ì§®¢ ­¨¥:\n\r more <¨¬ï ä ©« >\n\r", &cmd_more},
{"ps", " ‚뢮¤¨â ᯨ᮪ ¯à®æ¥áᮢ\n\r …᫨ 㪠§ ­® <¨¬ï¯à®æ¥áá >, ¯®ª §ë¢ ¥â ¡®«ìè¥ ¤ ­­ëå ¨ á®åà ­ï¥â LASTPID\n\r", &cmd_ps},
{"pwd", " <20>®ª §ë¢ ¥â ¨¬ï ⥪ã饩 ¤¨à¥ªâ®à¨¨\n\r", &cmd_pwd},
{"reboot", " <20>¥à¥§ £à㦠¥â ª®¬¯ìîâ¥à ¨«¨ ï¤à® KolibriOS. ˆá¯®«ì§®¢ ­¨¥:\n\r reboot ;¯¥à¥§ £à㧨âì <20>Š\n\r reboot kernel ;¯¥à¥§ ¯ãáâ¨âì ï¤à® Kolibri\n\r", &cmd_reboot},
{"rm", " “¤ «ï¥â ä ©«. ˆá¯®«ì§®¢ ­¨¥:\n\r rm <¨¬ï ä ©« >\n\r", &cmd_rm},
{"rmdir", " “¤ «ï¥â ¯ ¯ªã. ˆá¯®«ì§®¢ ­¨¥:\n\r rmdir <¤¨à¥ªâ®à¨ï>\n\r", &cmd_rmdir},
{"shutdown"," ‚몫î砥⠪®¬¯ìîâ¥à\n\r", &cmd_shutdown},
{"sleep", " Žáâ ­ ¢«¨¢ ¥â à ¡®âã Shell'  ­  § ¤ ­­®¥ ¢à¥¬ï. ˆá¯®«ì§®¢ ­¨¥:\n\r sleep <¨­â¥à¢ « ¢ á®âëå ¤®«ï ᥪ㭤ë>\n\r <20>ਬ¥à:\n\r sleep 500 ;¯ ã§  ­  5 ᥪ.\n\r", &cmd_sleep},
{"touch", " ‘®§¤ ñâ ¯ãá⮩ ä ©« ¨«¨ ¨§¬¥­ï¥â ¤ âã/¢à¥¬ï ᮧ¤ ­¨ï ä ©« . ˆá¯®«ì§®¢ ­¨¥:\n\r touch <¨¬ï ä ©« >\n\r", &cmd_touch},
{"uptime", " <20>®ª §ë¢ ¥â uptime\n\r", &cmd_uptime},
{"ver", " <20>®ª §ë¢ ¥â ¢¥àá¨î. ˆá¯®«ì§®¢ ­¨¥:\n\r ver ;¢¥àá¨ï Shell\n\r ver kernel ;¢¥àá¨ï ¨ ­®¬¥à ॢ¨§¨¨ ï¤à  KolibriOS\n\r ver cpu ;¨­ä®à¬ æ¨ï ® ¯à®æ¥áá®à¥\n\r", &cmd_ver},
{"waitfor", " <20>ਮáâ ­ ¢«¨¢ ¥â ¢ë¯®«­¥­¨¥ ª®¬ ­¤. ˆá¯®«ì§®¢ ­¨¥:\n\r waitfor ;®¦¨¤ ¥¬ ¯à¥¤ë¤ã騩 § ¯ã饭­ë© ¯à®æ¥áá LASTPID\n\r waitfor <PID>;¦¤¥¬ § ¢¥à襭¨ï ¯à®æ¥áá  á 㪠§ ­­ë¬ PID\n\r", &cmd_waitfor},
{"about", " ‚뢮¤¨â ¨­ä®à¬ æ¨î ® ¯à®£à ¬¬¥ Shell\n\r", &cmd_about},
{"alias", " <20>®ª §ë¢ ¥â ¨ ¯®§¢®«ï¥â ¨§¬¥­¨âì ᯨ᮪ ᨭ®­¨¬®¢ ª®¬ ­¤\n\r", &cmd_alias},
{"cd", " ˆ§¬¥­ï¥â ⥪ãéãî ¤¥à¨ªâ®à¨î. ˆá¯®«ì§®¢ ­¨¥:\n\r cd <¤¨à¥ªâ®à¨ï>\n\r", &cmd_cd},
{"clear", " Žç¨é ¥â íªà ­\n\r", &cmd_clear},
{"cp", " Š®¯¨àã¥â ä ©«\n\r", &cmd_cp},
{"mv", " <20>¥à¥¬¥é ¥â ä ©«\n\r", &cmd_mv},
{"ren", " <20>¥à¥¨¬¥­®¢ë¢ ¥â ä ©«\n\r", &cmd_ren},
{"date", " <20>®ª §ë¢ ¥â ⥪ãéãî ¤ âã ¨ ¢à¥¬ï\n\r", &cmd_date},
{"echo", " ‚뢮¤¨â ¤ ­­ë¥ ­  íªà ­. ˆá¯®«ì§®¢ ­¨¥:\n\r echo <¤ ­­ë¥>\n\r", &cmd_echo},
{"exit", " ‡ ¢¥à襭¨¥ à ¡®âë Shell\n\r", &cmd_exit},
{"free", " <20>®ª §ë¢ ¥â ®¡êñ¬ ®¯¥à â¨¢­®© ¯ ¬ïâ¨: ¢á¥©, ᢮¡®¤­®© ¨ ¨á¯®«ì§ã¥¬®©\n\r", &cmd_memory},
{"help", " ‘¯à ¢ª  ¯® ª®¬ ­¤ ¬. ˆá¯®«ì§®¢ ­¨¥:\n\r help ;ᯨ᮪ ¢á¥å ª®¬ ­¤\n\r help <ª®¬ ­¤ > ;á¯à ¢ª  ¯® ª®¬ ­¤¥\n\r", &cmd_help},
{"history", " ‘¯¨á®ª ¨á¯®«ì§®¢ ­­ëå ª®¬ ­¤\n\r", &cmd_history},
{"kfetch", " <20>¥ç â ¥â «®£® ¨ ¨­ä®à¬ æ¨î ® á¨á⥬¥.\n\r", &cmd_kfetch},
{"kill", " “¡¨¢ ¥â ¯à®æ¥áá. ˆá¯®«ì§®¢ ­¨¥:\n\r kill <PID ¯à®æ¥áá >\n\r kill all\n\r", &cmd_kill},
{"pkill", " “¡¨¢ ¥â ¢á¥ ¯à®æ¥ááë ¯® ¨¬¥­¨. ˆá¯®«ì§®¢ ­¨¥:\n\r pkill <¨¬ï_¯à®æ¥áá >\n\r", &cmd_pkill},
{"ls", " ‚뢮¤¨â ᯨ᮪ ä ©«®¢. ˆá¯®«ì§®¢ ­¨¥:\n\r ls ;ᯨ᮪ ä ©«®¢ ¢ ⥪ã饬 ª â «®£¥\n\r ls <¤¨à¥ªâ®à¨ï> ;ᯨ᮪ ä ©«®¢ ¨§ § ¤ ­­®© ¤¨à¥ªâ®à¨¨\n\r", &cmd_ls},
{"mkdir", " ‘®§¤ ¥â ª â «®£. ˆá¯®«ì§®¢ ­¨¥:\n\r mkdir <¨¬ï ¯ ¯ª¨> ;ᮧ¤ âì ¯ ¯ªã ¢ ⥪ã饬 ª â «®£¥\n\r mkdir <¯ãâì><¨¬ï ¯ ¯ª¨> ;ᮧ¤ âì ¯ ¯ªã ¯® 㪠§ ­­®¬ã ¯ãâ¨\n\r", &cmd_mkdir},
{"more", " ‚뢮¤¨â ᮤ¥à¦¨¬®¥ ä ©«  ­  íªà ­. ˆá¯®«ì§®¢ ­¨¥:\n\r more <¨¬ï ä ©« >\n\r", &cmd_more},
{"ps", " ‚뢮¤¨â ᯨ᮪ ¯à®æ¥áᮢ\n\r …᫨ 㪠§ ­® <¨¬ï¯à®æ¥áá >, ¯®ª §ë¢ ¥â ¡®«ìè¥ ¤ ­­ëå ¨ á®åà ­ï¥â LASTPID\n\r", &cmd_ps},
{"pwd", " <20>®ª §ë¢ ¥â ¨¬ï ⥪ã饩 ¤¨à¥ªâ®à¨¨\n\r", &cmd_pwd},
{"reboot", " <20>¥à¥§ £à㦠¥â ª®¬¯ìîâ¥à ¨«¨ ï¤à® KolibriOS. ˆá¯®«ì§®¢ ­¨¥:\n\r reboot ;¯¥à¥§ £à㧨âì <20>Š\n\r reboot kernel ;¯¥à¥§ ¯ãáâ¨âì ï¤à® Kolibri\n\r", &cmd_reboot},
{"rm", " “¤ «ï¥â ä ©«. ˆá¯®«ì§®¢ ­¨¥:\n\r rm <¨¬ï ä ©« >\n\r", &cmd_rm},
{"rmdir", " “¤ «ï¥â ¯ ¯ªã. ˆá¯®«ì§®¢ ­¨¥:\n\r rmdir <¤¨à¥ªâ®à¨ï>\n\r", &cmd_rmdir},
{"shutdown"," ‚몫î砥⠪®¬¯ìîâ¥à\n\r", &cmd_shutdown},
{"sleep", " Žáâ ­ ¢«¨¢ ¥â à ¡®âã Shell'  ­  § ¤ ­­®¥ ¢à¥¬ï. ˆá¯®«ì§®¢ ­¨¥:\n\r sleep <¨­â¥à¢ « ¢ á®âëå ¤®«ï ᥪ㭤ë>\n\r <20>ਬ¥à:\n\r sleep 500 ;¯ ã§  ­  5 ᥪ.\n\r", &cmd_sleep},
{"touch", " ‘®§¤ ñâ ¯ãá⮩ ä ©« ¨«¨ ¨§¬¥­ï¥â ¤ âã/¢à¥¬ï ᮧ¤ ­¨ï ä ©« . ˆá¯®«ì§®¢ ­¨¥:\n\r touch <¨¬ï ä ©« >\n\r", &cmd_touch},
{"uptime", " <20>®ª §ë¢ ¥â uptime\n\r", &cmd_uptime},
{"ver", " <20>®ª §ë¢ ¥â ¢¥àá¨î. ˆá¯®«ì§®¢ ­¨¥:\n\r ver ;¢¥àá¨ï Shell\n\r ver kernel ;¢¥àá¨ï ¨ ­®¬¥à ॢ¨§¨¨ ï¤à  KolibriOS\n\r ver cpu ;¨­ä®à¬ æ¨ï ® ¯à®æ¥áá®à¥\n\r", &cmd_ver},
{"waitfor", " <20>ਮáâ ­ ¢«¨¢ ¥â ¢ë¯®«­¥­¨¥ ª®¬ ­¤. ˆá¯®«ì§®¢ ­¨¥:\n\r waitfor ;®¦¨¤ ¥¬ ¯à¥¤ë¤ã騩 § ¯ã饭­ë© ¯à®æ¥áá LASTPID\n\r waitfor <PID>;¦¤¥¬ § ¢¥à襭¨ï ¯à®æ¥áá  á 㪠§ ­­ë¬ PID\n\r", &cmd_waitfor},
};
#define CMD_ABOUT_MSG "Shell %s\n\r"
#define CMD_CD_USAGE " cd <¤¨à¥ªâ®à¨ï>\n\r"
#define CMD_CP_USAGE " cp <¨áâ®ç­¨ª> <१ã«ìâ â>\n\r"
#define CMD_DATE_DATE_FMT " „ â  [¤¤.¬¬.££]: %x%x.%x%x.%x%x"
#define CMD_DATE_TIME_FMT "\n\r ‚६ï [çç:¬¬:áá]: %x%x:%x%x:%x%x\n\r"
#define CMD_FREE_FMT " ‚ᥣ® [Š<> / Œ<> / %%]: %-7d / %-5d / 100\n\r ‘¢®¡®¤­® [Š<> / Œ<> / %%]: %-7d / %-5d / %d\n\r ˆá¯®«ì§ã¥âáï [Š<> / Œ<> / %%]: %-7d / %-5d / %d\n\r"
#define CMD_HELP_AVAIL " Š®«¨ç¥á⢮ ¤®áâ㯭ëå ª®¬ ­¤: %d\n\r"
#define CMD_HELP_CMD_NOT_FOUND " Š®¬ ­¤  \'%s\' ­¥ ­ ©¤¥­ .\n\r"
#define CMD_KILL_USAGE " kill <PID>\n\r"
#define CMD_MKDIR_USAGE " mkdir <¤¨à¥ªâ®à¨ï>\n\r"
#define CMD_MORE_USAGE " more <¨¬ï ä ©« >\n\r"
#define CMD_MV_USAGE " mv <¨áâ®ç­¨ª> <१ã«ìâ â>\n\r"
#define CMD_PKILL_HELP " pkill <¨¬ï ¯à®æ¥áá >\n\r"
#define CMD_PKILL_KILL " PID: %u - 㡨â\n"
#define CMD_PKILL_NOT_KILL " PID: %u - ­¥ 㡨â\n"
#define CMD_PKILL_NOT_FOUND " <20>à®æ¥áᮢ á â ª¨¬ ¨¬¥­¥¬ ­¥ ­ ©¤¥­®!\n"
#define CMD_REN_USAGE " ren <ä ©«> <­®¢®¥ ¨¬ï>\n\r"
#define CMD_RM_USAGE " rm <¨¬ï ä ©« >\n\r"
#define CMD_RMDIR_USAGE " rmdir <¤¨à¥ªâ®à¨ï>\n\r"
#define CMD_SLEEP_USAGE " sleep <¨­â¥à¢ « ¢ á®âëå ¤®«ïx ᥪ㭤ë>\n\r"
#define CMD_TOUCH_USAGE " touch <¨¬ï ä ©« >\n\r"
#define CMD_UPTIME_FMT " Uptime: %d ¤­¥©, %d:%d:%d.%d\n\r"
#define CMD_VER_FMT1 " KolibriOS v%d.%d.%d.%d. SVN-ॢ. ï¤à : %d\n\r"
#define CMD_WAITFOR_FMT " Ž¦¨¤ ¥¬ § ¢¥à襭¨ï PID %d\n\r"
#define EXEC_STARTED_FMT " '%s' § ¯ã饭. PID = %d\n\r"
#define EXEC_SCRIPT_ERROR_FMT "Žè¨¡ª  ¢ '%s' : áªà¨¯â ¤®«¦¥­ ­ ç¨­ âìáï á® áâà®çª¨ #SHS\n\r"
#define UNKNOWN_CMD_ERROR " Žè¨¡ª !\n\r"
#define CON_APP_ERROR " Žè¨¡ª  ¢ ª®­á®«ì­®¬ ¯à¨«®¦¥­¨¨.\n\r"
#define FILE_NOT_FOUND_ERROR " ” ©« '%s' ­¥ ­ ©¤¥­.\n\r"

View File

@ -1,29 +1,25 @@
/// ===========================================================
void command_history_add() {
int i;
void command_history_add()
{
if ('\0' == CMD[0]) return;
int i;
CMD_NUM = -1;
if ('\0' == CMD[0]) return;
for (i = 0; i < CMD_HISTORY_NUM_REAL; i++)
if ( 0 == strcmp( CMD_HISTORY[i], CMD ) )
return;
CMD_NUM = -1;
for (i = CMD_HISTORY_NUM_REAL; i > 0 ; i--)
strcpy(CMD_HISTORY[i], CMD_HISTORY[i-1]);
for (i = 0; i < CMD_HISTORY_NUM_REAL; i++)
if ( 0 == strcmp( CMD_HISTORY[i], CMD ) )
return;
strcpy(CMD_HISTORY[0], CMD);
for (i = CMD_HISTORY_NUM_REAL; i > 0 ; i--)
strcpy(CMD_HISTORY[i], CMD_HISTORY[i-1]);
strcpy(CMD_HISTORY[0], CMD);
if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM-1)
CMD_HISTORY_NUM_REAL++;
if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM-1)
CMD_HISTORY_NUM_REAL++;
}
// ============================================================
char * insert_string( char s1[], unsigned int pos, const char s2[] )
{
@ -48,362 +44,346 @@ char * insert_string( char s1[], unsigned int pos, const char s2[] )
return s1;
}
/// ===========================================================
void command_get()
{
unsigned key;
unsigned key;
unsigned i;
unsigned cmdLen = 0;
unsigned cmdPos = 0;
CMD[0] = '\0';
unsigned i;
unsigned cmdLen = 0;
unsigned cmdPos = 0;
CMD[0] = '\0';
int clipNum; // number of clipboard slots
char* clipBuf; // clipboard buffer
char clipCopy[255+12];
int clipNum; // number of clipboard slots
char* clipBuf; // clipboard buffer
char clipCopy[255+12];
for (;;)
{
key = getch();
if ( 0 != (key & 0xff) )
{
key &= 0xff;
switch (key)
{
case 27: // ESC
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';
break;
for (;;) {
key = getch();
if ( 0 != (key & 0xff) ) {
key &= 0xff;
switch (key) {
case 27: // ESC
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';
break;
case 13: // ENTER
printf("\n\r");
command_history_add();
return;
case 13: // ENTER
printf("\n\r");
command_history_add();
return;
case 8: // BACKSPACE
if (cmdPos > 0)
{
for (i = cmdPos-1; i < cmdLen; i++)
CMD[i] = CMD[i+1];
for (i = 0; i < cmdLen-cmdPos; i++)
printf (" ");
case 8: // BACKSPACE
if (cmdPos > 0)
{
for (i = cmdPos-1; i < cmdLen; i++)
CMD[i] = CMD[i+1];
for (i = 0; i < cmdLen-cmdPos; i++)
printf (" ");
for (i = 0; i < cmdLen; i++)
printf ("%c %c", 8, 8);
for (i = 0; i < cmdLen; i++)
printf ("%c %c", 8, 8);
printf("%s", CMD);
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--;
}
break;
cmdPos--;
cmdLen--;
}
break;
case 9: // TAB
break;
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?
{
// clear previous text
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
case 22: // Ctrl+V
clipNum = _ksys_clip_num();
if (clipNum > 0)
{
clipBuf = _ksys_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?
{
// clear previous text
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
char *pasteText = clipBuf + 12;
int pasteLen = strlen(pasteText);
insert_string(CMD, cmdPos, pasteText);
cmdLen = strlen(CMD);
cmdPos += pasteLen;
printf("%s", CMD);
for (i = 0; i < cmdLen-cmdPos; i++) printf("%c", 8); // rewind the internal console cursor
}
}
}
}
break;
char *pasteText = clipBuf + 12;
int pasteLen = strlen(pasteText);
insert_string(CMD, cmdPos, pasteText);
cmdLen = strlen(CMD);
cmdPos += pasteLen;
printf("%s", CMD);
for (i = 0; i < cmdLen-cmdPos; i++) printf("%c", 8); // rewind the internal console cursor
}
}
}
}
break;
case 3: // Ctrl+C
if ( cmdLen > 0 )
{
case 3: // Ctrl+C
if ( cmdLen > 0 )
{
*clipCopy = 12 + cmdLen;
*(clipCopy+4)=0;
*(clipCopy+8)=1;
*clipCopy = 12 + cmdLen;
*(clipCopy+4)=0;
*(clipCopy+8)=1;
for (i = 0; i <= cmdLen; i++)
*(clipCopy+12+i) = CMD[i];
for (i = 0; i <= cmdLen; i++)
*(clipCopy+12+i) = CMD[i];
kol_clip_set(12+cmdLen, clipCopy);
_ksys_clip_set(12+cmdLen, clipCopy);
}
break;
}
break;
default:
if (cmdLen < 255)
{
if ( kol_key_control() & 0x40 ) // ¥á«¨ ¢ª«îçñ­ CapsLock
if ( (kol_key_control() & 1) || (kol_key_control() & 2)) // ¥á«¨ ­ ¦ âë è¨äâë
key = tolower(key);
else
key = toupper(key);
default:
if (cmdLen < 255)
{
if ( kol_key_control() & 0x40 ) // <EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CapsLock
if ( (kol_key_control() & 1) || (kol_key_control() & 2)) // <EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
key = tolower(key);
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;
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);
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++;
}
break;
cmdPos++;
cmdLen++;
}
break;
}
}
else
{
key = (key>>8)&0xff;
switch (key)
{
case 83: // Del
if (cmdPos < cmdLen)
{
for (i = cmdPos; i < cmdLen; i++)
CMD[i] = CMD[i+1];
}
}
else
{
key = (key>>8)&0xff;
switch (key)
{
case 83: // Del
if (cmdPos < cmdLen)
{
for (i = cmdPos; i < cmdLen; i++)
CMD[i] = CMD[i+1];
for (i = 0; i < cmdLen-cmdPos; i++)
printf(" ");
for (i = 0; i < cmdLen-cmdPos; i++)
printf(" ");
for (i = 0; i < cmdLen-cmdPos; i++)
printf("%c", 8);
for (i = 0; i < cmdLen-cmdPos; i++)
printf("%c", 8);
for (i = cmdPos; i < cmdLen; i++)
printf("%c", CMD[i]);
for (i = cmdPos; i < cmdLen; i++)
printf("%c", CMD[i]);
for (i = 0; i < cmdLen-cmdPos; i++)
printf("%c", 8);
for (i = 0; i < cmdLen-cmdPos; i++)
printf("%c", 8);
cmdLen--;
}
break;
cmdLen--;
}
break;
case 0x47: // Home
// move internal cursor and cmdPos to the beginning of the line
for (;cmdPos > 0; cmdPos--) {printf("%c", 8);}
break;
case 0x47: // Home
// move internal cursor and cmdPos to the beginning of the line
for (;cmdPos > 0; cmdPos--) {printf("%c", 8);}
break;
case 0x4F: // End
// move internal cursor and cmdPos to the end of the line
for (;cmdPos < cmdLen; cmdPos++) {printf("%c", CMD[cmdPos]);}
break;
case 0x4F: // End
// move internal cursor and cmdPos to the end of the line
for (;cmdPos < cmdLen; cmdPos++) {printf("%c", CMD[cmdPos]);}
break;
case 75: // Left
if (cmdPos > 0)
{
printf("%c", 8);
cmdPos--;
}
break;
case 75: // Left
if (cmdPos > 0)
{
printf("%c", 8);
cmdPos--;
}
break;
case 77: // Right
if (cmdPos < cmdLen)
{
printf("%c", CMD[cmdPos]);
cmdPos++;
}
break;
case 77: // Right
if (cmdPos < cmdLen)
{
printf("%c", CMD[cmdPos]);
cmdPos++;
}
break;
case 72: // Up
if (CMD_HISTORY_NUM_REAL > 0 && CMD_NUM >= -1)
{
case 72: // Up
if (CMD_HISTORY_NUM_REAL > 0 && CMD_NUM >= -1)
{
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
if (CMD_NUM < CMD_HISTORY_NUM_REAL-1)
CMD_NUM++;
/* else
CMD_NUM = 0;
*/
printf("%s", CMD_HISTORY[CMD_NUM]);
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD);
cmdPos = strlen(CMD);
if (CMD_NUM < CMD_HISTORY_NUM_REAL-1)
CMD_NUM++;
/* else
CMD_NUM = 0;
*/
printf("%s", CMD_HISTORY[CMD_NUM]);
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD);
cmdPos = strlen(CMD);
}
}
break;
break;
case 80: // Down
if (CMD_HISTORY_NUM_REAL > 0 && CMD_NUM >= 0)
{
case 80: // Down
if (CMD_HISTORY_NUM_REAL > 0 && CMD_NUM >= 0)
{
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdPos; i < cmdLen; i++)
printf(" ");
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8);
if (CMD_NUM > 0)
CMD_NUM--;
/* else
CMD_NUM = CMD_HISTORY_NUM_REAL-1;
*/
printf("%s", CMD_HISTORY[CMD_NUM]);
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD);
cmdPos = strlen(CMD);
if (CMD_NUM > 0)
CMD_NUM--;
/* else
CMD_NUM = CMD_HISTORY_NUM_REAL-1;
*/
printf("%s", CMD_HISTORY[CMD_NUM]);
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD);
cmdPos = strlen(CMD);
}
break;
}
break;
case 0: // console window closed
cmd_exit(NULL);
case 0: // console window closed
cmd_exit(NULL);
}
}
}
} // switch end
} // if end
} // for end
}
/// ===========================================================
int command_get_cmd(char cmd[])
{
unsigned i, len;
int quote = 0;
unsigned i, len;
int quote = 0;
if (CMD[0]=='"')
quote = 1;
if (CMD[0]=='"')
quote = 1;
if (quote == 0)
{
for (i=0;;i++)
{
cmd[i] = CMD[i];
if (0 == cmd[i])
return i;
if ( iswhite(cmd[i]) )
{
cmd[i] = '\0';
break;
}
}
return i+1;
}
else
{
len = 0;
for (i=1;;i++)
{
cmd[len] = CMD[i];
if (0 == cmd[len])
{
i--;
break;
}
if ( cmd[len] == '"' )
{
cmd[len] = '\0';
break;
}
len++;
}
trim(cmd);
return i+1;
}
if (quote == 0)
{
for (i=0;;i++)
{
cmd[i] = CMD[i];
if (0 == cmd[i])
return i;
if ( iswhite(cmd[i]) )
{
cmd[i] = '\0';
break;
}
}
return i+1;
}
else
{
len = 0;
for (i=1;;i++)
{
cmd[len] = CMD[i];
if (0 == cmd[len])
{
i--;
break;
}
if ( cmd[len] == '"' )
{
cmd[len] = '\0';
break;
}
len++;
}
trim(cmd);
return i+1;
}
}
/// ===========================================================
typedef int (*handler1_t)(char* arg);
/// ===========================================================
void command_execute()
{
char cmd[256];
char args[256];
unsigned arg;
int i;
int result;
char cmd[256];
char args[256];
unsigned arg;
int i;
int result;
trim(CMD);
arg = command_get_cmd(cmd);
trim(CMD);
arg = command_get_cmd(cmd);
if ( !strlen(cmd) )
return;
if ( !strlen(cmd) )
return;
strcpy(args, CMD+arg);
trim(args);
strcpy(args, CMD+arg);
trim(args);
for (i = 0; i < NUM_OF_CMD; i++)
{
if (!strcmp(cmd, COMMANDS[i].name))
{
result = ((handler1_t)COMMANDS[i].handler)(args);
if (result == FALSE)
{
#if LANG_ENG
printf(" Error!\n\r");
#elif LANG_RUS
printf(" Žè¨¡ª !\n\r");
#endif
}
return;
}
}
for (i = 0; i < NUM_OF_CMD; i++) {
if (!strcmp(cmd, COMMANDS[i].name)) {
result = ((handler1_t)COMMANDS[i].handler)(args);
if (result == FALSE) {
printf(UNKNOWN_CMD_ERROR);
}
return;
}
}
if ( -1 != alias_search(CMD) ) {
strcpy(CMD, ALIASES+64*1024+256*alias_search(CMD));
command_execute();
return;
}
if ( -1 != alias_search(CMD) )
{
strcpy(CMD, ALIASES+64*1024+256*alias_search(CMD));
command_execute();
return;
}
executable_run(cmd, args);
executable_run(cmd, args);
}
/// ===========================================================

View File

@ -1,74 +1,54 @@
/// ===========================================================
int executable_run(char cmd[], char args[]) {
char exec[FILENAME_MAX];
int result;
int executable_run(char cmd[], char args[])
{
if ( '/' == cmd[0]) // if path is absolute
{
strcpy(exec, cmd);
if (!file_check(exec) ) // check file existense
{
file_not_found(cmd);
return FALSE;
}
} else {
strcpy(exec, cur_dir); // check file in current directory
if (exec[strlen(exec)-1] != '/')
strcat(exec, "/"); // add slash
strcat(exec, cmd);
char exec[FILENAME_MAX];
int result;
if ( !file_check(exec) ) // check file existense
{
strcpy(exec, "/rd/1/"); // check file on virtual disk
strcat(exec, cmd);
if ( !file_check(exec) ) // check file existense
{
file_not_found(cmd);
return FALSE;
}
}
}
if ( '/' == cmd[0]) // if path is absolute
{
strcpy(exec, cmd);
if (!file_check(exec) ) // check file existense
{
file_not_found(cmd);
return FALSE;
}
}
else
{
strcpy(exec, cur_dir); // check file in current directory
if (exec[strlen(exec)-1] != '/')
strcat(exec, "/"); // add slash
strcat(exec, cmd);
// if file exists:
if ( !file_check(exec) ) // check file existense
{
strcpy(exec, "/rd/1/"); // check file on virtual disk
strcat(exec, cmd);
if ( !file_check(exec) ) // check file existense
{
file_not_found(cmd);
return FALSE;
}
}
}
// if file exists:
// try to run as a program
result = program_run(exec, args);
if (result > 0)
{
if ( !program_console(result) )
{
LAST_PID = result;
#if LANG_ENG
printf (" '%s' started. PID = %d\n\r", cmd, result);
#elif LANG_RUS
printf (" '%s' § ¯ã饭. PID = %d\n\r", cmd, result);
#endif
}
return TRUE;
}
else
{
if ( script_check(exec) ) // if file is a valid script
{
return script_run(exec, args);
} else
{
#if LANG_ENG
printf ("Error in '%s' : script must start with #SHS line\n\r", cmd);
#elif LANG_RUS
printf ("Žè¨¡ª  ¢ '%s' : áªà¨¯â ¤®«¦¥­ ­ ç¨­ âìáï á® áâà®çª¨ #SHS\n\r", cmd);
#endif
return FALSE;
}
}
// try to run as a program
result = program_run(exec, args);
if (result > 0) {
if ( !program_console(result) ) {
LAST_PID = result;
printf (EXEC_STARTED_FMT, cmd, result);
}
return TRUE;
} else {
if ( script_check(exec) ) // if file is a valid script
{
return script_run(exec, args);
} else
{
printf (EXEC_SCRIPT_ERROR_FMT, cmd);
return FALSE;
}
}
}
/// ===========================================================

View File

@ -1,63 +1,53 @@
/// ===========================================================
int parameters_prepare(char *param, char* argv[]) {
int i, param_len;
int argc = 1;
int quote = 0;
int argv_len;
int parameters_prepare(char *param, char* argv[])
{
param_len = strlen(param);
if ( param_len == 0 )
return 0;
int i, param_len;
int argc = 1;
int quote = 0;
int argv_len;
argv[0] = (char*) malloc(4096);
param_len = strlen(param);
if ( param_len == 0 )
return 0;
argv_len = 0;
for (i = 0; i < param_len; i++) {
switch (param[i]) {
case '\\':
if (param[i+1]!='\0') {
switch(param[i+1]) {
argv[0] = (char*) malloc(4096);
case 'n':
argv[argc-1][argv_len] = '\n';
argv_len++;
i++;
break;
argv_len = 0;
for (i = 0; i < param_len; i++)
{
switch (param[i])
{
case 't':
argv[argc-1][argv_len] = '\t';
argv_len++;
i++;
case '\\':
if (param[i+1]!='\0')
{
switch(param[i+1])
{
case '\\':
case '\'':
case '"':
case '?':
argv[argc-1][argv_len] = param[i+1];
argv_len++;
i++;
break;
case 'n':
argv[argc-1][argv_len] = '\n';
argv_len++;
i++;
break;
default:
i++;
};
}
break;
case 't':
argv[argc-1][argv_len] = '\t';
argv_len++;
i++;
case '\\':
case '\'':
case '"':
case '?':
argv[argc-1][argv_len] = param[i+1];
argv_len++;
i++;
break;
default:
i++;
};
}
break;
case '"':
if (quote == 0)
case '"':
if (quote == 0)
quote = 1;
else
{
else {
quote = 0;
argv[argc-1][argv_len] = '\0';
argc++;
@ -65,62 +55,46 @@ for (i = 0; i < param_len; i++)
argv[argc-1][argv_len] = '\0';
argv_len = 0;
}
break;
break;
case 9:
case 32:
if (quote == 0)
{
if ( ( param[i+1] != 32) || ( param[i+1] != 9) )
{
if (argv_len != 0)
{
argv[argc-1][argv_len] = '\0';
argc++;
argv[argc-1] = (char*) malloc(4096);
argv[argc-1][argv_len] = '\0';
argv_len = 0;
case 9:
case 32:
if (quote == 0) {
if ( ( param[i+1] != 32) || ( param[i+1] != 9) ) {
if (argv_len != 0) {
argv[argc-1][argv_len] = '\0';
argc++;
argv[argc-1] = (char*) malloc(4096);
argv[argc-1][argv_len] = '\0';
argv_len = 0;
}
}
}
else
{
}
} else {
argv[argc-1][argv_len] = param[i];
argv_len++;
}
}
break;
default:
argv[argc-1][argv_len] = param[i];
argv_len++;
break;
break;
}; // switch end
} // for end
default:
argv[argc-1][argv_len] = param[i];
argv_len++;
break;
argv[argc-1][argv_len] = '\0';
};
}
if ( strlen(argv[argc-1]) == 0 ) {
free(argv[argc-1]);
argc--;
}
argv[argc-1][argv_len] = '\0';
if ( strlen(argv[argc-1]) == 0 )
{
free(argv[argc-1]);
argc--;
}
return argc;
return argc;
}
/// ===========================================================
void parameters_free(int argc, char* argv[])
{
int i;
for (i = 0; i < argc; i++)
free(argv[i]);
void parameters_free(int argc, char* argv[]) {
int i;
for (i = 0; i < argc; i++) free(argv[i]);
}
/// ===========================================================

View File

@ -2,107 +2,95 @@
#include "../program_console.h"
int program_console(int pid)
{
int program_console(int pid) {
char name[32];
char *buffer;
char *buf1k;
int result;
int i;
char command;
int size;
int is_end;
char name[32];
char *buffer;
char *buf1k;
int result;
int i;
char command;
int size;
int is_end;
itoa(pid, name);
strcat(name, "-SHELL");
itoa(pid, name);
strcat(name, "-SHELL");
buffer = NULL;
buf1k = NULL;
buffer = NULL;
buf1k = NULL;
for (i = 0; i < 30; i++) {
result = kol_buffer_open(name, SHM_OPEN | SHM_WRITE, 0, &buffer);
if (buffer != NULL)
break;
for (i = 0; i < 30; i++)
{
result = kol_buffer_open(name, SHM_OPEN | SHM_WRITE, 0, &buffer);
if (buffer != NULL)
break;
kol_sleep(2);
}
kol_sleep(2);
}
if (buffer == NULL)
return 0;
else
size = result;
if (buffer == NULL)
return 0;
else
size = result;
is_end = 0;
for (;;) {
command = *(buffer);
is_end = 0;
for (;;)
{
switch (command) {
case SC_EXIT:
*buffer = SC_OK;
is_end = 1;
break;
command = *(buffer);
case SC_OK:
kol_sleep(5);
break;
switch (command)
{
case SC_EXIT:
*buffer = SC_OK;
is_end = 1;
break;
case SC_CLS:
con_cls();
*buffer = SC_OK;
break;
case SC_OK:
kol_sleep(5);
break;
case SC_PUTC:
printf("%c", *(buffer+1));
*buffer = SC_OK;
break;
case SC_CLS:
con_cls();
*buffer = SC_OK;
break;
case SC_PUTS:
printf("%s", buffer+1 );
*buffer = SC_OK;
break;
case SC_PUTC:
printf("%c", *(buffer+1));
*buffer = SC_OK;
break;
case SC_GETC:
*(buffer+1) = (char) getch() ;
*buffer = SC_OK;
break;
case SC_PUTS:
printf("%s", buffer+1 );
*buffer = SC_OK;
break;
case SC_GETS:
gets(buffer+1, size-2);
*buffer = SC_OK;
break;
case SC_GETC:
*(buffer+1) = (char) getch() ;
*buffer = SC_OK;
break;
case SC_PID:
buf1k=malloc(1024);
kol_process_info(-1, buf1k);
memcpy(buffer+1, buf1k+30, sizeof(unsigned));
*buffer = SC_OK;
free(buf1k);
break;
case SC_GETS:
gets(buffer+1, size-2);
*buffer = SC_OK;
break;
case SC_PING:
*buffer = SC_OK;
break;
case SC_PID:
buf1k=malloc(1024);
kol_process_info(-1, buf1k);
memcpy(buffer+1, buf1k+30, sizeof(unsigned));
*buffer = SC_OK;
free(buf1k);
break;
case SC_PING:
*buffer = SC_OK;
break;
default:
#if LANG_ENG
printf (" Error in console application.\n\r");
#elif LANG_RUS
printf (" Žè¨¡ª  ¢ ª®­á®«ì­®¬ ¯à¨«®¦¥­¨¨.\n\r");
#endif
return 0;
};
if (is_end)
{
printf("\n\r");
return 1;
}
}
return 9;
default:
printf (CON_APP_ERROR);
return 0;
};
if (is_end) {
printf("\n\r");
return 1;
}
} // for end
return 9;
}

View File

@ -1,106 +1,96 @@
/// ===========================================================
int script_check(char file[])
{
int script_check(char file[]) {
kol_struct70 k70;
char buf[4];
kol_struct70 k70;
char buf[4];
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 4; // read 4 bytes
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = file;
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 4; // read 4 bytes
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = file;
kol_file_70(&k70);
kol_file_70(&k70);
if ( !strcmp(buf, script_sign) ) // if we found the script signature
return TRUE;
else
return FALSE;
if ( !strcmp(buf, script_sign) ) // if we found the script signature
return TRUE;
else
return FALSE;
}
/// ===========================================================
int script_run(char exec[], char args[])
{
int script_run(char exec[], char args[]) {
kol_struct70 k70;
kol_struct_BDVK bdvk;
unsigned result, i;
unsigned long long filesize, pos;
char *buf; // buffer, where script is copied
kol_struct70 k70;
kol_struct_BDVK bdvk;
unsigned result, i;
unsigned long long filesize, pos;
char *buf; // buffer, where script is copied
k70.p00 = 5;
k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = exec;
k70.p00 = 5;
k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = exec;
result = kol_file_70(&k70); // get file info
if ( 0 != result )
return FALSE;
result = kol_file_70(&k70); // get file info
if ( 0 != result )
return FALSE;
filesize = bdvk.p32; // get file size
filesize = bdvk.p32; // get file size
buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
if (NULL == buf)
return FALSE;
buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
if (NULL == buf)
return FALSE;
buf[filesize]=0;
buf[filesize]=0;
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = filesize;
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = exec;
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = filesize;
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = exec;
result = kol_file_70(&k70); // read file to the buffer
if ( 0 != result )
{
free(buf);
return FALSE;
}
result = kol_file_70(&k70); // read file to the buffer
if ( 0 != result )
{
free(buf);
return FALSE;
}
pos = 0;
pos = 0;
for (;;) // script processing
{
if (pos > filesize)
break;
for (;;) // script processing
{
for (i=0;;i++) // reading a string
{
if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
{
pos++;
CMD[i] = '\0';
break;
}
CMD[i] = buf[pos];
pos++;
}
if (pos > filesize)
break;
if ( 0 == strlen(CMD) ) // empty string
continue;
for (i=0;;i++) // reading a string
{
if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
{
pos++;
CMD[i] = '\0';
break;
}
CMD[i] = buf[pos];
pos++;
}
if ('#' == CMD[0]) // comment
continue;
if ( 0 == strlen(CMD) ) // empty string
continue;
command_execute();
if ('#' == CMD[0]) // comment
continue;
}
command_execute();
}
free(buf);
return TRUE;
free(buf);
return TRUE;
}
/// ===========================================================

View File

@ -8,7 +8,6 @@ void dir_truncate(char dir[]);
int iswhite(char c);
void trim(char string[]);
void execute();
void kol_main();
int executable_run(char cmd[], char args[]);

View File

@ -1,188 +1,170 @@
#include "all.h"
/// ===========================================================
int dir_check(char dir[])
/// just checks, if dir[] is really a directory
{
kol_struct70 k70;
int result;
kol_struct70 k70;
int result;
k70.p00 = 1;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 2; // enough to read . & ..
k70.p16 = (unsigned)malloc(32+k70.p12*560);
k70.p20 = 0;
k70.p21 = dir;
k70.p00 = 1;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 2; // enough to read . & ..
k70.p16 = (unsigned)malloc(32+k70.p12*560);
k70.p20 = 0;
k70.p21 = dir;
result = kol_file_70(&k70);
result = kol_file_70(&k70);
free((void*)k70.p16);
free((void*)k70.p16);
if ( (0 == result)||(6 == result) ) // 6 is possible ???
return TRUE;
else
return FALSE;
if ( (0 == result)||(6 == result) ) // 6 is possible ???
return TRUE;
else
return FALSE;
}
/// ===========================================================
void dir_truncate(char dir[])
{
int i;
i = strlen(dir)-1;
for (;;i--)
if ('/' == dir[i])
{
dir[i+1] = 0;
break;
}
int i;
i = strlen(dir)-1;
for (;;i--)
if ('/' == dir[i])
{
dir[i+1] = 0;
break;
}
}
/// ===========================================================
void get_file_dir_loc(char *filepath, char *dir_path)
{
char *res = strrchr(filepath, '/');
if (res == 0)
{
dir_path = '\0';
return;
}
size_t pos = res - filepath;
strncpy(dir_path, filepath, pos);
dir_path[pos] = '\0';
char *res = strrchr(filepath, '/');
if (res == 0)
{
dir_path = '\0';
return;
}
size_t pos = res - filepath;
strncpy(dir_path, filepath, pos);
dir_path[pos] = '\0';
}
/// ===========================================================
int file_check(char file[])
{
kol_struct70 k70;
int result;
kol_struct70 k70;
int result;
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = file;
k70.p00 = 0;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 0;
k70.p16 = 0;
k70.p20 = 0;
k70.p21 = file;
result = kol_file_70(&k70);
result = kol_file_70(&k70);
if (0 == result)
return TRUE;
else
return FALSE;
if (0 == result)
return TRUE;
else
return FALSE;
}
/// ===========================================================
void file_not_found(char file[])
{
#if LANG_ENG
printf (" File '%s' not found.\n\r", file);
#elif LANG_RUS
printf (" ” ©« '%s' ­¥ ­ ©¤¥­.\n\r", file);
#endif
void file_not_found(char file[]) {
printf (FILE_NOT_FOUND_ERROR, file);
}
/// ===========================================================
int iswhite(char c)
{
return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
}
/// ===========================================================
int iswhite(char c) {return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c)); }
void trim(char string[])
{
int i, j;
int i, j;
for (i=0; ;i++)
if ( !iswhite(string[i]) )
break;
j = 0;
for (;;i++, j++)
{
string[j] = string[i];
if ('\0' == string[i] )
break;
}
for (i=0; ;i++)
if ( !iswhite(string[i]) )
break;
j = 0;
for (;;i++, j++)
{
string[j] = string[i];
if ('\0' == string[i] )
break;
}
for (i=0; ;i++)
if ('\0' == string[i])
break;
i--;
for (;i>0;--i)
if ( iswhite(string[i]) )
string[i] = '\0';
else
break;
for (i=0; ;i++)
if ('\0' == string[i])
break;
i--;
for (;i>0;--i)
if ( iswhite(string[i]) )
string[i] = '\0';
else
break;
}
/// ===========================================================
void kol_main()
// entry point
int main(int argc, char **argv)
{
int i; for (i = 1; i < argc; i++) {
strcat(cmdline, argv[i]);
if (i != argc - 1) {
strcat(cmdline, " ");
}
}
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
strcpy(title, "SHELL ");
strcat(title, SHELL_VERSION);
con_init_opt(-1, -1, -1, -1, title);
strcpy(title, "SHELL ");
strcat(title, SHELL_VERSION);
CONSOLE_INIT(title);
//printf("argc = %d\ncmdline = '%s'\n", argc, cmdline);
if (sizeof (kol_struct70) != 25)
{
printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
kol_exit();
if (sizeof (kol_struct70) != 25) {
printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
kol_exit();
}
//strcpy(cur_dir, PATH);
//dir_truncate(cur_dir);
getcwd(cur_dir, sizeof cur_dir);
//printf("curdir %s\n", cur_dir);
con_set_cursor_height(con_get_font_height()-1);
ALIASES = malloc(128*1024);
if (!cmdline || cmdline[0] == 0) {
strcpy(CMD, argv[0]);
dir_truncate(CMD);
strcat(CMD, ".shell");
if ( !file_check(CMD) )
strcpy(CMD, "/sys/settings/.shell");
}
else {
if (cmdline[0] == '/')
{
strcpy(cur_dir, cmdline);
*(strrchr(cur_dir, '/')+1)=0;
}
strcpy(CMD, cmdline);
}
command_execute();
for (;;) {
//printf("\033[32;1m");
printf ("# ");
//printf("\033[0m");
command_get();
command_execute();
}
con_exit(0);
kol_exit();
}
//strcpy(cur_dir, PATH);
//dir_truncate(cur_dir);
getcwd(cur_dir, sizeof cur_dir);
//printf("curdir %s\n", cur_dir);
con_set_cursor_height(con_get_font_height()-1);
ALIASES = malloc(128*1024);
if (!PARAM || PARAM[0] == 0)
{
strcpy(CMD, PATH);
dir_truncate(CMD);
strcat(CMD, ".shell");
if ( !file_check(CMD) )
strcpy(CMD, "/sys/settings/.shell");
}
else
{
if (PARAM[0] == '/')
{
strcpy(cur_dir, PARAM);
*(strrchr(cur_dir, '/')+1)=0;
}
strcpy(CMD, PARAM);
}
command_execute();
for (;;)
{
//printf("\033[32;1m");
printf ("# ");
//printf("\033[0m");
command_get();
command_execute();
}
_exit(0);
kol_exit();
}
/// ===========================================================

View File

@ -1,41 +0,0 @@
format MS COFF
public Start
public _PATH
public _PARAM
extrn Memory
extrn hEnd
extrn _kol_main
section ".text" code
db "MENUET01"
dd 1, Start, hEnd, Memory, hStack, _PARAM, _PATH
Start:
; èíèöèàëèçàöèÿ êó÷è
mov eax, 68
mov ebx, 11
int 0x40
; âûçîâ ãëàâíîé ïðîöåäóðû
mov eax, _kol_main
call eax
; çàâåðøåíèå ðàáîòû ïðîãðàììû
mov eax, -1
int 0x40
section ".bss"
_PARAM:
rb 256
_PATH:
rb 256
rb 8*1024
hStack:

View File

@ -1,88 +0,0 @@
///===========================
#define CON_COLOR_BLUE 1
#define CON_COLOR_GREEN 2
#define CON_COLOR_RED 4
#define CON_COLOR_BRIGHT 8
/* öâåò ôîíà */
#define CON_BGR_BLUE 0x10
#define CON_BGR_GREEN 0x20
#define CON_BGR_RED 0x40
#define CON_BGR_BRIGHT 0x80
///===========================
void (* _stdcall con_init)(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
void (* _cdecl printf)(const char* format,...);
void (* _stdcall _exit)(char bCloseWindow);
void (* __stdcall gets)(char* str, int n);
int (* __stdcall getch)(void);
int (* __stdcall con_get_font_height)(void);
int (* __stdcall con_set_cursor_height)(int new_height);
unsigned (*__stdcall con_get_flags)(void);
unsigned (*__stdcall con_set_flags)(unsigned new_flags);
void (*__stdcall con_cls)(void);
///===========================
void CONSOLE_INIT(char title[])
{
kol_struct_import *imp;
imp = kol_cofflib_load("/sys/lib/console.obj");
if (imp == NULL)
kol_exit();
con_init = ( _stdcall void (*)(unsigned, unsigned, unsigned, unsigned, const char*))
kol_cofflib_procload (imp, "con_init");
if (con_init == NULL)
kol_exit();
printf = ( _cdecl void (*)(const char*,...))
kol_cofflib_procload (imp, "con_printf");
if (printf == NULL)
kol_exit();
_exit = ( _stdcall void (*)(char))
kol_cofflib_procload (imp, "con_exit");
if (_exit == NULL)
kol_exit();
gets = ( _stdcall void (*)(char*, int))
kol_cofflib_procload (imp, "con_gets");
if (gets == NULL)
kol_exit();
getch = ( _stdcall int (*)(void))
kol_cofflib_procload (imp, "con_getch2");
if (getch == NULL)
kol_exit();
con_get_font_height = ( _stdcall int (*)(void))
kol_cofflib_procload (imp, "con_get_font_height");
if (con_get_font_height == NULL)
kol_exit();
con_set_cursor_height = ( _stdcall int (*)(int))
kol_cofflib_procload (imp, "con_set_cursor_height");
if (con_set_cursor_height == NULL)
kol_exit();
con_get_flags = ( _stdcall unsigned (*)(void))
kol_cofflib_procload (imp, "con_get_flags");
if (con_get_flags == NULL)
kol_exit();
con_set_flags = ( _stdcall unsigned (*)(unsigned))
kol_cofflib_procload (imp, "con_set_flags");
if (con_set_flags == NULL)
kol_exit();
con_cls = ( _stdcall void (*)(void))
kol_cofflib_procload (imp, "con_cls");
if (con_cls == NULL)
kol_exit();
con_init(-1, -1, -1, -1, title);
}

View File

@ -1,39 +0,0 @@
#include "ctype.h"
int toupper(int c)
{
if ( (c >= 97) && (c <= 122) )
return c-32 ;
if ( (c >= 160) && (c <= 175) )
return c-32 ;
if ( (c >= 224) && (c <= 239) )
return c-80 ;
if ( (c == 241) || (c == 243) || (c == 245) || (c == 247) )
return c-1;
return c;
}
int tolower(int c)
{
if ( (c >= 65) && (c <= 90) )
return c+32 ;
if ( (c >= 128) && (c <= 143) )
return c+32 ;
if ( (c >= 144) && (c <= 159) )
return c+80 ;
if ( (c == 240) || (c == 242) || (c == 244) || (c == 246) )
return c+1;
return c;
}

View File

@ -1,3 +0,0 @@
int toupper(int c);
int tolower(int c);

View File

@ -354,13 +354,13 @@ asm volatile ("int $0x40"::"a"(18), "b"(14));
void kol_screen_get_size(unsigned *w, unsigned *h)
/*void kol_screen_get_size(unsigned *w, unsigned *h)
{
unsigned size;
asm volatile ("int $0x40":"=a"(size):"a"(14));
*w = size / 65536;
*h = size % 65536;
}
}*/
@ -422,7 +422,7 @@ void kol_buffer_close(char name[])
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name));
}
int kol_clip_num()
/*int kol_clip_num()
{
asm volatile ("int $0x40"::"a"(54), "b"(0));
}
@ -435,7 +435,7 @@ 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));
}
}*/
void set_cwd(const char* cwd)
{

View File

@ -100,7 +100,7 @@ unsigned kol_system_date_get();
void kol_path_file2dir(char *dir, char *fname);
void kol_path_full(char *full, char *fname);
void kol_screen_wait_rr();
void kol_screen_get_size(unsigned *w, unsigned *h);
//void kol_screen_get_size(unsigned *w, unsigned *h);
unsigned kol_skin_height();
unsigned kol_thread_start(unsigned start, unsigned stack);
unsigned kol_time_tick();
@ -111,9 +111,9 @@ 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[]);
//int kol_clip_num();
//char* kol_clip_get(int n);
//int kol_clip_set(int n, char buffer[]);
void set_cwd(const char* cwd);
int getcwd(char *buf, unsigned size);

View File

@ -1,33 +0,0 @@
unsigned int seed_o = 0x45168297;
void srand (unsigned seed)
{
seed_o = seed;
}
int rand (void)
{
seed_o = seed_o * 0x15a4e35 + 1;
return(seed_o >> 16);
}
void* malloc(unsigned s)
{
asm ("int $0x40"::"a"(68), "b"(12), "c"(s) );
}
void free(void *p)
{
asm ("int $0x40"::"a"(68), "b"(13), "c"(p) );
}
void* realloc(void *p, unsigned s)
{
asm ("int $0x40"::"a"(68), "b"(20), "c"(p), "d"(s) );
}

View File

@ -1,14 +0,0 @@
#define RAND_MAX 0x7FFFU
#define isspace(c) ((c)==' ')
#define abs(i) (((i)<0)?(-(i)):(i))
#define random(num) ((rand()*(num))/((RAND_MAX+1)))
void* malloc(unsigned size);
void free(void* pointer);
void* realloc(void* pointer, unsigned size);
void srand (unsigned seed);
int rand (void);

View File

@ -1,221 +0,0 @@
#include "string.h"
#include "ctype.h"
void* memset(void *mem, int c, unsigned size)
{
unsigned i;
for ( i = 0; i < size; i++ )
*((char *)mem+i) = (char) c;
return NULL;
}
void* memcpy(void *dst, const void *src, unsigned size)
{
unsigned i;
for ( i = 0; i < size; i++)
*(char *)(dst+i) = *(char *)(src+i);
return NULL;
}
int memcmp(const void* buf1, const void* buf2, int count)
{
int i;
for (i=0;i<count;i++)
{
if (*(unsigned char*)buf1<*(unsigned char*)buf2)
return -1;
if (*(unsigned char*)buf1>*(unsigned char*)buf2)
return 1;
}
return 0;
}
void strcat(char strDest[], char strSource[])
{
int i, j;
i = j = 0;
while (strDest[i] != '\0')
i++;
while ((strDest[i++] = strSource[j++]) != '\0')
;
}
int strcmp(const char* string1, const char* string2)
{
while (1)
{
if (*string1<*string2)
return -1;
if (*string1>*string2)
return 1;
if (*string1=='\0')
return 0;
string1++;
string2++;
}
}
int strnicmp(const char* string1, const char* string2, unsigned count)
{
int pc = 0;
while (1)
{
if (toupper(*string1)<toupper(*string2))
return -1;
if (toupper(*string1)>toupper(*string2))
return 1;
if (*string1=='\0' || pc == count)
return 0;
string1++;
string2++;
pc++;
}
}
void strcpy(char strDest[], const char strSource[])
{
unsigned i;
i = 0;
while ((strDest[i] = strSource[i]) != '\0')
i++;
}
char* strncpy(char *strDest, const char *strSource, unsigned n)
{
unsigned i;
if (! n )
return strDest;
i = 0;
while ((strDest[i] = strSource[i]) != '\0')
if ( (n-1) == i )
break;
else
i++;
return strDest;
}
int strlen(const char* string)
{
int i;
i=0;
while (*string++) i++;
return i;
}
char* strchr(const char* string, int c)
{
while (*string)
{
if (*string==c)
return (char*)string;
string++;
}
return (char*)0;
}
char* strrchr(const char* string, int c)
{
char* last_found = 0; // !
while (*string)
{
if (*string==c)
{
last_found = (char*)string;
}
string++;
}
return last_found;
}
void _itoa(int i, char *s)
{
int a, b, c, d;
a = (i - i%1000)/1000;
b = (i - i%100)/100 - a*10;
c = (i - i%10)/10 - a*100 - b*10;
d = i%10;
s[0] = a + '0';
s[1] = b + '0';
s[2] = c + '0';
s[3] = d + '0';
s[4] = 0;
}
/* reverse: ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */
void reverse(char s[])
{
int i, j;
char c;
for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
/* itoa: êîíâåðòèðóåì n â ñèìâîëû â s */
void itoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0)
n = -n;
i = 0;
do {
s[i++] = n % 10 + '0';
} while ((n /= 10) > 0);
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
int _atoi ( char *s )
{
int i, n;
n = 0;
for ( i = 0; s[i]!= '\0'; ++i)
if ((s[i]<'0') || (s[i]>'9'))
return 0;
else
n = 10 * n + s[i] - '0';
return n;
}

View File

@ -1,21 +0,0 @@
#ifndef NULL
#define NULL ((void*)0)
#endif
void* memset(void *mem, int c, unsigned size);
void* memcpy(void *dst, const void *src, unsigned size);
int memcmp(const void* buf1, const void* buf2, int count);
void strcat(char strDest[], char strSource[]);
int strcmp(const char* string1, const char* string2);
void strcpy(char strDest[], const char strSource[]);
char* strncpy(char *strDest, const char *strSource, unsigned n);
int strlen(const char* string);
char* strchr(const char* string, int c);
char* strrchr(const char* string, int c);
void _itoa(int i, char *s);
void reverse(char *s);
void itoa(int i, char *s);
int _atoi( char *s );
int strnicmp(const char* string1, const char* string2, unsigned count);