ndt-dev - [ndt-dev] [ndt] r742 committed - Remove unwanted chars from web100 var names after readingfrom web100 f...
Subject: NDT-DEV email list created
List archive
[ndt-dev] [ndt] r742 committed - Remove unwanted chars from web100 var names after readingfrom web100 f...
Chronological Thread
- From:
- To:
- Subject: [ndt-dev] [ndt] r742 committed - Remove unwanted chars from web100 var names after readingfrom web100 f...
- Date: Sat, 29 Oct 2011 02:24:28 +0000
Revision: 742
Author:
Date: Fri Oct 28 19:23:28 2011
Log: Remove unwanted chars from web100 var names after readingfrom web100 file to avoid KIS-var-not-found-errors consitently
http://code.google.com/p/ndt/source/detail?r=742
Modified:
/branches/kkumar_code_organize/src/utils.c
/branches/kkumar_code_organize/src/utils.h
/branches/kkumar_code_organize/src/web100-util.c
=======================================
--- /branches/kkumar_code_organize/src/utils.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/utils.c Fri Oct 28 19:23:28 2011
@@ -162,3 +162,38 @@
return;
}
}
+
+/**
+ * Utility function to trim unwanted characters from a string.
+ * @param line String to trim
+ * @param line_size Size of line to be trimmed
+ * @param output_buf Location to store trimmed line in
+ * @param output_buf_size output buffer size
+ * @return strlen of output string
+ */
+int trim(char *line, int line_size,
+ char * output_buf, int output_buf_size) {
+ static char whitespacearr[4]= { '\n', ' ', '\t', '\r' };
+
+ int i, j, k;
+
+ for (i = j = 0; i < line_size && j < output_buf_size - 1; i++) {
+ // find any matching characters among the quoted
+ int is_whitespace = 0;
+ for (k = 0; k < 4; k++) {
+ if (line[i] == whitespacearr[k]) {
+ is_whitespace = 1;
+ break;
+ }
+ }
+ if (!is_whitespace) {
+ output_buf[j] = line[i];
+ j++ ;
+ }
+ }
+ output_buf[j] = '\0'; // null terminate
+ printf("****Received=%s; len=%d; dest=%d; MSG=%s", line, line_size,
+ strlen(output_buf), output_buf);
+ return j - 1;
+}
+
=======================================
--- /branches/kkumar_code_organize/src/utils.h Tue Oct 25 13:58:59 2011
+++ /branches/kkumar_code_organize/src/utils.h Fri Oct 28 19:23:28 2011
@@ -16,6 +16,8 @@
void err_sys(char* s);
int sndq_len(int fd);
void mysleep(double time);
+int trim(char *line, int line_size,
+ char * output_buf, int output_buf_size);
#endif
=======================================
--- /branches/kkumar_code_organize/src/web100-util.c Mon Oct 17 06:43:25 2011
+++ /branches/kkumar_code_organize/src/web100-util.c Fri Oct 28 19:23:28 2011
@@ -27,7 +27,7 @@
int web100_init(char *VarFileName) {
FILE * fp;
- char line[256];
+ char line[256], trimmedline[256];
int count_vars = 0;
assert(VarFileName);
@@ -42,8 +42,10 @@
if ((line[0] == '#') || (line[0] == '\n')) // if newline or comment, ignore
continue;
// copy web100 variable into our array and increment count of read variables
- //strncpy(web_vars[count_vars].name, line, (strlen(line)-1));
- strlcpy(web_vars[count_vars].name, line,
+
+ trim(line, strlen(line), trimmedline, sizeof(trimmedline)); // remove unwanted
+ // chars (right now, trailing/preceding
chars from wb100 var names)
+ strlcpy(web_vars[count_vars].name, trimmedline,
sizeof(web_vars[count_vars].name));
count_vars++;
}
@@ -330,11 +332,10 @@
assert(snap);
assert(agent);
- // Read values for number of variables intended
for (i = 0; i < count_vars; i++) {
if ((web100_agent_find_var_and_group(agent, web_vars[i].name,
&group,
&var)) != WEB100_ERR_SUCCESS) {
- log_println(9, "Variable %d (%s) not found in KIS", i,
+ log_println(9, "Variable %d (%s) not found in KIS: ",
i,
web_vars[i].name);
continue;
}
- [ndt-dev] [ndt] r742 committed - Remove unwanted chars from web100 var names after readingfrom web100 f..., ndt, 10/28/2011
Archive powered by MHonArc 2.6.16.