#-------------------------------------------------------------------------------
#
#	Name    : C
#	Purpose : StrongED mode file for C source files
#	Author  :  Guttorm Vik
#	Licence : Freeware
#	Version : 1.04, 08-07-06
#
#	Compilation may be started with F10.
#
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Changes:
# 10.06.98 Made "{" a shortcut, which expands to brace set and places caret in the middle. (hmm)
# 16.06.98 Made "*/" a Syntaxword (group4), so it sticks out if the "/*" is missing.
# 29.06.98 Changed ListOfC button to not sort (since functions are often grouped logically)
#          In addition, Select now only searches *this* text, and adjust searches *all* texts.
# 29.06.98 Removed the ^H key binding for the 'load headerfile' function. This is now better
#          catered for by the clicklist (ctrl-Home or just doubleclick with mouse)
# 04.07.98 Dropped the ()'s from include1/2. Can now write A * @5 B
# 09.07.98 Removed the "{" shortcut again. Too damn annoying.
#          Added an "i(" shortcut
# 26.07.98 ctrl-Return will include any "/*" in its auto-indent.
# 22.10.98 Removed "*/" as reserved word. Clashed with " .. (char */*parm_name*/)
# 03.01.99 Removed duplicate 'do' and 'default' from Group1
# 21.07.00 Added #warning and #elif to the directives group (carl)
# 22.08.01 Updated HelpPath
# 03.11.02 Updated HelpPath again
# 22.07.03 Group3 (preprocessor directives) now uses expression
# 22.07.03 Group1 was missing "case", part of switch..case..default
# 31.12.05 Added _ParPrefix to allow comments to be reformatted using hardwrap
# 04.07.06 Changed include1 and include2 for use with Andrew Hodgkinson's tools
#          Changed clicklist entries for include1 and include2 accordingly
#          Moved support for Philip Ludlam's LoadHdr to c-Select2 clicklist
#          Combined goto next/previous function in a single toolbar icon
#          Added option to look in current file only to Goto function definition
#          Added SmartIndent section, commented out initially
#-------------------------------------------------------------------------------

HelpPath	C-Version5,C++,C,OS,Wimp,MiscSWIs,InetSWIs,InetSocket,VDU,Toolbox,Desk,OSLib,UnixLib,

Foldparm1	("/*{{{","/*}}}",StartSpace,Case)

#-------------------------------------------------------------------------------

Search
#	include1	[_spct] "#include" _spct "<" [_spct] @0 * @9 ".H" [_spct] ">"
#	include2	[_spct] "#include" _spct '"' [_spct] @0 * @9 ".H" [_spct] '"'

	include1	[_spct] "#include" _spct ('"') [_spct] @0 * @9 ('"')
	include2	[_spct] "#include" _spct ('<') [_spct] @0 * @9 ('>')
	include3	[_spct] "#include" _spct '"' [_spct] @0 * @9 ".H" [_spct] '"'

	isblock		inblock .
	iscomment	"/*"
	wholecomment	"/*" ** "*/"
	preprocessor_	{" "} ("include" | "ifdef" | "ifndef" | "if" | "else" | "endif" | "pragma" | "line" | "error" | "define" | "undef" | "warning" | "elif")
	preprocessor	"#" preprocessor_
	Function	< {" "} ~"else" ~"return" AD|"_" {'_A-Za-z0-9'}{' *'} AD|"_" {'_A-Za-z0-9'} {" "} "(" * ")" {\s} "{"

#	Function	@0 AD|"_" {'_A-Za-z0-9'} @9 {" "} "(" * ")" {\s} \{
#	GoFunction	@0 CW {" "} "(" * ")" {\s} \{

	Spaces		{' '}
	Comments	{"//"}
	_ParPrefix	< Spaces Comments @1 @2 Spaces
	_Indent2	{" "} [ "/*" | "//" ] {" "}
End

#-------------------------------------------------------------------------------

ClickList
#	include1	LoadOne ("C:H.<tmp$word>")
#	include2	LoadOne ("<tmp$path>.^.H.<tmp$word>")
	include1	SetTmp(include1, "StrongED$Tmp_MarkWord") Run("<StrongED$Tmp_ModePath>.Tools.LoadHdrLcl")
	include2	SetTmp(include2, "StrongED$Tmp_MarkWord") Run("<StrongED$Tmp_ModePath>.Tools.LoadHdrGbl")
	iscomment	NoIndent MarkWord(WholeComment) GotoBlock_End CaretLeft CaretLeft DeleteRight DeleteRight GotoBlock_Start DeleteRight DeleteRight BlockClear
	isblock		NoIndent GotoBlock_Start "/*" GotoBlock_End "*/"
