/*	Title	All-Pro Diagnostics Editor Support*/
/******************************************************************************/
/*				     Diagpars				      */
/*			       All-pro Diagnostic Editor Support	      */
/*									      */
/* Module ...................... DIAGPARS				      */
/* Title ....................... All-pro Diagnostic Editor Support	      */
/* Developing Engineer ......... Steven T. Harr 			      */
/* Company ..................... Logical Devices			      */
/* Revision Level .............. 1.00					      */
/* Date of Last Revision ....... 02-13-87				      */
/* Last Revision by ............ STH					      */
/* Developing System .......... IBM PC or compatible			      */
/* Target System .............. IBM PC or compatible			      */
/* Language ................... C					      */
/* Compiler ................... Manx Aztec C v3.20e			      */
/* Compiler Command(s) ........ cc Diagpars				      */
/*									      */
/* Interpreter ................ none					      */
/*									      */
/* Synopsis ................... This module contains the Diagnostic Editor    */
/*				commands and the Program execution control.   */
/*									      */
/* Revision History:							      */
/*  v1.00   02-13-87		Original version - STH			      */
/*									      */
/******************************************************************************/
/*	Subttl	Includes*/
#include <stdio.h>
#include <ctype.h>
#include "cmdfile.h"
#include "keybrd.h"
#include "diag2.h"
#include "diagedit.h"
#include "diagpars.h"

extern unsigned char edit_buffer [];
extern file_compiled;

unsigned char object_buffer [OBJECT_BUFFER_SIZE];
unsigned char *arg_buffer [MAX_ARGS];
unsigned char *object_buffer_ptr;
unsigned char *edit_buffer_ptr;

int cmd_begin_flag;
int cmd_end_flag;

struct
{
    int usize;
    int utype;
    union
    {
	unsigned char byte;
	int word;
    } uval;
} arg_reg;




unsigned char key_word_table [MAX_OPR] [MAX_COMMAND_SIZE] =
{
    {""},
    {"WRPIN"},
    {"RDPIN"},
    {"WRCOMM"},
    {"RDCOMM"},
    {"WRMEM"},
    {"RDMEM"},
    {"DEFINE"},
    {"CMP"},
    {"PRINT"},
    {"BRA"},
    {"CALL"},
    {"BEGIN"},
    {"END"},
    {"RET"},
    {"RETURN"},
    {"DELAY"},
    {"PAUSE"},
    {"PUSH"},
    {"POP"},
    {"INPUT"},

    {"FLAGS"},
    {"ACC"},
    {"DAC"},
    {"STATE"},
    {"SOURCE"},
    {"GROUND"},
    {"PULLUP"},
    {"TTL_HI"},
    {"TTL_LOW"},
    {"DECOUPLE"},
    {"VOLTS"},
    {"COMP"},
    {"THRESH"},
    {"POWER"},
    {"CURRENT"},
    {"SLEWRATE"},
    {"ID"},
    {"OVC"},
    {"CHAR"},
    {"VAR"},
    {"BIT"},
    {"BYTE"},
    {"WORD"},
    {"LONG"},
    {"DEC"},
    {"HEX"},
    {"KEYSTAT"},
    {"EQU"},
    {"NEQ"},
    {"LT"},
    {"GT"},
    {"NLT"},
    {"NGT"},
    {"LTE"},
    {"GTE"},
    {"OVF"},
    {"UNC"},
    {"LOCAL"},
    {"EXTERN"},
    {"MS"},
    {"US"},
    {"LABEL"},
    {"CALC"},
    {"="},
    {"+"},
    {"-"},
    {"*"},
    {"/"},
    {"&"},
    {"|"},
    {">>"},
    {"<<"},
    {"%"}
};


