OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_spec.c versions 1.4 and 1.5
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_spec.c 1.4 -> 1.5

--- l2_spec.c    2001/11/30 09:44:47     1.4
+++ l2_spec.c    2001/12/14 12:42:07     1.5
@@ -95,3 +95,61 @@
     return ctx.rv;
 }
 
+/* remember a specification parsing error (used internally) */
+void l2_spec_error(l2_spec_ctx_t *ctx, l2_result_t rv, YYLTYPE *loc, const char *fmt, ...)
+{
+    const char *cpF, *cpL;
+    const char *cpP, *cpE;
+    int line, column;
+    char *cpBuf;
+    char *cp;
+    int n;
+
+    /* determine first and last positions of token */
+    cpF = ctx->inputbuf+loc->first;
+    cpL = ctx->inputbuf+loc->last;
+
+    /* determine epilog and prolog of token */
+    cpP = cpF-4;
+    if (cpP < ctx->inputbuf)
+        cpP = ctx->inputbuf;
+    cpE = cpL+4;
+    if (cpE > ctx->inputbuf+ctx->inputlen)
+        cpE = ctx->inputbuf+ctx->inputlen;
+
+    /* calculate line and column of token */
+    line   = 1;
+    column = 1;
+    for (cp = ctx->inputbuf; cp < (ctx->inputbuf+ctx->inputlen) && cp != cpF; cp++) {
+        column++;
+        if (*cp == '\n') {
+            column = 1;
+            line++;
+        }
+    }
+
+    /* extract token context with mark token borders */
+    if ((cpBuf = malloc((cpE-cpP)+2+1)) == NULL)
+        return;
+    cp = cpBuf;
+    n = cpF-cpP;
+    memcpy(cp, cpP, n); cp += n;
+    *cp++ = '<';
+    n = cpL-cpF;
+    memcpy(cp, cpF, n); cp += n;
+    *cp++ = '>';
+    n = cpE-cpL;
+    memcpy(cp, cpL, n); cp += n;
+    *cp++ = '\0';
+
+    /* remember error */
+    l2_env_errorinfo(ctx->env, rv, "line %d, column %d: `%s'; %s",
+                     line, column, cpBuf, fmt);
+    ctx->rv = rv;
+
+    /* cleanup */
+    free(cpBuf);
+
+    return;
+}
+

CVSTrac 2.0.1