Example #1
0
static boolean AutomakeMakeTag (vString *const name, const char* suffix, boolean appending,
			    int kindex, int rindex, struct sBlacklist *blacklist,
			    void *data)
{
	int *index = data;
	size_t expected_len;
	size_t len;
	char* tail;
	vString *subname;
	int i;

	len = vStringLength (name);
	expected_len = strlen (suffix);

	if (len <= expected_len)
		return FALSE;

	for (i = 0; blacklist[i].type != BL_END; i++)
	{
		if (bl_check (vStringValue(name), blacklist + i) == FALSE)
			return FALSE;
	}

	tail = vStringValue (name) + len - expected_len;
	if (strcmp (tail, suffix))
		return FALSE;

	subname = vStringNew();

	/* ??? dist, nodist, nobase, notrans,... */
	if (strncmp (vStringValue(name), "dist_", 5) == 0)
		vStringNCopyS(subname, vStringValue(name) + 5, len - expected_len - 5);
	else
		vStringNCopyS(subname, vStringValue(name), len - expected_len);

	if (rindex == ROLE_INDEX_DEFINITION)
	{
		*index = makeSimpleTag (subname, AutomakeKinds, kindex);
		addAutomakeDirectory (subname, *index);
	}
	else
	{
		*index = CORK_NIL;
		if (appending)
			*index = lookupAutomakeDirectory (subname);

		if ((!appending) || (*index == CORK_NIL))
			*index = makeSimpleRefTag (subname, AutomakeKinds, kindex, rindex);
	}

	vStringDelete (subname);
	return TRUE;
}
Example #2
0
/* in OCaml the file name is the module name used in the language
 * with it first letter put in upper case */
