File: toshset.cc

package info (click to toggle)
toshset 1.46-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 284 kB
  • ctags: 429
  • sloc: cpp: 1,997; sh: 1,507; ansic: 909; makefile: 132
file content (1383 lines) | stat: -rw-r--r-- 43,926 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
/* toshset.cc
 *
 * Copyright (C) 1999, 2000 Charles D. Schwieters
 *
 * Based on tools by Jonathan Buzzard
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

static char const rcsid[]="$Id: toshset.cc,v 1.15 2002/01/29 01:43:54 schwitrs Exp $";
static char const rcsversion[]="$State: Exp $";


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include <ctype.h>
#include<errno.h>
#include<signal.h>
#include<paths.h>
#include<pwd.h>
#include<features.h>
#include <iostream.h>
#include <streambuf.h>
#include <strstream.h>
#include <iomanip.h>
#include "cdsList.hh"
#include "cdsString.hh"
#ifdef __GLIBC__
#include<sys/perm.h>
#endif

#include"sci.h"
#include"hci.h"
#include "wildmat.h"

enum { EMPTY, PRIMARY, AUXILLARY };

static int id;

static char versionString[80];
static int  verbose=0;
static int  longQuery=0;


/*
 * Convert a single character to an interger, similar to atoi 
 */
inline int ctoi(char *s)
{
	return ((*s>='0') && (*s<='9')) ? *s-'0' : -1;
}


struct ValueSet {
  const char* iString;
  unsigned short sciCode;
  const char* oString;
  ValueSet(const char*          input,
		 unsigned short sciCode,
	   const char*          output) :
    iString(input), sciCode(sciCode), oString(output) {}
};
 
struct Feature {
  const char* name;
  Feature(const char* name) : name(name) {}
  virtual ~Feature() {}
  virtual int action(const char**) const=0;
  virtual int query(ostrstream &os) const=0;
  virtual const char* error(int) const=0;
};

struct ToggleFeature : public Feature {
  int&        toggleVar;
  //  const char* name;
  ToggleFeature(      int&  toggleVar,
		const char* name) :
    Feature(name), toggleVar(toggleVar) {}
  virtual ~ToggleFeature() {}
  virtual int action(const char**) const 
    { toggleVar = (toggleVar?0:1); return 1;}
  virtual int query(ostrstream &os) const {return 1;}
  virtual const char* error(int) const {return "";}
};

struct SciFeature : public Feature {
  unsigned short sciMode;
  //  const char* name;
  SciFeature(unsigned short sciMode,const char* name) :
    Feature(name), sciMode(sciMode) {}
  CDSList<ValueSet*> values;
  void addValue(const char* input,
		      unsigned short sciCode,
		const char* output) 
    { values.append(new ValueSet(input,sciCode,output)); }
  virtual ~SciFeature() 
    { for (int i=0 ; i<values.size() ; i++) delete values[i];}
  virtual int action(const char**) const;
  virtual int query(ostrstream &os) const;
  const char*  error(int code) const;
};

const char*
SciFeature::error(int code) const
{
 const char* ret;
 static char defret[80];
 snprintf(defret,80,"%s (%d)","unknown error.",code);
 ret = defret;
 switch ( code ) {
   case SCI_FAILURE         : ret =  "FAILURE"         ; break;
   case SCI_NOT_SUPPORTED   : ret =  "NOT_SUPPORTED"   ; break;
   case SCI_ALREADY_OPEN    : ret =  "ALREADY_OPEN"    ; break;
   case SCI_NOT_OPENED      : ret =  "NOT_OPENED"      ; break;
   case SCI_INPUT_ERROR     : ret =  "INPUT_ERROR"     ; break;
   case SCI_WRITE_PROTECTED : ret =  "WRITE_PROTECTED" ; break;
   case SCI_NOT_PRESENT     : ret =  "NOT_PRESENT"     ; break;
   case SCI_NOT_READY       : ret =  "NOT_READY"       ; break;
   case SCI_DEVICE_ERROR    : ret =  "DEVICE_ERROR"    ; break;
   case SCI_NOT_INSTALLED   : ret =  "NOT_INSTALLED"   ; break;
 }
 return ret;
} /* SciFeature::error */


int
SciFeature::action(const char **s) const
{
 SMMRegisters reg;
 reg.ebx = sciMode;
 for (int i=0 ; i<values.size() ; i++)
   if ( strcmp( values[i]->iString , *s ) == 0 ) {
     reg.ecx = values[i]->sciCode;
     reg.edx = reg.esi = reg.edi = 0;
     int ret=SciSet( &reg );
     if ( ret == SCI_SUCCESS )
       return 1;
     else {
       cerr << "SciFeature:action: error when setting feature " << name << '\n'
	    << "\tSciSet returned " << error(ret) << '\n';
       return 0;
     }
   }
 cerr << "SCIFeature: error when setting feature " << name 
      << ":\n\terror in command-line option: " << *s << "\n";
 cerr << "valid settings are:\n";
 for (int i=0 ; i<values.size() ; i++)
   cerr << '\t' << values[i]->iString << '\n';
 return 0;
} /* SciFeature::action */

int
SciFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = sciMode;
 int ret = SciGet( &reg );
 if ( ret == SCI_SUCCESS ) {
   for (int i=0 ; i<values.size() ; i++)
     if ( reg.ebx == values[i]->sciCode ) {
       os << name << ": " << values[i]->oString << ends;
       return 0;
     }
   cerr << "SciFeature::query: received an unexpected response for feature " 
	<< name << ": " << reg.ebx << '\n';
 } 
//else 
//   cerr << "SciFeature:query: error when querying feature " << name << '\n'
//	  << "\tSciGet returned " << error(ret) << '\n';
 return ret;
} /* SciFeature::action */

struct TimeFeature : public SciFeature {
  TimeFeature(unsigned short sciMode,const char* name) :
    SciFeature(sciMode,name) {}
  virtual ~TimeFeature() 
    { for (int i=0 ; i<values.size() ; i++) delete values[i];}
  virtual int action(const char**) const;
  virtual int query(ostrstream& os) const;
};

