2002-05-01 04:51:32 +08:00
|
|
|
/* outform.c manages a list of output formats, and associates
|
2007-10-20 05:42:29 +08:00
|
|
|
* them with their relevant drivers. Also has a
|
|
|
|
* routine to find the correct driver given a name
|
|
|
|
* for it
|
2002-05-01 04:51:32 +08:00
|
|
|
*
|
|
|
|
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
|
|
|
|
* Julian Hall. All rights reserved. The software is
|
|
|
|
* redistributable under the licence given in the file "Licence"
|
|
|
|
* distributed in the NASM archive.
|
|
|
|
*/
|
|
|
|
|
2007-10-03 12:53:51 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-04-12 10:40:54 +08:00
|
|
|
#include <inttypes.h>
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
#define BUILD_DRIVERS_ARRAY
|
2002-05-01 04:51:32 +08:00
|
|
|
#include "outform.h"
|
|
|
|
|
|
|
|
static int ndrivers = 0;
|
|
|
|
|
2007-04-14 00:47:53 +08:00
|
|
|
struct ofmt *ofmt_find(char *name)
|
2005-01-16 06:15:51 +08:00
|
|
|
{ /* find driver */
|
2002-05-01 04:51:32 +08:00
|
|
|
int i;
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
for (i = 0; i < ndrivers; i++)
|
|
|
|
if (!strcmp(name, drivers[i]->shortname))
|
|
|
|
return drivers[i];
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-04-14 00:47:53 +08:00
|
|
|
struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
|
2005-01-16 06:15:51 +08:00
|
|
|
{ /* find driver */
|
2002-05-01 04:53:55 +08:00
|
|
|
struct dfmt **dfmt = ofmt->debug_formats;
|
|
|
|
while (*dfmt) {
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!strcmp(name, (*dfmt)->shortname))
|
|
|
|
return (*dfmt);
|
|
|
|
dfmt++;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
void ofmt_list(struct ofmt *deffmt, FILE * fp)
|
2002-05-01 04:51:32 +08:00
|
|
|
{
|
|
|
|
int i;
|
2005-01-16 06:15:51 +08:00
|
|
|
for (i = 0; i < ndrivers; i++)
|
|
|
|
fprintf(fp, " %c %-10s%s\n",
|
|
|
|
drivers[i] == deffmt ? '*' : ' ',
|
|
|
|
drivers[i]->shortname, drivers[i]->fullname);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
void dfmt_list(struct ofmt *ofmt, FILE * fp)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2005-01-16 06:15:51 +08:00
|
|
|
struct dfmt **drivers = ofmt->debug_formats;
|
2002-05-01 04:53:55 +08:00
|
|
|
while (*drivers) {
|
2005-01-16 06:15:51 +08:00
|
|
|
fprintf(fp, " %c %-10s%s\n",
|
|
|
|
drivers[0] == ofmt->current_dfmt ? '*' : ' ',
|
|
|
|
drivers[0]->shortname, drivers[0]->fullname);
|
|
|
|
drivers++;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ofmt *ofmt_register(efunc error)
|
|
|
|
{
|
|
|
|
for (ndrivers = 0; drivers[ndrivers] != NULL; ndrivers++) ;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
if (ndrivers == 0) {
|
2002-05-01 04:53:55 +08:00
|
|
|
error(ERR_PANIC | ERR_NOFILE,
|
2005-01-16 06:15:51 +08:00
|
|
|
"No output drivers given at compile time");
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
return (&OF_DEFAULT);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|