compile_program ()
{
    int i;
    int error;
    int line;

    file_compiled = FALSE;
    if (edit_buffer [0] != STX)
    {
	return (0);
    }

    cmd_begin_flag = FALSE;
    cmd_end_flag = FALSE;

    object_buffer_ptr = &object_buffer [0];

    while (object_buffer_ptr < &object_buffer [OBJECT_BUFFER_SIZE])
    {
	*object_buffer_ptr++ = '\0';
    }

    object_buffer_ptr = &object_buffer [0];
    edit_buffer_ptr = &edit_buffer [2];

    pos_printf (10, 5, ">");
    line = 1;
    while ((*edit_buffer_ptr != ETX) && !(error = parse_line (edit_buffer_ptr, 1)))
    {
	printf (".");
	object_buffer_ptr += *object_buffer_ptr;
	while (*edit_buffer_ptr != CRLF)
	{
	    edit_buffer_ptr++;
	}
	edit_buffer_ptr++;
	line++;
    }
    if (error == -1)
    {
	pos_printf (20, 5, "Unrecognized command on line ");
	printf ("%d", line);
    }
    else if (error == -2)
    {
	pos_printf (20, 5, "Invalid number of arguments on line ");
	printf ("%d", line);
	pos_printf (21, 5, ">>> ");
	while ((*edit_buffer_ptr != CRLF) && (*edit_buffer_ptr != ETX))
	{
	    printf ("%c", *edit_buffer_ptr++);
	}
    }
    else if (error)
    {
	pos_printf (20, 5, "Error on line ");
	printf ("%d, argument %d", line, error);
    }
    else if (!cmd_begin_flag)
    {
	pos_printf (20, 5, "Missing BEGIN Statement");
    }
    else if (!cmd_end_flag)
    {
	pos_printf (20, 5, "Missing END Statement");
    }
    else
    {
/*
	video_clear_screen ();
*/
	object_buffer_ptr = &object_buffer [0];
	edit_buffer_ptr = &edit_buffer [2];

	pos_printf (12, 5, ">");
	line = 1;
	while ((*edit_buffer_ptr != ETX) && !(error = parse_line (edit_buffer_ptr, 2)))
	{
	    printf (".");
	    object_buffer_ptr += *object_buffer_ptr;
	    while (*edit_buffer_ptr != CRLF)
	    {
		edit_buffer_ptr++;
	    }
	    edit_buffer_ptr++;
	    line++;
	}
	if (error)
	{
	    pos_printf (20, 5, "Error on line ");
	    printf ("%d, argument %d", line, error);
	}
    }
    if (error)
    {
	pos_printf (21, 5, "Hit any key to return to menu");
	keybrd_getc ();
	return (0);
    }
    file_compiled = TRUE;
    return (1);
}



/* parse a line and return offset of error */
/* if no error then return end of buffer */