int
TimeFeature::action(const char **s) const
{
 if (!**s) {
   cout << "<dis|HH:MM[/everyday|DD/MM[/YYYY]]> time/date to wake\n";
   return 0;
 }
 SMMRegisters reg;
 enum {
   ALARM_TIME  = 0x0001,
   ALARM_DATE  = 0x0002,
   ALARM_EVERY = 0x0004,
   ALARM_YEAR  = 0x0008
 };
 int support = 0x0000;
 reg.ebx = SCI_ALARM_TIME;
 if (SciGet(&reg)==SCI_SUCCESS) {
   support |= ALARM_TIME;
 }

 reg.ebx = SCI_ALARM_DATE;
 if ( SciGet(&reg) == SCI_SUCCESS ) {
   support |= ALARM_DATE;
   if ( SCI_DATE_EVERYDAY(reg.edx) )
     support |= ALARM_EVERY;
   if (SCI_YEAR(reg.edx)!=1990)
     support |= ALARM_YEAR;
 }
 if ( verbose ) 
   cout << "TimeFeature: supported date elements: " 
	<< (support&ALARM_DATE?"month/day ":"")
	<< (support&ALARM_YEAR?"year ":"")
	<< (support&ALARM_EVERY?"everyday\n":"\n");

 reg.ebx = sciMode;
 int ret=0;
 if ( strncmp(*s,"dis",3) == 0 ) {
   reg.ecx = SCI_ALARM_DISABLED;
   ret = SciSet( &reg );
 } else {
   istrstream istr(*s);
   char delim; 
   char hour[4];
   istr.get(hour,4,':'); istr.get( delim );
   char minute[4];
   istr.get(minute,4,'/'); istr.get( delim );
   reg.ecx = SCI_TIME( atoi(hour) , atoi(minute) );
   ret = SciSet( &reg );
   if ( delim == '/' && ret == SCI_SUCCESS && support&ALARM_DATE ) {
     reg.ebx = SCI_ALARM_DATE;
     reg.ecx = 0;
     delim = '\0';
     char day[9];
     istr.get(day,9,'/'); istr.get( delim );
     if ( delim=='\0' && strcmp(day,"everyday")==0 ) {
       if (support&ALARM_EVERY) reg.ecx = 1;
     } else {
       char month[3];
       delim = '\0';
       istr.get(month,3,'/'); istr.get( delim );
       if ( delim=='/' && support&ALARM_YEAR) {
	 char year[9];
	 istr.get(year,9,'/');
	 reg.ecx = SCI_FULLDATE( atoi(year) , atoi(month) , atoi(day) );
       } else 
	 reg.ecx = SCI_DATE( atoi(month) , atoi(day) );
     }
     
     if (reg.ecx) ret=SciSet( &reg );
     if ( ret != SCI_SUCCESS ) {
       cerr << "TimeFeature:action: error when setting date for feature " 
	    << name << '\n'
	    << "\tSciSet returned " << error(ret) << '\n';
       return 0;
     }
   }
 }
 if ( ret == SCI_SUCCESS )
   return 1;
 else 
   cerr << "TimeFeature:action: error when setting feature " << name << '\n'
	<< "\tSciSet returned " << error(ret) << '\n';
 return 0;
} /* TimeFeature::action */

int
TimeFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = sciMode;
 int ret = SciGet( &reg );
 if ( ret == SCI_SUCCESS ) {
   os << name << ": ";
   if ( reg.ebx == SCI_ALARM_DISABLED ) 
     os << "disabled";
   else {
     os << setfill('0') << setw(2) << SCI_HOUR(reg.ebx) << ':' 
	<< setfill('0') << setw(2) << SCI_MINUTE(reg.ebx) << ' ';
     reg.eax = SCI_ALARM_DATE;
     SciGet( &reg );
     int year = SCI_YEAR(reg.ebx);
     if ( SCI_DATE_EVERYDAY(reg.ebx) )
       os << "everyday";
     else {
       if ( year !=1990 ) 
	 os << year << '/';
       os << SCI_MONTH(reg.ebx) << '/'
	  << SCI_DAY(reg.ebx);
     }
   }
   os << ends;
   return 0;
 } 
 return ret;
//else 
//   cerr << "TimeFeature:query: error when querying feature " << name << '\n'
//	  << "\tSciGet returned " << error(ret) << '\n';
// return 0;
} /* SciFeature::action */

struct PasswdFeature : public SciFeature {
  unsigned short passwdType;
  PasswdFeature(unsigned short passwdType,const char* name) :
    SciFeature(SCI_PASSWORD,name), passwdType(passwdType) {}
  virtual ~PasswdFeature() {}
  virtual int action(const char**) const;
  virtual int query(ostrstream& os) const;
};

int
PasswdFeature::action(const char **s) const // doesn't work
{
 // int trys=0;

 char password[11];
 memset(password,0,10);
 strncpy(password,*s,10);
 cout << "setting password to >" << password << "<\n";

	SMMRegisters reg;

	reg.eax = 0xf4f4;
	reg.ebx = SCI_PASSWORD;
	reg.ecx = SCI_USER_PASSWORD;
	reg.edx = *(password+3) + *(password+2)*0x100 + *(password+1)*0x10000 +
	        *(password)*0x1000000;
	reg.esi = *(password+7) + *(password+6)*0x100 + *(password+5)*0x10000 +
	        *(password+4)*0x1000000;
	reg.edi = *(password+9) + *(password+8)*0x100;
//	  reg.ebx = SCI_PASSWORD;
//	  reg.ecx = SCI_USER_PASSWORD;//passwdType;
//	  reg.edx = *(password+3) + *(password+2)*0x100 + 
//			 *(password+1)*0x10000 +
//			 *(password)*0x1000000;
//	  reg.esi = *(password+7) + *(password+6)*0x100 + 
//			 *(password+5)*0x10000 +
//			 *(password+4)*0x1000000;
//	  reg.edi = *(password+9) + *(password+8)*0x100;

	int ret = SciSet( &reg );

	//	*trys = (int) (reg.edx & 0xffff);

	//	return (int) (reg.eax & 0xff00)>>8;

// SMMRegisters reg;
// reg.setting = 0;
// reg.ebx = SCI_PASSWORD;
// reg.ecx = passwdType;
// reg.ecx = SCI_USER_PASSWORD;
// 
// reg.edx  = *(passwd+3) + *(passwd+2)*0x100 + *(passwd+1)*0x10000 +
//		   *(passwd  )*0x1000000;
// reg.esi = *(passwd+7) + *(passwd+6)*0x100 + *(passwd+5)*0x10000 +
//		   *(passwd+4)*0x1000000;
// reg.esi2 = *(passwd+9) + *(passwd+8)*0x100;
// 
// SciSet(&reg);
//
 int trys = (int) (reg.edx & 0xffff);
 cout << "trys: " << trys << '\n';

 // int ret = (int) (reg.eax & 0xff00)>>8;

 ///  int ret = SciSetPassword(passwd,passwdType,&trys);
 // int ret = SciSetPassword(passwd,SCI_USER_PASSWORD,&trys);
 if ( ret == SCI_SUCCESS )
   return 1;
 else 
   cerr << "PasswdFeature:action: error when setting feature " << name << '\n'
	  << "\tSciSetPasswd returned " << error(ret) << '\n';
 return 0;
} /* PasswdFeature::action */

int
PasswdFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = sciMode;
 reg.ebx = passwdType;
 int ret = SciGet( &reg );
 if ( ret == SCI_SUCCESS ) {
   os << name << ": ";
   switch ( reg.ebx ) {
     case 0 : os << "not registered"; break;
     case 1 : os << "registered"; break;
     default : os << "unexpected response: " << reg.ebx;
   }
   os << ends;
   return 0;
 } 
