1b39c5158Smillert void 2b39c5158Smillert constant(sv) 3b39c5158Smillert PREINIT: 4b39c5158Smillert #ifdef dXSTARG 5b39c5158Smillert dXSTARG; /* Faster if we have it. */ 6b39c5158Smillert #else 7b39c5158Smillert dTARGET; 8b39c5158Smillert #endif 9b39c5158Smillert STRLEN len; 10b39c5158Smillert int type; 11b39c5158Smillert IV iv; 12b39c5158Smillert /* NV nv; Uncomment this if you need to return NVs */ 13b39c5158Smillert const char *pv; 14b39c5158Smillert INPUT: 15b39c5158Smillert SV * sv; 16b39c5158Smillert const char * s = SvPV(sv, len); 17b39c5158Smillert PPCODE: 18b39c5158Smillert /* Change this to constant(aTHX_ s, len, &iv, &nv); 19b39c5158Smillert if you need to return both NVs and IVs */ 20b39c5158Smillert type = constant(aTHX_ s, len, &iv, &pv); 21b39c5158Smillert /* Return 1 or 2 items. First is error message, or undef if no error. 22b39c5158Smillert Second, if present, is found value */ 23b39c5158Smillert switch (type) { 24b39c5158Smillert case PERL_constant_NOTFOUND: 25*898184e3Ssthen sv = 26*898184e3Ssthen sv_2mortal(newSVpvf("%s is not a valid Zlib macro", s)); 27b39c5158Smillert PUSHs(sv); 28b39c5158Smillert break; 29b39c5158Smillert case PERL_constant_NOTDEF: 30b39c5158Smillert sv = sv_2mortal(newSVpvf( 31*898184e3Ssthen "Your vendor has not defined Zlib macro %s, used", 32*898184e3Ssthen s)); 33b39c5158Smillert PUSHs(sv); 34b39c5158Smillert break; 35b39c5158Smillert case PERL_constant_ISIV: 36b39c5158Smillert EXTEND(SP, 1); 37b39c5158Smillert PUSHs(&PL_sv_undef); 38b39c5158Smillert PUSHi(iv); 39b39c5158Smillert break; 40b39c5158Smillert /* Uncomment this if you need to return NOs 41b39c5158Smillert case PERL_constant_ISNO: 42b39c5158Smillert EXTEND(SP, 1); 43b39c5158Smillert PUSHs(&PL_sv_undef); 44b39c5158Smillert PUSHs(&PL_sv_no); 45b39c5158Smillert break; */ 46b39c5158Smillert /* Uncomment this if you need to return NVs 47b39c5158Smillert case PERL_constant_ISNV: 48b39c5158Smillert EXTEND(SP, 1); 49b39c5158Smillert PUSHs(&PL_sv_undef); 50b39c5158Smillert PUSHn(nv); 51b39c5158Smillert break; */ 52b39c5158Smillert case PERL_constant_ISPV: 53b39c5158Smillert EXTEND(SP, 1); 54b39c5158Smillert PUSHs(&PL_sv_undef); 55b39c5158Smillert PUSHp(pv, strlen(pv)); 56b39c5158Smillert break; 57b39c5158Smillert /* Uncomment this if you need to return PVNs 58b39c5158Smillert case PERL_constant_ISPVN: 59b39c5158Smillert EXTEND(SP, 1); 60b39c5158Smillert PUSHs(&PL_sv_undef); 61b39c5158Smillert PUSHp(pv, iv); 62b39c5158Smillert break; */ 63b39c5158Smillert /* Uncomment this if you need to return SVs 64b39c5158Smillert case PERL_constant_ISSV: 65b39c5158Smillert EXTEND(SP, 1); 66b39c5158Smillert PUSHs(&PL_sv_undef); 67b39c5158Smillert PUSHs(sv); 68b39c5158Smillert break; */ 69b39c5158Smillert /* Uncomment this if you need to return UNDEFs 70b39c5158Smillert case PERL_constant_ISUNDEF: 71b39c5158Smillert break; */ 72b39c5158Smillert /* Uncomment this if you need to return UVs 73b39c5158Smillert case PERL_constant_ISUV: 74b39c5158Smillert EXTEND(SP, 1); 75b39c5158Smillert PUSHs(&PL_sv_undef); 76b39c5158Smillert PUSHu((UV)iv); 77b39c5158Smillert break; */ 78b39c5158Smillert /* Uncomment this if you need to return YESs 79b39c5158Smillert case PERL_constant_ISYES: 80b39c5158Smillert EXTEND(SP, 1); 81b39c5158Smillert PUSHs(&PL_sv_undef); 82b39c5158Smillert PUSHs(&PL_sv_yes); 83b39c5158Smillert break; */ 84b39c5158Smillert default: 85b39c5158Smillert sv = sv_2mortal(newSVpvf( 86b39c5158Smillert "Unexpected return type %d while processing Zlib macro %s, used", 87b39c5158Smillert type, s)); 88b39c5158Smillert PUSHs(sv); 89b39c5158Smillert } 90