Tony Balinski wrote:

Seems reasonable to me, though, at a glance, it seems you have an off-by-1
error if your name is too long (you copy up to size characters *then* add
a '\0' at the end). 

   Yep.

Another thing is the expression isalnum((int)*name).
If char is signed (I think it is/was(?) with Sun's compiler), this can
cause problems, especially with the old-fashioned macro implementation of
ctype.h. Better to use isalnum((unsigned char)*name) instead to be
explicit. You'll see that construct used elsewhere (but not systematically)
in nedit code.
  

   I am in the habit of casting it to int because some compilers (e.g.
   gcc) complain when an int is not passed to these macros.  Anyway, I
   don't think being a signed char will matter.  If the eighth bit is set
   (*name & 0x80), then isalnum will fail, regardless of the casting.
   Nevertheless, change it as you feel necessary.

Opinions?
    

I for one will give it a whirl. Just out of interest, why do you want to
color these menu entries separately?
  

   Attached are my NEdit resource file and my nedit.rc file.  Try them
   and press the popup menu.  You will see that I have two groups of 3
   buttons.  The first set is the classic cut-copy-paste.  The second set
   of buttons jump to a spot in the file using the selected text.  I like
   to emphasize the grouping.  In most gui apps, menus group buttons with
   separators.  Since separators are not available, colors do the trick.
   (I admit my color selection may not be the best.)  Also, I group
   buttons on the customized shell menu.
   Of course, in general, it is better that the widgets get unique names
   so the user can customize the widgets via the resource file.
   -David
! Preferences file for NEdit
!
! This file is overwritten by the "Save Defaults..." command in NEdit 
! and serves only the interactively settable options presented in the NEdit
! "Preferences" menu.  To modify other options, such as key bindings, use 
! the .Xdefaults file in your home directory (or the X resource 
! specification method appropriate to your system).  The contents of this 
! file can be moved into an X resource file, but since resources in this file
! override their corresponding X resources, either this file should be 
! deleted or individual resource lines in the file should be deleted for the
! moved lines to take effect.

nedit.fileVersion: 5.5
nedit.shellCommands: \
        spell:Alt+B:s:ED:\n\
                (cat;echo "") | spell\n\
        make:Alt+Z:m:W:\n\
                make\n\
        pwd:::D:\n\
                pwd\n\
        Indent:::IX:\n\
                sed 's/^/       /'\n\
        Remove indent:::IX:\n\
                sed 's/^        //'\n\
        Center:::I:\n\
                center\n\
        Remove ALL Indents:::I:\n\
                sed 's/^[       ]*//'\n\
        info:::D:\n\
                env_info\n\
        Justify:::IX:\n\
                fmt\n\
        Comment Out:::IX:\n\
                comment %\n\
        Uncomment Out:::IX:\n\
                uncomment\n\
        ifdef DEBUG:::IX:\n\
                ifdef DEBUG\n\
        ifndef DEBUG:::IX:\n\
                ifndef DEBUG\n\
        File Header::::\n\
                header %\n\
        Function Header::::\n\
                header_function %\n\
        Class Header::::\n\
                header_class\n
nedit.macroCommands: \
        Complete Word:Alt+D::: {\n\
                # Tuning parameters\n\
                ScanDistance = 200\n\
                \n\
                # Search back to a word boundary to find the word to complete\n\
                startScan = max(0, $cursor - ScanDistance)\n\
                endScan = min($text_length, $cursor + ScanDistance)\n\
                scanString = get_range(startScan, endScan)\n\
                keyEnd = $cursor-startScan\n\
                keyStart = search_string(scanString, "<", keyEnd, "backward", 
"regex")\n\
                if (keyStart == -1)\n\
                    return\n\
                keyString = "<" substring(scanString, keyStart, keyEnd)\n\
                \n\
                # search both forward and backward from the cursor position.  
Note that\n\
                # using a regex search can lead to incorrect results if any of 
the special\n\
                # regex characters is encountered, which is not considered a 
delimiter\n\
                backwardSearchResult = search_string(scanString, keyString, 
keyStart-1, \\\n\
                        "backward", "regex")\n\
                forwardSearchResult = search_string(scanString, keyString, 
keyEnd, "regex")\n\
                if (backwardSearchResult == -1 && forwardSearchResult == -1) 
{\n\
                    beep()\n\
                    return\n\
                }\n\
                \n\
                # if only one direction matched, use that, otherwise use the 
nearest\n\
                if (backwardSearchResult == -1)\n\
                    matchStart = forwardSearchResult\n\
                else if (forwardSearchResult == -1)\n\
                    matchStart = backwardSearchResult\n\
                else {\n\
                    if (keyStart - backwardSearchResult <= forwardSearchResult 
- keyEnd)\n\
                        matchStart = backwardSearchResult\n\
                    else\n\
                        matchStart = forwardSearchResult\n\
                }\n\
                \n\
                # find the complete word\n\
                matchEnd = search_string(scanString, ">", matchStart, 
"regex")\n\
                completedWord = substring(scanString, matchStart, matchEnd)\n\
                \n\
                # replace it in the window\n\
                replace_range(startScan + keyStart, $cursor, completedWord)\n\
        }\n\
        Fill Sel. w/Char:::R: {\n\
                if ($selection_start == -1) {\n\
                    beep()\n\
                    return\n\
                }\n\
                \n\
                # Ask the user what character to fill with\n\
                fillChar = string_dialog("Fill selection with what character?", 
"OK", "Cancel")\n\
                if ($string_dialog_button == 2 || $string_dialog_button == 0)\n\
                    return\n\
                \n\
                # Count the number of lines in the selection\n\
                nLines = 0\n\
                for (i=$selection_start; i<$selection_end; i++)\n\
                    if (get_character(i) == "\\n")\n\
                        nLines++\n\
                \n\
                # Create the fill text\n\
                rectangular = $selection_left != -1\n\
                line = ""\n\
                fillText = ""\n\
                if (rectangular) {\n\
                    for (i=0; i<$selection_right-$selection_left; i++)\n\
                        line = line fillChar\n\
                    for (i=0; i<nLines; i++)\n\
                        fillText = fillText line "\\n"\n\
                    fillText = fillText line\n\
                } else {\n\
                    if (nLines == 0) {\n\
                        for (i=$selection_start; i<$selection_end; i++)\n\
                            fillText = fillText fillChar\n\
                    } else {\n\
                        startIndent = 0\n\
                        for (i=$selection_start-1; i>=0 && 
get_character(i)!="\\n"; i--)\n\
                            startIndent++\n\
                        for (i=0; i<$wrap_margin-startIndent; i++)\n\
                            fillText = fillText fillChar\n\
                        fillText = fillText "\\n"\n\
                        for (i=0; i<$wrap_margin; i++)\n\
                            line = line fillChar\n\
                        for (i=0; i<nLines-1; i++)\n\
                            fillText = fillText line "\\n"\n\
                        for (i=$selection_end-1; i>=$selection_start && 
get_character(i)!="\\n"; \\\n\
                                i--)\n\
                            fillText = fillText fillChar\n\
                    }\n\
                }\n\
                \n\
                # Replace the selection with the fill text\n\
                replace_selection(fillText)\n\
        }\n\
        Comments>/* Comment */@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]:::R: {\n\
                selStart = $selection_start\n\
                selEnd = $selection_end\n\
                replace_range(selStart, selEnd, "/* " get_selection() " */")\n\
                select(selStart, selEnd + 6)\n\
        }\n\
        Comments>/* Uncomment */@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]:::R: {\n\
                sel = get_selection()\n\
                selStart = $selection_start\n\
                selEnd = $selection_end\n\
                commentStart = search_string(sel, "/*", 0)\n\
                if (substring(sel, commentStart + 2, commentStart + 3) == " 
")\n\
                    keepStart = commentStart + 3\n\
                else\n\
                    keepStart = commentStart + 2\n\
                keepEnd = search_string(sel, "*/", length(sel), "backward")\n\
                commentEnd = keepEnd + 2\n\
                if (substring(sel, keepEnd - 1, keepEnd) == " ")\n\
                    keepEnd = keepEnd - 1\n\
                replace_range(selStart + commentStart, selStart + commentEnd, 
\\\n\
                        substring(sel, keepStart, keepEnd))\n\
                select(selStart, selEnd - (keepStart-commentStart) - \\\n\
                        (commentEnd - keepEnd))\n\
        }\n\
        Comments>// [EMAIL PROTECTED]@[EMAIL PROTECTED]@JavaScript:::R: {\n\
                replace_in_selection("^.*$", "// &", "regex")\n\
        }\n\
        Comments>// [EMAIL PROTECTED]@[EMAIL PROTECTED]@JavaScript:::R: {\n\
                replace_in_selection("(^[ \\\\t]*// ?)(.*)$", "\\\\2", 
"regex")\n\
        }\n\
        Comments># [EMAIL PROTECTED]@Sh Ksh [EMAIL PROTECTED] [EMAIL 
PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]:::R: {\n\
                replace_in_selection("^.*$", "#&", "regex")\n\
        }\n\
        Comments># [EMAIL PROTECTED]@Sh Ksh [EMAIL PROTECTED] [EMAIL 
PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]:::R: {\n\
                replace_in_selection("(^[ \\\\t]*#)(.*)$", "\\\\2", "regex")\n\
        }\n\
        Comments>-- [EMAIL PROTECTED]:::R: {\n\
                replace_in_selection("^.*$", "--&", "regex")\n\
        }\n\
        Comments>-- [EMAIL PROTECTED]:::R: {\n\
                replace_in_selection("(^[ \\\\t]*--)(.*)$", "\\\\2", "regex")\n\
        }\n\
        Comments>! [EMAIL PROTECTED] Resources:::R: {\n\
                replace_in_selection("^.*$", "!&", "regex")\n\
        }\n\
        Comments>! [EMAIL PROTECTED] Resources:::R: {\n\
                replace_in_selection("(^[ \\\\t]*!)(.*)$", "\\\\2", "regex")\n\
        }\n\
        Comments>% [EMAIL PROTECTED]:::R: {\n\
                                replace_in_selection("^.*$", "%&", "regex")\n\
                                }\n\
        Comments>% [EMAIL PROTECTED]:::R: {\n\
                                replace_in_selection("(^[ \\\\t]*%)(.*)$", 
"\\\\2", "regex")\n\
                                }\n\
        Comments>Bar [EMAIL PROTECTED]:::R: {\n\
                if ($selection_left != -1) {\n\
                    dialog("Selection must not be rectangular")\n\
                    return\n\
                }\n\
                start = $selection_start\n\
                end = $selection_end-1\n\
                origText = get_range($selection_start, $selection_end-1)\n\
                newText = "/*\\n" replace_in_string(get_range(start, end), \\\n\
                        "^", " * ", "regex") "\\n */\\n"\n\
                replace_selection(newText)\n\
                select(start, start + length(newText))\n\
        }\n\
        Comments>Bar [EMAIL PROTECTED]:::R: {\n\
                selStart = $selection_start\n\
                selEnd = $selection_end\n\
                newText = get_range(selStart+3, selEnd-4)\n\
                newText = replace_in_string(newText, "^ \\\\* ", "", "regex")\n\
                replace_range(selStart, selEnd, newText)\n\
                select(selStart, selStart + length(newText))\n\
        }\n\
        Make C [EMAIL PROTECTED]@C++:::: {\n\
                if ($selection_start == -1) {\n\
                    start = 0\n\
                    end = $text_length\n\
                } else {\n\
                    start = $selection_start\n\
                    end = $selection_end\n\
                }\n\
                string = get_range(start, end)\n\
                nDefs = 0\n\
                searchPos = 0\n\
                prototypes = ""\n\
                staticPrototypes = ""\n\
                for (;;) {\n\
                    headerStart = search_string(string, \\\n\
                            "^[a-zA-Z]([^;#\\"'{}=><!/]|\\n)*\\\\)[ \\t]*\\n?[ 
\\t]*\\\\{", \\\n\
                            searchPos, "regex")\n\
                    if (headerStart == -1)\n\
                        break\n\
                    headerEnd = search_string(string, ")", 
$search_end,"backward") + 1\n\
                    prototype = substring(string, headerStart, headerEnd) 
";\\n"\n\
                    if (substring(string, headerStart, headerStart+6) == 
"static")\n\
                        staticPrototypes = staticPrototypes prototype\n\
                    else\n\
                                        prototypes = prototypes prototype\n\
                    searchPos = headerEnd\n\
                    nDefs++\n\
                }\n\
                if (nDefs == 0) {\n\
                    dialog("No function declarations found")\n\
                    return\n\
                }\n\
                new()\n\
                focus_window("last")\n\
                replace_range(0, 0, prototypes staticPrototypes)\n\
        }\n
