At 08.58 31/07/02 -0400, you wrote:

>I tried to make a new savetable in tablesave.c (btw I'M using Ivans OLC 2.0 
>on a Rom24b6 codebase), and tried changing save_skills so that if it 
>encounters a spell it will save it differently. Apparently my approach does 
>not work. The problem I come up with is this, when it tries to save the 
>minimum position, i get an error from my save_struct under case 
>FIELD_FUNCION_SHINT_TO_STR from the fprintf...
>
>#0  0x400aaab7 in vfprintf () from /lib/libc.so.6
>#1  0x400b32f3 in fprintf () from /lib/libc.so.6
>#2  0x080ab6a9 in save_struct (fp=0x8111c18, typebase=0x810a200, 
>tabla=0x80e756c, header=0x810adc8) at tablesave.c:540
>#3  0x080ac564 in save_skills () at tablesave.c:1047
>#4  0x080a8b1c in skedit (ch=0x4030c454, argument=0x4030ba01 "save") at 
>skedit.c:132
>
>-snip-
>                         case FIELD_FUNCION_SHINT_TO_STR:
>                                 function = temp->argument;
>                                 pshint = (sh_int *) ((int) 
>temp->header_field - (int) typebase + (int) header);
>                                 chain = (*function) ((void *) pshint);
>540>>                   fprintf( fp, "%s %s~\n", temp->field, chain );
>                                 break;
>-snip-
>(btw I translated some of the stuff from Spanish to English, i.e. 
>FIELD_FUNCION_SHINT_TO_STR was CAMPO_FUNCTION_SHINT_TO_STR)


You should check the string values to whom temp->field and chain are
pointing, to see
if they are valid values... gdb can tell you that.  If fprintf() is
crashing one of those
two is probably not a valid one.


>If anyone could explain to me what exactly is going on in this function 
>(save_struct, and the cases) I would be glad to give it another shot, but I 
>really don't understand what its trying to do here...


Well, I'm looking at the original snippet I just downloaded from Ivan's
site, so I can
try to translate it to your code...  'temp' is a pointer to a structure
that describes the
fields that needs to be saved from a skill_table's record type.  In the
original snippet,
'temp->argument' holds a pointer to a function whose purpose is to
translate the field's
value into a string format, for writing to disk...position_str() for the
only short int field
present.  'Pshint' is meant to be a pointer to the actual field value...  a
global variable
of type struct skill_type and named 'sk' is defined in the original, and
'temp->header_field'
(temp->puntero_campo in the original) holds the address in that var of the
same field that
is being saved now from the structure pointed by 'header'.  Since
'typebase' holds the
base address of 'sk', that expression equates to:

(address of the field in the sk template - base address of the sk template)
+ base address of the actual structure

And this gives 'pshint' the actual address of the field to be saved to
disk.  The mapping
function from 'temp->argument' is then called upon that pointer to
translate it into the
ascii name of the value and the subsequent fprintf() would then write
something like
"minimum_position sitting~\n" to disk.  At least this is how I understood
it....

Hope it helps ;)

-Luc


Reply via email to