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.

81 lines
1.8KB

  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. int main(int argc, char *argv[]) {
  8. atexit(cleanup);
  9. char *config_file = "";
  10. if (argc == 1) {
  11. /* No arguments were passed */
  12. printusage(0);
  13. return 1;
  14. }
  15. /* Read the command line arguments */
  16. int i;
  17. for (i = 1; i < argc; i++) {
  18. if ((strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) && i != argc - 1 && strlen(config_file) == 0) {
  19. config_file = (char *) malloc(strlen(argv[i + 1]) * sizeof(char));
  20. config_file = argv[i + 1];
  21. i++;
  22. }
  23. else {
  24. /* Incorrect usage or used the same option more than once */
  25. printusage(1);
  26. return 1;
  27. }
  28. }
  29. config = (CONFIG *) malloc (sizeof(CONFIG));
  30. int status = readconfig(config_file, config);
  31. if (status != 0) {
  32. return 1;
  33. }
  34. printf("file: %s\n", config->file);
  35. printf("bible: %s\n", config->bible);
  36. return 0;
  37. }
  38. /* Cleanup on aisle 3
  39. * */
  40. void cleanup() {
  41. if (config != NULL) {
  42. if (config->file != NULL) {
  43. xmlFree(config->file);
  44. }
  45. if (config->bible != NULL) {
  46. xmlFree(config->bible);
  47. }
  48. if (config->book != NULL) {
  49. xmlFree(config->book);
  50. }
  51. if (config->chapter != NULL) {
  52. xmlFree(config->chapter);
  53. }
  54. if (config->chapter_numbers != NULL) {
  55. xmlFree(config->chapter_numbers);
  56. }
  57. free(config);
  58. }
  59. }
  60. /* Print how to use the program
  61. * */
  62. void printusage(int error) {
  63. if (error == 1) {
  64. printf("Opcion desconocido!\n\n");
  65. }
  66. printf("usage: generarxml [opciones] \n");
  67. printf(" -s, --config <archivo> archivo de configuraciĆ³n\n");
  68. }