nedit.bgMenuCommands: \
        Cut:::R: {\n\
                cut_clipboard()\n\
        }\n\
        Copy:::R: {\n\
                copy_clipboard()\n\
        }\n\
        Paste:::: {\n\
                paste_clipboard()\n\
        }\n\
        Find foreward:::: {\n\
                find_selection("foreward")\n\
        }\n\
        Find backward:::: {\n\
                find_selection("backward")\n\
        }\n\
        Goto line:::: {\n\
                goto_selected()\n\
        }\n
nedit.highlightPatterns: Ada:Default\n\
        Awk:Default\n\
        C++:Default\n\
        C:Default\n\
        CSS:Default\n\
        Csh:Default\n\
        Fortran:Default\n\
        Java:Default\n\
        JavaScript:Default\n\
        LaTeX:Default\n\
        Lex:Default\n\
        Makefile:Default\n\
        Matlab:Default\n\
        NEdit Macro:Default\n\
        Pascal:Default\n\
        Perl:Default\n\
        PostScript:Default\n\
        Python:Default\n\
        Regex:Default\n\
        SGML HTML:Default\n\
        SQL:Default\n\
        Sh Ksh Bash:Default\n\
        Tcl:Default\n\
        VHDL:Default\n\
        Verilog:Default\n\
        XML:Default\n\
        X Resources:Default\n\
        Yacc:Default
