-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsuix_cmd.js
2243 lines (2171 loc) · 61.9 KB
/
jsuix_cmd.js
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// JS/UIX v0.46
// (c) mass:werk (N.Landsteiner) 2003
// all rights reserved
// commands
var usrFDump='';
var usrExWin=null;
function commandHelp(env) {
env.stdin=new VfsFileHandle(new VfsFile('p',[
'%+r System Help %-r',
'JS/UIX is a virtual OS in UN*X-style for JavaScript and web-browsers.',
'',
'%+uFor help on specific topics type any of these commands:%-u',
' ',
'info site information - about %+imass:werk%-i',
'features OS features / system info - about %+i'+os_version+'%-i',
'man <command> to display a manual entry for <command>',
//'-------------------------------------------------------------------------------',
'',
'%+uCurrently implemented UN*X-commands (see "man" for implemented options)%-u',
'',
' alias set an alias',
' apropos display a short description of a command',
' cal display a monthly calendar (non-standard opt. "-w" for weeks-count)',
' cat concatenate files',
' chmod change file permissions',
' cd change current working directory',
' cp copy files or directories',
' date display date and time (non-standard opt. "-u" for UTC)',
' echo write arguments back',
' halt halt system, shut down',
' ls list directory',
' logname display login name',
' mkdir make a directory',
' man display manual page',
' more pager',
' mv move/rename files or directories',
' pager synonym for more',
' pg synonym for more',
' pr print (to a browser window)',
' ps display list of active processes',
' pwd print working directory',
' reboot reboot system',
' rm remove file(s)',
' rmdir remove a directory',
' set set a variable',
' sh start a new sub-shell',
' stty set terminal attributes',
' su switch user',
' touch set the timestamp of file or create empty file',
' uname display system name',
' unalias discard an alias',
' unset discard a variable',
' vi visual editor (simple vi)',
' view vi in view mode',
' wc word count',
' which evaluate command path for command to be executed',
'',
'%+uCurrently implemented non-standard commands%-u',
'',
' browse open a new browser window with specified url (or site-homepage)',
' clear clear and reset the display',
' features display features of the virtual OS and the terminal',
' fexport export/backup of home-directory for intersession operability.',
' fimport re-import of backuped home-data for intersession operability.',
' hallo display a short system-identification',
' hello display a short system-identification',
' help display this help table',
' info display site-information',
' invaders the "space invaders" arcade game for JS/UIX',
' js javascr'+'ipt debugging',
' mail open a mail-client with specified address (default webmaster)',
' news displays latest news on system changes',
' reset reboot system',
' splitmode (on/off) - switch window splitting on|off',
' time display system time ("-l" for local, "-u" for UTC)',
' type echo with specified type-style (see man page)',
' web synonym for "browse"',
' write write args with formating (marked up type-styles)',
'-------------------------------------------------------------------------------',
'P.S.: Some data for testing can be found in "/var".'
]));
env.stdin.close();
env.args=['more'];
commandMore(env)
}
function commandNews(env) {
cnslClear();
env.args=['news','/etc/news'];
commandMore(env)
}
function commandClear(env) {
cnslClear();
}
function commandReset(env) {
if (env.status=='') {
cnslType('sure to reboot system [y/n]? ');
cursorOn();
env.bin='commandReset';
env.status='wait';
env.wantChar=true;
return
}
else if (krnlTtyChar==121) {
cnslType('y'); newLine(); cnslType('halting system for reboot ...');
setTimeout('termClose();termOpen()',100)
}
else {
cnslType('n');
newLine();
};
env.status='';
env.wantChar=false;
krnlTtyChar=0
}
function commandHalt(env) {
if (env.status=='') {
cnslType('sure to halt system [y/n]? ');
cursorOn();
env.bin='commandHalt';
env.status='wait';
env.wantChar=true;
return
}
else if (krnlTtyChar==121) {
cnslType('y'); newLine(); cnslType('halting system ...');
setTimeout('termClose()',100)
}
else {
cnslType('n');
newLine();
};
env.status='';
env.wantChar=false;
krnlTtyChar=0
}
//************************************
function commandPhil(env){
krnlFOut(env.stdout, "Hi , I am Phil I am forking this project . If you want to know more about check my github https://qbasicfan.github.io/term/");
}
//************************************
function commandHello(env) {
var now=new Date();
var t=(self.location.hostname)? ' @ '+self.location.hostname : ' @ localhost';
t+= ' at '+now.getHours()+':'+txtNormalize(now.getMinutes(),2)+':'+txtNormalize(now.getSeconds(),2) +' local time';
var s=' '+os_version+t+'\n';
s+=' by mass:werk - media environments <http://www.masswerk.at>\n';
s+=' Type "help" for available commands.';
krnlFOut(env.stdout, s);
}
function commandParse(env) {
var args=env.args;
var s='parsed args:';
if (args.length>1) {
for (var i=1; i<args.length; i++) s+=' "'+args[i]+'"';
}
else {
s+='none.'
};
krnlFOut(env.stdout,s)
}
function commandEcho(env) {
var args=env.args;
var s='';
for (var i=1; i<args.length; i++) {
s+=args[i];
if (i+1!=args.length) s+=' ';
};
krnlFOut(env.stdout,s);
}
function commandType(env) {
var args=env.args;
var s='';
var style=-1;
var a=1;
var opt=krnlGetOpts(args,1);
if (krnlTestOpts(opt,'npruis')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
if (opt.length) {
style=0;
if (opt.n) {
if (args.length>2) {
var sn=parseInt(args[2]);
if (isNaN(sn)==false) {
style=sn&15;
a++
}
}
}
else {
if (opt.p) style|=0;
if (opt.r) style|=1;
if (opt.u) style|=2;
if (opt.i) style|=4;
if (opt.s) style|=8;
}
};
a+=opt.length;
if (style>=0) {
for (var i=a; i<args.length; i++) {
s+=args[i];
if (i+1!=args.length) s+=' ';
};
cnslType(s,style);
newLine()
}
else {
commandEcho(env)
}
}
function commandWrite(env) {
var args=env.args;
var s='';
for (var i=1; i<args.length; i++) {
s+=args[i];
if (i+1!=args.length) s+=' ';
};
krnlFOut(env.stdout,s,1);
}
function commandTime(env) {
var args=env.args;
var utc=0;
var opt=krnlGetOpts(args,1);
if (krnlTestOpts(opt,'ul')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
if (opt.u) utc=1;
else if (opt.l) utc=0;
var now=new Date();
if (utc) {
var s=now.getUTCHours()+':'+txtNormalize(now.getUTCMinutes(),2)+':'+txtNormalize(now.getUTCSeconds(),2);
krnlFOut(env.stdout,s+' UTC')
}
else {
var s=now.getHours()+':'+txtNormalize(now.getMinutes(),2)+':'+txtNormalize(now.getSeconds(),2);
krnlFOut(env.stdout,s)
}
}
function commandDate(env) {
var args=env.args;
var m=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var d=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var now=new Date();
var utc=false;
var a=1;
var opt=krnlGetOpts(args,1);
if (krnlTestOpts(opt,'ul')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
a+=opt.length;
if (opt.u) {
now=new Date(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds()
);
utc=true;
};
var s='';
if ((args.length>a) && (args[a].charAt(0)=='+')) {
// unix style formats
var ta=args[a].split('%');
for (var i=1; i<ta.length;i++) {
var f=(ta[i].length>0)? ta[i].charAt(0):'';
if (f=='a') s+=d[now.getDay()]
else if (f=='D') s+=txtNormalize(now.getMonth()+1,2)+'/'+txtNormalize(now.getDate(),2)+'/'+txtNormalize(now.getFullYear()%100,2)
else if (f=='T') s+=txtNormalize(now.getHours(),2)+':'+txtNormalize(now.getMinutes(),2)+':'+txtNormalize(now.getSeconds(),2)
else if (f=='H') s+=txtNormalize(now.getHours(),2)
else if (f=='M') s+=txtNormalize(now.getMinutes(),2)
else if (f=='S') s+=txtNormalize(now.getSeconds(),2)
else if (f=='d') s+=now.getDate()
else if (f=='h') s+=m[now.getMonth()]
else if (f=='m') s+=txtNormalize(now.getMonth()+1,2)
else if (f=='w') s+=now.getDay()
else if (f=='y') s+=mormalize(now.getFullYear()%100,2)
else if (f=='t') s+=' '
else if (f=='r') {
var h=now.getHours();
var z;
if (h>12) {
h-=12; z=' PM'
}
else z=' AM';
s+=h+':'+txtNormalize(now.getMinutes(),2)+':'+txtNormalize(now.getSeconds(),2)+z;
}
else if (f=='j') {
var y=now.getFullYear();
var m=now.getMonth();
var isLeap=(((y%4==0) && (y%100>0)) || (y%400==0))? true: false;
var mLength=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var ds=0;
for (var k=0; k<m; k++) ds+=((k==1) && (isLeap))? mLength[k]+1: mLength[k];
ds+=now.getDate();
s+=txtNormalize(ds,3)
}
else if (f=='n') s+='%n';
}
}
else {
var s=d[now.getDay()]+', '+now.getDate()+' '+m[now.getMonth()]+' '+now.getFullYear();
s+=' '+now.getHours()+':'+txtNormalize(now.getMinutes(),2)+':'+txtNormalize(now.getSeconds(),2);
if (utc) s+=' UTC';
};
krnlFOut(env.stdout,s)
}
function commandCal(env) {
var args=env.args;
var mLength=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var mLabel=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var now=new Date();
var weeks=false;
var m,y;
var a=1;
var opt=krnlGetOpts(args,1);
if (krnlTestOpts(opt,'w')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
if (opt.w) weeks=true;
a+=opt.length;
if (args.length==a) {
m=now.getMonth();
y=now.getFullYear()
}
else if (args.length<a+3) {
m=parseInt(args[a],10);
a++;
if ((isNaN(m)) || (m<1) || (m>12)) {
krnlFOut(env.stderr,'usage: '+args[0]+' [-w] [<month_nr>] [<year>] - month_nr must be in 1..12');
return
};
m--;
if (args.length==a+1) {
y=parseInt(args[a],10);
if ((isNaN(y)) || (y<1900) || (y>9999)) {
krnlFOut(env.stderr,'usage: '+args[0]+' [-w] [<month_nr>] [<year>] - year must be in 1900..9999');
return
}
}
else {
y=now.getFullYear()
}
}
else {
krnlFOut(env.stderr,'usage: '+args[0]+' [-w] [<month_nr>] [<year>] - to many arguments');
return
};
var isLeap=(((y%4==0) && (y%100>0)) || (y%400==0))? true: false;
var wcnt=0;
var wos=0;
var d=new Date(y,m,1,0,0,0);
var buf=txtCenter(mLabel[m]+' '+y,20)+'\n S M Tu W Th F S';
if (weeks) {
buf+=' week';
var df=new Date(y,0,1,0,0,0);
var yds=df.getDay();
for (var mi=0; mi<m; mi++) yds+= ((mi==1) && (isLeap))? mLength[mi]+1 : mLength[mi];
wos=yds%7;
wcnt=Math.floor(yds/7)+1;
};
buf+='\n';
var os=d.getDay();
var l=mLength[m];
if ((m==1) && (isLeap)) l++;
for (var i=0; i<os; i++) buf+=' ';
for (var i=1; i<=l; i++) {
var s= (i<10)? ' ': '';
s+=i;
if ((i+os)%7==0) {
buf+=s;
if (weeks) {
var ws=(wcnt<10)? ' '+wcnt:wcnt;
buf+=' '+ws;
wcnt++
};
buf+='\n';
}
else buf+=s+' ';
if ((weeks) && (i==l) && ((i+os)%7>0)) {
var ii=i+os;
var ss='';
while (ii%7>0) {
ss+=' ';
ii++
};
var ws=(wcnt<10)? ' '+wcnt:wcnt;
buf+=' '+ss+ws;
}
};
krnlFOut(env.stdout, buf+'\n');
}
function commandMail(env) {
var args=env.args;
var to=conf_defaultmail;
if (args.length==2) to=args[1]
else if (args.length>2) {
krnlFOut(env.stderr,'usage: '+args[0]+' [<user@host>] - to many arguments');
return
};
var os1=to.indexOf('@');
var os2=to.indexOf('.',Math.max(0,os1));
if ((os1<1) || (os2<0)) {
krnlFOut(env.stderr,'usage: '+args[0]+' [<user@host>] - illegal address');
return
};
krnlFOut(env.stdout,'opening mail-client for "'+to+'".');
self.location.href='mailto:'+to
}
function commandBrowse(env) {
var args=env.args;
var url=conf_defaulturl;
var a=1;
var n=true; // open in new window!
if (args[1]=='-n') {
a++;
n=true
};
if (args.length==a+1) {
url=args[a];
if (url.charAt(0)=='-') {
krnlFOut(env.stderr,'usage: '+args[0]+' [-n] [<url>] - illegal option');
return
}
}
else if (args.length>a) {
krnlFOut(env.stderr,'usage: '+args[0]+' [-n] [<url>] - to many arguments');
return
};
if ((url.indexOf('http://')!=0) && (url.indexOf('https://')!=0) && (url.indexOf('ftp://')!=0) && (url.indexOf('ftps://')!=0) && (url.indexOf('file:')!=0) && (url.indexOf('mailto:')!=0)) url='http://'+url;
if (n) {
krnlFOut(env.stdout,'opening url "'+url+'" in new browser window.');
var w=window.open(url);
if (window.focus) w.focus();
}
else {
if (confirm('Sure to open the URL "'+url+'" in the same window?')) {
krnlFOut(env.stdout,'opening url "'+url+'".');
self.location.href=url
}
else {
krnlFOut(env.stdout,'cancled by user. use -n to open an address in a new window.')
}
}
}
function commandSplitScreen(env) {
var args=env.args;
var split=false;
if (args.length==2) {
if (args[1]=='on') {
split=true;
}
else if (args[1]!='off') {
krnlFOut(env.stderr,'usage: '+args[0]+' on|off - illegal argument');
return
}
}
else {
krnlFOut(env.stderr,'usage: '+args[0]+' on|off');
return
};
cnslClear();
if (split) {
cnslType('split mode on',1); newLine();
cnslTypeAt(conf_rows-2,0,'--------------------------------------------------------------------------------');
cnslTypeAt(conf_rows-1,0,'JS/UIX by mass:werk. type "splitmode off" or "clear" to return to normal mode.');
cnslMaxLines=conf_rows-2
}
else {
krnlFOut(env.stdout,'split mode off',1)
}
}
function commandInfo(env) {
cnslClear();
krnlFOut(env.stdout,[
'%+r Site Information %-r',
' kk',
' mm mm mm aaaaa sssss sssss ww ww eeeee rr rrr kk kk',
' mmm mmm mm aa ss ss :: ww ww ww ee ee rrr kk kk',
' mm mm mm aaaaaa ssss ssss ww wwww ww eeeeeee rr kkkk',
' mm mm mm aa aaa ss ss :: www www ee rr kk kk',
' mm mm mm aaa aa sssss sssss ww ww eeeee rr kk kk%n',
' - m e d i a e n v i r o n m e n t s -%n',
' http://www.masswerk.at%n',
' * web design & development',
' * clientside & serverside programming',
' * HTML, Perl, JavaScript, Java, Flash, WAP/WML',
' * graphic design & layout%n',
' * multimedia semiotics & conceptualization',
' * consulting & research on traditional & new media%n',
' fine sites since 1996.%n',
'Type "mail" for email, "web" for website, "help" for available commands.'
],1);
}
function commandFeatures(env) {
env.stdin=new VfsFileHandle(new VfsFile('p',[
'%+r System Features %-r',
os_greeting,
' by mass:werk - media environments; (c) N.Landsteiner <http://www.masswerk.at>',
' ',
' JS/UIX is a virtual terminal and UN*X-like operating system for web browsers.',
' It is written completely in JavaScript using DHTML for the display.',
' The current version is v0.46 (Feb. 2007).',
' ',
' ',
'%+uFeatures%-u:',
' ',
' * virtual machine and operating system with:',
' * keyboard input supporting US-ASCII charset',
' * multi-line input and output, line-editing, insert mode',
' * input modes (getChar, cooked, raw mode)',
' * scrolling & cursor movements',
' * overlapping type styles (plain, %+rreverse%-r, %+uunderline%-u, %+iitalics%-i, %+sstrike%-s)',
' * window splitting (e.g. reserved status line)',
' * shell (sh alike) with',
' - command parsing and interpretation',
' supports quoting with backslash, single- and double-quotes, backticks',
' - variables and aliases with interpolation',
' - positional parameters',
' - command path (configurable commands)',
' - simple shell-scripts (e.g. initialization via /etc/profile)',
' - command history (cursor up/down)',
' - output redirection (>, >>), pipes (|)',
' * virtual file-system with permissions, users & groups',
' * filehandles, STDIN/STDOUT/STDERR streaming',
' * environment- and process-management with fork, subshells, pipes',
' * cooperative multitasking',
' * man-system',
' * vi - visual editor',
' * export/backup and import of home-directory for intersession oparibility.',
' * web and mail launch (external)',
' * compatibility for all major browsers',
' (e.g. Netscape 4+, MS IE 4+, DOM-aware browsers as Mozilla.)',
' ',
'%+uTo Do%-u:',
' ',
' * shell globbing ',
' * some more commands (e.g. grep, egrep ...)',
' * some shell features (e.g. input redirection)',
' * complex shell scripts (control structures and clauses)',
' * flock / semaphores',
' * %+icould be:%-i interface for remote tasks via CGI',
' ',
'%+uWhat For?%-u',
' ',
' First of all, because it\'s possible.',
' Second this could well be the basis for some fail-safe remote-job-systems',
'needing a local environment for command parsing, interpretation and/or exe-',
'cution. Think of \'rlogin\' to a remote host (via a CGI-process) for an example.',
' ',
'LEGAL',
'This system and its applications are built entirely from scratch and subject to',
'an all black-box-type re-engeering. I state not to have known any line of code',
'of any UN*X-type system (e.g. AT&T/SCO-UNIX, AIX, HPUIX, SunOS, BSD, Darwin,',
'Irix, Linux, Minix, GNU, etc) or any of its applications. This implementation:',
'All rights reserved, (c) 2003, N. Landsteiner, mass:werk - media environments.',
' '
]));
env.stdin.close();
env.args=['more'];
commandMore(env)
}
function commandApropos(env) {
var args=env.args;
if (args.length==1) {
krnlFOut(env.stderr,'usage: '+args[0]+' <command> - no argument')
return
};
var cmd=args[1];
if ((manPages[cmd]) && (manPages[cmd].content) && (manPages[cmd].content.apropos)) {
krnlFOut(env.stdout,manPages[cmd].content.apropos)
}
else {
krnlFOut(env.stderr,'no entry found for "'+cmd+'".')
}
}
function commandMan(env) {
var args=env.args;
if (args.length==1) {
krnlFOut(env.stderr,'usage: '+args[0]+' <command> - no argument')
return
};
var cmd=args[1];
var opt=krnlGetOpts(args,1);
if (krnlTestOpts(opt,'p')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
if (opt.p) {
krnlFOut(env.stderr,'opening new window with full list ...');
manPrintAll()
}
else if (manPages[cmd]) {
var fh=(env.stdin)? env.stdin : new VfsFileHandle(new VfsFile('p',[]));
//if (env.stdout) fh=env.stdout;
//else {
// fh=new VfsFileHandle(new VfsFile('p',[]));
// env.pager=true
//};
var mc=manPages[cmd].content;
krnlFOut(fh,'%+uSynopsis%-u:',1);
if (mc.synopsis) krnlFOut(fh,mc.synopsis+'\n',1);
//krnlFOut(fh,'%+uDescription%-u:',1);
if (mc.description) {
krnlFOut(fh,mc.description,1);
};
if (mc.link) {
krnlFOut(fh,'=> '+mc.link,1);
env.stdin=fh;
env.args=['man',mc.link];
commandMan(env);
return
};
if (mc.arguments) {
krnlFOut(fh,'\n%+uArguments%-u:',1);
var ofs=0;
for (var i=0; i<mc.arguments.length; i+=2) ofs=Math.max(ofs,mc.arguments[i].length);
for (var i=0; i<mc.arguments.length; i+=2) {
var arg=mc.arguments[i];
var s=' '+arg+' ';
for (var k=arg.length; k<ofs; k++) s+=' ';
var lines=mc.arguments[i+1].split('\n');
for (var n=0; n<lines.length; n++) {
if (n>0) {
for (var m=0; m<ofs+6; m++) s+=' ';
};
s+=lines[n];
if (n<lines.length-1) s+='\n';
};
krnlFOut(fh,s,1)
}
};
if (mc.options) {
krnlFOut(fh,'\n%+uOptions%-u:',1);
var ofs=0;
for (var i=0; i<mc.options.length; i+=2) ofs=Math.max(ofs,mc.options[i].length);
for (var i=0; i<mc.options.length; i+=2) {
var opt=mc.options[i];
var s=' '+opt+' ';
for (var k=opt.length; k<ofs; k++) s+=' ';
var lines=mc.options[i+1].split('\n');
for (var n=0; n<lines.length; n++) {
if (n>0) {
for (var m=0; m<ofs+6; m++) s+=' ';
};
s+=lines[n];
if (n<lines.length-1) s+='\n';
};
krnlFOut(fh,s,1)
}
};
//if (env.pager) {
//env.stdout=null;
fh.close();
env.stdin=fh;
env.args=['more'];
commandMore(env)
//}
}
else if (usrALIAS[cmd]) {
var s=usrALIAS[cmd];
var cs='';
for (var i=0; i<s.length; i++) {
var ch=s.charAt(i);
if (krnlWordChar(ch)) cs+=ch
else break
}
krnlFOut(env.stderr,'"'+cmd+'" is an alias to "'+usrALIAS[cmd]+'".\n=> see "man '+cs+'" for more.',1)
}
else {
krnlFOut(env.stderr,'no manual entry found for "'+cmd+'".')
}
}
function manPrintAll() {
var cmds=new Array();
var cmdcols=0;
for (var n in manPages) {
cmds[cmds.length]=n;
cmdcols=Math.max(cmdcols,n.length)
};
cmds.sort();
cmdcols+=2;
var s='Man Pages for '+os_version+'\n\n\n';
s+='Contents:\n\n';
for (var cnr=0; cnr<cmds.length; cnr++) {
var cmd=cmds[cnr];
if (cmd=='shell') continue;
var mc=manPages[cmd].content;
s+=' '+cmd;
if (mc.apropos) {
for (var i=cmd.length; i<=cmdcols; i++) s+=' ';
s+=mc.apropos
};
s+='\n'
};
s+='\n'
for (var cnr=0; cnr<cmds.length; cnr++) {
var cmd=cmds[cnr];
var mc=manPages[cmd].content;
s+='\n\n'+cmd+'\n\n';
s+='* Synopsis:\n';
if (mc.synopsis) s+=txtStripStyles(mc.synopsis);
s+='\n\n';
//s+='* Description:\n';
if (mc.description) {
s+=txtStripStyles(mc.description)+'\n';
};
if (mc.link) {
s+='\n=> see "'+mc.link+'".\n';
continue
};
if (mc.arguments) {
s+='\n* Arguments:\n';
var ofs=0;
for (var i=0; i<mc.arguments.length; i+=2) ofs=Math.max(ofs,mc.arguments[i].length);
for (var i=0; i<mc.arguments.length; i+=2) {
var arg=mc.arguments[i];
var sl=' '+arg+' ';
for (var k=arg.length; k<ofs; k++) sl+=' ';
var lines=mc.arguments[i+1].split('\n');
for (var n=0; n<lines.length; n++) {
if (n>0) {
for (var m=0; m<ofs+6; m++) sl+=' ';
};
sl+=txtStripStyles(lines[n])+'\n'
};
s+=sl
}
};
if (mc.options) {
s+='\n* Options:\n';
var ofs=0;
for (var i=0; i<mc.options.length; i+=2) ofs=Math.max(ofs,mc.options[i].length);
for (var i=0; i<mc.options.length; i+=2) {
var opt=mc.options[i];
var sl=' '+opt+' ';
for (var k=opt.length; k<ofs; k++) sl+=' ';
var lines=mc.options[i+1].split('\n');
for (var n=0; n<lines.length; n++) {
if (n>0) {
for (var m=0; m<ofs+6; m++) sl+=' ';
};
sl+=txtStripStyles(lines[n])+'\n'
};
s+=sl
}
}
};
s+='\n\n(c) mass:werk 2003; <http://www.masswerk.at>';
var w=window.open();
w.document.write('<xmp>');
w.document.write(s);
w.document.write('<\/xmp>');
w.document.close();
if (window.focus) w.focus();
}
function commandLs(env) {
var dir=new Array();
var a=1;
var opt=krnlGetOpts(env.args,1);
if (opt.length>0) a+=opt.length;
if (krnlTestOpts(opt,'aCFilL')<0) {
krnlFOut(env.stderr,'illegal option - use "./<filename>" for files of "-*".');
return
};
var dname=(env.args[a])? vfsGetPath(env.args[a],env.cwd) : env.cwd;
var dfile=vfsOpen(dname,4);
if (dfile==0) {
krnlFOut(env.stderr,dname+': no such file or directory.');
return
}
else if (dfile<0) {
krnlFOut(env.stderr,dname+': permission denied.');
return
}
else if (dfile.kind!='d') {
dfile=vfsGetParent(dname);
dir=[vfsBasename(dname)];
opt.a=1
}
else {
dir=vfsDirList(dfile)
};
var l=0;
var so='';
for (var i=0; i<dir.length; i++) {
var n=dir[i];
if ((n.charAt(0)=='.') && (opt.a==null)) continue;
var ff;
if (n=='.') ff=dfile
else if (n=='..') {
ff=vfsGetParent(dname)
if (ff<=0) continue
}
else ff=dfile.lines[n];
if (opt.l) {
if (ff.kind=='d') so+='d'
else if (ff.kind=='l') so+='l'
else so+='-';
if (ff.mode) {
var m=ff.mode;
var ma=new Array();
for (var mi=0; mi<4; mi++) {
ma[mi]=m&7;
m>>=3
};
for (var mi=2; mi>=0; mi--) {
so+= (ma[mi]&4)? 'r':'-';
so+= (ma[mi]&2)? 'w':'-';
if (mi==0) {
if (ma[3]&1) {
so+= (ma[mi]&1)? 't':'T';
}
else {
so+= (ma[mi]&1)? 'x':'-';
}
}
else so+= (ma[mi]&1)? 'x':'-';
}
}
else so+='---------';
so+=' ';
so+=(ff.icnt)? ff.icnt:'?';
var fo=(ff.owner!=null)? krnlUIDs[ff.owner] : 'unknown';
var fg=(ff.group!=null)? krnlGIDs[ff.group] : 'unknown';
while (fo.length<8) fo+=' ';
while (fg.length<8) fg+=' ';
so+=' '+fo+' '+fg+' ';
if (ff.kind=='d') so+='-------- '
else if (ff.kind=='b') so+='bin/n.a. '
else so+=txtFillLeft(vfsGetSize(ff),8)+' ';
so+= vfsGetMdate(ff) +' '+n;
if (i<dir.length-1) so+='\n';
}
else {
if (opt.F) {
if (ff.kind=='d') n+='/'
else if ((ff.kind=='b') || (ff.mode&0111)) n+='*'
else if (ff.kind=='l') n+='@';
};
if (opt.i) n+=' '+ ff.inode;
if ((opt.L) || (((env.stdout) || (opt.i)) && (!opt.C))) {
so+=n;
if (i<dir.length-1) so+='\n';
continue
};
var s='';
if (l>0) {
s=' ';
for (var k=(l+2)%12; k<12; k++) s+=' ';
};
l+=n.length+s.length;
if (l>=conf_cols) {
so+='\n';
l=n.length;
s=''
};
so+=s+n
}
};
krnlFOut(env.stdout,so)
}
function commandTouch(env) {
var files=new Array();
if (env.stdin) {
for (var i=0; i<env.stdin.lines.length; i++) files[files.length]=vfsGetPath(env.stdin.lines[i],env.cwd);
};
for (var i=1; i<env.args.length; i++) files[files.length]=vfsGetPath(env.args[i],env.cwd);
for (var n=0; n<files.length; n++) {
var fn=files[n];
if (fn=='') continue;
var f=vfsOpen(fn,2);
if (f<0) krnlFOut(env.stderr,fn+': permission denied.')
else if (f==0) {
f=vfsCreate(fn,'f',0660);
if (f<0) krnlFOut(env.stderr,fn+': permission denied.')
else if (f==0) krnlFOut(env.stderr,fn+': no such directory '+vfsDirname(fn));
}
else f.touch()
}
}
function commandPs(env) {
var buf=new Array();
buf[buf.length]=' PID COMMAND';
buf[buf.length]='---------------';
for (var i=0; i<krnlPIDs.length; i++) {
if (krnlPIDs[i]) {
s=' '+i;
if (i<10) s+=' ';
if (i<100) s+=' ';
if (i<1000) s+=' ';
s+=' '+krnlPIDs[i].id;
buf[buf.length]=s
}
};
krnlFOut(env.stdout, buf);
}
function commandWc(env) {
var l=0;
var w=0;
var c=0;
var fh=null;
var a=1;
var opt=krnlGetOpts(env.args,1);
if (krnlTestOpts(opt,'clw')<0) {
krnlFOut(env.stderr,'illegal option.');
return
};
if (opt.length>0) a+=opt.length
else {
opt.l=1;
opt.c=1;
opt.w=1
};
if (env.stdin) fh=env.stdin
else if (env.args[a]) {
var fn=vfsGetPath(env.args[a],env.cwd);
var f=vfsOpen(fn,4);
if (f<0) {
krnlFOut(env.stderr,fn+': permission denied.');
return
}
if (f==0) {
krnlFOut(env.stderr,env.args[a]+': file not found.');
return
}
else if (f) fh=new VfsFileHandle(f);
};
if (fh!=null) {
var ldscrp=fh.readLine();
while (ldscrp[0]>=0) {
if (opt.l) l++;
if (opt.c) c+=ldscrp[1].length+1;
if (opt.w) {
var word=false;
var ln=ldscrp[1];
for (var i=0; i<ln.length; i++) {
if (ln.charCodeAt(i)>32) {
if (!word) {
word=true;
w++
}
}
else if (word) {
word=false
}
}
};
ldscrp=fh.readLine();
}
};
var s='';
if ((opt.l) && (opt.c) && (opt.w)) {
s=txtFillLeft(l,8)+' '+txtFillLeft(w,7)+' '+txtFillLeft(c,7)
}
else {
if (opt.l) {
if (s) s+=' ';
s+=l
};
if (opt.w) {