[net.database] Unify RPT local function

john@birtch.UUCP (John Pipkins x257) (01/08/86)

I like the idea of sharing RPT (unify) functions, so I make my first
contributions.  The first is instring.  Instring will check for the
occurrance of any characters in the first string in the second string.
We needed it, honest. Oh yeah,  I developed this routine on a 4.2bsd
system and transfered it to our Pyramid 90x.  Guess what. The 90x version
was (partially) done in the SYSV. So, if you get a compile error, check
the 'strchr'.

The second routine I don't know (or refuse to remember) why I wrote it.  It
compares dates and returns an integer value (-1,0,1) based on the comparison.
(I think I did it for fun. We design types don't get to sling code much.)
Anyway, they work!


/********INSTRING*********/
/* instring.c - RPT local function to check for characters in string 1 in */
/*      string 2.                                                         */
/* inputs: string1, string2                                               */
/* output: 1 if any characters in string1 are in string2, else 0          */


#include <stdio.h>
#include <strings.h>
#include "../include/rptincl.h"
#include "../include/dbtypes.h"

#define FRSSTR (args[0].ur_val.c_val)
#define TSTSTR (args[1].ur_val.c_val)

union vals scheck;                              /* return value */

union vals instring(count, args)
int count;
struct uargs *args;
{
 int i;

/* check to see if we got right number of arguements */
        if(count != 2){
                fprintf(stderr,"instring: Wrong number of arguemnts\n");
                exit(99);
        }

/* see if we go right type of arguement */
        if((args[0].ur_type != STRNG) | (args[1].ur_type != STRNG)){
                fprintf(stderr,"instring: Bad arguement type\n");
                exit(99);
        }
/* do the checks */
        scheck.s_val = 0;                       /* assume not */

        for(i=0; FRSSTR[i] != NULL; i++){       /* while there are characters */
                if(strchr(TSTSTR, FRSSTR[i]) != NULL){  /* got non-null pointer? */
                        scheck.s_val = 1;       /* yes, set true return */
                        return scheck;          /* get out of here */
                }
        }
        return scheck;
}


/*********CHECKDATE*********/

/* checkdate - RPT local function to compare dates */
/* inputs: date1, date2 */
/* output: -1 if date1< date2, 0 if equal, 1 if date1 > date2 */

#include <stdio.h>
#include "../include/rptincl.h"
#include "../include/dbtypes.h"

#define LDATE args[0]
#define RDATE args[1]

union vals checkdate(count, args)
int count;
struct uargs *args;
{

union vals rdate;

/* check to see if we got right number of arguements */
        if(count != 2){
                fprintf(stderr,"checkdate: Wrong number of arguemnts\n");
                exit(99);
        }

/* see if we go right type of arguement */
        if((LDATE.ur_type != DATE) | (RDATE.ur_type != DATE)){
                fprintf(stderr,"checkdate: Bad arguement type\n");
                exit(99);
        }
/* do the checks */
        rdate.s_val = 0;
        if(LDATE.ur_val.s_val < RDATE.ur_val.s_val) rdate.s_val = -1;
        if(LDATE.ur_val.s_val > RDATE.ur_val.s_val) rdate.s_val = 1;
        return rdate;
}