nedit.languageModes:    Ada:.ada .ad .ads .adb .a:::::::\n\
        Awk:.awk:::::::\n\
        C++:.cc .hh .C .H .i .cxx .hxx .cpp 
.c++::::::".,/\\`'!|@#%^&*()-=+{}[]"":;<>?~":\n\
        C:.c .h::::::".,/\\`'!|@#%^&*()-=+{}[]"":;<>?~":\n\
        CSS:css::Auto:None:::".,/\\`'!|@#%^&*()=+{}[]"":;<>?~":\n\
        Csh:.csh .cshrc .login .logout:"^[ \\t]*#[ \\t]*![ 
\\t]*/bin/csh"::::::\n\
        Fortran:.f .f77 .for:::::::\n\
        Java:.java:::::::\n\
        JavaScript:.js:::::::\n\
        LaTeX:.tex .sty .cls .ltx .ins:::::::\n\
        Lex:.lex:::::::\n\
        Makefile:Makefile makefile .gmk:::None:8:8::\n\
        Matlab:.m .oct .sci:::::::\n\
        NEdit Macro:.nm .neditmacro:::::::\n\
        Pascal:.pas .p .int:::::::\n\
        Perl:.pl .pm .p5 .PL:"^[ \\t]*#[ 
\\t]*!.*perl":Auto:None:::".,/\\\\`'[EMAIL PROTECTED]&*()-=+{}[]"":;<>?~|":\n\
        PostScript:.ps .eps .epsf .epsi:"^%!":::::"/%(){}[]<>":\n\
        Python:.py:"^#!.*python":Auto:None:::"!""#$%&'()*+,-./:;<=>[EMAIL 
PROTECTED]|}~":\n\
        Regex:.reg .regex:"\\(\\?[:#=!iInN].+\\)":None:Continuous::::\n\
        SGML HTML:.sgml .sgm .html .htm:"\\<[Hh][Tt][Mm][Ll]\\>"::::::\n\
        SQL:.sql:::::::\n\
        Sh Ksh Bash:.sh .bash .ksh .profile .bashrc .bash_logout .bash_login 
.bash_profile:"^[ \\t]*#[ \\t]*![ \\t]*/.*bin/(bash|ksh|sh|zsh)"::::::\n\
        Tcl:.tcl .tk .itcl .itk::Smart:None::::\n\
        VHDL:.vhd .vhdl .vdl:::::::\n\
        Verilog:.v:::::::\n\
        XML:.xml .xsl .dtd:"\\<(?i\\?xml|!doctype)"::None:::"<>/=""'()+*?|":\n\
        X Resources:.Xresources .Xdefaults 
.nedit:"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults"::::::\n\
        Yacc:.y::::::".,/\\`'!|@#%^&*()-=+{}[]"":;<>?~":
nedit.styles:   Plain:black:Plain\n\
        Comment:DarkOliveGreen:Plain\n\
        Keyword:black:Plain\n\
        Storage Type:brown:Plain\n\
        Storage Type1:saddle brown:Plain\n\
        String:darkGreen:Plain\n\
        String1:SeaGreen:Plain\n\
        String2:darkGreen:Plain\n\
        Preprocessor:RoyalBlue4:Plain\n\
        Preprocessor1:blue:Plain\n\
        Character Const:darkGreen:Plain\n\
        Numeric Const:darkGreen:Plain\n\
        Identifier:brown:Plain\n\
        Identifier1:RoyalBlue4:Plain\n\
        Identifier2:SteelBlue:Plain\n\
        Subroutine:brown:Plain\n\
        Subroutine1:chocolate:Plain\n\
        Ada Attributes:plum:Bold\n\
        Label:red:Plain\n\
        Flag:red:Plain\n\
        Text Comment:DarkOliveGreen:Plain\n\
        Text Key:VioletRed4:Plain\n\
        Text Key1:VioletRed4:Plain\n\
        Text Arg:RoyalBlue4:Plain\n\
        Text Arg1:SteelBlue4:Plain\n\
        Text Arg2:RoyalBlue4:Plain\n\
        Text Escape:gray30:Bold\n\
        LaTeX Math:darkGreen:Plain\n\
        Pointer:#660000:Bold\n\
        Regex:#009944:Bold\n\
        Warning:brown2:Italic
