// cppawk: C preprocessor wrapper around awk // Kaz Kylheku // // BSD-2 License // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. #ifndef __CPPAWK_VARG_PRIV_H #define __CPPAWK_VARG_PRIV_H #ifndef __CPPAWK_BASE_H #include "base.h" #endif #ifndef __CPPAWK_CASE_PRIV_H #include "case-priv.h" #endif #define __rest \ __r1, __r2, __r3, __r4, __r5, __r6, __r7, __r8, __r9, __r10, __r11, \ __r12, __r13, __r14, __r15, __r16, __r17, __r18, __r19, __r20, __r21, \ __r22, __r23, __r24, __r25, __r26, __r27, __r28, __r29, __r30, __r31, __r32 #define __varg_count(name, check, count) \ if (__present(check)) \ __error(name ": too many arguments"); \ count = 0; \ if (__present(__r16)) { \ if (__present(__r24)) { \ if (__present(__r28)) { \ if (__present(__r30)) { \ if (__present(__r31)) { \ if (__present(__r32)) \ count = 32; \ else \ count = 31; \ } else { \ count = 30; \ } \ } else { /* !__present(__r30) */ \ if (__present(__r29)) \ count = 29; \ else \ count = 28; \ } \ } else { /* !__present(__r28) */ \ if (__present(__r26)) { \ if (__present(__r27)) \ count = 27; \ else \ count = 26; \ } else { /* !__present(__r26) */ \ if (__present(__r25)) \ count = 25; \ else \ count = 24; \ } \ } \ } else { /* !__present(__r24) */ \ if (__present(__r20)) { \ if (__present(__r22)) { \ if (__present(__r23)) \ count = 23; \ else \ count = 22; \ } else { /* !__present(__r22) */ \ if (__present(__r21)) \ count = 21; \ else \ count = 20; \ } \ } else { /* !__present(__r20) */ \ if (__present(__r18)) { \ if (__present(__r19)) \ count = 19; \ else \ count = 18; \ } else { /* !__present(__r18) */ \ if (__present(__r17)) \ count = 17; \ else \ count = 16; \ } \ } \ } \ } else { /*!__present(__r16) */ \ if (__present(__r8)) { \ if (__present(__r12)) { \ if (__present(__r14)) { \ if (__present(__r15)) { \ count = 15; \ } else { \ count = 14; \ } \ } else { /* !__present(__r14) */ \ if (__present(__r13)) \ count = 13; \ else \ count = 12; \ } \ } else { /* !__present(__r12) */ \ if (__present(__r10)) { \ if (__present(__r11)) \ count = 11; \ else \ count = 10; \ } else { /* !__present(__r10) */ \ if (__present(__r9)) \ count = 9; \ else \ count = 8; \ } \ } \ } else { /* !__present(__r8) */ \ if (__present(__r4)) { \ if (__present(__r6)) { \ if (__present(__r7)) \ count = 7; \ else \ count = 6; \ } else { /* !__present(__r6) */ \ if (__present(__r5)) \ count = 5; \ else \ count = 4; \ } \ } else { /* !__present(__r4) */ \ if (__present(__r2)) { \ if (__present(__r3)) \ count = 3; \ else \ count = 2; \ } else { /* !__present(__r2) */ \ if (__present(__r1)) \ count = 1; \ } \ } \ } \ } #define __varg_list(name, check, count, out) \ __varg_count(name, check, count); \ out = nil; \ __case (count) { \ __of (32) \ out = __cons(__r32, out); \ __cfall; \ __of (31) \ out = __cons(__r31, out); \ __cfall; \ __of (30) \ out = __cons(__r30, out); \ __cfall; \ __of (29) \ out = __cons(__r29, out); \ __cfall; \ __of (28) \ out = __cons(__r28, out); \ __cfall; \ __of (27) \ out = __cons(__r27, out); \ __cfall; \ __of (26) \ out = __cons(__r26, out); \ __cfall; \ __of (25) \ out = __cons(__r25, out); \ __cfall; \ __of (24) \ out = __cons(__r24, out); \ __cfall; \ __of (23) \ out = __cons(__r23, out); \ __cfall; \ __of (22) \ out = __cons(__r22, out); \ __cfall; \ __of (21) \ out = __cons(__r21, out); \ __cfall; \ __of (20) \ out = __cons(__r20, out); \ __cfall; \ __of (19) \ out = __cons(__r19, out); \ __cfall; \ __of (18) \ out = __cons(__r18, out); \ __cfall; \ __of (17) \ out = __cons(__r17, out); \ __cfall; \ __of (16) \ out = __cons(__r16, out); \ __cfall; \ __of (15) \ out = __cons(__r15, out); \ __cfall; \ __of (14) \ out = __cons(__r14, out); \ __cfall; \ __of (13) \ out = __cons(__r13, out); \ __cfall; \ __of (12) \ out = __cons(__r12, out); \ __cfall; \ __of (11) \ out = __cons(__r11, out); \ __cfall; \ __of (10) \ out = __cons(__r10, out); \ __cfall; \ __of (9) \ out = __cons(__r9, out); \ __cfall; \ __of (8) \ out = __cons(__r8, out); \ __cfall; \ __of (7) \ out = __cons(__r7, out); \ __cfall; \ __of (6) \ out = __cons(__r6, out); \ __cfall; \ __of (5) \ out = __cons(__r5, out); \ __cfall; \ __of (4) \ out = __cons(__r4, out); \ __cfall; \ __of (3) \ out = __cons(__r3, out); \ __cfall; \ __of (2) \ out = __cons(__r2, out); \ __cfall; \ __of (1) \ out = __cons(__r1, out); \ __cfall; \ } #define __varg_array(name, check, count, out) \ __varg_count(name, check, count); \ delete out; \ __case (count) { \ __of (32) \ out[32] = __r32; \ __cfall; \ __of (31) \ out[31] = __r31; \ __cfall; \ __of (30) \ out[30] = __r30; \ __cfall; \ __of (29) \ out[29] = __r29; \ __cfall; \ __of (28) \ out[28] = __r28; \ __cfall; \ __of (27) \ out[27] = __r27; \ __cfall; \ __of (26) \ out[26] = __r26; \ __cfall; \ __of (25) \ out[25] = __r25; \ __cfall; \ __of (24) \ out[24] = __r24; \ __cfall; \ __of (23) \ out[23] = __r23; \ __cfall; \ __of (22) \ out[22] = __r22; \ __cfall; \ __of (21) \ out[21] = __r21; \ __cfall; \ __of (20) \ out[20] = __r20; \ __cfall; \ __of (19) \ out[19] = __r19; \ __cfall; \ __of (18) \ out[18] = __r18; \ __cfall; \ __of (17) \ out[17] = __r17; \ __cfall; \ __of (16) \ out[16] = __r16; \ __cfall; \ __of (15) \ out[15] = __r15; \ __cfall; \ __of (14) \ out[14] = __r14; \ __cfall; \ __of (13) \ out[13] = __r13; \ __cfall; \ __of (12) \ out[12] = __r12; \ __cfall; \ __of (11) \ out[11] = __r11; \ __cfall; \ __of (10) \ out[10] = __r10; \ __cfall; \ __of (9) \ out[9] = __r9; \ __cfall; \ __of (8) \ out[8] = __r8; \ __cfall; \ __of (7) \ out[7] = __r7; \ __cfall; \ __of (6) \ out[6] = __r6; \ __cfall; \ __of (5) \ out[5] = __r5; \ __cfall; \ __of (4) \ out[4] = __r4; \ __cfall; \ __of (3) \ out[3] = __r3; \ __cfall; \ __of (2) \ out[2] = __r2; \ __cfall; \ __of (1) \ out[1] = __r1; \ __cfall; \ } #ifndef __CPPAWK_CONS_PRIV_H #include "cons-priv.h" #endif function __argcount(__name, __rest, __narg, // check argument; doubles as local count __case_temps) { __varg_count(__name, __narg, __narg) return __narg; } function __arglist(__name, __rest, __narg, // check argument; doubles as local count __out, __case_temps) { __varg_list(__name, __narg, __narg, __out) return __out; } function __argarray(__name, __to_array, __rest, __narg, // check argument; doubles as local count __case_temps) { __varg_array(__name, __narg, __narg, __to_array) } #endif