<glimmer-definition>
   <settings>
      <language>C</language>
      <compiler>glimmerout gcc -g %2 -o %3 2&gt;&amp;1</compiler>
      <debugger>%term% gdb %3</debugger>
      <execution>%term% %1/%3</execution>
      <auto-indent>1</auto-indent>
      <use-spaces>0</use-spaces>
      <tab-stop>4</tab-stop>
   </settings>

   <mime-types>
      <extension>c</extension>
      <extension>h</extension>
      <extension>m</extension>
      <mime-type>text/x-c</mime-type>
   </mime-types>

   <syntax-items>
      <syntax-item>
         <name>cpp-comment</name>
         <start-regex>//</start-regex>
         <end-regex>\n</end-regex>
         <style>comment</style>
      </syntax-item>
      <syntax-item>
         <name>c-comment</name>
         <start-regex>/\*</start-regex>
         <end-regex>\*/</end-regex>
         <style>comment</style>
      </syntax-item>
      <syntax-item>
         <name>defs_full</name>
         <start-regex>^#\ *\t*\(include\|pragma\)</start-regex>
         <end-regex>\(\n\)</end-regex>
         <style>preprocessor</style>
      </syntax-item>
      <syntax-item>
         <name>string</name>
         <start-regex>&quot;</start-regex>
         <end-regex>\(&quot;\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>define_comment</name>
         <start-regex>^#if 0</start-regex>
         <end-regex>^#endif</end-regex>
         <style>comment</style>
      </syntax-item>
   </syntax-items>

   <pattern-items>
      <pattern-item>
         <name>chars</name>
         <regex>&apos;\\?[a-zA-Z0-9_\\()#@!$%^&amp;*-=+&quot;{}&lt;&gt;]&apos;</regex>
         <style>char_string</style>
      </pattern-item>
      <pattern-item>
         <name>defs</name>
         <regex>^#\ *\t*\(if\|ifdef\|ifndef\|else\|elif\|define\|endif\|undef\)\b</regex>
         <style>preprocessor</style>
      </pattern-item>
      <pattern-item>
         <name>typedefs</name>
         <regex>\b\(char\|double\|float\|int\|long\|register\|short\|unsigned\)\b</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>keywords</name>
         <regex>\b\(asm\|auto\|break\|case\|const\|continue\|default\|do\|else\|enum\|extern\|for\|goto\|if\|return\|signed\|sizeof\|static\|struct\|switch\|typedef\|union\|unsigned\|void\|volotile\|while\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>glib</name>
         <regex>\b\(gint\|gfloat\|gdouble\|gboolean\|gchar\|gpointer\|guint\|guchar\|GList\|GSList\|GHash\|GString\|GModule\|GTable\|GTree\)\b</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>macros</name>
         <regex>\b[A-Z_][A-Z0-9_\-]+\b</regex>
         <style>macro</style>
      </pattern-item>
      <pattern-item>
         <name>gui-types</name>
         <regex>\b\(Gtk\|Gds\|Gdk\|Gnome\)[a-zA-Z0-9_]+</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>gui-funcs</name>
         <regex>\b\(gtk\|gdk\|g\|gnome\|gds\)_[a-zA-Z0-9_]+</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>bonobo-types</name>
         <regex>\bBonobo[a-zA-Z0-9_]+</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>bonobo-calls</name>
         <regex>\bbonobo_[a-zA-Z0-9_]+</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>labels</name>
         <regex>^[a-zA-Z_]*:</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>whole_numbers1</name>
         <regex>\b[0-9]\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>whole_numbers2</name>
         <regex>\b[1-9][0-9]*\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>float_numbers1</name>
         <regex>\.\b[0-9]+\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>float_numbers2</name>
         <regex>\b[0-9]*\.\W</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>hex_numbers</name>
         <regex>\b0x[0-9a-fA-F]+\b</regex>
         <style>hexidecimal</style>
      </pattern-item>
      <pattern-item>
         <name>oct_numbers</name>
         <regex>\b0[0-7]+\b</regex>
         <style>octal</style>
      </pattern-item>
      <pattern-item>
         <name>bin_numbers</name>
         <regex>\b0[01]+\b</regex>
         <style>octal</style>
      </pattern-item>
      <pattern-item>
         <name>operators</name>
         <regex>\(\*\|\*\*\|-&gt;\|::\|&gt;&gt;\|&lt;&lt;\|&gt;\|&lt;\|=\|==\|!=\|&lt;=\|&gt;=\|++\|--\|%\|+\|-\|||\|&amp;&amp;\|!\|+=\|-=\|\*=\|/=\|%=\|~\)</regex>
         <style>operator</style>
      </pattern-item>
      <pattern-item>
         <name>punctuation</name>
         <regex>\((\|)\|;\|:\|{\|}\|,\|\[\|\]\|\.\)</regex>
         <style>punctuation</style>
      </pattern-item>
   </pattern-items>
</glimmer-definition>

<python-definition>
import glimmer
import string

def c_enter_callback():
    insert = "\n"
    extralen = 0
    slen = 0
    file = glimmer.get_file_number()
    tstart = glimmer.line_start()
    tend = glimmer.current_position()
    if (tend-tstart) > 0:
        chars = glimmer.get_text(tstart, tend)
        slen = len(chars)
        if slen > 0:
            index = 0
            while index < slen:
                c = chars[index]
                if c == '\t' or c == ' ':
                    insert = insert + chars[index]
                    index = index+1
                else:
                    break
            c = chars[slen-1]
            if c == '{':
                extralen = glimmer.get_file_tab_width(file)
                if glimmer.get_file_use_spaces(file):
                    while extralen > 0:
                        insert = insert + " "
                        extralen = extralen-1
                else:
                    insert = insert + '\t'
    glimmer.insert(insert)

def c_tab_callback():
   tablen = 0
   insertchars = ""
   file = glimmer.get_file_number()
   if glimmer.get_file_use_spaces(file):
      tablen = glimmer.get_file_tab_width(file)
      pos = glimmer.current_position()
      lstart = glimmer.line_start()
      if pos - lstart > 0:
         str1 = glimmer.get_text(lstart, pos)
      else:
         str1 = ""
      if glimmer.get_tab_stops():
         str1 = string.expandtabs(str1, tablen)
         len1 = len(str1)
         del str1
         tablen = tablen - (len1 % tablen)
      while tablen > 0:
         insertchars = insertchars + " "
         tablen = tablen-1
   else:
      insertchars = insertchars + "\t"
   glimmer.insert(insertchars)

def insert_comment():
    glimmer.freeze()
    if glimmer.has_selection():
        start = glimmer.selection_start()
        end = glimmer.selection_end()
        file = glimmer.get_file_number()
        glimmer.move(0)
        glimmer.insert_in(file, start, "/* ")
        glimmer.insert_in(file, end+3, " */")
        glimmer.move_to(end+6)
    else:
        glimmer.insert("/*\n *\n*/")
        glimmer.move(-3)
    glimmer.thaw()

def open_c_header():
    import string
    file = 0
    fname = ""
    file = glimmer.get_file_number()
    fname = glimmer.get_filename(file)
    path = ""
    noext = ""
    fullfile = ""
    openfile = 0
    if string.count(fname, ".c"):
       openfile = 1
       path = glimmer.get_path(file)
       noext = glimmer.get_file(file)
       fullfile = path + "/" + noext + ".h"
    elif string.count(fname, ".h"):
        openfile = 1
        path = glimmer.get_path(file)
        noext = glimmer.get_file(file)
        fullfile = path + "/" + noext + ".c"
    if openfile:
        openedfile = open(fullfile)
        if openedfile:
            del openedfile
            glimmer.open_file(fullfile)

glimmer.register_signal_hook("enter-pressed", c_enter_callback)
glimmer.register_signal_hook("tab-pressed", c_tab_callback)

glimmer.add_sub_to_menu("_Insert/", "C", -1)
glimmer.add_item_to_menu("_Insert/C/", "Comment (C)", "", "", -1, insert_comment)
glimmer.add_item_to_popup_menu("Open Reverse", -1, open_c_header)
glimmer.add_item_to_popup_menu("Comment (C)", -1, insert_comment)
</python-definition>
