/*static char *SCCSID = "@(#)str.c      6.1 90/11/18";*/
/****************************************************************************/
/*                                                                          */
/*                       IBM/Microsoft Confidential                         */
/*                                                                          */
/*                 Copyright (c) IBM Corporation  1987, 1990                */
/*                 Copyright (c) Microsoft Corp.  1987, 1990                */
/*                           All Rights Reserved                            */
/*                                                                          */
/****************************************************************************/

#include <doscalls.h>
#include <ipcqueue.h>

/********************** START OF SPECIFICATIONS **********************/
/*                                                                   */
/* SOURCE FILE NAME: str.c                                           */
/*                                                                   */
/* DESCRIPTIVE NAME: substitutes for needed 'C' runtime support      */
/*                                                                   */
/* COPYRIGHT: (TOP MODULE ONLY)                                      */
/*                                                                   */
/* STATUS: RELEASE 1 LEVEL 0                                         */
/*                                                                   */
/* FUNCTION:                                                         */
/*                                                                   */
/* NOTES:                                                            */
/*    DEPENDENCIES:                                                  */
/*    RESTRICTIONS:                                                  */
/*    PATCH LABEL: (TOP MODULE ONLY)                                 */
/*                                                                   */
/* ENTRY POINTS:                                                     */
/*             rascpy                                                */
/*             strcmp                                                */
/*             strcpy                                                */
/*             strlen                                                */
/*             strncmp                                               */
/*                                                                   */
/* INTERNAL REFERENCES:                                              */
/*    ROUTINES:                                                      */
/*                                                                   */
/* EXTERNAL REFERENCES:                                              */
/*                                                                   */
/*********************** END OF SPECIFICATIONS ***********************/

/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    strlen                                       */
/*                                                                  */
/* DESCRIPTIVE NAME:   string length                                */
/*                                                                  */
/* FUNCTION:   finds the length of the supplied ASCIIZ string       */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        strlen                                       */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DW       address of ASCIIZ string                    */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             AX = length of string                                */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:                                                         */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      strlen:                                                         */
/*                                                                      */
/*      set count = NULL                                                */
/*      while (*string++ != NULL)                                       */
/*        ;                                                             */
/*      endwhile                                                        */
/*      set return code = count                                         */
/*      return                                                          */

strlen(instring)
register char *instring;
{
   register int count;

   for (count = 0; *instring++ != '\0'; count++);
   return(count);
}


/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    farstrlen                                    */
/*                                                                  */
/* DESCRIPTIVE NAME:   string length                                */
/*                                                                  */
/* FUNCTION:   finds the length of the supplied ASCIIZ string       */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        strlen                                       */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DD      far  address of ASCIIZ string                */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             AX = length of string                                */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:                                                         */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      strlen:                                                         */
/*                                                                      */
/*      set count = NULL                                                */
/*      while (*string++ != NULL)                                       */
/*        ;                                                             */
/*      endwhile                                                        */
/*      set return code = count                                         */
/*      return                                                          */

farstrlen(instring)
char far *instring;
{
   register int count;

   for (count = 0; *instring++ != '\0'; count++);
   return(count);
}

/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    strcmp                                       */
/*                                                                  */
/* DESCRIPTIVE NAME:   string compare                               */
/*                                                                  */
/* FUNCTION:   compares two ASCIIZ strings for alphabetical order   */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        strcmp                                       */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DD       address of ASCIIZ string 1                  */
/*             DD       address of ASCIIZ string 2                  */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             AX = 0   strings are identical                       */
/*             AX > 0   string1 is greater                          */
/*             AX < 0   string2 is greater                          */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:                                                         */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      strcmp:                                                         */
/*                                                                      */
/*      while (both strings are non-zero in the current position) do    */
/*        if (string1 - string2 != 0) then                              */
/*          (strings are not eq in current position,                    */
/*           subtraction has set proper +/- return value)               */
/*          set return code = string1 - string2                         */
/*          return                                                      */
/*        else                                                          */
/*          (strings are eq in current position, check next position)   */
/*          increment string1 pointer                                   */
/*          increment string2 pointer                                   */
/*        endif                                                         */
/*      endwhile                                                        */
/*      (one or both strings have terminated)                           */
/*      if (string1 != NULL) then                                       */
/*        (string1 hasn't term., but string2 has, string1 greater)      */
/*        set return code = 1                                           */
/*        return                                                        */
/*      endif                                                           */
/*      if (string2 != NULL) then                                       */
/*        (string2 hasn't term., but string1 has, string2 greater)      */
/*        set return code = -1                                          */
/*        return                                                        */
/*      endif                                                           */
/*      (both strings have terminated with-out finding a difference,    */
/*       must be equal)                                                 */
/*      set return code = 0                                             */
/*      return                                                          */

