00001 #include <stdio.h>
00002 #include <soi_key.h>
00003 #include <printk.h>
00004
00005 extern int write_log(char *fmt, ...);
00006
00007 void logkey (KEY *key)
00008 {
00009 switch(key->type) {
00010 case KEYTYP_STRING:
00011 write_log ("%s:\tKEYTYP_STRING\t%s\n", key->name, (char*)key->val);
00012 break;
00013 case KEYTYP_BYTE:
00014 write_log ("%s:\tKEYTYP_BYTE\t%d\n", key->name, *(char*)key->val);
00015 break;
00016 case KEYTYP_INT:
00017 write_log ("%s:\tKEYTYP_INT\t%d\n", key->name, *(int*)key->val);
00018 break;
00019 case KEYTYP_FLOAT:
00020 write_log ("%s:\tKEYTYP_FLOAT\t%13.6e\n", key->name, *(float*)key->val);
00021 break;
00022 case KEYTYP_DOUBLE:
00023 write_log ("%s:\tKEYTYP_DOUBLE\t%23.6e\n", key->name, *(double*)key->val);
00024 break;
00025 case KEYTYP_TIME:
00026 write_log ("%s:\tKEYTYP_TIME\t%23.6e\n", key->name, *(TIME*)key->val);
00027 break;
00028 case KEYTYP_SHORT:
00029 write_log ("%s:\tKEYTYP_SHORT\t%d\n", key->name, *(short*)key->val);
00030 break;
00031 case KEYTYP_LONG:
00032 write_log ("%s:\tKEYTYP_LONG\t%d\n", key->name, *(long*)key->val);
00033 break;
00034 case KEYTYP_UBYTE:
00035 write_log ("%s:\tKEYTYP_UBYTE\t%d\n", key->name, *(unsigned char*)key->val);
00036 break;
00037 case KEYTYP_USHORT:
00038 write_log ("%s:\tKEYTYP_USHORT\t%d\n", key->name, *(unsigned short*)key->val);
00039 break;
00040 case KEYTYP_UINT:
00041 write_log ("%s:\tKEYTYP_UINT\t%d\n", key->name, *(unsigned int*)key->val);
00042 break;
00043 case KEYTYP_ULONG:
00044 write_log ("%s:\tKEYTYP_ULONG\t%d\n", key->name, *(unsigned long*)key->val);
00045 break;
00046 case KEYTYP_UINT64:
00047 write_log ("%s:\tKEYTYP_UINT64\t%ld\n", key->name, *(uint64_t*)key->val);
00048 break;
00049 case KEYTYP_UINT32:
00050 write_log ("%s:\tKEYTYP_UINT32\t%d\n", key->name, *(uint32_t*)key->val);
00051 break;
00052 case KEYTYP_FILEP:
00053 write_log ("%s:\tKEYTYP_FILEP\t%ld\n", key->name, *(FILE **)key->val);
00054 break;
00055 default:
00056 write_log ("(void)\n");
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 int file2keylist(char *filename, KEY **list) {
00070 FILE *fp2;
00071 char *token;
00072 char line[256], name[96], type[96], value[96];
00073
00074 if((fp2=fopen(filename, "r")) == NULL) {
00075 printk("**Can't keylist file %s\n", filename);
00076 return(1);
00077 }
00078 while(fgets(line, 128, fp2)) {
00079 if(line[0] == '#' || line[0] == '\n') continue;
00080 if(token=(char *)strtok(line, ":\t")) {
00081 strcpy(name, token);
00082 if(token=(char *)strtok(NULL, "\t\n")) {
00083 strcpy(type, token);
00084 }
00085 else {
00086 fclose(fp2);
00087 return(1);
00088 }
00089 if(token=(char *)strtok(NULL, "\t\n"))
00090 strcpy(value, token);
00091 if(!strcmp(type, "KEYTYP_STRING")) {
00092 setkey_str(list, name, value);
00093 continue;
00094 }
00095 if(!strcmp(type, "KEYTYP_INT")) {
00096 setkey_int(list, name, atoi(value));
00097 continue;
00098 }
00099 if(!strcmp(type, "KEYTYP_FILEP")) {
00100 setkey_fileptr(list, name, (FILE *)strtoul(value, NULL, 0));
00101 continue;
00102 }
00103 if(!strcmp(type, "KEYTYP_BYTE")) {
00104 setkey_byte(list, name, (char)atoi(value));
00105 continue;
00106 }
00107 if(!strcmp(type, "KEYTYP_UBYTE")) {
00108 setkey_ubyte(list, name, (unsigned char)atoi(value));
00109 continue;
00110 }
00111 if(!strcmp(type, "KEYTYP_SHORT")) {
00112 setkey_short(list, name, (short)atoi(value));
00113 continue;
00114 }
00115 if(!strcmp(type, "KEYTYP_USHORT")) {
00116 setkey_ushort(list, name, (unsigned short)atoi(value));
00117 continue;
00118 }
00119 if(!strcmp(type, "KEYTYP_UINT")) {
00120 setkey_uint(list, name, (unsigned int)atoi(value));
00121 continue;
00122 }
00123 if(!strcmp(type, "KEYTYP_LONG")) {
00124 setkey_long(list, name, (long)atol(value));
00125 continue;
00126 }
00127 if(!strcmp(type, "KEYTYP_ULONG")) {
00128 setkey_ulong(list, name, (unsigned long)strtoul(value,NULL,0));
00129 continue;
00130 }
00131 if(!strcmp(type, "KEYTYP_FLOAT")) {
00132 setkey_float(list, name, (float)atof(value));
00133 continue;
00134 }
00135 if(!strcmp(type, "KEYTYP_DOUBLE")) {
00136 setkey_double(list, name, (double)strtod(value,NULL));
00137 continue;
00138 }
00139
00140
00141
00142
00143
00144 }
00145 else {
00146 fclose(fp2);
00147 return(1);
00148 }
00149 }
00150 fclose(fp2);
00151 return(0);
00152 }