-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmds1.cpp
152 lines (138 loc) · 3.56 KB
/
cmds1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stddef.h>
#include <stdlib.h>
#include <ctype.h>
#if defined(NYADOS)
# include <dos.h>
#endif
#ifndef OS2EMX
# include <dir.h>
#endif
#include <errno.h>
#include "getline.h"
#include "shell.h"
#include "nnhash.h"
#include "nndir.h"
extern NnHash properties;
extern NnHash aliases;
/* エイリアスなどの設定系のコマンドの共通処理
* hash - 扱うハッシュテーブル
* argv - 設定内容
* 空 => 全ての対応を標準出力へ出す
* 1トークンのみ => そのトークンに対応する値を出力
* 2トークン以上 => 最初のトークンに後の内容を代入する
* lower - 1 のとき、値に tolower のフィルタをかける。
* return
* 常に 0
*/
int cmd_setter( NyadosShell &shell , NnHash &hash , const NnString &argv )
{
if( argv.empty() ){
// 一覧表示.
for( NnHash::Each itr(hash) ; itr.more() ; ++itr )
shell.out()
<< itr->key() << ' '
<< *(NnString*)itr->value()
<< '\n';
return 0;
}
NnString name;
NnString *value=new NnString;
if( value == NULL )
return 0;
argv.splitTo( name , *value );
name.downcase();
value->trim();
if( name.length() <= 0 ){
delete value;
}else if( value->length() <= 0 ){
if( name.at(0)=='+'){
name.shift();
hash.put( name , new NnString("(set)") );
}else if( name.at(0)=='-'){
name.shift();
hash.remove( name );
}else{
// 1エイリアス内容表示.
NnString *rvalue=(NnString *)hash.get( name );
if( rvalue != NULL )
shell.out() << name << ' ' << *rvalue << '\n';
delete value;
}
}else{
// エイリアス定義.
if( value->startsWith("\"") ){
NnString tmp;
NyadosShell::dequote( value->chars() , tmp );
*value = tmp;
}
hash.put( name , value );
}
return 0;
}
/* エイリアスの定義参照を行う.
* argv - 引数
* return
* 常に 0
*/
int cmd_alias( NyadosShell &shell , const NnString &argv )
{
return cmd_setter( shell , aliases , argv );
}
/* 別名を削除する */
int cmd_unalias( NyadosShell & , const NnString &argv )
{
aliases.remove( argv );
return 0;
}
int cmd_suffix( NyadosShell &shell , const NnString &argv )
{
return cmd_setter( shell , DosShell::executableSuffix , argv );
}
int cmd_unsuffix( NyadosShell & , const NnString &argv )
{
NnString argvL(argv);
argvL.downcase();
DosShell::executableSuffix.remove( argvL );
return 0;
}
int cmd_history( NyadosShell &shell , const NnString &argv )
{
int n=10;
if( ! argv.empty() && isDigit(argv.at(0)) ){
n = atoi( argv.chars() );
if( n <= 0 )
n = 10;
}
History *hisObj=shell.getHistoryObject();
if( hisObj == NULL )
return 0;
int start=hisObj->size()-n;
if( start < 0 )
start = 0;
for(int i=start ; i<hisObj->size() ; i++ ){
NnString history;
hisObj->get(i,history);
shell.out() << i << " : ";
for(int j=0;j<history.length();++j){
if( TwinBuffer::isCtrl(history.at(j)) )
shell.out() << '^' << (char)('@'+history.at(j));
else
shell.out() << (char)history.at(j);
}
shell.out() << '\n';
}
return 0;
}
int cmd_option( NyadosShell &shell , const NnString &argv )
{
return cmd_setter( shell , properties , argv );
}
int cmd_folder( NyadosShell &shell , const NnString &argv )
{
return cmd_setter( shell , NnDir::specialFolder , argv );
}
int cmd_unoption( NyadosShell & , const NnString &argv )
{
properties.remove( argv );
return 0;
}