From 1933610719be44b55cf79fb902d251d665c61071 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Fri, 24 Aug 2007 15:05:37 +0200 Subject: [PATCH] Moved template size calculation out to Awk script --- ngx_http_fancyindex_module.h | 13 +++---------- template.awk | 7 +++++++ template.h | 11 +++++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ngx_http_fancyindex_module.h b/ngx_http_fancyindex_module.h index 829f952..915665e 100644 --- a/ngx_http_fancyindex_module.h +++ b/ngx_http_fancyindex_module.h @@ -8,18 +8,11 @@ #ifndef __ngx_http_fancyindex_module_h__ #define __ngx_http_fancyindex_module_h__ +#define nfi_sizeof_ssz(_s) (sizeof(_s) - 1) + + #include "template.h" -#define NFI_TEMPLATE_SIZE \ - ( (sizeof(t01_head1) - 1) \ - + (sizeof(t02_head2) - 1) \ - + (sizeof(t03_body1) - 1) \ - + (sizeof(t04_body2) - 1) \ - + (sizeof(t05_list1) - 1) \ - + (sizeof(t06_list2) - 1) \ - + (sizeof(t07_body3) - 1) \ - + (sizeof(t08_body4) - 1) \ - + (sizeof(t09_foot1) - 1) ) /** * Copy a static zero-terminated string. Useful to output template diff --git a/template.awk b/template.awk index 5422435..9c8c48b 100755 --- a/template.awk +++ b/template.awk @@ -10,6 +10,7 @@ BEGIN { varname = 0; print "/* Automagically generated, do not edit! */" + vars_count = 0; } /^$/ { @@ -19,6 +20,7 @@ BEGIN { next; } varname = $3; + vars[vars_count++] = varname; print "static const u_char " varname "[] = \"\""; next; } @@ -35,5 +37,10 @@ BEGIN { END { if (varname) print ";"; + print "#define NFI_TEMPLATE_SIZE (0 \\"; + for (var in vars) { + print "\t+ nfi_sizeof_ssz(" var ") \\"; + } + print "\t)" } diff --git a/template.h b/template.h index 9fcc31f..f620f6c 100644 --- a/template.h +++ b/template.h @@ -78,3 +78,14 @@ static const u_char t09_foot1[] = "" "" "" ; +#define NFI_TEMPLATE_SIZE (0 \ + + nfi_sizeof_ssz(4) \ + + nfi_sizeof_ssz(5) \ + + nfi_sizeof_ssz(6) \ + + nfi_sizeof_ssz(7) \ + + nfi_sizeof_ssz(8) \ + + nfi_sizeof_ssz(0) \ + + nfi_sizeof_ssz(1) \ + + nfi_sizeof_ssz(2) \ + + nfi_sizeof_ssz(3) \ + )