MCPcopy Create free account
hub / github.com/NetHack/NetHack / splitsubfields

Function splitsubfields

src/botl.c:2687–2727  ·  view source on GitHub ↗

splitsubfields(): splits str in place into '+' or '&' separated strings. returns number of strings, or -1 if more than maxsf or MAX_SUBFIELDS */

Source from the content-addressed store, hash-verified

2685/* splitsubfields(): splits str in place into '+' or '&' separated strings.
2686 returns number of strings, or -1 if more than maxsf or MAX_SUBFIELDS */
2687staticfn int
2688splitsubfields(char *str, char ***sfarr, int maxsf)
2689{
2690#define MAX_SUBFIELDS 16
2691 static char *subfields[MAX_SUBFIELDS];
2692 char *st = (char *) 0;
2693 int sf = 0;
2694
2695 if (!str)
2696 return 0;
2697 for (sf = 0; sf < MAX_SUBFIELDS; ++sf)
2698 subfields[sf] = (char *) 0;
2699
2700 maxsf = (maxsf == 0) ? MAX_SUBFIELDS : min(maxsf, MAX_SUBFIELDS);
2701
2702 if (strchr(str, '+') || strchr(str, '&')) {
2703 char *c = str;
2704
2705 sf = 0;
2706 st = c;
2707 while (*c && sf < maxsf) {
2708 if (*c == '&' || *c == '+') {
2709 *c = '\0';
2710 subfields[sf] = st;
2711 st = c+1;
2712 sf++;
2713 }
2714 c++;
2715 }
2716 if (sf >= maxsf - 1)
2717 return -1;
2718 if (!*c && c != st)
2719 subfields[sf++] = st;
2720 } else {
2721 sf = 1;
2722 subfields[0] = str;
2723 }
2724 *sfarr = subfields;
2725 return sf;
2726#undef MAX_SUBFIELDS
2727}
2728
2729staticfn boolean
2730is_fld_arrayvalues(

Callers 3

parse_status_hl2Function · 0.85
str2conditionbitmaskFunction · 0.85
parse_conditionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected