RuneOptimizer.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This file is part of RuneOptimizer.
  3. *
  4. * RuneOptimizer is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation, either version 3 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <sqlite3.h>
  21. #include <math.h>
  22. #include "RuneOptimizer.h"
  23. #include "error/error.h"
  24. #include "help/help.h"
  25. #include "help/help.c"
  26. #include "optimize/optimize.h"
  27. #include "optimize/optimize.c"
  28. #include "team/team.h"
  29. #include "team/team.c"
  30. #include "update/update.h"
  31. #include "update/update.c"
  32. /**
  33. * Starts the program.
  34. *
  35. * Reads parameters and runs the appropiate functions.
  36. *
  37. * @param argc Argument count.
  38. * @param argv Argument list.
  39. * @return SUCCESS on success, other on error.
  40. */
  41. int main(int argc, char *argv[]){
  42. // Parse the arguments to find the command (index 1)
  43. // If no arguments, end here
  44. if (argc < 2){
  45. fprintf(stderr, "No command specified\n");
  46. return ERROR_INPUT_NO_COMMAND;
  47. }
  48. // Update command, TODO
  49. if (strcmp(argv[1], "update") == 0){
  50. fprintf(stderr, "Updating is still unimplemented\n");
  51. return UNIMPLEMENTED;
  52. }
  53. // Optimize command, call the function with all the arguments to be
  54. // processed there.
  55. else if (strcmp(argv[1], "optimize") == 0){
  56. int result = optimize(argc, argv);
  57. return result;
  58. }
  59. // Help command. Call and return
  60. else if (strcmp(argv[1], "help") == 0){
  61. show_help();
  62. return SUCCESS;
  63. }
  64. // Help command. Call and return
  65. else if (strcmp(argv[1], "team") == 0){
  66. if (argc < 3){
  67. fprintf(stderr, "Command team needs an action\n");
  68. return ERROR_INPUT_TEAM_NO_ACTION;
  69. }
  70. if (strcmp(argv[2], "list") == 0){
  71. int result = list_teams(argc, argv);
  72. return result;
  73. }
  74. else{
  75. fprintf(stderr, "Invalid action for team command: %s\n", argv[1]);
  76. return ERROR_INPUT_TEAM_INVALID_ACTION;
  77. }
  78. }
  79. // Any other command is an error
  80. else{
  81. fprintf(stderr, "Invalid command specified: %s\n", argv[1]);
  82. return ERROR_INPUT_INVALID_COMMAND;
  83. }
  84. }