DLLEXPORT void jl_show_any(jl_value_t *str, jl_value_t *v) { ios_t *s = (ios_t*)jl_iostr_data(str); // fallback for printing some other builtin types if (jl_is_tuple(v)) { jl_show_tuple(str, (jl_tuple_t*)v, '(', ')', 1); } else if (jl_is_type(v)) { show_type(str, v); } else if (jl_is_func(v)) { show_function(s, v); } else if (jl_typeis(v,jl_intrinsic_type)) { JL_PRINTF(s, "#<intrinsic-function %d>", *(uint32_t*)jl_bits_data(v)); } else { jl_value_t *t = (jl_value_t*)jl_typeof(v); if (jl_is_struct_type(t)) { jl_struct_type_t *st = (jl_struct_type_t*)t; JL_PUTS(st->name->name->name, s); JL_PUTC('(', s); size_t i; size_t n = jl_tuple_len(st->names); for(i=0; i < n; i++) { jl_show(str, nth_field(v, i)); if (i < n-1) JL_PUTC(',', s); } JL_PUTC(')', s); } } }
DLLEXPORT void jl_show_any(jl_value_t *v) { // fallback for printing some other builtin types ios_t *s = jl_current_output_stream(); if (jl_is_tuple(v)) { show_tuple((jl_tuple_t*)v, '(', ')', 1); } else if (jl_is_type(v)) { show_type(v); } else if (jl_is_func(v)) { show_function(v); } else if (jl_typeis(v,jl_intrinsic_type)) { ios_printf(s, "#<intrinsic-function %d>", *(uint32_t*)jl_bits_data(v)); } else { jl_value_t *t = (jl_value_t*)jl_typeof(v); if (jl_is_struct_type(t)) { jl_struct_type_t *st = (jl_struct_type_t*)t; ios_puts(st->name->name->name, s); ios_putc('(', s); size_t i; size_t n = st->names->length; for(i=0; i < n; i++) { jl_show(nth_field(v, i)); if (i < n-1) ios_putc(',', s); } ios_putc(')', s); } } }
const char *reference::get_author(int i, const char **endp) const { for (const char *f = AUTHOR_FIELDS; *f != '\0'; f++) { const char *start = get_field(*f, endp); if (start) { if (strchr(MULTI_FIELD_NAMES, *f) != 0) return nth_field(i, start, endp); else if (i == 0) return start; else return 0; } } return 0; }
const char *reference::get_author_last_name(int i, const char **endp) const { for (const char *f = AUTHOR_FIELDS; *f != '\0'; f++) { const char *start = get_field(*f, endp); if (start) { if (strchr(MULTI_FIELD_NAMES, *f) != 0) { start = nth_field(i, start, endp); if (!start) return 0; } if (*f == 'A') return find_last_name(start, *endp, endp); else return start; } } return 0; }
/*! \brief Lease file parser. The parser can only read ISC DHCPD * dhcpd.leases file format. */ int parse_leases(void) { FILE *dhcpd_leases; char *line, *ipstring, macstring[20]; union ipaddr_t addr; struct stat lease_file_stats; bool ethernets = false; struct leases_t *lease; dhcpd_leases = fopen(config.dhcpdlease_file, "r"); if (dhcpd_leases == NULL) { err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file); } #ifdef HAVE_POSIX_FADVISE # ifdef POSIX_FADV_WILLNEED posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED); if (errno) { err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file); } # endif /* POSIX_FADV_WILLNEED */ # ifdef POSIX_FADV_SEQUENTIAL posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL); if (errno) { err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file); } # endif /* POSIX_FADV_SEQUENTIAL */ #endif /* HAVE_POSIX_FADVISE */ /* I found out that there's one lease address per 300 bytes in * dhcpd.leases file. Malloc is little bit pessimistic and uses 250. * If someone has higher density in lease file I'm interested to * hear about that. */ if (stat(config.dhcpdlease_file, &lease_file_stats)) { err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file); } line = xmalloc(sizeof(char) * MAXLEN); ipstring = xmalloc(sizeof(char) * MAXLEN); if (config.output_format[0] == 'X' || config.output_format[0] == 'J') { ethernets = true; } const char **p = prefixes[config.dhcp_version]; int *l = prefix_length[config.dhcp_version]; /*! \def HAS_PREFIX(line, type) * \brief A macro to match IPv4 and IPv6 lease lines. * * FIXME: This macro should have better name. The HAS_PREFIX sounds like * some sort of prefix length test. */ #define HAS_PREFIX(line, type) xstrstr((line), p[type], l[type]) while (!feof(dhcpd_leases)) { if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases)) { err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file); } /* It's a lease, save IP */ if (HAS_PREFIX(line, PREFIX_LEASE)) { nth_field(ipstring, line + l[PREFIX_LEASE]); parse_ipaddr(ipstring, &addr); continue; } if (HAS_PREFIX(line, PREFIX_BINDING_STATE_FREE) || HAS_PREFIX(line, PREFIX_BINDING_STATE_ABANDONED) || HAS_PREFIX(line, PREFIX_BINDING_STATE_EXPIRED) || HAS_PREFIX(line, PREFIX_BINDING_STATE_RELEASED)) { /* remove old entry, if exists */ if ((lease = find_lease(&addr)) != NULL) { delete_lease(lease); } add_lease(&addr, FREE); continue; } /* Copy IP to correct array */ if (HAS_PREFIX(line, PREFIX_BINDING_STATE_ACTIVE)) { /* remove old entry, if exists */ if ((lease = find_lease(&addr)) != NULL) { delete_lease(lease); } add_lease(&addr, ACTIVE); continue; } if (HAS_PREFIX(line, PREFIX_BINDING_STATE_BACKUP)) { /* remove old entry, if exists */ if ((lease = find_lease(&addr)) != NULL) { delete_lease(lease); } add_lease(&addr, BACKUP); config.backups_found = true; continue; } if (ethernets && (xstrstr(line, " hardware ethernet", 19))) { nth_field(macstring, line + 20); macstring[17] = '\0'; if ((lease = find_lease(&addr)) != NULL) { lease->ethernet = xstrdup(macstring); } } } #undef HAS_PREFIX free(line); free(ipstring); fclose(dhcpd_leases); return 0; }