]> granicus.if.org Git - yasm/commitdiff
Initial check-in. Still need to implement dynamic argument typing.
authorPeter Johnson <peter@tortall.net>
Sun, 20 May 2001 08:28:57 +0000 (08:28 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 20 May 2001 08:28:57 +0000 (08:28 -0000)
svn path=/trunk/yasm/; revision=13

include/errwarn.h [new file with mode: 0644]
libyasm/errwarn.c [new file with mode: 0644]
libyasm/errwarn.h [new file with mode: 0644]
src/errwarn.c [new file with mode: 0644]
src/errwarn.h [new file with mode: 0644]

diff --git a/include/errwarn.h b/include/errwarn.h
new file mode 100644 (file)
index 0000000..c57aa0f
--- /dev/null
@@ -0,0 +1,51 @@
+/* $Id: errwarn.h,v 1.1 2001/05/20 08:28:57 peter Exp $
+ * Error and warning reporting and related functions header file.
+ *
+ *  Copyright (C) 2001  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _ERRWARN_H_
+#define _ERRWARN_H_
+
+char *conv_unprint(char ch);
+
+typedef enum {
+    FATAL_UNKNOWN = 0,
+    FATAL_NOMEM
+} fatal_num;
+
+void Fatal(fatal_num);
+
+typedef enum {
+    ERR_UNKNOWN = 0,
+    ERR_PARSER,
+    ERR_MISSING,
+    ERR_MISSING_ARG,
+    ERR_INVALID_ARG
+} err_num;
+
+void Error(err_num, char *, ...);
+
+typedef enum {
+    WARN_UNKNOWN = 0,
+    WARN_UNREC_CHAR
+} warn_num;
+
+void Warning(warn_num, char *, ...);
+
+#endif
diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c
new file mode 100644 (file)
index 0000000..78319c6
--- /dev/null
@@ -0,0 +1,137 @@
+/* $Id: errwarn.c,v 1.1 2001/05/20 08:28:57 peter Exp $
+ * Error and warning reporting and related functions.
+ *
+ *  Copyright (C) 2001  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include "errwarn.h"
+#include "globals.h"
+
+unsigned int error_count = 0;
+unsigned int warning_count = 0;
+
+static char *fatal_msgs[] = {
+    "unknown",
+    "out of memory"
+};
+
+static char *err_msgs[] = {
+    "unknown error",
+    "parser error: %s",
+    "missing '%1'",
+    "missing argument to %s",
+    "invalid argument to %s"
+};
+
+static char *warn_msgs[] = {
+    "unknown",
+    "ignoring unrecognized character '%s'"
+};
+
+/* conv_unprint: convert a possibly unprintable character into a printable
+ * string, using standard cat(1) convention for unprintable characters. */
+static char unprint[5];
+char *conv_unprint(char ch)
+{
+    int pos=0;
+
+    if(!isascii(ch) && !isprint(ch)) {
+       unprint[pos++] = 'M';
+       unprint[pos++] = '-';
+       ch = toascii(ch);
+    }
+    if(iscntrl(ch)) {
+       unprint[pos++] = '^';
+       unprint[pos++] = (ch == '\177') ? '?' : ch | 0100;
+    } else
+       unprint[pos++] = ch;
+    unprint[pos] = '\0';
+
+    return unprint;
+}
+
+/* yyerror: parser error handler */
+void yyerror(char *s)
+{
+    Error(ERR_PARSER, (char *)NULL, s);
+}
+
+void Fatal(fatal_num num)
+{
+    fprintf(stderr, "FATAL: %s\n", fatal_msgs[num]);
+    exit(EXIT_FAILURE);
+}
+
+static char *process_argtypes(char *src, char *argtypes)
+{
+    char *dest;
+
+    if(argtypes) {
+       dest = malloc(strlen(src) + strlen(argtypes));
+       if(!dest)
+           Fatal(FATAL_NOMEM);
+       /* TODO: Implement */
+    } else {
+       dest = strdup(src);
+       if(!dest)
+           Fatal(FATAL_NOMEM);
+    }
+    return dest;
+}
+
+void Error(err_num num, char *argtypes, ...)
+{
+    va_list ap;
+    char *printf_str;
+
+    printf_str = process_argtypes(err_msgs[num], argtypes);
+
+    fprintf(stderr, "filename:%u: ", line_number);
+    va_start(ap, argtypes);
+    vfprintf(stderr, printf_str, ap);
+    va_end(ap);
+    fprintf(stderr, "\n");
+
+    free(printf_str);
+
+    error_count++;
+}
+
+void Warning(warn_num num, char *argtypes, ...)
+{
+    va_list ap;
+    char *printf_str;
+
+    printf_str = process_argtypes(warn_msgs[num], argtypes);
+
+    fprintf(stderr, "filename:%u: warning: ", line_number);
+    va_start(ap, argtypes);
+    vfprintf(stderr, printf_str, ap);
+    va_end(ap);
+    fprintf(stderr, "\n");
+
+    free(printf_str);
+
+    warning_count++;
+}
+
diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h
new file mode 100644 (file)
index 0000000..c57aa0f
--- /dev/null
@@ -0,0 +1,51 @@
+/* $Id: errwarn.h,v 1.1 2001/05/20 08:28:57 peter Exp $
+ * Error and warning reporting and related functions header file.
+ *
+ *  Copyright (C) 2001  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _ERRWARN_H_
+#define _ERRWARN_H_
+
+char *conv_unprint(char ch);
+
+typedef enum {
+    FATAL_UNKNOWN = 0,
+    FATAL_NOMEM
+} fatal_num;
+
+void Fatal(fatal_num);
+
+typedef enum {
+    ERR_UNKNOWN = 0,
+    ERR_PARSER,
+    ERR_MISSING,
+    ERR_MISSING_ARG,
+    ERR_INVALID_ARG
+} err_num;
+
+void Error(err_num, char *, ...);
+
+typedef enum {
+    WARN_UNKNOWN = 0,
+    WARN_UNREC_CHAR
+} warn_num;
+
+void Warning(warn_num, char *, ...);
+
+#endif
diff --git a/src/errwarn.c b/src/errwarn.c
new file mode 100644 (file)
index 0000000..78319c6
--- /dev/null
@@ -0,0 +1,137 @@
+/* $Id: errwarn.c,v 1.1 2001/05/20 08:28:57 peter Exp $
+ * Error and warning reporting and related functions.
+ *
+ *  Copyright (C) 2001  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include "errwarn.h"
+#include "globals.h"
+
+unsigned int error_count = 0;
+unsigned int warning_count = 0;
+
+static char *fatal_msgs[] = {
+    "unknown",
+    "out of memory"
+};
+
+static char *err_msgs[] = {
+    "unknown error",
+    "parser error: %s",
+    "missing '%1'",
+    "missing argument to %s",
+    "invalid argument to %s"
+};
+
+static char *warn_msgs[] = {
+    "unknown",
+    "ignoring unrecognized character '%s'"
+};
+
+/* conv_unprint: convert a possibly unprintable character into a printable
+ * string, using standard cat(1) convention for unprintable characters. */
+static char unprint[5];
+char *conv_unprint(char ch)
+{
+    int pos=0;
+
+    if(!isascii(ch) && !isprint(ch)) {
+       unprint[pos++] = 'M';
+       unprint[pos++] = '-';
+       ch = toascii(ch);
+    }
+    if(iscntrl(ch)) {
+       unprint[pos++] = '^';
+       unprint[pos++] = (ch == '\177') ? '?' : ch | 0100;
+    } else
+       unprint[pos++] = ch;
+    unprint[pos] = '\0';
+
+    return unprint;
+}
+
+/* yyerror: parser error handler */
+void yyerror(char *s)
+{
+    Error(ERR_PARSER, (char *)NULL, s);
+}
+
+void Fatal(fatal_num num)
+{
+    fprintf(stderr, "FATAL: %s\n", fatal_msgs[num]);
+    exit(EXIT_FAILURE);
+}
+
+static char *process_argtypes(char *src, char *argtypes)
+{
+    char *dest;
+
+    if(argtypes) {
+       dest = malloc(strlen(src) + strlen(argtypes));
+       if(!dest)
+           Fatal(FATAL_NOMEM);
+       /* TODO: Implement */
+    } else {
+       dest = strdup(src);
+       if(!dest)
+           Fatal(FATAL_NOMEM);
+    }
+    return dest;
+}
+
+void Error(err_num num, char *argtypes, ...)
+{
+    va_list ap;
+    char *printf_str;
+
+    printf_str = process_argtypes(err_msgs[num], argtypes);
+
+    fprintf(stderr, "filename:%u: ", line_number);
+    va_start(ap, argtypes);
+    vfprintf(stderr, printf_str, ap);
+    va_end(ap);
+    fprintf(stderr, "\n");
+
+    free(printf_str);
+
+    error_count++;
+}
+
+void Warning(warn_num num, char *argtypes, ...)
+{
+    va_list ap;
+    char *printf_str;
+
+    printf_str = process_argtypes(warn_msgs[num], argtypes);
+
+    fprintf(stderr, "filename:%u: warning: ", line_number);
+    va_start(ap, argtypes);
+    vfprintf(stderr, printf_str, ap);
+    va_end(ap);
+    fprintf(stderr, "\n");
+
+    free(printf_str);
+
+    warning_count++;
+}
+
diff --git a/src/errwarn.h b/src/errwarn.h
new file mode 100644 (file)
index 0000000..c57aa0f
--- /dev/null
@@ -0,0 +1,51 @@
+/* $Id: errwarn.h,v 1.1 2001/05/20 08:28:57 peter Exp $
+ * Error and warning reporting and related functions header file.
+ *
+ *  Copyright (C) 2001  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _ERRWARN_H_
+#define _ERRWARN_H_
+
+char *conv_unprint(char ch);
+
+typedef enum {
+    FATAL_UNKNOWN = 0,
+    FATAL_NOMEM
+} fatal_num;
+
+void Fatal(fatal_num);
+
+typedef enum {
+    ERR_UNKNOWN = 0,
+    ERR_PARSER,
+    ERR_MISSING,
+    ERR_MISSING_ARG,
+    ERR_INVALID_ARG
+} err_num;
+
+void Error(err_num, char *, ...);
+
+typedef enum {
+    WARN_UNKNOWN = 0,
+    WARN_UNREC_CHAR
+} warn_num;
+
+void Warning(warn_num, char *, ...);
+
+#endif