static void computeModuleName ( void )
{
	/* in Ocaml the file name define a module.
	 * so we define a module =)
	 */
	const char *filename = getSourceFileName ();
	int beginIndex = 0;
	int endIndex = strlen (filename) - 1;
	vString *moduleName = vStringNew ();

	while (filename[endIndex] != '.' && endIndex > 0)
		endIndex--;

	/* avoid problem with path in front of filename */
	beginIndex = endIndex;
	while (beginIndex > 0)
	{
		if (filename[beginIndex] == '\\' || filename[beginIndex] == '/')
		{
			beginIndex++;
			break;
		}

		beginIndex--;
	}

	vStringNCopyS (moduleName, &filename[beginIndex], endIndex - beginIndex);
	vStringTerminate (moduleName);

	if (isLowerAlpha (moduleName->buffer[0]))
		moduleName->buffer[0] += ('A' - 'a');

	addTag (moduleName, K_MODULE);
	vStringDelete (moduleName);
}
Example #3
0
static boolean parseTxt2tagsTitle (const unsigned char *line,
                                   vString *const title,
                                   int *const depth_)
{
	const int MAX_TITLE_DEPTH = 5; /* maximum length of a title delimiter */
	unsigned char delim;
	int delim_delta = 0;
	const unsigned char *end;

	/* skip leading spaces, but no tabs (probably because they create quotes) */
	while (*line == ' ') line++;

	/* normal/numbered titles */
	if (*line != '=' && *line != '+')
		return FALSE;

	delim = *line;

	/* find the start delimiter length */
	while (*line == delim && delim_delta < MAX_TITLE_DEPTH+1)
	{
		line++;
		delim_delta++;
	}
	while (isspace(*line))
		line++;

	if (delim_delta > MAX_TITLE_DEPTH) /* invalid */
		return FALSE;

	*depth_ = delim_delta;

	/* find the end delimiter */
	end = line + strlen((const char *) line) - 1;
	while (end > line && isspace(*end)) end--;
	/* skip a possible label: \[[A-Za-z0-9_-]+\] */
	if (*end == ']')
	{
		end--;
		while (end > line && (isalnum(*end) || *end == '_' || *end == '-'))
			end--;
		if (*end != '[') /* invalid */
			return FALSE;
		end--;
	}
	while (end > line && *end == delim && delim_delta >= 0)
	{
		delim_delta--;
		end--;
	}
	while (end > line && isspace(*end)) end--;
	end++;

	/* if start and end delimiters are not identical, or the the name is empty */
	if (delim_delta != 0 || (end - line) <= 0)
		return FALSE;

	vStringNCopyS(title, (const char *) line, end - line);
	return TRUE;
}
Example #4
0
/* strip a possible PowerShell scope specification and convert it to accessType */
static const char *parsePowerShellScope (tokenInfo *const token)
{
	const char *access = ACCESS_UNDEFINED;
	const char *const tokenName = vStringValue (token->string);
	const char *powershellScopeEnd;

	powershellScopeEnd = strchr (tokenName, ':');
	if (powershellScopeEnd)
	{
		size_t powershellScopeLen;
		vString * powershellScope = vStringNew ();

		powershellScopeLen = (size_t)(powershellScopeEnd - tokenName);
		/* extract the scope */
		vStringNCopyS (powershellScope, tokenName, powershellScopeLen);
		/* cut the resulting scope string from the identifier */
		memmove (token->string->buffer,
				 /* +1 to skip the leading colon */
				 token->string->buffer + powershellScopeLen + 1,
				 /* +1 for the skipped leading colon and - 1 to include the trailing \0 byte */
				 token->string->length + 1 - powershellScopeLen - 1);
		token->string->length -= powershellScopeLen + 1;

		access = findValidAccessType (vStringValue (powershellScope));

		vStringDelete (powershellScope);
	}
	return access;
}
Example #5
0
static void
makeTag (struct p6Ctx *ctx, int kind, const char *name, int len)
{
    tagEntryInfo entry;
    vStringNCopyS(ctx->name, name, len);
    initTagEntry(&entry, vStringValue(ctx->name), &(perl6Kinds[kind]));
    makeTagEntry(&entry);
}
Example #6
0
static void
makeTag (struct p6Ctx *ctx, int kind, const char *name, int len)
{
    tagEntryInfo entry;
    vStringNCopyS(ctx->name, name, len);
    initTagEntry(&entry, vStringValue(ctx->name));
    entry.kind     = perl6Kinds[kind].letter;
    entry.kindName = perl6Kinds[kind].name;
    makeTagEntry(&entry);
}
Example #7
0
static void found_macro_cb (const char *line,
			    const regexMatch *matches,
			    unsigned int count,
			    void *uesrData)
{
	struct macro_cb_data *data = uesrData;

	if (count > 0)
	{
		vString *signature = ((count > 1) && (matches[2].length > 0))? vStringNew(): NULL;
		vString *name = vStringNew ();
		tagEntryInfo tag;

		if (signature)
			vStringNCopyS (signature, line + matches[2].start, matches[2].length);
		vStringNCopyS (name, line + matches[1].start, matches[1].length);

		if (data->rindex == ROLE_INDEX_DEFINITION)
			initTagEntry (&tag, vStringValue (name), &(RpmSpecKinds[data->kindex]));
		else
			initRefTagEntry (&tag, vStringValue (name), &(RpmSpecKinds[data->kindex]), data->rindex);

		if (signature)
			tag.extensionFields.signature = vStringValue (signature);

		/* Skip the definition */
		while (line && is_line_continued (line))
		{
			rejecting = TRUE;
			line = (const char *)readLineFromInputFile ();
		}
		rejecting = FALSE;

		tag.extensionFields.endLine = getInputLineNumber();

		makeTagEntry (&tag);

		vStringDelete (name);
		if (signature)
			vStringDelete (signature);
	}
}
Example #8
0
static void found_tag_cb (const char *line,
			  const regexMatch *matches,
			  unsigned int count,
			  void *userData)
{
	if (count > 0)
	{
		vString *name = vStringNew ();
		vStringNCopyS (name, line + matches[1].start, matches[1].length);
		makeSimpleTag (name, RpmSpecKinds, K_TAG);

		if (count > 1)
		{
			if (strcasecmp (vStringValue (name), "name") == 0)
			{
				vString *package = vStringNew ();
				vStringNCopyS (package, line + matches[2].start, matches[2].length);
				*((int *)userData) = makeSimpleTag (package, RpmSpecKinds, K_PACKAGE);
				vStringDelete (package);
			}
		}
		vStringDelete (name);
	}
}
Example #9
0
static void setOwnerDirectoryOfInputFile (const char *const fileName)
{
	const char *const head = fileName;
	const char *const tail = baseFilename (head);

	if (File.path != NULL)
		vStringDelete (File.path);
	if (tail == head)
		File.path = NULL;
	else
	{
		const size_t length = tail - head - 1;
		File.path = vStringNew ();
		vStringNCopyS (File.path, fileName, length);
	}
}
Example #10
0
File: main.c Project: koron/ctags
static boolean createTagsForWildcardEntry (
		const char *const pattern, const size_t dirLength,
		const char *const entryName)
{
	boolean resize = FALSE;
	/* we must not recurse into the directories "." or ".." */
	if (strcmp (entryName, ".") != 0  &&  strcmp (entryName, "..") != 0)
	{
		vString *const filePath = vStringNew ();
		vStringNCopyS (filePath, pattern, dirLength);
		vStringCatS (filePath, entryName);
		resize = createTagsForEntry (vStringValue (filePath));
		vStringDelete (filePath);
	}
	return resize;
}
Example #11
0
static void found_package_cb (const char *line,
			      const regexMatch *matches,
			      unsigned int count,
			      void *userData)
{
	if (count > 0)
	{
		vString *name = vStringNew ();
		tagEntryInfo tag;

		vStringNCopyS (name, line + matches[1].start, matches[1].length);
		initTagEntry (&tag, vStringValue (name), RpmSpecKinds + K_PACKAGE);
		tag.extensionFields.scopeIndex = *(int *)userData;
		makeTagEntry (&tag);
		vStringDelete (name);
	}
}
Example #12
0
static int parseHunk (const unsigned char* cp, vString *hunk, int scope_index)
{
    /*
       example input: @@ -0,0 +1,134 @@
       expected output: -0,0 +1,134
    */

    const char *next_delim;
    const char *start, *end;
    const char *c;
    int i = SCOPE_NIL;

    cp += 3;
    start = (const char*)cp;

    if (*start != '-')
        return i;

    next_delim = strstr ((const char*)cp, HunkDelim[1]);
    if ((next_delim == NULL)
            || (! (start < next_delim )))
        return i;
    end = next_delim;
    if (! ( '0' <= *( end - 1 ) && *( end - 1 ) <= '9'))
        return i;
    for (c = start; c < end; c++)
        if (*c == '\t')
            return i;
    vStringNCopyS (hunk, start, end - start);
    i = makeSimpleTag (hunk, DiffKinds, K_HUNK);
    if (i > SCOPE_NIL && scope_index > SCOPE_NIL)
    {
        tagEntryInfo *e =  getEntryInCorkQueue (i);
        e->extensionFields.scopeIndex = scope_index;
    }
    return i;
}
Example #13
0
/* Algorithm adapted from from GNU etags.
 * Locates tags for procedures & functions.  Doesn't do any type- or
 * var-definitions.  It does look for the keyword "extern" or "forward"
 * immediately following the procedure statement; if found, the tag is
 * skipped.
 */
