File: tag.xs

package info (click to toggle)
libconvert-binary-c-perl 0.74-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 9,100 kB
  • ctags: 21,416
  • sloc: ansic: 63,666; perl: 18,582; yacc: 2,143; makefile: 44
file content (106 lines) | stat: -rw-r--r-- 2,496 bytes parent folder | download
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
99
100
101
102
103
104
105
106
################################################################################
#
# $Project: /Convert-Binary-C $
# $Author: mhx $
# $Date: 2009/03/15 04:10:42 +0100 $
# $Revision: 12 $
# $Source: /xsubs/tag.xs $
#
################################################################################
#
# Copyright (c) 2002-2009 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);