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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/lib/lib_vpd.h ('k') | vpd.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. 2 * Copyright (C) 2010 Google Inc.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License 5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2 6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version. 7 * of the License, or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 struct StringPair *found; 277 struct StringPair *found;
278 278
279 found = findString(container, key); 279 found = findString(container, key);
280 if (found) { 280 if (found) {
281 free(found->key); 281 free(found->key);
282 free(found->value); 282 free(found->value);
283 fillStringPair(found, key, value, pad_len); 283 fillStringPair(found, key, value, pad_len);
284 } else { 284 } else {
285 struct StringPair *new_pair = malloc(sizeof(struct StringPair)); 285 struct StringPair *new_pair = malloc(sizeof(struct StringPair));
286 assert(new_pair); 286 assert(new_pair);
287 memset(new_pair, 0, sizeof(struct StringPair));
287 288
288 fillStringPair(new_pair, key, value, pad_len); 289 fillStringPair(new_pair, key, value, pad_len);
289 290
290 /* append this pair to the end of list. to keep the order */ 291 /* append this pair to the end of list. to keep the order */
291 if (found = container->first) { 292 if (found = container->first) {
292 while (found->next) found = found->next; 293 while (found->next) found = found->next;
293 found->next = new_pair; 294 found->next = new_pair;
294 } else { 295 } else {
295 container->first = new_pair; 296 container->first = new_pair;
296 } 297 }
(...skipping 25 matching lines...) Expand all
322 current->pad_len, 323 current->pad_len,
323 max_buf_len, 324 max_buf_len,
324 buf, 325 buf,
325 generated)) { 326 generated)) {
326 return VPD_FAIL; 327 return VPD_FAIL;
327 } 328 }
328 } 329 }
329 return VPD_OK; 330 return VPD_OK;
330 } 331 }
331 332
333 int setContainerFilter(struct PairContainer *container,
334 const uint8_t *filter) {
335 struct StringPair *str;
336
337 for (str = container->first; str; str = str->next) {
338 if (filter) {
339 /*
340 * TODO(yjlou):
341 * Now, we treat the inputing filter string as plain string.
342 * Will support regular expression syntax in future if needed.
343 */
344 if (strcmp(str->key, filter)) {
345 str->filter_out = 1;
346 }
347 } else {
348 str->filter_out = 0;
349 }
350 }
351 return VPD_OK;
352 }
353
332 /* Export the container content with human-readable text. */ 354 /* Export the container content with human-readable text. */
333 int exportContainer(const int export_type, 355 int exportContainer(const int export_type,
334 const struct PairContainer *container, 356 const struct PairContainer *container,
335 const int max_buf_len, 357 const int max_buf_len,
336 uint8_t *buf, 358 uint8_t *buf,
337 int *generated) { 359 int *generated) {
338 struct StringPair *str; 360 struct StringPair *str;
339 int index; 361 int index;
340 362
341 assert(generated); 363 assert(generated);
342 index = *generated; 364 index = *generated;
343 365
344 for (str = container->first; str; str = str->next) { 366 for (str = container->first; str; str = str->next) {
345 int copy_len; 367 int copy_len;
346 368
369 if (str->filter_out)
370 continue;
371
347 if (export_type == VPD_EXPORT_AS_PARAMETER) { 372 if (export_type == VPD_EXPORT_AS_PARAMETER) {
348 char pad_str[32]; 373 char pad_str[32];
349 int pad_len; 374 int pad_len;
350 375
351 snprintf(pad_str, sizeof(pad_str), "-p %d -s ", str->pad_len); 376 snprintf(pad_str, sizeof(pad_str), "-p %d -s ", str->pad_len);
352 pad_len = strlen(pad_str); 377 pad_len = strlen(pad_str);
353 if ((index + pad_len) > max_buf_len) return VPD_FAIL; 378 if ((index + pad_len) > max_buf_len) return VPD_FAIL;
354 strcpy(&buf[index], pad_str); 379 strcpy(&buf[index], pad_str);
355 index += pad_len; 380 index += pad_len;
356 } 381 }
357 382
358 /* double quote */ 383 if (export_type != VPD_EXPORT_VALUE) {
359 if ((index + 1 > max_buf_len)) return VPD_FAIL; 384 /* double quote */
360 buf[index++] = '"'; 385 if ((index + 1 > max_buf_len)) return VPD_FAIL;
386 buf[index++] = '"';
361 387
362 /* output key */ 388 /* output key */
363 if ((index + strlen(str->key)) > max_buf_len) return VPD_FAIL; 389 if ((index + strlen(str->key)) > max_buf_len) return VPD_FAIL;
364 strcpy(&buf[index], str->key); 390 strcpy(&buf[index], str->key);
365 index += strlen(str->key); 391 index += strlen(str->key);
366 392
367 /* double quote */ 393 /* double quote */
368 if ((index + 1 > max_buf_len)) return VPD_FAIL; 394 if ((index + 1 > max_buf_len)) return VPD_FAIL;
369 buf[index++] = '"'; 395 buf[index++] = '"';
370 396
371 /* equal sign */ 397 /* equal sign */
372 if ((index + 1 > max_buf_len)) return VPD_FAIL; 398 if ((index + 1 > max_buf_len)) return VPD_FAIL;
373 buf[index++] = '='; 399 buf[index++] = '=';
374 400
375 /* double quote */ 401 /* double quote */
376 if ((index + 1 > max_buf_len)) return VPD_FAIL; 402 if ((index + 1 > max_buf_len)) return VPD_FAIL;
377 buf[index++] = '"'; 403 buf[index++] = '"';
404 }
378 405
379 /* output value */ 406 /* output value */
380 if (str->pad_len != VPD_AS_LONG_AS) 407 if (str->pad_len != VPD_AS_LONG_AS)
381 copy_len = MIN(str->pad_len, strlen(str->value)); 408 copy_len = MIN(str->pad_len, strlen(str->value));
382 else 409 else
383 copy_len = strlen(str->value); 410 copy_len = strlen(str->value);
384 if ((index + copy_len) > max_buf_len) return VPD_FAIL; 411 if ((index + copy_len) > max_buf_len) return VPD_FAIL;
385 memcpy(&buf[index], str->value, copy_len); 412 memcpy(&buf[index], str->value, copy_len);
386 index += copy_len; 413 index += copy_len;
387 414
388 /* double quote */ 415 if (export_type != VPD_EXPORT_VALUE) {
389 if ((index + 1 > max_buf_len)) return VPD_FAIL; 416 /* double quote */
390 buf[index++] = '"'; 417 if ((index + 1 > max_buf_len)) return VPD_FAIL;
418 buf[index++] = '"';
391 419
392 /* new line */ 420 /* new line */
393 if ((index + 1 > max_buf_len)) return VPD_FAIL; 421 if ((index + 1 > max_buf_len)) return VPD_FAIL;
394 buf[index++] = '\n'; 422 buf[index++] = '\n';
423 }
395 } 424 }
396 425
397 /* null terminator */ 426 /* null terminator */
398 if ((index + 1 > max_buf_len)) return VPD_FAIL; 427 if ((index + 1 > max_buf_len)) return VPD_FAIL;
399 buf[index++] = '\0'; 428 buf[index++] = '\0';
400 429
401 *generated = index; 430 *generated = index;
402 431
403 return VPD_OK; 432 return VPD_OK;
404 } 433 }
405 434
406 void destroyContainer(struct PairContainer *container) { 435 void destroyContainer(struct PairContainer *container) {
407 struct StringPair *current; 436 struct StringPair *current;
408 437
409 for (current = container->first; current;) { 438 for (current = container->first; current;) {
410 struct StringPair *next; 439 struct StringPair *next;
411 440
412 if (current->key) free(current->key); 441 if (current->key) free(current->key);
413 if (current->value) free(current->value); 442 if (current->value) free(current->value);
414 next = current->next; 443 next = current->next;
415 free(current); 444 free(current);
416 current = next; 445 current = next;
417 } 446 }
418 } 447 }
OLDNEW
« 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