//else 
//   cerr << "PasswdFeature:query: error when querying feature " << name << '\n'
//	  << "\tSciGet returned " << error(ret) << '\n';
// return 0;
 return ret;
} /* PasswdFeature::query */

struct PercentFeature : public SciFeature {
  PercentFeature(unsigned short sciMode,const char* name) :
    SciFeature(sciMode,name) {}
  ~PercentFeature() {}
  int action(const char**) const {return 1;}
  int query(ostrstream& os) const;
};

int
PercentFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = sciMode;
 SciGet( &reg );
 int percent = ((100*reg.ebx)/reg.ecx);
 os << name << ": " << percent << "\% " << ends;
 return 0;
} /* Feature::action */


struct HciFeature : public Feature {
  unsigned short hciMode;
  HciFeature(unsigned short hciMode,const char* name) :
    Feature(name), hciMode(hciMode) {}
  CDSList<ValueSet*> values;
  void addValue(const char* input,
		      unsigned short hciCode,
		const char* output) 
    { values.append(new ValueSet(input,hciCode,output)); }
  virtual ~HciFeature() 
    { for (int i=0 ; i<values.size() ; i++) delete values[i];}
  virtual int action(const char**) const;
  virtual int query(ostrstream& os) const;
  virtual const char* error(int) const;
};

const char*
HciFeature::error(int code) const
{
 const char* ret;
 static char defret[80];
 snprintf(defret,80,"%s (%d)","unknown error.",code);
 ret = defret;
 switch (code) {
   case HCI_FAILURE         : ret = "FAILURE"         ; break;
   case HCI_NOT_SUPPORTED   : ret = "NOT_SUPPORTED"   ; break;
   case HCI_INPUT_ERROR     : ret = "INPUT_ERROR"     ; break;
   case HCI_WRITE_PROTECTED : ret = "WRITE_PROTECTED" ; break;
   case HCI_FIFO_EMPTY      : ret = "FIFO_EMPTY"      ; break;
 }
 return ret;
} /* HciFeature::error */

int
HciFeature::action(const char **s) const
{
 SMMRegisters reg;
 reg.eax = HCI_SET;
 reg.ebx = hciMode;
 reg.edx = 0;
 if (**s)
   for (int i=0 ; i<values.size() ; i++)
     if ( strcmp( values[i]->iString , *s ) == 0 ) {
       reg.ecx =values[i]->sciCode;
       int ret = HciFunction( &reg );
       if ( ret == HCI_SUCCESS ) 
	 return 1;
       else {
	 cerr << "HCI error setting " << name << '\n';
	 cerr << "\tHciFunction returned: " << error(ret) <<'\n';
       return 0;
       }
     }
 cerr << "HCI error setting " << name 
      << ":\n\terror in command-line option: " << *s << "\n";
 cerr << "valid settings are:\n";
 for (int i=0 ; i<values.size() ; i++)
   cerr << '\t' << values[i]->iString << '\n';
 return 0;
} /* Feature::action */

int
HciFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = HCI_GET;
 reg.ebx = hciMode;
 reg.ecx = 0;
 int ret = HciFunction( &reg );
 if ( ret == HCI_SUCCESS ) {
   for (int i=0 ; i<values.size() ; i++)
     if ( reg.ecx == values[i]->sciCode ) {
       os << name << ": " << values[i]->oString << ends;
       return 0;
     }
   cerr << "HciFeature::query: received an unexpected response for feature " 
	<< name << ": " << reg.ecx << '\n';
 } else {
   cerr << "HciFeature::query: HciFunction for feature "
	<< name << " returned " << error(ret) << '\n';
 }
 return 1;
 // return ret;
} /* HciFeature::query */

struct LbaFeature : public HciFeature {
  LbaFeature(unsigned short hciMode,const char* name) :
    HciFeature(hciMode,name) {}
  virtual ~LbaFeature() {}

  //  virtual int action(const char**) const;
  virtual int action(const char **s) const {
   SMMRegisters reg;
   reg.eax = HCI_SET;
   reg.ebx = hciMode;
   reg.edx = 0;
   if ((*s)[0]=='0' &&
       tolower((*s)[1])=='x') {
     istrstream is( (*s)+2 );
     is >> hex >> reg.ecx;
   } else {
     istrstream is( *s );
     is >> reg.ecx;
   }
   cout << "setting lba to " << reg.ecx << '\n';
   int ret = HciFunction( &reg );
   if ( ret == HCI_SUCCESS ) 
     return 1;
   else {
     cerr << "HCI error setting " << name << '\n';
     cerr << "\tHciFunction returned: " << error(ret) <<'\n';
     return 0;
   }
  };

  virtual int query(ostrstream& os) const {
   SMMRegisters reg;
   reg.eax = HCI_GET;
   reg.ebx = hciMode;
   reg.ecx = 0;
   int ret = HciFunction( &reg );
   if ( ret == HCI_SUCCESS ) {
     os << name << ": 0x" << hex << reg.ecx << dec << " (" << reg.ecx << ")\n";
     return 0;
   } else {
     cerr << "HciFeature::query: HciFunction for feature "
	  << name << " returned " << error(ret) << '\n';
   }
   return 1;
  }
};
   

struct OwnerStringFeature : public HciFeature {
  OwnerStringFeature(unsigned short hciMode,const char* name) :
    HciFeature(hciMode,name) {}
  virtual ~OwnerStringFeature() {}
  virtual int action(const char**) const;
  virtual int query(ostrstream& os) const;
};

int
OwnerStringFeature::action(const char **s) const
{
 SMMRegisters reg;
 String str(*s);
 str.gsub("\\n","\n\r");       //deal w newlines and tabs
 str.gsub("\\t" ,"        "); 
 // str.gsub("\n[^\r]","\n\r"); //doesn't work
 for (int i=0 ; i<(int)str.length() ; i++)
   if ( str[i] == '\n' )
     str = subString(str,0,i) + "\n\r" + subString(str,i+1,-1);
 // str.gsub("	","        "); 
 // str.gsub("\011","        "); 
 // str.gsub("\t","        "); 
 const char* p=str;
 // cout << "setting owner string to " << p << '\n';
 if ( strlen(p) > 512 ) {//FIX: should query for this
   cerr << "string too long\n";
   return 0;
 }
 for (int i=0 ; i<512 ; i+=4) {
   reg.eax = HCI_SET;
   reg.ebx = HCI_OWNERSTRING;
   reg.ecx = 4;
   reg.esi = i;
   reg.edx = 0;
   for (int j=0 ; j<4 ; j++,p++) {
     unsigned int tmp=0;
     tmp |= *p;
     tmp = tmp<<8*j;
     reg.edx |= tmp;
     if ( !*p) {
//	 reg.edx = reg.edx<<(3-j)*8;
	 break;
     }
   }
   //   cout << "edx: " << hex << reg.edx << dec << '\n';
   int ret = HciFunction(&reg);
   if ( ret != HCI_SUCCESS ) {
     i -= 4;
     p -= 4;
   }
//     cerr << "HCI error setting feature " << name << '\n'
//	    << "\tHciFunction returned " << error(ret) 
//	    << "for i= " << i << '\n';
//     return 0;
 }
 return 1;
} /* OwnerStringFeature::action */