nedit.smartIndentInit:  C:Default\n\
        C++:Default\n\
        Python:Default\n\
        Matlab:Default
nedit.smartIndentInitCommon: Default
nedit.autoWrap: Continuous
nedit.wrapMargin: 0
nedit.autoIndent: Auto
nedit.autoSave: True
nedit.openInTab: True
nedit.saveOldVersion: False
nedit.showMatching: Range
nedit.matchSyntaxBased: True
nedit.highlightSyntax: True
nedit.backlightChars: False
nedit.searchDialogs: False
nedit.beepOnSearchWrap: False
nedit.retainSearchDialogs: True
nedit.searchWraps: True
nedit.stickyCaseSenseButton: True
nedit.repositionDialogs: True
nedit.autoScroll: False
nedit.appendLF: True
nedit.sortOpenPrevMenu: True
nedit.statisticsLine: False
nedit.iSearchLine: True
nedit.sortTabs: False
nedit.tabBar: False
nedit.tabBarHideOne: True
nedit.toolTips: True
nedit.globalTabNavigate: False
nedit.lineNumbers: True
nedit.pathInWindowsMenu: True
nedit.warnFileMods: True
nedit.warnRealFileMods: True
nedit.warnExit: False
nedit.searchMethod: Literal
nedit.textRows: 30
nedit.textCols: 80
nedit.tabDistance: 8
nedit.emulateTabs: 0
nedit.insertTabs: True
nedit.textFont: -misc-fixed-medium-r-normal-*-20-*-*-*-*-*-*-*
nedit.boldHighlightFont: 
-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1
nedit.italicHighlightFont: 
-adobe-courier-medium-o-normal--20-140-100-100-m-110-iso8859-1
nedit.boldItalicHighlightFont: 
-adobe-courier-bold-o-normal--20-140-100-100-m-110-iso8859-1
nedit.textFgColor: black
nedit.textBgColor: OldLace
nedit.selectFgColor: black
nedit.selectBgColor: rgb:cc/cc/cc
nedit.hiliteFgColor: white
nedit.hiliteBgColor: RosyBrown
nedit.lineNoFgColor: blue
nedit.cursorFgColor: black
nedit.smartTags: True
nedit.prefFileRead: True
nedit.titleFormat: %f (%S) - %d [%s]
NEdit*enableEtchedInMenu:      True
NEdit*enableThinThickness:     False
NEdit*enableToggleVisual:      True
NEdit*enableToggleColor:       True
NEdit*XmToggleButton.indicatorSize: 11
NEdit*XmMenuShell*XmTearOffButton*ShadowThickness:   2
NEdit*text.background:          white
NEdit*text.selectBackground:   #D0D0FF
NEdit*text.lineNumForeground:  #A0A0D0
NEdit*background:              gray85
NEdit*statsForm.background:    gray85
NEdit*statsLine.background:    gray85
NEdit*bottomShadowColor:       gray65
NEdit*topShadowColor:          #fefefe
NEdit*XmText.background:       white
NEdit*XmTextField.background:  white
NEdit*XmList.background:       white
!NEdit*XmRowColumn*fontList: -adobe-helvetica-*-r-*-*-16-*-*-*-*-*-*-*
NEdit*XmRowColumn*fontList: -adobe-helvetica-bold-r-*-*-16-*-*-*-*-*-*-*
NEdit.shell: /bin/ksh
NEdit*bgMenu*background: LightBlue
NEdit*bgMenu.Copy.background: CadetBlue
NEdit*bgMenu.Cut.background: CadetBlue
NEdit*bgMenu.Paste.background: CadetBlue
!NEdit*bgMenu.Find foreward.background: RosyBrown
!NEdit*bgMenu.Find backward.background: RosyBrown
!NEdit*bgMenu.Goto line.background: RosyBrown
NEdit*shellMenu*Indent.background: LightBlue
NEdit*shellMenu*Removeindent.background: LightBlue
NEdit*shellMenu*Center.background: LightBlue
NEdit*shellMenu*RemoveALLIndents.background: LightBlue
NEdit*shellMenu*Justify.background: LightBlue
NEdit*shellMenu*ifdefDEBUG.background: LightBlue
NEdit*shellMenu*ifndefDEBUG.background: LightBlue
-- 
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to