#include<stdio.h> 
 
/* 




                 VV                   VV    EEEEEEEEEEEEEE   
                  VV                 VV     EE  
                   VV               VV      EE
                    VV             VV       EE
                     VV           VV        EE
                      VV         VV         EEEEEEEEEEEEEE
                       VV       VV          EE
                        VV     VV           EE
                         VV   VV            EE
                          VV VV             EE
                           VVV              EE
                            V               EEEEEEEEEEEEEE
                                                       
 
 
 
 
                       MODULE  : stringprim.c
 
                       VERSION : v3.0
 
                       REVISED : 28 Apr 2005
 
                       AUTHOR  : Michael A. Campbell
 
 
 
 
 
 


                          FUNCTIONAL DESCRIPTION
                          ----------------------
 
               This module contains the C versions of basic string
 
               primitives required by the VE editor.  These routines
 
               emulate the actions of the 8086 string manipulation
 
               instructions, for the sake of portability.  The original

               optimized versions for the 8086 were in file STRPRIM.A.








*/

/* .page */

int findb (buf_p, target, count)

    /* Find a target byte in the buffer pointed to by buf_p. */

    char *buf_p;
    char target;
    int  count;

{
    register int i;

    for (i = 0; i < count; i++)
         if (buf_p[i] == target)
             return (i);

    return (-1);

} /* findb */

/* .page */

int findb_not (buf_p, target, count)

    /* Find a byte in the buffer pointed to by buf_p that is not equal to */
    /* the supplied target byte. Return the index of this byte.           */

    char *buf_p;
    char target;
    int  count;

{
    register int i;

    for (i = 0; i < count; i++)
         if (buf_p[i] != target)
             return ( i);

    return (-1);

} /* findb_not */

/* .page */

void setb (value, buf_p, count)

/* Set the buffer pointed to by buf_p to the given value. */

    char  value;
    char  *buf_p;
    int   count;

{
    register int i;

    for (i = 0; i < count; i++)
         buf_p[i] = value;

} /* setb */

/* .page */

void movb (srcb, dstb, count)

/* Move a string of bytes from one place to another.                        */

    char *srcb;            /* Pointer to source bytes                       */
    char *dstb;            /* Pointer to destination bytes                  */
    int  count;            /* Number of bytes to move                       */

{
    register int i;        /* Simple loop counter                           */

    for ( i = 0; i < count; i++ )
         dstb[i] = srcb[i];

} /* movb */

/* .page */

void movw (srcw, dstw, count)

/* Move a string of words from one place to another. */

    int *srcw;
    int *dstw;
    int  count;

{
    register int i;

    for (i = 0; i < count; i++)
         dstw[i] = srcw[i];

} /* movw */

/* .page */

int cmpb (buf1, buf2,count)

/* Compare two buffers for equality. */

    char    buf1 [];
    char    buf2 [];

    int     count;
{
    register int i;

    for (i = 0; i < count; i++)
        if (buf1[i] != buf2[i]) 
            return (i);

    return (-1);

} /* cmpb */

/* .page */

int sumb ( buf, len )

/* Return the sum of all the characters in char array pointed to by buf */
/* That char array is assumed to hold "len" chars.                      */

char buf [];
int  len;

{
   register int sum = 0;
   register int i; 

   for ( i = 0; i < len; i++ )
      sum += (int) buf[i];

   return ( sum );

} /* sumb */

/* .page */

int sumw ( buf, len )

/* Return the sum of all the integers in the integer array pointed to   */
/* by buf. That array is assumed to hold "len" elements.                */

int buf [];
int len;

{
   register int sum = 0;
   register int i; 

   for ( i = 0; i < len; i++ )
      sum += buf[i];

   return ( sum );

} /* sumw */

