Index: README =================================================================== --- README (.../vendor/blender/working/current/blender) (revision 79) +++ README (.../blender/working/branches/bcp/blender) (revision 79) @@ -24,7 +24,7 @@ -------------------------------------Links-------------------------------------- Getting Involved: -http://www.blender.org/docs/get_involved.html +http://www.blender.org/community/get-involved/ Community: http://www.blender3d.org/Community/ Index: source/creator/creator.c =================================================================== --- source/creator/creator.c (.../vendor/blender/working/current/blender) (revision 79) +++ source/creator/creator.c (.../blender/working/branches/bcp/blender) (revision 79) @@ -25,8 +25,14 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): * + * - Dietrich Bollmann (dietrich), 2007/06/21: + * - commandport initialization code, + * - debug option (--debug, UTL_debug), + * - functions to simplify use of command line options (UTL_parse_options), + * - geometry option (--geometry, UTL_parse_options_geometry). + * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ #include @@ -81,11 +87,19 @@ #include "RE_pipeline.h" +#include "UTL_debug.h" +#include "UTL_parse_options.h" +#include "UTL_parse_options_geometry.h" + #include "playanim_ext.h" #include "mydevice.h" #include "nla.h" #include "datatoc.h" +#ifdef WITH_COMMAND_PORT +#include "commandport.h" /* the Blender command port (dietrich) */ +#endif + /* for passing information between creator and gameengine */ #include "SYS_System.h" @@ -107,8 +121,15 @@ /* Local Function prototypes */ static void print_help(); +static void print_help_debug(); /* (dietrich) */ static void print_version(); +/* handle command port option (dietrich) */ +#ifdef WITH_COMMAND_PORT +void handle_commandport_option_delete(int *argc, char **argv); +#endif +void handle_debug_option_delete(int *argc, char **argv); +void handle_geometry_option_delete(int *argc, char **argv); /* defined in ghostwinlay and winlay, we can't include carbon here, conflict with DNA */ #ifdef __APPLE__ @@ -199,6 +220,9 @@ printf (" -W\t\tForce opening without borders\n"); printf (" -p \tOpen with lower left corner at , \n"); printf (" \tand width and height , \n"); + printf (" --geometry {xX}][{+-}{+-}\n"); /* (dietrich) */ + printf (" \t--geometry can be used alternatively to the -p option\n"); + printf (" \tto specify size and position of the Blender window.\n"); printf ("\nGame Engine specific options:\n"); printf (" -g fixedtime\t\tRun on 50 hertz without dropping frames\n"); printf (" -g vertexarrays\tUse Vertex Arrays for rendering (usually faster)\n"); @@ -207,7 +231,22 @@ printf (" -g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)\n"); printf ("\nMisc options:\n"); - printf (" -d\t\tTurn debugging on\n"); + printf (" -d | --debug [:],[:],...\n"); /* (dietrich) */ + printf (" \t\tTurn debugging on for module .\n"); + printf (" \t\tSet the debug level if is given.\n"); + printf (" \t\tTo see which debug options can be used, try -hd or --help=debug.\n"); +#ifdef WITH_COMMAND_PORT + printf (" \t\tExample:\n"); + printf (" \t\t blender --debug debug,bcp:2,opt ...\n"); + printf (" \t\tDebug the debug option itself,\n"); + printf (" \t\tthe command port at verbosity level 2 (`bcp:2')\n"); + printf (" \t\tand some command line options (`opt').\n"); +#else + printf (" \t\tExample:\n"); + printf (" \t\t blender --debug debug,opt ...\n"); + printf (" \t\tDebug the debug option itself\n"); + printf (" \t\tand some command line options (`opt').\n"); +#endif printf (" -noaudio\tDisable audio on systems that support audio\n"); printf (" -h\t\tPrint this help text\n"); printf (" -y\t\tDisable script links, use -Y to find out why its -y\n"); @@ -215,23 +254,101 @@ #ifdef WIN32 printf (" -R\t\tRegister .blend extension\n"); #endif +#ifdef WITH_COMMAND_PORT + printf (" -c | --bcp \tStart the Blender Command Port\n" + " \t\tusing port \n"); /* (dietrich) */ +#endif printf (" -v\t\tPrint Blender version and exit\n"); } +/** + help message for debugging mode + + (dietrich) +*/ +static void print_help_debug() +{ + printf("\n" + "* Blender Debug Modes\n" + "\n" + " Usage:\n" + "\n" + " blender --debug | -d [:],[:],... [more options]\n" + "\n" + " Turn on debugging for module ;\n" + " if is given, set debug level for module to \n" + "\n" + " Possible Arguments:\n" + "\n" + " debug -- debug the -d | --debug option itself.\n" + " opt -- debug some command line options.\n" +#ifdef WITH_COMMAND_PORT + " bcp -- debug the command port.\n" + "\n" + " This option has to be used together with `--bcp '.\n" + " The following debug verbosity levels are available\n" + " for debugging the command port:\n" + "\n" + " bcp:1 -- print general command port debug messages.\n" + " bcp:2 -- print more detailed information about\n" + " the evaluation of received commands,\n" + " the command packages received from a Blender client and\n" + " the result packages sent back to the client\n" + " after evaluating the commands.\n" + " bcp:3 -- hexdump the received packages before processing them.\n" + " bcp:4 -- hexdump the received packages without processing them.\n" +#endif + "\n" + ); +} + + double PIL_check_seconds_timer(void); extern void winlay_get_screensize(int *width_r, int *height_r); int main(int argc, char **argv) { - int a, i, stax, stay, sizx, sizy; + int a, stax, stay, sizx, sizy, i; SYS_SystemHandle syshandle; Scene *sce; + int audio; + /* Handle unix and windows style help requests */ + if (option_is_defined_delete(&argc, argv, "-h", "--help") || + option_is_defined_delete(&argc, argv, "/?", "/help" ) + ) { + print_help(); + exit(0); + } + + /* Handle unix and windows style help requests */ + if (option_is_defined_delete(&argc, argv, "-hd", "--help=debug")) { + print_help_debug(); + exit(0); + } + + /* Handle version request */ + if (option_is_defined_delete(&argc, argv, "-v", "--version")) { + print_version(); + exit(0); + } + + /* Handle debug mode requests */ + handle_debug_option_delete(&argc, argv); + + /* Handle geometry option */ + handle_geometry_option_delete(&argc, argv); + +#ifdef WITH_COMMAND_PORT + /* Handle Blender command port option (dietrich) */ + handle_commandport_option_delete(&argc, argv); +#endif + #if defined(WIN32) || defined (__linux__) - int audio = 1; + audio = 1; #else - int audio = 0; + audio = 0; #endif setCallbacks(); @@ -308,20 +425,9 @@ for(a=1; a, position: <%d, %d>.\n", + sizx, sizy, stax, stay); + } + setprefsize(stax, stay, sizx, sizy, 0); break; case 'd': @@ -444,6 +550,11 @@ if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio); } break; + default: + printf("\nError: Undefined option: %s\n", argv[a]); /* (dietrich) */ + printf("Try %s --help for usage information.\n\n", argv[0]); + exit(2); + break; } } } @@ -459,7 +570,7 @@ BIF_init(); } - else { + else { /* G.background != 0 */ BPY_start_python(argc, argv); // (ton) Commented out. I have no idea whats thisfor... will mail around! @@ -671,6 +782,13 @@ printf("\nError: you must specify a path after '- '.\n"); } break; + + default: + printf("\nError: Undefined option: %s\n", argv[a]); /* (dietrich) */ + printf("Try %s --help for usage information.\n\n", argv[0]); + exit(2); + break; + } } else { @@ -691,6 +809,10 @@ set_scene(sce); } + /* flush stdout and stderr */ + fflush(stdout); + fflush(stderr); + screenmain(); return 0; @@ -718,3 +840,141 @@ BLI_setInterruptCallBack(blender_test_break); } + +/** + Init debug mode. + + Parse argv for debug options + -d or + -d : or + --debug or + --debug : + process them + and delete them from argv / argc. + + (dietrich) +*/ +void handle_debug_option_delete(int *argc, char **argv) +{ + char* debug_options; + int i; + + /* init debug mode */ + debug_options = get_string_option_delete_allocate(argc, argv, "-d", "--debug"); + + if (debug_options != (char*) NULL) { + + G.f |= G_DEBUG; /* std output printf's */ + + /* print version */ + printf ("Blender V %d.%02d\n", G.version/100, G.version%100); +#ifdef NAN_BUILDINFO + printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type); +#endif // NAN_BUILDINFO + + MEM_set_memory_debug(); + + for (i = 0; i < *argc; i++) { + printf("argv[%d] = %s\n", i, argv[i]); + } + + /* init the debug mode */ + init_debug_mode(debug_options); + + /* free memory */ + free(debug_options); + } +} + +/** + Handle the geometry option. + + Parse argv for command port options + -G {xX}][{+-}{+-} or + --geometry {xX}][{+-}{+-} + delete them from argv / argc and set the Geometry of the Blender window + to the given values. + + The values for size and position passed into the function + are only changed if the respective values have been specified. + + (dietrich) +*/ +void handle_geometry_option_delete(int *argc, char **argv) +{ + char* geometry; + int sizex, sizey, x, y; + int debug_level; + debug_level = debug("opt"); /* use blender --debug opt ... for debugging */ + + /* set defaults */ + + /* window default position = lower left corner */ + x = y = 0; + + /* window default size = maximal size */ + winlay_get_screensize(&sizex, &sizey); + + /* get the geometry value string */ + geometry = get_string_option_delete_allocate(argc, argv, "-G", "--geometry"); + + if (geometry != (char*) NULL) { + + /* parse the value string, + overwrite default values with parsed values and + set geometry + */ + if (parse_geometry(geometry, &sizex, &sizey, &x, &y)) { + + if (debug_level) { + printf("[DEBUG opt] Setting window geometry - " + "size <%d, %d>, position: <%d, %d>.\n", + sizex, sizey, x, y); + } + + setprefsize(x, y, sizex, sizey, 0); + + } else { + + /* the geometry string is ill-formed - + print an error message and exit + */ + printf("\nError: Ill-formed geometry value: %s\n", geometry); + printf("\n"); + printf(" try something like:\n"); + printf(" --geometry 800x600\n"); + printf(" --geometry +10+20\n"); + printf(" --geometry 800x600+10+20\n"); + printf("\n"); + exit(2); + } + } +} + +#ifdef WITH_COMMAND_PORT +/** + Handle command port options. + + Parse argv for command port options + -c or + --bcp + and delete them from argv / argc. + If the options have been given, init the command port. + + (dietrich) +*/ +void handle_commandport_option_delete(int *argc, char **argv) +{ + /* get the port number */ + unsigned short port; + port = (unsigned short) get_int_option_delete(argc, argv, "-c", "--bcp"); + + /* do nothing if the bcp option hasn't been found */ + if (port == 0) return; + + /* init the command port */ + commandport_init(port); +} +#endif + +/* fin */ Index: source/creator/SConscript =================================================================== --- source/creator/SConscript (.../vendor/blender/working/current/blender) (revision 79) +++ source/creator/SConscript (.../blender/working/branches/bcp/blender) (revision 79) @@ -15,4 +15,8 @@ incs += ' ' + env['BF_QUICKTIME_INC'] defs.append('WITH_QUICKTIME') +# command port (dietrich) +if env['WITH_COMMAND_PORT'] == 1: + incs += ' ../blender/commandport/include' + env.BlenderLib ( libname = 'blender_creator', sources = Split(sources), includes = Split(incs), defines = defs, libtype='core', priority = 1 ) Index: source/blender/blenkernel/intern/parse_options_geometry.c =================================================================== --- source/blender/blenkernel/intern/parse_options_geometry.c (.../vendor/blender/working/current/blender) (revision 0) +++ source/blender/blenkernel/intern/parse_options_geometry.c (.../blender/working/branches/bcp/blender) (revision 79) @@ -0,0 +1,290 @@ +/* + * $Id: parse_options_geometry.c, v 1.0 2007/05/31, dietrich, tokyo $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2007 by the Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Author: Dietrich Bollmann + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + * Functions to parse the `' value + * of the `--geometry ' option. + * + * geometry pattern: [=][{xX}][{+-}{+-}] + * + * header file: ../../include/UTL_parse_options_geometry.h + * + */ + +#include +#include + +/* declaration local functions */ +int is_digit(char c); +int is_digit(char c); +int digit_to_integer(char c); +int is_sign(char c); +int parse_character(char **str, char c); +int parse_sign(char **str, int* sign); +int parse_integer(char **str, int* result); +int parse_size(char **geometry, int* x, int* y); +int parse_position(char **geometry, int* x, int* y); + +/* function definitions */ + +/** + Returns true if `c' is a digit. + */ +int is_digit(char c) +{ + return ('0' <= c) && (c <= '9'); +} + +/** + Converts a digit to an integer. + */ +int digit_to_integer(char c) +{ + return c - '0'; +} + +/** + Returns true if `c' is `+' or `-'. + */ +int is_sign(char c) +{ + return (c == '+') || (c == '-'); +} + +/** + Try to parse the character `c' from `*str'. + + If successful, return 1 and increment `*str'; + if not (`*str' doesnt start with `c'), leave `*str' as it is and return 0. + */ +int parse_character(char **str, char c) +{ + /* when given, skip leading `=' */ + if (**str == c) { + (*str)++; + return 1; + } else { + return 0; + } +} + +/** + Try to parse a sign (`+' or `-') from `*str'. + + If successful, + - increment `*str' + - set `*sign' to + - 1 if `+' was parsed, to + - -1 if `-' was parsed and + return 1. + + if `*str' doesnt start with a sign, + - set `*sign' to 0, + - leave `*str' as it is and + - return 0. + */ +int parse_sign(char **str, int* sign) +{ + /* parse sign */ + if (**str == '+') { + (*str)++; + *sign = 1; + return 1; + } else if (**str == '-') { + (*str)++; + *sign = -1; + return 1; + } else { + *sign = 0; + return 0; + } +} + +/** + Parse an integer from the beginning of `*str'. + + `*result' is set to the parsed integer. + The length of the parsed integer string is returned by the function. + */ +int parse_integer(char **str, int* result) +{ + /* parse integer */ + int len = 0; + *result = 0; + while (*str != NULL && is_digit(**str)) { + len++; + *result = (*result * 10) + digit_to_integer(**str); + (*str)++; + } + + /* return length of parsed integer */ + return len; +} + +/** + Try to parse the size pattern from `*geometry'. + + size pattern: [{xX}] + + In the case of success, + - `*x' and `*y' are set to the parsed size values, + - `*geometry' is set at the end of the parsed string and + - 1 is returned. + + If the size couldn't be parsed, + - the values of `*x' and `*y' are not changed, + - `*geometry' is not changed either and + - 0 is returned. +*/ +int parse_size(char **geometry, int* x, int* y) +{ + int len, xx, yy; + char* geo; + geo = *geometry; + + /* try to parse size */ + + /* parse the x dimension */ + len = parse_integer(&geo, &xx); + + /* if no integer could be parsed, return 0 for fail */ + if (!len) return 0; + + /* parse 'x' or 'X' */ + len = parse_character(&geo, 'x') || parse_character(&geo, 'X'); + + /* if neither 'x' nor 'X' could be parsed, return 0 for fail */ + if (!len) return 0; + + /* parse the y dimension */ + len = parse_integer(&geo, &yy); + + /* if no integer could be parsed, return 0 for fail */ + if (!len) return 0; + + /* the size was passed successfully */ + + /* overwrite the defaults */ + *x = xx; + *y = yy; + + /* set `*geometry' to first char after the parsed size string */ + *geometry = geo; + + /* return 1 for success */ + return 1; +} + +/** + Try to parse the position pattern from `*geometry'. + + size pattern: [{+-}{+-}] + + In the case of success, + - `*x' and `*y' are set to the parsed position values, + - `*geometry' is set at the end of the parsed string and + - 1 is returned. + + If the position couldn't be parsed, + - the values of `*x' and `*y' are not changed, + - `*geometry' is not changed either and + - 0 is returned. +*/ +int parse_position(char **geometry, int* x, int* y) +{ + int xsign, xabs, ysign, yabs; + char* geo; + geo = *geometry; + + /* try to parse position */ + + /* parse sign of x position */ + if (!parse_sign(&geo, &xsign)) return 0; + + /* parse absolute x position */ + if (!parse_integer(&geo, &xabs)) return 0; + + /* parse sign of y position */ + if (!parse_sign(&geo, &ysign)) return 0; + + /* parse absolute y position */ + if (!parse_integer(&geo, &yabs)) return 0; + + /* the position was passed successfully */ + + /* overwrite the defaults */ + *x = xsign * xabs; + *y = ysign * yabs; + + /* set `*geometry' to first char after the parsed size string */ + *geometry = geo; + + /* return 1 for success */ + return 1; +} + +/** + */ +int parse_geometry(char *geometry, int* sizex, int* sizey, int* x, int* y) +{ + int result, sx, sy, px, py; + char* geo; + geo = geometry; + result = 0; + + /* when given, skip leading `=' */ + parse_character(&geo, '='); + + /* parse size */ + if (parse_size(&geo, &sx, &sy)) result += 1; + + /* parse position */ + if (parse_position(&geo, &px, &py)) result += 2; + + /* if the whole string could be parsed, + overwrite the defaults and + return a value indicating if + size, position or both could be parsed. + */ + if (*geo == '\0') { + + switch (result) { + case 1: *sizex = sx; *sizey = sy; break; + case 2: *x = px; *y = py; break; + case 3: *sizex = sx; *sizey = sy; *x = px; *y = py; break; + } + return result; + + } else { + + return 0; + + } +} + +/* fin */ Index: source/blender/blenkernel/intern/parse_options.c =================================================================== --- source/blender/blenkernel/intern/parse_options.c (.../vendor/blender/working/current/blender) (revision 0) +++ source/blender/blenkernel/intern/parse_options.c (.../blender/working/branches/bcp/blender) (revision 79) @@ -0,0 +1,219 @@ +/* + * $Id: UTL_parse_options.c, v 1.0 2007/05/31, dietrich, tokyo $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2007 by the Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Author: Dietrich Bollmann + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + * Functions to parse command-line options. + * + * header file: ../../include/UTL_parse_options.h + * + */ + +#include +#include +#include +#include "UTL_debug.h" + +#include "UTL_parse_options.h" + +/* definition of local functions */ +int get_option_index(int argc, char **argv, char *option_short, char *option_long); +void delete_args(int *argc, char **argv, int index, int number); +void print_argv(int argc, char **argv); + +/** + Parse argv for an option and return its index. + The option can be given in two different forms: a short form and a long form. + If the option was not found 0 is returned. + (dietrich) +*/ +int get_option_index(int argc, char **argv, char *option_short, char *option_long) +{ + int i; + for(i = 1; i < argc; i++) { + if ((option_short != NULL) && (strcmp(argv[i], option_short) == 0)) return i; + if ((option_long != NULL) && (strcmp(argv[i], option_long) == 0)) return i; + } + return 0; +} + +/** +*/ +int option_is_defined_delete(int *argc, char **argv, char *option_short, char *option_long) +{ + /* get the index of option if given */ + int i_option; + i_option = get_option_index(*argc, argv, option_short, option_long); + + /* return 0 if the option hasn't been found */ + if (i_option == 0) return 0; + + /* delete the options from argv and decrement *argc accordingly */ + delete_args(argc, argv, i_option, 1); + + /* check if the option was given a second time */ + if (get_option_index(*argc, argv, option_short, option_long)) { + printf("\nERROR: The option %s / %s can only be used once!\n", + option_short, option_long); + exit(2); + } + + /* return true */ + return 1; +} + +/** +*/ +int get_int_option_delete(int *argc, char **argv, char *option_short, char *option_long) +{ + int i_option; + int i_value; + int value; + + /* get the index of option if given */ + i_option = get_option_index(*argc, argv, option_short, option_long); + + /* return 0 if the option hasn't been found */ + if (i_option == 0) return 0; + + /* check if a value for the option has been given */ + i_value = i_option + 1; + if (i_value >= *argc) { + printf("\nUsage: %s | %s \n", option_short, option_long); + exit(2); + } + + /* get the value */ + value = atoi(argv[i_value]); + + /* delete the options from argv and decrement *argc accordingly */ + delete_args(argc, argv, i_option, 2); + + /* check if the option was given a second time */ + if (get_option_index(*argc, argv, option_short, option_long)) { + printf("\nERROR: The option %s / %s can only be used once!\n", + option_short, option_long); + exit(2); + } + + /* return the option value */ + return value; +} + +/** +*/ +char* get_string_option_delete_allocate(int *argc, char **argv, + char *option_short, char *option_long) + +{ + int i_option, i_value, length; + char* value_str; + + /* get the index of option if given */ + i_option = get_option_index(*argc, argv, option_short, option_long); + + /* return 0 if the option hasn't been found */ + if (i_option == 0) return (char*) NULL; + + /* check if a value for the option has been given */ + i_value = i_option + 1; + if (i_value >= *argc) { + printf("\nUsage: %s | %s \n", option_short, option_long); + exit(2); + } + + /* get the value */ + length = strlen(argv[i_value]); + value_str = (char*) malloc((length + 1) * sizeof(char)); + memcpy(value_str, argv[i_value], length); + value_str[length]= '\0'; + + /* delete the options from argv and decrement *argc accordingly */ + delete_args(argc, argv, i_option, 2); + + /* check if the option was given a second time */ + if (get_option_index(*argc, argv, option_short, option_long)) { + printf("\nERROR: The option %s / %s can only be used once!\n", + option_short, option_long); + exit(2); + } + + /* return the option value */ + return value_str; +} + +/** + Delete `number' of options from argv starting at `index' + and decrement `*argc' by `number'. + (dietrich) +*/ +void delete_args(int *argc, char **argv, int index, int number) +{ + int i; + + /* check if argc/argv is big enough */ + if ((index + number - 1) >= *argc) { + printf("\nERROR: Not enough arguments given " + "for deleting %d args starting at %d from argv:\n", number, index); + print_argv(*argc, argv); + exit(2); + } + + /* if in debug mode - print a message */ + if (debug("opt")) { + printf("[DEBUG args] Deleting \""); + for(i = index; i < (index + number); i++) { + if (i > index) printf(" "); + printf(argv[i]); + } + printf("\" from "); + print_argv(*argc, argv); + } + + /* delete the args */ + *argc -= number; + for( ; index < *argc; index++) { + argv[index] = argv[index + number]; + } +} + +/** + Print argc/argv. + (dietrich) +*/ +void print_argv(int argc, char **argv) +{ + int i; + printf("argv[%d]: ", argc); + for(i = 0; i < argc; i++) { + if (i > 0) printf(" "); + printf(argv[i]); + } + printf("\n"); +} + +/* fin */ Index: source/blender/blenkernel/intern/debug.c =================================================================== --- source/blender/blenkernel/intern/debug.c (.../vendor/blender/working/current/blender) (revision 0) +++ source/blender/blenkernel/intern/debug.c (.../blender/working/branches/bcp/blender) (revision 79) @@ -0,0 +1,375 @@ +/* + * $Id: debug.c, v 1.0 2007/06/20, dietrich, tokyo $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2007 by the Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Author: Dietrich Bollmann + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + * Debug command line option functionality. + * + * When starting Blender, the option + * + * -d[ebug] [:],[:],... + * + * can be used to switch on debug mode and to specify a debug level + * for certain modules. + * + * Example: + * + * blender --debug debug,opt,bcp:2 -geometry 650x600+0+100 --bcp 6789 + * + * Start blender and print debug messages for the + * + * debug -- debug the debug option itself + * opt -- debug some Blender command line options, see: + * - source/blender/blenkernel/intern/parse_options.c and + * - source/creator/creator.c + * bcp:2 -- debug the Blender command port, debug level 2, + * see files in: source/blender/commandport/ + * + * Note that for the debug option argument `bcp:' first + * the command port has to be activated via the `--bcp ' option. + * + * The debug level for the specified modules is stored by the debugging functions + * in `source/blender/commandport/utilities/{include/bcp_debug.h,src/bcp_debug.c}' + * and can be queried by the functions implementing the modules via the + * function `debug("name of module")'. + * + * Example: + * + * // print command port debug message (bcp) + * if (debug("bcp") > 2) print_a_level_2_debug_message(); + * + * For a list of modules currently using the debug functionality see + * the help text defined in function `print_help_debug()', file `source/creator/creator.c' + * or call `blender --help=debug'. + * + * header file: ../../include/UTL_debug.h + * + */ + +#include +#include +#include + +#include "BKE_global.h" + +#include "UTL_debug.h" + +/* struct to store an option with level */ +typedef struct option_struct { + char* name; + int level; + struct option_struct* next; +} option_struct; + +/** + Array holding the flags indicating which modules should be debugged. +*/ +option_struct* g_debug_module_list = NULL; +int g_debug = 0; + + +/* function declarations */ +char* get_next_option_allocate(char* options, option_struct** option); +option_struct* new_option(char* name, int level); +void delete_option(option_struct* option); +char* new_string(char* str, int length); +void dump_options(); + + +/** + + example: + The command `blender --debug debug,bcp:2,args' turns debugging on for + - this module (the debug module), + - the Blender Command Port module (debug level 2) and + - the `args' module. +*/ +void init_debug_mode(char* options) +{ + /* DEBUG */ + extern int g_debug; + extern option_struct* g_debug_module_list; + + char *p, *next; + option_struct *first, *last, *option; + + /* check if the debug code itself should be debugged */ + if (((p = strstr(options, "debug")) != NULL) /* "`debug' is a substring of `options' */ + && ((p == options) /* `options' starts with "debug" (ex: "debug...") */ + || (*(p-1) == ',')) /* or follows directly a ',' (ex: "...,debug") */ + && ((*(p+5) == ':') /* and the character after "debug" is one of ':', (ex: "debug:10") */ + || (*(p+5) == ',') /* ',' (ex: "debug,...") */ + || (*(p+5) == '\0')) /* and '\0' (ex: "...debug") */ + ) { /* print debug messages also for the debug module :) */ + g_debug = 1; + } + + /* DEBUG */ + if (g_debug) printf("[DEBUG debug] found the following debug options: %s\n", options); + + /* pointer to the first and last read option */ + first = NULL; + last = NULL; + + next = options; + while (NULL != (next = get_next_option_allocate(next, &option))) { + + /* DEBUG */ + printf("[DEBUG] Turning debugging on for module `%s' (level: %d).\n", + option->name, option->level); + + /* this option is the new last one */ + option->next = NULL; + + /* append the option the the option queue */ + if (first == NULL) { + + /* this is the first option to be stored */ + first = option; + last = option; + + } else { + + /* append this option to the last option */ + last->next = option; + last = option; + + } + } + + /* init the global variable + which stores the list of parsed options + */ + g_debug_module_list = first; + + /* DEBUG */ + if (g_debug) dump_options(); +} + + +/** +*/ +char* get_next_option_allocate(char* options, option_struct** option) +{ + char* cp; + int olength, level, noi; + option_struct* opt; + + /* if `options' is an empty string return NULL */ + if (*options == '\0') { + option = NULL; + return NULL; + } + + /* parse next option */ + for (cp = options, olength = 0; + *cp != ':' && *cp != ',' && *cp != '\0'; + cp++, olength++ + ) {}; + + /* the default debug level is 1 */ + level = 1; + + /* if a level is given in the option (