示例#1
0
文件: parse.c 项目: FelikZ/ctags
extern langType getFileLanguage (const char *const fileName)
{
	langType language = Option.language;
	if (language == LANG_AUTO)
	{
		language = getExtensionLanguage (fileExtension (fileName));
		if (language == LANG_IGNORE)
			language = getPatternLanguage (fileName);
#ifdef SYS_INTERPRETER
		if (language == LANG_IGNORE)
		{
			fileStatus *status = eStat (fileName);
			if (status->isExecutable)
				language = getInterpreterLanguage (fileName);
		}
#endif
	}
	return language;
}
示例#2
0
文件: parse.c 项目: b4n/fishman-ctags
extern langType getFileLanguage (const char *const fileName)
{
	langType language = Option.language;
	if (language == LANG_AUTO)
	{
		vString* spec;
		FILE* input;

		language = LANG_IGNORE;
		verbose ("Get file language for %s\n", fileName);

		input = fopen (fileName, "rb");
		{
			const char* baseName = baseFilename (fileName);
			verbose ("	pattern: %s\n", baseName);
			language = getPatternLanguage (baseName, input);
			if (input)
				rewind (input);
			else
				goto template_file;
		}

		if (language == LANG_IGNORE && (spec = extracEmacsModeAtFirstLine (input)))
		{
			verbose ("	emacs mode at the first line: %s\n", vStringValue (spec));
			language = getSpecLanguage (vStringValue (spec), input);
			vStringDelete (spec);
		}
		rewind(input);

		if (language == LANG_IGNORE && (spec = extractInterpreter (input)))
		{
			verbose ("	interpreter: %s\n", vStringValue (spec));
			language = getSpecLanguage (vStringValue (spec), input);
			vStringDelete (spec);
		}
		rewind(input);

		if (language == LANG_IGNORE && (spec = extractEmacsModeLanguageAtEOF (input)))
		{
			verbose ("	emacs mode at the EOF: %s\n", vStringValue (spec));
			language = getSpecLanguage (vStringValue (spec), input);
			vStringDelete (spec);
		}
		rewind(input);

		if (language == LANG_IGNORE && (spec = extractVimFileType (input)))
		{
			verbose ("	vim modeline: %s\n", vStringValue (spec));
			language = getSpecLanguage (vStringValue (spec), input);
			vStringDelete (spec);
		}
		rewind(input);

	  template_file:
		if (language == LANG_IGNORE)
		{
			const char* const tExt = ".in";
			char* baseName = baseFilenameSansExtensionNew (fileName, tExt);
			if (baseName)
			{
				verbose ("	pattern + template(%s): %s\n", tExt, baseName);
				language = getPatternLanguage(baseName, input);
				eFree (baseName);
			}
		}

		if (input)
			fclose (input);
	}
	return language;
}