perl 3.0 patch #22 patch #19, continued
[p5sagit/p5-mst-13.2.git] / util.c
diff --git a/util.c b/util.c
index dd28d8d..07e057b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,4 +1,4 @@
-/* $Header: util.c,v 3.0.1.3 89/12/21 20:27:41 lwall Locked $
+/* $Header: util.c,v 3.0.1.5 90/03/27 16:35:13 lwall Locked $
  *
  *    Copyright (c) 1989, Larry Wall
  *
@@ -6,6 +6,17 @@
  *    as specified in the README file that comes with the perl 3.0 kit.
  *
  * $Log:       util.c,v $
+ * Revision 3.0.1.5  90/03/27  16:35:13  lwall
+ * patch16: MSDOS support
+ * patch16: support for machines that can't cast negative floats to unsigned ints
+ * patch16: tail anchored pattern could dump if string to search was shorter
+ * 
+ * Revision 3.0.1.4  90/03/01  10:26:48  lwall
+ * patch9: fbminstr() called instr() rather than ninstr()
+ * patch9: nested evals clobbered their longjmp environment
+ * patch9: piped opens returned undefined rather than 0 in child
+ * patch9: the x operator is now up to 10 times faster
+ * 
  * Revision 3.0.1.3  89/12/21  20:27:41  lwall
  * patch7: errno may now be a macro with an lvalue
  * 
@@ -479,12 +490,15 @@ STR *littlestr;
 
 #ifndef lint
     if (!(littlestr->str_pok & SP_FBM))
-       return instr((char*)big,littlestr->str_ptr);
+       return ninstr((char*)big,(char*)bigend,
+               littlestr->str_ptr, littlestr->str_ptr + littlestr->str_cur);
 #endif
 
     littlelen = littlestr->str_cur;
 #ifndef lint
     if (littlestr->str_pok & SP_TAIL && !multiline) {  /* tail anchored? */
+       if (littlelen > bigend - big)
+           return Nullch;
        little = (unsigned char*)littlestr->str_ptr;
        if (littlestr->str_pok & SP_CASEFOLD) { /* oops, fake it */
            big = bigend - littlelen;           /* just start near end */
@@ -733,11 +747,33 @@ long a1, a2, a3, a4;
 {
     extern FILE *e_fp;
     extern char *e_tmpname;
+    char *tmps;
 
     mess(pat,a1,a2,a3,a4);
     if (in_eval) {
        str_set(stab_val(stabent("@",TRUE)),buf);
-       longjmp(eval_env,1);
+       tmps = "_EVAL_";
+       while (loop_ptr >= 0 && (!loop_stack[loop_ptr].loop_label ||
+         strNE(tmps,loop_stack[loop_ptr].loop_label) )) {
+#ifdef DEBUGGING
+           if (debug & 4) {
+               deb("(Skipping label #%d %s)\n",loop_ptr,
+                   loop_stack[loop_ptr].loop_label);
+           }
+#endif
+           loop_ptr--;
+       }
+#ifdef DEBUGGING
+       if (debug & 4) {
+           deb("(Found label #%d %s)\n",loop_ptr,
+               loop_stack[loop_ptr].loop_label);
+       }
+#endif
+       if (loop_ptr < 0) {
+           in_eval = 0;
+           fatal("Bad label: %s", tmps);
+       }
+       longjmp(loop_stack[loop_ptr].loop_env, 1);
     }
     fputs(buf,stderr);
     (void)fflush(stderr);
@@ -809,6 +845,7 @@ va_dcl
     va_list args;
     extern FILE *e_fp;
     extern char *e_tmpname;
+    char *tmps;
 
 #ifndef lint
     va_start(args);
@@ -819,7 +856,28 @@ va_dcl
     va_end(args);
     if (in_eval) {
        str_set(stab_val(stabent("@",TRUE)),buf);
-       longjmp(eval_env,1);
+       tmps = "_EVAL_";
+       while (loop_ptr >= 0 && (!loop_stack[loop_ptr].loop_label ||
+         strNE(tmps,loop_stack[loop_ptr].loop_label) )) {
+#ifdef DEBUGGING
+           if (debug & 4) {
+               deb("(Skipping label #%d %s)\n",loop_ptr,
+                   loop_stack[loop_ptr].loop_label);
+           }
+#endif
+           loop_ptr--;
+       }
+#ifdef DEBUGGING
+       if (debug & 4) {
+           deb("(Found label #%d %s)\n",loop_ptr,
+               loop_stack[loop_ptr].loop_label);
+       }
+#endif
+       if (loop_ptr < 0) {
+           in_eval = 0;
+           fatal("Bad label: %s", tmps);
+       }
+       longjmp(loop_stack[loop_ptr].loop_env, 1);
     }
     fputs(buf,stderr);
     (void)fflush(stderr);
@@ -1065,6 +1123,7 @@ register long l;
 #endif /* BYTEORDER != 0x4321 */
 #endif /* HTONS */
 
+#ifndef MSDOS
 FILE *
 mypopen(cmd,mode)
 char   *cmd;
@@ -1112,6 +1171,7 @@ char      *mode;
        }
        if (tmpstab = stabent("$",allstabs))
            str_numset(STAB_STR(tmpstab),(double)getpid());
+       forkprocess = 0;
        return Nullfp;
 #undef THIS
 #undef THAT
@@ -1123,6 +1183,7 @@ char      *mode;
     forkprocess = pid;
     return fdopen(p[this], mode);
 }
+#endif /* !MSDOS */
 
 #ifdef NOTDEF
 dumpfds(s)
@@ -1157,6 +1218,7 @@ int newfd;
 }
 #endif
 
+#ifndef MSDOS
 int
 mypclose(ptr)
 FILE *ptr;
@@ -1198,6 +1260,7 @@ FILE *ptr;
     str_numset(str,0.0);
     return(status);
 }
+#endif /* !MSDOS */
 
 pidgone(pid,status)
 int pid;
@@ -1235,3 +1298,41 @@ register int len;
     return 0;
 }
 #endif /* MEMCMP */
+
+void
+repeatcpy(to,from,len,count)
+register char *to;
+register char *from;
+int len;
+register int count;
+{
+    register int todo;
+    register char *frombase = from;
+
+    if (len == 1) {
+       todo = *from;
+       while (count-- > 0)
+           *to++ = todo;
+       return;
+    }
+    while (count-- > 0) {
+       for (todo = len; todo > 0; todo--) {
+           *to++ = *from++;
+       }
+       from = frombase;
+    }
+}
+
+#ifndef CASTNEGFLOAT
+unsigned long
+castulong(f)
+double f;
+{
+    long along;
+
+    if (f >= 0.0)
+       return (unsigned long)f;
+    along = (long)f;
+    return (unsigned long)along;
+}
+#endif