Fixed the bugs pointed out by CodeSmith and nueron. Also fixed a bug that would occur with filename with spaces.
#include <exec/types.h>
#include <exec/libraries.h>
#include <dos/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "assembler.h"
int assemble(char *file_name)
{
struct Library *DOSBase = NULL;
if (!(DOSBase = OpenLibrary(DOSNAME, 33)))
{
printf("Unable to open dos.library\n");
return FALSE;
}
else
{
char *command = NULL;
char *assembler_name = "PhxAss";
char *output_file_name = "file.err";
BPTR output_file = NULL;
if (!(command = (char *)malloc(strlen(assembler_name) + strlen(file_name) + 4)))
{
printf("Out of memory\n");
return FALSE;
}
strcpy(command, assembler_name);
strcat(command, " \"");
strcat(command, file_name);
strcat(command, "\"");
output_file = Open(output_file_name, MODE_NEWFILE);
printf("command <%s>\n", command);
Execute(command, NULL, output_file); /* Call the assembler. */
if (output_file)
{
Close(output_file);
}
CloseLibrary(DOSBase);
}
return TRUE;
}