Atrinik Server 2.5
Data Structures | Defines | Typedefs | Functions | Variables
loaders/object.c File Reference
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <global.h>
#include <loader.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  yy_buffer_state
struct  yy_trans_info

Defines

#define YY_INT_ALIGNED   short int
#define yy_create_buffer   yy_object_create_buffer
#define yy_delete_buffer   yy_object_delete_buffer
#define yy_flex_debug   yy_object_flex_debug
#define yy_init_buffer   yy_object_init_buffer
#define yy_flush_buffer   yy_object_flush_buffer
#define yy_load_buffer_state   yy_object_load_buffer_state
#define yy_switch_to_buffer   yy_object_switch_to_buffer
#define yyin   yy_objectin
#define yyleng   yy_objectleng
#define yylex   yy_objectlex
#define yylineno   yy_objectlineno
#define yyout   yy_objectout
#define yyrestart   yy_objectrestart
#define yytext   yy_objecttext
#define yywrap   yy_objectwrap
#define yyalloc   yy_objectalloc
#define yyrealloc   yy_objectrealloc
#define yyfree   yy_objectfree
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION   2
#define YY_FLEX_MINOR_VERSION   5
#define YY_FLEX_SUBMINOR_VERSION   35
#define FLEX_BETA
#define FLEXINT_H
#define INT8_MIN   (-128)
#define INT16_MIN   (-32767-1)
#define INT32_MIN   (-2147483647-1)
#define INT8_MAX   (127)
#define INT16_MAX   (32767)
#define INT32_MAX   (2147483647)
#define UINT8_MAX   (255U)
#define UINT16_MAX   (65535U)
#define UINT32_MAX   (4294967295U)
#define yyconst
#define YY_NULL   0
#define YY_SC_TO_UI(c)   ((unsigned int) (unsigned char) c)
#define BEGIN   (yy_start) = 1 + 2 *
#define YY_START   (((yy_start) - 1) / 2)
#define YYSTATE   YY_START
#define YY_STATE_EOF(state)   (YY_END_OF_BUFFER + state + 1)
#define YY_NEW_FILE   yy_objectrestart(yy_objectin )
#define YY_END_OF_BUFFER_CHAR   0
#define YY_BUF_SIZE   16384
#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
#define YY_TYPEDEF_YY_BUFFER_STATE
#define EOB_ACT_CONTINUE_SCAN   0
#define EOB_ACT_END_OF_FILE   1
#define EOB_ACT_LAST_MATCH   2
#define YY_LESS_LINENO(n)
#define yyless(n)
#define unput(c)   yyunput( c, (yytext_ptr) )
#define YY_TYPEDEF_YY_SIZE_T
#define YY_STRUCT_YY_BUFFER_STATE
#define YY_BUFFER_NEW   0
#define YY_BUFFER_NORMAL   1
#define YY_BUFFER_EOF_PENDING   2
#define YY_CURRENT_BUFFER
#define YY_CURRENT_BUFFER_LVALUE   (yy_buffer_stack)[(yy_buffer_stack_top)]
#define YY_FLUSH_BUFFER   yy_object_flush_buffer(YY_CURRENT_BUFFER )
#define yy_new_buffer   yy_object_create_buffer
#define yy_set_interactive(is_interactive)
#define yy_set_bol(at_bol)
#define YY_AT_BOL()   (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
#define yy_objectwrap(n)   1
#define YY_SKIP_YYWRAP
#define yytext_ptr   yy_objecttext
#define YY_DO_BEFORE_ACTION
#define YY_NUM_RULES   329
#define YY_END_OF_BUFFER   330
#define REJECT   reject_used_but_not_detected
#define yymore()   yymore_used_but_not_detected
#define YY_MORE_ADJ   0
#define YY_RESTORE_YY_MORE_OFFSET
#define YY_DECL   int lex_load(int *depth, object **items, int maxdepth, int map_flags, int linemode)
#define MAXDEPTH   10
#define SET_OR_CLEAR_FLAG(op, flag, val)
#define SET_ATTACK(op, type, val)   op->attack[type] = val;
#define SET_PROTECTION(op, type, val)   op->protection[type] = val;
#define IVAL   atoi(yval())
#define FVAL   (float) atof(yval())
#define YY_NO_INPUT
#define INITIAL   0
#define MESSAGE   1
#define YY_EXTRA_TYPE   void *
#define YY_READ_BUF_SIZE   8192
#define ECHO   do { if (fwrite( yy_objecttext, yy_objectleng, 1, yy_objectout )) {} } while (0)
#define YY_INPUT(buf, result, max_size)
#define yyterminate()   return YY_NULL
#define YY_START_STACK_INCR   25
#define YY_FATAL_ERROR(msg)   yy_fatal_error( msg )
#define YY_USER_ACTION
#define YY_BREAK   break;
#define YY_RULE_SETUP
#define YY_EXIT_FAILURE   2
#define yyless(n)
#define YYTABLES_NAME   "yytables"
#define ADD_STRINGLINE_ENTRY(sb__, entryname__, entryvalue__)
#define FAST_SAVE_LONG(sb__, entryname__, entryvalue__)   stringbuffer_append_printf(sb__, "%s%ld\n", entryname__, (long int) entryvalue__)
#define FAST_SAVE_DOUBLE(sb__, entryname__, entryvalue__)   stringbuffer_append_printf(sb__, "%s%f\n", entryname__, entryvalue__)