int
OwnerStringFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = HCI_GET;
 reg.ebx = hciMode;
 reg.ecx = 0;
 reg.esi = 0;
 int ret = HciFunction( &reg );
 os << name << ": ";
 if ( ret == HCI_SUCCESS ) {
   int length = (reg.ecx & 0xffff0000)>>16;
   
   os << "[ max length: " << length << ']' << '\n';

   for (int i=0 ; i<length ; i+=4) {
     reg.eax = HCI_GET;
     reg.ebx = hciMode;
     reg.ecx = 4;
     reg.esi = (unsigned long) i;
     if ( HciFunction( &reg ) != HCI_SUCCESS )
       i -= 4;
     else {
       //int valid = reg.ecx & 0xffff;
       if ( reg.edx == 0x0000 ) {
	 os << '\n' << ends;
	 return 0;
       }
       //printf("index=%d  valid=%d\n", reg.esi, valid);
       unsigned int characters = reg.edx;
       for (int j=0 ; j<4 ; j++) {
	 char c = (char) characters & 0xff;
	 os << c;
	 //printf("%02x ", c);
	 characters = characters >> 8;
       }
       
       //     if ((c>=0x20) && (c<=0x80))
//	 *(string++) = c;
       //     if (c==0x0d)
//	 *(string++) = c;
     }
   }
//   char temp[5];
//   memcpy(temp,&reg.ecx,4);
//   temp[4]='\0';
//   os << name << ": " << temp[0] << temp[1] << temp[2] << temp[3] << '\n';
//   os << reg.ecx << '\n' << ends;
//   cout	<< name << ": " << temp[3] << '\n';
//   cout	<< reg.ecx << '\n';
   //os << name << ':' << ( reg.cx?(char*)reg.cx:(char*)"" ) << ends;
   os << '\n';
 } 
 os << ends;
//else {
//   cerr << "HciFeature::query: HciFunction for feature "
//	  << name << " returned " << error(ret) << '\n';
//   return 0;
// }
 return ret;
} /* OwnerStringFeature::query */

struct LCDFeature : public HciFeature {
  LCDFeature(unsigned short hciMode,const char* name) :
    HciFeature(hciMode,name) {}
  CDSList<ValueSet*> values;
  void addValue(const char* input,
		      unsigned short hciCode,
		const char* output) 
    { values.append(new ValueSet(input,hciCode,output)); }
  virtual ~LCDFeature() {}
  virtual int action(const char**) const { return 0; }
  virtual int query(ostrstream& os) const;
};

int
LCDFeature::query(ostrstream& os) const
{
 SMMRegisters reg;
 reg.eax = HCI_GET;
 reg.ebx = hciMode;
 int ret = HciFunction( &reg );
 if ( ret == HCI_SUCCESS ) {
   os << name << ": ";
   switch ( (reg.ecx & 0xff00)>>8 ) {
     case HCI_640_480 : os << " 640x480, "; break;
     case HCI_800_600 : os << " 800x600, "; break;
     case HCI_1024_768: os << "1024x768, "; break;
     case HCI_1024_600: os << "1024x600, "; break;
     case HCI_800_480 : os << " 800x480, "; break;
     default: os << "resolution (" << ((reg.ecx & 0xff00)>>8 ) << ") unknown";
   }
   switch ( reg.ecx & 0xff ) {
     case HCI_STN_MONO   : os << "mono STN  "; break;
     case HCI_STN_COLOUR : os << "colour STN"; break;
     case HCI_9BIT_TFT   : os << "9 bit TFT "; break; 
     case HCI_12BIT_TFT  : os << "12 bit TFT"; break; 
     case HCI_18BIT_TFT  : os << "18 bit TFT"; break; 
     case HCI_24BIT_TFT  : os << "24 bit TFT"; break;	   
     default: os << "type (" << (reg.ecx&0xff) << ") unknown";
   }
   os << ends;
   return 0;
 }
 return ret;
} /* LCDFeature::query */


class CmdLineArg {
public:
  virtual ~CmdLineArg() {}
  virtual const char* flag() const =0;
  virtual int         numArgs() const =0;
  virtual const char* usage() const =0;
  virtual void        action(const int&,
			     const char**) =0;
  virtual const char* name() const { return ""; }
};

class CmdLineArgs {
  CDSList<const char*> argList;
  const char*        path;
  CmdLineArg** options;
public:
  CmdLineArgs(const char*        path,
		    CmdLineArg** options) : path(path), options(options) {}

  int process(const int          argc,
	      const char**       argv);
  void usage();
  void error(const char *err);
};


void 
CmdLineArgs::usage()
{
 cerr << "usage: " << path << " [args]\n";
 cerr << "\twhere args are one or more of:\n";
 for ( CmdLineArg** opp=options ; *opp ; opp++ ) {
   CmdLineArg* op = *opp;
   cerr << op->flag() << ": " << op->usage() << '\n';
 }
} /* CmdLineArgs::usage */

void 
CmdLineArgs::error(const char *err)
{
 cerr << "Command line error: " << err << '\n';
 usage();
 exit(2);
}


int 
CmdLineArgs::process(const int          argc,
		     const char**       argv)
{
 int  argcnt  = argc-1;
 const char **argvp = argv;
 int ret=1;

 while (argvp++ , (argcnt--) > 0) {
   if (**argvp == '-') {
     int ok=0;
     for ( CmdLineArg** opp=options ; *opp ; opp++ ) {
       CmdLineArg* op = *opp;
       if ( strcmp( op->flag() , argvp[0] ) == 0 ) {
	 const char **p = argvp;
	 const char* empty = "";
	 if (argcnt < op->numArgs())
	   //	   error( op->flag() );
	   p = &empty;
	 op->action( argcnt, p );
	 argcnt-=op->numArgs(); argvp+=op->numArgs();
	 ok=1;
	 break;
       }
     }
     if ( !ok ) {
       error("unrecognized command-line option");
       ret=0;
     }
   }
   // deal with default arguments (no ``-'')
   argList.append( argvp[0] );
 }
 return ret;
} /* CmdLineArg::process */