End

ClickList c-Select2
	include3	SetTmp(include3, "StrongED$Tmp_MarkWord") Run("<StrongED$Tmp_ModePath>.Tools.LoadHdr")

End

#-------------------------------------------------------------------------------

ID_FirstChar	A-Za-z_
ID_Middle	A-Za-z_0-9

SyntaxOptions
	SingleQuote	Yes
	DoubleQuote	Yes
	QuoteChar	\
	QuoteQuote	No
	SplitString	Yes
	HexPrefix	0x
End

SyntaxComment 1
	Type		MultiLine
	StartWith	/*
	EndWith		*/
End

SyntaxComment 2
	Type		OneLine
	StartWith	//
End

SyntaxWords Group1 case
	continue
	for while break return goto
	if else switch do default case
End

SyntaxWords Group2 case
	auto register static extern typedef
	void char short int long float double signed unsigned
	const volatile
	struct union
End

SyntaxWords Group3 nocase EndOfExpr preprocessor_
	#
End

SyntaxWords Group4 nocase EndAlways
	& *
End

SyntaxWords Group5 case
	namespace public private friend operator class :: ~
End


## Make sure superfluous comment-end's stick out
#
#SyntaxWords Group6 nocase
#	"*/"
#End

#-------------------------------------------------------------------------------

KeyList
	^[		InsertStr("/*")
	^]		InsertStr("*/")
#	Return		Clicklist("indent")
	^Return		NewLine(indent,_Indent2)
End

#-------------------------------------------------------------------------------

Functions
	Icon		LoF
	Menu		List of functions F2
	Help		HCM_lof
	Key		F2
	Select		ListOfC(Text)

	Adjust		ListOfC(All)

	Select 	ListOfFound( Function, Text, Whole, NoLine, Case, Nosort )

	Adjust 	ListOfFound( Function, All, Whole, NoLine, Case, Nosort )

	Icon		updown
	Help		HCM_updn
	Key 		^PgDown
	Select		GotoNextC(Text)

	Key 		^PgUp
	Adjust		GotoPrevC(Text)

	Icon		load
	Menu		Load H.*
	Help		HCM_load
#	Key		^H
	Select		SetTmp() LoadOne("<tmp$path>.^.H.<tmp$word>","C:H.<tmp$word>")

	Icon		Run
	Menu		Save & Compile      F10
	Help		HCM_run
	Key		F10
#	Select		SaveDrag ("cc")
	Select		SetTmp() SaveRun("taskwindow \"gcc <tmp$path>.<tmp$leaf> -mthrowback\" -wimpslot 8000K")

	Icon		brick
	Menu		Save & Make      ^F10
	Help		HCM_mak
	Key		^F10
	Select		SetTmp() SaveDClick("<tmp$path>.^.Makefile")

	Icon		goto
	Menu		Goto function definition
	Help		HCM_go
	Key		^G 1
	Select		Push GotoFoundC(Text)

	Key		^G 2
	Adjust		Push GotoFoundC(All)

#	Key		^G 1
#	Select		Push GotoFound( GoFunction, Text, Whole, Line, Case, NoSort)

#	Key		^G 2
#	Adjust		Push GotoFound( GoFunction, All, Whole, Line, Case, NoSort )

	^Select	Pop()

	^Adjust	Pop()
End

#-------------------------------------------------------------------------------

Shortcuts
	w(	while (\@) {\n\i  \@\n\i}
	f(	for (\@;\@;\@) {\n\i  \@\n\i}
	s(	switch (\@) {\n\i  case \@\n\i}
	p(	printf("\@");
	i(	if(\@) \@
	#<	#include <\@.h>\n\@
	#"	#include "\@.h"\n\@
	``-	/*----------------------------------------------------------------------------*/
	``/	/*--- \@  */
	``*	/* \@  */
End

#-------------------------------------------------------------------------------

#SmartIndent
#	IndentSize	4
#	IndentChar	{
#	OutdentChar	}
#End