Typedefs

typedef signed char flex_int8_t
typedef short int flex_int16_t
typedef int flex_int32_t
typedef unsigned char flex_uint8_t
typedef unsigned short int flex_uint16_t
typedef unsigned int flex_uint32_t
typedef struct yy_buffer_stateYY_BUFFER_STATE
typedef size_t yy_size_t
typedef unsigned char YY_CHAR
typedef int yy_state_type

Functions

void yy_objectrestart (FILE *input_file)
void yy_object_switch_to_buffer (YY_BUFFER_STATE new_buffer)
YY_BUFFER_STATE yy_object_create_buffer (FILE *file, int size)
void yy_object_delete_buffer (YY_BUFFER_STATE b)
void yy_object_flush_buffer (YY_BUFFER_STATE b)
void yy_objectpush_buffer_state (YY_BUFFER_STATE new_buffer)
void yy_objectpop_buffer_state (void)
static void yy_objectensure_buffer_stack (void)
static void yy_object_load_buffer_state (void)
static void yy_object_init_buffer (YY_BUFFER_STATE b, FILE *file)
YY_BUFFER_STATE yy_object_scan_buffer (char *base, yy_size_t size)
YY_BUFFER_STATE yy_object_scan_string (yyconst char *yy_str)
YY_BUFFER_STATE yy_object_scan_bytes (yyconst char *bytes, int len)
void * yy_objectalloc (yy_size_t)
void * yy_objectrealloc (void *, yy_size_t)
void yy_objectfree (void *)
static yy_state_type yy_get_previous_state (void)
static yy_state_type yy_try_NUL_trans (yy_state_type current_state)
static int yy_get_next_buffer (void)
static void yy_fatal_error (yyconst char msg[])
static char * yval ()
static void add_key_value (object *op)
static void set_random_protection (object *op, int val)
static void set_random_attack (object *op, int val)
static int yy_init_globals (void)
int yy_objectlex_destroy (void)
int yy_objectget_debug (void)
void yy_objectset_debug (int debug_flag)
YY_EXTRA_TYPE yy_objectget_extra (void)
void yy_objectset_extra (YY_EXTRA_TYPE user_defined)
FILE * yy_objectget_in (void)
void yy_objectset_in (FILE *in_str)
FILE * yy_objectget_out (void)
void yy_objectset_out (FILE *out_str)
int yy_objectget_leng (void)
char * yy_objectget_text (void)
int yy_objectget_lineno (void)
void yy_objectset_lineno (int line_number)
static void yy_push_state (int new_state)
static void yy_pop_state (void)
static void yy_fatal_error (yyconst char *msg)
int yyerror (char *s)
void delete_loader_buffer (void *buffer)
void * create_loader_buffer (void *fp)
int load_object (void *fp, object *op, void *mybuffer, int bufstate, int map_flags)
int set_variable (object *op, char *buf)
void get_ob_diff (StringBuffer *sb, object *op, object *op2)
void save_object (FILE *fp, object *op, int flag)

Variables

