/Proj4/pj_pr_list.c

http://github.com/route-me/route-me · C · 94 lines · 72 code · 11 blank · 11 comment · 16 complexity · 8a9a2f1dcbe9220c4e65cd87237e5684 MD5 · raw file

  1. /* print projection's list of parameters */
  2. #ifndef lint
  3. static const char SCCSID[]="@(#)pj_pr_list.c 4.6 94/03/19 GIE REL";
  4. #endif
  5. #include "projects.h"
  6. #include <stdio.h>
  7. #include <string.h>
  8. #define LINE_LEN 72
  9. static int
  10. pr_list(PJ *P, int not_used) {
  11. paralist *t;
  12. int l, n = 1, flag = 0;
  13. (void)putchar('#');
  14. for (t = P->params; t; t = t->next)
  15. if ((!not_used && t->used) || (not_used && !t->used)) {
  16. l = strlen(t->param) + 1;
  17. if (n + l > LINE_LEN) {
  18. (void)fputs("\n#", stdout);
  19. n = 2;
  20. }
  21. (void)putchar(' ');
  22. if (*(t->param) != '+')
  23. (void)putchar('+');
  24. (void)fputs(t->param, stdout);
  25. n += l;
  26. } else
  27. flag = 1;
  28. if (n > 1)
  29. (void)putchar('\n');
  30. return flag;
  31. }
  32. void /* print link list of projection parameters */
  33. pj_pr_list(PJ *P) {
  34. char const *s;
  35. (void)putchar('#');
  36. for (s = P->descr; *s ; ++s) {
  37. (void)putchar(*s);
  38. if (*s == '\n')
  39. (void)putchar('#');
  40. }
  41. (void)putchar('\n');
  42. if (pr_list(P, 0)) {
  43. (void)fputs("#--- following specified but NOT used\n", stdout);
  44. (void)pr_list(P, 1);
  45. }
  46. }
  47. /************************************************************************/
  48. /* pj_get_def() */
  49. /* */
  50. /* Returns the PROJ.4 command string that would produce this */
  51. /* definition expanded as much as possible. For instance, */
  52. /* +init= calls and +datum= defintions would be expanded. */
  53. /************************************************************************/
  54. char *pj_get_def( PJ *P, int options )
  55. {
  56. paralist *t;
  57. int l;
  58. char *definition;
  59. int def_max = 10;
  60. definition = (char *) pj_malloc(def_max);
  61. definition[0] = '\0';
  62. for (t = P->params; t; t = t->next)
  63. {
  64. /* skip unused parameters ... mostly appended defaults and stuff */
  65. if (!t->used)
  66. continue;
  67. /* grow the resulting string if needed */
  68. l = strlen(t->param) + 1;
  69. if( strlen(definition) + l + 5 > def_max )
  70. {
  71. char *def2;
  72. def_max = def_max * 2 + l + 5;
  73. def2 = (char *) pj_malloc(def_max);
  74. strcpy( def2, definition );
  75. pj_dalloc( definition );
  76. definition = def2;
  77. }
  78. /* append this parameter */
  79. strcat( definition, " +" );
  80. strcat( definition, t->param );
  81. }
  82. return definition;
  83. }