| 65 | | printf("Usage: %s [OPTION]... [CHIP]...\n",PROGRAM); |
| 66 | | printf(" -c, --config-file Specify a config file (default: %s)\n", |
| 67 | | DEFAULT_CONFIG_FILE); |
| 68 | | puts(" -h, --help Display this help text\n" |
| 69 | | " -s, --set Execute `set' statements (root only)\n" |
| 70 | | " -f, --fahrenheit Show temperatures in degrees fahrenheit\n" |
| 71 | | " -A, --no-adapter Do not show adapter for each chip\n" |
| 72 | | " -u Raw output (debugging only)\n" |
| 73 | | " -v, --version Display the program version\n" |
| 74 | | "\n" |
| 75 | | "Use `-' after `-c' to read the config file from stdin.\n" |
| 76 | | "If no chips are specified, all chip info will be printed.\n" |
| 77 | | "Example chip names:\n" |
| 78 | | "\tlm78-i2c-0-2d\t*-i2c-0-2d\n" |
| 79 | | "\tlm78-i2c-0-*\t*-i2c-0-*\n" |
| 80 | | "\tlm78-i2c-*-2d\t*-i2c-*-2d\n" |
| 81 | | "\tlm78-i2c-*-*\t*-i2c-*-*\n" |
| 82 | | "\tlm78-isa-0290\t*-isa-0290\n" |
| 83 | | "\tlm78-isa-*\t*-isa-*\n" |
| 84 | | "\tlm78-*"); |
| | 65 | printf("Usage: %s [OPTION]... [CHIP]...\n", PROGRAM); |
| | 66 | printf(" -c, --config-file Specify a config file (default: %s)\n", |
| | 67 | DEFAULT_CONFIG_FILE); |
| | 68 | puts(" -h, --help Display this help text\n" |
| | 69 | " -s, --set Execute `set' statements (root only)\n" |
| | 70 | " -f, --fahrenheit Show temperatures in degrees fahrenheit\n" |
| | 71 | " -A, --no-adapter Do not show adapter for each chip\n" |
| | 72 | " -u Raw output (debugging only)\n" |
| | 73 | " -v, --version Display the program version\n" |
| | 74 | "\n" |
| | 75 | "Use `-' after `-c' to read the config file from stdin.\n" |
| | 76 | "If no chips are specified, all chip info will be printed.\n" |
| | 77 | "Example chip names:\n" |
| | 78 | "\tlm78-i2c-0-2d\t*-i2c-0-2d\n" |
| | 79 | "\tlm78-i2c-0-*\t*-i2c-0-*\n" |
| | 80 | "\tlm78-i2c-*-2d\t*-i2c-*-2d\n" |
| | 81 | "\tlm78-i2c-*-*\t*-i2c-*-*\n" |
| | 82 | "\tlm78-isa-0290\t*-isa-0290\n" |
| | 83 | "\tlm78-isa-*\t*-isa-*\n" |
| | 84 | "\tlm78-*"); |
| 122 | | /* Size hardcoded for better performance. |
| 123 | | Don't forget to count the trailing \0! */ |
| 124 | | size_t deg_latin1_size = 3; |
| 125 | | char *deg_latin1_text[2] = {"\260C", "\260F"}; |
| 126 | | size_t nconv; |
| 127 | | size_t degstr_size = sizeof(degstr); |
| 128 | | char *degstr_ptr = degstr; |
| 129 | | |
| 130 | | iconv_t cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1"); |
| 131 | | if (cd != (iconv_t) -1) { |
| 132 | | nconv = iconv(cd, &(deg_latin1_text[fahrenheit]), °_latin1_size, |
| 133 | | °str_ptr, °str_size); |
| 134 | | iconv_close(cd); |
| 135 | | |
| 136 | | if (nconv != (size_t) -1) |
| 137 | | return; |
| 138 | | } |
| | 123 | /* Size hardcoded for better performance. |
| | 124 | Don't forget to count the trailing \0! */ |
| | 125 | size_t deg_latin1_size = 3; |
| | 126 | char *deg_latin1_text[2] = { "\260C", "\260F" }; |
| | 127 | size_t nconv; |
| | 128 | size_t degstr_size = sizeof(degstr); |
| | 129 | char *degstr_ptr = degstr; |
| | 130 | |
| | 131 | iconv_t cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1"); |
| | 132 | if (cd != (iconv_t) -1) { |
| | 133 | nconv = iconv(cd, &(deg_latin1_text[fahrenheit]), |
| | 134 | °_latin1_size, °str_ptr, °str_size); |
| | 135 | iconv_close(cd); |
| | 136 | |
| | 137 | if (nconv != (size_t) -1) |
| | 138 | return; |
| | 139 | } |
| 147 | | int c,res,i,error; |
| 148 | | const char *config_file_name = DEFAULT_CONFIG_FILE; |
| 149 | | |
| 150 | | struct option long_opts[] = { |
| 151 | | { "help", no_argument, NULL, 'h' }, |
| 152 | | { "set", no_argument, NULL, 's' }, |
| 153 | | { "version", no_argument, NULL, 'v'}, |
| 154 | | { "fahrenheit", no_argument, NULL, 'f' }, |
| 155 | | { "no-adapter", no_argument, NULL, 'A' }, |
| 156 | | { "config-file", required_argument, NULL, 'c' }, |
| 157 | | { 0,0,0,0 } |
| 158 | | }; |
| 159 | | |
| 160 | | setlocale(LC_CTYPE, ""); |
| 161 | | |
| 162 | | do_raw = 0; |
| 163 | | do_sets = 0; |
| 164 | | hide_adapter = 0; |
| 165 | | while (1) { |
| 166 | | c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL); |
| 167 | | if (c == EOF) |
| 168 | | break; |
| 169 | | switch(c) { |
| 170 | | case ':': |
| 171 | | case '?': |
| 172 | | print_short_help(); |
| 173 | | exit(1); |
| 174 | | case 'h': |
| 175 | | print_long_help(); |
| 176 | | exit(0); |
| 177 | | case 'v': |
| 178 | | print_version(); |
| 179 | | exit(0); |
| 180 | | case 'c': |
| 181 | | config_file_name = optarg; |
| 182 | | break; |
| 183 | | case 's': |
| 184 | | do_sets = 1; |
| 185 | | break; |
| 186 | | case 'f': |
| 187 | | fahrenheit = 1; |
| 188 | | break; |
| 189 | | case 'A': |
| 190 | | hide_adapter = 1; |
| 191 | | break; |
| 192 | | case 'u': |
| 193 | | do_raw = 1; |
| 194 | | break; |
| 195 | | default: |
| 196 | | fprintf(stderr,"Internal error while parsing options!\n"); |
| 197 | | exit(1); |
| 198 | | } |
| 199 | | } |
| 200 | | |
| 201 | | open_config_file(config_file_name); |
| 202 | | if ((res = sensors_init(config_file))) { |
| 203 | | fprintf(stderr, "sensors_init: %s\n", sensors_strerror(res)); |
| 204 | | exit(1); |
| 205 | | } |
| 206 | | close_config_file(config_file_name); |
| 207 | | |
| 208 | | /* build the degrees string */ |
| 209 | | set_degstr(); |
| 210 | | |
| 211 | | if (optind == argc) { /* No chip name on command line */ |
| 212 | | if (!do_the_real_work(NULL, &error)) { |
| 213 | | fprintf(stderr, |
| 214 | | "No sensors found!\n" |
| 215 | | "Make sure you loaded all the kernel drivers you need.\n" |
| 216 | | "Try sensors-detect to find out which these are.\n"); |
| 217 | | error = 1; |
| 218 | | } |
| 219 | | } else { |
| 220 | | int cnt = 0; |
| 221 | | sensors_chip_name chip; |
| 222 | | |
| 223 | | for (i = optind; i < argc; i++) { |
| 224 | | if (sensors_parse_chip_name(argv[i], &chip)) { |
| 225 | | fprintf(stderr, "Parse error in chip name `%s'\n", argv[i]); |
| 226 | | print_short_help(); |
| 227 | | error = 1; |
| 228 | | goto exit; |
| 229 | | } |
| 230 | | cnt += do_the_real_work(&chip, &error); |
| 231 | | } |
| 232 | | |
| 233 | | if (!cnt) { |
| 234 | | fprintf(stderr, "Specified sensor(s) not found!\n"); |
| 235 | | error = 1; |
| 236 | | } |
| 237 | | } |
| | 148 | int c, res, i, error; |
| | 149 | const char *config_file_name = DEFAULT_CONFIG_FILE; |
| | 150 | |
| | 151 | struct option long_opts[] = { |
| | 152 | { "help", no_argument, NULL, 'h' }, |
| | 153 | { "set", no_argument, NULL, 's' }, |
| | 154 | { "version", no_argument, NULL, 'v'}, |
| | 155 | { "fahrenheit", no_argument, NULL, 'f' }, |
| | 156 | { "no-adapter", no_argument, NULL, 'A' }, |
| | 157 | { "config-file", required_argument, NULL, 'c' }, |
| | 158 | { 0, 0, 0, 0 } |
| | 159 | }; |
| | 160 | |
| | 161 | setlocale(LC_CTYPE, ""); |
| | 162 | |
| | 163 | do_raw = 0; |
| | 164 | do_sets = 0; |
| | 165 | hide_adapter = 0; |
| | 166 | while (1) { |
| | 167 | c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL); |
| | 168 | if (c == EOF) |
| | 169 | break; |
| | 170 | switch(c) { |
| | 171 | case ':': |
| | 172 | case '?': |
| | 173 | print_short_help(); |
| | 174 | exit(1); |
| | 175 | case 'h': |
| | 176 | print_long_help(); |
| | 177 | exit(0); |
| | 178 | case 'v': |
| | 179 | print_version(); |
| | 180 | exit(0); |
| | 181 | case 'c': |
| | 182 | config_file_name = optarg; |
| | 183 | break; |
| | 184 | case 's': |
| | 185 | do_sets = 1; |
| | 186 | break; |
| | 187 | case 'f': |
| | 188 | fahrenheit = 1; |
| | 189 | break; |
| | 190 | case 'A': |
| | 191 | hide_adapter = 1; |
| | 192 | break; |
| | 193 | case 'u': |
| | 194 | do_raw = 1; |
| | 195 | break; |
| | 196 | default: |
| | 197 | fprintf(stderr, |
| | 198 | "Internal error while parsing options!\n"); |
| | 199 | exit(1); |
| | 200 | } |
| | 201 | } |
| | 202 | |
| | 203 | open_config_file(config_file_name); |
| | 204 | if ((res = sensors_init(config_file))) { |
| | 205 | fprintf(stderr, "sensors_init: %s\n", sensors_strerror(res)); |
| | 206 | exit(1); |
| | 207 | } |
| | 208 | close_config_file(config_file_name); |
| | 209 | |
| | 210 | /* build the degrees string */ |
| | 211 | set_degstr(); |
| | 212 | |
| | 213 | if (optind == argc) { /* No chip name on command line */ |
| | 214 | if (!do_the_real_work(NULL, &error)) { |
| | 215 | fprintf(stderr, |
| | 216 | "No sensors found!\n" |
| | 217 | "Make sure you loaded all the kernel drivers you need.\n" |
| | 218 | "Try sensors-detect to find out which these are.\n"); |
| | 219 | error = 1; |
| | 220 | } |
| | 221 | } else { |
| | 222 | int cnt = 0; |
| | 223 | sensors_chip_name chip; |
| | 224 | |
| | 225 | for (i = optind; i < argc; i++) { |
| | 226 | if (sensors_parse_chip_name(argv[i], &chip)) { |
| | 227 | fprintf(stderr, |
| | 228 | "Parse error in chip name `%s'\n", |
| | 229 | argv[i]); |
| | 230 | print_short_help(); |
| | 231 | error = 1; |
| | 232 | goto exit; |
| | 233 | } |
| | 234 | cnt += do_the_real_work(&chip, &error); |
| | 235 | } |
| | 236 | |
| | 237 | if (!cnt) { |
| | 238 | fprintf(stderr, "Specified sensor(s) not found!\n"); |
| | 239 | error = 1; |
| | 240 | } |
| | 241 | } |
| 266 | | int res; |
| 267 | | |
| 268 | | if ((res = sensors_do_chip_sets(name))) { |
| 269 | | if (res == -SENSORS_ERR_PROC) { |
| 270 | | fprintf(stderr,"%s: %s for writing;\n",sprintf_chip_name(name), |
| 271 | | sensors_strerror(res)); |
| 272 | | fprintf(stderr,"Run as root?\n"); |
| 273 | | return 1; |
| 274 | | } else if (res == -SENSORS_ERR_ACCESS_W) { |
| 275 | | fprintf(stderr, "%s: At least one \"set\" statement failed\n", |
| 276 | | sprintf_chip_name(name)); |
| 277 | | } else { |
| 278 | | fprintf(stderr,"%s: %s\n",sprintf_chip_name(name), |
| 279 | | sensors_strerror(res)); |
| 280 | | } |
| 281 | | } |
| 282 | | return 0; |
| | 270 | int res; |
| | 271 | |
| | 272 | if ((res = sensors_do_chip_sets(name))) { |
| | 273 | if (res == -SENSORS_ERR_PROC) { |
| | 274 | fprintf(stderr, "%s: %s for writing;\n", |
| | 275 | sprintf_chip_name(name), |
| | 276 | sensors_strerror(res)); |
| | 277 | fprintf(stderr, "Run as root?\n"); |
| | 278 | return 1; |
| | 279 | } else if (res == -SENSORS_ERR_ACCESS_W) { |
| | 280 | fprintf(stderr, |
| | 281 | "%s: At least one \"set\" statement failed\n", |
| | 282 | sprintf_chip_name(name)); |
| | 283 | } else { |
| | 284 | fprintf(stderr, "%s: %s\n", sprintf_chip_name(name), |
| | 285 | sensors_strerror(res)); |
| | 286 | } |
| | 287 | } |
| | 288 | return 0; |