int yy_objectleng
FILE * yy_objectin = (FILE *) 0
FILE * yy_objectout = (FILE *) 0
static size_t yy_buffer_stack_top = 0
static size_t yy_buffer_stack_max = 0
static YY_BUFFER_STATEyy_buffer_stack = 0
static char yy_hold_char
static int yy_n_chars
static char * yy_c_buf_p = (char *) 0
static int yy_init = 0
static int yy_start = 0
static int yy_did_buffer_switch_on_eof
int yy_objectlineno = 1
char * yy_objecttext
static yyconst flex_int16_t yy_accept [2916]
static yyconst flex_int32_t yy_ec [256]
static yyconst flex_int32_t yy_meta [63]
static yyconst flex_int16_t yy_base [3485]
static yyconst flex_int16_t yy_def [3485]
static yyconst flex_int16_t yy_nxt [5469]
static yyconst flex_int16_t yy_chk [5469]
static yy_state_type yy_last_accepting_state
static char * yy_last_accepting_cpos
int yy_object_flex_debug = 0
static void * cur_buffer
static int object_load_flag
static int lex_error
static char msgbuf [HUGE_BUF *4]
static size_t msgbuf_len
static artifactart_amask
static int yy_start_stack_ptr = 0
static int yy_start_stack_depth = 0
static int * yy_start_stack = NULL

Detailed Description

C file generated by GNU Flex from loader.l, it handles object loading related code.

Definition in file object.c.


Define Documentation

#define ADD_STRINGLINE_ENTRY (   sb__,
  entryname__,
  entryvalue__ 
)
Value:
do {\
    stringbuffer_append_string(sb__, entryname__);\
    stringbuffer_append_string(sb__, entryvalue__);\
    stringbuffer_append_string(sb__, "\n");\
    } while (0)

Adds a line to the buffer.

Definition at line 6534 of file object.c.

#define FAST_SAVE_DOUBLE (   sb__,
  entryname__,
  entryvalue__ 
)    stringbuffer_append_printf(sb__, "%s%f\n", entryname__, entryvalue__)

Adds a double to the buffer. entryname__ must have a space at the end.

Definition at line 6543 of file object.c.

#define FAST_SAVE_LONG (   sb__,
  entryname__,
  entryvalue__ 
)    stringbuffer_append_printf(sb__, "%s%ld\n", entryname__, (long int) entryvalue__)

Adds a long to the buffer. entryname__ must have a space at the end.

Definition at line 6540 of file object.c.

#define FVAL   (float) atof(yval())

Next value as float.

Definition at line 2842 of file object.c.

#define IVAL   atoi(yval())

Next value as integer.

Definition at line 2840 of file object.c.

#define SET_OR_CLEAR_FLAG (   op,
  flag,
  val 
)
Value:
{                                           \
    if (val)                                \
    {                                       \
        SET_FLAG(op, flag);                 \
    }                                       \
    else                                    \
    {                                       \
        CLEAR_FLAG(op, flag);               \
    }                                       \
}

Utility macro to set or clear an object's flag depending whether the value parameter is 1 or 0.

Parameters:
opObject to set or clear the flag for
flagThe flag we're setting
valNon-zero to set the flag, zero to clear the flag.

Definition at line 2824 of file object.c.

#define YY_CURRENT_BUFFER
Value:

Definition at line 291 of file object.c.

#define YY_DO_BEFORE_ACTION
Value:
(yytext_ptr) = yy_bp; \
    yy_objectleng = (size_t) (yy_cp - yy_bp); \
    (yy_hold_char) = *yy_cp; \
    *yy_cp = '\0'; \
    (yy_c_buf_p) = yy_cp;

Definition at line 387 of file object.c.

#define YY_INPUT (   buf,
  result,
  max_size 
)
Value:
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
        { \
        int c = '*'; \
        size_t n; \
        for ( n = 0; n < max_size && \
                 (c = getc( yy_objectin )) != EOF && c != '\n'; ++n ) \
            buf[n] = (char) c; \
        if ( c == '\n' ) \
            buf[n++] = (char) c; \
        if ( c == EOF && ferror( yy_objectin ) ) \
            YY_FATAL_ERROR( "input in flex scanner failed" ); \
        result = n; \
        } \
    else \
        { \
        errno=0; \
        while ( (result = fread(buf, 1, max_size, yy_objectin))==0 && ferror(yy_objectin)) \
            { \
            if( errno != EINTR) \
                { \
                YY_FATAL_ERROR( "input in flex scanner failed" ); \
                break; \
                } \
            errno=0; \
            clearerr(yy_objectin); \
            } \
        }\
