Blender V2.61 - r43446
Defines | Functions | Variables

makesdna.c File Reference

Struct muncher for making SDNA. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "DNA_sdna_types.h"
#include "BLO_sys_types.h"
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
#include "DNA_ID.h"
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "DNA_text_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_camera_types.h"
#include "DNA_image_types.h"
#include "DNA_texture_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_vfont_types.h"
#include "DNA_meta_types.h"
#include "DNA_curve_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_lattice_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h"
#include "DNA_object_fluidsim.h"
#include "DNA_world_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "DNA_view2d_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_screen_types.h"
#include "DNA_fileglobal_types.h"
#include "DNA_sequence_types.h"
#include "DNA_effect_types.h"
#include "DNA_outliner_types.h"
#include "DNA_property_types.h"
#include "DNA_sensor_types.h"
#include "DNA_controller_types.h"
#include "DNA_actuator_types.h"
#include "DNA_sound_types.h"
#include "DNA_group_types.h"
#include "DNA_armature_types.h"
#include "DNA_action_types.h"
#include "DNA_constraint_types.h"
#include "DNA_nla_types.h"
#include "DNA_node_types.h"
#include "DNA_color_types.h"
#include "DNA_brush_types.h"
#include "DNA_customdata_types.h"
#include "DNA_particle_types.h"
#include "DNA_cloth_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_anim_types.h"
#include "DNA_boid_types.h"
#include "DNA_smoke_types.h"
#include "DNA_speaker_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "DNA_dynamicpaint_types.h"

Go to the source code of this file.

Defines

#define DNA_VERSION_DATE   "FIXME-DNA_VERSION_DATE"
#define SDNA_MAX_FILENAME_LENGTH   255
#define MAX_DNA_LINE_LENGTH   20
#define BASE_HEADER   "../"

Functions

static int add_type (const char *str, int len)
static int add_name (const char *str)
static short * add_struct (int namecode)
static int preprocess_include (char *maindata, int len)
static int convert_include (char *filename)
static int arraysize (char *astr, int len)
static int calculate_structlens (int)
void dna_write (FILE *file, void *pntr, int size)
void printStructLenghts (void)
static void * read_file_data (char *filename, int *len_r)
static int make_structDNA (char *baseDirectory, FILE *file)
static void make_bad_file (const char *file, int line)
int main (int argc, char **argv)

Variables

static const char * includefiles []
static int maxdata = 500000
static int maxnr = 50000
static int nr_names = 0
static int nr_types = 0
static int nr_structs = 0
static char ** names
static char * namedata
static char ** types
static char * typedata
static short * typelens
static short * alphalens
static short ** structs
static short * structdata
static int debugSDNA = 0
static int additional_slen_offset

Detailed Description

Struct muncher for making SDNA.

About makesdna tool

Originally by Ton, some mods by Frank, and some cleaning and extension by Nzc.

Makesdna creates a .c file with a long string of numbers that encode the Blender file format. It is fast, because it is basically a binary dump. There are some details to mind when reconstructing the file (endianness and byte-alignment).

This little program scans all structs that need to be serialized, and determined the names and types of all members. It calculates how much memory (on disk or in ram) is needed to store that struct, and the offsets for reaching a particular one.

There is a facility to get verbose output from sdna. Search for debugSDNA. This int can be set to 0 (no output) to some int. Higher numbers give more output.

Definition in file makesdna.c.


Define Documentation

#define BASE_HEADER   "../"

Definition at line 1112 of file makesdna.c.

Referenced by main().

#define DNA_VERSION_DATE   "FIXME-DNA_VERSION_DATE"

Definition at line 51 of file makesdna.c.

Referenced by make_structDNA().

#define MAX_DNA_LINE_LENGTH   20

Definition at line 857 of file makesdna.c.

Referenced by dna_write().

#define SDNA_MAX_FILENAME_LENGTH   255

Definition at line 62 of file makesdna.c.

Referenced by make_structDNA().


Function Documentation

static int add_name ( const char *  str) [static]

Add variable str to

Parameters:
strBecause of the weird way of tokenizing, we have to 'cast' function pointers to ... (*f)(), whatever the original signature. In fact, we add name and type at the same time... There are two special cases, unfortunately. These are explicitly checked.

Definition at line 273 of file makesdna.c.

References additional_slen_offset, debugSDNA, i, maxnr, namedata, names, nr_names, NULL, str, and strlen().

Referenced by convert_include().

static short * add_struct ( int  namecode) [static]

Search whether this structure type was already found, and if not, add it.