parse_line (line_ptr, pass)
unsigned char *line_ptr;
int pass;
{
    int i;
    int j;
    int error;
    int arg_count;
    unsigned char *dest_buffer;
    unsigned char *aptr;

    if (*line_ptr == CRLF)
    {
	return (0); /* blank line */
    }

    dest_buffer = object_buffer_ptr;

    /* separate arguments */
    for (arg_count = 0; (arg_count < MAX_ARGS) && (*line_ptr != CRLF) && (*line_ptr != ETX); arg_count++)
    {
	while (*line_ptr == ' ') line_ptr++; /* skip spaces */
	arg_buffer [arg_count] = line_ptr;

	if (*line_ptr == '"')
	{
	    line_ptr++;
	    while ((*line_ptr != ETX) && (*line_ptr != CRLF) && (*line_ptr != '"')) line_ptr++;
	    if (*line_ptr == '"') line_ptr++;
	}
	else
	{
	    while ((*line_ptr != ' ') && (*line_ptr != CRLF) && (*line_ptr != ','))
	    {
		line_ptr++;
	    }
	    if (*line_ptr != CRLF) line_ptr++;
	}
    }

    /* find key word tags */
    error = 0;
    dest_buffer [1] = get_cmd (arg_buffer [0]);
    switch (dest_buffer [1])
    {
	case 0:
	{
	    if ((dest_buffer [2] = get_arg (arg_buffer [0])) == ARG_VARIABLE)
	    {
		if (get_opr (arg_buffer [1]) == OPR_EQUALS)
		{
		    if (arg_count < 3)
		    {
			return (-2);
		    }
		    dest_buffer [1] = ARG_CALC;
		    aptr = &dest_buffer [3];
		    insert_arg_val (aptr);
		    aptr += arg_reg.usize;

		    aptr [0] = get_arg (arg_buffer [2]);
		    if ((aptr [0] != ARG_VARIABLE) && (aptr [0] != ARG_NUMBER))
		    {
			return (2);
		    }
		    else
		    {
			insert_arg_val (++aptr);
			aptr += arg_reg.usize;
		    }

		    for (i = 3; i < arg_count; i++)
		    {
			aptr [0] = get_opr (arg_buffer [i]);
			if ((aptr [0] >= MAX_KEY_WORDS) && (aptr [0] < MAX_OPR))
			{
			    aptr++;
			}
			else if (((aptr [0] = get_arg (arg_buffer [i])) == ARG_VARIABLE) || (aptr [0] == ARG_NUMBER))
			{
			    insert_arg_val (++aptr);
			    aptr += arg_reg.usize;
			}
			else
			{
			    return (i);
			}
		    }
		    aptr [0] = 0;
		    aptr++;
		    dest_buffer [0] = (unsigned char) (aptr - dest_buffer);
		}
		else
		{
		    return (1);
		}
	    }
	    else
	    {
		/* test for label */
		j = lenstr (arg_buffer [0]) - 1;
		if (j && (arg_buffer [0] [j] == ':'))
		{
		    if (arg_count != 1)
		    {
			return (-2);
		    }
		    cpystr (&dest_buffer [2], arg_buffer [0]);
		    dest_buffer [j + 2] = '\0';
		    dest_buffer [1] = ARG_LABEL;
		    dest_buffer [0] = j + 3;
		}
		else
		{
		    error = -1;
		}
	    }
	    break;
	}

	case CMD_WRPIN:
	{
	    if (arg_count != 4)
	    {
		return (-2);
	    }

	    dest_buffer [0] = 9;
	    dest_buffer [6] = get_arg (arg_buffer [3]);
	    if ((dest_buffer [6] == ARG_VARIABLE) || (dest_buffer [6] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [7]);
	    }
	    else
	    {
		switch (dest_buffer [6])
		{
		    case ARG_SOURCE:
		    case ARG_GROUND:
		    case ARG_PULLUP:
		    case ARG_TTL_HI:
		    case ARG_DECOUPLE:
		    {
			insert_arg_val (&dest_buffer [7]);
			break;
		    }
		    default:
		    {
			error = 3;
		    }
		}
	    }

	    dest_buffer [3] = get_arg (arg_buffer [2]);
	    if ((dest_buffer [3] == ARG_VARIABLE) || (dest_buffer [3] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [4]);
	    }
	    else
	    {
		error = 2;
	    }

	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if ((dest_buffer [2] != ARG_DAC) && (dest_buffer [2] != ARG_STATE))
	    {
		error = 1;
	    }
	    break;
	}

	case CMD_RDPIN:
	{
	    if (arg_count != 4)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 9;
	    if ((dest_buffer [6] = get_arg (arg_buffer [3])) == ARG_VARIABLE)
	    {
		insert_arg_val (&dest_buffer [7]);
	    }
	    else
	    {
		error = 3;
	    }

	    dest_buffer [3] = get_arg (arg_buffer [2]);
	    if ((dest_buffer [3] == ARG_VARIABLE) || (dest_buffer [3] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [4]);
	    }
	    else
	    {
		error = 2;
	    }

	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if ((dest_buffer [2] == ARG_VOLTS) || (dest_buffer [2] == ARG_COMP))
	    {
		insert_arg_val (&dest_buffer [2]);
	    }
	    else
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_WRCOMM:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    if (((dest_buffer [3] = get_arg (arg_buffer [2])) == ARG_VARIABLE) || (dest_buffer [3] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [4]);
		dest_buffer [0] = 6;
	    }
	    else
	    {
		error = 2;
	    }
	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    switch (dest_buffer [2])
	    {
		case ARG_THRESH:
		case ARG_POWER:
		case ARG_CURRENT:
		case ARG_PULLUP:
		case ARG_SLEWRATE:
		{
		    break;
		}
		default:
		{
		    error = 1;
		    break;
		}
	    }
	    break;
	}
	case CMD_RDCOMM:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    if ((dest_buffer [3] = get_arg (arg_buffer [2])) == ARG_VARIABLE)
	    {
		insert_arg_val (&dest_buffer [4]);
		dest_buffer [0] = 6;
	    }
	    else
	    {
		error = 2;
	    }
	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if ((dest_buffer [2] != ARG_ID) && (dest_buffer [2] != ARG_OVC))
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_WRMEM:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    if (((dest_buffer [5] = get_arg (arg_buffer [2])) == ARG_VARIABLE) || (dest_buffer [5] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [6]);
		dest_buffer [0] = 8;
	    }
	    else
	    {
		error = 2;
	    }
	    if (((dest_buffer [2] = get_arg (arg_buffer [1])) == ARG_VARIABLE) || (dest_buffer [2] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [3]);
	    }
	    else
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_RDMEM:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    if ((dest_buffer [5] = get_arg (arg_buffer [2])) == ARG_VARIABLE)
	    {
		insert_arg_val (&dest_buffer [6]);
		dest_buffer [0] = 8;
	    }
	    else
	    {
		error = 2;
	    }
	    if (((dest_buffer [2] = get_arg (arg_buffer [1])) == ARG_VARIABLE) || (dest_buffer [2] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [3]);
	    }
	    else
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_DEFINE:
	{
	    if (arg_count != 2)
	    {
		return (-2);
	    }

	    if (pass == 1 && get_arg (arg_buffer [1]))
	    {
		error = 1;
	    }
	    else
	    {
		cpystr (&dest_buffer [4], arg_buffer [1]);
		dest_buffer [0] = lenstr (arg_buffer [1]) + 5;
	    }
	    break;
	}
	case CMD_PUSH:
	case CMD_POP:
	{
	    if (arg_count != 2)
	    {
		return -2;
	    }
	    if (((dest_buffer [2] = get_arg (arg_buffer [1])) == ARG_VARIABLE) || (dest_buffer [2] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [3]);
		dest_buffer [0] = 5;
	    }
	    else
	    {
		error = 1;
	    }
	    break;
	}

	case CMD_CALL:
	{
	    if (arg_count != 2)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 4;
	    if (get_arg (arg_buffer [1]) == ARG_LABEL)
	    {
		insert_arg_val (&dest_buffer [2]);
	    }
	    else if (pass == 2)
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_RET:
	case CMD_RETURN:
	{
	    if (arg_count != 1)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 2;
	    break;
	}
	case CMD_BRA:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 5;
	    if (get_arg (arg_buffer [2]) == ARG_LABEL)
	    {
		insert_arg_val (&dest_buffer [3]);
	    }
	    else if (pass == 2)
	    {
		error = 2;
	    }
	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if (arg_reg.utype == TYP_BYTE)
	    {
		switch (arg_reg.uval.byte)
		{
		    case ARG_EQU:
		    case ARG_NEQ:
		    case ARG_LT:
		    case ARG_GT:
		    case ARG_NLT:
		    case ARG_NGT:
		    case ARG_GTE:
		    case ARG_LTE:
		    case ARG_OVF:
		    case ARG_UNC:
		    {
			insert_arg_val (&dest_buffer [2]);
			break;
		    }
		    default:
		    {
			error = 1;
		    }
		}
	    }
	    else
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_PRINT:
	{
	    unsigned char *k;
	    k = dest_buffer + 2;
	    *k++ = arg_count - 1;
	    for (j = 1; j < arg_count; j++)
	    {
		if ((*k = get_arg (arg_buffer [j])) == ARG_VARIABLE)
		{
		    insert_arg_val (++k);
		    k += arg_reg.usize;
		}
		else if (*k++ == ARG_STRING)
		{
		    *k = copy_quote (k + 1, arg_buffer [j]);
		    k += *k + 1;
		}
		else
		{
		    error = 1;
		}
	    }
	    dest_buffer [0] = k - dest_buffer;
	    break;
	}
	case CMD_INPUT:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 6;
	    if ((dest_buffer [3] = get_arg (arg_buffer [2])) == ARG_VARIABLE)
	    {
		insert_arg_val (&dest_buffer [4]);
	    }
	    else
	    {
		error = 2;
	    }
	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if ((dest_buffer [2] != ARG_HEX) && (dest_buffer [2] != ARG_DEC) && (dest_buffer [2] != ARG_CHAR))
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_CMP:
	{
	    if (arg_count != 3)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 8;

	    if (((dest_buffer [5] = get_arg (arg_buffer [2])) == ARG_VARIABLE) || (dest_buffer [5] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [6]);
	    }
	    else error = 2;

	    if (((dest_buffer [2] = get_arg (arg_buffer [1])) == ARG_VARIABLE) || (dest_buffer [2] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [3]);
	    }
	    else error = 1;

	    break;
	}
	case CMD_DELAY:
	{
	    if (arg_count != 3)
	    {
		return -2;
	    }
	    if (((dest_buffer [3] = get_arg (arg_buffer [2])) == ARG_VARIABLE) || (dest_buffer [3] == ARG_NUMBER))
	    {
		insert_arg_val (&dest_buffer [4]);
		dest_buffer [0] = 6;
	    }
	    else
	    {
		error = 2;
	    }
	    dest_buffer [2] = get_arg (arg_buffer [1]);
	    if ((dest_buffer [2] != ARG_MS) && (dest_buffer [2] != ARG_US))
	    {
		error = 1;
	    }
	    break;
	}
	case CMD_PAUSE:
	{
	    if (arg_count != 1)
	    {
		return -2;
	    }
	    dest_buffer [0] = 2;
	    break;
	}
	case CMD_BEGIN:
	{
	    if (arg_count != 1)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 2;
	    cmd_begin_flag = TRUE;
	    break;
	}
	case CMD_END:
	{
	    if (arg_count != 1)
	    {
		return (-2);
	    }
	    dest_buffer [0] = 2;
	    cmd_end_flag = TRUE;
	    break;
	}
	default:
	{
	    break;
	}
    }
    return (error);
}


get_cmd (arg_ptr)
unsigned char *arg_ptr;
{
    int i;

    for (i = 0; i < MAX_COMMANDS; i++)
    {
	if (cmpstr (&key_word_table [i] [0], arg_ptr) == 0)
	{
	    return (i);
	}
    }
    return (0);
}

get_opr (bfr_ptr)
unsigned char *bfr_ptr;
{
    int i;
    for (i = MAX_KEY_WORDS; i < MAX_OPR; i++)
    {
	if (cmpstr (bfr_ptr, &key_word_table [i] [0]) == 0)
	{
	    return (i);
	}
    }
    return (0);
}


get_arg (arg_ptr)
unsigned char *arg_ptr;
{
    int i;
    int arg_type;
    unsigned char *search_ptr;
    int num;
    unsigned char mod;

    arg_reg.usize = 0;
    arg_reg.utype = 0;

    if (*arg_ptr == '"')
    {
	return (ARG_STRING);
    }

    for (arg_type = 0, i = MAX_COMMANDS; !arg_type && (i < MAX_KEY_WORDS); i++)
    {
	if (cmpstr (key_word_table [i], arg_ptr) == 0)
	{
	    arg_reg.utype = TYP_BYTE;
	    arg_reg.usize = SIZE_BYTE;
	    arg_reg.uval.byte = i;
	    return (i);
	}
    }

    /* test for number */
    if ((*arg_ptr >= '0') && (*arg_ptr <= '9'))
    {
	/* make value */
	mod = arg_ptr [lenstr (arg_ptr) - 1];

	if (((mod >= '0') && (mod <= '9')) || (mod == 'D'))
	{
	    sscanf (arg_ptr, "%d", &arg_reg.uval.word);
	    arg_reg.usize = SIZE_WORD;
	    arg_reg.utype = TYP_WORD;
	}
	else
	{
	    sscanf (arg_ptr, "%h", &arg_reg.uval.word);
	    arg_reg.usize = SIZE_WORD;
	    arg_reg.utype = TYP_WORD;
	}
	return (ARG_NUMBER);
    }

    /* test for variable */
    search_ptr = &object_buffer [0];
    while ((search_ptr < &object_buffer [OBJECT_BUFFER_SIZE]) && (*search_ptr != 0))
    {
	if (search_ptr [1] == CMD_DEFINE)
	{
	    if (cmpstr (arg_ptr, &search_ptr [4]) == 0)
	    {
		arg_reg.uval.word = &search_ptr [2] - &object_buffer [0];
		arg_reg.utype = TYP_WORD;
		arg_reg.usize = SIZE_WORD;
		return (ARG_VARIABLE);
	    }
	}
	search_ptr += *search_ptr;
    }

    /* test for label */
    search_ptr = &object_buffer [0];
    num = 0;
    while ((search_ptr < &object_buffer [512]) && *search_ptr )
    {
	if (search_ptr [1] == ARG_LABEL)
	{
	    if (cmpstr (arg_ptr, &search_ptr [2]) == 0)
	    {
		arg_reg.uval.word = search_ptr - &object_buffer [0];
		arg_reg.utype = TYP_WORD;
		arg_reg.usize = SIZE_WORD;
		return (ARG_LABEL);
	    }
	}
	search_ptr += *search_ptr;
    }


    /* bad argument */
    return (0);
}

insert_arg_val (buffer_ptr)
unsigned char *buffer_ptr;
{
    int i;
    unsigned char *arg_ptr;

    arg_ptr = &arg_reg.uval.byte;
    for (i = 0; i < arg_reg.usize; i++)
    {
	*buffer_ptr++ = *arg_ptr++;
    }
}


lenstr (strptr)
unsigned char *strptr;
{
    int i;

    for (i = 0; (*strptr != ' ') && (*strptr != ',') &&
	(*strptr != CRLF) && (*strptr != ETX) && (*strptr != '\0'); i++)
    {
	strptr++;
    }
    return (i);
}

cpystr (strd, strs)
unsigned char *strd, *strs;
{
    while ((*strs != ' ') && (*strs != ',') && (*strs != CRLF) && (*strs != ETX) && (*strs != '\0'))
    {
	*strd++ = *strs++;
    }
    *strd = '\0';
}

cmpstr (str1, str2)
unsigned char *str1, *str2;
{
    while ((*str1 == *str2) && (*str1 != '\0') && (*str2 != '\0'))
    {
	str1++;
	str2++;
    }

    if ((*str1 == '\0') && ((*str2 == ' ') || (*str2 == CRLF) ||
	(*str2 == '\0') || (*str2 == ETX) || (*str2 == ',')))
	{
	    return (0);
	}
    if ((*str2 == '\0') && ((*str1 == ' ') || (*str1 == CRLF) ||
	(*str1 == '\0') || (*str1 == ETX) || (*str1 == ',')))
	{
	    return (0);
	}
    return (1);
}

copy_quote (dptr, sptr)
unsigned char *dptr, *sptr;
{
    int i;

    if (*sptr == '"') sptr++;

    for (i = 1; (*sptr != '"') && (*sptr != CRLF) && (*sptr != ETX); i++)
    {
	*dptr++ = *sptr++;
    }
    *dptr = '\0';
    return (i);
}