template<int args>
class ArgSet : public CmdLineArg {
  const char* flag_;
  const char* usage_;
  const Feature* feature;
public:
  ArgSet(const char* flag,
	   const char* usage,
	   const Feature* feature) :
    flag_(flag), usage_(usage), feature(feature) {}
  const char* flag() const    { return flag_; }
  int         numArgs() const { return args; }
  const char* usage() const   { return usage_; }
  void        action(const int&   i,
		     const char** a)
    { 
     const char* empty = "";
     const char* p[args];
     String tmpStr;
     for (int j=0 ; j<i ; j++)
       p[j] = a[j+1];
     for (int j=i ; j<args ; j++)
       p[j] = empty;
     for (int j=0 ; j<args ; j++) {
       if ( String(p[j]) == "-" ) {
	 read(cin,tmpStr);
	 if ( tmpStr[ tmpStr.length()-1 ] == '\n' ) // strip trailing nl
	   tmpStr = subString(tmpStr,0,tmpStr.length()-1);
	 p[j] = (const char*)tmpStr;
       }
       //cout << "arg[" << j << "]: " << p[j] << ' ' << strlen(p[j]) << '\n';
     }
     feature->action( p ); 
     ostrstream os; 
     feature->query(os); 
     //     const char* c=os.rdbuf();
     if ( os.rdbuf()->pcount() )
       cout << os.rdbuf() << '\n'; 
    }
  const char* name() const { return feature->name; }
};

class ArgVersion : public CmdLineArg {
  const char* flag_;
  const char* usage_;
//  int numArgs_;
//  CDSList<Feature*> features;
//  CmdLineArg** options;
public:
  ArgVersion(const char* flag,
	     const char* usage) :
    flag_(flag), usage_(usage) {}

  const char* flag() const    { return flag_; }
  int         numArgs() const { return 0; }
  const char* usage() const   { return usage_; }
  void        action(const int&   numArgs,
		     const char** a      ) {
   cout << "toshset version: " << VERSION << endl;
  }
};

class ArgQuery : public CmdLineArg {
  const char* flag_;
  const char* usage_;
  int numArgs_;
  CDSList<Feature*> features;
  CmdLineArg** options;
public:
  ArgQuery(const char* flag,
	   const char* usage,
	   const CDSList<Feature*>& features,
		 CmdLineArg** options) :
    flag_(flag), usage_(usage), numArgs_(0), features(features),
    options(options) {}
  const char* flag() const    { return flag_; }
  int         numArgs() const { return numArgs_; }
  const char* usage() const   { return usage_; }
  void        action(const int&   numArgs,
		     const char** a      );
};

void
ArgQuery::action(const int&   numArgs,
		 const char** a      ) 
{
 String glob = "*";
 if (numArgs == 0) {
   cout << versionString;
   numArgs_=0;
 } else {
   glob = String("*") + a[1] + "*";
   numArgs_=1;
 }

 int cnt=0;
 for (int i=0 ; i<features.size() ; i++) {
   ostrstream os;
   if ( wildmat(features[i]->name , glob,1) ) {
     int ret = features[i]->query(os);
     if ( ret==0 ) {
       cout.setf(ios::left);
       const char* str = os.str();
       if ( longQuery ) {
	 const char* flag = "";
	 for (CmdLineArg** cl=options ; *cl ; cl++)
	   if ( features[i]->name == (*cl)->name() ) 
	     flag = (*cl)->flag();
	 cout << ' ' << setw(10) << ' ' << flag
	      << setw(38) << (str?str:"") << '\n';
       } else {
	 cout << ' ' << setfill(' ') <<setw(38)<< (str?str:"");
	 if ( cnt%2==1 )
	   cout << '\n';
       }
       cnt++;
     }
     if ( ret && verbose )
       cerr << "error when querying feature: " << features[i]->name << ": "
	    << features[i]->error(ret) << '\n';
   }
 }
 if ( !longQuery && cnt%2==1 )
   cout << '\n';
} /* ArgQuery::action */


