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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "readtags.h"
#include "tagEntry_to_HV.h"
typedef struct {
tagFile* file;
tagFileInfo* fileInfo;
tagEntry* entryBuffer;
} myTagFile;
/*tagResult
tagsSetSortType(file, type)
tagFile * file
sortType type
*/
MODULE = Parse::ExuberantCTags PACKAGE = Parse::ExuberantCTags
PROTOTYPES: DISABLE
myTagFile*
new(CLASS, path)
char* CLASS
char* path
PREINIT:
tagFile* theFile;
tagFileInfo* theInfo;
CODE:
theInfo = (tagFileInfo*)safemalloc( sizeof(tagFileInfo) );
if( theInfo == NULL ){
warn("unable to malloc tagFileInfo");
XSRETURN_UNDEF;
}
theFile = tagsOpen(path, theInfo);
if (theFile == NULL) {
safefree(theInfo);
XSRETURN_UNDEF;
}
if (theInfo->status.opened == 0) {
safefree(theFile);
safefree(theInfo);
XSRETURN_UNDEF;
}
RETVAL = (myTagFile*)safemalloc( sizeof(myTagFile) );
if( RETVAL == NULL ){
warn("unable to malloc myTagFile");
tagsClose(theFile);
safefree(theInfo);
XSRETURN_UNDEF;
}
RETVAL->entryBuffer = (tagEntry*)safemalloc( sizeof(tagEntry) );
if( RETVAL == NULL ){
warn("unable to malloc tagEntry");
tagsClose(theFile);
safefree(theInfo);
safefree(RETVAL);
XSRETURN_UNDEF;
}
RETVAL->file = theFile;
RETVAL->fileInfo = theInfo;
OUTPUT:
RETVAL
void
DESTROY(self)
myTagFile* self
CODE:
if (self->file != NULL)
tagsClose(self->file);
safefree(self->fileInfo);
safefree(self->entryBuffer);
safefree(self);
SV*
firstTag(self)
myTagFile* self
PREINIT:
HV* result;
CODE:
if (self->file == NULL)
XSRETURN_UNDEF;
if (tagsFirst(self->file, self->entryBuffer) == TagFailure)
XSRETURN_UNDEF;
result = tagEntry_to_HV(self->entryBuffer);
RETVAL = newRV_noinc((SV*) result);
OUTPUT:
RETVAL
SV*
nextTag(self)
myTagFile* self
PREINIT:
HV* result;
CODE:
if (self->file == NULL)
XSRETURN_UNDEF;
if (tagsNext(self->file, self->entryBuffer) == TagFailure)
XSRETURN_UNDEF;
result = tagEntry_to_HV(self->entryBuffer);
RETVAL = newRV_noinc((SV*) result);
OUTPUT:
RETVAL
SV*
findTag(self, name, ...)
myTagFile* self
char* name
PREINIT:
int options = TAG_FULLMATCH | TAG_OBSERVECASE;
unsigned int i;
SV* sv;
HV* result;
CODE:
if ( (items % 2) == 1 )
croak("Syntax: ->findTag('tagname', [option => value, ...])");
if (self->file == NULL)
XSRETURN_UNDEF;
if (items > 2) {
for (i = 2; i < (unsigned int)items; i += 2) {
sv = ST(i);
if ( SvOK(sv) ) {
if ( strEQ(SvPV_nolen(sv), "partial") && SvTRUE(ST(i+1)) )
options |= TAG_PARTIALMATCH;
else if ( strEQ(SvPV_nolen(sv), "ignore_case") && SvTRUE(ST(i+1)) )
options |= TAG_IGNORECASE;
}
}
} /* end if optional args */
if (tagsFind(self->file, self->entryBuffer, name, options) == TagFailure)
XSRETURN_UNDEF;
result = tagEntry_to_HV(self->entryBuffer);
RETVAL = newRV_noinc((SV*) result);
OUTPUT:
RETVAL
SV*
findNextTag(self)
myTagFile* self
PREINIT:
HV* result;
CODE:
if (self->file == NULL)
XSRETURN_UNDEF;
if (tagsFindNext(self->file, self->entryBuffer) == TagFailure)
XSRETURN_UNDEF;
result = tagEntry_to_HV(self->entryBuffer);
RETVAL = newRV_noinc((SV*) result);
OUTPUT:
RETVAL
|