\

Definition at line 3044 of file object.c.

#define YY_RULE_SETUP
Value:
if ( yy_objectleng > 0 ) \
        YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
                (yy_objecttext[yy_objectleng - 1] == '\n'); \
    YY_USER_ACTION

Definition at line 3119 of file object.c.

#define yy_set_bol (   at_bol)
Value:
{ \
    if ( ! YY_CURRENT_BUFFER ){\
        yy_objectensure_buffer_stack (); \
        YY_CURRENT_BUFFER_LVALUE =    \
            yy_object_create_buffer(yy_objectin,YY_BUF_SIZE ); \
    } \
    YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
    }

Definition at line 349 of file object.c.

#define yy_set_interactive (   is_interactive)
Value:
{ \
    if ( ! YY_CURRENT_BUFFER ){ \
        yy_objectensure_buffer_stack (); \
        YY_CURRENT_BUFFER_LVALUE =    \
            yy_object_create_buffer(yy_objectin,YY_BUF_SIZE ); \
    } \
    YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
    }

Definition at line 339 of file object.c.

#define yyless (   n)
Value:
do \
        { \
        /* Undo effects of setting up yy_objecttext. */ \
        int yyless_macro_arg = (n); \
        YY_LESS_LINENO(yyless_macro_arg);\
        yy_objecttext[yy_objectleng] = (yy_hold_char); \
        (yy_c_buf_p) = yy_objecttext + yyless_macro_arg; \
        (yy_hold_char) = *(yy_c_buf_p); \
        *(yy_c_buf_p) = '\0'; \
        yy_objectleng = yyless_macro_arg; \
        } \
    while ( 0 )

Definition at line 6031 of file object.c.

