📄 si_ops.c
字号:
/*
* Copyright (C) Ericsson Mobile Communications AB, 2000.
* Licensed to AU-System AB.
* All rights reserved.
*
* This software is covered by the license agreement between
* the end user and AU-System AB, and may be used and copied
* only in accordance with the terms of the said agreement.
*
* Neither Ericsson Mobile Communications AB nor AU-System AB
* assumes any responsibility or liability for any errors or inaccuracies in
* this software, or any consequential, incidental or indirect damage arising
* out of the use of the Generic WAP Client software.
*/
#include "si_ops.h"
#include "si_types.h"
#include "si_misc.h"
/*==========================================
OpS_New
============================================
---Purpose:
To create and initialise an operand stack.
---Params:
---Return:
pstructOpS the created OpS
NULL something went wrong
------------------------------------------------------------------------*/
pstructOpS OpS_New( VOID )
{
pstructOpS ops = NEWSTRUCT( structOpS );
if (ops != NULL) {
f_lh_newhead( &(ops->head) );
if (ops->head == NULL) {
DEALLOC( &ops );
}
}
return ops;
}
/*==========================================
OpS_NewFromOpS
============================================
---Purpose:
To create and initialise an operand stack. The created OpS is initialised by moving entries from
another OpS.
---Params:
src The OpS to move from
nbrToCopy how many entries from the top of the stack to be moved.
If -1 is passed in this argument all entries from src are moved.
---Return:
pstructOpS the created OpS
NULL something went wrong
------------------------------------------------------------------------*/
pstructOpS OpS_NewFromOpS( pstructOpS src, INT16 nbrToMove )
/* nbrToMove == -1 means the whole OpS */
/* NULL is returned if something went wrong (e.g. nbrToMove > topIndex of src) */
{
pstructOpS result = NULL;
t_link link;
UINT16 i;
if (src == NULL)
return NULL;
if (nbrToMove == -1)
nbrToMove = OpS_GetTopIndex(src);
if (nbrToMove > OpS_GetTopIndex(src)) /* can't move more than the src holds */
return NULL;
result = OpS_New();
if (result != NULL) {
i = 0;
while (i < nbrToMove) {
link = f_lh_last( src->head );
f_lh_out( &link );
f_lh_into_as_first( &link, &(result->head) );
/* the entries must be in the same order as in the src stack.
Therfore the entries are taken from the back and put in at the front.*/
i++;
}
}
return result;
}
/*==========================================
OpS_NewFromOpS
============================================
---Purpose:
To create and initialise an operand stack. The created OpS is initialised
by copying entries from another OpS.
---Params:
src The OpS to copy from
nbrToCopy how many entries from the top of the stack to be copied.
If -1 is passed in this argument all entries from src are copied.
---Return:
pstructOpS the created OpS
NULL something went wrong
------------------------------------------------------------------------*/
VOID OpS_Delete( pstructOpS *pThis )
{
t_link link;
pstructVar aVar;
if (*pThis != NULL) {
while ( ! f_lh_empty((*pThis)->head) ) {
link = f_lh_last((*pThis)->head);
aVar = (pstructVar) link->data;
Var_Delete( &aVar );
f_lh_disposelink( &link );
}
f_lh_disposehead( &((*pThis)->head) );
DEALLOC( pThis );
}
}
/*==========================================
OpS_Push
============================================
---Purpose:
To push a var on an OpS.
---Params:
thisx the OpS to operate on
pVar the var to be push.
The reference will afterwards be set to NULL to avoid
misuse of the reference.
---Return:
------------------------------------------------------------------------*/
VOID OpS_Push( pstructOpS thisx, pstructVar *pVar )
{
t_link newEl = NULL;
if ((thisx != NULL) && (*pVar != NULL)) {
f_lh_newlink( &newEl );
if (newEl != NULL) {
newEl->data = *pVar;
*pVar = NULL; /* so that the reference is not used by mistake somewhere else */
f_lh_into( &newEl, &(thisx->head) );
}
}
}
/*==========================================
OpS_Pop
============================================
---Purpose:
To pop a var from an OpS.
---Params:
thisx the OpS to operate on
---Return:
pstructVar the top stack element
NULL the stack is empty
------------------------------------------------------------------------*/
pstructVar OpS_Pop( pstructOpS thisx )
{
t_link link;
pstructVar res = NULL;
link = f_lh_last(thisx->head);
if (link != NULL) {
res = (pstructVar) link->data;
f_lh_disposelink( &link );
}
return res;
}
/*==========================================
OpS_GetTopIndex
============================================
---Purpose:
To get the index of the top element
(i.e. how many elements are in the stack).
Example: If one element is is the stack the topindex is 1.
If the stack is empty zero is returned.
---Params:
thisx the OpS to operate on
---Return:
UINT16 the index of the top stack element
------------------------------------------------------------------------*/
UINT16 OpS_GetTopIndex( pstructOpS thisx )
/* top index is 0 if the stack is empty */
{
UINT16 res = 0;
if (thisx != NULL) {
if (thisx->head != NULL) {
res = f_lh_cardinal( thisx->head );
}
}
return res;
}
/*==========================================
OpS_ClearUntilIndex
============================================
---Purpose:
To pop stack entries until there is <index> entries left in the stack.
(Needed for cleaning up the OpS after upon function return statement)
---Params:
thisx the OpS to operate on
index which index the top entry in the stack must have after
the operation is done
---Return:
TRUE the operation was successful
FALSE the operation failed (e.g. less than <index> entries in the stack)
------------------------------------------------------------------------*/
BOOL OpS_ClearUntilIndex( pstructOpS thisx, UINT16 index )
{
UINT16 topIndex = OpS_GetTopIndex(thisx);
UINT16 nbrOfElToPop;
UINT16 i;
pstructVar aVar;
if (index > topIndex) {
return FALSE;
}
else {
nbrOfElToPop = topIndex - index;
i=0;
while (i < nbrOfElToPop) {
aVar = OpS_Pop( thisx );
Var_Delete( &aVar );
i++;
}
return TRUE;
}
}
/*==========================================
OpS_NewFromArgString
============================================
---Purpose:
---Params:
---Return:
------------------------------------------------------------------------*/
/* the states needed to parse the argstring */
typedef enum {
argstate_start,
argstate_nextOrDone,
argstate_next,
argstate_invalid,
argstate_true,
argstate_false,
argstate_string,
argstate_number,
argstate_done,
argstate_error
} enumArgState;
/*------------------------------------------------------*/
pstructOpS OpS_NewFromArgString( WCHAR* argString )
/*
The argString must start with a '(' and then ends parsing when ')' is found
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -