prog/dump/*: More robust user input handling.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4256 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2006-12-09 19:20:00 +00:00
1 parent 6cb6e13159
commit 8afee51d60
9 files changed
+85 -32

No files matched your search

+2
View File
@@ -18,6 +18,7 @@ SVN HEAD
Program eepromer: Fix loads of warnings
Program i2cdetect: Make the output clearer
Program py-smbus: New! Python i2c-dev bindings (prog/py-smbus)
Programs dump/*: More robust handling of user inputs
Program sensord: Add pc87247 support (fans only)
Add vt1211 support (#2150)
Program sensors: Add pc87247 support (fans only)
@@ -33,6 +34,7 @@ SVN HEAD
Add Intel ICH9 detection
Add Maxim MAX6648/MAX6692 detection
2.10.1 (20060924)
File doc/developers/checklist renamed to dev/developers/release_checklist
with clarifications and updates for new SVN server.
+9 -5
View File
@@ -30,7 +30,8 @@ PROGDUMPMAN8FILES := $(MODULE_DIR)/i2cdump.8 $(MODULE_DIR)/i2cset.8 \
PROGDUMPTARGETS := $(MODULE_DIR)/i2cdump $(MODULE_DIR)/i2cset \
$(MODULE_DIR)/i2cget
PROGDUMPSOURCES := $(MODULE_DIR)/i2cdump.c $(MODULE_DIR)/i2cset.c \
$(MODULE_DIR)/i2cget.c $(MODULE_DIR)/i2cbusses.c
$(MODULE_DIR)/i2cget.c $(MODULE_DIR)/i2cbusses.c \
$(MODULE_DIR)/util.c
PROGDUMPBININSTALL := $(MODULE_DIR)/i2cdump $(MODULE_DIR)/i2cset \
$(MODULE_DIR)/i2cget
@@ -53,16 +54,19 @@ REMOVEDUMPMAN := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(PROGDUMPMAN8DIR)/%,$(PRO
all-prog-dump: $(PROGDUMPTARGETS)
user :: all-prog-dump
$(MODULE_DIR)/i2cdump: $(MODULE_DIR)/i2cdump.ro $(MODULE_DIR)/i2cbusses.ro
$(MODULE_DIR)/i2cdump: $(MODULE_DIR)/i2cdump.ro $(MODULE_DIR)/i2cbusses.ro $(MODULE_DIR)/util.ro
$(CC) $(EXLDFLAGS) -o $@ $^
$(MODULE_DIR)/i2cset: $(MODULE_DIR)/i2cset.ro $(MODULE_DIR)/i2cbusses.ro
$(MODULE_DIR)/i2cset: $(MODULE_DIR)/i2cset.ro $(MODULE_DIR)/i2cbusses.ro $(MODULE_DIR)/util.ro
$(CC) $(EXLDFLAGS) -o $@ $^
$(MODULE_DIR)/i2cget: $(MODULE_DIR)/i2cget.ro $(MODULE_DIR)/i2cbusses.ro
$(MODULE_DIR)/i2cget: $(MODULE_DIR)/i2cget.ro $(MODULE_DIR)/i2cbusses.ro $(MODULE_DIR)/util.ro
$(CC) $(EXLDFLAGS) -o $@ $^
$(MODULE_DIR)/isadump: $(MODULE_DIR)/isadump.ro $(MODULE_DIR)/superio.ro
$(MODULE_DIR)/isadump: $(MODULE_DIR)/isadump.ro $(MODULE_DIR)/superio.ro $(MODULE_DIR)/util.ro
$(CC) $(EXLDFLAGS) -o $@ $^
$(MODULE_DIR)/isaset: $(MODULE_DIR)/isaset.ro $(MODULE_DIR)/util.ro
$(CC) $(EXLDFLAGS) -o $@ $^
install-prog-dump: all-prog-dump
+2 -4
View File
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
#include "i2cbusses.h"
#include "i2c-dev.h"
#include "version.h"
@@ -254,8 +255,6 @@ int main(int argc, char *argv[])
}
if (!yes) {
char s[2];
fprintf(stderr, "WARNING! This program can confuse your I2C "
"bus, cause data loss and worse!\n");
@@ -281,8 +280,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [Y/n] ");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(1)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
+2 -3
View File
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
#include "i2cbusses.h"
#include "i2c-dev.h"
#include "version.h"
@@ -116,7 +117,6 @@ int set_slave(int file, int address)
int confirm(const char *filename, int address, int size, int daddress, int pec)
{
char s[2];
int dont = 0;
fprintf(stderr, "WARNING! This program can confuse your I2C "
@@ -156,8 +156,7 @@ int confirm(const char *filename, int address, int size, int daddress, int pec)
fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| ((s[0] != '\n' || dont) && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(!dont)) {
fprintf(stderr, "Aborting on user request.\n");
return 0;
}
+3 -7
View File
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "i2cbusses.h"
#include "util.h"
#include "i2c-dev.h"
#include "version.h"
@@ -168,7 +169,6 @@ int main(int argc, char *argv[])
}
if (!yes) {
char s[2];
int dont = 0;
fprintf(stderr, "WARNING! This program can confuse your I2C "
@@ -192,8 +192,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| ((s[0] != '\n' || dont) && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(!dont)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
@@ -216,8 +215,6 @@ int main(int argc, char *argv[])
value = (value & vmask) | (oldvalue & ~vmask);
if (!yes) {
char s[2];
fprintf(stderr, "Old value 0x%0*x, write mask "
"0x%0*x: Will write 0x%0*x to register "
"0x%02x\n",
@@ -228,8 +225,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [Y/n] ");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(1)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
+2 -5
View File
@@ -32,7 +32,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "util.h"
#include "superio.h"
@@ -230,8 +230,6 @@ int main(int argc, char *argv[])
}
if (!yes) {
char s[2];
fprintf(stderr, "WARNING! Running this program can cause "
"system crashes, data loss and worse!\n");
@@ -248,8 +246,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [Y/n] ");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(1)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
+3 -8
View File
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "util.h"
/* To keep glibc2 happy */
@@ -161,8 +162,6 @@ int main(int argc, char *argv[])
}
if (!yes) {
char s[2];
fprintf(stderr, "WARNING! Running this program can cause "
"system crashes, data loss and worse!\n");
@@ -179,8 +178,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [Y/n] ");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(1)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
@@ -224,8 +222,6 @@ int main(int argc, char *argv[])
value = (value & vmask) | (oldvalue & ~vmask);
if (!yes) {
char s[2];
fprintf(stderr, "Old value 0x%02x, write mask "
"0x%02x: Will write 0x%02x to %s "
"0x%02x\n", oldvalue, vmask, value,
@@ -234,8 +230,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Continue? [Y/n] ");
fflush(stderr);
if (!fgets(s, 2, stdin)
|| (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y')) {
if (!user_ack(1)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
+47
View File
@@ -0,0 +1,47 @@
/*
util.c - helper functions
Copyright (C) 2006 Jean Delvare <khali@linux-fr.org>
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; version 2.
*/
#include <stdio.h>
#include "util.h"
/* Return 1 if we should continue, 0 if we should abort */
int user_ack(int def)
{
char s[2];
int ret;
if (!fgets(s, 2, stdin))
return 0; /* Nack by default */
switch (s[0]) {
case 'y':
case 'Y':
ret = 1;
break;
case 'n':
case 'N':
ret = 0;
break;
default:
ret = def;
}
/* Flush extra characters */
while (s[0] != '\n') {
int c = fgetc(stdin);
if (c == EOF) {
ret = 0;
break;
}
s[0] = c;
}
return ret;
}
+15
View File
@@ -0,0 +1,15 @@
/*
util - helper functions
Copyright (C) 2006 Jean Delvare <khali@linux-fr.org>
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; version 2.
*/
#ifndef _UTIL_H
#define _UTIL_H
extern int user_ack(int def);
#endif /* _UTIL_H */