static void findPascalTags (void)
{
	vString *name = vStringNew ();
	tagEntryInfo tag;
	pascalKind kind = K_FUNCTION;
		/* each of these flags is TRUE iff: */
	boolean incomment = FALSE;  /* point is inside a comment */
	int comment_char = '\0';    /* type of current comment */
	boolean inquote = FALSE;    /* point is inside '..' string */
	boolean get_tagname = FALSE;/* point is after PROCEDURE/FUNCTION
		keyword, so next item = potential tag */
	boolean found_tag = FALSE;  /* point is after a potential tag */
	boolean inparms = FALSE;    /* point is within parameter-list */
	boolean verify_tag = FALSE;
		/* point has passed the parm-list, so the next token will determine
		 * whether this is a FORWARD/EXTERN to be ignored, or whether it is a
		 * real tag
		 */

	dbp = readLineFromInputFile ();
	while (dbp != NULL)
	{
		int c = *dbp++;

		if (c == '\0')  /* if end of line */
		{
			dbp = readLineFromInputFile ();
			if (dbp == NULL  ||  *dbp == '\0')
				continue;
			if (!((found_tag && verify_tag) || get_tagname))
				c = *dbp++;
					/* only if don't need *dbp pointing to the beginning of
					 * the name of the procedure or function
					 */
		}
		if (incomment)
		{
			if (comment_char == '{' && c == '}')
				incomment = FALSE;
			else if (comment_char == '(' && c == '*' && *dbp == ')')
			{
				dbp++;
				incomment = FALSE;
			}
			continue;
		}
		else if (inquote)
		{
			if (c == '\'')
				inquote = FALSE;
			continue;
		}
		else switch (c)
		{
			case '\'':
				inquote = TRUE;  /* found first quote */
				continue;
			case '{':  /* found open { comment */
				incomment = TRUE;
				comment_char = c;
				continue;
			case '(':
				if (*dbp == '*')  /* found open (* comment */
				{
					incomment = TRUE;
					comment_char = c;
					dbp++;
				}
				else if (found_tag)  /* found '(' after tag, i.e., parm-list */
					inparms = TRUE;
				continue;
			case ')':  /* end of parms list */
				if (inparms)
					inparms = FALSE;
				continue;
			case ';':
				if (found_tag && !inparms)  /* end of proc or fn stmt */
				{
					verify_tag = TRUE;
					break;
				}
				continue;
		}
		if (found_tag && verify_tag && *dbp != ' ')
		{
			/* check if this is an "extern" declaration */
			if (*dbp == '\0')
				continue;
			if (tolower ((int) *dbp == 'e'))
			{
				if (tail ("extern"))  /* superfluous, really! */
				{
					found_tag = FALSE;
					verify_tag = FALSE;
				}
			}
			else if (tolower ((int) *dbp) == 'f')
			{
				if (tail ("forward"))  /*  check for forward reference */
				{
					found_tag = FALSE;
					verify_tag = FALSE;
				}
			}
			if (found_tag && verify_tag)  /* not external proc, so make tag */
			{
				found_tag = FALSE;
				verify_tag = FALSE;
				makePascalTag (&tag);
				continue;
			}
		}
		if (get_tagname)  /* grab name of proc or fn */
		{
			const unsigned char *cp;

			if (*dbp == '\0')
				continue;

			/* grab block name */
			while (isspace ((int) *dbp))
				++dbp;
			for (cp = dbp  ;  *cp != '\0' && !endtoken (*cp)  ;  cp++)
				continue;
			vStringNCopyS (name, (const char*) dbp,  cp - dbp);
			createPascalTag (&tag, name, kind);
			dbp = cp;  /* set dbp to e-o-token */
			get_tagname = FALSE;
			found_tag = TRUE;
			/* and proceed to check for "extern" */
		}
		else if (!incomment && !inquote && !found_tag)
		{
			switch (tolower ((int) c))
			{
				case 'c':
					if (tail ("onstructor"))
					{
						get_tagname = TRUE;
						kind = K_PROCEDURE;
					}
					break;
				case 'd':
					if (tail ("estructor"))
					{
						get_tagname = TRUE;
						kind = K_PROCEDURE;
					}
					break;
				case 'p':
					if (tail ("rocedure"))
					{
						get_tagname = TRUE;
						kind = K_PROCEDURE;
					}
					break;
				case 'f':
					if (tail ("unction"))
					{
						get_tagname = TRUE;
						kind = K_FUNCTION;
					}
					break;
			}
		}  /* while not eof */
	}
	vStringDelete (name);
}