cleaned up the mess I left behind
[fw/sdcc] / as / mcs51 / aslex.c
index 4cbcda629e67b43a96508ec7f485a551b6b651dd..4f774c424d03a17495448fb949ea42567cb72374 100644 (file)
@@ -15,7 +15,6 @@
 #include <stdio.h>
 #include <setjmp.h>
 #include <string.h>
-#include <alloc.h>
 #include "asm.h"
 
 /*)Module      aslex.c
@@ -402,8 +401,6 @@ getmap(d)
 int
 getline()
 {
-register int i;
-
 loop:  if (incfil >= 0) {
                if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
                        fclose(ifp[incfil--]);
@@ -423,9 +420,7 @@ loop:       if (incfil >= 0) {
                        ++srcline[cfile];
                }
        }
-       i = strlen(ib) - 1;
-       if (ib[i] == '\n')
-               ib[i] = 0;
+       chop_crlf(ib);
        return (1);
 }
 
@@ -492,3 +487,34 @@ endline()
        c = getnb();
        return( (c == '\0' || c == ';') ? 0 : c );
 }
+
+/*)Function    VOID    chop_crlf(str)
+ *
+ *             char    *str            string to chop
+ *
+ *     The function chop_crlf() removes trailing LF or CR/LF from
+ *     str, if present.
+ *
+ *     local variables:
+ *             int     i               string length
+ *
+ *     global variables:
+ *             none
+ *
+ *     functions called:
+ *             none
+ *
+ *     side effects:
+ *             none
+ */
+
+VOID
+chop_crlf(str)
+char *str;
+{
+       register int i;
+
+       i = strlen(str);
+       if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
+       if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;
+}