Definition at line 403 of file makesdna.c.

References len(), maxnr, nr_structs, structdata, and structs.

Referenced by convert_include().

static int add_type ( const char *  str,
int  len 
) [static]

Add type str to struct indexed by len, if it was not yet found.

Parameters:
strchar
lenint

Definition at line 227 of file makesdna.c.

References alphalens, len(), maxnr, nr_types, strlen(), typedata, typelens, and types.

Referenced by convert_include(), and make_structDNA().

static int arraysize ( char *  astr,
int  len 
) [static]

Determine how many bytes are needed for an array.

Definition at line 670 of file makesdna.c.

References len(), mul(), NULL, and str.

Referenced by calculate_structlens().

static int calculate_structlens ( int  firststruct) [static]

Determine how many bytes are needed for each struct.

Definition at line 692 of file makesdna.c.

References alphalens, arraysize(), debugSDNA, len(), mul(), names, nr_structs, strlen(), structs, typelens, and types.

Referenced by make_structDNA().

static int convert_include ( char *  filename) [static]

Scan this file for serializable types.

Definition at line 533 of file makesdna.c.

References add_name(), add_struct(), add_type(), additional_slen_offset, debugSDNA, MEM_freeN(), names, NULL, preprocess_include(), read_file_data(), strlen(), and types.

Referenced by make_structDNA().

void dna_write ( FILE *  file,
void *  pntr,
int  size 
)

Construct the DNA.c file

Definition at line 859 of file makesdna.c.

References data, i, MAX_DNA_LINE_LENGTH, and size().

Referenced by make_structDNA().

int main ( int  argc,
char **  argv 
)
static void make_bad_file ( const char *  file,
int  line 
) [static]

Definition at line 1104 of file makesdna.c.

Referenced by main().

static int make_structDNA ( char *  baseDirectory,
FILE *  file 
) [static]
static int preprocess_include ( char *  maindata,
int  len 
) [static]

Remove comments from this buffer. Assumes that the buffer refers to ascii-code text.

Definition at line 429 of file makesdna.c.

References len(), MEM_freeN(), and MEM_mallocN().

Referenced by convert_include().

void printStructLenghts ( void  )

Report all structures found so far, and print their lengths.

Definition at line 878 of file makesdna.c.

References nr_structs, structs, typelens, and types.

static void* read_file_data ( char *  filename,
int *  len_r 
) [static]

Definition at line 497 of file makesdna.c.

References data, L, MEM_freeN(), MEM_mallocN(), and NULL.

Referenced by convert_include().


Variable Documentation

int additional_slen_offset [static]

Definition at line 163 of file makesdna.c.

Referenced by add_name(), and convert_include().

short* alphalens [static]

Definition at line 149 of file makesdna.c.

Referenced by add_type(), calculate_structlens(), and make_structDNA().

int debugSDNA = 0 [static]

Variable to control debug output of makesdna. debugSDNA:

  • 0 = no output, except errors
  • 1 = detail actions
  • 2 = full trace, tell which names and types were found
  • 4 = full trace, plus all gritty details

Definition at line 162 of file makesdna.c.

Referenced by add_name(), calculate_structlens(), convert_include(), and make_structDNA().

const char* includefiles[] [static]

Definition at line 67 of file makesdna.c.

Referenced by make_structDNA().

int maxdata = 500000 [static]

Definition at line 142 of file makesdna.c.

Referenced by make_structDNA().

int maxnr = 50000

Definition at line 142 of file makesdna.c.

Referenced by add_name(), add_struct(), add_type(), and make_structDNA().

char * namedata

Definition at line 146 of file makesdna.c.

Referenced by add_name(), and make_structDNA().

char** names [static]
int nr_names = 0 [static]

Definition at line 143 of file makesdna.c.

Referenced by add_name(), init_structDNA(), and make_structDNA().

int nr_structs = 0 [static]
int nr_types = 0 [static]

Definition at line 144 of file makesdna.c.

Referenced by add_type(), init_structDNA(), and make_structDNA().

short * structdata

Definition at line 150 of file makesdna.c.

Referenced by add_struct(), and make_structDNA().

short** structs [static]

Definition at line 150 of file makesdna.c.

Referenced by add_struct(), calculate_structlens(), make_structDNA(), and printStructLenghts().

char * typedata

Definition at line 147 of file makesdna.c.

Referenced by add_type(), and make_structDNA().

short* typelens [static]

Definition at line 148 of file makesdna.c.

Referenced by add_type(), calculate_structlens(), make_structDNA(), and printStructLenghts().

char** types [static]