misc-parser.c 5.1 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: misc-parser.c,v 0.12 1998/07/08 13:41:32 ceder Exp $
3
 * Copyright (C) 1990, 1991, 1993, 1994, 1995  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
.  
Per Cederqvist committed
25 26 27 28 29
/*
 *  misc-parser.c
 *		Parse a list of misc-items for LysKOM texts.
 *
 *
30
 *  Copyright (C) 1990, 1991, 1993, 1994, 1995	Lysator Computer Club,
Per Cederqvist's avatar
.  
Per Cederqvist committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 *			Linkoping University,  Sweden
 *
 *  Everyone is granted permission to copy, modify and redistribute
 *  this code, provided the people they give it to can.
 *
 *
 *  Author:	Thomas Bellman
 *		Lysator Computer Club
 *		Linkoping University
 *		Sweden
 *
 *  email:	Bellman@Lysator.LiU.SE
 *
 *
 *  Any opinions expressed in this code are the author's PERSONAL opinions,
 *  and does NOT, repeat NOT, represent any official standpoint of Lysator,
 *  even if so stated.
 */

50 51
static const char *
rcsid = "$Id: misc-parser.c,v 0.12 1998/07/08 13:41:32 ceder Exp $";
52 53
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
.  
Per Cederqvist committed
54

55 56
#include <sys/types.h>
#include <time.h>
57

58 59
#include "s-string.h"
#include "misc-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
60 61
#include "misc-parser.h"

Per Cederqvist's avatar
.  
Per Cederqvist committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#define EXPORT


/*
 *  Return TRUE if the next misc-item exist, and it is of type
 *  MTYPE, FALSE otherwise.  Can only be used within the function
 *  parse_next_misc().
 */
#define NEXT_IS(mtype)						\
    (*info < stop_pointer && (*info)->type == (mtype))


#define BARF	{  result.type = m_error;  return  result;  }


/*
 *  Parse out a "group" of misc-items from a list of them pointed
 *  to by *INFO.  *STOP_POINTER must point to the item directly
 *  after the last in the list.  **INFO will be incremented to
 *  point to the item after the recently parsed out group.  The
 *  return value will have the TYPE field set to 'm_end_of_list'
 *  when the end of the list has been reached.
 */
EXPORT  Misc_info_group
parse_next_misc (const Misc_info	** info,
		 const Misc_info	 * stop_pointer)

{
    Misc_info_group	  result;

    
	
    /* Clear the 'result' struct */
    result.type = m_error;
    result.recipient = 0;
    result.cc_recipient = 0;
    result.local_no = 0;
    result.is_received = FALSE;
    result.comment_to = 0;
    result.commented_in = 0;
    result.footnote_to = 0;
    result.footnoted_in = 0;
    result.sender = 0;
105
    result.is_sent = FALSE;
Per Cederqvist's avatar
.  
Per Cederqvist committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214


    if (*info >= stop_pointer)
    {
	result.type = m_end_of_list;
	return  result;
    }

    
    /* Now, do the real work... */
    switch ((*info)->type)
    {
    case  recpt:	/* These two are so similar that they can */
    case  cc_recpt:	/* Be handled in the same clause	  */
	if ((*info)->type == recpt)
	{
	    result.type = m_recpt;
	    result.recipient = (*(*info)++).datum.recipient;
	}
	else
	{
	    result.type = m_cc_recpt;
	    result.cc_recipient = (*(*info)++).datum.cc_recipient;
	}
	
	/* There should follow a 'Local no', but check nevertheless */
	if (! NEXT_IS (loc_no))
	    { BARF }
	else
	    result.local_no = (*(*info)++).datum.local_no;

	if (NEXT_IS (rec_time))
	{
	    result.is_received = TRUE;
	    result.received_at = (*(*info)++).datum.received_at;
	}

	if (NEXT_IS (sent_by))
	{
	    result.sender = (*(*info)++).datum.sender;
	    /* There _should_ be a 'sent_at' here... */
	    if (! NEXT_IS (sent_at))
		{ BARF }
	    /* Let the following if clause insert the 'sent_at' data. */
	}
	if (NEXT_IS (sent_at))
	{
	    result.is_sent = TRUE;
	    result.sent_at = (*(*info)++).datum.sent_at;
	}

	break;


    case  comm_to:
	result.type = m_comm_to;
	result.comment_to = (*(*info)++).datum.comment_to;

	if (NEXT_IS (sent_by))
	{
	    result.sender = (*(*info)++).datum.sender;
	    /* There _should_ be a 'sent_at' here. */
	    if (! NEXT_IS (sent_at))
		{ BARF }
	    /* Let the following if clause insert the 'sent_at' data. */
	}
	if (NEXT_IS (sent_at))
	{
	    result.is_sent = TRUE;
	    result.sent_at = (*(*info)++).datum.sent_at;
	}

	break;


    case  footn_to:
	result.type = m_footn_to;
	result.footnote_to = (*(*info)++).datum.footnote_to;

	if (NEXT_IS (sent_at))
	{
	    result.is_sent = TRUE;
	    result.sent_at = (*(*info)++).datum.sent_at;
	}

	break;


    case  comm_in:
	result.type = m_comm_in;
	result.commented_in = (*(*info)++).datum.commented_in;
	break;


    case  footn_in:
	result.type = m_footn_in;
	result.footnoted_in = (*(*info)++).datum.footnoted_in;
	break;


#ifndef COMPILE_CHECKS
    default:
	result.type = m_error;
	break;
#endif
    }

    return  result;
}