strcmp(string1,string2)
char far *string1;
char far *string2;
{
        register int position;

        while (*string1 && *string2)
        {
                if(position = *string1++ - *string2++)
                        return(position);
        }
        if(*string1)
                return(1);
        if(*string2)
                return(-1);
        return(0);
}

/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    strncmp                                      */
/*                                                                  */
/* DESCRIPTIVE NAME:   length string compare                        */
/*                                                                  */
/* FUNCTION:   compares two ASCIIZ strings for alphabetical order   */
/*             up to a specified length                             */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        strncmp                                      */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DD       address of ASCIIZ string 1                  */
/*             DW       address of ASCIIZ string 2                  */
/*             DW       number of characters to compare             */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             AX = 0   strings are identical up to length          */
/*             AX > 0   string1 is greater    "  "    "             */
/*             AX < 0   string2 is greater    "  "    "             */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:                                                         */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      strncmp:                                                        */
/*                                                                      */
/*      repeat                                                          */
/*        if (string1 - string2 != 0) then                              */
/*          (strings are not eq in current position,                    */
/*           subtraction has set proper +/- return value)               */
/*          set return code = string1 - string2                         */
/*          return                                                      */
/*        else                                                          */
/*          (strings are eq in current position, check next position)   */
/*          increment string1 pointer                                   */
/*          increment string2 pointer                                   */
/*          decrement length                                            */
/*        endif                                                         */
/*      until (length = 0 or string1 = 0 or string 2 = 0)               */
/*      if (length !=0) then                                            */
/*      (havn't completed search, one or both strings have terminated)  */
/*        if (string1[position] != NULL) then                           */
/*          (string1 hasn't term., but string2 has, string1 greater)    */
/*          set return code = 1                                         */
/*          return                                                      */
/*        endif                                                         */
/*        if (string2[position] != NULL) then                           */
/*          (string2 hasn't term., but string1 has, string2 greater)    */
/*          set return code = -1                                        */
/*          return                                                      */
/*        endif                                                         */
/*        (if neither branch taken,both strings terminated before count */
/*         without finding a difference)                                */
/*      endif                                                           */
/*      (unable to find a difference, must be equal)                    */
/*      set return code = 0                                             */
/*      return                                                          */

strncmp(string1,string2,length)
char far *string1;
char *string2;
register int length;
{
        register int position;

        for (; (length && *string1 && *string2); length--)
        {
                if (position = *string1++ - *string2++)
                        return(position);
        }
        if (length)
        {
                if(*string1)
                        return(1);
                if(*string2)
                        return(-1);
        }
        return(0);
}

/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    strcpy                                       */
/*                                                                  */
/* DESCRIPTIVE NAME:   string copy                                  */
/*                                                                  */
/* FUNCTION:   copies contents of one string buffer to another      */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        strcpy                                       */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DD       address of destination ASCIIZ string        */
/*             DD       address of source ASCIIZ string             */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             N/A                                                  */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:     fills destination buffer                            */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      strcpy:                                                         */
/*                                                                      */
/*      repeat                                                          */
/*        destination = source                                          */
/*        increment destination pointer                                 */
/*        increment source pointer                                      */
/*      until (character copied = 0)                                    */
/*      return                                                          */
/* MDLL
void
strcpy(dest,source)
char far *dest;
char far *source;
{
        while (*dest++ = *source++)
               ;
        return;
}
   MDLL */
/********************** START OF SPECIFICATIONS *********************/
/*                                                                  */
/* SUBROUTINE NAME:    rascpy                                       */
/*                                                                  */
/* DESCRIPTIVE NAME:   ras string copy                              */
/*                                                                  */
/* FUNCTION:   copies contents of one string buffer to the ras      */
/*             buffer, obtains the size of the string               */
/*                                                                  */
/* NOTES:                                                           */
/*                                                                  */
/* ENTRY POINT:        rascpy                                       */
/*    LINKAGE:         near at pl 2                                 */
/*                                                                  */
/* INPUT:                                                           */
/*             DD       address of destination ASCIIZ string        */
/*             DD       address of source ASCIIZ string             */
/*             DD       address of length storage                   */
/*                                                                  */
/* EXIT-NORMAL:                                                     */
/*             N/A                                                  */
/*                                                                  */
/* EXIT-ERROR:                                                      */
/*                                                                  */
/* EFFECTS:     fills ras buffer, finds size of string              */
/*                                                                  */
/* INTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/* EXTERNAL REFERENCES:                                             */
/*    ROUTINES:                                                     */
/*                                                                  */
/*********************** END OF SPECIFICATIONS **********************/

/*      rascpy:                                                         */
/*                                                                      */
/*      copy input string to ras buffer                                 */
/*      len = size of ras string                                        */
/*      return                                                          */

void
rascpy(new,old,len)
char far *new;
char far *old;
unsigned far *len;
{
        register unsigned int   lcnt = 1;

        while (*new++ = *old++)
               lcnt++;
        *len = lcnt;
        return;
}