#define yyless (   n)
Value:
do \
        { \
        /* Undo effects of setting up yy_objecttext. */ \
        int yyless_macro_arg = (n); \
        YY_LESS_LINENO(yyless_macro_arg);\
        *yy_cp = (yy_hold_char); \
        YY_RESTORE_YY_MORE_OFFSET \
        (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
        YY_DO_BEFORE_ACTION; /* set up yy_objecttext again */ \
        } \
    while ( 0 )

Definition at line 6031 of file object.c.


Function Documentation

static void add_key_value ( object op) [static]

This extracts the key/value from the yy_objecttext field - calls object_set_value() to actually set the value.

Function basically has to find spaces, strip out extra, etc. strchr() doesn't work as good because could also be tabs.

Parameters:
opObject in which to insert the value.

Definition at line 2853 of file object.c.

void get_ob_diff ( StringBuffer sb,
object op,
object op2 
)

Get difference between two objects, and save it in StringBuffer.

This function is typically used to dump objects (op2 = empty object), or to save objects (op2 is the objects original archetype).

Parameters:
sbString buffer to modify.
opWhat object the different values will be taken from.
op2Object's original archetype.

Definition at line 6554 of file object.c.

int load_object ( void *  fp,
object op,
void *  mybuffer,
int  bufstate,
int  map_flags 
)

Loads an object from the given file-pointer.

Variables will be read, parsed and patched into the object until the string "end" is reached, or the end of the file.

Parameters:
fpFile pointer from which to read.
opWhere to read the data.
bufstateUsed to determine various file attributes:
  • LO_REPEAT (0): We are reading from the same buffer as the last call.
  • LO_LINEMODE (1): File that is being read from is multi purpose (ie, other functions will also be reading from this (treasures file, artifacts.)
  • LO_NEWFILE (2): Disabled.
  • LO_NOREAD (3): Disabled.
  • LO_MEMORYMODE (4): Read from a memory buffer instead of a file.

Definition at line 6329 of file object.c.

void save_object ( FILE *  fp,
object op,
int  flag 
)

Dumps all variables in an object to a file.

If bit 0 of flag is set, unpaid objects will be saved. As of now, the only place this is not set is when saving the player.

If bit 1 of flag is set, don't remove the object after save. As of now, all of the callers are setting this.

Definition at line 7047 of file object.c.

int set_variable ( object op,
char *  buf 
)

This takes a buffer, scans it for variables, and sets those variables as appropriate in op.

This function appears to be used only in c_wiz::c to mutate values.

Parameters:
opObject to alter.
bufModifications to apply.

Definition at line 6509 of file object.c.

static char * yval ( ) [static]

Returns the next token for lex.

Our save file syntax is very simple, so we can use a very simple processing mechanism here instead using something like bison.

This skips over the space and returns the value, or "" if no value is found.

Definition at line 6253 of file object.c.

void yy_object_flush_buffer ( YY_BUFFER_STATE  b)

Discard all buffered characters. On the next scan, YY_INPUT will be called.

Parameters:
bthe buffer state to be flushed, usually YY_CURRENT_BUFFER.

Definition at line 5779 of file object.c.

static void yy_object_init_buffer ( YY_BUFFER_STATE  b,
FILE *  file 
) [static]

The main scanner function which does all the work.

Definition at line 5751 of file object.c.

YY_BUFFER_STATE yy_object_scan_buffer ( char *  base,
yy_size_t  size 
)

Setup the input buffer state to scan directly from a user-specified character buffer.

Parameters:
basethe character buffer
sizethe size in bytes of the character buffer
Returns:
the newly allocated buffer state object.

Definition at line 5906 of file object.c.

YY_BUFFER_STATE yy_object_scan_bytes ( yyconst char *  yybytes,
int  _yybytes_len 
)

Setup the input buffer state to scan the given bytes. The next call to yy_objectlex() will scan from a copy of bytes.

Parameters:
yybytesthe byte buffer to scan
_yybytes_lenthe number of bytes in the buffer pointed to by bytes.
Returns:
the newly allocated buffer state object.

Definition at line 5956 of file object.c.

YY_BUFFER_STATE yy_object_scan_string ( yyconst char *  yystr)

Setup the input buffer state to scan a string. The next call to yy_objectlex() will scan from a copy of str.

Parameters:
yystra NUL-terminated string to scan
Returns:
the newly allocated buffer state object.
Note:
If you want to scan bytes that may contain NUL values, then use yy_object_scan_bytes() instead.

Definition at line 5943 of file object.c.

FILE* yy_objectget_in ( void  )

Get the input stream.

Definition at line 6059 of file object.c.

int yy_objectget_leng ( void  )

Get the length of the current token.

Definition at line 6075 of file object.c.

int yy_objectget_lineno ( void  )

Get the current line number.

Definition at line 6050 of file object.c.

FILE* yy_objectget_out ( void  )

Get the output stream.

Definition at line 6067 of file object.c.

char* yy_objectget_text ( void  )

Get the current token.

Definition at line 6084 of file object.c.

void yy_objectpop_buffer_state ( void  )

Removes and deletes the top of the stack, if present. The next element becomes the new top.

Definition at line 5838 of file object.c.

void yy_objectpush_buffer_state ( YY_BUFFER_STATE  new_buffer)

Pushes the new state onto the stack. The new state becomes the current state. This function will allocate the stack if necessary.

Parameters:
new_bufferThe new state.

Definition at line 5808 of file object.c.

void yy_objectset_in ( FILE *  in_str)

Set the input stream. This does not discard the current input buffer.

Parameters:
in_strA readable stream.
See also:
yy_object_switch_to_buffer

Definition at line 6105 of file object.c.

void yy_objectset_lineno ( int  line_number)

Set the current line number.

Parameters:
line_number

Definition at line 6093 of file object.c.

int yyerror ( char *  s)

Used to report an error when parsing object data.

Parameters:
sThe error to report.
Returns:
Always returns -1.

Definition at line 6239 of file object.c.


Variable Documentation

Stack as an array.

Definition at line 283 of file object.c.

size_t yy_buffer_stack_max = 0 [static]

capacity of stack.

Definition at line 282 of file object.c.

size_t yy_buffer_stack_top = 0 [static]

index of top of stack.

Definition at line 281 of file object.c.

yyconst flex_int32_t yy_meta[63] [static]
Initial value:
    {   0,
        1,    1,    2,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1
    }

Definition at line 760 of file object.c.