int 
main(      int   argc, 
     const char* argv[])
{
 int version,bios;

 ///* this program *must* be run as root */
 //if (getuid()) {
 //  cerr << argv[0] << ": must be run as root.\n";
 //  return 1;
 //}

 if (ioperm(0xb2, 1, 1)) {
   cerr << argv[0] << ": can't get I/O permissions.\n" 
	<< "\tPlease run as root.\n";
   return 1;
 }

 /* do some quick checks on the laptop */

 if (SciSupportCheck(&version)==1) {
   fprintf(stderr, "%s: this computer is not supported\n",argv[0]);
   return 1;
 }

 bios = HciGetBiosVersion();
 if (bios==0) {
   fprintf(stderr, "%s: unable to get BIOS version\n",argv[0]);
   return 1;
 }

 if (HciGetMachineID(&id)==HCI_FAILURE) {
   fprintf(stderr, "%s: unable to get machine "
	   "identification\n",argv[0]);
   return 1;
 }

 /* drop root priveleges to minimize the risk of running suid root */

 seteuid(getuid()); //FIX: use setuid/setgid
 setegid(getgid());

 switch (id) {
		case 0xfc02: /* Satellite Pro 4290 */
		case 0xfc09: /* Satellite 2610CDT, 2650XDVD */
		case 0xfc0c: /* Tecra 8100x */
		case 0xfc0f: /* Satellite 2060CDS/CDT */
		case 0xfc10: /* Satellite 2550/2590 */
		case 0xfc11: /* Portage 3110CT */
		case 0xfc12: /* Portage 3300CT */
		case 0xfc13: /* Portage 7020CT */
		case 0xfc15: /* Satellite 4030/4030X/4050/4060/4070/4080/4090/4100X CDS/CDT */
		case 0xfc17: /* Satellite 2520/2540 CDS/CDT */
		case 0xfc18: /* Satellite 4000/4010 XCDT */
		case 0xfc19: /* Satellite 4000/4010/4020 CDS/CDT */
		case 0xfc1a: /* Tecra 8000x */
		case 0xfc1c: /* Satellite 2510CDS/CDT */
		case 0xfc1d: /* Portage 3020x */
		case 0xfc1f: /* Portage 7000CT/7010CT */
		case 0xfc39: /* T2200SX */
		case 0xfc40: /* T4500C */
		case 0xfc41: /* T4500 */
		case 0xfc45: /* T4400SX/SXC */
		case 0xfc54: /* Libretto 50CT ??????? */
		case 0xfc5f: /* T3300SL */
		case 0xfc64: /* Satellite 1800-S253 */
		case 0xfc69: /* T1900C */
		case 0xfc6a: /* T1900 */
                case 0xfc6c: /* satellite 5005-s504 */
		case 0xfc6d: /* T1850C */
		case 0xfc6e: /* T1850 */
		case 0xfc6f: /* T1800 */
		case 0xfc7e: /* T4600C */
		case 0xfc7f: /* T4600 */
		case 0xfc8a: /* T6600C */
		case 0xfc91: /* T2400CT */
		case 0xfc97: /* T4800CT */
		case 0xfc99: /* T4700CS */
		case 0xfc9b: /* T4700CT */
		case 0xfc9d: /* T1950 */
		case 0xfc9e: /* T3400/T3400CT */
		case 0xfcb2: /* Libretto 30CT */
		case 0xfcba: /* T2150 */
		case 0xfcbe: /* T4850CT */
		case 0xfcc0: /* Satellite Pro 420x */
		case 0xfcc1: /* Satellite 100x */
		case 0xfcc3: /* Tecra 710x/720x */
		case 0xfcc6: /* Satellite Pro 410x */
		case 0xfcca: /* Satellite Pro 400x */
		case 0xfccb: /* Portage 610CT */
		case 0xfccc: /* Tecra 700x */
		case 0xfccf: /* T4900CT */
		case 0xfcd0: /* Satellite 300x */
		case 0xfcd1: /* Tecra 750CDT */
		case 0xfcd2: /* Vision Connect -- what is this??? */
		case 0xfcd4: /* Tecra 510x */
		case 0xfcd5: /* Satellite 200x */
                case 0xfcd6: /* Libretto 50CT */
		case 0xfcd7: /* Satellite Pro 430x */
		case 0xfcd8: /* Tecra 740x */
		case 0xfcd9: /* Portage 660CDT */
		case 0xfcda: /* Tecra 730x/730X */
		case 0xfcdb: /* Portage 620CT */
		case 0xfcdc: /* Portage 650CT */
		case 0xfcdd: /* Satellite 110x */
		case 0xfcdf: /* Tecra 500x */
		case 0xfce0: /* Tecra 780DVD */
		case 0xfce2: /* Satellite 300x */
		case 0xfce3: /* Satellite 310x */
		case 0xfce4: /* Satellite Pro 490x */
		case 0xfce5: /* Libretto 100CT */
		case 0xfce6: /* Libretto 70CT */
		case 0xfce7: /* Tecra 540x/550x */
		case 0xfce8: /* Satellite Pro 470x/480x */
		case 0xfce9: /* Tecra 750DVD */
		case 0xfcea: /* Libretto 60 */
		case 0xfceb: /* Libretto 50CT */
		case 0xfcec: /* Satellite 320x/330x, Satellite 2500CDS */
		case 0xfced: /* Tecra 520x/530x */
		case 0xfcef: /* Satellite 220x, Satellite Pro 440x/460x */
     snprintf(versionString,80,
	      " machine id: 0x%04x    BIOS version:"
	      " %d.%d    SCI version: %d.%d\n", id,
	      (bios & 0xff00)>>8, bios & 0xff,
	      (version & 0xff00)>>8, version & 0xff);
     break;
   default:
     printf("%s: unrecognized machine "
	    "identification:\n",argv[0]);
     printf("machine id : 0x%04x    BIOS version : %d.%d"
	    "    SCI version: %d.%d\n", id,
	    (bios & 0xff00)>>8, bios & 0xff,
	    (version & 0xff00)>>8, version & 0xff);
     printf("\nplease email this information to "
	    "charles@schwieters.org and include the "
	    "model\nand model number, eg. Libretto 50CT "
	    " model number PA1249E\n");
 }

 /* check to see if a copy of wmTuxTime is already running */
 
 SciOpenInterface();

 CDSList<Feature*> features;

 ToggleFeature verboseFeature(verbose,"verbose");
 ToggleFeature longFeature(longQuery,"long query");

 SciFeature batteryFeature(SCI_BATTERY_SAVE,"battery save mode");
 batteryFeature.addValue( "user"   , SCI_USER_SETTINGS , "user settings");
 batteryFeature.addValue( "full"   , SCI_FULL_POWER    , "full power");
 batteryFeature.addValue( "low"    , SCI_LOW_POWER     , "low power");
 batteryFeature.addValue( "economy", SCI_ECONOMY       , "economy settings");
 batteryFeature.addValue( "normal" , SCI_NORMAL_LIFE   , "normal life");
 batteryFeature.addValue( "long"   , SCI_LONG_LIFE     , "long life");
 batteryFeature.addValue( "full"   , SCI_FULL_LIFE     , "full life");
 features.append(&batteryFeature);

 HciFeature acFeature(HCI_AC_ADAPTOR,"power source");
 acFeature.addValue( ""   , 3   , "battery" );
 acFeature.addValue( ""   , 4   , "external" );
 features.append(&acFeature);

 HciFeature backlightFeature(HCI_BACKLIGHT,"LCD backlight");
 backlightFeature.addValue( "on"   , HCI_ENABLE   , "on" );
 backlightFeature.addValue( "off"  , HCI_DISABLE   , "off" );
 features.append(&backlightFeature);

 HciFeature fanFeature(HCI_FAN,"fan");
 // fanFeature.addValue( "on"   , HCI_ENABLE   , "on" );
 fanFeature.addValue( "low"  , 128   , "low" );
 fanFeature.addValue( "high" , 255   , "high" );
 fanFeature.addValue( "off"  , HCI_DISABLE   , "off" );
 features.append(&fanFeature);

 HciFeature selectBayFeature(HCI_SELECT_STATUS,"select bay");
 // fanFeature.addValue( "on"   , HCI_ENABLE   , "on" );
 selectBayFeature.addValue( ""  , HCI_NOTHING  , "empty" );
 selectBayFeature.addValue( ""  , HCI_FLOPPY   , "floppy" );
 selectBayFeature.addValue( ""  , HCI_ATAPI    , "CDROM" );
 selectBayFeature.addValue( ""  , HCI_IDE      , "hard disk" );
 selectBayFeature.addValue( ""  , HCI_BATTERY  , "battery" );
 features.append(&selectBayFeature);

 HciFeature selectBayLockFeature(HCI_LOCK_STATUS,"select bay lock");
 // fanFeature.addValue( "on"   , HCI_ENABLE   , "on" );
 selectBayLockFeature.addValue( "engage"  , HCI_LOCKED   , "engaged" );
 selectBayLockFeature.addValue( "dis"     , HCI_UNLOCKED , "disabled" );
 features.append(&selectBayLockFeature);

 SciFeature irFeature(SCI_INFRARED_PORT,"IR port");
 irFeature.addValue( "on"   , SCI_ON    , "on" );
 irFeature.addValue( "off"  , SCI_OFF   , "off" );
 features.append(&irFeature);

// HciFeature firFeature(HCI_FIR_STATUS,"HCI IR port");
// firFeature.addValue( "on"   , HCI_ENABLE   , "on" );
// firFeature.addValue( "off"  , HCI_DISABLE   , "off" );
// features.append(&firFeature);

 HciFeature videoFeature(HCI_VIDEO_OUT,"Video out");
 videoFeature.addValue("int" ,HCI_INTERNAL , "internal" );
 videoFeature.addValue("ext" ,HCI_EXTERNAL , "external" );
 videoFeature.addValue("both",HCI_SIMULTANEOUS , "both internal and external");
 videoFeature.addValue("tv",HCI_TVOUT , "tv output");
 features.append(&videoFeature);

 int supportsHibernation = 1; //doesn't work on my 8100
 HciFeature hibInfoFeature(HCI_HIBERNATION_INFO,"Hibernation info");
// if ( supportsHibernation )
//   features.append(&hibInfoFeature);

 LbaFeature hibLbaFeature(HCI_HIBERNATION_LBA,"Hibernation LBA");
 if ( supportsHibernation )
   features.append(&hibLbaFeature);

 LCDFeature fpanelFeature(HCI_FLAT_PANEL,"flat panel");
 // fpanelFeature.addValue("" , 516 , "1024x768 active matrix");
// fanFeature.addValue( "on"   , HCI_ENABLE   , "on" );
// fanFeature.addValue( "off"  , HCI_DISABLE   , "off" );
 features.append(&fpanelFeature);

 SciFeature beepFeature(SCI_SYSTEM_BEEP,"system beep");
 beepFeature.addValue( "on"   , SCI_ON   , "on" );
 beepFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&beepFeature);

 SciFeature lcdFeature(SCI_LCD_BRIGHTNESS,"lcd brightness");
 lcdFeature.addValue("bright" , SCI_BRIGHT       , "bright" );
 lcdFeature.addValue("semi"   , SCI_SEMI_BRIGHT  , "semi-bright" );
 lcdFeature.addValue("super"  , SCI_SUPER_BRIGHT , "super-bright" );
 features.append(&lcdFeature);

 SciFeature processingFeature(SCI_PROCESSING,"CPU speed");
 processingFeature.addValue("slow" , SCI_LOW  , "slow" );
 processingFeature.addValue("fast" , SCI_HIGH  , "fast" );
 features.append(&processingFeature);

 SciFeature sleepFeature(SCI_SLEEP_MODE,"CPU sleep mode");
 sleepFeature.addValue( "on"   , SCI_ON   , "on" );
 sleepFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&sleepFeature);

 SciFeature dstretchFeature(SCI_SLEEP_MODE,"Display stretch");
 dstretchFeature.addValue( "on"   , SCI_ON   , "on" );
 dstretchFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&dstretchFeature);

 SciFeature cpuCacheFeature(SCI_CPU_CACHE,"CPU cache");
 cpuCacheFeature.addValue( "on"   , SCI_ON   , "on" );
 cpuCacheFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&cpuCacheFeature);

 //????
 SciFeature cachePolicyFeature(SCI_CACHE_POLICY,"cache policy");
 cachePolicyFeature.addValue( "write-back"    , 0 , "write back" );
 cachePolicyFeature.addValue( "write-through" , 1 , "write through" );
 features.append(&cachePolicyFeature);

 SciFeature volumeFeature(SCI_SPEAKER_VOLUME,"speaker volume");
 volumeFeature.addValue( "off"    , SCI_VOLUME_OFF    , "off"    );
 volumeFeature.addValue( "low"    , SCI_VOLUME_LOW    , "low"    );
 volumeFeature.addValue( "medium" , SCI_VOLUME_MEDIUM , "medium" );
 volumeFeature.addValue( "high"   , SCI_VOLUME_HIGH   , "high"   );
 features.append(&volumeFeature);

 SciFeature batAlarmFeature(SCI_BATTERY_ALARM,"battery alarm");
 batAlarmFeature.addValue( "on"   , SCI_ON   , "on" );
 batAlarmFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&batAlarmFeature);

 SciFeature panAlarmFeature(SCI_PANEL_ALARM,"panel alarm");
 panAlarmFeature.addValue( "on"   , SCI_ON   , "on" );
 panAlarmFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&panAlarmFeature);

 SciFeature panPowerFeature(SCI_PANEL_POWER,"panel power");
 panPowerFeature.addValue( "on"   , SCI_ON   , "on" );
 panPowerFeature.addValue( "off"  , SCI_OFF  , "off" );
 features.append(&panPowerFeature);

 SciFeature hddFeature(SCI_HDD_AUTO_OFF,"hard disk auto-off time");
 hddFeature.addValue( "dis" , SCI_TIME_DISABLED , "disabled");
 hddFeature.addValue( "1"   , SCI_TIME_01 , "1 minute");
 hddFeature.addValue( "3"   , SCI_TIME_03 , "3 minutes");
 hddFeature.addValue( "5"   , SCI_TIME_05 , "5 minutes");
 hddFeature.addValue( "10"  , SCI_TIME_10 , "10 minutes");
 hddFeature.addValue( "15"  , SCI_TIME_15 , "15 minutes");
 hddFeature.addValue( "20"  , SCI_TIME_20 , "20 minutes");
 hddFeature.addValue( "30"  , SCI_TIME_30 , "30 minutes");
 features.append(&hddFeature);

 SciFeature displayFeature(SCI_DISPLAY_AUTO,"display auto-off time");
 displayFeature.addValue( "dis" , SCI_TIME_DISABLED , "disabled");
 displayFeature.addValue( "1"   , SCI_TIME_01 , "1 minute");
 displayFeature.addValue( "3"   , SCI_TIME_03 , "3 minutes");
 displayFeature.addValue( "5"   , SCI_TIME_05 , "5 minutes");
 displayFeature.addValue( "10"  , SCI_TIME_10 , "10 minutes");
 displayFeature.addValue( "15"  , SCI_TIME_15 , "15 minutes");
 displayFeature.addValue( "20"  , SCI_TIME_20 , "20 minutes");
 displayFeature.addValue( "30"  , SCI_TIME_30 , "30 minutes");
 features.append(&displayFeature);

 HciFeature hciPowerFeature(HCI_POWER_UP,"HCI power-up mode");
 hciPowerFeature.addValue( "boot"      , SCI_BOOT         	  , "boot");
 hciPowerFeature.addValue( "resume"    , SCI_RESUME       	  , "resume");
 hciPowerFeature.addValue( "hibernate" , SCI_HIBERNATE    	  , "hibernate");
 hciPowerFeature.addValue( "quick"     , SCI_QUICK_HIBERNATE , "quick-hibernate");
 features.append(&hciPowerFeature);

 SciFeature powerFeature(SCI_POWER_UP,"power-up mode");
 powerFeature.addValue( "boot"      , SCI_BOOT         	  , "boot");
 powerFeature.addValue( "resume"    , SCI_RESUME       	  , "resume");
 powerFeature.addValue( "hibernate" , SCI_HIBERNATE    	  , "hibernate");
 powerFeature.addValue( "quick"     , SCI_QUICK_HIBERNATE , "quick-hibernate");
 features.append(&powerFeature);

 PercentFeature batteryPercentFeature(SCI_BATTERY_PERCENT,"battery percent");
 features.append(&batteryPercentFeature);

 SciFeature coolingFeature(SCI_COOLING_METHOD,"cooling method");
 coolingFeature.addValue( "perform"   , SCI_PERFORMANCE	  , "performance");
 coolingFeature.addValue( "quiet"     , SCI_QUIET  	  , "quiet");
 coolingFeature.addValue( "other"     , 2      	          , "other");
 features.append(&coolingFeature);

 TimeFeature wakeAlarmFeature(SCI_ALARM_POWER,"power-up alarm");
