Fix some path problems
[fw/sdcc] / as / mcs51 / asnoice.c
1 /* asnoice.c */
2
3 /*
4  * Extensions to CUG 292 assembler ASxxxx to produce NoICE debug files
5  *
6  * 3-Nov-1997 by John Hartman
7  */
8
9 #include <stdio.h>
10 #include <setjmp.h>
11 #include <string.h>
12 //#if !defined(_MSC_VER)
13 //#include <alloc.h>
14 //#endif
15 #include "asm.h"
16
17 /* Return basic file name without path or extension */
18 static char* BaseFileName( int fileNumber );
19
20 char* BaseFileName( int fileNumber )
21 {
22         static int prevFile = -1;
23         static char baseName[ FILSPC ];
24
25         char *p1, *p2;
26
27         if (fileNumber != prevFile)
28         {
29                 prevFile = fileNumber;
30
31                 p1 = srcfn[prevFile];
32
33                 /* issue a FILE command with full path and extension */
34                 fprintf( ofp, ";!FILE %s\n", p1 );
35
36                 /* Name starts after any colon or backslash (DOS) */
37                 p2 = strrchr( p1, '\\' );
38                 if (p2 == NULL) p2 = strrchr( p1, '/' );
39                 if (p2 == NULL) p2 = strrchr( p1, ':' );
40                 if (p2 == NULL) p2 = p1-1;
41                 strcpy( baseName, p2+1 );
42
43                 /* Name ends at any separator */
44                 p2 = strrchr( baseName, FSEPX );
45                 if (p2 != NULL) *p2 = 0;
46                 /* SD comment this out since not a ANSI Function */
47                 /* strupr( baseName ); */
48         }
49         return baseName;
50 }
51
52 /* Define a symbol for current location:  FILE.line# */
53 void DefineNoICE_Line()
54 {
55         char name[ NCPS ];
56         struct sym *pSym;
57
58         /* symbol is FILE.nnn */
59         sprintf( name, "%s.%u", BaseFileName( cfile ), srcline[ cfile ] );
60
61         pSym = lookup( name );
62         pSym->s_type = S_USER;
63         pSym->s_area = dot.s_area;
64         pSym->s_addr = laddr;
65         pSym->s_flag |= S_GBL;
66 }
67
68 /* Define a symbol for current location:  A$FILE$line# */
69 void DefineCDB_Line()
70 {
71         char name[ NCPS ];
72         struct sym *pSym;
73
74         /* symbol is FILE.nnn */
75         sprintf( name, "A$%s$%u", BaseFileName( cfile ), srcline[ cfile ] );
76
77         pSym = lookup( name );
78         pSym->s_type = S_USER;
79         pSym->s_area = dot.s_area;
80         pSym->s_addr = laddr;
81         pSym->s_flag |= S_GBL;
82 }
83
84 #if 0
85 OLD VERSION
86 /* Define a symbol for current location:  FILE.line# */
87 void DefineNoICE_Line()
88 {
89         static int prevFile = -1;
90         static struct area *pPrevArea = NULL;
91         static char baseName[ FILSPC ];
92
93         int j;
94         char *p1, *p2;
95
96         /* Get outfilename without extension for use as base symbol name */
97         if (baseName[0] == 0)
98         {
99                 p1 = srcfn[0];
100                 p2 = baseName;
101                 while ((*p1 != 0) && (*p1 != FSEPX))
102                 {
103                         *p2++ = *p1++;
104                 }
105                 *p2 = 0;
106                 /* SD Commented this out since it is not a 
107                    ASNI Function */
108                 /* strupr( baseName ); */
109         }
110
111         if ((cfile != prevFile) || (dot.s_area != pPrevArea))
112         {
113                 prevFile = cfile;
114                 pPrevArea = dot.s_area;
115
116                 /* file or area change: issue FILE command with base @ */
117                 fprintf( ofp, ";!FILE %s %s_%s\n", srcfn[ cfile ],
118                          baseName,
119                          dot.s_area->a_id );
120         }
121
122         fprintf( ofp, ";!LINE %u. 0x%X\n", srcline[ cfile ], laddr );
123 }
124
125 #endif