Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: lib/lib_vpd.c

Issue 6849018: Support -g option to dump value string only (no key string, no quotes). (Closed) Base URL: ssh://gitrw.chromium.org:9222/vpd.git@master
Patch Set: remove newline Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/lib/lib_vpd.h ('k') | vpd.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/lib_vpd.c
diff --git a/lib/lib_vpd.c b/lib/lib_vpd.c
index 5eaedabd73769441cdd81ff9556f28da0e25769c..fa447aab2eb462dae29bbba9672e8897a05d716d 100644
--- a/lib/lib_vpd.c
+++ b/lib/lib_vpd.c
@@ -284,6 +284,7 @@ void setString(struct PairContainer *container,
} else {
struct StringPair *new_pair = malloc(sizeof(struct StringPair));
assert(new_pair);
+ memset(new_pair, 0, sizeof(struct StringPair));
fillStringPair(new_pair, key, value, pad_len);
@@ -329,6 +330,27 @@ int encodeContainer(const struct PairContainer *container,
return VPD_OK;
}
+int setContainerFilter(struct PairContainer *container,
+ const uint8_t *filter) {
+ struct StringPair *str;
+
+ for (str = container->first; str; str = str->next) {
+ if (filter) {
+ /*
+ * TODO(yjlou):
+ * Now, we treat the inputing filter string as plain string.
+ * Will support regular expression syntax in future if needed.
+ */
+ if (strcmp(str->key, filter)) {
+ str->filter_out = 1;
+ }
+ } else {
+ str->filter_out = 0;
+ }
+ }
+ return VPD_OK;
+}
+
/* Export the container content with human-readable text. */
int exportContainer(const int export_type,
const struct PairContainer *container,
@@ -344,6 +366,9 @@ int exportContainer(const int export_type,
for (str = container->first; str; str = str->next) {
int copy_len;
+ if (str->filter_out)
+ continue;
+
if (export_type == VPD_EXPORT_AS_PARAMETER) {
char pad_str[32];
int pad_len;
@@ -355,26 +380,28 @@ int exportContainer(const int export_type,
index += pad_len;
}
- /* double quote */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '"';
+ if (export_type != VPD_EXPORT_VALUE) {
+ /* double quote */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '"';
- /* output key */
- if ((index + strlen(str->key)) > max_buf_len) return VPD_FAIL;
- strcpy(&buf[index], str->key);
- index += strlen(str->key);
+ /* output key */
+ if ((index + strlen(str->key)) > max_buf_len) return VPD_FAIL;
+ strcpy(&buf[index], str->key);
+ index += strlen(str->key);
- /* double quote */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '"';
+ /* double quote */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '"';
- /* equal sign */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '=';
+ /* equal sign */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '=';
- /* double quote */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '"';
+ /* double quote */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '"';
+ }
/* output value */
if (str->pad_len != VPD_AS_LONG_AS)
@@ -385,13 +412,15 @@ int exportContainer(const int export_type,
memcpy(&buf[index], str->value, copy_len);
index += copy_len;
- /* double quote */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '"';
+ if (export_type != VPD_EXPORT_VALUE) {
+ /* double quote */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '"';
- /* new line */
- if ((index + 1 > max_buf_len)) return VPD_FAIL;
- buf[index++] = '\n';
+ /* new line */
+ if ((index + 1 > max_buf_len)) return VPD_FAIL;
+ buf[index++] = '\n';
+ }
}
/* null terminator */
« no previous file with comments | « include/lib/lib_vpd.h ('k') | vpd.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698