X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=as%2Fmcs51%2Fasmain.c;h=bb2194286945ad9c698ff7308eb90a69b5c6225b;hb=fa424f943fbccc663c46934b1785972d6eb28bc2;hp=57707cd53b7276038f9cc96df9c2ce30e56fb863;hpb=a49b42e497041dc982fa12e36b116d3335d3bd2a;p=fw%2Fsdcc diff --git a/as/mcs51/asmain.c b/as/mcs51/asmain.c index 57707cd5..bb219428 100644 --- a/as/mcs51/asmain.c +++ b/as/mcs51/asmain.c @@ -11,13 +11,13 @@ * 29-Oct-97 JLH pass ";!" comments to output file */ +#include #include #include #include #include "asm.h" -extern VOID machine(struct mne *); /*)Module asmain.c * * The module asmain.c includes the command argument parser, @@ -451,7 +451,7 @@ int i; * char getnb() aslex.c * VOID getst() aslex.c * sym * lookup() assym.c - * VOID machin() ___mch.c + * VOID machine() ___mch.c * mne * mlookup() assym.c * int more() aslex.c * VOID * new() assym.c @@ -479,7 +479,7 @@ asmbl() struct expr e1; char id[NCPS]; char opt[NCPS]; - char fn[FILSPC]; + char fn[PATH_MAX]; char *p; int d, n, uaf, uf; @@ -911,7 +911,7 @@ loop: d = getnb(); p = fn; while ((c = get()) != d) { - if (p < &fn[FILSPC-1]) { + if (p < &fn[PATH_MAX-1]) { *p++ = c; } else { break; @@ -1042,30 +1042,36 @@ char *fn; char *ft; int wf; { - register char *p1, *p2, *p3; + register char *p2, *p3; register int c; FILE *fp; - p1 = fn; p2 = afn; p3 = ft; - while ((c = *p1++) != 0 && c != FSEPX) { - if (p2 < &afn[FILSPC-4]) - *p2++ = c; - } + + strcpy (afn, fn); + p2 = strrchr (afn, FSEPX); // search last '.' + if (!p2) + p2 = afn + strlen (afn); + if (p2 > &afn[PATH_MAX-4]) // truncate filename, if it's too long + p2 = &afn[PATH_MAX-4]; *p2++ = FSEPX; - if (*p3 == 0) { - if (c == FSEPX) { - p3 = p1; - } else { - p3 = dsft; - } + + // choose a file-extension + if (*p3 == 0) { // extension supplied? + p3 = strrchr (fn, FSEPX); // no: extension in fn? + if (p3) + ++p3; + else + p3 = dsft; // no: default extension } - while ((c = *p3++) != 0) { - if (p2 < &afn[FILSPC-1]) + + while ((c = *p3++) != 0) { // strncpy + if (p2 < &afn[PATH_MAX-1]) *p2++ = c; } *p2++ = 0; + if ((fp = fopen(afn, wf?"w":"r")) == NULL) { fprintf(stderr, "%s: cannot %s.\n", afn, wf?"create":"open"); asexit(1);