// wakeAlarmFeature.addValue( "on"   , SCI_ALARM_ENABLED	, "on" );
// wakeAlarmFeature.addValue( "off"  , SCI_ALARM_DISABLED	, "off" );
 features.append(&wakeAlarmFeature);

 TimeFeature autoOffFeature(SCI_SYSTEM_AUTO,"auto-off time");
// wakeAlarmFeature.addValue( "on"   , SCI_ALARM_ENABLED	, "on" );
// wakeAlarmFeature.addValue( "off"  , SCI_ALARM_DISABLED	, "off" );
 features.append(&autoOffFeature);

 SciFeature parallelFeature(SCI_PARALLEL_PORT,"parallel port mode");
 parallelFeature.addValue( "ecp" ,SCI_PARALLEL_ECP, "ecp" );
 parallelFeature.addValue( "spp" ,SCI_PARALLEL_SPP, "spp" );
 parallelFeature.addValue( "ps2" ,SCI_PARALLEL_PS2, "ps2" );
 // parallelFeature.addValue
 features.append(&parallelFeature);

 SciFeature secBatFeature(SCI_2ND_BATTERY,"second battery");
 features.append(&secBatFeature);

 SciFeature standbyFeature(SCI_STANDBY_TIME,"Standby time");
 features.append(&standbyFeature);

 SciFeature hibernationFeature(SCI_HIBERNATION,"Hibernation");
 hibernationFeature.addValue("disable" , 0 , "not configured");
 hibernationFeature.addValue("enable"  , 1 , "configured");
 features.append(&hibernationFeature);

 SciFeature bootFeature(SCI_BOOT_METHOD,"boot method");
 bootFeature.addValue( "fdhdcd" , SCI_FD_HD , "floppy->hard disk->CDROM");
 bootFeature.addValue( "hdfdcd" , SCI_HD_FD , "hard disk->floppy->CDROM");
 bootFeature.addValue( "fdcdhd" , 2         , "floppy->CDROM->hard disk");
 bootFeature.addValue( "hdcdfd" , 3         , "hard disk->CDROM->floppy");
 bootFeature.addValue( "cdfdhd" , 4         , "CDROM->floppy->hard disk");
 bootFeature.addValue( "cdhdfd" , 5         , "CDROM->hard disk->floppy");
 features.append(&bootFeature);

 //FIX: need to enumerate these
 HciFeature bootDeviceFeature(HCI_BOOT_DEVICE,"boot device");
 //features.append(&bootDeviceFeature);

 PasswdFeature userPasswdFeature(SCI_USER_PASSWORD,"user password");
 features.append(&userPasswdFeature);

 PasswdFeature superPasswdFeature(SCI_SUPER_PASSWORD,"supervisor password");
 features.append(&superPasswdFeature);

 OwnerStringFeature ownerStringFeature(HCI_OWNERSTRING,"owner string");
 features.append(&ownerStringFeature);

 CmdLineArg* argList[] = { 
   new ArgSet<1>("-b","<on|off> enable/disable system beep" ,     &beepFeature),
   new ArgSet<1>("-lcd","<string> set lcd brightness"       ,     &lcdFeature),
   new ArgSet<1>("-pow","<setting> set power-up mode",            &powerFeature),
   new ArgSet<1>("-hpow","<setting> set power-up mode",          &hciPowerFeature),
   new ArgSet<1>("-vol","<0-4> set beep (and modem!) volume",       &volumeFeature),
   new ArgSet<1>("-hdd","<num> number of minutes until disk spindown",&hddFeature),
   new ArgSet<1>("-dstretch","<on|off> display stretch",&dstretchFeature),
   new ArgSet<1>("-d","<num> number of minutes until display auto-off",&displayFeature),
   new ArgSet<1>("-c","<quiet|perform> set cooling method",&coolingFeature),
   new ArgSet<1>("-bs","<setting> battery-save mode",&batteryFeature),
   new ArgSet<1>("-bl","<on|off> lcd backlight",&backlightFeature),
   new ArgSet<1>("-fan","<on|off> fan",&fanFeature),
   new ArgSet<1>("-hib","<enable|disable> hibernation",&hibernationFeature),
   new ArgSet<1>("-lba","hibernation address",&hibLbaFeature),
   new ArgSet<1>("-video","<int|ext|both|tv> video out",&videoFeature),
   new ArgSet<1>("-cpu","<fast|slow> CPU speed",&processingFeature),
   new ArgSet<1>("-cpucache","<on|off> CPU cache",&cpuCacheFeature),
   new ArgSet<1>("-sleep","<on|off> sleep mode",&sleepFeature),
   new ArgSet<1>("-balarm","<on|off> battery alarm",&batAlarmFeature),
   new ArgSet<1>("-palarm","<on|off> lid-closed alarm",&panAlarmFeature),
   new ArgSet<1>("-walarm",
		 "<dis|HH:MM[/everyday|DD/MM[/YYYY]]> time/date to wake",
		 &wakeAlarmFeature),
   new ArgSet<1>("-ostring","<string> owner string",&ownerStringFeature),
   new ArgSet<1>("-ppower","<on|off> power-off when lid closed",&panPowerFeature),
   new ArgSet<1>("-boot","<boot sequence>",&bootFeature),
   new ArgSet<1>("-parallel","<option> parallel port mode",&parallelFeature),
   //
   // the passwd feature is badly broken in this version: do no use
   // CDS - 7/11/02
   //
   //new ArgSet<1>("-upasswd","<password> set user password",&userPasswdFeature),
   //new ArgSet<1>("-spasswd","<password> set supervisor password",&superPasswdFeature),
   new ArgSet<1>("-autooff","<dis|time> auto-off time",&autoOffFeature),
   new ArgQuery("-q",
		"[glob] query option matching glob (or all if no arg)",
		features,argList),
   new ArgSet<0>("-v","toggle verbose mode",&verboseFeature),
   new ArgSet<0>("-l","toggle long query",&longFeature),
   new ArgVersion("-version","print toshset version"),
   0 };

 CmdLineArgs args( argv[0], argList );

 if ( argc<2 ) {
   args.usage();
   return 1;
 } else 
   if ( !args.process(argc,argv) )
     return 1;

 // cout << "successfull.\n";
 SciCloseInterface();

 return 0;
}

#if __GNUG__
#include "cdsList.cc"
#include "cdsString.cc"
#endif