Description: This macro file implements features that can be in the coding process, such as adding file heads, function descriptions, and macro definitions, automatically add file name, function name, and current date when using.
Instructions for use: 1. Project-> Open Project ... Open Base Project (This project is generally in "My Document / Source Insight / Projects / Base"); 2. Project-> Add and Remove Project Files ... Join Macro file (ie gaoke.em); 3. Options-> Menu Assignments opens the Menu Assignments window, enter Macro in Command, select the macro to use, add to the appropriate menu.
[Original article, please keep your article intact, and indicate the source. For more exciting articles, please visit http://blog.9cbs.net/jupin or http://hi.baidu.com/qiupingwu]
/ * Attached to macro definition files * // * T357.em - a sales collection of useful editing macros * /
/ ************************************************** *************************************** * InsfileHeader - Insert the information of file * * mode.com ------- ------------- * 01A, 23Mar2003, Added Description by T357 * 01a, 05Mar2003, T357 Written * -------------------- *********************************************************** *************************** / / * ------------------- -------------------------------------------------- ---- Insert HEADER
INSERTS A Comment Header Block at the top of the current function. This actually Works on Any Type of Symbol, Not Just Functions.
To use this, define an environment variable "szmyname" and set it to your email name. Eg. Set szmyname = raygr ------------------------- ----------------------------------------------- * /
Macro insfileHeader () {
/ * ############################################################################ ######### ############################################################################################################################################################################################################################################################################################## ############## ####### set szmyname variable to your name ####### ######## ###### @ #PLE SZMYNAME = "T357 "######## ############################################################## ########################################################################################################################################################################################################################################################################################################### ################ * / szmyname = ""
// get current time sztime = getSystime (1) day = sztime.day month = sztime.mont year = sztime.year if (day <10) szday = "0 @ day @" else szday = day szmonth = Numtoname (Month) hBuf = GetCurrentBuf () szpathName = GetBufName (hBuf) szfileName = GetFileName (szpathName) nlength = StrLen (szfileName) szInf = Ask ( "Enter the information of file:") szDescription = Ask ( "Enter the description of file:")
HBUF = getcurrentbuf () // begin assembly the title string insbuffline (hbuf, 0, "/ *************************************** ************************************ ") INSBUFLINE (HBUF, 1, "* @ SZFileName @ - @ Szinf @") Insbuffline (HBUF, 2, "*") INSBUFLINE (HBUF, 3, "* Copyright 1998-2003 Guangzhou GaoKe Communication Technology Co., Ltd. INSBUFLINE (HBUF, 5, "* Description: -") Insbuffline (HBUF, 6, "* @ szdescription @") Insbuffline (HBUF, 7, "* Modification History") Insbuffline HBUF, 8, "* ------------------") insbufline (hbuf, 9, "* 01a, @ szday @@ szmonth @@ Year @, @szmyname @ Written ") Insbuffline (HBUF, 10," * ------------------ ") Insbuffline (HBUF, 11," ******** *********************************************************** ******************* / ")
// put the insertion point inside the header Comment setBufins (HBUF, 1, NLENGTH STRLEN (SZINF) 8)}
/ ************************************************** ************************************** * InsfunHeader - Insert Function's Information * * Modification History * --------- ----------- * 01A, 23Mar2003, Added Description by T357 * 01a, 05Mar2003, T357 Written * -------------------- ** *********************************************************** ******************************************** / macro insfunheader () {// Get The Owner's name from the Environment Variable: szmyName. //iff the variable Doesn't exist, then @*################################################################################################################################################################################################################################################################################################ ############################################################################################################################################################################################################################################################# ##################### ####### set szmyname variable to your name ######## #### ###### for example szmyname = "t357" ##################################################################################################################################################################################################################################################################################### ####################################################################################################################################################################################### ########################### * / szmyname = ""
// Get a Handle To the Current File Buffer and the name // and location of the current symbol where the currs. HBUF = getCurrentBuf () szfunc = getcursymbol () ln = getsymbolline (SZFUNC)
// get current time sztime = getSystime (1) day = sztime.day month = sztime.mont year = sztime.year if (day <10) szday = "0 @ day @" else szday = day szmonth = Numtoname (Month) Szinf = ask ("Enter the information of function:") szdescription = ask ("Enter the description of function:")
= "/ ************************************************************** ************************************** "INSBUFLINE (HBUF, LN, SZ) INSBUFLINE HBUF, LN 1, "* @ SZFUNC @ - @ Szinf @") Insbuffline (HBUF, LN 2, "* Desbription: -") Insbuffline (HBUF, LN 3, "* @ szdescription @") // Remove INSBUFLINE (HBUF, LN 4, "* INPUT:") INSBUFLINE (HBUF, LN 5, "* OUTPUT:") Insbuffline (HBUF, LN 6, "* Returns:") Insbuffline (HBUF, LN 7, "*") Insbuffline (HBUF, LN 8, "* MODIFICATION HISTORY") Insbuffline (HBUF, LN 9, "* --------------- ----- ") INSBUFLINE (HBUF, LN 10," * 01a, @ szday @@ szmonth @@ Year @, @ szmyname @ Written ") Insbuffline (HBUF, LN 11," * ----- --------------- ") Insbuffline (HBUF, LN 12," ********************** *********************************************************** **** / ") // Put the insertion point inside the header comment setbufins (HBUF, LN 1, Strlen (SZFUNC) Strlen (Szinf) 8)}
/ ************************************************** **************************** * Numtoname - Change the Month Number to Name * * MODIFICATION HISTORY * ------ -------------- * 01A, 05MAR2003, T357 Written * ------------------ ********* *********************************************************** ******************** / MACRO NUMTONAME (MONTH) {if (Month == 1) Return "Jan" if (Month == 2) Return "Feb" IF (MONTH == 3) Return "Mar" if (Month == 4) Return "APR" if (Month == 5) Return "May" if (Month == 6) Return "Jun" if (Month == 7) Return "JUL" if (Month == 8) Return "AUG" if (Month == 9) Return "SEP" if (Month == 10) Return "Oct" if (Month == 11) Return "NOV" IF Month == 12) Return "DEC"}
/ ************************************************** ***************************** * Cutword - Auto newline * * odification history * ---------- ---------- * 01A, 24Mar2003, T357 FIX Some Bug * 01a, 05Mar2003, T357 Written * ------------------ *** *********************************************************** ********************************** / Macro Cutword (ncurline, szinf) {length = 63 nlength = strlen (SZINF) i = 0 / * loop control * / begin = 0 / * first character's index of current line * / pre = 0 / * preceding word's index * / hbuf = GetCurrentBuf () // nline = GetBufLnCur () while (i 1 }}/********************************************** ******************************** * GetFileName - Get the filename only from the path * * model history * - ------------------ * 01A, 05MAR2003, T357 Written * ------------------ **** *********************************************************** ********************************** / Macro getFileName (pathname) {nlength = Strlen (pathname) i = NLENGTH - 1 Name = "" While (i 1) {CH = Pathname [i] IF ("//" == "@ CH @") Break i = i - 1} i = i 1 while (i Return name} / ************************************************** **************************** * RETURNTRUEORFALSE - INSERTS "Returns True or false" at the current line * * modification history * - ------------------- * 01A, 05Mar2003, T357 Written * ------------------ *** *********************************************************** ********************************** / macro returntrueorfalse () {szreturns = "Return True if successful or false if errors." hbuf = getcurrentbuf () ln = GetBufLnCur (hbuf) szCurLine = getBufLine (hbuf, ln) DelBufLine (hbuf, ln) InsBufLine (hbuf, ln, "@ szCurLine @@ szReturns @") SetBufIns (hbuf, ln, StrLen (szReturns) StrLen (szCurLine) 3)} / ************************************************** ************************************** * insideerdef - INSERTS the header define in the headerfile * * mode history * ----- --------------- * 01A, 05Mar2003, T357 Written * ------------------ ******** *********************************************************** ****************************** / macro insicyaderdef () {hbuf = getCurrentBuf () szpathname = getBuFName (hbuf) SZFileName = getFileName (szpathname) SZFileName = Toupper (SZFileName) NLENGTH = STRLEN (SZFileName) i = 0 / * loop control * / szdefinename = "" "") {IF (SZFileName [i] == ") szdefinename = cat (szdefinename," _ ") Else Szdefinename = Cat (szdefinename, szfilename [i]) i = i 1} szdefinename = cat ("_", szdefinename) ifdefinesz (szdefinename)} / ************************** *********************************************************** ********** * PrintDate - Print Date ON Where The Cursor Point To * Description: - * * Input: * Output: * Returns: * * MODIFICATION HISTORY * ---------- ---------- * 01A, 2 3MAR2003, T357 Written * ------------------ ********************************* *********************************************************** *** / macro printdate () {sztime = getSystime (1) day = sztime.day month = sztime.mont year = sztime.year if (day <10) szday = "0 @ day @" Else szday = day szmonth = NumToName (Month) hbuf = GetCurrentBuf () ln = GetBufLnCur (hbuf) szCurLine = getBufLine (hbuf, ln) DelBufLine (hbuf, ln) InsBufLine (hbuf, ln, "@ szCurLine @ @ szDay @@ szMonth @@ Year @") SetBufins (HBUF, LN, Strlen (Szcurline) 10)} // ask user for ifdef condition and wrap it arround current // selection.//28mar2003, Modified by T357.//26MAR2003, Modified by T357.Macro InsifDef () {SZ = Ask ("Enter ifdef Condition:") IF SZ! = "") {// ifdefsz (sz); hWnd = getCurrentWnd () SEL = getWndsel (hwnd) HBUF = getWndbuf (hwnd) // Get line the selection (Insertion Point) is on szline = getBufline (HBUF, SEL .lnfirst - 1); chtab = charfromascii (9) // prepare a new indented blank line to be insert. // Keep White Space on left and add a Tab to indent. // this preserves the indeentation level. i = 0 / * loop control * / ich = "" "" "" "|| szline [i] == chtab) {ICH = CAT (ICH, SZLINE [I]) i = i 1} insbuffline (HBUF , SEL.LNFIRST, "") Insbuffline (HBUF, SEL.LNFirst 1, "@ ICH @ # IFDEF @ SZ @") Insbuffline (HBUF, SEL.LNFIRST 2, "@ ICH @" # chtab) Insbuffline (HBUF , SEL.LNFIRST 3, "@ ICH @ # endif / * @ SZ @ * /") SetBufins (HBUF, SEL.LNFIRST 2, STRLEN (ICH) Strlen (ChTAB)}} // wrap ifdeinef HBUF = getCurrentBuf () insbuffline (HBUF, Lnfirst, "#ifndef @ SZ @") Insbuffline (HBUF, Lnfirst 1, "#define @ SZ @") INSBUFLINE (HBUF, LNLAST 3, "#ENDIF / * @SZ @ * / ") Setbufins (hbuf, lnfirst 2, 0)} / * Auto Expand * // * ------------------------------------------ ------------------------------ AUTOMAATICLY Expands c Statements Like if, for, while, switch, etc..to use this Macro, 1. Add this file to your project. 2. Run the options-> Key Assignments Command and Assign A Convenient Keystroke to the "AutoExpand" Command. 3. After Typing a KeyWord, Press The AutoExpand Keystroke To Have The Statement Expanded. The Expanded Statement Will Contain A ### string Which represents a field where you are supplosed to Type More. The ### string is also loaded in to the search pattern so you can use "search forward" to select the next ### field. For example: 1. You Type "for" autoexpand key 2. this is inserted: for (###; ###; ###) {###} 3. and the first ### field is selected. -------------------------------------------------- ----------------------- * // ********************** *********************************************************** **** * AutoExpand - Automatically expands C statements * * DESCRIPTION: - Automatically expands C statements like if, for, while, * switch, etc .. * * Input: * Output: * Returns: * * modification history * - ------------------ * 01A, 27MAR2003, T357 Modified * ------------------ **** *********************************************************** ********************************** / macro autoexpand () {// get window, sel, and buffer handles hwnd = getCurrentWnd () if (hwnd == 0) Stop SEL = getWndsel (HWND) IF (SEL.ICHFIRST == 0) STOP HBUF = GetWNDBUF (HWND) // Get line the selection (Insertion Point) is on szline = getBufline (HBUF, SEL.LNFIRST); // Parse Word Just to the Left of the Insert WordInfo = getWordLeftofich (Sel.ichfirst, Szline) ln = sel.lnfirst; chtab = charfromascii (9) // Prepare a new indeted. // Keep White Space on Left and add a Tab to indent. // this preserves the inde (szline [ICH] == '|| Szline [ICH] == chtab) {ICH = ICH 1} SZLINE = Strmid (Szline, 0, ICH) SEL.LNFIRST = SEL.LNLAST SEL.ICHFIRST = WordInfo.ich Sel.ichlim = WordInfo.ich // Expand Szword Keyword ... IF (WordInfo.szword == "if" || WordInfo.szword == "while" || WordInfo.szword == "elseif") {setbufseltext (hbuf, "(###)") Insbuffline (HBUF, LN 1, "@ Szline @" # "{"); insbufline (hbuf, ln 2, "@ Szline @" # chtab); insbuff, ln 3, "@ Szline @" # "}"); Else if (WordInfo.szword == "for") {setbufseltext (hbuf, "(###)") INSBUFLINE (HBUF, LN 1, "@ Szline @" # "{"); insbuff, ln 2, "@ SZLINE @" # chtab; insbufline (hbuf, ln 3, "@ Szline @" # "}");} else if (WordInfo.szword == "Switch") {setbufseltext (hbuf, " ###) ") INSBUFLINE (HBUF, LN 1," @ Szline @ "#" {") Insbuffline (HBUF, LN 2," @ SZLINE @ "#" case ") Insbuffline (HBUF, LN 3, "@ SZLINE @" # chtab) Insbuffline (HBUF, LN 4, "@ Szline @" # chtab # "Break;") Insbuffline (HBUF, LN 5, "@ Szline @" # "default:") Insbuffline HBUF, LN 6, "@ SZLINE @" # chtab) INSBUFLINE (HBUF, LN 7, "@ Szline @" # "}")} else if (WordInfo.szword == "do") {insbuff, LN 1, "@ Szline @" # "{") Insbuffline (HBUF, LN 2, "@Szlin E @ "# chtab); insbuffline (hbuf, ln 3," @ Szline @ "#"} while (); ")} else if (WordInfo.szword ==" CASE ") {setbufseltext (hbuf," ## # ") Insbuffline (HBUF, LN 1," @ Szline @ " # chtab) Insbuffline (HBUF, LN 2, "@ Szline @" # chtab # "Break;")} else stopsetWndsel (HWND, SEL) LoadSearchPattern ("###", true, false, false; search_forward} / * GET Word Left of Ich * // * --------------------------------------- --------------------------------- Given an index to a character (ich) and a string (SZ), Return A "WordInfo" Record Variable That Describes The Text Word Just To The Left of The Ich. Output: Wordinfo.szword = The word string wordinfo.ich = the first Ich of the word word info.ichlim = the limit ich of the word --------------------- -------------------------------------------------- - * / Macro getWordLeftofich (ICH, SZ) {WordInfo = "" "// Create a" WordInfo "Structure Chtab = charfromascii (9) // scan backwords over white space, if any ich = ICH - 1; if (iCH> = 0) while (SZ [ICH] == "|| SZ [ICH] == ChTAB) {ICH = ICH - 1; ICH <0) Break;} // scan backwords to start of word ichlim = ICH 1; asciia = asciifromchar ("a") asciiz = asciifromchar ("z") While (ICH> = 0) {ch = TouPper (SZ [ICH]) ASCIICH = asciifromchar (CH) IF ((ASCIICH ICH = ICH 1 WordInfo.szword = Strmid (SZ, ICH, ICHLIM) WordInfo.ich = ICH WordInfo.ichlim = ICHLIM; Return WordInfo}