zlog-chk-conf.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * This file is part of the zlog Library.
  3. *
  4. * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING in base directory.
  7. */
  8. #include "fmacros.h"
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdarg.h>
  12. #include <string.h>
  13. #include <unistd.h>
  14. #include "zlog.h"
  15. #include "version.h"
  16. int main(int argc, char *argv[])
  17. {
  18. int rc = 0;
  19. int op;
  20. int quiet = 0;
  21. static const char *help =
  22. "usage: zlog-chk-conf [conf files]...\n"
  23. "\t-q,\tsuppress non-error message\n"
  24. "\t-h,\tshow help message\n"
  25. "zlog version: " ZLOG_VERSION "\n";
  26. while((op = getopt(argc, argv, "qhv")) > 0) {
  27. if (op == 'h') {
  28. fputs(help, stdout);
  29. return 0;
  30. } else if (op == 'q') {
  31. quiet = 1;
  32. }
  33. }
  34. argc -= optind;
  35. argv += optind;
  36. if (argc == 0) {
  37. fputs(help, stdout);
  38. return -1;
  39. }
  40. setenv("ZLOG_PROFILE_ERROR", "/dev/stderr", 1);
  41. setenv("ZLOG_CHECK_FORMAT_RULE", "1", 1);
  42. while (argc > 0) {
  43. rc = zlog_init(*argv);
  44. if (rc) {
  45. printf("\n---[%s] syntax error, see error message above\n",
  46. *argv);
  47. exit(2);
  48. } else {
  49. zlog_fini();
  50. if (!quiet) {
  51. printf("--[%s] syntax right\n", *argv);
  52. }
  53. }
  54. argc--;
  55. argv++;
  56. }
  57. exit(0);
  58. }