summaryrefslogtreecommitdiff
path: root/cesar/lib/visual_state_api/src/SMPExpl.c
blob: b4b6c15aba60c0c8d8a4a781d461c7e254fa2ab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
/*
 * Type:        Source Code File
 * 
 * Id:          SMPExpl.c
 *
 * Function:    Contains the SMP_Expl SEM Library Expert version 4 function.
 *
 * Portability: ANSI-C Compiler.
 *
 * Copyright (c) 1999-2006 IAR Systems. All rights reserved.
 */

/*
 * Version   ! Date   ! Status ! Changes
 *----------------------------------------------------------------------------
 * 4.0.0.1   ! 101298 ! Closed ! -
 * 4.0.4     ! 010799 ! Closed ! Minor update, there might be no changes to this particular file.
 */

#include "SEMLibE.h"


unsigned char SMP_Expl (SEM_CONTEXT VS_TQ_CONTEXT *Context, unsigned char IdentType, 
  SEM_EXPLANATION_TYPE IdentNo, char *Text, unsigned short MaxSize)
{
  int c;
  unsigned long Pos;
  unsigned short i;
  char VS_TQ_RULEBASE * pT = NULL; /* initialization may be necessary to avoid compiler warnings */

  if (!Context)
    return (SES_NOT_LOADED);
  if (!MaxSize)
    return (SES_TEXT_TOO_LONG);
  switch (IdentType)
  {
    case EVENT_TYPE :
      if (!Context->pEEIPos)
        return (SES_TYPE_ERR);
      if (Context->nNofEvents <= (SEM_EVENT_TYPE)IdentNo)
        return (SES_RANGE_ERR);
      Pos = Context->pEEIPos[IdentNo];
      break;
    case STATE_TYPE :
      if (!Context->pSEIPos)
        return (SES_TYPE_ERR);
      if (Context->nNofStates <= (SEM_STATE_TYPE)IdentNo)
        return (SES_RANGE_ERR);
      Pos = Context->pSEIPos[IdentNo];
      break;
    case ACTION_TYPE :
      if (!Context->pAEIPos)
        return (SES_TYPE_ERR);
      if (Context->nNofActionFunctions <= (SEM_ACTION_FUNCTION_TYPE)IdentNo)
        return (SES_RANGE_ERR);
      Pos = Context->pAEIPos[IdentNo];
      break;
    default :
      return (SES_TYPE_ERR);
  }
  if (Context->pVSFile)
  {
#ifndef SE_EXPERTDLL
    return (SES_NOT_LOADED);
#else
    if (fseek (Context->pVSFile, (long)Pos, SEEK_SET))
      return (SES_FILE_ERR);
#endif
  }
  else
    pT = (char VS_TQ_RULEBASE *)((char VS_TQ_RULEBASE *)Context->pVSData + Pos);

  for (i = 0; i < MaxSize; i++)
  {
#ifdef SE_EXPERTDLL
    if (Context->pVSFile)
    {
      c = fgetc (Context->pVSFile);
      if (c == EOF)
        return (SES_FILE_ERR);
    }
    else
#endif
      c = *pT++;
    *Text++ = (char)c;
    if (c == '\0')
      return (SES_OKAY);
  }
  Text--;
  *Text = '\0';
  return (SES_TEXT_TOO_LONG);
}