Program to generate an xml file based on a provided text file
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <libxml/tree.h>
  5. #include "main.h"
  6. #include "readconfig.h"
  7. #ifdef LIBXML_TREE_ENABLED
  8. int main(int argc, char *argv[]) {
  9. atexit(cleanup);
  10. char *config_file = "";
  11. if (argc == 1) {
  12. /* No arguments were passed */
  13. printusage(0);
  14. return 1;
  15. }
  16. /* Read the command line arguments */
  17. int i;
  18. for (i = 1; i < argc; i++) {
  19. if ((strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) && i != argc - 1 && strlen(config_file) == 0) {
  20. config_file = (char *) malloc(strlen(argv[i + 1]) * sizeof(char));
  21. config_file = argv[i + 1];
  22. i++;
  23. }
  24. else {
  25. /* Incorrect usage or used the same option more than once */
  26. printusage(1);
  27. return 1;
  28. }
  29. }
  30. config = (CONFIG *) malloc (sizeof(CONFIG));
  31. int status = readconfig(config_file, config);
  32. if (status != 0) {
  33. return 1;
  34. }
  35. printf("Configuración:\n");
  36. printf("Archivo: %s\n", config->file);
  37. printf("Biblia: %s\n", config->bible);
  38. printf("Libro: %s\n", config->book);
  39. printf("Nombre de capitulo: %s\n", config->chapter);
  40. printf("Numeros de capitulo: %s\n", config->chapter_numbers);
  41. return 0;
  42. }
  43. #else
  44. int main(int argc, char *argv[]) {
  45. fprintf(stderr, "libxml2 no tiene tree support compilado\n");
  46. return 1;
  47. }
  48. #endif
  49. /* Cleanup on aisle 3
  50. * */
  51. void cleanup() {
  52. if (config != NULL) {
  53. if (config->file != NULL) {
  54. xmlFree(config->file);
  55. }
  56. if (config->bible != NULL) {
  57. xmlFree(config->bible);
  58. }
  59. if (config->book != NULL) {
  60. xmlFree(config->book);
  61. }
  62. if (config->chapter != NULL) {
  63. xmlFree(config->chapter);
  64. }
  65. if (config->chapter_numbers != NULL) {
  66. xmlFree(config->chapter_numbers);
  67. }
  68. free(config);
  69. }
  70. }
  71. /* Print how to use the program
  72. * */
  73. void printusage(int error) {
  74. if (error == 1) {
  75. printf("Opcion desconocido!\n\n");
  76. }
  77. printf("usage: generarxml [opciones] \n");
  78. printf(" -s, --config <archivo> archivo de configuración\n");
  79. }