code style cleanup. A new feature is that if ->processes == 'web' we won't include it in the c++ header defines. We can use this to shrink ram use and startup time of c++ processes a bit
This commit is contained in:
parent
08aee63f66
commit
615b9f6ee6
241
zmconfgen.pl.in
241
zmconfgen.pl.in
|
@ -43,148 +43,125 @@ sub generateConfigFiles
|
||||||
generateConfigSQL();
|
generateConfigSQL();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub generateConfigHeader
|
sub generateConfigHeader {
|
||||||
{
|
print("Generating '$config_header'\n");
|
||||||
print( "Generating '$config_header'\n" );
|
open(CFG_HDR_FILE, '>'.$config_header) or die("Can't open '$config_header' for writing");
|
||||||
open( CFG_HDR_FILE, ">$config_header" ) or die( "Can't open '$config_header' for writing" );
|
print(CFG_HDR_FILE "// The file is autogenerated by zmconfgen.pl\n");
|
||||||
print( CFG_HDR_FILE "// The file is autogenerated by zmconfgen.pl\n" );
|
print(CFG_HDR_FILE "// Do not edit this file as any changes will be overwritten\n\n");
|
||||||
print( CFG_HDR_FILE "// Do not edit this file as any changes will be overwritten\n\n" );
|
|
||||||
my $last_id = 0;
|
my $last_id = 0;
|
||||||
my $define_list = "";
|
my $define_list = '';
|
||||||
my $declare_list = "";
|
my $declare_list = '';
|
||||||
my $assign_list = "";
|
my $assign_list = '';
|
||||||
foreach my $option ( @options )
|
foreach my $option ( @options ) {
|
||||||
{
|
next if !defined($option->{id});
|
||||||
next if ( !defined($option->{id}) );
|
|
||||||
|
|
||||||
my $opt_id = $option->{id};
|
# If only used in ui, then don't include it in C++ config defines
|
||||||
my $opt_name = $option->{name};
|
next if $option->{processes} and ($option->{processes} ne 'web');
|
||||||
my $opt_type = $option->{type};
|
|
||||||
my $var_name = substr( lc($opt_name), 3 );
|
|
||||||
|
|
||||||
$define_list .= sprintf( "#define $opt_name $opt_id\n" );
|
my $opt_id = $option->{id};
|
||||||
|
my $opt_name = $option->{name};
|
||||||
|
my $opt_type = $option->{type};
|
||||||
|
my $var_name = substr( lc($opt_name), 3 );
|
||||||
|
|
||||||
$declare_list .= sprintf( "\t" );
|
$define_list .= "#define $opt_name $opt_id\n";
|
||||||
if ( $opt_type->{db_type} eq 'boolean' )
|
|
||||||
{
|
|
||||||
$declare_list .= sprintf( "bool " );
|
|
||||||
}
|
|
||||||
elsif ( $opt_type->{db_type} eq 'integer' || $opt_type->{db_type} eq 'hexadecimal' )
|
|
||||||
{
|
|
||||||
$declare_list .= sprintf( "int " );
|
|
||||||
}
|
|
||||||
elsif ( $opt_type->{db_type} eq 'decimal' )
|
|
||||||
{
|
|
||||||
$declare_list .= sprintf( "double " );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$declare_list .= sprintf( "const char *" );
|
|
||||||
}
|
|
||||||
$declare_list .= sprintf( $var_name.";\\\n" );
|
|
||||||
|
|
||||||
$assign_list .= sprintf( "\t" );
|
$declare_list .= "\t";
|
||||||
$assign_list .= sprintf( $var_name." = " );
|
if ( $opt_type->{db_type} eq 'boolean' ) {
|
||||||
if ( $opt_type->{db_type} eq 'boolean' )
|
$declare_list .= 'bool ';
|
||||||
{
|
} elsif ( $opt_type->{db_type} eq 'integer' || $opt_type->{db_type} eq 'hexadecimal' ) {
|
||||||
$assign_list .= sprintf( "(bool)" );
|
$declare_list .= 'int ';
|
||||||
}
|
} elsif ( $opt_type->{db_type} eq 'decimal' ) {
|
||||||
elsif ( $opt_type->{db_type} eq 'integer' || $opt_type->{db_type} eq 'hexadecimal' )
|
$declare_list .= 'double ';
|
||||||
{
|
} else {
|
||||||
$assign_list .= sprintf( "(int)" );
|
$declare_list .= 'const char *';
|
||||||
}
|
}
|
||||||
elsif ( $opt_type->{db_type} eq 'decimal' )
|
$declare_list .= $var_name.";\\\n";
|
||||||
{
|
|
||||||
$assign_list .= sprintf( "(double) " );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$assign_list .= sprintf( "(const char *)" );
|
|
||||||
}
|
|
||||||
$assign_list .= sprintf( "config.Item( ".$opt_name." );\\\n" );
|
|
||||||
|
|
||||||
$last_id = $option->{id};
|
$assign_list .= "\t";
|
||||||
}
|
$assign_list .= $var_name.' = ';
|
||||||
print( CFG_HDR_FILE $define_list."\n\n" );
|
if ( $opt_type->{db_type} eq 'boolean' ) {
|
||||||
print( CFG_HDR_FILE "#define ZM_MAX_CFG_ID $last_id\n\n" );
|
$assign_list .= '(bool)';
|
||||||
print( CFG_HDR_FILE "#define ZM_CFG_DECLARE_LIST \\\n" );
|
} elsif ( $opt_type->{db_type} eq 'integer' || $opt_type->{db_type} eq 'hexadecimal' ) {
|
||||||
print( CFG_HDR_FILE $declare_list."\n\n" );
|
$assign_list .= '(int)';
|
||||||
print( CFG_HDR_FILE "#define ZM_CFG_ASSIGN_LIST \\\n" );
|
} elsif ( $opt_type->{db_type} eq 'decimal' ) {
|
||||||
print( CFG_HDR_FILE $assign_list."\n\n" );
|
$assign_list .= '(double) ';
|
||||||
close( CFG_HDR_FILE );
|
} else {
|
||||||
|
$assign_list .= '(const char *)';
|
||||||
|
}
|
||||||
|
$assign_list .= 'config.Item('.$opt_name.");\\\n";
|
||||||
|
|
||||||
|
$last_id = $option->{id};
|
||||||
|
} # end foreach option
|
||||||
|
print( CFG_HDR_FILE $define_list."\n\n" );
|
||||||
|
print( CFG_HDR_FILE "#define ZM_MAX_CFG_ID $last_id\n\n" );
|
||||||
|
print( CFG_HDR_FILE "#define ZM_CFG_DECLARE_LIST \\\n" );
|
||||||
|
print( CFG_HDR_FILE $declare_list."\n\n" );
|
||||||
|
print( CFG_HDR_FILE "#define ZM_CFG_ASSIGN_LIST \\\n" );
|
||||||
|
print( CFG_HDR_FILE $assign_list."\n\n" );
|
||||||
|
close( CFG_HDR_FILE );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub generateConfigSQL
|
sub generateConfigSQL {
|
||||||
{
|
print("Updating '$config_sql'\n");
|
||||||
print( "Updating '$config_sql'\n" );
|
my $config_sql_temp = $config_sql.'.temp';
|
||||||
my $config_sql_temp = $config_sql.".temp";
|
open(CFG_SQL_FILE, '<'.$config_sql) or die("Can't open '$config_sql' for reading");
|
||||||
open( CFG_SQL_FILE, "<$config_sql" ) or die( "Can't open '$config_sql' for reading" );
|
open(CFG_TEMP_SQL_FILE, '>'.$config_sql_temp) or die("Can't open '$config_sql_temp' for writing");
|
||||||
open( CFG_TEMP_SQL_FILE, ">$config_sql_temp" ) or die( "Can't open '$config_sql_temp' for writing" );
|
while ( my $line = <CFG_SQL_FILE> ) {
|
||||||
while ( my $line = <CFG_SQL_FILE> )
|
last if ( $line =~ /^-- This section is autogenerated/ );
|
||||||
{
|
print(CFG_TEMP_SQL_FILE $line);
|
||||||
last if ( $line =~ /^-- This section is autogenerated/ );
|
}
|
||||||
print( CFG_TEMP_SQL_FILE $line );
|
close(CFG_SQL_FILE);
|
||||||
}
|
|
||||||
close( CFG_SQL_FILE );
|
|
||||||
|
|
||||||
print( CFG_TEMP_SQL_FILE "-- This section is autogenerated by zmconfgen.pl\n" );
|
print( CFG_TEMP_SQL_FILE "-- This section is autogenerated by zmconfgen.pl\n" );
|
||||||
print( CFG_TEMP_SQL_FILE "-- Do not edit this file as any changes will be overwritten\n" );
|
print( CFG_TEMP_SQL_FILE "-- Do not edit this file as any changes will be overwritten\n" );
|
||||||
print( CFG_TEMP_SQL_FILE "--\n\n" );
|
print( CFG_TEMP_SQL_FILE "--\n\n" );
|
||||||
print( CFG_TEMP_SQL_FILE "delete from Config;\n\n" );
|
print( CFG_TEMP_SQL_FILE "delete from Config;\n\n" );
|
||||||
foreach my $option ( @options )
|
foreach my $option ( @options ) {
|
||||||
{
|
#print( $option->{name}."\n" ) if ( !$option->{category} );
|
||||||
#print( $option->{name}."\n" ) if ( !$option->{category} );
|
$option->{db_type} = $option->{type}->{db_type};
|
||||||
$option->{db_type} = $option->{type}->{db_type};
|
$option->{db_hint} = $option->{type}->{hint};
|
||||||
$option->{db_hint} = $option->{type}->{hint};
|
$option->{db_pattern} = $option->{type}->{pattern};
|
||||||
$option->{db_pattern} = $option->{type}->{pattern};
|
$option->{db_format} = $option->{type}->{format};
|
||||||
$option->{db_format} = $option->{type}->{format};
|
my %processes = map { $_ => $_ } split(',', $option->{processes}) if $option->{processes};
|
||||||
if ( $option->{db_type} eq "boolean" )
|
if ( $option->{db_type} eq 'boolean' ) {
|
||||||
{
|
$option->{db_value} = ($option->{value} eq 'yes') ? '1' : '0';
|
||||||
$option->{db_value} = ($option->{value} eq "yes")?"1":"0";
|
} else {
|
||||||
}
|
$option->{db_value} = $option->{value};
|
||||||
else
|
}
|
||||||
{
|
if ( $option->{name} eq 'ZM_DYN_CURR_VERSION' || $option->{name} eq 'ZM_DYN_DB_VERSION' ) {
|
||||||
$option->{db_value} = $option->{value};
|
$option->{db_value} = '@VERSION@';
|
||||||
}
|
}
|
||||||
if ( $option->{name} eq "ZM_DYN_CURR_VERSION" || $option->{name} eq "ZM_DYN_DB_VERSION" )
|
if ( my $requires = $option->{requires} ) {
|
||||||
{
|
$option->{db_requires} = join(';', map { my $value = $_->{value}; $value = ($value eq 'yes')?1:0 if ( $options_hash{$_->{name}}->{db_type} eq 'boolean' ); ( "$_->{name}=$value" ) } @$requires );
|
||||||
$option->{db_value} = '@VERSION@';
|
} else {
|
||||||
}
|
$option->{db_requires} = '';
|
||||||
if ( my $requires = $option->{requires} )
|
}
|
||||||
{
|
printf( CFG_TEMP_SQL_FILE
|
||||||
$option->{db_requires} = join( ";", map { my $value = $_->{value}; $value = ($value eq "yes")?1:0 if ( $options_hash{$_->{name}}->{db_type} eq "boolean" ); ( "$_->{name}=$value" ) } @$requires );
|
"INSERT INTO Config SET Id = %d, Name = '%s', Value = '%s', Type = '%s', DefaultValue = '%s', Hint = '%s', Pattern = '%s', Format = '%s', Prompt = '%s', Help = '%s', Category = '%s', Readonly = '%s', Requires = '%s';\n",
|
||||||
}
|
$option->{id},
|
||||||
else
|
$option->{name},
|
||||||
{
|
addSlashes($option->{db_value}),
|
||||||
$option->{db_requires} = "";
|
$option->{db_type},
|
||||||
}
|
addSlashes($option->{default}),
|
||||||
printf( CFG_TEMP_SQL_FILE
|
addSlashes($option->{db_hint}),
|
||||||
"insert into Config set Id = %d, Name = '%s', Value = '%s', Type = '%s', DefaultValue = '%s', Hint = '%s', Pattern = '%s', Format = '%s', Prompt = '%s', Help = '%s', Category = '%s', Readonly = '%s', Requires = '%s';\n",
|
addSlashes($option->{db_pattern}),
|
||||||
$option->{id},
|
addSlashes($option->{db_format}),
|
||||||
$option->{name},
|
addSlashes($option->{description}),
|
||||||
addSlashes($option->{db_value}),
|
addSlashes($option->{help}),
|
||||||
$option->{db_type},
|
$option->{category},
|
||||||
addSlashes($option->{default}),
|
$option->{readonly}?1:0,
|
||||||
addSlashes($option->{db_hint}),
|
$option->{db_requires}
|
||||||
addSlashes($option->{db_pattern}),
|
);
|
||||||
addSlashes($option->{db_format}),
|
} # end foreach option
|
||||||
addSlashes($option->{description}),
|
print(CFG_TEMP_SQL_FILE "\n");
|
||||||
addSlashes($option->{help}),
|
close(CFG_TEMP_SQL_FILE);
|
||||||
$option->{category},
|
|
||||||
$option->{readonly}?1:0,
|
|
||||||
$option->{db_requires}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
print( CFG_TEMP_SQL_FILE "\n" );
|
|
||||||
close( CFG_TEMP_SQL_FILE );
|
|
||||||
|
|
||||||
rename( $config_sql_temp, $config_sql ) or die( "Can't rename '$config_sql_temp' to '$config_sql': $!" );
|
rename( $config_sql_temp, $config_sql ) or die( "Can't rename '$config_sql_temp' to '$config_sql': $!" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addSlashes
|
sub addSlashes {
|
||||||
{
|
my $string = shift;
|
||||||
my $string = shift;
|
return '' if !defined($string);
|
||||||
return( "" ) if ( !defined($string) );
|
$string =~ s|(['"])|\\$1|g;
|
||||||
$string =~ s|(['"])|\\$1|g;
|
return $string;
|
||||||
return( $string );
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue