outform.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2011 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. /*
  34. * outform.c manages a list of output formats, and associates
  35. * them with their relevant drivers. Also has a
  36. * routine to find the correct driver given a name
  37. * for it
  38. */
  39. #include "compiler.h"
  40. #include <stdio.h>
  41. #include <string.h>
  42. #define BUILD_DRIVERS_ARRAY
  43. #include "outform.h"
  44. const struct ofmt *ofmt_find(const char *name,
  45. const struct ofmt_alias **ofmt_alias)
  46. {
  47. const struct ofmt * const *ofp;
  48. const struct ofmt *of;
  49. unsigned int i;
  50. *ofmt_alias = NULL;
  51. /* primary targets first */
  52. for (ofp = drivers; (of = *ofp); ofp++) {
  53. if (!nasm_stricmp(name, of->shortname))
  54. return of;
  55. }
  56. /* lets walk thru aliases then */
  57. for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
  58. if (ofmt_aliases[i].shortname &&
  59. !nasm_stricmp(name, ofmt_aliases[i].shortname)) {
  60. *ofmt_alias = &ofmt_aliases[i];
  61. return ofmt_aliases[i].ofmt;
  62. }
  63. }
  64. return NULL;
  65. }
  66. const struct dfmt *dfmt_find(const struct ofmt *ofmt, const char *name)
  67. {
  68. const struct dfmt * const *dfp;
  69. const struct dfmt *df;
  70. for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
  71. if (!nasm_stricmp(name, df->shortname))
  72. return df;
  73. }
  74. return NULL;
  75. }
  76. void ofmt_list(const struct ofmt *deffmt, FILE * fp)
  77. {
  78. const struct ofmt * const *ofp, *of;
  79. unsigned int i;
  80. /* primary targets first */
  81. for (ofp = drivers; (of = *ofp); ofp++) {
  82. fprintf(fp, " %c %-10s%s\n",
  83. of == deffmt ? '*' : ' ',
  84. of->shortname, of->fullname);
  85. }
  86. /* lets walk through aliases then */
  87. for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
  88. if (!ofmt_aliases[i].shortname)
  89. continue;
  90. fprintf(fp, " %-10s%s\n",
  91. ofmt_aliases[i].shortname,
  92. ofmt_aliases[i].fullname);
  93. }
  94. }
  95. void dfmt_list(const struct ofmt *ofmt, FILE *fp)
  96. {
  97. const struct dfmt * const *dfp;
  98. const struct dfmt *df;
  99. for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
  100. fprintf(fp, " %c %-10s%s\n",
  101. df == dfmt ? '*' : ' ',
  102. df->shortname, df->fullname);
  103. }
  104. }