Proyecto para encontrar 2 puntos más cercano para el curso de Análisis y Diseño de Algoritmos.
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.

points.c 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2018 Christopher Cromer
  3. * Copyright 2018 Rodolfo Cuevas
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  8. *
  9. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  10. *
  11. * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <getopt.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #include <limits.h>
  21. #include "timer.h"
  22. #define POINTS_VERSION "1.0.0"
  23. /**
  24. * Imprimir el uso del programa
  25. */
  26. void print_usage() {
  27. fprintf(stdout, "uso: points [OPCIÓN]\n");
  28. fprintf(stdout, " -a, --all usar todos los algoritmos de ordenamentio\n");
  29. fprintf(stdout, " -b, --brute usar brute force\n");
  30. fprintf(stdout, " -d, --divide usar divide and conquer\n");
  31. fprintf(stdout, " -h, --help mostrar como usar el programa\n");
  32. fprintf(stdout, " -v, --version mostrar la versión del programa\n");
  33. }
  34. /**
  35. * La entrada del programa
  36. * @param argc La cantidad de argumentos pasado al programa
  37. * @return Retorna el codigo de error o 0 por exito
  38. */
  39. int main (int argc, char **argv) {
  40. int brute = 0;
  41. int divide = 0;
  42. int opt;
  43. int long_index = 0;
  44. static struct option long_options[] = {
  45. {"all", no_argument, 0, 'a'},
  46. {"brute", no_argument, 0, 'b'},
  47. {"divide", no_argument, 0, 'd'},
  48. {"help", no_argument, 0, 'h'},
  49. {"version", no_argument, 0, 'v'},
  50. {0, 0, 0, 0}
  51. };
  52. if (argc == 1) {
  53. print_usage();
  54. return 0;
  55. }
  56. while ((opt = getopt_long(argc, argv, "abdhv", long_options, &long_index)) != -1) {
  57. switch (opt) {
  58. case 'a':
  59. brute = 1;
  60. divide = 1;
  61. break;
  62. case 'b':
  63. brute = 1;
  64. break;
  65. case 'd':
  66. divide = 1;
  67. break;
  68. case 'h':
  69. print_usage();
  70. return 0;
  71. case 'v':
  72. printf("points versión: %s\n", POINTS_VERSION);
  73. return 0;
  74. break;
  75. default:
  76. print_usage();
  77. return 1;
  78. }
  79. }
  80. if (!brute && !divide) {
  81. fprintf(stderr, "Error: No se seleccionó un algoritmo valido!\n");
  82. print_usage();
  83. return 4;
  84. }
  85. return 0;
  86. }