File: tag.xs

package info (click to toggle)
libconvert-binary-c-perl 0.86-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,264 kB
  • sloc: ansic: 47,836; perl: 4,980; yacc: 2,143; makefile: 61
file content (98 lines) | stat: -rw-r--r-- 2,280 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
################################################################################
#
# Copyright (c) 2002-2024 Marcus Holland-Moritz. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
################################################################################


################################################################################
#
#   METHOD: tag / untag
#
#   WRITTEN BY: Marcus Holland-Moritz             ON: Dec 2004
#   CHANGED BY:                                   ON:
#
################################################################################

void
CBC::tag(type, ...)
  const char *type

  ALIAS:
    untag = 1

  PREINIT:
    CBC_METHOD_VAR;
    TagTypeInfo tti;
    CtTagList *taglist;

  CODE:
    switch (ix)
    {
      case 0:
        CBC_METHOD_SET("tag");
        break;

      case 1:
        CBC_METHOD_SET("untag");
        break;

      default:
        fatal("Invalid alias (%d) for tag method", ix);
        break;
    }

    CT_DEBUG_METHOD1("'%s'", type);

    if (ix == 0 && items <= 3 && GIMME_V == G_VOID)
    {
      WARN_VOID_CONTEXT;
      XSRETURN_EMPTY;
    }

    NEED_PARSE_DATA;

    tti.type = type;

    if (!get_member_info(aTHX_ THIS, type, &tti.mi, 0))
      Perl_croak(aTHX_ "Cannot find '%s'", type);

    if (tti.mi.level != 0)
      Perl_croak(aTHX_ "Cannot tag array members");

    taglist = tti.mi.pDecl ? &tti.mi.pDecl->tags
                           : find_taglist_ptr(tti.mi.type.ptr);

    assert(taglist != NULL);

    if (ix == 0) /* tag */
    {
      if (items == 2)
        ST(0) = get_tags(aTHX_ &tti, *taglist);
      else if (items == 3)
        handle_tag(aTHX_ &tti, taglist, ST(2), NULL, &ST(0));
      else if (items % 2 == 0)
      {
        int i;
        for (i = 2; i < items; i += 2)
          handle_tag(aTHX_ &tti, taglist, ST(i), ST(i+1), NULL);
      }
      else
        Perl_croak(aTHX_ "Invalid number of arguments to %s", method);
    }
    else /* untag */
    {
      if (items == 2)
        delete_all_tags(taglist);
      else
      {
        int i;
        for (i = 2; i < items; i++)
          handle_tag(aTHX_ &tti, taglist, ST(i), &PL_sv_undef, NULL);
      }
    }

    XSRETURN(1);