Patch for error in Search on win 10

Home Forums Multi-Edit User Created Macros Patch for error in Search on win 10

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Brad M. 3 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #21486

    Clay Martin
    Keymaster

    A ME user, Glenn Soffler, has patched Search.s to correct a problem with it running ME V11 on Win 10. Seems that after the first search, search would fail. Here is what he wrote:
    Attached is the work around for win 10

    You will still get an error beep for the first execution of the postmessage command,
    However the second postmessage command executes ok and the macro continues

    If you see a way to eliminate the error beep please forward

    Here is the updated search.s code
    /*==============================================================================
    Multi-Edit Macro File
    29-Jan-08 12:04

    Function: Search related macros.
    Author : Dan Hughes

    GlobalExpHighlight –
    S_And_R – The general purpose search and search/replace macro.
    Srch_Across_Line – Performs Word/Phrase search
    Parse_Phrase – Used by SRCH_ACROSS_LINE to …
    Repl_Across_Line – Performs Word/Phrase replace
    Search – This is the user interface for a SEARCH.
    S_Repl – This is the user interface for a SEARCH AND REPLACE.
    RepSrch – This repeats the last search or search/replace.
    IncSrch – Incremental search
    Fs – The interface to multi-file search
    SwitchBestFile –

    Copyright (C) 2002-2008 by Multi Edit Software, Inc.
    ====================================================================( ldh )==*/
    macro_file Search;

    //#define _UseTreeInsert_
    #include TDbg.sh

    TDBG_DEFINE_AREA( Search );

    #include Win32.sh
    #include Messages.sh
    #include ComCtlx.sh

    #ifdef _MeSAS_
    #include MeLSLib.sh
    #endif

    #ifdef _MeLite_
    #include MeLiteLib.sh
    #endif

    #ifdef _Mew32_
    #include MeLib.sh
    #include Project.sh
    #endif

    #include MeTools.sh
    #include Dialog.sh
    #include ListCtrl.sh
    #include TreeCtrl.sh
    #include Help.sh
    #include Mew.sh
    #include RegExp.sh
    #include StdDlgs.sh
    #include Panes.sh
    #include Window.sh
    #include MeUtil.sh
    #include HelpLinks.sh
    #include Block.sh
    #include Search.sh

    // Search Tabbed dialog control constants
    #define id_st_TabBar 88

    // Search Option dialog control constants
    #define id_sopt_AllBtnCB 501
    #define id_sopt_FindLstHideCB 502
    #define id_sopt_UseSrDefCB 504
    #define id_sopt_UseFsDefCB 505
    #define id_sopt_ShowHis0CB 506
    #define id_sopt_NoBlkChkCB 507
    #define id_sopt_AutoWrapCB 508
    #define id_sopt_NoWrapPromptCB 509
    #define id_sopt_FindLstCloseCB 510

    // Search dialog controls constants
    #define Repl_Ctrl 1001
    #define Skip_Ctrl 1003
    #define Cancel_Ctrl 1002
    #define NonStop_Ctrl 1004
    #define SkipFile_Ctrl 1006
    #define AllFiles_Ctrl 1005
    #define SearchAgain_Ctrl 1001
    #define SkipWindow_Ctrl 1007

    #define id_sr_SearchStr 201
    #define id_sr_ReplaceStr 202
    #define id_sr_FilespecStr 203
    #define id_sr_PathStr 204

    #define id_sr_TypeGrp 301
    #define id_sr_OptionGrp 302
    #define id_sr_ModeGrp 303
    #define id_sr_ColGrp 304
    #define id_sr_UseLstGrp 305
    #define id_sr_AttributeGrp 306

    #define id_sr_LiteralRB 401
    #define id_sr_RegExpRB 402
    #define id_sr_WordSrchRB 403
    #define id_sr_List0RB 404
    #define id_sr_List1RB 405

    #define id_sr_REClassicRB 406
    #define id_sr_REUnixRB 407
    #define id_sr_REPerlRB 408

    #define id_sr_CaseCB 501
    #define id_sr_GlobalSrchCB 502
    #define id_sr_BlockSrchCB 503
    #define id_sr_AllWindowsCB 504
    #define id_sr_ProjectSrchCB 505
    #define id_sr_ReplaceOneCB 506
    #define id_sr_PromptSrchCB 507
    #define id_sr_BackwardCB 509
    #define id_sr_PosBegStrCB 510
    #define id_sr_ExitNoFindCB 511
    #define id_sr_MarkFndTxtCB 522
    #define id_sr_RegExpCB 523
    #define id_sr_SearchDirCB 524
    #define id_sr_LeaveOpenCB 525
    #define id_sr_ShowAllCB 526
    #define id_sr_ColumnsCB 527

    #define id_sr_ArchiveCB 530
    #define id_sr_ReadOnlyCB 531
    #define id_sr_HiddenCB 532
    #define id_sr_SystemCB 533

    #define id_sr_BegCol 701
    #define id_sr_EndCol 702

    #define id_sr_BegColLbl 901
    #define id_sr_EndColLbl 902
    #define id_sr_RegExLbl 903

    #define id_sr_SearchBtn 1101
    #define id_sr_CancelBtn 1102
    #define id_sr_RegExpHlpBtn 1103
    #define id_sr_HelpBtn 1104
    #define id_sr_ListPrevBtn 1105
    #define id_sr_AllBtn 1106
    #define id_sr_ReplaceBtn 1107
    #define id_sr_AliasBtn 1108
    #define id_sr_DirBtn 1109
    #define id_sr_DefaultsBtn 1110

    #define id_sr_ShrinkBtn 1200
    #define id_sr_DirSwitchBtn 1201
    #define id_sr_SrchRegExBtn 1202
    #define id_sr_RepRegExBtn 1203

    // Find list dialog
    #define id_fl_MessageStr 201

    #define id_fl_MessageFrm 301

    #define id_fl_FTypeCL 601

    #define id_fl_Listbox 1000

    #define id_fl_SelectBtn 1101
    #define id_fl_ExportBtn 1102
    #define id_fl_ViewBtn 1103
    #define id_fl_SaveBtn 1104
    #define id_fl_LoadBtn 1105
    #define id_fl_MenuBtn 1106

    #define id_fl_DeleteNode 1120
    #define id_fl_ExpandAll 1121
    #define id_fl_CollapseAll 1122
    #define id_fl_Clear 1123

    // Dialog position save global names
    #define _g_CSRDlgPos “CSRDlgPos”
    #define _g_SearchTabDlgPos “SearchTabDlgPos”

    /*——————————————————————————

    Function: Function to tell if List all is available
    Exit : int – True no list available
    False list available
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    int ListAllAvailable( )
    {
    // return ( Global_Str( “!SR_LST_WN” ) == “” );
    // return ( False );
    return ( True );

    } // ListAllAvailable

    void RegExpHelp( ) trans2
    {
    switch ( g_RegExStyle ) {

    case esClassic :
    MeHelp( hc_RegExpClassic );
    break;

    case esUnix :
    MeHelp( hc_RegExpUnix );
    break;

    case esPerl :
    MeHelp( hc_RegExpPerl );
    break;
    }
    Return_Int = 0;

    } // RegExpHelp

    /*——————————————————————————

    Function: Called by search dialogs to set the first search history item to
    the word or block under the cursor

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    str SetSearchHistory(
    str SearchStr,
    int SetGlobals,
    int Window,
    int CtrlId
    ) trans2
    {
    if ( SearchStr == “” ) {

    int SavRefresh = Refresh;
    int SavPBlocks = Persistent_Blocks;

    Refresh = False;
    Persistent_Blocks = True;
    Mark_Pos;
    if ( ( C_Line == Block_Line1 ) && ( Block_Stat > 0 ) &&
    ( Block_Line1 == Block_Line2 ) ) {
    if ( Block_Stat == _LinBlock ) {
    First_Word;
    SearchStr = Get_Word( “” );
    }
    else {
    SearchStr = Copy( Get_Line( ), Block_Col1,
    ( Block_Col2 – Block_Col1 ) + 1 );
    }
    }
    else {
    Right;
    Word_Left;
    SearchStr = Get_Word( Word_Delimits );
    }
    Goto_Mark;
    Persistent_Blocks = SavPBlocks;
    Refresh = SavRefresh;
    }
    if ( SetGlobals ) {
    Set_Global_Str( “Search_History0”, SearchStr );
    Set_Global_Str( “Replace_History0”, SearchStr );
    }
    if ( Window && CtrlId ) {

    int Jx;

    str TStr;

    CtrlId = GetDlgItem( Window, CtrlId );

    // Add current word to the top of the search history list
    SendMessageStr( CtrlId, cb_GetLbText, 0, TStr );
    if ( TStr != SearchStr ) {
    Jx = SendMessage( CtrlId, cb_GetCurSel, 0, 0 );
    SendMessageStr( CtrlId, cb_InsertString, 0, SearchStr );
    if ( Jx ) {
    SendMessage( CtrlId, cb_DeleteString, 1, 0 );
    if ( Jx != cb_Err ) {
    SendMessage( CtrlId, cb_SetCurSel, Jx, 0 );
    }
    }
    else {
    SendMessage( CtrlId, cb_SetCurSel, 1, 0 );
    }
    }
    }
    return ( SearchStr );

    } // SetSearchHistory

    /*——————————————————————————

    Function: Called by search dialogs to get aliases
    Entry : int Dlg – The window handle of the dialog box ( /DLGHANDLE= )
    int Id – The control id of the text control ( /ID= )
    int Flags – Flags ( /FLAGS= )
    0x01 If set, then set the search type radio buttons.
    0x02 If set, then set the RegEx checkbox.

    ——————————————————————–( ldh )–*/
    void SearchGetAlias(
    int Dlg = Parse_Int( “/DLGHANDLE=”, MParm_Str ),
    int Id = Parse_Int( “/ID=”, MParm_Str ),
    int Flags = Parse_Int( “/FLAGS=”, MParm_Str )
    ) trans2
    {
    str WText;
    str TStr;

    int CtrlId = GetDlgItem( Dlg, Id );

    TStr = ReSelectAlias( );
    if ( Return_Int ) {
    if ( Flags & 1 ) {
    SendDlgItemMessage( Dlg, id_sr_LiteralRB, bm_SetCheck, False, 0 );
    SendDlgItemMessage( Dlg, id_sr_WordSrchRB, bm_SetCheck, False, 0 );
    SendDlgItemMessage( Dlg, id_sr_RegExpRB, bm_SetCheck, True, 0 );
    }
    if ( Flags & 2 ) {
    SendDlgItemMessage( Dlg, id_sr_RegExpCB, bm_SetCheck, True, 0 );
    }

    int XSCaretPos = g_SCaretPos;
    int CpLo = ( XSCaretPos & 0xFFFF );
    int CpHi = ( XSCaretPos >> 16 );

    //DebugLog( 0, “SearchGetAlias”, “%x”, XSCaretPos );
    GetWindowText( CtrlId, WText, 254 );
    if ( CpLo != CpHi ) {
    WText = Str_Del( WText, CpLo + 1, CpHi – CpLo );
    }

    WText = Str_Ins( TStr, WText, CpLo + 1 );
    SendMessageStr( CtrlId, wm_SetText, 0, WText );
    SetFocus( CtrlId );
    CpLo += Svl( TStr );
    SendMessage( CtrlId, cb_SetEditSel, 0, ( CpLo < < 16 ) | ( CpLo & 0xFFFF ) ); } } // SearchGetAlias /*------------------------------------------------------------------------------ Function: This macro creates processes the Global Expression Highlight feature. Entry : If no search string is passed on the commandline, and /R=1 is not passed, then a dialog is brought up. If a search string is passed, then ExpOn=1 turns on Unix expressions, ExpOn=2 turns on Classic expressions, CaseSen=1 turns on Case Sensitivity and Reset=1 causes the reset of the commandline to be ignored and the highlighting to be turned off. Exit : Does not return a result. By : Todd Johnson --------------------------------------------------------------------( ldh )--*/ void GlobalExpHighlight( str SearchStr = Parse_Str( "/S=", MParm_str), int ExpOn = Parse_Int( "/E=", MParm_Str), int CaseSen = Parse_Int( "/C=", MParm_Str), int Reset = Parse_Int( "/R=", MParm_Str) ) trans2 { int Style; TTRACE_ENTER( "Search", TDBG_TRACE, "GlobalExpHighlight(\"%s\", %d, %d, %d)", SearchStr, ExpOn, CaseSen, Reset ); // If reset was passed on the commandline, then turn highlight off and exit if ( Reset ) { SetSearchHighlightStr( "", 0 ); Redraw; TTRACE_LEAVE( "GlobalExpHighlight()" ); return ( ); } // If a search string was passed on the command line, then process the search // without a dialog. if ( SearchStr != "" ) { int SearchFlags = ( CaseSen != 0 ) | 0x80000000; int Prompted = g_HighlightFlags & 0x10; switch ( ExpOn ) { case 1 : SearchFlags |= 0x02; Style = rasUnix; break; case 2 : SearchFlags |= 0x04; Style = rasClassic; break; case 3 : SearchFlags |= 0x06; Style = rasPerl; break; } // Save values g_SearchStr = SearchStr; g_HighlightFlags = SearchFlags | Prompted; if ( SearchFlags & 0x06 ) { SearchStr = ReTranslate( SearchStr, Style ); } TTRACE( "Search", TDBG_TRACE, "Flags=%x, '%s'", SearchFlags, SearchStr ); SetSearchHighlightStr( SearchStr, SearchFlags ); Redraw; TTRACE_LEAVE( "GlobalExpHighlight()" ); return ( ); } // Show dialog Rm( "SearchTabDlg /T#=" + Str( _tab_sr_Highlight ) ); TTRACE_LEAVE( "GlobalExpHighlight()" ); } // GlobalExpHighlight int Create_SR_Dialog( int Search_Mode, int MultiFile, int Prompted, int Search_All_Windows ) trans2 { int X; int Ctrl; int Dlg; int RetVal; int TRefresh = Refresh; Refresh = True; Redraw; DlgCreate( Dlg ); if ( Search_Mode ) { X = 1; // *indent-off* DlgAddCtrl( Dlg, dlg_PushButton, "&Replace", X, 1, dlg_StanBtnWidth, 0, Repl_Ctrl, dlgf_DefButton, '/R=101' ); X += Dlg_StanBtnWidth + 2; Ctrl = Repl_Ctrl; if ( Prompted ) { DlgAddCtrl( dlg, Dlg_PushButton, '&Skip', X, dlg_PosOffset + 0, Dlg_StanBtnWidth, 0, Skip_Ctrl, 0, '/R=103' ); X += Dlg_StanBtnWidth + 2; } if ( search_all_windows ) { DlgAddCtrl( dlg, Dlg_PushButton, 'Skip &Window', X, dlg_PosOffset + 0, dlg_StanBtnWidth + 4, 0, SkipWindow_Ctrl, 0, '/R=107' ); X += Dlg_StanBtnWidth + 6; } DlgAddCtrl( dlg, Dlg_PushButton, 'Cancel', X, dlg_PosOffset + 0, dlg_StanBtnWidth, 0, Cancel_Ctrl, 0, '/R=102' ); x += Dlg_StanBtnWidth + 2; if ( prompted ) { DlgAddCtrl( Dlg, Dlg_PushButton, '&Non Stop', X, 1, Dlg_StanBtnWidth + 1, 0, NonStop_Ctrl, 0, '/R=104' ); x += Dlg_StanBtnWidth + 3; } if ( MultiFile ) { DlgAddCtrl( Dlg, Dlg_PushButton, 'Skip &File', X, 1, Dlg_StanBtnWidth, 0, SkipFile_Ctrl, 0, '/R=106' ); X += Dlg_StanBtnWidth + 2; DlgAddCtrl( dlg, Dlg_PushButton, "A&ll Files", X, 1, Dlg_StanBtnWidth, 0, AllFiles_Ctrl, 0, '/R=105' ); X += Dlg_StanBtnWidth + 2; } } else { X = 1; DlgAddCtrl( dlg, Dlg_PushButton, '&Search Again', x, 1, Dlg_StanBtnWidth + 5, 0, SearchAgain_Ctrl, DLGF_DefButton, '/R=101' ); X += Dlg_StanBtnWidth + 7; Ctrl = SearchAgain_Ctrl; if ( Search_All_Windows ) { DlgAddCtrl( Dlg, Dlg_PushButton, 'Skip &Window', x, 1, Dlg_StanBtnWidth + 4, 0, SkipWindow_Ctrl, 0, '/R=103' ); X += Dlg_StanBtnWidth + 6; } DlgAddCtrl( Dlg, Dlg_PushButton, '&Cancel', X, 1, Dlg_StanBtnWidth, 0, Cancel_Ctrl, 0, '/R=102' ); } RetVal = DlgExecute( Dlg, Ctrl, "Search Options", hc_SrPromptDlg, "/RPOS=" + _g_CSRDlgPos, 0 ); // *indent-on* DlgKill( dlg ); Refresh = TRefresh; return ( RetVal ); } // Create_SR_Dialog /*------------------------------------------------------------------------------ Function: Search and search/replace main macro. Entry : /FR=1 - Flag that this macro was called by the multi-file search-and-replace routine. Exit : Returns - Return_Int ( Normal search ) 0 - if or Cancel was pressed at the prompts.
    1 – if search was carried through.

    Return_Int – File Replace ( /FR=1 )
    0 – Normal s/r occurred
    1 – Non-Stop all files
    -1 – Abort remaining files

    Global_Int( “Found_Count” ) = # of occurrences found.
    Global_Int( “Replace_Count” ) = # of replaces.

    Globals :
    Global_Str(‘Switches’) The search switches
    A – Search all windows
    B – Search backwards
    C – Don’t move cursor to the right after a replace has occurred
    between multiple searches and replaces. ( Replace only )
    G – Global, search entire file
    I – Ignore case
    J – Search project
    K – Kill dialog when no string found
    L – List all occurrences
    M – Mark found string ( Find only )
    N – No prompts, search and replace unconditionally
    O – Restrict to specified column
    P – Prompt for repeated searches/replaces
    R – Restrict search to marked block
    W – Word/Phrase search
    X – Regular expressions off. Faster if regs not needed.

    Global_Str(‘Repl_Switches’) Replace switches – See above.
    Global_Str(‘SEARCH_STR’) String to search for.
    Global_Str(‘REPLACE_STR’) String to replace with.
    Global_Int(‘SEARCH_MODE’) Mode 0=search 1=search and replace
    Global_Int(‘REPSEARCH’) Simply repeat search or search/replace
    according to previous search. No box
    with prompts.
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    macro S_And_R no_break trans2
    {
    int SavRefresh = Refresh;
    int TInsert_Mode = Insert_Mode;
    int TSearch_Highlight = Search_Highlight;
    int T_Tab_Expand = Tab_Expand;
    int Tpb = Persistent_Blocks;
    int Active_Window = Window_Id;
    int First_Window = Window_Id;
    int Msg_Hit_Count = 0;
    int Making_List = False;
    int File_Replace = ( Parse_Int( “/FR=”, MParm_Str ) > 0 );
    int LstId = Parse_Int( “/L=”, MParm_Str );
    int All_Files = 0;
    int FirstTime = 0;

    int Search_All_Windows = 0;
    int All_Windows_Count = 0;
    int All_Windows_FoundNum = 0;
    int All_Windows_Scanned = 0;
    int All_Windows_Global = 0;
    int Skip_All = 0;
    int MarkFoundText = 0;

    int S_Flags = 0; // TMJ – 06-15-93 12:58pm – For Unix style expressions
    int TabNo;

    int FoundNum;
    int Count;
    int Jm;
    int Jz;
    int Jx;
    int Start_Row;
    int Box_Ofs;
    int T_Col;
    int Tp;
    int hl;
    int Back_Search;
    int Search_Mode;
    int Restrict;
    int Restrict_Count;
    int orig_line;
    int Orig_Row;

    int RbC1 = 0;
    int RbC2 = 0;

    int GLOBALSEARCH;
    int noprompt;
    int S_Prompt;
    int Searching;
    int s_res;
    int No_Cursor_Movement;
    int New_Line_Num;
    int Across_Lines;
    int at_top = 0;

    str Search_Str;
    str Replace_Str;
    str SpareString[ Max_Line_Length ];
    str Switches_Str[ 20 ];
    str Help_Str[ 20 ];
    str Interface_Mac;
    str List_File_Name[ 260 ];
    str SwitchesGlobal;
    str SearchLinks;

    if ( !g_SRModalDlg ) {
    if ( SReturn_Int == 0 ) {
    goto S_And_R_Exit;
    }
    }
    Refresh = False;
    Persistent_Blocks = True;
    Start_Row = Parse_Int( “/Y=”, MParm_Str );
    Box_Ofs = 0;

    Push_Undo;
    Help_Str = hc_Find;
    Search_Str = g_SearchStr;
    Replace_Str = g_ReplaceStr;
    Search_Mode = g_SearchMode;

    if ( File_Replace ) {
    Search_Mode = True;
    g_SearchMode = True;
    SwitchesGlobal = _g_FRSwitches;
    }
    else {
    if ( Search_Mode ) {
    SwitchesGlobal = _g_ReplSwitches;
    }
    else {
    SwitchesGlobal = _g_Switches;
    }
    }
    Switches_Str = Caps( Global_Str( SwitchesGlobal ) );

    FoundNum = 0;
    Count = 0;

    if ( g_RepSearch == False ) {
    Set_Global_Str( SwitchesGlobal, Switches_Str );
    if ( Search_Mode ) {
    Box_Ofs = 1;
    Help_Str = hc_Replace;
    }
    Set_Global_Int( “Menu_Result”, False );

    Return_Int = SReturn_Int;
    }
    Return_Int = True;
    SearchLinks = ” “;

    Start_Search:
    Switches_Str = Caps( Switches_Str );
    Ignore_Case = XPos( “I”, Switches_Str, 1 ) != 0;
    GlobalSearch = XPos( “G”, Switches_Str, 1 ) != 0;

    if ( g_RepSearch ) {
    GlobalSearch = False;
    }
    if ( Search_All_Windows && All_Windows_Global ) {
    GlobalSearch = True;
    }
    NoPrompt = XPos( “N”, Switches_Str, 1 ) != 0;
    Making_List = XPos( “L”, Switches_Str, 1 ) != 0;
    S_Prompt = ( XPos( “P”, Switches_Str, 1 ) != 0 ) | File_Replace;
    Back_Search = XPos( “B”, Switches_Str, 1 ) != 0;
    Across_Lines = XPos( “W”, Switches_Str, 1 ) != 0;

    // Search_All_Windows is not compatible with file_replace
    Search_All_Windows = ( XPos( “A”, Switches_Str, 1 ) != 0 ) && ( File_Replace == 0 );

    if ( XPos( “O”, Switches_Str, 1 ) != 0 ) {

    // Set column restrict vars
    RbC1 = g_SearchColBeg;
    RbC2 = g_SearchColEnd;
    }

    if ( Search_Mode == True ) {
    Making_List = False;
    SpareString = Search_Str;
    Return_Str = Replace_Str;
    if ( Ignore_Case ) {
    SpareString = Caps( SpareString );
    Return_Str = Caps( Return_Str );
    }
    No_Cursor_Movement = False;
    if ( SpareString != Return_Str ) {

    // Don’t allow ‘C’ switch if search_Str = Replace_Str. This would cause
    // a continuous loop
    No_Cursor_Movement = XPos( “C”, Switches_Str, 1 ) != 0;
    }
    }
    else {
    if ( NoPrompt ) {
    Making_List = True;
    }
    if ( Making_List ) {
    NoPrompt = True;
    if ( FirstTime == 0 ) {
    ++FirstTime;
    FindLstGetWin( LstId, False, _pwa_AddTab ); // Open Find list window

    // Add header to Find list
    FindLstSetHeader( LstId, 0, 0, 0, S_Flags, g_SearchStr, “”, “”,
    “/SW=” + g_Switches + “/CB=” + Str( Rbc1 ) + “/CE=” + Str( Rbc2 ) +
    “/L=” + Str( LstId ), False );
    }
    }
    }
    Reg_Exp_Stat = XPos( “X”, Switches_Str, 1 ) == 0;
    Restrict_Count = 0;
    Orig_Line = C_Line;
    Orig_Row = C_Row;
    if ( Reg_Exp_Stat ) {
    switch ( g_RegExStyle ) {

    case esClassic :
    S_Flags |= _oldExp;
    break;

    case esUnix :
    S_Flags |= _regExp;
    break;

    case esPerl :
    S_Flags |= _perlExp;
    break;
    }
    Search_Str = ReTranslate( g_SearchStr, g_RegExStyle );
    if ( Search_Mode ) {
    Replace_Str = ReTranslate( g_ReplaceStr, g_RegExStyle );
    }
    }
    if ( !Ignore_Case ) {
    S_Flags |= _CaseSensitive;
    }
    if ( Back_Search ) {
    S_Flags |= _Backward;
    }
    Mark_Pos;
    Restrict = XPos( “R”, Switches_Str, 1 ) != 0;
    if ( Restrict ) {
    Block_End;
    if ( Block_Stat == 0 ) {
    if ( Search_All_Windows ) {
    goto Search_Out;
    }

    // Remove restrict option from switches
    if ( Jx = XPos( “R”, Switches_Str, 1 ) ) {
    Switches_Str = Str_Del( Switches_Str, Jx, 1 );
    Set_Global_Str( SwitchesGlobal, Switches_Str );
    }
    Restrict = 0;
    }
    else {
    if ( Block_Stat == _ColBlock ) {
    Rbc1 = Block_Col1;
    Rbc2 = Block_Col2;
    }
    if ( ( ( C_Line == Block_Line1 ) && ( C_Col < Block_Col1 ) ) || ( ( C_Line == Block_Line2 ) && ( C_Col >= Block_Col2 ) ) ||
    ( C_Line < Block_Line1 ) || ( C_Line > Block_Line2 ) || !Tpb ) {
    if ( !g_SRModalDlg ) { // for modeless dialog
    if ( g_RepSearch == False ) {
    goto Restrict1;
    }
    }
    else {
    goto Restrict1;
    }
    }
    }
    }
    if ( GlobalSearch == True ) {

    Restrict1:
    if ( Back_Search ) {
    if ( Restrict ) {
    Goto_Line( Block_Line2 );
    Eol;
    }
    else {
    Eof;
    }
    }
    else {
    if ( Restrict ) {
    Goto_Line( Block_Line1 );
    Goto_Col( 1 );
    Goto_Col( Block_Col1 );
    }
    else {
    Tof;
    }
    }
    }
    Insert_Mode = True;
    Searching = True;

    if ( NoPrompt && Search_Mode ) {
    Refresh = False;
    }

    Error_Level = 0;

    while ( Searching ) {
    Refresh = False;
    ProcessMsgQueue( 10 );
    if ( NoPrompt ) {
    if ( Msg_Hit_Count++ > 100 ) {
    Msg_Hit_Count = 0;
    if ( Search_Mode ) {
    Make_Message( “Searching… Replaces:” + Str( Count ) +
    to abort.” );
    }
    else {
    Make_Message( “Searching… Occurrences:” + Str( FoundNum ) +
    to abort.” );
    }
    }
    }
    else {
    if ( ( g_SWrapFlags & _swf_NoMessage ) == 0 ) {
    Make_Message( “Searching…
    to abort.” );
    }
    }
    Working;
    Orig_Line = C_Line;
    Orig_Row = C_Row;
    if ( Back_Search ) {
    if ( Restrict ) {

    _SAgain2:
    Restrict_Count = C_Line – Block_Line1 + 1;
    if ( Restrict_Count < 1 ) { goto Search_Out; } if ( Across_Lines ) { Return_Str = Search_Str; Rm( "Srch_Across_Line /R=" + Str( Restrict_Count ) + "/B=" + Str( Back_Search ) ); S_Res = Return_Int; } else { S_Res = Find_Text_Ex( Search_Str, Restrict_Count, S_Flags, Rbc1, Rbc2 ); } // Check to see if the last Time we went through this loop we set the // at_top flag. if so, consider this find to have failed to avoid a // continuous loop if ( At_Top ) { S_Res = 0; } // Set special flag if we are already at the top of the file so we // don't get into a continuous loop At_Top = ( C_Line == 1 ) && ( C_Col == 1 ); if ( S_Res ) { // if( Block_Stat == 2 ) { // if( ( C_Col < Block_Col1 ) | ( ( C_Col + Length( Found_Str ) - 1 ) > Block_Col2 ) ) {
    // call searchmove;
    // goto _SAgain2;
    // }
    // }
    // else
    if ( Block_Stat == 3 ) {
    if ( ( ( C_Line == Block_Line1 ) & ( C_Col < Block_Col1 ) ) ) { call SearchMove; goto _SAgain2; } else if ( ( ( C_Line == Block_Line2 ) & ( ( C_Col + Length( Found_Str ) - 1 ) > Block_Col2 ) ) ) {
    call SearchMove;
    goto _SAgain2;
    }
    }
    }
    }
    else {
    if ( Across_Lines ) {
    Return_Str = Search_Str;
    Rm( “Srch_Across_Line /R=” + Str( Restrict_Count ) +
    “/B=” + Str( Back_Search ) );
    S_Res = Return_Int;
    }
    else {
    S_Res = Find_Text_Ex( Search_Str, Restrict_Count, s_flags, rbc1, rbc2 );
    }

    // Check to see if the last Time we went through this loop we set the
    // at_top flag. if so, consider this find to have failed to avoid a
    // continuous loop
    if ( At_Top ) {
    S_Res = 0;
    }

    // Set special flag if we are already at the top of the file so we
    // don’t get into a continuous loop
    At_Top = ( ( C_Line == 1 ) && ( C_Col == 1 ) );
    }
    }
    else {
    if ( Restrict ) {

    _SAgain:
    Restrict_Count = Block_Line2 – C_Line + 1;
    if ( Restrict_Count < 1 ) { goto Search_Out; } if ( Across_Lines ) { Return_Str = Search_Str; Rm( "Srch_Across_Line /R=" + Str( Restrict_Count ) + "/B=" + Str( Back_Search ) ); S_Res = Return_Int; } else { S_Res = Find_Text_Ex( Search_Str, Restrict_Count, s_flags, rbc1, rbc2 ); } if ( S_Res ) { // if( Block_Stat == 2 ) { // if( ( C_Col < Block_Col1 ) | ( ( C_Col + Length( Found_Str ) - 1 ) > Block_Col2 ) ) {
    // call searchmove;
    // goto _SAgain;
    // }
    // }
    // else
    if ( Block_Stat == 3 ) {
    if ( ( C_Line == Block_Line1 ) && ( C_Col < Block_Col1 ) ) { call SearchMove; goto _SAgain; } else if ( ( C_Line == Block_Line2 ) && ( ( C_Col + Length( Found_Str ) - 1 ) > Block_Col2 ) ) {
    call SearchMove;
    goto _SAgain;
    }
    }
    }
    }
    else {
    if ( Across_Lines ) {
    Return_Str = Search_Str;
    Rm( “Srch_Across_Line /R=” + Str( Restrict_Count ) +
    “/B=” + Str( Back_Search ) );
    S_Res = Return_Int;
    }
    else {
    S_Res = Find_Text_Ex( Search_Str, Restrict_Count, S_Flags, RbC1, RbC2 );
    }
    }
    }

    // This only occurs if user pressed
    if ( Error_Level == 1015 ) {
    Make_Message( “Search aborted by user.” );
    Error_Level = 0;
    goto S_And_R_Exit;
    }
    if ( S_Res ) {
    if ( FoundNum == 0 ) {
    ++All_Windows_Count;
    if ( Making_List ) {

    // Add file info to Find list
    FindLstSetFile( LstId, 1, Get_Path( File_Name ),
    Truncate_Path( File_Name ), False );
    }
    else {
    Pop_Mark;
    }
    }
    ++FoundNum;
    if ( Making_List ) {
    SpareString = Get_Line( );
    Tabs_To_Spaces( SpareString );
    Tab_Expand = True;

    // Add found info to Find list
    FindLstSetFound( LstId, C_Line, SpareString );

    ProcessMsgQueue( 10 ); // *** ldh test ***
    }
    if ( Search_Mode ) {
    if ( Read_Only ) {
    Searching = False;
    }
    else {
    call Do_Replace_Prompt;
    }
    }
    else {
    call Do_Search_Prompt;
    }
    }
    else {
    Searching = False;
    if ( FoundNum == 0 ) {
    Goto_Mark;
    }
    }
    }

    Search_Out:
    if ( Making_List && FoundNum ) {

    // Update file info found count in Find list
    FindLstSetFile( LstId, FoundNum, “”, “”, True );
    }
    All_Windows_FoundNum += FoundNum;
    if ( Search_All_Windows ) {
    if ( !S_Prompt && FoundNum && !Making_List && !NoPrompt) {

    // We should only get here if we have stop on first occurrence selected
    Search_All_Windows = False;
    goto All_Windows_Found;
    }
    if ( !Skip_All ) {
    if ( All_Windows_Count > 1 ) {
    Goto_Mark;
    }
    Pop_Undo;
    if ( Link_Stat ) {
    if ( !XPos( ” ” + Str( Buffer_Id ) + ” “, SearchLinks, 1 ) ) {
    SearchLinks += Str( Buffer_Id ) + ” “;
    }
    }

    NextWin:
    if ( !GlobalSearch ) {
    if ( ( g_SWrapFlags & _swf_Wrapped ) && ( Window_Id == g_SWrapWinId ) ) {
    goto All_Windows_Found; // We have wrapped once so exit
    }
    }
    if ( Back_Search ) {
    Switch_Window( Cur_Window – 1 );
    }
    else {
    Switch_Window( Cur_Window + 1 );
    }
    ++All_Windows_Scanned;
    Rm( “FindWin /HIDDEN=1/B=” + Str( Back_Search ) );
    Push_Undo;
    Active_Window = Window_Id;
    if ( Window_Id == g_SWrapWinId ) {

    // Set wrapped flag
    g_SWrapFlags |= _swf_Wrapped;
    }
    if ( Window_Id != First_Window ) {
    if ( Link_Stat ) {
    if ( XPos( ” ” + Str( Buffer_Id ) + ” “, SearchLinks, 1 ) ) {
    goto NextWin;
    }
    }
    All_Windows_Global = True;
    FoundNum = 0;
    goto Start_Search;
    }
    }
    }
    else {
    ++All_Windows_Scanned;
    }

    All_Windows_Found:
    Set_Global_Int( “Menu_Result”, True );
    if ( Making_List && ( FoundNum || All_Windows_FoundNum ) ) {

    // Update found count in Find list
    FindLstSetHeader( LstId, All_Windows_Count, All_Windows_FoundNum, All_Windows_Scanned, 0, “”, “”,
    “”, “”, True );
    Goto_Mark;
    }
    else {
    SpareString = “\”” + g_SearchStr + “\””;
    if ( Search_All_Windows ) {
    SpareString += ” found ” + Str( All_Windows_FoundNum ) + ” time(s) in ” +
    Str( All_Windows_Count ) + ” file(s). Scanned ” +
    Str( All_Windows_Scanned ) + ” file(s).”;
    }
    else {
    if ( Search_Mode ) {
    SpareString += ” replaced ” + Str( Count ) + ” time(s).”;
    }
    else {
    SpareString += ” found ” + Str( FoundNum ) + ” time(s).”;
    }
    }
    if ( ( g_SWrapFlags & _swf_NoMessage ) == 0 ) {
    Make_Message( SpareString );
    }
    }
    if ( Making_List ) {

    // Show Find list
    FindLstDlg( LstId, _pwa_SelTab, _pws_Show );
    }
    goto S_And_R_Exit;

    Do_Replace_Prompt:
    if ( NoPrompt == False ) {
    call Highlight_Find;
    if ( !S_Prompt ) {
    Searching = False;
    }

    Replace_Loop1:
    if ( g_SRModalDlg ) {
    Return_Int = Create_SR_Dialog( Search_Mode, File_Replace, S_Prompt, Search_All_Windows );
    }
    else {
    Return_Int = SReturn_Int;
    if ( Return_Int == 555 ) {
    if ( g_hSRDialog ) {
    if ( GetActiveWindow( ) != g_hSRDialog ) {
    SetActiveWindow( g_hSRDialog );
    }
    SReturn_Int = 0;
    Return_Int = 0;
    }
    else {
    TSearch_Highlight = Search_Highlight;
    if ( g_SearchMode ) {
    TabNo = _tab_sr_Replace;
    }
    else {
    TabNo = _tab_sr_Search;
    }
    Rm( “SearchTabDlg /T#=” + Str( TabNo ) + “/SRG=” + _g_SearchStr + “/RPG=” + _g_ReplaceStr );
    Search_Highlight = TSearch_Highlight;
    }
    }
    }
    if ( Return_Int == 103 ) { // Skip
    call SearchMove;
    }
    else if ( Return_Int == 104 ) { // Non stop
    NoPrompt = True;
    }
    else if ( Return_Int == 105 ) { // All files
    NoPrompt = True;
    All_Files = 1;
    }
    else if ( Return_Int == 106 ) { // Skip file
    Searching = False;
    }
    else if ( Return_Int == 107 ) { // Skip window
    Searching = False;
    }
    else if ( ( Return_Int == 102 ) || ( Return_Int == 0 ) ) { //value of -100 is used because
    All_Files = -1;
    Skip_All = 1; // we subtract 100 from the value
    Searching = False; // in Create_SR_Dialog
    }
    else if ( ( Return_Int == 101 ) || ( Return_Int == 555 ) ) { // Again
    if ( !g_SRModalDlg ) {
    SReturn_Int = 0;
    }
    call _DoReplace;
    // T_Col = C_Col;
    // if ( Across_Lines ) {
    // Return_Str = Replace_Str;
    // Rm( “Repl_Across_Line ” );
    // }
    // else {
    // Replace( Replace_Str );
    // }
    // if ( No_Cursor_Movement ) {
    // Goto_Col( T_Col );
    // }
    // else {
    // if ( Back_Search ) {
    // Goto_Col( T_Col );
    // Left;
    // }
    // else {
    // while ( !At_Eol && ( Cur_Char == “\x01” ) ) {
    // Right;
    // }
    // if ( At_Eol ) {
    // Right;
    // }
    // }
    // }
    // ++Count;
    }
    else {
    goto Replace_Loop1;
    }
    // if ( NoPrompt == True ) {
    // goto NonStop;
    // }
    if ( NoPrompt == False ) {
    ret;
    }
    }
    // else {

    // NonStop:
    _DoReplace:
    T_Col = C_Col;
    if ( Across_Lines ) {
    Return_Str = Replace_Str;
    Rm( “Repl_Across_Line “);
    }
    else {
    Replace( Replace_Str );
    }
    if ( No_Cursor_Movement ) {
    //DebugLog( 0, “S_And_R”, “>1 %d:%d -> %d”, C_Line, C_Col, T_Col );
    Goto_Col( T_Col );
    }
    else {
    //DebugLog( 0, “S_And_R”, “>2 %d:%d -> %d”, C_Line, C_Col, T_Col );
    if ( Back_Search ) {
    Goto_Col( T_Col );
    Left;
    }
    else {
    while ( !At_Eol && ( Cur_Char == “\x01” ) ) {
    Right;
    }
    if ( At_Eol ) {
    Right;
    }
    }
    }
    //DebugLog( 0, “S_And_R”, “< %d:%d -> %d”, C_Line, C_Col, T_Col );
    ++Count;
    // }
    ret;

    Highlight_Find:
    Refresh = False;
    if ( Across_Lines ) {

    // This will scroll the screen to make as much of the phrase as possible visable
    Jx = Parse_Int( “/L=”, Global_Str( “@LINE_SEARCH_POS” ) ) – C_Line;
    if ( Jx > ( Win_Y2 – Win_Y1 ) ) {
    Jx = ( Win_Y2 – Win_Y1 );
    }
    Goto_Line( C_Line + Jx );
    }
    if ( Collapse_Mode & 0x01 ) {
    if ( Line_Stat & _ls_Hidden ) {
    Rm( “Collapse^CollapseMouse /M=2” );
    }
    }
    if ( C_Line > Orig_Line ) {
    if ( ( C_Line – Orig_Line ) < = ( ( Win_Y2 - Win_Y1 ) - C_Row ) ) { Tp = C_Line; Goto_Line( Orig_Line ); while ( C_Line < Tp ) { Down; } } else { call Center_Line; } } else { if ( ( Orig_Line - C_Line ) < C_Row ) { Tp = C_Line; Goto_Line( Orig_Line ); while ( C_Line > Tp ) {
    Up;
    }
    }
    else {
    call Center_Line;
    }
    }

    // Make sure found text is fully visible
    T_Col = C_Col;
    if ( Search_End_Line == C_Line ) {
    Tp = GetForceAdjOffset( );
    SetForceAdjOffset( True );
    Goto_Col( C_Col + Length( Found_Str ) + 10 );
    SetForceAdjOffset( Tp );
    Goto_Col( T_Col );
    }

    MarkFoundText = ( XPos( “M”, Switches_Str, 1 ) != 0 );
    if ( Across_Lines ) {

    // This brings the cursor back to the right place after the scrolling above
    Refresh = True;
    Redraw;
    for ( Jx; Jx > 0; Jx– ) {
    Up;
    }

    // Highlight the entire phrase
    Jx = Parse_Int( ‘/#=’,Global_Str( ‘@LINE_SEARCH_POS’ ) );
    if ( MarkFoundText && !Search_Mode ) {
    Mark_Pos;
    Str_Block_Begin;
    Goto_Line( Parse_Int( “/L=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ) );
    Goto_Col( Parse_Int( “/C=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ) +
    Length( Parse_Str( “/S=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ) ) –
    Stream_Block_Mode ); // Adjust for inclusive blocks
    Block_End;
    Goto_Mark;
    }
    else {
    Set_Highlight( C_Line, C_Col,
    Parse_Int( “/L=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ),
    Parse_Int( “/C=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ) +
    Length( Parse_Str( “/S=”, Global_Str( “@LINE_SEARCH_STR” + Str( Jx ) ) ) ) );
    }
    }
    else {
    if ( ( C_Line – C_Row ) != ( Orig_Line – Orig_Row ) ) {
    Redraw;
    }
    if ( MarkFoundText && !Search_Mode ) {
    Refresh = True;
    Hl = C_Line;
    Tp = C_Col;
    Goto_Line( Search_End_Line );
    Goto_Col( Search_End_Col – Stream_Block_Mode ); // Adjust for inclusive blocks
    Str_Block_Begin; //mnb block stuff
    Goto_Line( Hl );
    Goto_Col( Tp );
    Block_End; //mnb block stuff
    }
    else {
    Search_Highlight = Buffer_Id; //mnb block stuff commented out
    }
    if ( Event_Macro != “” ) {
    Key1 = 0;
    Key2 = 0;
    Rm( Event_Macro );
    }
    }
    ret;

    Do_Search_Prompt:
    if ( NoPrompt ) {
    call SearchMove;
    ret;
    }
    call Highlight_Find;
    if ( !S_Prompt ) {
    Make_Message( “String Found ” + Str( FoundNum ) + ” Times.” );
    Searching = False;
    ret;
    }
    if ( g_SRModalDlg ) {
    Return_Int = Create_SR_Dialog( Search_Mode, File_Replace, S_prompt,
    Search_All_Windows );
    }
    else {
    Return_Int = SReturn_Int;
    if ( Return_Int == 555 ) {
    if ( g_hSRDialog ) {
    if ( GetActiveWindow( ) != g_hSRDialog ) {
    SetActiveWindow( g_hSRDialog );
    }
    SReturn_Int = 0;
    Return_Int = 0;
    }
    else {
    TSearch_Highlight = Search_Highlight;
    if ( g_SearchMode ) {
    TabNo = _tab_sr_Replace;
    }
    else {
    TabNo = _tab_sr_Search;
    }
    Rm( “SearchTabDlg /T#=” + Str( TabNo ) + “/SRG=” + _g_SearchStr +
    “/RPG=” + _g_ReplaceStr );
    Search_Highlight = TSearch_Highlight;
    }
    }
    }

    Search_PromptX:
    if ( ( Return_Int == 102 ) || ( Return_Int == 0 ) ) { //value of -100 is used because
    Searching = False; //we subtract 100 from the value
    Skip_All = 1; //in Create_SR_Dialog
    }
    else if ( Return_Int == 103 ) {
    Searching = False;
    }
    else {
    call SearchMove;
    }
    ret;

    SearchMove:
    if ( Back_Search ) {
    Left;
    }
    else {
    Right;
    while ( !At_Eol && ( Cur_Char == “\x01” ) ) {
    Right;
    }
    if ( At_Eol ) {
    Right;
    }
    }
    ret;

    Center_Line:

    int TOldLine;

    New_Line_Num = C_Line;
    Tp = ( Win_Y2 – Win_Y1 ) / 2;

    // These lines will center the selected line on the screen if possible
    while ( C_Row > Tp ) {
    TOldLine = C_Line;
    Up;
    if ( TOldLine == C_Line ) {
    break;
    }
    }
    while ( C_Row < Tp ) { TOldLine = C_Line; Down; if ( TOldLine == C_Line ) { break; } } Goto_Line( New_Line_Num ); ret; S_And_R_Exit: Tab_Expand = T_Tab_Expand; Persistent_Blocks = TPb; if ( Search_All_Windows ) { g_FoundCount = All_Windows_FoundNum; } else { g_FoundCount = FoundNum; } g_ReplaceCount = Count; Pop_Undo; g_RepSearch = False; Reg_Exp_Stat = True; Rm( "Select_Window" ); Refresh = SavRefresh; Insert_mode = TInsert_Mode; Redraw; if ( Across_Lines ) { Jx = Parse_Int( "/#=", Global_Str( "@LINE_SEARCH_POS" ) ); while ( Jx ) { Set_Global_Str( "@LINE_SEARCH_STR" + Str( Jx ), "" ); --Jx; } Set_Global_Str( '@LINE_SEARCH_POS', '' ); } if ( File_Replace ) { Return_Int = All_Files; } else { if ( g_SearchMode ) { if ( Jx = XPos( "N", Switches_Str, 1 ) ) { Switches_Str = Str_Del( Switches_Str, Jx, 1 ); } Set_Global_Str( SwitchesGlobal, Switches_Str ); } else { if ( Jx = XPos( "L", Switches_Str, 1 ) ) { Switches_Str = Str_Del( Switches_Str, Jx, 1 ); } Set_Global_Str( SwitchesGlobal, Switches_Str ); } } if ( Making_List ) { FindLstUpdate( LstId ); } } // S_And_R /*------------------------------------------------------------------------------ Name: SRCH_ACROSS_LINE Description: Performs Word/Phrase search --------------------------------------------------------------------( ldh )--*/ macro Srch_Across_Line trans2 { str Current_Word[ 80 ]; str T_Delimits[ 40 ] = Word_Delimits; str Punctuation[ 5 ] = ',.?;:'; int Restrict_Count = Parse_Int('/R=',MParm_Str); int Back_Search = Parse_Int('/B=',MParm_Str); int Word_Index; int Word_Count = 0; int Check_Col; int Ret_Val = 0; Reg_Exp_Stat = False; if ( Global_Str( "@Phrase_Srch_Delim" ) != "" ) { Word_Delimits = Global_Str( "@Phrase_Srch_Delim" ); } if ( Ignore_Case ) { Return_Str = Caps( Return_Str ); } Ret_Val = 0; Rm( "Parse_Phrase /M=0" ); Word_Count = Return_Int; if ( Word_Count < 1 ) { goto Exit; } Search_Again: Word_Index = 1; if ( Back_Search ) { if ( ( C_Line == 1 ) && ( C_Col == 1 ) ) { goto Exit; // if we are at the top of the file already, get out! } if ( Search_Bwd( Parse_Str( "/S=", Global_Str( "@Line_Search_Str1" ) ), Restrict_Count ) == 0 ) { goto Exit; } } else { if ( At_Eof ) { goto Exit; // if we are at the end of the file already, get out! } if ( Search_Fwd( Parse_Str( "/S=", Global_Str( "@Line_Search_Str1" ) ), Restrict_Count ) == 0 ) { goto Exit; } } Set_Global_Str( "@Line_Search_Str1", "/S=" + Parse_Str( "/S=", Global_Str( "@Line_Search_Str1" ) ) + "/L=" + Str( C_Line ) + "/C=" + Str( C_Col ) ); // Check to make sure that we found a whole word Mark_Pos; if ( ( C_Col > 1 ) && ( XPos( Cur_Char, Punctuation, 1 ) == 0 ) ){
    Left;

    // For the first word, we’ll acccept default word delimiters as leading chars
    if ( XPos( Cur_Char, T_Delimits, 1 ) == 0 ) {
    Pop_Mark;
    if ( !Back_Search ) {
    Word_Right;
    }
    goto Search_Again;
    }
    Right;
    }
    if ( Word_Count > 1 ) {
    Goto_Col( C_Col + Length( Found_Str ) );
    if ( ( At_Eol == 0 ) && ( XPos( Cur_Char, Word_Delimits, 1 ) == 0 ) ) {
    Pop_Mark;
    goto Search_Again;
    }
    Goto_Mark;
    Mark_Pos;
    Word_Right;
    if ( !At_Eol ) {
    Word_Left;
    }
    }

    Check_Next_Word:
    if ( Word_Index == Word_Count ) {

    // If we found all the words, then…
    if ( Word_Count == 1 ) {
    Goto_Col( C_Col + Length( Found_Str ));
    if ( ( At_Eol == 0 ) & ( XPos( Cur_Char, T_Delimits, 1 ) == 0 ) ) {
    if ( back_search ) {
    Goto_Mark;
    Left;
    } else {
    Pop_Mark;
    }
    goto SEARCH_AGAIN;
    }
    }
    Set_Global_Str( “@Line_Search_Pos”, “/L=” + Str( C_Line ) + “/C=” + Str( C_Col ) + “/#=” + Str( Word_Count ) );
    Goto_Mark;
    Ret_Val = 1;
    goto Exit;
    }
    ++Word_Index;

    Eol_Delimits:
    Word_Right;
    if ( ( ( XPos( Cur_Char, Word_Delimits, 1 ) | ( At_Eol == True ) ) > 0 ) && !At_Eof ) {

    // We would only get here if there are word delimiters at the end of a line
    goto Eol_Delimits;
    }
    Check_Col = C_Col;
    if ( Word_Index == Word_Count ) {

    // On the last word, allow trailing chars according to users word delimits
    Current_Word = Get_Word( T_Delimits );
    }
    else {
    Current_Word = Get_Word( Word_Delimits );
    }
    if ( Ignore_Case ) {
    Current_Word = Caps( Current_Word );
    }
    if ( Current_Word != Parse_Str( “/S=”, Global_Str( “@Line_Search_Str” + Str( Word_Index ) ) ) ) {
    Goto_Mark;
    if ( Back_Search ) {
    Left;
    }
    else {
    Right;
    }
    goto Search_Again;
    }
    Set_Global_Str( “@Line_Search_Str” + Str( Word_Index ), “/S=” + Current_Word + “/L=” + Str( C_Line ) + “/C=” + Str( Check_Col ) );

    goto Check_Next_Word;

    Exit:
    Return_Int = Ret_Val;
    Word_Delimits = T_Delimits;

    } // Srch_Across_Line

    macro Parse_Phrase trans2
    {
    str Search_Str = Return_Str;
    str Current_Word[ 80 ];
    str GStr[ 18 ];

    int Copy_Index = 1;
    int Word_Count = 0;

    char Ch;

    if ( Parse_Int( “/M=”, MParm_Str ) ) {
    GStr = “@Line_Replace_Str”;
    }
    else {
    GStr = “@Line_Search_Str”;
    }
    do {
    Current_Word = ”;
    while ( Copy_Index < = Svl( Search_Str ) ) { Ch = Str_Char( Search_Str, Copy_Index ); ++Copy_Index; if ( XPos( Ch, Word_Delimits, 1 ) != 0 ) { break; } Current_Word += Ch; } if ( Svl( Current_Word ) != 0 ) { ++Word_Count; Set_Global_Str( GStr + Str( Word_Count ), "/S=" + Current_Word ); } // Find the beginning next word in Search_Str for next time while ( ( Copy_Index < Svl( Search_Str ) ) && ( XPos( Str_Char( Search_Str, Copy_Index ), Word_Delimits, 1 ) > 0 ) ) {
    ++Copy_Index;
    }
    } while ( Copy_Index < = Svl( Search_Str ) ); Return_Int = Word_Count; } // Parse_Phrase /*------------------------------------------------------------------------------ Function: Performs Word/Phrase replace. --------------------------------------------------------------------( ldh )--*/ macro Repl_Across_Line trans2 { str T_Delimits[40] = Word_Delimits; int Search_Count = Parse_Int( "/#=", Global_Str( "@Line_Search_Pos" ) ); int Done_Count; int Replace_Count; int T_line = C_Line; int T_Row = C_Row; Refresh = False; Word_Delimits = " \t\x01"; if ( Global_Str( "@Phrase_Srch_Delim" ) != "" ) { Word_Delimits = Global_Str( "@Phrase_Srch_Delim" ); } Rm( "Parse_Phrase /M=1" ); Replace_Count = Return_Int; Mark_Pos; // Place markers at the beginning of every found WORD, then at the end of the // found phrase Goto_Line( Parse_Int( "/L=", Global_Str( "@Line_SEarch_Pos" ) ) ); Goto_Col( Parse_Int( "/C=", Global_Str( "@Line_Search_Pos" ) ) ); Insert_Mode = True; Text( '|0' ); for ( Done_Count = 1; Done_Count <= Search_Count; Done_Count++ ) { Goto_Line( Parse_Int( "/L=", Global_Str( "@Line_Search_Str" + Str( Done_Count ) ) ) ); Goto_Col( Parse_Int( '/C=', Global_Str( "@Line_Search_Str" + Str( Done_Count ) ) ) ); Insert_Mode = False; Text( '|0' ); } Goto_Mark; Insert_Mode = True; for ( Done_Count = 1; Done_Count <= Search_Count; Done_Count++ ) { Goto_Line( Parse_Int( "/L=", Global_Str( "@Line_Search_Str" + Str( Done_Count ) ) ) ); Goto_Col( 1 ); Search_Fwd( '|0', 1 ); Del_Chars( Length( Parse_Str( "/S=", Global_Str( "@Line_Search_Str" + Str( Done_Count ) ) ) ) ); if ( Done_Count <= Replace_Count ) { Text( Parse_Str( "/S=", Global_Str( "@Line_Replace_Str" + Str( Done_Count ) ) ) ); } } while ( Search_Count < Replace_Count ) { ++Search_Count; Text( " " + Parse_Str( "/S=", Global_Str( "@Line_Replace_Str" + Str( Search_Count ) ) ) ); } // Get rid of end of found phrase mark if ( Search_Fwd( '|0', 1 ) ) { Del_Char; } // Fix it so the display does not scroll unless neccessary t_row = t_row + ( C_Line - t_line ); t_line = C_Line; while ( C_Row < t_row ) { Down; } Goto_Line( t_line ); Refresh = True; for ( Replace_count; Replace_count > 0; Replace_count– ) {
    Set_Global_Str( “@Line_Replace_Str” + Str( Replace_Count ), “” );
    }
    Word_Delimits = T_Delimits;

    } // Repl_Across_Line

    /*——————————————————————————

    Function: Prompt to ask to continue search after wrapping.
    Entry : int Direction – Direction of search 0 – Fwd, 1 – Bwd
    Exit : int – 0 = no, 1 = yes
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    int _SearchWrapPrompt( int Direction ) trans2
    {
    int Jx;

    str DirMsg = “top”;
    str Dir2Msg = “end”;

    if ( Direction ) {
    DirMsg = “end”;
    Dir2Msg = “top”;
    }
    Jx = VerifyDlg( “The ” + Dir2Msg + ” of file was reached with nothing found.\n” +
    “Continue searching from the ” + DirMsg + “?”, “”, “”, 0, 0 );

    return ( Jx == id_std_Yes );

    } // _SearchWrapPrompt

    /*——————————————————————————

    Function: Calls S_and_R in search only mode.
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    macro Search trans2
    {
    g_RepSearch = False;
    if ( g_DefSearchOpts & _so_UseSrDef ) {
    g_Switches = g_DefSwitches;
    }
    Rm( “SearchTabDlg /T#=” + Str( _tab_sr_Search ) + “/SRG=” + _g_SearchStr );

    } // Search

    /*——————————————————————————

    Function: Calls S_and_R in search and replace mode.
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    macro S_Repl trans2
    {
    g_RepSearch = False;
    if ( g_DefSearchOpts & _so_UseSrDef ) {
    g_ReplSwitches = g_DefReplSwitches;
    }
    Rm( “SearchTabDlg /T#=” + Str( _tab_sr_Replace ) + “/SRG=” + _g_SearchStr +
    “/RPG=” + _g_ReplaceStr );

    } // S_Repl

    /*——————————————————————————

    Function: Calls S_and_R in repeat mode.
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    macro RepSrch trans2
    {
    int SavRefresh = Refresh;
    int SavPBlocks = Persistent_Blocks;
    int OrgWinId = Window_Id;
    int NoMessage = False;
    int Jx;
    int Bwd;
    int GlobalSearch;
    int Wrap;

    Refresh = False;
    Persistent_Blocks = True;
    Push_Undo;
    Mark_Pos;
    if ( g_SearchMode ) {
    Bwd = XPos( “B”, Caps( g_ReplSwitches ), 1 );
    GlobalSearch = XPos( “G”, Caps( g_ReplSwitches ), 1 ) != 0;
    }
    else {
    Bwd = XPos( “B”, Caps( g_Switches ), 1 );
    GlobalSearch = XPos( “G”, Caps( g_Switches ), 1 ) != 0;
    }
    if ( Bwd ) {
    Left;
    }
    else {
    Right;
    while ( !At_Eol && ( Cur_Char == “\x01” ) ) {
    Right;
    }
    }
    if ( g_SearchStr != “” ) {
    g_RepSearch = True;
    }
    while ( True ) {
    if ( !g_SRModalDlg ) {
    SReturn_Int = 555;
    }
    Rm( “S_And_R ” + MParm_Str );
    Jx = Window_Id == OrgWinId;
    if ( Jx ) {
    call CheckWrap;
    if ( g_FoundCount == 0 ) { // changed to not look at return_int
    if ( Wrap ) {
    g_SWrapFlags &= ( 0xFFFFFFFF ^ _swf_NoMessage );
    NoMessage = g_SWrapFlags & _swf_NoMessage;
    switch ( Bwd ) {

    case 0 :
    Tof;
    continue;

    case 1 :
    Eof;
    continue;
    }
    }
    Goto_Mark;
    if ( !NoMessage ) {
    Make_Message( “No more occurrences.” );
    Beep;
    }
    }
    else {
    if ( Wrap ) {
    g_FoundCount = 0;
    Goto_Mark;
    Goto_Line( g_SWrapLine );
    Goto_Col( g_SWrapCol );
    if ( ( g_SWrapFlags & _swf_NoMessage ) == 0 ) {
    Make_Message( “No more occurrences.” );
    Beep;
    }
    }
    else {
    Pop_Mark;
    }
    if ( !g_SRModalDlg ) {
    g_RepSearch = True;
    }
    }
    }
    else {
    Jx = Window_Id;

    // Restore marked position in original file
    Switch_Win_Id( OrgWinId );
    Goto_Mark;
    Switch_Win_Id( Jx );
    if ( !g_SRModalDlg ) {
    g_RepSearch = True;
    }
    }
    break;
    }
    Pop_Undo;
    Persistent_Blocks = SavPBlocks;
    Refresh = SavRefresh;
    Redraw;
    return ( );

    // Internal Routines ———————————————————–

    CheckWrap:
    Wrap = False;
    if ( ( g_DefSearchOpts & _so_AutoWrap ) && !GlobalSearch ) {
    if ( g_FoundCount == 0 ) { // changed to not look at return_int

    // Show wrap prompt if we have not already wrapped
    if ( ( g_SWrapFlags & _swf_Wrapped ) == 0 ) {
    g_SWrapFlags |= _swf_Wrapped;
    if ( ( g_DefSearchOpts & _so_NoWrapPrompt ) ) {
    Wrap = True;
    }
    else {
    Wrap = _SearchWrapPrompt( Bwd );
    }
    }
    else {
    g_SWrapFlags &= ( 0xFFFFFFFF ^ _swf_Wrapped );
    }
    }
    else {

    // Check for wrapped
    if ( ( g_SWrapFlags & _swf_Wrapped ) != 0 ) {
    if ( Bwd ) {
    if ( C_Line < g_SWrapLine ) { Wrap = True; } else if ( ( C_Line == g_SWrapLine ) && ( C_Col <= g_SWrapCol ) ) { Wrap = True; } } else { if ( ( C_Line > g_SWrapLine ) ) {
    Wrap = True;
    }
    else if ( ( C_Line == g_SWrapLine ) && ( C_Col >= g_SWrapCol ) ) {
    Wrap = True;
    }
    }
    }
    if ( Wrap ) {
    g_SWrapFlags &= ( 0xFFFFFFFF ^ _swf_Wrapped );
    }
    }
    }
    ret;

    } // RepSrch

    /*——————————————————————————

    Function: Search for the currently marked word.
    Entry : int Direction – 0 Search forward, 1 – Search backward ( /D= )
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    void SearchWord( int Direction = Parse_Int( “/D=”, MParm_Str ) ) trans2
    {
    int TPb = Persistent_Blocks;
    int TRefresh = Refresh;

    Persistent_Blocks = True;
    Refresh = False;
    if ( ( Block_Stat > 0 ) && ( Block_Line1 == Block_Line2 ) ) {

    int TSearchMode = g_SearchMode;

    str TSwitches = g_Switches; // Save search option switches

    Mark_Pos;
    Goto_Line( Block_Line1 );

    g_SearchStr = Copy( Get_Line, Block_Col1, Block_Col2 – Block_Col1 + 1 );
    Goto_Mark;
    if ( Length( g_SearchStr ) ) {
    g_SearchMode = 0; // Set for search only (no replace)
    if ( Direction ) {
    g_Switches = “IBX”;
    if ( ( Block_Line1 == C_Line ) && ( C_Col > Block_Col1 ) ) {
    Goto_Col( Block_Col1 );
    }
    Left;
    }
    else {
    g_Switches = “IX”;
    Right;
    }
    g_RepSearch = 1;
    SReturn_Int = 1;
    Rm( “S_And_R” );
    if ( g_FoundCount == 0 ) {

    // Adjust cursor
    if ( Direction ) {
    Right;
    }
    else {
    Left;
    }
    }
    g_RepSearch = 0;
    g_Switches = TSwitches; // restore search option switches
    g_SearchMode = TSearchMode; // restore search mode
    }
    else {
    Make_Message( “Nothing marked to find” );
    }
    }
    else {
    Mark_Pos;
    Right;
    Word_Left;
    Str_Block_Begin;
    Get_Word( Word_Delimits );
    Block_End;
    Goto_Mark;
    }
    Refresh = TRefresh;
    Persistent_Blocks = TPb;

    } // SearchWord

    /*——————————————————————————

    Module Name: IncSrch

    Description: Incremental Search such as in Emacs and such.

    Creation Date: 02-19-93 04:07pm
    MNB modified to make this usable for MEW 09-09-94

    Key Assignments: – cancels search and returns cursor to
    original position prior to the search.
    – searches backwards (previous)
    – searches for next occurrence
    – removes the last char in the search
    string and searches for the new string
    – performs a word search
    – performs case sensitive searching

    ——————————————————————–( ldh )–*/
    macro IncSrch trans2
    {
    int t_Reg_Exp_Stat = Reg_Exp_Stat; // Save system vars so we can restore
    int t_Ignore_Case = Ignore_Case; // them to their original state on exit
    int t_Refresh = Refresh;
    int orig_line;
    int tp;
    int New_line_Num;
    int newline;
    int backward = Parse_Int( ‘/BWD=’, MParm_Str );
    int case_sensitive = 0;
    int MsgChanged = True;
    int Found = True;
    int Again = 0;
    int Done = False;
    int Kx;
    int AddChar;

    str Search_Str;
    str MStr;
    str Word_Srch;
    str Bwd;
    str Cs;

    struct TMsg Msg;
    struct TKeyboardState KState;

    if ( Backward != 0 ) {
    Backward = _Backward;
    Bwd = “Bwd “;
    }
    Reg_Exp_Stat = False;
    Ignore_Case = True;
    Mark_Pos;
    while ( True ) {
    while ( !PeekMessage( &Msg, 0, 0, 0, pm_NoRemove ) ) {
    Sleep( 10 );
    }
    AddChar = False;
    if ( MsgChanged ) {
    Redraw;
    Orig_Line = C_Line;
    NewLine = 0;
    Make_Message( Bwd + Cs + “I-Search: ” + Word_Srch + “\”” + Search_Str +
    “\” ” + MStr );
    MsgChanged = False;
    }
    Refresh = False;
    switch ( Msg.Message ) {

    case wm_VScroll :

    // Ignore mouse scroll generated messages
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    break;

    case wm_SysKeyDown :
    case wm_KeyDown :
    if ( ( Msg.WParam == vk_Capital ) || ( Msg.WParam == vk_NumLock ) ) {
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    TranslateMessage( &Msg );
    DispatchMessage( &Msg );
    break;
    }
    if ( Msg.WParam == vk_Escape ) {
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    Done = True;
    break;
    }
    if ( ( Msg.WParam == vk_Shift ) || ( Msg.WParam == vk_Control ) ||
    ( Msg.WParam == vk_Menu ) ) {
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    break;
    }
    if ( Msg.WParam == vk_Back ) {
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    MsgChanged = True;
    Search_Str = Str_Del( Search_Str, Svl( Search_Str ), 1 );
    if ( Svl( Search_Str ) == 0 ) {
    break;
    }
    goto Search_Only;
    }
    if ( Msg.Message == wm_SysKeyDown ) {
    if ( Msg.WParam == 87 ) { // Alt W
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    MsgChanged = True;
    if ( Global_Int( “Inc_Word_Srch” ) ) {
    Set_Global_Int( “Inc_Word_Srch”, 0 );
    Word_Srch = “”;
    }
    else {
    Set_Global_Int( “Inc_Word_Srch”, 1 );
    Word_Srch = “Word “;
    if ( Svl( Search_Str ) != 0 ) {
    goto Search_Only;
    }
    }
    }
    else if ( Msg.WParam == 67 ) { // Alt C
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    MsgChanged = True;
    if ( Case_Sensitive ) {
    Case_Sensitive = 0;
    Ignore_Case = True;
    Cs = “”;
    }
    else {
    Case_Sensitive = _CaseSensitive;
    Ignore_Case = False;
    Cs = “Case “;
    if ( Svl( Search_Str ) != 0 ) {
    goto Search_Only;
    }
    }
    }
    else if ( Msg.WParam == 78 ) { // Alt N
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    MsgChanged = True;
    Backward = 0;
    Bwd = “”;
    Again = 1;
    Right;
    goto Search_Only;
    }
    else if ( Msg.WParam == 80 ) { // Alt P
    PeekMessage( &Msg, 0, 0, 0, pm_Remove );
    MsgChanged = True;
    Backward = _backward;
    Bwd = “Bwd “;
    Again = -1;
    Left;
    goto Search_Only;
    }
    else {
    Done = True;
    break;
    }
    }
    else {
    Kx = 0;
    GetKeyboardState( &KState );
    if ( ToAscii( Msg.WParam, MapVirtualKey( Msg.WParam, 0 ), &KState.K,
    &Kx, 0 ) < 1 ) { Done = true; break; } PeekMessage( &Msg, 0, 0, 0, pm_Remove ); TranslateMessage( &Msg ); } break; case wm_Char : PeekMessage( &Msg, 0, 0, 0, pm_Remove ); // All alphanumeric keys are added to the search string, // but only if the new search string finds something. str Jx = Char( Msg.WParam ); // if ( !Found && Svl( Search_Str ) ) { // break; // } MsgChanged = True; Search_Str += Jx; AddChar = True; Search_Only: Mark_Pos; if ( Global_Int( "Inc_Word_Srch" ) ) { Return_Str = Search_Str; Rm( "Srch_Across_Line /B=" + Str( Backward ) ); } else { Return_Int = Find_Text( Search_Str, 0, Backward | Case_Sensitive ); } if ( Return_Int ) { Pop_Mark; if ( Collapse_Mode & 0x01 ) { if ( Line_Stat & 0x04 ) { Rm( "Collapse^CollapseMouse /M=2" ); } } call Highlight_Find; MStr = ""; Found = True; } else { Goto_Mark; if ( Again > 0 ) {
    Left;
    Find_Text( Search_Str, 0, Case_Sensitive );
    call Highlight_Find;
    }
    else if ( Again < 0 ) { Right; Find_Text( Search_Str, 0, Case_Sensitive ); call Highlight_Find; } Rm( "MEERROR^Beeps /C=2" ); MStr = " String not found"; Found = False; if ( AddChar ) { Search_Str = Copy( Search_Str, 1, Svl( Search_Str ) - 1 ); } } Again = 0; break; default: PeekMessage( &Msg, 0, 0, 0, pm_Remove ); if ( ( ( Msg.Message <= wm_MouseFirst ) || ( Msg.Message > wm_MouseLast ) ) &&
    ( ( Msg.Message < wm_NCLButtonDown ) || ( Msg.Message > wm_NCMButtonDblClk ) ) ) {
    TranslateMessage( &Msg );
    DispatchMessage( &Msg );
    }
    }
    if ( Done ) { // Cancel and return cursor to original
    break;
    }
    }
    if ( Msg.WParam == vk_Escape ) { // Cancel and return cursor to original
    Goto_Mark; // position if ESC is pressed
    Redraw;
    }
    else {
    Pop_Mark;

    // Set normal search to use the original search pattern
    g_SearchStr = Search_Str;
    g_SearchMode = False; // Force search for repeat
    }
    Reg_Exp_Stat = T_Reg_Exp_Stat; // Restore system variables
    Ignore_Case = T_Ignore_Case;
    Refresh = T_Refresh;

    Make_Message( “” ); // Erase prompt
    goto Done;

    // These subroutines were swiped from MEUTIL2 and modified a bit.

    Highlight_Find:
    if ( C_Line > Orig_Line ) {
    if ( ( C_Line – Orig_Line ) < = ( Win_CHeight - C_Row ) ) { Tp = C_Line; Goto_Line( Orig_Line ); while ( C_Line != Tp ) { Down; } } else { call Center_Line; } } else if ( NewLine == 0 ) { // if( (orig_line - c_line) <= (win_CHeight - (win_CHeight - c_row)) ) { if ( ( Orig_Line - C_Line ) < C_Row ) { Tp = C_Line; Goto_Line( Orig_Line ); while ( C_Line != Tp ) { Up; } } else { call Center_Line; } } if ( Event_Macro != "" ) { Key1 = 0; Key2 = 0; Rm( Event_Macro ); } Refresh = True; // tp = c_col; // goto_col(search_end_col); // goto_col(tp); Search_Highlight = Buffer_Id; ret; /* will center the selected line on the screen if possible */ Center_Line: New_Line_Num = C_Line; // tp = c_col; Tp = Win_CHeight / 2; while ( C_Row > Tp ) {
    Up;
    }
    while ( C_Row < Tp ) { Down; } Goto_Line( New_line_Num ); ret; Done: // Comment out the line below if you want the status of WORD search // to be restored Set_Global_Int( "Inc_Word_Srch", 0 ); } // IncSrch /*------------------------------------------------------------------------------ Function: Support macro for search list. It finds occurrences of the "/" character and duplicates the character Author : Dan Hughes --------------------------------------------------------------------( ldh )--*/ str ConvSL( str Cs[ max_Line_Length ] ) trans2 { int Position = 0; Position = XPos( "/", Cs, 1 ); while ( Position ) { Cs = Str_Ins( "/", Cs, Position ); Position = XPos( "/", Cs, Position + 2 ); } return ( Cs ); } // ConvSL /*------------------------------------------------------------------------------ Function: Called by Fs to perform the actual file search. Entry : str SearchStr Search string str FileSpec Files(s) to search str Mask str Root Root path to search if no dir is specified in the paths int SearchDirs 1 = search subdirectories. int Sm Search files in Memory. If a file is already loaded, then search there instead. int Sub "True" when called recursivly int Flags Search flags int Misc Miscellaneous options /FL=id List window id, used to search list of files specified in the window with id /BDFL=int When > 0 will bypass the deletion of the file
    list window
    /SW=str Switches string

    Exit : int Search results
    0 Successful
    -1 Aborted

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    int _FileSearch(
    str &SearchStr,
    str FileSpec,
    str Mask,
    str &Root,
    int SearchDirs,
    int Sm,
    int Flags,
    int Sub,
    str Misc
    ) trans2
    {
    TTRACE_ENTER(“Search”, TDBG_Trace, “_FileSearch(\”%s\”, \”%s\”, \”%s\”, \”%s\”, %d, %d, %d, %d, \”%s\”)”, SearchStr, FileSpec, Mask, Root, SearchDirs, Sm, Flags, Sub, Misc);

    str Path[ 255 ];
    str TStr[ max_Line_Length ];
    str TStr1[ max_Line_Length ];
    str MsgStr;
    str Switches = Parse_Str( “/SW=”, Misc );

    int T_Undo_Stat;
    int Jx;
    int Jy;
    int Pp;
    int FileOnly = SearchStr == “”;
    int FindHandle = 0;
    int SearchWin = g_SearchWin;
    int SavTabExpand = Tab_Expand;
    int FndLn;
    int InMemory = 0;
    int ListWin = Parse_Int( “/FL=”, Misc );
    int MsgDlg = g_FsMsgDlg;
    int LstId = Parse_Int( “/L=”, Misc );
    int DirAttr = _fa_Directory;
    int DirAttrMask = _fa_Directory;
    int FileAttr = 0;
    int FileAttrMask = 0;
    int Style;

    struct Win32_Find_Data NewFd;
    struct Dos_Find_Data OldFd;

    //DebugLog( 0, “_FileSearch”, “Sm=%d F=%d Sub=%d R=%s SS=%s P=%s Misc=%s”, Sm, Flags, Sub, Root, SearchStr, FileSpec, Misc );
    if ( FileOnly ) {
    if ( Svl( Mask ) == 0 ) {
    Mask = FileSpec;
    }
    MsgStr = “Searching for \”” + Mask + “\” in “;
    }
    else {
    MsgStr = “Searching for \”” + Copy( SearchStr, 1, 100 ) + “\” in “;
    }

    // Setup file attribute filter
    if ( XPos( “-1”, Switches, 1 ) ) {
    FileAttrMask |= _fa_Archive;
    }
    if ( XPos( “+1”, Switches, 1 ) ) {
    FileAttrMask |= _fa_Archive;
    FileAttr |= _fa_Archive;
    }
    if ( XPos( “-2”, Switches, 1 ) ) {
    FileAttrMask |= _fa_Hidden;
    }
    if ( XPos( “+2”, Switches, 1 ) ) {
    FileAttrMask |= _fa_Hidden;
    FileAttr |= _fa_Hidden;
    }
    if ( XPos( “-3”, Switches, 1 ) ) {
    FileAttrMask |= _fa_ReadOnly;
    }
    if ( XPos( “+3”, Switches, 1 ) ) {
    FileAttrMask |= _fa_ReadOnly;
    FileAttr |= _fa_ReadOnly;
    }
    if ( XPos( “-4”, Switches, 1 ) ) {
    FileAttrMask |= _fa_System;
    }
    if ( XPos( “+4”, Switches, 1 ) ) {
    FileAttrMask |= _fa_System;
    FileAttr |= _fa_System;
    }

    if ( Sub == 0 ) {

    str GFindLstTab = _g_FindLstTab + Str( LstId );

    int LstTab = Global_Int( GFindLstTab );

    T_Undo_Stat = Undo_Stat;
    Refresh = False;
    Undo_Stat = False;
    g_TotalFnd = 0;
    g_TotalScan = 0;
    g_TotalFiles = 0;
    if ( ListWin ) {
    Root = “File List”;
    }

    // Show find list dialog
    if ( LstTab ) {
    FindLstSetHeader( LstId, 0, 0, 1, Flags, SearchStr, FileSpec, Root,
    “/FF=1/SW=” + g_FSwitches + “/L=” + Str( LstId ), False );
    PanesShow( _pwt_Tool, _pws_Activate, LstTab );
    }
    if ( !FileOnly ) {

    // Translate regular expression aliases
    if ( ( Flags & _PerlExp ) == _PerlExp ) {
    Style = rasPerl;
    }
    else if ( Flags & _RegExp ) {
    Style = rasUnix;
    }
    else if ( Flags & _OldExp ) {
    Style = rasClassic;
    }
    SearchStr = ReTranslate( SearchStr, Style );

    // Setup to show all occurrences
    if ( Sm & 2 ) {
    Create_Window;
    SearchWin = Window_Id;
    g_SearchWin = SearchWin;
    Tab_Expand = True;
    }
    }

    // Create message dialog
    MsgDlg = OutputDlgCreate( “File Search”, “Searching…”, “BT_SR_103”, 40, 1, _od_Cancel );
    g_FsMsgDlg = MsgDlg;
    Return_Int = 0;
    Pp = 1;
    if ( ListWin ) {
    call _DoSearch;
    }
    else {
    while ( True ) {
    Path = FileSpec;
    if ( Pp < = Svl( Path ) ) { Jx = XPos( ";", Path, Pp ); Jy = XPos( " ", Path, Pp ); if ( ( Jy > 0 ) && ( ( Jy < Jx ) || ( Jx == 0 ) ) ) { Jx = Jy; } if ( Jx == 0 ) { Jx = Svl( Path ) + 1; } Path = Copy( Path, Pp, Jx - Pp ); Pp = Jx + 1; Mask = Truncate_Path( Path ); Path = Get_Path( Path ); if ( Svl( Path ) == 0 ) { // Process multiple paths in Root Jy = 1; while ( True ) { // Ignore leading spaces while ( Copy( Root, Jy, 1 ) == " " ) { ++Jy; } Jx = XPos( ";", Root, Jy ); if ( Jx == 0 ) { Jx = Svl( Root ) + 1; } Path = AddTrailingSlash( Copy( Root, Jy, Jx - Jy ) ); //DebugLog( 0, "_FileSearch", "y=%d x=%d P=%s R=%s", Jy, Jx, Path, Root ); Jy = Jx + 1; if ( Svl( Path ) ) { call _DoSearch; continue; } break; } } else { Path = AddTrailingSlash( FExpand( Path ) ); call _DoSearch; } continue; } break; } } } else { Path = FileSpec; call _DoSearch; } if ( Sub == 0 ) { // Kill message dialog OutputDlgKill( MsgDlg ); // Delete temporary search window if ( Switch_Win_Id( SearchWin ) ) { Delete_Window; } FindLstSetHeader( LstId, g_TotalFiles, g_TotalFnd, g_TotalScan, Flags, "", "", "", "", True ); Make_Message( "Scanned " + Str( g_TotalScan ) + " file(s)" ); // Clear global variables g_TotalFiles = 0; g_TotalFnd = 0; g_TotalScan = 0; g_SearchWin = 0; g_FsMsgDlg = 0; Tab_Expand = SavTabExpand; Undo_Stat = T_Undo_Stat; } TTRACE_LEAVE( "_FileSearch() -> %d”, Return_Int );
    return ( Return_Int );

    // Internal Routines ———————————————————–

    _DoSearch:
    Working;
    FindHandle = 0;
    if ( ListWin ) {

    // Process file list
    if ( Switch_Win_Id( ListWin ) ) {
    Tof;
    while ( True ) {
    Switch_Win_Id( ListWin );
    TStr = Shorten_Str( Get_Line( ) );
    Down;
    if ( Svl( TStr ) != 0 ) {
    if ( Caps( TStr ) == g_FindLstCurName ) {
    continue; // Ignore find list file
    }
    Path = Get_Path( TStr );
    NewFd.cFileName = Truncate_Path( TStr );
    Error_Level = 0;
    if ( !FileOnly ) {

    // Update message
    FindLstUpdateMsg( LstId, MsgStr + Path + NewFd.cFileName );

    // Now we are going to do the Search in Memory mode
    if ( Switch_File( Path + NewFd.cFileName ) ) {
    Jx = 0;
    Mark_Pos;
    Tof;
    if ( Find_Text( SearchStr, 0, Flags ) ) {
    Jx = C_Line;
    }
    Goto_Mark;
    if ( Jx > 0 ) {
    InMemory = Cur_Window;
    call _PutSuccess;
    InMemory = 0;
    }
    if ( Error_Level == 1010 ) {
    break;
    }
    continue;
    }
    Jx = Search_File( Path + NewFd.cFileName, SearchStr, Flags );
    ++g_TotalScan;
    if ( Jx > 0 ) {
    call _PutSuccess;
    }
    else {
    if ( Error_Level == 1010 ) {
    break;
    }
    Error_Level = 0;
    }
    }
    else {

    // Update find list message
    FindLstUpdateMsg( LstId, MsgStr + Path );
    OutputDlgMessage( MsgDlg, “Found ” + Str( g_TotalFnd ) +
    ” time(s) in ” + Str( g_TotalFiles ) + ” file(s)…” );
    ++g_TotalScan;
    }
    }
    else {
    break;
    }
    ProcessMsgQueue( 10 );
    }
    if ( !Parse_Int( “/BDFL=”, Misc ) ) {
    if ( Switch_Win_Id( ListWin ) ) {
    Delete_Window;
    }
    }
    }
    }
    else {
    if ( SearchDirs ) {
    FindHandle = FindFirstFile( Path + “*”, &NewFd, &OldFd );
    if ( FindHandle ) {

    // Setup directory attribute filter
    if ( XPos( “-2”, Switches, 1 ) ) {
    DirAttrMask |= _fa_Hidden;
    }
    if ( XPos( “+2”, Switches, 1 ) ) {
    DirAttrMask |= _fa_Hidden;
    DirAttr |= _fa_Hidden;
    }
    if ( XPos( “-3”, Switches, 1 ) ) {
    DirAttrMask |= _fa_ReadOnly;
    }
    if ( XPos( “+3”, Switches, 1 ) ) {
    DirAttrMask |= _fa_ReadOnly;
    DirAttr |= _fa_ReadOnly;
    }
    if ( XPos( “-4”, Switches, 1 ) ) {
    DirAttrMask |= _fa_System;
    }
    if ( XPos( “+4”, Switches, 1 ) ) {
    DirAttrMask |= _fa_System;
    DirAttr |= _fa_System;
    }
    do {
    call _CheckAbort;
    if ( Return_Int == -1 ) {
    goto _SearchExit;
    }
    TTRACE( “Search”, TDBG_Loud, “%s: DM=%x DA=%x A=%x”, NewFd.cFileName, DirAttrMask, DirAttr, NewFd.dwFileAttributes );
    if ( ( NewFd.dwFileAttributes & DirAttrMask ) == DirAttr ) {
    if ( ( NewFd.cFileName != ‘.’ ) && ( NewFd.cFileName != “..” ) ) {
    if ( _FileSearch( SearchStr, Path + NewFd.cFileName + “\\”,
    Mask, Root, 1, Sm, Flags, 1, Misc ) == -1 ) {
    goto _SearchExit;
    }
    }
    }
    } while ( FindNextFile( FindHandle, &NewFd, &OldFd ) );
    call _SearchExit;
    }
    }

    // Update message to show path
    FindLstUpdateMsg( LstId, MsgStr + Path );
    OutputDlgMessage( MsgDlg, “Found ” + Str( g_TotalFnd ) +
    ” time(s) in ” + Str( g_TotalFiles ) + ” file(s)…” );

    //DebugLog( 0, “_FileSearch”, “P=%s M=%s”, Path, Mask );
    FindHandle = FindFirstFile( Path + Mask, &NewFd, &OldFd );
    if ( FindHandle ) {
    do {
    //DebugLog( 0, “_FileSearch”, “P=%s F=%s”, Path, NewFd.cFileName, );
    call _CheckAbort;
    if ( Return_Int == -1 ) {
    break;
    }
    if ( NewFd.dwFileAttributes & _fa_Directory ) {

    // Ignore directory entries
    continue;
    }
    TTRACE( “Search”, TDBG_Loud, “%s: FM=%x FA=%x A=%x”, NewFd.cFileName, FileAttrMask, FileAttr, NewFd.dwFileAttributes );
    if ( ( NewFd.dwFileAttributes & FileAttrMask ) != FileAttr ) {

    // Filter file attributes
    continue;
    }
    if ( Caps( Path + NewFd.cFileName ) == g_FindLstCurName ) {

    // Ignore find list file
    continue;
    }
    Error_Level = 0;
    if ( !FileOnly ) {

    // Update find list message
    FindLstUpdateMsg( LstId, MsgStr + Path + NewFd.cFileName );
    OutputDlgMessage( MsgDlg, “Found ” + Str( g_TotalFnd ) +
    ” time(s) in ” + Str( g_TotalFiles ) + ” file(s)…” );

    // Now we are going to do the Search in Memory mode
    if ( Switch_File( Path + NewFd.cFileName ) ) {
    Jx = 0;
    Mark_Pos;
    Tof;
    if ( Find_Text( SearchStr, 0, Flags ) ) {
    Jx = C_Line;
    }
    Goto_Mark;
    if ( Jx > 0 ) {
    InMemory = Cur_Window;
    call _PutSuccess;
    InMemory = 0;
    }
    if ( Error_Level == 1010 ) {
    break;
    }
    continue;
    }
    Jx = Search_File( Path + NewFd.cFileName, SearchStr, Flags );
    ++g_TotalScan;
    if ( Jx > 0 ) {
    call _PutSuccess;
    }
    else {
    if ( Error_Level == 1010 ) {
    break;
    }
    }
    }
    else {

    // Update find list message
    FindLstUpdateMsg( LstId, MsgStr + Path );
    OutputDlgMessage( MsgDlg, “Found ” + Str( g_TotalFnd ) +
    ” time(s) in ” + Str( g_TotalFiles ) + ” file(s)…” );
    Jx = 1;
    ++g_TotalScan;
    call _PutSuccess;
    }
    } while ( FindNextFile( FindHandle, &NewFd, &OldFd ) );
    }
    _SearchExit:
    if ( FindHandle ) {
    FindClose( FindHandle ); // This is IMPORTANT!!!
    FindHandle = 0;
    }
    }
    ret;

    _PutSuccess:
    FindLstSetFile( LstId, Jx, Path, NewFd.cFileName, False );
    if ( SearchWin ) {
    call _AddAllFound;
    }
    else {
    ++g_TotalFnd;
    }
    ++g_TotalFiles;

    // Update find list
    Working;
    ProcessMsgQueue( 10 ); // *** ldh test ***
    ret;

    _AddAllFound:
    FndLn = 0;
    if ( Switch_Win_Id( SearchWin ) ) {
    if ( InMemory ) {
    Link_Window( InMemory );
    Tof;
    }
    else {
    Rm( “LdFiles /NSW=1/NWS=1/NHA=1/NBF=1/NR=1/FN=” + Path + NewFd.cFileName );
    }
    if ( !Error_Level ) {
    while ( Find_Text( SearchStr, 0, Flags ) ) {
    TStr1 = Get_Line( );
    Tabs_To_Spaces( TStr1 );
    FindLstSetFound( LstId, C_Line, TStr1 );
    ++g_TotalFnd;
    ++FndLn;
    Eol;
    }
    }
    Error_Level = 0;
    FindLstSetFile( LstId, FndLn, “”, “”, true );
    }
    ret;

    _CheckAbort:
    if ( !OutputDlgCheck( MsgDlg ) ) {
    Return_Int = -1;
    }
    ret;

    } // _FileSearch

    /*——————————————————————————

    Function: The file search/replace macro

    Entry : /N=1 – Show the file list results dialog
    /M=int – “True” for file replace otherwise file search
    /BD=1 – Bypass file search dialog
    /NS=1 – Do not show the results window
    /L=int – The list number 0 or 1
    /FL=id – List window id, used to search list of files
    specified in the window with id

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    void Fs( ) trans2
    {
    int DoReplace = Parse_Int( “/M=”, MParm_Str );

    if ( Parse_Int( “/BD=”, MParm_Str ) == 0 ) {

    // Show file search/replace dialog
    if ( DoReplace ) {
    if ( g_DefSearchOpts & _so_UseFsDef ) {
    g_FRSwitches = g_DefFRSwitches;
    }
    Rm( “SearchTabDlg /T#=” + Str( _tab_sr_ReplaceFiles ) );
    }
    else {
    if ( g_DefSearchOpts & _so_UseFsDef ) {
    g_FSwitches = g_DefFSSwitches;
    }
    Rm( “SearchTabDlg /T#=” + Str( _tab_sr_SearchFiles ) );
    }
    return ( );
    }

    // Generate list

    int LstId = Parse_Int( “/L=”, MParm_Str );
    int NoShow = Parse_Int( “/NS=”, MParm_Str );
    int ListWin = Parse_Int( “/FL=”, MParm_Str );

    str GFindLstTab = _g_FindLstTab + Str( LstId );

    FindLstGetWin( LstId, False, _pwa_AddTab );

    int ActiveWin = Window_Id;
    int SavRefresh = Refresh;
    int ReplaceWin;
    int TreeWin;

    int RegExp;
    int IgnoreCase;
    int SearchDirs;
    int LeaveOpen;
    int ShowAllFind;
    int Flags;
    int AlreadyOpen;
    int Jx;
    int AllFiles;
    int Line;

    str Switches;
    str SearchStr;
    str ReplaceStr;
    str FileSpec;
    str SearchPath;
    str TStr;

    Refresh = False;
    if ( DoReplace ) {
    Switches = Caps( g_FRSwitches );
    ReplaceStr = g_ReplaceStr;
    FileSpec = g_FRFileSpec;
    SearchPath = TranslateCmdLine( g_FRSearchPath, File_Name );
    }
    else {
    Switches = Caps( g_FSwitches );
    FileSpec = g_FFileSpec;
    SearchPath = TranslateCmdLine( g_FSearchPath, File_Name );
    }
    if ( !ListWin ) {

    // Abort if first path in SearchPath is not valid
    TStr = SearchPath;
    if ( Svl( TStr ) == 0 ) {
    TStr = FExpand( “” );
    SearchPath = TStr;
    }
    if ( Jx = XPos( “;”, SearchPath, 1 ) ) {
    TStr = Copy( SearchPath, 1, Jx – 1 );
    }
    if ( !ValidatePath( TStr, “”, 0 ) ) {
    MsgDlg( “The starting path \”” + TStr + “\” does not exist.”, “File Find Error”, “”, 1 );
    return ( );
    }
    }

    // Force FileSpec to “*.*” if it were originally blank.
    if ( Svl( FileSpec ) == 0 ) {
    FileSpec = “*.*”;
    }
    SearchStr = g_SearchStr;

    RegExp = XPos( “X”, Switches, 1 ) == 0;
    IgnoreCase = XPos( “I”, Switches, 1 ) == 0;
    SearchDirs = XPos( “S”, Switches, 1 ) != 0;
    LeaveOpen = XPos( “O”, Switches, 1 ) != 0;
    ShowAllFind = XPos( “L”, Switches, 1 ) != 0;

    Reg_Exp_Stat = RegExp;

    // Setup flags for find_text
    Flags = 0;
    if ( RegExp ) {
    switch ( g_RegExStyle ) {

    case esClassic :
    Flags = _oldExp;
    break;

    case esUnix :
    Flags = _regExp;
    break;

    case esPerl :
    Flags = _perlExp;
    break;
    }
    }
    if ( IgnoreCase ) {
    Flags |= _caseSensitive;
    }
    if ( !DoReplace ) {
    ShowAllFind *= 2;
    }

    // Get find list window
    TreeWin = FindLstGetWin( LstId, True, _pwa_None );

    // Save name of current file list file
    g_FindLstCurName = Caps( File_Name );

    _FileSearch( SearchStr, FileSpec, “”, SearchPath, SearchDirs, ShowAllFind, Flags, 0, “/SW=” + Switches + MParm_Str );

    call _ShowResults;

    if ( DoReplace ) {
    g_SearchMode = True;
    g_FRSwitches = “P” + g_FRSwitches;
    AllFiles = False;

    Switch_Window( Window_Count );
    Create_Window;
    ReplaceWin = Window_Id;

    Line = 1;
    TStr = Get_Line_From_Win( Line, TreeWin );
    if ( Parse_Int( _fl_TreeLevel, TStr ) == 1 ) {
    ++Line;
    Return_Int = 0;
    while ( True ) {
    AlreadyOpen = False;
    TStr = Get_Line_From_Win( Line, TreeWin );
    if ( ( Parse_Int( _fl_TreeLevel, TStr ) != 2 ) || ( Return_Int == -1 ) ) {
    break;
    }
    FileSpec = FExpand( Parse_Str( _fl_Path, TStr ) + Parse_Str( _fl_File, TStr ) );
    Jx = Parse_Int( _fl_NumFound, TStr );
    if ( Switch_File( FileSpec ) ) {
    AlreadyOpen = True;
    Rm( “Select_Window” );
    Tof;
    Error_Level = 0;
    }
    else {
    Switch_Win_Id( ReplaceWin );
    Rm( “LdFiles /CW=” + Str( LeaveOpen ) + “/FN=” + FileSpec );
    }
    if ( Error_Level ) {
    break;
    }
    if ( LeaveOpen ) {
    ActiveWin = Window_Id;
    }
    Down; Down; Down; Down;
    Goto_Line( Jx );
    Goto_Col( 1 );
    Left;
    Reg_Exp_Stat = ( Flags & ( _regExp | _oldExp ) ) != 0;
    g_RepSearch = True;
    g_SRModalDlg = True;
    Rm( “S_And_R /FR=1/L=” + Str( g_FFindLstId ) );
    g_SRModalDlg = False;

    // Return_Int can have 3 values:
    // 0 = Normal s/r occurred
    // 1 = Non-Stop all files
    // -1 = Abort remaining files
    if ( ( Return_Int == 1 ) && !AllFiles ) {
    AllFiles = True;
    g_FRSwitches += “N”;
    }
    if ( !AlreadyOpen ) {
    if ( File_Changed ) {
    Save_File;
    }
    }
    Refresh = False;
    ++Line;
    }
    }
    if ( Switch_Win_Id( ReplaceWin ) ) {
    if ( !LeaveOpen || ( File_Name == “?No-File?” ) ) {
    Delete_Window;
    }
    }
    }
    Switch_Win_Id( ActiveWin );
    Refresh = SavRefresh;
    g_FindLstCurName = “”;
    return ( );

    // Internal Routines ———————————————————–

    _ShowResults:
    if ( Global_Int( GFindLstTab ) && !NoShow ) {
    PanesShow( _pwt_Tool, _pws_Activate, Global_Int( GFindLstTab ) );
    FindLstUpdate( LstId );
    }
    ret;

    } // Fs

    /*——————————————————————————

    Function: Check to see if Find list tabs being active.
    Entry : /L=int – The list number
    Exit : int – True if Find list is active, else False
    Author : Dan Hughes

    Note : This macro is called from the command map and thus can not have the
    LstId passed as a parameter on the function line.

    ——————————————————————–( ldh )–*/
    int FindLstIsActive( ) trans2
    {
    int Result = False;
    int LstId = Parse_Int( “/L=”, MParm_Str );

    if ( Global_Int( _g_FindLstTab + Str( LstId ) ) ) {
    Result = True;
    }
    return ( Result );

    } // FindLstIsActive

    void FindLstDlg(
    int LstId = Parse_Int( “/L=”, MParm_Str ),
    int Action = Parse_Int( “/A=”, MParm_Str ),
    int Show = Parse_Int( “/S=”, MParm_Str )
    ) trans2
    {
    int M = Parse_Int( “/M=”, MParm_Str );
    int Dlg = Parse_Int( “/DLG=”, MParm_Str );
    int OrgWinId = Window_Id;
    int SavRefresh = Refresh;
    int LstWin;

    str GFindLstWin = _g_FindLstWin + Str( LstId );
    str GFindLstTab = _g_FindLstTab + Str( LstId );

    Refresh = False;
    switch ( M ) {

    case 0 :

    int LstTab = Global_Int( GFindLstTab );

    LstTab = PanesOp( _pwt_Tool, Action, Show, LstTab,
    “Find ” + Str( LstId ), “BT_SR_105_S”,
    “FindLstDlg //L=” + Str( LstId ) );

    Set_Global_Int( GFindLstTab, LstTab );
    break;

    case 1 :
    FindLstGetWin( LstId, True, _pwa_None );
    Eof;

    // *indent-off*
    DlgAddCtrl( Dlg, dlg_TreeList, “/T=” + _fl_TreeStr + “/I=” + _fl_TreeLevel +
    “/E=” + _fl_TreeExpand + “/NI=” + _fl_StdBmp + “/OI=” + _fl_OpenBmp,
    0, 0,
    0, 0,
    id_fl_ListBox, 0, // tvs_EditLabels,
    // “/INSWCMD=” +
    “/DELWCMD=” + Str( id_fl_DeleteNode ) +
    // “/EDWCMD=” +
    “/HSCROLL=255/WIN=” + Str( Cur_Window ) +
    “/SLINE=1” +
    “/RECS=” + Str( C_Line ) +
    “/IMG=” + _fl_ImageList
    );

    DlgAddCtrl( Dlg, dlg_BitmapBtn, “RARROW”,
    1, dlg_Units,
    3, dlg_Units | 7,
    id_fl_MenuBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “&Open”,
    dlg_PosOffset | dlg_Units | ( dlg_Units_Per_Col * 4 ) + 2, dlg_PosOffset,
    10, dlg_Units | 10,
    id_fl_SelectBtn, dlgf_DefButton, “” );

    DlgAddCtrl( dlg, dlg_PushButton, “&View”,
    dlg_PosOffset | dlg_Units | ( dlg_Units_Per_Col * 10 ) + 2, dlg_PosOffset,
    10, dlg_Units | 10,
    id_fl_ViewBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_Choice, “Default()Dos()Unix()Binary()”,
    dlg_PosOffset | dlg_Units | ( dlg_Units_Per_Col * 10 ) + 2, dlg_PosOffset,
    12, dlg_Units | 8,
    id_fl_FTypeCL, 0, “” );
    DlgSetInt( Dlg, id_fl_FTypeCL, g_FType + 1 );

    DlgAddCtrl( Dlg, dlg_BlackFrame, “”,
    dlg_PosOffset + 14, dlg_Units | 3,
    55, dlg_Units | 7,
    id_fl_MessageFrm, 0, “” );

    DlgAddCtrl( Dlg, dlg_Static, “”,
    dlg_PosOffset + 1, dlg_NegOffset | dlg_Units + 2,
    53, 0,
    id_fl_MessageStr, 0, “” );
    // *indent-on*

    Return_Str = “/H=” + hc_FindList + “/HOOK=_FindLstDlgProc //L=” + Str( LstId );
    Switch_Win_Id( OrgWinId );
    break;

    case 2 :
    LstWin = Global_Int( GFindLstWin );
    if ( Switch_Win_Id( LstWin ) ) {
    if ( File_Changed ) {
    Save_File;
    }
    Delete_Window;
    Set_Global_Int( GFindLstWin, 0 );
    Switch_Win_Id( OrgWinId );
    }
    break;

    case 3 :
    Set_Global_Int( GFindLstTab, 0 );
    break;
    }
    Refresh = SavRefresh;

    } // _FindLstDlg

    /*——————————————————————————

    Function: Create and return the window number of the find list results
    window. If an Action is set then also create or delete the results
    window dialog.

    Entry : int LstId – List number
    int SwitchWin – True to return with Find list window current
    int Action – Results window action
    _pwa_None – No action
    _pwa_AddTab – Add tab to results window if not already there
    _pwa_DelTab – Delete tab from results window if there
    _pwa_SelTab – Select the tab and add it if it doesn’t exist

    Exit : int – The window number of the Find List window

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    int FindLstGetWin(
    int LstId = Parse_Int( “/L=”, MParm_Str ),
    int SwitchWin = Parse_Int( “/S=”, MParm_Str ),
    int Action = Parse_Int( “/A=”, MParm_Str )
    ) trans2
    {
    str FName[ 260 ] = TempFileName( _fl_FileName + Str( LstId ) + _fl_FileExt );
    str GFindLstWin = _g_FindLstWin + Str( LstId );

    int OrgWin = Window_Id;
    int TRefresh = Refresh;
    int LstWin;

    Refresh = False;
    if ( Action != _pwa_None ) {
    FindLstDlg( LstId, Action, _pws_Show );
    }
    LstWin = Global_Int( GFindLstWin );
    if ( !Switch_Win_Id( LstWin ) ) {
    Create_Window;
    Load_File( FName );
    Error_Level = 0;
    }
    File_Name = FName;
    Window_Attr = _wa_SystemHidden;
    Set_Global_Int( GFindLstWin, Window_Id );
    LstWin = Cur_Window;
    if ( !SwitchWin ) {
    Switch_Window( OrgWin );
    }
    Refresh = TRefresh;
    return ( LstWin );

    } // FindLstGetWin

    int _FindLstContextMenu(
    int Window,
    int Item,
    int Count,
    int MType
    ) trans2
    {
    int Result = False;
    int Tree = GetDlgItem( Window, id_fl_Listbox );
    int Flags = mf_String;

    struct TRect ItemRect;
    struct TPoint ItemPt;

    int HMenu = CreatePopupMenu( );

    if ( Count == 0 ) {
    Flags |= mf_Grayed;
    }
    if ( MType == 0 ) {
    AppendMenu( HMenu, Flags, id_fl_SelectBtn, “&Open” );
    AppendMenu( HMenu, Flags, id_fl_ViewBtn, “&View” );
    AppendMenu( HMenu, mf_Separator, 0, “” );
    AppendMenu( HMenu, Flags, id_fl_ExpandAll, “&Expand All” );
    AppendMenu( HMenu, Flags, id_fl_CollapseAll, “&Collapse All” );
    AppendMenu( HMenu, Flags, id_fl_DeleteNode, “&Delete Node” );

    Tree_GetItemRect( Tree, Item, ItemRect );
    ItemPt.X = ItemRect.Left;
    ItemPt.Y = ItemRect.Top;
    ClientToScreen( Tree, &ItemPt );
    }
    else {
    AppendMenu( HMenu, Flags, id_fl_SaveBtn, “&Save” );
    AppendMenu( HMenu, Flags, id_fl_ExportBtn, “E&xport” );
    AppendMenu( HMenu, mf_String, id_fl_LoadBtn, “&Load” );
    AppendMenu( HMenu, mf_Separator, 0, “” );
    AppendMenu( HMenu, mf_String, id_fl_Clear, “Clear &All” );

    GetWindowRect( GetDlgItem( Window, id_fl_MenuBtn ), &ItemRect );
    ItemPt.X = ItemRect.Right;
    ItemPt.Y = ItemRect.Top;
    }
    TrackPopupMenu( HMenu, tpm_LeftAlign | tpm_BottomAlign | tpm_RightButton, ItemPt.X, ItemPt.Y, 0, Window, 0 );
    DestroyMenu( HMenu );

    return ( Result );

    } // _FindLstContextMenu

    void _FindLstExpandAll(
    int Tree = Parse_Int( “/TREE=”, MParm_Str ),
    int Item = Parse_Int( “/ITEM=”, MParm_Str ),
    int Expand = Parse_Int( “/X=”, MParm_Str )
    ) trans2
    {
    if ( Tree_ItemHasChildren( Tree, Item ) ) {
    Tree_ExpandItem( Tree, Item, Expand );
    }
    } // _FindLstExpandAll

    void _FindLstClearAll( int Tree ) trans2
    {
    int WinId = Window_Id;
    int SRefresh = Refresh;

    str FName[ 260 ];

    Refresh = False;
    Switch_Window( Tree_GetBuf( Tree ) );
    FName = File_Name;
    Tree_Initialize( Tree, 0 );
    Erase_Window;
    File_Name = FName;
    Save_File;
    Switch_Win_Id( WinId );
    Refresh = SRefresh;

    } // _FindLstClearAll

    int _FindListSave( int Tree ) trans2
    {
    int Result = False;
    int WinId = Window_Id;
    int SRefresh = Refresh;

    str FName;

    Refresh = False;
    Switch_Window( Tree_GetBuf( Tree ) );
    FName = File_Name;
    File_Name = TempFileName( _fl_FileName + _fl_SaveExt );
    Rm( “SaveFile” );
    File_Name = FName;
    Switch_Win_Id( WinId );
    Refresh = SRefresh;
    return ( Result );

    } // _FindListSave

    int _FindListLoad( int Tree ) trans2
    {
    int Result = False;
    int WinId = Window_Id;
    int SRefresh = Refresh;

    str FName;

    Refresh = False;
    Switch_Window( Tree_GetBuf( Tree ) );
    FName = File_Name;
    Return_Str = TempFileName( _fl_FileName + _fl_SaveExt );
    Rm( “File_Prompt /DD=1/FTO=1/OEM=1/NHA=1/WM=1” );
    if ( Return_Int ) {
    Tree_Initialize( Tree, 0 );
    Load_File( Return_Str );
    File_Name = FName;
    Save_File;
    }
    Switch_Win_Id( WinId );
    Refresh = SRefresh;
    return ( Return_Int );

    } // _FindListLoad

    int _FindLstDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    int Result = 0;
    int Tree = GetDlgItem( Window, id_fl_Listbox );
    int LstId = Parse_Int( “/L=”, Parms );
    int LstDlg = Global_Int( _g_FindLstDlg + Str( LstId ) );
    int Style;

    switch ( Message ) {

    case wm_Destroy :
    RetVal = 0;

    // Deallocate globals
    Set_Global_Int( _g_FindLstDlg + Str( LstId ), 0 );
    Set_Global_Int( _g_FindLstCur + Str( LstId ), 0 );
    Set_Global_Int( _g_FindLstLine + Str( LstId ), 0 );
    break;

    case wm_ShowWindow :
    if ( WParam ) {

    str GFindLstCur = _g_FindLstCur + Str( LstId );

    int LstCur = Global_Int( GFindLstCur );

    if ( LstCur < 1 ) { int SavRefresh = Refresh; int ActiveWin = Window_Id; int Count; str TStr[ max_Line_Length ]; Refresh = False; Switch_Window( Tree_GetBuf( Tree ) ); Eof; Count = C_Line; Tof; TStr = Get_Line( ); if ( Svl( TStr ) == 0 ) { // Disable all buttons EnableWindow( GetDlgItem( Window, id_fl_SelectBtn ), False ); EnableWindow( GetDlgItem( Window, id_fl_ViewBtn ), False ); TStr = "Nothing found."; Count = 0; } else { // Enable buttons EnableWindow( GetDlgItem( Window, id_fl_SelectBtn ), True ); EnableWindow( GetDlgItem( Window, id_fl_ViewBtn ), True ); Tree_Initialize( Tree, Count ); Tree_ExpandNodes( Tree ); Count = Tree_GetItemHandle( Tree, 1 ); Tree_SelectItem( Tree, Count ); TStr = Parse_Str( _fl_TreeStr, TStr ); } SetDlgItemText( Window, id_fl_MessageStr, TStr ); Switch_Win_Id( ActiveWin ); Refresh = SavRefresh; } if ( LstCur != 0 ) { SetFocus( Tree ); } Set_Global_Int( GFindLstCur, 1 ); } break; case wm_Size : struct TRect Tr; int W = ( LParam & 0xFFFF ); int H = ( LParam >> 16 );
    int Bw;
    int Bh;

    GetWindowRect( GetDlgItem( Window, id_fl_ViewBtn ), &Tr );
    Bw = Tr.Right – Tr.Left;
    Bh = Tr.Bottom – Tr.Top;

    SetWindowPos( GetDlgItem( Window, id_fl_Listbox ), 0, 1, Bh + 7, W,
    H – Bh – 7, swp_NoActivate | swp_NoZOrder );

    SetWindowPos( GetDlgItem( Window, id_fl_MessageFrm ), 0,
    ( Bw * 3 ) + 26 + 18, 5, W – ( Bw * 3 ) – 26 – 18, Bh, swp_NoActivate | swp_NoZOrder );

    GetWindowRect( GetDlgItem( Window, id_fl_MessageStr ), &Tr );
    SetWindowPos( GetDlgItem( Window, id_fl_MessageStr ), 0,
    0, 0, W – ( Bw * 4 ) – 26 – 24, Tr.Bottom – Tr.Top,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );
    break;

    case wm_Command :
    switch ( WParam & 0xFFFF ) {

    case dlg_WCmd_Init :
    Tree_SetFlags( Tree, _tf_NoDblClickExpand );
    Set_Global_Int( _g_FindLstDlg + Str( LstId ), Window );
    break;

    case id_fl_FTypeCL :
    if ( ( WParam >> 16 ) == cbn_SelChange ) {
    g_FType = SendDlgItemMessage( Window, id_fl_FTypeCL, cb_GetCurSel, 0, 0 );
    }
    break;

    case id_fl_SaveBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    _FindListSave( Tree );
    }
    break;

    case id_fl_ExportBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    FindLstExport( LstId, “”, _xo_Prompt | g_ExportOpts );
    }
    break;

    case id_fl_LoadBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    _FindListLoad( Tree );
    if ( Return_Int ) {
    Set_Global_Int( _g_FindLstCur + Str( LstId ), -1 );
    FindLstUpdate( LstId );
    }
    }
    break;

    case id_fl_ExpandAll :

    int Item = Tree_GetItemSelected( Tree );

    Tree_Traverse( Tree, Tree_GetRoot( Tree ), “_FindLstExpandAll /X=1” );
    Tree_SelectItem( Tree, Item );
    break;

    case id_fl_CollapseAll :

    int Item = Tree_GetBaseParent( Tree, Tree_GetItemSelected( Tree ) );

    Tree_Traverse( Tree, Tree_GetRoot( Tree ), “_FindLstExpandAll /X=0” );
    Tree_SelectItem( Tree, Item );
    break;

    case id_fl_DeleteNode :
    PostMessage( LstDlg, wm_Command, ( id_fl_DeleteNode < < 16 ) | id_fl_ListBox, 0 ); break; case id_fl_Clear : if ( ( WParam >> 16 ) == bn_Clicked ) {
    _FindLstClearAll( Tree );
    PostMessage( LstDlg, wm_Command, ( WCmd_TreeSelChanged < < 16 ) | id_fl_ListBox, 0 ); } break; case id_fl_ListBox : switch ( WParam >> 16 ) {

    case id_fl_DeleteNode :

    int SavRefresh = Refresh;
    int FHandle;
    int Count;
    int Jx;

    Refresh = False;
    FHandle = Tree_FindFirstSelected( Tree, Count, Item );
    if ( FHandle ) {
    if ( Count == 1 ) {
    Tree_DeleteItem( Tree, Tree_GetItemSelected( Tree ) );
    }
    else {

    // Delete node from the end to not cause exceptions
    for ( Jx = Count; Jx; –Jx ) {
    Tree_FindNextSelected( FHandle, Jx, Item );
    Tree_DeleteItem( Tree, Item );
    }
    }
    Tree_FindClose( FHandle );
    }
    Refresh = SavRefresh;

    // Fall through

    case wcmd_TreeSelChanged :
    if ( Global_Int( _g_FindLstCur + Str( LstId ) ) != 1 ) {
    break;
    }

    int Item = Tree_GetItemSelected( Tree );
    int TreeWin = Tree_GetBuf( Tree );
    int Level;

    str TStr[ max_Line_Length ];

    // Update find list status line
    TStr = Tree_GetItemData( Tree, Item, _tgid_ItemData, TreeWin );
    Level = Parse_Int( _fl_TreeLevel, TStr );
    switch ( Level ) {

    case 2 :
    case 3 :
    TStr = Tree_GetItemData( Tree, Item, _tgid_ParentData, TreeWin );

    // Drop through

    case 1 :
    TStr = Parse_Str( _fl_TreeStr, TStr );
    break;

    default :
    if ( g_DefSearchOpts & _so_FindLstClose ) {

    // Remove tab since it is empty
    PanesRemoveDlg( _pwt_Tool, Global_Int( _g_FindLstTab + Str( LstId ) ) );
    SetFocus( Frame_Handle );
    return ( True );
    }
    EnableWindow( GetDlgItem( Window, id_fl_SelectBtn ), false );
    EnableWindow( GetDlgItem( Window, id_fl_ViewBtn ), false );
    TStr = “Nothing found.”;
    }
    SetDlgItemText( Window, id_fl_MessageStr, TStr );
    break;

    case wcmd_TreeRClick :

    int Start;
    int Count;

    Tree_GetStartCount( Tree, Start, Count );
    _FindLstContextMenu( Window, LParam, Count, false );
    return ( True );

    case wcmd_TreeEnter:
    case wcmd_TreeDblClick :
    PostMessage( Window, wm_Command, id_fl_SelectBtn, LParam );
    RetVal = True;
    return ( True );
    }
    break;

    case id_fl_MenuBtn :

    int Start;
    int Count;

    Tree_GetStartCount( Tree, Start, Count );
    _FindLstContextMenu( Window, LParam, Count, true );
    return ( True );

    case id_fl_SelectBtn :
    case id_fl_ViewBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {

    int SavRefresh = Refresh;
    int ActiveWin = Window_Id;
    int TFocus = GetFocus( );
    int ViewBtn = ( WParam & 0xFFFF ) == id_fl_ViewBtn;
    int FirstTime = True;
    int FileFind = 0;
    int ColBeg = 0;
    int ColEnd = 0;
    int Done = False;
    int Item;
    int Jx;
    int Flags;
    int TreeWin;
    int Level;
    int LineNo;
    int Lock;
    int FHandle;
    int Count;

    str ItemDat[ max_Line_Length ];
    str TStr[ max_Line_Length ];
    str Misc[ 1024 ];
    str FName[ 260 ];
    str SearchStr;
    str Switches;

    Refresh = False;

    // Turn window redraw off to stop flashing when loading files
    Lock = SetWinRedraw( _rd_Client, false );
    TreeWin = Tree_GetBuf( Tree );
    FHandle = Tree_FindFirstSelected( Tree, Count, Item );
    if ( FHandle ) {
    if ( Count > 1 ) {
    ItemDat = Tree_GetItemData( Tree, Item, _tgid_ItemData, TreeWin );
    Level = Parse_Int( _fl_TreeLevel, ItemDat );
    if ( Level == _fld_FileDat ) {
    call _DoSelect;
    while ( Tree_FindNextSelected( FHandle, 0, Item ) ) {
    ItemDat = Tree_GetItemData( Tree, Item, _tgid_ItemData, TreeWin );
    Level = Parse_Int( _fl_TreeLevel, ItemDat );
    if ( Level == _fld_FileDat ) {
    call _DoSelect;
    }
    }
    Done = True;
    }
    }
    Tree_FindClose( FHandle );
    }
    if ( !Done ) {
    Item = Tree_GetItemSelected( Tree );
    ItemDat = Tree_GetItemData( Tree, Item, _tgid_ItemData, TreeWin );
    Level = Parse_Int( _fl_TreeLevel, ItemDat );
    call _DoSelect;
    }

    // Window redraw back on
    RedrawWindow( GetDlgItem( Window, id_fl_Listbox ), 0, 0, rdw_Invalidate );
    SetWinRedraw( _rd_Client, !Lock );
    Switch_Win_Id( ActiveWin );
    Rm( “Select_Window” );
    SortWindows( 0 );
    if ( ViewBtn ) {
    SetFocus( GetDlgItem( Window, id_fl_Listbox ) );
    }
    else {
    if ( g_DefSearchOpts & _so_FindLstHide ) {
    PanesShow( _pwt_Tool, _pws_Hide, -1 );
    }
    SetFocus( TFocus );
    }
    Refresh = SavRefresh;
    Redraw;
    return ( 0 );

    _DoSelect:
    if ( Level == 0 ) {
    break;
    }
    switch ( Level ) {

    case _fld_FindDat :

    // Bring up the correct Find dialog
    g_SearchStr = Parse_Str( _fl_SearchStr, ItemDat );
    g_SearchMode = False;
    Misc = Parse_Str( _fl_Misc, ItemDat );
    if ( Parse_Int( “/FF=”, Misc ) == 1 ) {
    g_FSwitches = Parse_Str( “/SW=”, Misc );
    g_FFindLstId = Parse_Int( “/L=”, Misc );
    g_FFileSpec = Parse_Str( _fl_FileStr, ItemDat );
    g_FSearchPath = Parse_Str( _fl_SPath, ItemDat );
    Rm( “Fs” );
    }
    else {
    g_Switches = Parse_Str( “/SW=”, Misc );
    g_SFindLstId = Parse_Int( “/L=”, Misc );
    if ( XPos( ‘O’, g_Switches, 1 ) ) {
    g_SearchColBeg = Parse_Int( “/CB=”, Misc );
    g_SearchColEnd = Parse_Int( “/CE=”, Misc );
    }
    Rm( “Search” );
    }
    TFocus = GetFocus( );
    break;

    case _fld_FileDat :

    // Change image to be checked
    LineNo = Tree_GetItemLine( Tree, Item );
    Var_Remove_Str( _fl_StdBmp, ItemDat );
    ItemDat += _fl_StdBmp + “4”;
    Tree_UpdateItem( Tree, LineNo, ItemDat );

    // Load file and locate first occurrence
    TStr = Tree_GetItemData( Tree, Item, _tgid_BaseParentData, TreeWin );
    call _SetFind;
    LineNo = 1;
    TStr = ItemDat;
    call _LoadFile;
    break;

    case _fld_FoundDat :

    // Change image to be checked
    LineNo = Tree_GetItemLine( Tree, Item );
    Var_Remove_Str( _fl_StdBmp, ItemDat );
    ItemDat += _fl_StdBmp + “5”;
    Tree_UpdateItem( Tree, LineNo, ItemDat );

    // Load file and locate current occurrence
    TStr = Tree_GetItemData( Tree, Item, _tgid_BaseParentData, TreeWin );
    call _SetFind;
    LineNo = Parse_Int( _fl_LineNo, ItemDat );
    TStr = Tree_GetItemData( Tree, Item, _tgid_ParentData, TreeWin );
    call _LoadFile;
    break;
    }
    ret;

    _SetFind:

    // The following code resets the SearchStr and Switches globals
    SearchStr = Parse_Str( _fl_SearchStr, TStr );
    Flags = Parse_Int( _fl_Flags, TStr );
    Misc = Parse_Str( _fl_Misc, TStr );

    Switches = Parse_Str( “/SW=”, Misc );

    // Set normal search to use the original search pattern
    g_SearchStr = SearchStr;
    g_SearchMode = False; // Force find mode for repeat

    TStr = g_Switches;

    // Add/remove regular expression flag from normal search flags
    if ( XPos( “X”, Switches, 1 ) == 0 ) {
    if ( Jx = XPos( “X”, TStr, 1 ) ) {
    TStr = Str_Del( TStr, Jx, 1 );
    }
    }
    else if ( XPos( “X”, TStr, 1 ) == 0 ) {
    TStr += “X”;
    }

    // Add/remove ignore case flag from normal search flags
    if ( XPos( “I”, Switches, 1 ) == 0 ) {
    if ( Jx = XPos( “I”, TStr, 1 ) ) {
    TStr = Str_Del( TStr, Jx, 1 );
    }
    }
    else if ( XPos( “I”, TStr, 1 ) == 0 ) {
    TStr += “I”;
    }

    // Force forward search
    if ( Jx = XPos( “B”, TStr, 1 ) ) {
    TStr = Str_Del( TStr, Jx, 1 );
    }
    if ( Parse_Int( “/FF=”, Misc ) == 0 ) {
    if ( XPos( ‘O’, Parse_Str( “/SW=”, Misc ), 1 ) ) {
    ColBeg = Parse_Int( “/CB=”, Misc );
    ColEnd = Parse_Int( “/CE=”, Misc );
    TStr += “O”;
    }
    else {
    if ( Jx = XPos( “O”, TStr, 1 ) ) {
    TStr = Str_Del( TStr, Jx, 1 );
    }
    }
    }
    g_Switches = TStr;

    // Force forward search
    Flags &= 0xFFFFFFFF ^ _Backward;
    if ( ( Flags & _PerlExp ) == _PerlExp ) {
    Style = rasPerl;
    }
    else if ( Flags & _RegExp ) {
    Style = rasUnix;
    }
    else if ( Flags & _OldExp ) {
    Style = rasClassic;
    }
    SearchStr = ReTranslate( SearchStr, Style );
    ret;

    _LoadFile:

    // Get file info
    FName = Parse_Str( _fl_Path, TStr ) + Parse_Str( _fl_File, TStr );

    // Load file and position cursor on found string
    if ( SwitchBestFile( ActiveWin, FName ) ) {
    Rm( “Select_Window /NSW=1” );
    Tof;
    }
    else {
    Rm( “LdFiles /NSW=1/NBF=1/NR=1/NWS=1/FTO=” + Str( g_FType ) +
    “/CW=1/FN=” + FName );
    }
    if ( Error_Level == 0 ) {
    TFocus = Window_Handle;
    Down;
    Down;
    Down;
    Down;
    Goto_Line( LineNo );
    Goto_Col( 1 );

    Find_Text_Ex( SearchStr, 0, Flags, ColBeg, ColEnd );
    Set_Highlight( C_Line, C_Col, C_Line, C_Col + Length( Found_Str ) );
    if ( FirstTime ) {
    ActiveWin = Window_Id;
    FirstTime = False;
    }
    }
    ret;

    }
    break;
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    } // _FindLstDlgProc

    void FindLstUpdateMsg(
    int LstId,
    str Msg
    ) trans2
    {
    int LstDlg = Global_Int( _g_FindLstDlg + Str( LstId ) );

    if ( LstDlg ) {
    SendDlgItemMessageStr( LstDlg, id_fl_MessageStr ,wm_SetText, 0, Msg );
    ProcessMsgQueue( 10 );
    }
    } // FindLstUpdateMsg

    void FindLstUpdate( int LstId ) trans2
    {
    int LstDlg = Global_Int( _g_FindLstDlg + Str( LstId ) );

    if ( LstDlg ) {
    PostMessage( LstDlg, wm_ShowWindow, 1, sw_OtherUnzoom );
    }
    } // FindLstUpdate

    void FindLstSetHeader(
    int LstId,
    int NumFiles,
    int NumFound,
    int NumScanFiles,
    int SFlags,
    str SStr,
    str FStr,
    str SPath,
    str Misc,
    int Update
    ) trans2
    {
    int OrgWinId = Window_Id;
    int SavRefresh = Refresh;
    int SavInsertMode = Insert_Mode;

    str TStr[ max_Line_Length ];

    Insert_Mode = True;
    Refresh = False;
    if ( Switch_Win_Id( Global_Int( _g_FindLstWin + Str( LstId ) ) ) ) {
    if ( Update ) {
    Tof;
    TStr = Get_Line( );
    if ( Svl( SStr ) == 0 ) {
    SStr = Parse_Str( _fl_SearchStr, TStr );
    }
    if ( Svl( FStr ) == 0 ) {
    FStr = Parse_Str( _fl_FileStr, TStr );
    }
    if ( Svl( SPath ) == 0 ) {
    SPath = Parse_Str( _fl_SPath, TStr );
    }
    if ( Svl( Misc ) == 0 ) {
    Misc = Parse_Str( _fl_Misc, TStr );
    }
    if ( SFlags == 0 ) {
    SFlags = Parse_Int( _fl_Flags, TStr );
    }
    }
    else {
    Tof;
    if ( !At_Eol ) {

    // Collapse last header
    TStr = Get_Line( );
    Var_Remove_Str( _fl_TreeExpand, TStr );
    TStr += _fl_TreeExpand + “0”;
    Put_Line( TStr );
    }
    Cr;
    Up;
    }
    TStr = “”;
    if ( NumFound >= NumFiles ) {
    TStr = Str( NumFound ) + ” time(s) “;
    }
    TStr = “. Found ” + TStr + “in ” + Str( NumFiles ) + ” file(s).” +
    ” Scanned ” + Str( NumScanFiles ) + ” file(s).”;
    if ( Svl( FStr ) != 0 ) {
    TStr = ‘[‘ + FStr + ‘]’ + TStr;
    if ( Svl( SPath ) != 0 ) {
    TStr = SPath + ” ” + TStr;
    }
    TStr = ” in ” + TStr;
    }
    TStr = _fl_TreeLevel + “1” +
    _fl_StdBmp + “1” +
    _fl_OpenBmp + “2” +
    _fl_NumFound + Str( NumFound ) +
    _fl_NumFiles + Str( NumFiles ) +
    // _fl_NumScanFiles + Str( NumScanFiles) +
    _fl_SearchStr + SStr +
    _fl_Flags + Str( SFlags ) +
    _fl_FileStr + FStr +
    _fl_SPath + SPath +
    _fl_Misc + Misc +
    _fl_TreeStr + “Find \”” + SStr + “\”” + TStr +
    _fl_TreeExpand + “1”;
    Put_Line( TStr );
    if ( Update && File_Changed ) {
    Save_File;
    }
    Switch_Win_Id( OrgWinId );

    // Set list changed flag
    Set_Global_Int( _g_FindLstCur + Str( LstId ), -1 );
    }
    Insert_Mode = SavInsertMode;
    Refresh = SavRefresh;

    } // FindLstSetHeader

    void FindLstSetFile(
    int LstId,
    int NumFound,
    str Path,
    str FName,
    int Update
    ) trans2
    {
    int OrgWinId = Window_Id;
    int SavRefresh = Refresh;
    int SavInsertMode = Insert_Mode;

    str TStr[ max_Line_Length ];

    Insert_Mode = True;
    Refresh = False;
    if ( Switch_Win_Id( Global_Int( _g_FindLstWin + Str( LstId ) ) ) ) {
    //DebugLog( 0, “SetFsLstFName”, “%d %s %d: %s”, Update, File_Name, C_Line, Get_Line( ) );
    if ( Update ) {
    Mark_Pos;

    // Find current file line
    TStr = Get_Line( );
    while ( ( C_Line != 1 ) && ( Parse_Int( _fl_TreeLevel, TStr ) != 2 ) ) {
    Up;
    TStr = Get_Line( );
    }
    if ( Svl( Path ) == 0 ) {
    Path = Parse_Str( _fl_Path, TStr );
    }
    if ( Svl( FName ) == 0 ) {
    FName = Parse_Str( _fl_File, TStr );
    }
    }
    else {
    Eol;
    Cr;
    }
    TStr = _fl_TreeLevel + “2” +
    _fl_NumFound + Str( NumFound ) +
    _fl_Path + Path +
    _fl_File + FName +
    _fl_TreeStr + Str( NumFound ) + ” : ” + Path + FName +
    _fl_TreeExpand + “1”;
    Put_Line( TStr );
    if ( Update ) {
    Goto_Mark;
    }
    else {
    Pop_Mark;
    }
    Switch_Win_Id( OrgWinId );

    // Set list changed flag
    Set_Global_Int( _g_FindLstCur + Str( LstId ), -1 );
    }
    Insert_Mode = SavInsertMode;
    Refresh = SavRefresh;

    } // SetFsLstFName

    void FindLstSetFound(
    int LstId,
    int LineNo,
    str FoundStr[ max_Line_Length ]
    ) trans2
    {
    int OrgWinId = Window_Id;
    int SavRefresh = Refresh;
    int SavInsertMode = Insert_Mode;

    str TStr[ max_Line_Length ];

    FoundStr = TreeTrim7F(FoundStr); //convert tabs, trim string to 240 chars, replace hex 7F chars with spaces. Fix TreeBuffer Invalid error
    Insert_Mode = True;
    Refresh = False;
    if ( Switch_Win_Id( Global_Int( _g_FindLstWin + Str( LstId ) ) ) ) {
    Eol;
    Cr;
    TStr = _fl_TreeLevel + “3” +
    _fl_StdBmp + “3” +
    _fl_LineNo + Str( LineNo ) +
    _fl_Data + FoundStr +
    _fl_TreeStr + StrRight( Str( LineNo ), 12, “0” ) + ” : ” + FoundStr;
    Put_Line( TStr );
    Switch_Win_Id( OrgWinId );

    // Set list changed flag
    Set_Global_Int( _g_FindLstCur + Str( LstId ), -1 );
    }
    Insert_Mode = SavInsertMode;
    Refresh = SavRefresh;

    } // FindLstSetFound

    /*——————————————————————————

    Function: Export the data from the Find list.

    Entry : int LstId – List number.
    str FName – The filename to write the exported data to.
    Defaults to XLIST.TMP in the temp directory.

    int Options – Options specifying what data to export

    _xo_Prompt – Set to show the export option dialog
    _xo_XLine – Set to export line number
    _xo_XData – Set to export line data
    _xo_XCount – Set to export file found count

    Exit : int – True if export done, otherwise False

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    int FindLstExport(
    int LstId,
    str FName,
    int Options
    ) trans2
    {
    int SavRefresh = Refresh;
    int ActiveWin = Window_Id;
    int FShow_Line = Options & _xo_XLine;
    int FShow_Data = Options & _xo_XData;
    int FShow_Count = Options & _xo_XCount;
    int ListWin;
    int LineCnt;
    int Result;
    int Dlg;
    int Jx;

    str TStr[ max_Line_Length ];
    str Line[ max_Line_Length ];
    str LStr;
    str FName[ 260 ];

    if ( Svl( FName ) == 0 ) {
    FName = TempFileName( _xl_FileName + Str( LstId ) ); // Name the export file list window
    }

    Result = True;
    if ( Options & _xo_Prompt ) { // Show export option dialog

    // *indent-off*
    DlgCreate( Dlg );
    DlgAddCtrl( Dlg, dlg_Static, “&File”,
    1, 1,
    0, 0,
    100, 0, “” );
    DlgAddCtrl( Dlg, dlg_Text, FName,
    dlg_PosOffset + 5, dlg_PosOffset + 0,
    30, 0,
    1000, 0, “/W=30/ML=260” );

    DlgAddCtrl( Dlg, dlg_GroupBox, “Export”,
    1, dlg_PosOffset + 1,
    40, 4,
    101, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Line numbers”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    30, 0,
    1100, 0, “” );
    DlgSetInt( Dlg, 1100, FShow_Line != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Line &data”,
    dlg_PosOffset, dlg_PosOffset + 1,
    30, 0,
    1101, 0, “” );
    DlgSetInt( Dlg, 1101, FShow_Data != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Found &count”,
    dlg_PosOffset, dlg_PosOffset + 1,
    30, 0,
    1102, 0, “” );
    DlgSetInt( Dlg, 1102, FShow_Count != 0 );

    DlgAddCtrl( Dlg, dlg_PushButton, “Ok”,
    1, dlg_PosOffset | dlg_Units | ( dlg_Units_HLine * 3 ),
    dlg_StanBtnWidth, 0,
    2001, 0, “/R=1” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Cancel”,
    dlg_PosOffset + dlg_StanBtnWidth + 2, dlg_PosOffset + 0,
    dlg_StanBtnWidth, 0,
    2000, 0, “/R=0” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Help”,
    dlg_PosOffset + dlg_StanBtnWidth + 2, dlg_PosOffset + 0,
    dlg_StanBtnWidth, 0,
    2002, 0, “/R=2” );
    // *indent-on*

    Result = DlgExecute( Dlg, 1000, “Export Find List”, hc_FindExport, “”, 0 );

    FName = DlgGetStr( Dlg, 1000 );
    FShow_Line = DlgGetInt( Dlg, 1100 );
    FShow_Data = DlgGetInt( Dlg, 1101 );
    FShow_Count = DlgGetInt( Dlg, 1102 );

    g_ExportOpts = ( FShow_Line * _xo_XLine ) | ( FShow_Data * _xo_XData ) |
    ( FShow_Count * _xo_XCount );
    DlgKill( Dlg );
    }
    if ( Result ) {
    Refresh = False; // Turn window refresh off
    Rm( “CreateWindow” ); // Create a new window for file list
    ListWin = Cur_Window; // Save window number
    File_Name = FName; // Name the new file list window

    FindLstGetWin( LstId, True, _pwa_None );

    Mark_Pos; // Save position in list
    Tof; // Go to top of list
    LineCnt = 1; // Set line count to first line
    while ( !At_Eof ) {
    Line = Get_Line( ); // Get line from list
    Down; // Goto next line
    switch ( Parse_Int( _fl_TreeLevel, Line ) ) {

    case _fld_FindDat :
    TStr = Parse_Str( _fl_TreeStr, Line );
    break;

    case _fld_FileDat :
    TStr = ” “;
    if ( FShow_Count ) {
    TStr += StrRight( Parse_Str( _fl_NumFound, Line ), 12 ) + ” : “;
    }
    TStr += Parse_Str( _fl_Path, Line ) + Parse_Str( _fl_File, Line );
    break;

    case _fld_FoundDat :
    if ( !FShow_Line && !FShow_Data ) {
    continue;
    }
    if ( FShow_Count ) {
    TStr = ” “;
    }
    else {
    TStr = ” “;
    }
    if ( FShow_Line ) {
    TStr += StrRight( Parse_Str( _fl_LineNo, Line ), 12 );
    }
    if ( FShow_Data ) {
    TStr += ” : ” + Parse_Str( _fl_Data, Line );
    }
    break;

    default:
    continue;
    }

    // Put data to new window
    Put_Line_To_Win( TStr, LineCnt, ListWin, False );
    ++LineCnt;
    }
    Goto_Mark; // Restore postion in list
    Switch_Window( ListWin ); // Switch to the new file list window
    Rm( “Select_Window” );
    Refresh = SavRefresh; // Restore window refresh
    }
    return ( Result );

    } // FindLstExport

    void DlgAddMenu(
    int Dlg,
    int HMenu,
    str MacroStr,
    str MenuStr
    ) trans2
    {
    if ( Svl( MenuStr ) ) {

    int TabPos = XPos( “\t”, MenuStr, 1 );
    int WCmd = GetAvailableWCmd( 0, 0 );

    if ( !TabPos ) {
    TabPos = Svl( MenuStr ) + 1;
    }
    if ( WCmd ) {
    WCmd_Add( 0, WCmd, 0, 0, 0, MacroStr + ” /DLGHANDLE=” + Str( Dlg ) +
    “/TEXT=” + Copy( MenuStr, 1, TabPos – 1 ), “” );
    AppendMenu( HMenu, mf_String, WCmd, MenuStr );
    }
    }
    } // DlgAddMenu

    /*——————————————————————————

    Description : Variant of DlgAddMenu that doesn’t display the insertion text
    Author : Reid Sweatman

    ——————————————————————–( rs )—*/
    void DlgAddMenu2(
    int Dlg,
    int HMenu,
    str MacroStr,
    str MenuStr
    ) trans2
    {
    if ( Svl( MenuStr ) ) {

    int TabPos = XPos( “\t”, MenuStr, 1 );
    int WCmd = GetAvailableWCmd( 0, 0 );

    if ( ! TabPos ) {
    TabPos = Svl( MenuStr ) + 1;
    }
    if ( WCmd ) {
    WCmd_Add( 0, WCmd, 0, 0, 0, MacroStr + ” /DLGHANDLE=” + Str( Dlg ) +
    “/TEXT=” + Copy( MenuStr, 1, TabPos – 1 ), “” );
    AppendMenu( HMenu, mf_String, WCmd, Copy( MenuStr, TabPos + 1, Svl( MenuStr ) – TabPos ) );
    }
    }
    } // DlgAddMenu2

    void DlgDelMenu( int HMenu ) trans2
    {
    int Jx;
    int Count;
    int MenuId;

    // Release WCmds
    Count = GetMenuItemCount( HMenu );
    for ( Jx = 0; Jx < Count; ++Jx ) { MenuId = GetMenuItemID( HMenu, Jx ); if ( MenuId != 0 ) { if ( MenuId == -1 ) { if ( GetSubMenu( HMenu, Jx ) ) { DlgDelMenu( GetSubMenu( HMenu, Jx ) ); } } else { ReleaseWCmd( MenuId ); } } } DestroyMenu( HMenu ); } // DlgDelMenu /*------------------------------------------------------------------------------ Exit : int Dlg - Windows dialog handle ( DLGHANDLE= ) int Id - The control id of the text control ( /ID= ) int Flags - Flags ( /FLAGS= ) 0x01 If set, then set the search type radio buttons. 0x02 If set, then set the RegEx checkbox. 0x04 Set for Replace RegEx, otherwise Search RegEx str RegEx - The text to insert into text control ( /CMD= ) Author : Dan Hughes --------------------------------------------------------------------( ldh )--*/ void _FindInsertRegEx( int Dlg = Parse_Int( "/DLGHANDLE=", MParm_Str ), int Id = Parse_Int( "/ID=", MParm_Str ), int Flags = Parse_Int( "/FLAGS=", MParm_Str ), str RegEx = Parse_Str( "/TEXT=", MParm_Str ) ) { if ( Dlg && Id ) { str TStr; int CtrlId = GetDlgItem( Dlg, Id ); int CaretPos; int CpLo; int CpHi; if ( Flags & 1 ) { SendDlgItemMessage( Dlg, id_sr_LiteralRB, bm_SetCheck, False, 0 ); SendDlgItemMessage( Dlg, id_sr_WordSrchRB, bm_SetCheck, False, 0 ); SendDlgItemMessage( Dlg, id_sr_RegExpRB, bm_SetCheck, True, 0 ); } else if ( Flags & 2 ) { SendDlgItemMessage( Dlg, id_sr_RegExpCB, bm_SetCheck, True, 0 ); } if ( Flags & 4 ) { // Replace string position CaretPos = g_RCaretPos; } else { // Search string position CaretPos = g_SCaretPos; } CpLo = ( CaretPos & 0xFFFF ); CpHi = ( CaretPos >> 16 );

    GetWindowText( CtrlId, TStr, 254 );
    if ( CpLo != CpHi ) {
    TStr = Str_Del( TStr, CpLo + 1, CpHi – CpLo );
    }
    if ( RegEx == “&&” ) {
    RegEx = “&”;
    }
    TStr = Str_Ins( RegEx, TStr, CpLo + 1 );
    SendMessageStr( CtrlId, wm_SetText, 0, TStr );
    SetFocus( CtrlId );
    CpLo += Svl( RegEx );
    SendMessage( CtrlId, cb_SetEditSel, 0, ( CpLo < < 16 ) | ( CpLo & 0xFFFF ) ); } } // _FindInsertRegEx void FindShowRegExMenu( int Window = Parse_Int( "/DLGHANDLE=", MParm_Str ), int Dlg = Parse_Int( "/DATAHANDLE=", MParm_Str ), int CtrlId = Parse_Int( "/CTRLID=", MParm_Str ), int Id = Parse_Int( "/ID=", MParm_Str ), int Flags = Parse_Int( "/FLAGS=", MParm_Str ) ) trans2 { int HMenu = CreatePopupMenu( ); int X; int Y; str MacroStr = "_FindInsertRegEx /ID=" + Str( Id ) + "/FLAGS=" + Str( Flags ); // Build menu if ( Flags & 4 ) { // Replace expressions switch ( g_RegExStyle ) { case esClassic : // Line break DlgAddMenu2( Window, hMenu, MacroStr, "$\t$\tLine break" ); // Captured submatches AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "#\t#n\tText matched by capture group n (zero-based)" ); DlgAddMenu2( Window, hMenu, MacroStr, "&&\t&&\tThe complete matched text" ); // Deletion operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "%\t%\tDelete previous character" ); // Final cursor position in replaced text AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "^\t^\tCursor location after replacement" ); // Embedded macro operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "!()\t!(...)\tExecute Multi-Edit macro within parentheses" ); break; case esUnix : // Line break DlgAddMenu2( Window, hMenu, MacroStr, "$\t$\tLine break" ); // Captured submatches AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\n\t\\n\tText matched by capture group n (zero-based)" ); DlgAddMenu2( Window, hMenu, MacroStr, "&&\t&&\tThe complete matched text" ); // Deletion operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "%\t%\tDelete previous character" ); // Final cursor position in replaced text AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "^\t^\tCursor location after replacement" ); // Embedded macro operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "!()\t!(...)\tExecute Multi-Edit macro within parentheses" ); // Characters AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\a\t\\a\t0x07 BEL" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\b\t\\b\t0x08 BS - Backspace" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\f\t\\f\t0x0C FF - Form Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\n\t\\n\t0x0A LF - Line Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\r\t\\r\t0x0D CR - Carriage Return" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\t\t\\t\t0x09 HT - Horizontal Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\v\t\\v\t0x0B VT - Vertical Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\x\t\\xHH\tByte specified by two hexadecimal digits" ); break; case esPerl : // Line break DlgAddMenu2( Window, hMenu, MacroStr, "$\t$\tLine break" ); // Captured submatches AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\n\t\\n\tText matched by capture group n (one-based)" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\0\t\\0\tThe complete matched text" ); // Deletion operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "%\t%\tDelete previous character" ); // Final cursor position in replaced text AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "^\t^\tCursor location after replacement" ); // Embedded macro operator AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "!()\t!(macro)\tExecute Multi-Edit macro within parentheses" ); // Characters AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\a\t\\a\t0x07 BEL" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\b\t\\b\t0x08 BS - Backspace" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\f\t\\f\t0x0C FF - Form Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\n\t\\n\t0x0A LF - Line Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\r\t\\r\t0x0D CR - Carriage Return" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\t\t\\t\t0x09 HT - Horizontal Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\v\t\\v\t0x0B VT - Vertical Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\x\t\\xHH\tByte specified by two hexadecimal digits" ); break; } } else { // Search expressions switch ( g_RegExStyle ) { case esClassic : DlgAddMenu2( Window, hMenu, MacroStr, "%\t%\tBeginning of line" ); DlgAddMenu2( Window, hMenu, MacroStr, "$\t$\tEnd of line" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "*\t...*\tMatch zero or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "+\t...+\tMatch one or more times" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "|\t...|...\tLeft OR right pattern" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "{}\t{...}\tGroup and capture into #0, #1, etc." ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "?\t...?\tAny single character" ); DlgAddMenu2( Window, hMenu, MacroStr, "[]\t[...]\tAny one character in the bracketed list" ); DlgAddMenu2( Window, hMenu, MacroStr, "[~]\t[~...]\tAny one character not in the bracketed list" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "@a\t@a\t0x07 BEL" ); DlgAddMenu2( Window, hMenu, MacroStr, "@b\t@b\t0x08 BS - Backspace" ); DlgAddMenu2( Window, hMenu, MacroStr, "@f\t@f\t0x0C FF - Form Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "@n\t@n\t0x0A LF - Newline" ); DlgAddMenu2( Window, hMenu, MacroStr, "@r\t@r\t0x0D CR - Carriage Return" ); DlgAddMenu2( Window, hMenu, MacroStr, "@t\t@t\t0x09 HT - Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "@v\t@v\t0x0B VT - Vertical Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "@x\t@xHH\tByte specified by two hexadecimal digits" ); break; case esUnix : DlgAddMenu2( Window, hMenu, MacroStr, "^\t^\tBeginning of line" ); DlgAddMenu2( Window, hMenu, MacroStr, "$\t$\tEnd of line" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "*\t...*\tMaximally match zero or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "+\t...+\tMaximally match one or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "@\t...@\tMinimally match zero or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "#\t...#\tMinimally match one or more times" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "|\t...|...\tLeft OR right pattern" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "()\t(...)\tGroup and capture into \\0, \\1, etc." ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, ".\t.\tAny single character" ); DlgAddMenu2( Window, hMenu, MacroStr, "[]\t[...]\tAny one character in the bracketed list" ); DlgAddMenu2( Window, hMenu, MacroStr, "[^]\t[^...]\tAny one character not in the bracketed list" ); AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\a\t\\a\t0x07 BEL" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\b\t\\b\t0x08 BS - Backspace" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\f\t\\f\t0x0C FF - Form Feed" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\n\t\\n\t0x0A LF - Newline" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\r\t\\r\t0x0D CR - Carriage Return" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\t\t\\t\t0x09 HT - Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\v\t\\v\t0x0B VT - Vertical Tab" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\x\t\\xHH\tByte specified by two hexadecimal digits" ); break; case esPerl : // Most-commonly-used expressions on first-level menu ------------------ // Multi-line matching DlgAddMenu2( Window, hMenu, MacroStr, "(?m)\t(?m)\tTurn multi-line matching on" ); // Characters, character classes, character modifiers AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, ".\t.\tAny single character" ); DlgAddMenu2( Window, hMenu, MacroStr, "[]\t[...]\tAny one character in the bracketed list" ); DlgAddMenu2( Window, hMenu, MacroStr, "[^]\t[^...]\tAny one character not in the bracketed list" ); DlgAddMenu2( Window, hMenu, MacroStr, "\\\t\\C\tPrepended modifier: interpret C as literal character" ); // Alternation AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "|\t...|...\tLeft OR right pattern" ); // Count-control expressions and modifiers AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "*\t...*\tMatch zero or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "+\t...+\tMatch one or more times" ); DlgAddMenu2( Window, hMenu, MacroStr, "?\t...?\tMatch zero or one times" ); DlgAddMenu2( Window, hMenu, MacroStr, "{}\t...{n}\tMatch exactly n times" ); DlgAddMenu2( Window, hMenu, MacroStr, "{,}\t...{n,}\tMatch at least n times" ); DlgAddMenu2( Window, hMenu, MacroStr, "{,}\t...{min,max}\tMatch between min and max times" ); DlgAddMenu2( Window, hMenu, MacroStr, "?\t...?\tAppended modifier: minimal match" ); DlgAddMenu2( Window, hMenu, MacroStr, "+\t...+\tAppended modifier: no backtracking" ); // Capture groups and references AppendMenu( hMenu, MF_SEPARATOR, 0, "" ); DlgAddMenu2( Window, hMenu, MacroStr, "()\t(...)\tGroup and capture into \\1, \\2, etc." ); DlgAddMenu2( Window, hMenu, MacroStr, "(?P<>)\t(?P…)\tGroup and capture into named group” );
    DlgAddMenu2( Window, hMenu, MacroStr, “\\\t\\n\tResults of nth earlier group submatch” );

    // Lookaround expressions
    AppendMenu( hMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hMenu, MacroStr, “(?=)\t(?=…)\tPositive lookahead” );
    DlgAddMenu2( Window, hMenu, MacroStr, “(?!)\t(?!…)\tNegative lookahead” );
    DlgAddMenu2( Window, hMenu, MacroStr, “(?< =)\t(?<=...)\tPositive lookbehind" ); DlgAddMenu2( Window, hMenu, MacroStr, "(?)\t(?P…)\tGroup and capture into named group” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “\\\t\\n\tResults of nth earlier group submatch” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “(?:)\t(?:…)\tGroup without capture” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “(?>)\t(?>…)\tGroup, disallowing backtracking” );

    // Alternation operator
    AppendMenu( hGroupingMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “|\t…|…\tLeft OR right pattern” );

    // Maximal-match (the default) controls
    AppendMenu( hGroupingMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “*\t…*\tMatch zero or more times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “+\t…+\tMatch one or more times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “?\t…?\tMatch zero or one times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{}\t…{n}\tMatch exactly n times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}\t…{n,}\tMatch at least n times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}\t…{min,max}\tMatch between min and max times” );

    // Minimal-match controls (same as maximal-match, but with appended ‘?’
    AppendMenu( hGroupingMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “*?\t…*?\tMinimally match zero or more times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “+?\t…+?\tMinimally match one or more times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “??\t…??\tMinimally match zero or one times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}?\t…{n,}?\tMinimally match at least n times” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}?\t…{min,max}?\tMinimally match between min and max times” );

    // No-backtracking controls (same as maximal-match, but with appended ‘+’
    AppendMenu( hGroupingMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “*+\t…*+\tMatch zero or more times, never backtrack” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “++\t…++\tMatch one or more times, never backtrack” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “?+\t…?+\tMatch zero or one times, never backtrack” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{}+\t…{n}+\tMatch exactly n times, never backtrack” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}+\t…{n,}+\tMatch at least n times, never backtrack” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “{,}+\t…{min,max}+\tMatch between min and max times, never backtrack” );

    // Conditional match expressions
    AppendMenu( hGroupingMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “(?()|)\t(?(condition)…|…)\tIf/else match; condition can be capture group or lookaround number” );
    DlgAddMenu2( Window, hGroupingMenu, MacroStr, “(?())\t(?(condition)…)\tIf match; condition can be capture group or lookaround number” );

    // Popup menu for mode modifiers and quote delimiters ——————

    int hModeMenu = CreatePopupMenu( );
    AppendMenu( hMenu, MF_POPUP, hModeMenu, “&Mode Modifiers” );

    // Modes
    DlgAddMenu2( Window, hModeMenu, MacroStr, “i\ti\tCase-insensitive match” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “m\tm\tMulti-line: ^ and $ match next to embedded \\n” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “s\ts\tDot metacharacter matches newlines” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “x\tx\tIgnore whitespace and allow EOL comments in expression” );
    // DlgAddMenu2( Window, hModeMenu, MacroStr, “U\tU\tReverse greediness of all count-controls” );

    // Modifier expressions
    AppendMenu( hModeMenu, MF_SEPARATOR, 0, “” );
    // DlgAddMenu2( Window, hModeMenu, MacroStr, “(?)\t(?imsxU)\tTurn listed modes on” );
    // DlgAddMenu2( Window, hModeMenu, MacroStr, “(?-)\t(?-imsxU)\tTurn listed modes off” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “(?)\t(?imsx)\tTurn listed modes on” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “(?-)\t(?-imsx)\tTurn listed modes off” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “(?:)\t(?modes:imsx)\tToggle listed modes within parentheses” );

    // Quote delimiters
    AppendMenu( hModeMenu, MF_SEPARATOR, 0, “” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “\\Q\t\\Q\tQuote all following metacharacters” );
    DlgAddMenu2( Window, hModeMenu, MacroStr, “\\E\t\\E\tEnd a span started with \\Q” );
    break;
    }
    }

    // Show menu
    DlgGetCtrlPos( Dlg, CtrlId, X, Y );
    TrackPopupMenu( HMenu, 0, X, Y, 0, Frame_Handle, 0 );

    // Allow menu message to be processed
    ProcessMsgQueue( 10 );
    DlgDelMenu( HMenu );

    } // FindShowRegExMenu

    /*——————————————————————————

    Function: The main tabbed search dialog.
    Entry : “/SETUP=1” – Set when called from Customize dialog
    “/T#=” – The number of the tab to show.

    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    void SearchTabDlg(
    int M = Parse_Int( “/M=”, MParm_Str ),
    int Dlg = Parse_Int( “/DLG=”, MParm_Str ),
    int Result = Parse_Int( “/RES=”, MParm_Str ),
    int Setup = Parse_Int( “/SETUP=”, MParm_Str )
    ) trans2
    {
    TTRACE_ENTER( “Search”, TDBG_Trace, “SearchTabDlg(%d, %d, %d, %d)”, M, Dlg, Result, Setup );

    int Top_Offset = 0;

    if ( Setup ) {
    Top_Offset = 8;
    }
    switch ( M ) {

    case 0 :
    TTRACE( “Search”, TDBG_Trace, “0: %s|”, MParm_Str );
    if ( g_hSRDialog != 0 ) {

    // Don’t allow multiple occurrences, switch to currently active dialog
    SetActiveWindow( g_hSRDialog );

    // Select correct tab
    DlgTabActivate( g_SearchTabDlg, id_st_TabBar, Parse_Int( “/T#=”, MParm_Str ));
    TTRACE_LEAVE( “SearchTabDlg()” );
    return ( );
    }
    SetSearchHistory( “”, True, 0, 0 );

    call _BuildCtrls;
    Return_Int = False;
    break;

    case 1 :
    TTRACE( “Search”, TDBG_Trace, “1: %s|”, MParm_Str );
    call _BuildCtrls;
    break;

    case 2 :
    TTRACE( “Search”, TDBG_Trace, “2: %s|”, MParm_Str );
    call _EndDlg;
    break;

    case 3 :
    TTRACE( “Search”, TDBG_Trace, “3: %s|”, MParm_Str );
    break;
    }
    TTRACE_LEAVE( “SearchTabDlg()” );
    return ( );

    // Internal Routines ———————————————————–

    _BuildCtrls:

    str TcStr = “/TC=” + Str( id_st_TabBar );

    if ( !Dlg ) {
    DlgCreate( Dlg );
    }
    if ( XPos( “/T#=”, MParm_Str, 1 ) ) {
    g_SearchTabNo = Parse_Int( “/T#=”, MParm_Str );
    }
    // *indent-off*
    DlgAddCtrl( Dlg, dlg_TabBar, “”,
    1, dlg_Units | top_offset,
    _stab_Width, _stab_Height,
    id_st_TabBar, 0, “/IL=1” );

    DlgAddCtrl( Dlg, dlg_SubDlg, “Find”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    “/IM=BT_SR_100_S” + TcStr + “/BM=_SearchDlg //SM=0” +
    “//H=” + Parse_Str( “/H=”, MParm_Str ) +
    “//SWG=” + Parse_Str( “/SWG=”, MParm_Str ) +
    “//SRG=” + Parse_Str( “/SRG=”, MParm_Str ) +
    “//SETUP=” + Str( Setup ) );

    DlgAddCtrl( Dlg, dlg_SubDlg, “Replace”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    “/IM=BT_SR_101_S” + TcStr + “/BM=_SearchDlg //SM=1” +
    “//H=” + Parse_Str( “/H=”, MParm_Str ) +
    “//SWG=” + Parse_Str( “/SWG=”, MParm_Str ) +
    “//SRG=” + Parse_Str( “/SRG=”, MParm_Str ) +
    “//RPG=” + Parse_Str( “/RPG=”, MParm_Str ) +
    “//SETUP=” + Str( Setup ) );

    DlgAddCtrl( Dlg, dlg_SubDlg, “File find”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    “/IM=BT_SR_103_S” + TcStr + “/BM=_FileSearchDlg //SM=0” +
    “//H=” + Parse_Str( “/H=”, MParm_Str ) +
    “//SWG=” + Parse_Str( “/SWG=”, MParm_Str ) +
    “//SRG=” + Parse_Str( “/SRG=”, MParm_Str ) +
    “//SPG=” + Parse_Str( “/SPG=”, MParm_Str ) +
    “//SETUP=” + Str( Setup ) );

    DlgAddCtrl( Dlg, dlg_SubDlg, “File replace”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    “/IM=BT_SR_104_S” + TcStr + “/BM=_FileSearchDlg //SM=1” +
    “//H=” + Parse_Str( “/H=”, MParm_Str ) +
    “//SWG=” + Parse_Str( “/SWG=”, MParm_Str ) +
    “//SRG=” + Parse_Str( “/SRG=”, MParm_Str ) +
    “//RPG=” + Parse_Str( “/RPG=”, MParm_Str ) +
    “//SPG=” + Parse_Str( “/SPG=”, MParm_Str ) +
    “//SETUP=” + Str( Setup ) );

    DlgAddCtrl( Dlg, dlg_SubDlg, “Hilite”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    “/IM=BT_SR_117_S” + TcStr + “/BM=_GHighlightDlg ” +
    “//H=” + Parse_Str( “/H=”, MParm_Str ) + “//SETUP=” + Str( Setup ) );

    DlgAddCtrl( Dlg, dlg_SubDlg, “Options”,
    dlg_PosOffset, dlg_PosOffset,
    0, 0,
    -1, 0,
    TcStr + “/BM=SrchOptionsDlg //H=” + Parse_Str( “/H=”, MParm_Str ) +
    “//SETUP=” + Str( Setup ) );

    DlgSetInt( Dlg, id_st_TabBar, g_SearchTabNo );
    if ( M == 0 ) {
    DlgAddCtrl( Dlg, dlg_PushButton, “&Search”,
    1, dlg_Units | ( ( _stab_Height * 12 ) + 3 ),
    dlg_StanBtnWidth, 0,
    id_sr_SearchBtn, dlgf_DefButton, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “&Replace”,
    dlg_PosOffset + dlg_StanBtnWidth + 1, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_sr_ReplaceBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “&All”,
    dlg_PosOffset + dlg_StanBtnWidth + 1, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_sr_AllBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “”,
    dlg_PosOffset + dlg_StanBtnWidth + 1, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_sr_DirSwitchBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Defaul&ts”,
    _stab_Width – 34, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_sr_DefaultsBtn, 0, “” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Close”,
    _stab_Width – 22, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_std_Close, 0, “/R=0” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Help”,
    dlg_PosOffset | dlg_StanBtnWidth + 2, dlg_PosOffset,
    dlg_StanBtnWidth, 0,
    id_std_Help, 0, “/R=2” );

    Result = DlgExecute( Dlg, -1, “Search”, “”,
    “/PARENT=” + Parse_Str( “/DLGHANDLE=”, MParm_Str ) +
    “/RPOS=” + _g_SearchTabDlgPos +
    “/H=” + hc_SearchDlg +
    “/HOOK=_SearchTabDlgProc”,
    dlg_Modeless | dlg_NoParDisable | dlg_MaximizeBtn );
    }
    // *indent-on*
    ret;

    _EndDlg:
    g_SearchTabNo = DlgGetInt( Dlg, id_st_TabBar );
    if ( Result && Setup ) {
    Set_Global_Int( “Setup_Changed”, Global_Int( “Setup_Changed” ) | 0x01 );
    }
    ret;

    } // SearchTabDlg

    int _SearchTabDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    switch ( Message ) {

    case wm_Activate :
    switch ( WParam & 0xFFFF ) {

    case wa_Active :
    case wa_ClickActive :
    call _SendChildMsg;
    break;

    case wa_Inactive :
    break;
    }
    break;

    case wm_Destroy :
    g_SCaretPos = 0;
    g_RCaretPos = 0;
    g_hSRDialog = 0;
    g_SearchTabDlg = 0;
    g_SrCollapsed = False;
    Set_Global_Str( “Search_History0”, “” );
    Set_Global_Str( “Replace_History0”, “” );
    break;

    case wm_SysCommand :
    switch ( WParam & 0xfff0 ) {

    case sc_Close :
    call _DoClose;
    break;

    case sc_Maximize :
    call _SendChildMsg;
    RetVal = 0;
    return ( 1 );

    case sc_Restore :
    RetVal = 0;
    return ( 1 );
    }
    break;

    case wm_Command :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    switch ( WParam & 0xffff ) {

    case dlg_WCmd_Init :
    g_hSRDialog = Window;
    g_SearchTabDlg = Parse_Int( “/DLG=”, Parms );
    break;

    case id_std_Close :
    call _DoClose;
    break;

    case id_sr_SearchBtn :
    case id_sr_ReplaceBtn :
    case id_sr_AllBtn :
    case id_sr_DirSwitchBtn :
    case id_sr_DefaultsBtn :
    call _SendChildMsg;
    break;
    }
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    // Internal Routines ———————————————————–

    _DoClose:
    g_SearchTabNo = DlgTabGetCurrentId( GetDlgItem( Window, id_st_TabBar ) );
    ret;

    _SendChildMsg:

    str SubDlgInfo = DlgTabGetSubInfo( 0, Window, id_st_TabBar, -1 );

    int SubDlgWin = Parse_Int( “/WH=”, SubDlgInfo );

    PostMessage( SubDlgWin, Message, WParam, LParam );
    ret;

    } // _SearchTabDlgProc

    void _SearchDlg(
    int M = Parse_Int( “/M=”, MParm_Str ),
    int Dlg = Parse_Int( “/DLG=”, MParm_Str ),
    int Result = Parse_Int( “/RES=”, MParm_Str ),
    int SetupOnly = Parse_Int( “/SETUP=”, MParm_Str )
    ) trans2
    {
    TTRACE_ENTER( “Search”, TDBG_Trace, “_SearchDlg(%d, %d, %d, %d)”, M, Dlg, Result, SetupOnly );

    int SearchMode = g_SearchMode;

    str GSwitches = Parse_Str( “/SWG=”, MParm_Str );
    str GSearchStr = Parse_Str( “/SRG=”, MParm_Str );
    str GReplaceStr = Parse_Str( “/RPG=”, MParm_Str );
    str GSColBeg;
    str GSColEnd;

    if ( XPos( “/SM=”, MParm_Str, 1 ) ) {
    SearchMode = Parse_Int( “/SM=”, MParm_Str );
    }
    if ( Svl( GSwitches ) == 0 ) {
    if ( SetupOnly ) {
    if ( SearchMode ) {
    GSwitches = _g_DefReplSwitches;
    }
    else {
    GSwitches = _g_DefSwitches;
    }
    }
    else {
    if ( SearchMode ) {
    GSwitches = _g_ReplSwitches;
    }
    else {
    GSwitches = _g_Switches;
    }
    }
    }
    if ( Svl( GSearchStr ) == 0 ) {
    GSearchStr = _g_SearchStr;
    }
    if ( Svl( GReplaceStr ) == 0 ) {
    GReplaceStr = _g_ReplaceStr;
    }
    if ( SetupOnly ) {
    GSColBeg = _g_DefSearchColBeg;
    GSColEnd = _g_DefSearchColEnd;
    }
    else {
    GSColBeg = _g_SearchColBeg;
    GSColEnd = _g_SearchColEnd;
    }
    switch ( M ) {

    case 1 :
    TTRACE( “Search”, TDBG_Debug, “1: %s|”, MParm_Str );
    call _BuildCtrls;
    break;

    case 2 :
    TTRACE( “Search”, TDBG_Debug, “2: %s|”, MParm_Str );
    call _EndDlg;
    break;

    case 3 :
    TTRACE( “Search”, TDBG_Debug, “3: %s|”, MParm_Str );
    break;
    }
    TTRACE_LEAVE( “_SearchDlg()” );
    return ( );

    // Internal Routines ———————————————————–

    _BuildCtrls:

    int StrWidth = 57;
    int X;
    int Y;
    int Opt;
    int IgnoreCase;
    int GlobalSrch;
    int Restrict;
    int AllWindows;
    int Backwards;
    int Prompted;
    int ExitNoFind;
    int CursorStart;
    int MarkText;
    int Columns;

    str Bitmap;
    str HelpContext = Parse_Str( “/H=”, MParm_Str );

    if ( Svl( HelpContext ) == 0 ) {
    if ( SetupOnly ) {
    if ( SearchMode ) {
    HelpContext = hc_ReplaceDef;
    }
    else {
    HelpContext = hc_FindDef;
    }
    }
    else {
    if ( SearchMode ) {
    HelpContext = hc_Replace;
    }
    else {
    HelpContext = hc_Find;
    }
    }
    }
    call _SetCtrls;

    X = 1;
    Y = dlg_Units;

    // *indent-off*
    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_Static, “Sear&ch for:”,
    X, Y,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GSearchStr ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_SearchStr, 0, “/ML=256/HISTORY=Search_History/SHOWH0=” +
    Str( g_DefSearchOpts & _so_ShowHis0 ) );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, dlg_Static, “Re&place with:”,
    // dlg_NegOffset + 14, dlg_PosOffset + 1,
    X, dlg_PosOffset + 1,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GReplaceStr ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_ReplaceStr, 0, “/ML=256/HISTORY=Replace_History” );

    Y = dlg_PosOffset | dlg_Units | 10;
    }
    else {
    Y = dlg_PosOffset | dlg_Units | 22;
    }
    // X = dlg_NegOffset + 14;
    }

    if ( !SetupOnly ) {

    // Add Reg Exp. Buttons here to adjust tab order…
    DlgAddCtrl( Dlg, dlg_BitmapBtn, “LARROW”,
    Dlg_units | 289, 1,
    dlg_Units + 11, dlg_Units + 9,
    id_sr_SrchRegExBtn, 0,
    “/M=FindShowRegExMenu /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=1” );
    }

    if ( SearchMode && !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_BitmapBtn, “LARROW”,
    dlg_PosOffset, 2,
    dlg_Units + 11, dlg_Units + 9,
    id_sr_RepRegExBtn, 0,
    “/M=FindShowRegExMenu /ID=” + Str( id_sr_ReplaceStr ) + “/FLAGS=5” );
    }

    DlgAddctrl( Dlg, dlg_GroupBox, “Type”,
    X, Y,
    32, 4,
    id_sr_TypeGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_RadioButton, “&Literal”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_LiteralRB, 0, “” );
    DlgSetInt( Dlg, id_sr_LiteralRB, Opt == 1 );

    DlgAddCtrl( Dlg, dlg_RadioButton, “Regular &expression”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_RegExpRB, 0, “” );
    DlgSetInt( Dlg, id_sr_RegExpRB, Opt == 2 );

    DlgAddCtrl( Dlg, dlg_RadioButton, “Wor&d/Phrase search”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_WordSrchRB, 0, “” );
    DlgSetInt( Dlg, id_sr_WordSrchRB, Opt == 3 );

    DlgAddCtrl( Dlg, dlg_GroupBox, “Mode”,
    dlg_NegOffset + 1, dlg_PosOffset | dlg_Units_5QLines – 1,
    32, 3,
    id_sr_ModeGrp, 0, “” );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, Dlg_CheckBox, “Pr&ompted replace”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_PromptSrchCB, 0, “” );
    DlgSetInt( Dlg, id_sr_PromptSrchCB, Prompted );
    }
    else {
    DlgAddCtrl( Dlg, dlg_CheckBox, “Pr&ompted search”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_PromptSrchCB, 0, “” );
    DlgSetInt( Dlg, id_sr_PromptSrchCB, Prompted );
    }
    DlgAddCtrl( Dlg, dlg_CheckBox, “E&xit when nothing found”,
    dlg_PosOffset + 0, dlg_PosOffset + 1,
    0, 0,
    id_sr_ExitNoFindCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ExitNoFindCB, ExitNoFind );

    DlgAddCtrl( Dlg, dlg_GroupBox, “”,
    dlg_NegOffset + 1, dlg_PosOffset | dlg_units_5QLines,
    // 30, 3,
    19, 3,
    id_sr_ColGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Col&umns”,
    dlg_PosOffset + 1, dlg_PosOffset + 0,
    0, 0,
    id_sr_ColumnsCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ColumnsCB, Columns );

    DlgAddCtrl( Dlg, dlg_Static, “Start”,
    dlg_PosOffset + 0, dlg_PosOffset + 1,
    0, 0,
    id_sr_BegColLbl, 0, “” );

    DlgAddCtrl( Dlg, dlg_Integer, “”,
    dlg_PosOffset + 6, dlg_PosOffset,
    8, 0,
    id_sr_BegCol, 0, “/MIN=0/MAX=” + Str( max_Line_Length ) );
    DlgSetInt( Dlg, id_sr_BegCol, Global_Int( GSColBeg ) );

    DlgAddCtrl( Dlg, dlg_Static, “Stop”,
    dlg_NegOffset + 6, dlg_PosOffset + 1,
    0, 0,
    id_sr_EndColLbl, 0, “” );

    DlgAddCtrl( Dlg, dlg_Integer, “”,
    dlg_PosOffset + 6, dlg_PosOffset,
    8, 0,
    id_sr_EndCol, 0, “/MIN=0/MAX=” + Str( max_Line_Length ) );
    DlgSetInt( Dlg, id_sr_EndCol, Global_Int( GSColEnd ) );

    DlgGetXY( Dlg, id_sr_ColGrp, X, Y );
    DlgAddCtrl( Dlg, dlg_GroupBox, “Find List”,
    dlg_Units | X + ( 20 * dlg_Units_Per_Col ), dlg_Units | Y,
    12, 3,
    id_sr_UseLstGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_RadioButton, “&0”,
    dlg_PosOffset + 1, dlg_PosOffset | dlg_Units | 10,
    0, 0,
    id_sr_List0RB, 0, “” );
    DlgSetInt( Dlg, id_sr_List0RB, g_SFindLstId == 0 );

    DlgAddCtrl( Dlg, dlg_RadioButton, “&1”,
    dlg_PosOffset + 0, dlg_PosOffset + 1,
    0, 0,
    id_sr_List1RB, 0, “” );
    DlgSetInt( Dlg, id_sr_List1RB, g_SFindLstId == 1 );

    DlgGetXY( Dlg, id_sr_TypeGrp, X, Y );
    DlgAddCtrl( Dlg, dlg_GroupBox, “Options”,
    dlg_Units | X + ( 34 * dlg_Units_Per_Col ), dlg_Units | Y,
    37, dlg_Units | 85,
    id_sr_OptionGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Backward search”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_BackwardCB, 0, “” );
    DlgSetInt( Dlg, id_sr_BackwardCB, Backwards );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Case sensiti&ve”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_CaseCB, 0, “” );
    DlgSetInt( Dlg, id_sr_CaseCB, IgnoreCase );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Global search”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_GlobalSrchCB, 0, “” );
    DlgSetInt( Dlg, id_sr_GlobalSrchCB, GlobalSrch );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Restrict to &marked block”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_BlockSrchCB, 0, ”);
    DlgSetInt( Dlg, id_sr_BlockSrchCB, Restrict );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Search all &windows”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_AllWindowsCB, 0, “” );
    DlgSetInt( Dlg, id_sr_AllWindowsCB, AllWindows );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, dlg_CheckBox, “Cursor le&ft at start of new text”,
    dlg_PosOffset + 0, dlg_PosOffset + 1,
    0, 0,
    id_sr_PosBegStrCB, 0, “” );
    DlgSetInt( Dlg, id_sr_PosBegStrCB, CursorStart );
    }
    else {
    DlgAddCtrl( Dlg, Dlg_CheckBox, “Mar&k found text”,
    dlg_PosOffset + 0, dlg_PosOffset + 1,
    0, 0,
    id_sr_MarkFndTxtCB, 0, “” );
    DlgSetInt( Dlg, id_sr_MarkFndTxtCB, MarkText != 0 );
    }

    Return_Str = “/H=” + HelpContext;
    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_PushButton, “Al&ias”,
    _stab_Width – 33, dlg_Units | ( ( ( _stab_Height – 3 ) * 12 ) + 3 ),
    dlg_StanBtnWidth, 0,
    id_sr_AliasBtn, 0,
    “/M=SearchGetAlias /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=1” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Reg Ex &Help”,
    dlg_PosOffset | dlg_StanBtnWidth + 2, dlg_PosOffset,
    dlg_StanBtnWidth + 4, 0,
    id_sr_RegExpHlpBtn, 0,
    “/M=RegExpHelp” );

    Return_Str = “/H=” + HelpContext + “/INITMAC=” +
    “/HOOK=_SearchDlgProc //SM=” + Str( SearchMode );
    }
    // *indent-on*
    ret;

    _EndDlg:
    if ( !SetupOnly ) {
    Result = True; // Always save settings
    }
    if ( Result ) {

    str Switches[ 40 ] = “”;

    if ( DlgGetInt( Dlg, id_sr_RegExpRB ) == 0 ) {
    Switches += “X”;
    }
    if ( DlgGetInt( Dlg, id_sr_WordSrchRB ) != 0 ) {
    Switches += “W”;
    }
    if ( DlgGetInt( Dlg, id_sr_PromptSrchCB ) != 0 ) {
    Switches += “P”;
    }
    if ( DlgGetInt( Dlg, id_sr_ExitNoFindCB ) != 0 ) {
    Switches += “K”;
    }
    if ( DlgGetInt( Dlg, id_sr_ColumnsCB ) != 0 ) {
    Switches += “O”;
    }
    if ( DlgGetInt( Dlg, id_sr_BackwardCB ) != 0 ) {
    Switches += “B”;
    }
    if ( DlgGetInt( Dlg, id_sr_CaseCB ) == 0 ) {
    Switches += “I”;
    }
    if ( DlgGetInt( Dlg, id_sr_GlobalSrchCB ) != 0 ) {
    Switches += “G”;
    }
    if ( DlgGetInt( Dlg, id_sr_BlockSrchCB ) != 0) {
    Switches += “R”;
    }
    if ( DlgGetInt( Dlg, id_sr_AllWindowsCB ) != 0) {
    Switches += “A”;
    }
    if ( SearchMode ) {
    if ( DlgGetInt( Dlg, id_sr_PosBegStrCB ) != 0 ) {
    Switches += “C”;
    }
    }
    else {
    if ( DlgGetInt( Dlg, id_sr_MarkFndTxtCB ) ) {
    Switches += “M”;
    }
    }
    Set_Global_Str( GSwitches, Switches );
    Set_Global_Int( GSColBeg, DlgGetInt( Dlg, id_sr_BegCol ) );
    Set_Global_Int( GSColEnd, DlgGetInt( Dlg, id_sr_EndCol ) );
    g_SFindLstId = DlgGetInt( Dlg, id_sr_List1RB );
    }
    if ( !SetupOnly ) {
    if ( g_SaveSearchStr ) {

    // Save Search str and add to history list
    Return_Str = DlgGetStr( Dlg, id_sr_SearchStr );
    Set_Global_Str( GSearchStr, Return_Str );
    Rm( “History_List /M=1/HISTORY=SEARCH_HISTORY” );
    g_SaveSearchStr = False;
    }
    if ( SearchMode && g_SaveReplaceStr ) {

    // Save Replace str and add to history list
    Return_Str = DlgGetStr( Dlg, id_sr_ReplaceStr );
    Set_Global_Str( GReplaceStr, Return_Str );
    Rm( “History_List /M=1/HISTORY=REPLACE_HISTORY” );
    g_SaveReplaceStr = False;
    }
    g_RepSearch = False;
    }
    ret;

    _SetCtrls:

    str Switches[ 40 ] = Global_Str( GSwitches );

    IgnoreCase = XPos( “I”, Switches, 1 ) == 0;
    GlobalSrch = XPos( “G”, Switches, 1 ) != 0;
    Restrict = XPos( “R”, Switches, 1 ) != 0;
    AllWindows = XPos( “A”, Switches, 1 ) != 0;
    Backwards = XPos( “B”, Switches, 1 ) != 0;
    Prompted = XPos( “P”, Switches, 1 ) != 0;
    ExitNoFind = XPos( “K”, Switches, 1 ) != 0;
    CursorStart = XPos( “C”, Switches, 1 ) != 0;
    MarkText = XPos( “M”, Switches, 1 ) != 0;
    Columns = XPos( “O”, Switches, 1 ) != 0;

    // Default to a forward search if cursor is at top of file
    // and a backward search if cursor is at end of file.
    // Backwards = ( ( ( XPos( “B”, Switches, 1 ) != 0 ) && !( C_Line == 1 && C_Col == 1 ) ) || At_Eof );

    if ( !XPos( “X”, Switches, 1 ) ) {
    Opt = 2; // regular expressions
    }
    else if ( XPos( “W”, Switches, 1 ) ) {
    Opt = 3; // word/phrase
    }
    else {
    Opt = 1; // literal
    }
    ret;

    } // _SearchDlg

    int _SearchDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    int SearchMode = Parse_Int( “/SM=”, Parms );
    int BlkOn = Block_Stat > 0;
    int Parent = GetParent( Window );
    int ExitNoFind;
    int Jx;
    int EnableFlag;
    int HideFlag;
    int Lock;

    str TStr;

    switch ( Message ) {

    case wm_Activate :
    if ( ( WParam & 0xFFFF ) != wa_Inactive ) {
    if ( !g_RepSearch ) {

    // Add current word to the top of the search history list
    TStr = SetSearchHistory( “”, True, Window, id_sr_SearchStr );
    if ( SearchMode ) {

    // Add current word to the top of the replace history list
    SetSearchHistory( TStr, False, Window, id_sr_ReplaceStr );
    }
    }
    else {
    if ( SearchMode ) {
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), True );
    // if ( !g_SrCollapsed ) {
    // call _Collapse;
    // }
    }
    }
    EnableWindow( GetDlgItem( Window, id_sr_BlockSrchCB ), BlkOn );
    if ( SearchMode ) {
    if ( ( g_DefSearchOpts & _so_NoBlkChk ) == 0 ) {
    if ( XPos( “R”, Caps( g_DefReplSwitches ), 1 ) ) {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, BlkOn, 0 );
    }
    else {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, false, 0 ); //clear checkmark
    }
    }

    // Set direction checkbox
    if ( XPos( “B”, Caps( g_ReplSwitches), 1 ) ) {
    Jx = True;
    }
    else {
    Jx = False;
    }
    SendDlgItemMessage( Window, id_sr_BackwardCB, bm_SetCheck, Jx, 0 );
    }
    else {
    if ( ( g_DefSearchOpts & _so_NoBlkChk ) == 0 ) {
    if ( XPos( “R”, Caps( g_DefSwitches ), 1 ) ) {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, BlkOn, 0 );
    }
    else {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, false, 0 ); //clear checkmark
    }
    }

    // Set direction checkbox
    if ( XPos( “B”, Caps( g_Switches), 1 ) ) {
    Jx = True;
    }
    else {
    Jx = False;
    }
    SendDlgItemMessage( Window, id_sr_BackwardCB, bm_SetCheck, Jx, 0 );
    }
    }
    return ( True );

    case wm_ShowWindow :
    if ( WParam ) {

    str TStr = “&Replace”;

    g_SearchMode = SearchMode;

    // Search button
    EnableWindow( GetDlgItem( Parent, id_sr_SearchBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_SearchBtn ), sw_Show );

    // Replace button
    SendMessageStr( GetDlgItem( Parent, id_sr_ReplaceBtn ), wm_SetText, 0,
    TStr );
    if ( SearchMode && g_RepSearch ) {
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), True );
    }
    else {
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), False );
    }
    ShowWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), sw_Show );

    // All button
    EnableWindow( GetDlgItem( Parent, id_sr_AllBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_AllBtn ), sw_Show );

    // Direction Switch button
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );

    // Defaults button
    EnableWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), sw_Show );
    }
    else if ( g_SrCollapsed ) {
    g_RepSearch = False;
    call _Collapse;
    }
    break;

    case wm_SysCommand :
    switch ( WParam & 0xfff0 ) {

    case sc_Maximize :
    call _Collapse;
    RetVal = 0;
    return ( 1 );

    case sc_Restore :
    RetVal = 0;
    return ( 1 );
    }
    break;

    case wm_Command :
    switch ( WParam & 0xFFFF ) {

    case dlg_WCmd_Init :
    SetFocus( GetDlgItem( Window, id_sr_SearchStr ) );
    g_SCaretPos = 0;
    g_RCaretPos = 0;
    // Subclass_With_Macro( GetWindow( GetDlgItem( Window, id_sr_SearchStr ),
    // gw_Child ), “SrchStringProc”, “/CRS=1” );
    if ( SearchMode ) {
    if ( g_RepSearch ) {
    SendMessage( Parent, dm_SetDefId, id_sr_ReplaceBtn, 0 );
    }
    else {
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), False );
    }
    }
    EnableWindow( GetDlgItem( Window, id_sr_BlockSrchCB ), BlkOn );
    if ( SearchMode ) {
    if ( XPos( “R”, Caps( g_DefReplSwitches ), 1 ) ) {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, BlkOn, 0 );
    }
    else {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, false, 0 ); //clear checkmark
    }
    }
    else {
    if ( XPos( “R”, Caps( g_DefSwitches ), 1 ) ) {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, BlkOn, 0 );
    }
    else {
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, false, 0 ); //clear checkmark
    }
    }
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );
    call _EnableColumns;
    g_SrCollapsed = 0;
    break;

    case id_sr_SearchStr :
    switch ( WParam >> 16 ) {

    case cbn_SelChange :
    case cbn_EditChange :
    g_SaveSearchStr = True;
    g_RepSearch = False;
    if ( SearchMode ) {
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), False );
    SendMessage( Parent, dm_SetDefId, id_sr_SearchBtn, 0 );
    }
    break;

    case cbn_SelEndCancel :
    g_SCaretPos = SendMessage( LParam, cb_GetEditSel, 0, 0 );
    break;
    }
    break;

    case id_sr_ReplaceStr :
    switch ( WParam >> 16 ) {

    case cbn_SelChange :
    case cbn_EditChange :
    g_SaveReplaceStr = True;
    break;

    case cbn_SelEndCancel :
    g_RCaretPos = SendMessage( LParam, cb_GetEditSel, 0, 0 );
    break;
    }
    break;

    case id_sr_List0RB :
    case id_sr_List1RB :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    g_SFindLstId = SendDlgItemMessage( Window, id_sr_List1RB, bm_GetCheck, 0, 0 );
    }
    break;

    case id_sr_ColumnsCB :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _EnableColumns;
    }
    break;

    case id_sr_GlobalSrchCB :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    if ( SendDlgItemMessage( Window, id_sr_GlobalSrchCB, bm_GetCheck, 0, 0 ) ) {
    g_RepSearch = False;
    }
    }
    break;

    // Main tab dlg buttons

    case id_sr_DirSwitchBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    Jx = SendDlgItemMessage( Window, id_sr_BackwardCB, bm_GetCheck, 0, 0 );
    call _SetDirBtn;
    if ( SearchMode ) {
    SendMessage( Parent, dm_SetDefId, id_sr_ReplaceBtn, 0 );
    }
    else {
    SendMessage( Parent, dm_SetDefId, id_sr_SearchBtn, 0 );
    }
    SetFocus( GetDlgItem( Window, id_sr_SearchStr ) );
    call _DoSearch;
    }
    break;

    case id_sr_SearchBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _DoSearch;
    }
    break;

    case id_sr_AllBtn :
    case id_sr_ReplaceBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {

    int CloseDlgFlag = False;

    SReturn_Int = 101;
    call _SetFlags;
    call _SetHistory;
    if ( ( WParam & 0xFFFF ) == id_sr_AllBtn ) {
    // if ( g_DefSearchOpts & _so_GlobalAllBtn ) {
    // g_ReplSwitches += “G”;
    // }
    if ( g_SearchMode ) {
    g_ReplSwitches += “N”;
    if ( g_DefSearchOpts & _so_GlobalAllBtn ) {
    g_ReplSwitches += “G”;
    }
    }
    else {
    g_Switches += “L”;
    if ( g_DefSearchOpts & _so_GlobalAllBtn ) {
    g_Switches += “G”;
    }
    }
    CloseDlgFlag = True;
    }
    else {
    if ( g_SearchMode ) {
    CloseDlgFlag = XPos( “P”, Caps( g_ReplSwitches ), 1 ) == 0;
    }
    else {
    CloseDlgFlag = False;
    }
    }
    if ( CloseDlgFlag ) {
    call _HideParent;
    }
    else if ( !g_SrCollapsed ) {
    call _Collapse;
    }
    call _SearchAll;
    if ( CloseDlgFlag ) {
    call _CloseParent;
    RetVal = 0;
    return ( True );
    }
    if ( ExitNoFind && ( g_FoundCount == g_ReplaceCount ) ) {
    g_FoundCount = 0;
    g_SWrapFlags |= _swf_NoMessage;
    call _CheckWrap;
    g_SWrapFlags &= ( 0xFFFFFFFF ^ _swf_NoMessage );
    if ( !g_FoundCount ) {
    call _CloseParent;
    RetVal = 0;
    return ( True );
    }
    }
    g_RepSearch = True;
    }
    break;

    case id_sr_DefaultsBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    if ( g_SrCollapsed ) {
    call _Collapse;
    }
    call _SetDefaults;
    }
    break;
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    // Internal Routines ———————————————————–

    _DoSearch:
    int SR_Prompt;
    int SavSWrapFlags;

    str OrigSwitches;

    SReturn_Int = 1;
    call _SetFlags;
    call _SetHistory;
    OrigSwitches = g_Switches;
    if ( SearchMode ) {
    g_Switches = g_ReplSwitches;
    }
    if ( SR_Prompt = XPos( “P”, Caps( g_Switches ), 1 ) ) {
    g_Switches = Str_Del( g_Switches, SR_Prompt, 1 );
    }
    if ( !g_SrCollapsed && ( SR_Prompt || SearchMode ) ) {
    call _Collapse;
    }
    g_SearchMode = False;
    if ( g_RepSearch ) {
    SavSWrapFlags = g_SWrapFlags;
    Rm( “RepSrch” );
    }
    else {

    // Set search wrap options
    SavSWrapFlags = 0;
    g_SWrapFlags = 0;
    g_SWrapWinId = Window_Id;
    g_SWrapLine = C_Line;
    g_SWrapCol = C_Col;
    // g_SWrapRow = C_Row;
    Rm( “S_And_R /L=” + Str( g_SFindLstId ) );
    }
    g_SearchMode = SearchMode;
    g_Switches = OrigSwitches;
    if ( !SR_Prompt && !SearchMode ) {

    // Destroy the dialog if not a prompted search and not in replace
    call _CloseParent;
    RetVal = 0;
    return ( True );
    }
    if ( ExitNoFind && !g_FoundCount ) {
    call _CheckWrap;
    if ( !g_FoundCount ) {

    // Destroy the dialog
    call _CloseParent;
    RetVal = 0;
    return ( True );
    }
    }
    if ( ( g_FoundCount != 0 ) && SearchMode ) {

    // Don’t enable Replace button until search
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), True );
    if ( g_SrCollapsed ) {
    SendMessage( Parent, dm_SetDefId, id_sr_ReplaceBtn, 0 );
    }
    }
    // call _CheckWrap;
    g_RepSearch = True;
    ret;

    _CheckWrap:
    if ( !g_RepSearch && ( g_DefSearchOpts & _so_AutoWrap ) && !g_FoundCount &&
    ( ( SavSWrapFlags & _swf_Wrapped ) == 0 ) ) {

    Rm( “RepSrch” );
    }
    ret;

    _Collapse:
    if ( Message != wm_ShowWindow ) {
    // SendMessage( Parent, wm_SetRedraw, False, 0);
    Lock = LockWindowUpdate( Parent );
    }
    else {
    Lock = False;
    }
    EnableFlag = g_SrCollapsed;
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), !EnableFlag );
    if ( EnableFlag ) {
    HideFlag = sw_Show;
    TStr = “”;
    SendMessageStr( GetDlgItem( Window, id_sr_DirSwitchBtn ), wm_SetText, 0,
    TStr );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );
    }
    else {
    HideFlag = sw_Hide;
    SendDlgItemMessage( Window, id_sr_SearchStr, cb_ShowDropDown, False, 0 );
    if ( g_SearchMode ) {
    SendDlgItemMessage( Window, id_sr_ReplaceStr, cb_ShowDropDown, False, 0 );
    if ( IsWindowEnabled( GetDlgItem( Window, id_sr_ReplaceBtn ) ) ) {
    SendMessage( Parent, dm_SetDefId, id_sr_ReplaceBtn, 0 );
    }
    }
    Jx = !SendDlgItemMessage( Window, id_sr_BackwardCB, bm_GetCheck, 0, 0 );
    call _SetDirBtn;
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Show );
    SetFocus( GetDlgItem( Window, id_sr_SearchStr ) );
    }
    EnableWindow( GetDlgItem( Window, id_sr_TypeGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_TypeGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_LiteralRB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_LiteralRB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_RegExpRB), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_RegExpRB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_WordSrchRB), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_WordSrchRB ), HideFlag );

    // Mode group
    EnableWindow( GetDlgItem( Window, id_sr_ModeGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_ModeGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_PromptSrchCB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_PromptSrchCB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_ExitNoFindCB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_ExitNoFindCB ), HideFlag );

    // Columns group
    Jx = SendDlgItemMessage( Window, id_sr_ColumnsCB, bm_GetCheck, 0, 0 );
    if ( !EnableFlag ) {
    Jx = False;
    }
    EnableWindow( GetDlgItem( Window, id_sr_ColumnsCB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_ColumnsCB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_BegCol ), Jx );
    ShowWindow( GetDlgItem( Window, id_sr_BegCol ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_EndCol ), Jx );
    ShowWindow( GetDlgItem( Window, id_sr_EndCol ), HideFlag );

    // Find list group
    EnableWindow( GetDlgItem( Window, id_sr_UseLstGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_UseLstGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_List0RB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_List0RB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_List1RB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_List1RB ), HideFlag );

    // Option group
    EnableWindow( GetDlgItem( Window, id_sr_OptionGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_OptionGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_BackwardCB), EnableFlag);
    ShowWindow( GetDlgItem( Window, id_sr_BackwardCB ), HideFlag );

    EnableWindow( GetDlgItem (Window, id_sr_GlobalSrchCB), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_GlobalSrchCB ), HideFlag );

    EnableWindow( GetDlgItem (Window, id_sr_CaseCB), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_CaseCB ), HideFlag );

    if ( EnableFlag ) {
    Jx = BlkOn;
    }
    else {
    Jx = False;
    }
    EnableWindow( GetDlgItem( Window, id_sr_BlockSrchCB ), Jx );
    ShowWindow( GetDlgItem( Window, id_sr_BlockSrchCB ), HideFlag );

    EnableWindow( GetDlgItem (Window, id_sr_AllWindowsCB), EnableFlag);
    ShowWindow( GetDlgItem( Window, id_sr_AllWindowsCB ), HideFlag );

    if ( SearchMode ) {
    EnableWindow( GetDlgItem( Window, id_sr_PosBegStrCB ), EnableFlag);
    ShowWindow( GetDlgItem( Window, id_sr_PosBegStrCB ), HideFlag);
    }
    else {
    EnableWindow( GetDlgItem( Window, id_sr_MarkFndTxtCB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_MarkFndTxtCB ), HideFlag );
    }

    EnableWindow( GetDlgItem( Window, id_sr_AliasBtn ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_AliasBtn ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_RegExpHlpBtn ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_RegExpHlpBtn ), HideFlag );

    struct TRect Rect;
    struct TPoint PParent;
    struct TPoint PTab;
    struct TPoint PWin;

    int Bottom;
    int HeightDiff;
    int CtrlWin;

    // Get resize location
    GetWindowRect( GetDlgItem( Window, id_sr_TypeGrp ), &Rect );
    Bottom = Rect.Top;

    // Get Parent window size
    GetWindowRect( Parent, &Rect );
    PParent.X = Rect.Right – Rect.Left;
    PParent.Y = Rect.Bottom – Rect.Top;

    // Get Search dialog window size
    GetWindowRect( Window, &Rect );
    PWin.X = Rect.Right – Rect.Left;
    PWin.Y = PParent.Y – ( Rect.Bottom – Rect.Top );

    // Get Tab ctrl window size
    GetWindowRect( GetDlgItem( Parent, id_st_TabBar ), &Rect );
    PTab.X = Rect.Right – Rect.Left;
    PTab.Y = PParent.Y – ( Rect.Bottom – Rect.Top );

    if ( EnableFlag ) {
    HeightDiff = -g_SrCollapsed;
    g_SrCollapsed = 0;
    }
    else {
    HeightDiff = Rect.Bottom – Bottom – 6;
    g_SrCollapsed = HeightDiff;
    }

    // Resize Search dialog
    SetWindowPos( Window, 0,
    0, 0,
    PWin.X, PParent.Y – PWin.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    // Resize TabBar control
    SetWindowPos( GetDlgItem( Parent, id_st_TabBar ), 0,
    0, 0,
    PTab.X, PParent.Y – PTab.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    // Move Search button
    CtrlWin = GetDlgItem( Parent, id_sr_SearchBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Replace button
    CtrlWin = GetDlgItem( Parent, id_sr_ReplaceBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move All button
    CtrlWin = GetDlgItem( Parent, id_sr_AllBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Direction switch button
    CtrlWin = GetDlgItem( Parent, id_sr_DirSwitchBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Defaults button
    CtrlWin = GetDlgItem( Parent, id_sr_DefaultsBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Cancel button
    CtrlWin = GetDlgItem( Parent, id_std_Close );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Help button
    CtrlWin = GetDlgItem( Parent, id_std_Help );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    if ( Message != wm_ShowWindow ) {
    // SendMessage( Parent, wm_SetRedraw, True, 0 ); // turn refresh of dialog back on
    if ( Lock ) {
    LockWindowUpdate( 0 );
    }
    }

    // Resize SearchTab dialog
    SetWindowPos( Parent, 0, 0, 0, PParent.X, PParent.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    if ( Message != wm_ShowWindow ) {
    RedrawWindow( Parent, 0, 0, rdw_Invalidate | rdw_Erase | rdw_UpdateNow );
    }
    ret;

    _SetFlags:

    // Simply sets the flags depending on what is selected in the dialog
    // Sets value for search str
    GetWindowText( GetDlgItem( Window, id_sr_SearchStr ), TStr, 256 );
    g_SearchStr = TStr;
    g_SaveSearchStr = False;
    if ( g_SearchMode ) {

    // Sets value for replace str
    GetWindowText( GetDlgItem( Window, id_sr_ReplaceStr ), TStr, 256 );
    g_ReplaceStr = TStr;
    g_SaveReplaceStr = False;
    }

    // Set the begin column restrict global
    GetWindowText( GetDlgItem( Window, id_sr_BegCol ), TStr, 256 );
    Val( Jx, TStr );
    g_SearchColBeg = Jx;

    // Set the end column restrict global
    GetWindowText( GetDlgItem( Window, id_sr_EndCol ), TStr, 256 );
    Val( Jx, TStr );
    g_SearchColEnd = Jx;

    TStr = “”;
    if ( !SendDlgItemMessage( Window, id_sr_RegExpRB, bm_GetCheck, 0, 0 ) ) {
    TStr += “X”;
    }
    if ( SendDlgItemMessage( Window, id_sr_WordSrchRB, bm_GetCheck, 0, 0 ) ) {
    TStr += “W”;
    }
    if ( SendDlgItemMessage( Window, id_sr_PromptSrchCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “P”;
    }
    if ( SendDlgItemMessage( Window, id_sr_ExitNoFindCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “K”;
    ExitNoFind = True;
    }
    else {
    ExitNoFind = False;
    }
    if ( SendDlgItemMessage( Window, id_sr_ColumnsCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “O”;
    }
    if ( SendDlgItemMessage( Window, id_sr_BackwardCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “B”;
    }
    if ( SendDlgItemMessage( Window, id_sr_CaseCB, bm_GetCheck, 0, 0 ) == 0 ) {
    TStr += “I”;
    }
    if ( SendDlgItemMessage( Window, id_sr_GlobalSrchCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “G”;
    }
    if ( SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_GetCheck, 0, 0 ) ) {
    if ( Block_Stat > 0 ) {
    TStr += “R”;
    }
    }
    if ( SendDlgItemMessage( Window, id_sr_AllWindowsCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “A”;
    }
    if ( g_SearchMode ) {

    // These options only appear on search and replace
    if ( SendDlgItemMessage( Window, id_sr_PosBegStrCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “C”;
    }
    g_ReplSwitches = TStr;
    }
    else {
    if ( SendDlgItemMessage( Window, id_sr_MarkFndTxtCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “M”;
    }
    g_Switches = TStr;
    }
    ret; // _SetFlags

    _SetDirBtn:
    SendDlgItemMessage( Window, id_sr_BackwardCB, bm_SetCheck, !Jx, 0 );
    if ( Jx ) {
    TStr = “B&wd”;
    }
    else {
    TStr = “F&wd”;
    }
    SendMessageStr( GetDlgItem( Parent, id_sr_DirSwitchBtn ), wm_SetText, 0, TStr );
    ret; // _SetDirBtn

    _SetHistory:

    // add items to history list
    Return_Str = g_SearchStr;
    Rm( “History_List /M=1/HISTORY=SEARCH_HISTORY” );
    if ( g_SearchMode ) {

    // add items to history list
    Return_Str = g_ReplaceStr;
    Rm( “History_List /M=1/HISTORY=REPLACE_HISTORY” );
    }
    ret;

    _SearchAll:
    Rm( “S_And_R /L=” + Str( g_SFindLstId ) );
    if ( g_FoundCount == g_ReplaceCount ) {
    TStr = “No more occurrences.”;
    if ( g_SearchMode ) {
    TStr += ” ” + Str( g_ReplaceCount ) + ” replacement(s).”;
    }
    Make_Message( TStr );
    }
    ret;

    _EnableColumns: // // Enable/Disable the column fields
    Jx = SendDlgItemMessage( Window, id_sr_ColumnsCB, bm_GetCheck, 0, 0 );
    EnableWindow( GetDlgItem( Window, id_sr_BegColLbl ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_BegCol ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_EndColLbl ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_EndCol ), Jx );
    ret;

    _HideParent: // Hide parent dialog
    ShowWindow( Parent, sw_Hide );
    ret;

    _CloseParent: // Close parent dialog
    // read_key;
    // Next line added (9/15/15) for Win 10 Workaround
    PostMessage( Parent, wm_SysCommand, sc_Close, 0 );
    PostMessage( Parent, wm_SysCommand, sc_Close, 0 );
    ret;

    _SetDefaults:

    // Reset the options to the defaults
    if ( g_SearchMode ) {
    TStr = g_DefReplSwitches;
    Jx = XPos( “C”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_PosBegStrCB, bm_SetCheck, Jx, 0 );
    }
    else {
    TStr = g_DefSwitches;
    Jx = XPos( “M”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_MarkFndTxtCB, bm_SetCheck, Jx, 0 );
    }
    Jx = XPos( “X”, TStr, 1 ) == 0;
    SendDlgItemMessage( Window, id_sr_RegExpRB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “W”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_WordSrchRB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “X”, TStr, 1 ) && !Jx;
    SendDlgItemMessage( Window, id_sr_LiteralRB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “P”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_PromptSrchCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “K”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_ExitNoFindCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “O”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_ColumnsCB, bm_SetCheck, Jx, 0 );

    Jx = g_DefSearchColBeg;
    SetWindowText( GetDlgItem( Window, id_sr_BegCol ), Str( Jx ) );

    Jx = g_DefSearchColEnd;
    SetWindowText( GetDlgItem( Window, id_sr_EndCol ), Str( Jx ) );
    call _EnableColumns;

    Jx = XPos( “B”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_BackwardCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “I”, TStr, 1 ) == 0;
    SendDlgItemMessage( Window, id_sr_CaseCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “G”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_GlobalSrchCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “R”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_BlockSrchCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “A”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_AllWindowsCB, bm_SetCheck, Jx, 0 );
    ret;

    } // _SearchDlgProc

    void _FileSearchDlg(
    int M = Parse_Int( “/M=”, MParm_Str ),
    int Dlg = Parse_Int( “/DLG=”, MParm_Str ),
    int Result = Parse_Int( “/RES=”, MParm_Str ),
    int SetupOnly = Parse_Int( “/SETUP=”, MParm_Str )
    ) trans2
    {
    TTRACE_ENTER( “Search”, TDBG_Trace, “_FileSearchDlg(%d, %d, %x)”, M, Dlg, SetupOnly );

    int SearchMode = g_SearchMode;

    str GSwitches = Parse_Str( “/SWG=”, MParm_Str );
    str GSearchStr = Parse_Str( “/SRG=”, MParm_Str );
    str GReplaceStr = Parse_Str( “/RPG=”, MParm_Str );
    str GFileSpec = Parse_Str( “/FSG=”, MParm_Str );
    str GSearchPath = Parse_Str( “/SPG=”, MParm_Str );

    if ( XPos( “/SM=”, MParm_Str, 1 ) ) {
    SearchMode = Parse_Int( “/SM=”, MParm_Str );
    }
    if ( Svl( GSwitches ) == 0 ) {
    if ( SetupOnly ) {
    if ( SearchMode ) {
    GSwitches = _g_DefFRSwitches;
    }
    else {
    GSwitches = _g_DefFSSwitches;
    }
    }
    else {
    if ( SearchMode ) {
    GSwitches = _g_FRSwitches;
    }
    else {
    GSwitches = _g_FSwitches;
    }
    }
    }
    if ( !SetupOnly ) {
    if ( Svl( GSearchStr ) == 0 ) {
    GSearchStr = _g_SearchStr;
    }
    if ( Svl( GReplaceStr ) == 0 ) {
    GReplaceStr = _g_ReplaceStr;
    }
    if ( Svl( GFileSpec ) == 0 ) {
    if ( SearchMode ) {
    GFileSpec = _g_FRFileSpec;
    }
    else {
    GFileSpec = _g_FFileSpec;
    }
    }
    }
    if ( Svl( GSearchPath ) == 0 ) {
    if ( SetupOnly ) {
    if ( SearchMode ) {
    GSearchPath = _g_DefFRSearchPath;
    }
    else {
    GSearchPath = _g_DefFSearchPath;
    }
    }
    else {
    if ( SearchMode ) {
    GSearchPath = _g_FRSearchPath;
    }
    else {
    GSearchPath = _g_FSearchPath;
    }
    }
    }
    switch ( M ) {

    case 1 :
    call _BuildCtrls;
    break;

    case 2 :
    call _EndDlg;
    break;
    }
    TTRACE_LEAVE( “_FileSearchDlg()” );
    return ( );

    // Internal Routines ———————————————————–

    _BuildCtrls:

    int StrWidth = 57;
    int X;
    int Y;
    int RegExp;
    int IgnoreCase;
    int SearchDirs;
    int LeaveOpen;
    int ShowAllFind;
    int Project;
    int ArchiveAttr;
    int ReadOnlyAttr;
    int HiddenAttr;
    int SystemAttr;

    str Bitmap;
    str HelpContext = Parse_Str( “/H=”, MParm_Str );

    if ( Svl( HelpContext ) == 0 ) {
    if ( SetupOnly ) {
    if ( SearchMode ) {
    HelpContext = hc_FileReplaceDef;
    }
    else {
    HelpContext = hc_FileFindDef;
    }
    }
    else {
    if ( SearchMode ) {
    HelpContext = hc_FileReplace;
    }
    else {
    HelpContext = hc_FileFind;
    }
    }
    }
    call _SetCtrls;

    X = 1;
    Y = dlg_Units;
    int sPathBtnY = 3;

    // *indent-off*
    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_Static, “Sear&ch for:”,
    X, Y,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GSearchStr ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_SearchStr, 0, “/ML=256/HISTORY=Search_History/SHOWH0=” +
    Str( g_DefSearchOpts & _so_ShowHis0 ) );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, Dlg_Static, “Re&place with:”,
    X, dlg_PosOffset + 1,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GReplaceStr ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_ReplaceStr, 0, “/ML=256/HISTORY=Replace_History” );

    sPathBtnY++; // inc. search path button y coord.
    }
    DlgAddCtrl( Dlg, dlg_Static, “&Filespec:”,
    X, dlg_PosOffset + 1,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GFileSpec ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_FileSpecStr, 0, “/ML=260/HISTORY=Filespec_History” );

    X = dlg_NegOffset + 14;
    Y = dlg_PosOffset + 1;
    }
    DlgAddCtrl( Dlg, dlg_Static, “Starting &path:”,
    X, Y,
    0, 0,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_Text, Global_Str( GSearchPath ),
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_PathStr, 0, “/ML=260/HISTORY=FSPath_History” );

    // Place reg. exp. menus here to adjust tab order —————————-
    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_BitmapBtn, “LARROW”,
    dlg_Units | 289, 1,
    dlg_Units + 11, dlg_Units + 9,
    id_sr_SrchRegExBtn, 0,
    “/M=FindShowRegExMenu /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=2” );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, dlg_BitmapBtn, “LARROW”,
    dlg_Units | 289, 2,
    dlg_Units + 11, DLG_units + 9,
    id_sr_RepRegExBtn, 0,
    “/M=FindShowRegExMenu /ID=” + Str( id_sr_ReplaceStr ) + “/FLAGS=6” );
    }
    DlgAddCtrl( Dlg, dlg_DirButton, “…”,
    dlg_Units | 289, SPathBtnY,
    4, 0,
    id_sr_DirBtn, 0, “/SID=” + Str( id_sr_PathStr ) );
    }

    DlgAddCtrl( Dlg, dlg_Groupbox, “Options”,
    1, dlg_PosOffset + 1,
    #ifdef __Project_sh__
    31, 6,
    #else
    31, 5,
    #endif
    id_sr_OptionGrp, 0, “” );

    DlgAddCtrl( Dlg, Dlg_Checkbox, “Regular &expressions”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_RegExpCB, 0, “” );
    DlgSetInt( Dlg, id_sr_RegExpCB, RegExp );

    DlgAddCtrl( Dlg, Dlg_Checkbox, “Case sensiti&ve”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_CaseCB, 0, “” );
    DlgSetInt( Dlg, id_sr_CaseCB, IgnoreCase );

    DlgAddCtrl( Dlg, dlg_Checkbox, “Search sub-&directories”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_SearchDirCB, 0, “” );
    DlgSetInt( Dlg, id_sr_SearchDirCB, SearchDirs );

    if ( SearchMode ) {
    DlgAddCtrl( Dlg, Dlg_Checkbox, “&Leave all files open”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_LeaveOpenCB, 0, “” );
    DlgSetInt( Dlg, id_sr_LeaveOpenCB, LeaveOpen );
    }
    else {
    DlgAddCtrl( Dlg, dlg_Checkbox, “&List all occurrences”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_ShowAllCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ShowAllCB, ShowAllFind );
    }

    #ifdef __Project_sh__
    DlgAddCtrl( Dlg, dlg_CheckBox, “Limit search to pro&ject list”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_ProjectSrchCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ProjectSrchCB, Project );
    #endif

    DlgAddCtrl( Dlg, dlg_GroupBox, “Find List”,
    1, dlg_PosOffset + 1,
    16, 2,
    id_sr_UseLstGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_RadioButton, “&0”,
    dlg_PosOffset + 1, dlg_PosOffset | dlg_Units | 10,
    0, 0,
    id_sr_List0RB, 0, “” );
    DlgSetInt( Dlg, id_sr_List0RB, g_FFindLstId == 0 );

    DlgAddCtrl( Dlg, dlg_RadioButton, “&1”,
    dlg_PosOffset | dlg_Units | 30, dlg_PosOffset + 0,
    0, 0,
    id_sr_List1RB, 0, “” );
    DlgSetInt( Dlg, id_sr_List1RB, g_FFindLstId == 1 );

    DlgGetXY( Dlg, id_sr_OptionGrp, X, Y );
    DlgAddCtrl( Dlg, dlg_Groupbox, “Attributes”,
    34, Y | dlg_Units,
    38, 3,
    id_sr_AttributeGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_3State, “&Archive”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_ArchiveCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ArchiveCB, ArchiveAttr );

    DlgAddCtrl( Dlg, dlg_3State, “&Hidden”,
    dlg_PosOffset + 15, dlg_PosOffset,
    0, 0,
    id_sr_HIddenCB, 0, “” );
    DlgSetInt( Dlg, id_sr_HiddenCB, HiddenAttr );

    DlgAddCtrl( Dlg, dlg_3State, “&Read-Only”,
    dlg_NegOffset + 15, dlg_PosOffset + 1,
    0, 0,
    id_sr_ReadOnlyCB, 0, “” );
    DlgSetInt( Dlg, id_sr_ReadOnlyCB, ReadOnlyAttr );

    DlgAddCtrl( Dlg, dlg_3State, “S&ystem”,
    dlg_PosOffset + 15, dlg_PosOffset,
    0, 0,
    id_sr_SystemCB, 0, “” );
    DlgSetInt( Dlg, id_sr_SystemCB, SystemAttr );

    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_PushButton, “Al&ias”,
    _stab_Width – 33, dlg_Units | ( ( ( _stab_Height – 3 ) * 12 ) + 3 ),
    dlg_StanBtnWidth, 0,
    id_sr_AliasBtn, 0,
    “/M=SearchGetAlias /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=2” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Reg Ex &Help”,
    dlg_PosOffset | dlg_StanBtnWidth + 2, dlg_PosOffset,
    dlg_StanBtnWidth + 4, 0,
    id_sr_RegExpHlpBtn, 0,
    “/M=Help^RegExpHelp” );
    }
    Return_Str = “/H=” + HelpContext;
    if ( !SetupOnly ) {
    Return_Str = “/H=” + HelpContext +
    “/HOOK=_FileSearchDlgProc //SM=” + Str( SearchMode );
    }
    // *indent-on*
    ret;

    _EndDlg:
    if ( !SetupOnly ) {
    Result = True; // Always save settings
    }
    if ( Result ) {

    str Switches[ 40 ] = “”;

    if ( DlgGetInt( Dlg, id_sr_RegExpCB ) == 0 ) {
    Switches += “X”;
    }
    if ( DlgGetInt( Dlg, id_sr_CaseCB ) == 0 ) {
    Switches += “I”;
    }
    if ( DlgGetInt( Dlg, id_sr_SearchDirCB ) != 0 ) {
    Switches += “S”;
    }
    #ifdef __Project_sh__
    if ( DlgGetInt( Dlg, id_sr_ProjectSrchCB ) != 0 ) {
    Switches += “J”;
    }
    #endif
    if ( SearchMode ) {
    if ( DlgGetInt( Dlg, id_sr_LeaveOpenCB ) != 0 ) {
    Switches += “O”;
    }
    }
    else {
    if ( DlgGetInt( Dlg, id_sr_ShowAllCB ) != 0 ) {
    Switches += “L”;
    }
    }
    switch ( DlgGetInt( Dlg, id_sr_ArchiveCB ) ) {

    case 0 :
    Switches += “-1”;
    break;

    case 1 :
    Switches += “+1”;
    break;
    }
    switch ( DlgGetInt( Dlg, id_sr_HiddenCB ) ) {

    case 0 :
    Switches += “-2”;
    break;

    case 1 :
    Switches += “+2”;
    break;
    }
    switch ( DlgGetInt( Dlg, id_sr_ReadOnlyCB ) ) {

    case 0 :
    Switches += “-3”;
    break;

    case 1 :
    Switches += “+3”;
    break;
    }
    switch ( DlgGetInt( Dlg, id_sr_SystemCB ) ) {

    case 0 :
    Switches += “-4”;
    break;

    case 1 :
    Switches += “+4”;
    break;
    }
    Set_Global_Str( GSwitches, Switches );

    Return_Str = DlgGetStr( Dlg, id_sr_PathStr );
    Set_Global_Str( GSearchPath, Return_Str );
    g_FFindLstId = DlgGetInt( Dlg, id_sr_List1RB );

    if ( !SetupOnly ) {

    // Add search path to history list
    Rm( “History_List /M=1/HISTORY=FSPath_History” );
    if ( g_SaveSearchStr ) {

    // Save Search str and add to history list
    Return_Str = DlgGetStr( Dlg, id_sr_SearchStr );
    Set_Global_Str( GSearchStr, Return_Str );
    Rm( “History_List /M=1/HISTORY=Search_History” );
    g_SaveSearchStr = False;
    }
    if ( SearchMode && g_SaveReplaceStr ) {

    // Save Replace str and add to history list
    Return_Str = DlgGetStr( Dlg, id_sr_ReplaceStr );
    Set_Global_Str( GReplaceStr, Return_Str );
    Rm( “History_List /M=1/HISTORY=Replace_History” );
    g_SaveReplaceStr = False;
    }

    // Save filespec str and add to history list
    Return_Str = DlgGetStr( Dlg, id_sr_FileSpecStr );
    Set_Global_Str( GFileSpec, Return_Str );
    Rm( “History_List /M=1/HISTORY=FileSpec_History” );
    }
    }
    ret;

    _SetCtrls:

    str Switches[ 40 ] = Global_Str( GSwitches );

    RegExp = XPos( “X”, Switches, 1 ) == 0;
    IgnoreCase = XPos( “I”, Switches, 1 ) == 0;
    SearchDirs = XPos( “S”, Switches, 1 ) != 0;
    #ifdef __Project_sh__
    Project = XPos( “J”, Switches, 1 ) != 0;
    #endif
    if ( SearchMode ) {
    LeaveOpen = XPos( “O”, Switches, 1 ) != 0;
    }
    else {
    ShowAllFind = XPos( “L”, Switches, 1 ) != 0;
    }
    ArchiveAttr = 2;
    if ( XPos( “+1”, Switches, 1 ) ) {
    ArchiveAttr = 1;
    }
    else if ( XPos( “-1”, Switches, 1 ) ) {
    ArchiveAttr = 0;
    }
    HiddenAttr = 2;
    if ( XPos( “+2”, Switches, 1 ) ) {
    HiddenAttr = 1;
    }
    else if ( XPos( “-2”, Switches, 1 ) ) {
    HiddenAttr = 0;
    }
    ReadOnlyAttr = 2;
    if ( XPos( “+3”, Switches, 1 ) ) {
    ReadOnlyAttr = 1;
    }
    else if ( XPos( “-3”, Switches, 1 ) ) {
    ReadOnlyAttr = 0;
    }
    SystemAttr = 2;
    if ( XPos( “+4”, Switches, 1 ) ) {
    SystemAttr = 1;
    }
    else if ( XPos( “-4”, Switches, 1 ) ) {
    SystemAttr = 0;
    }
    ret;

    } // _FileSearchDlg

    int _FileSearchDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    int SearchMode = Parse_Int( “/SM=”, Parms );
    int Parent = GetParent( Window );

    #ifdef __Project_sh__
    int InProject = !ProjectIsClosed;
    #endif

    int EnableFlag;
    int HideFlag;
    int Jx;

    str TStr;
    str GFileSpec;

    switch ( Message ) {

    case wm_Activate :
    if ( ( WParam & 0xFFFF ) != wa_Inactive ) {
    SetSearchHistory( “”, True, Window, id_sr_SearchStr );

    #ifdef __Project_sh__
    EnableWindow( GetDlgItem( Window, id_sr_ProjectSrchCB ), InProject );
    if ( InProject ) {
    call _EnableProject;
    }
    #endif
    }
    break;

    case wm_ShowWindow :
    if ( WParam ) {

    int Parent = GetParent( Window );

    // Search button
    EnableWindow( GetDlgItem( Parent, id_sr_SearchBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_SearchBtn ), sw_Show );

    // Replace button
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), sw_Hide );

    // All button
    EnableWindow( GetDlgItem( Parent, id_sr_AllBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_AllBtn ), sw_Hide );

    // Direction Switch button
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );

    // Defaults button
    EnableWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), sw_Show );
    }
    break;

    case wm_SysCommand :
    switch ( WParam & 0xFFF0 ) {

    case sc_Maximize :
    RetVal = 0;
    return ( 1 );

    case sc_Restore :
    RetVal = 0;
    return ( 1 );
    }
    break;

    case wm_Command :
    switch ( WParam & 0xFFFF ) {

    case dlg_WCmd_Init :
    g_SCaretPos = 0;
    g_RCaretPos = 0;
    SetFocus( GetDlgItem( Window, id_sr_SearchStr ) );
    #ifdef __Project_sh__
    EnableWindow( GetDlgItem( Window, id_sr_ProjectSrchCB ), InProject );
    if ( InProject ) {
    call _EnableProject;
    }
    #endif
    break;

    case id_sr_SearchStr :
    switch ( WParam >> 16 ) {

    case cbn_SelChange :
    case cbn_EditChange :
    g_SaveSearchStr = True;
    break;

    case cbn_SelEndCancel :
    g_SCaretPos = SendMessage( LParam, cb_GetEditSel, 0, 0 );
    break;
    }
    break;

    case id_sr_List0RB :
    case id_sr_List1RB :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    g_FFindLstId = SendDlgItemMessage( Window, id_sr_List1RB, bm_GetCheck, 0, 0 );
    }
    break;

    case id_sr_ReplaceStr :
    switch ( WParam >> 16 ) {

    case cbn_SelChange :
    case cbn_EditChange :
    g_SaveReplaceStr = True;
    break;

    case cbn_SelEndCancel :
    g_RCaretPos = SendMessage( LParam, cb_GetEditSel, 0, 0 );
    break;
    }
    break;

    #ifdef __Project_sh__
    case id_sr_ProjectSrchCB :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _EnableProject;
    }
    break;
    #endif

    case id_sr_SearchBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _SetFlags;

    #ifdef __Project_sh__
    if ( InProject && XPos( “J”, TStr, 1 ) ) {
    TStr = Global_Str( GFileSpec );
    if ( Svl( TStr ) == 0 ) {
    TStr = “*.*”;
    }

    // Search project file list
    Return_Int = ProjectFileList( 1, TStr, _prjp_NoneMask );
    }
    else {
    Return_Int = 0;
    }
    #else
    Return_Int = 0;
    #endif
    call _HideParent;
    Rm( “FS /BD=1/M=” + Str( SearchMode ) + “/FL=” + Str( Return_Int ) + “/L=” + Str( g_FFindLstId ) );
    call _CloseParent;
    RetVal = 0;
    return ( True );
    }
    break;

    case id_sr_DefaultsBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _SetDefaults;
    }
    break;
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    // Internal Routines ———————————————————–

    _SetFlags:

    str GSearchPath;
    str GSwitches;

    // Set value for search str
    GetWindowText( GetDlgItem( Window, id_sr_SearchStr ), TStr, 256 );
    g_SearchStr = TStr;
    g_SaveSearchStr = False;
    if ( SearchMode ) {

    // Set value for replace str
    GetWindowText( GetDlgItem( Window, id_sr_ReplaceStr ), TStr, 256 );
    g_ReplaceStr = TStr;
    g_SaveReplaceStr = False;
    GFileSpec = _g_FRFileSpec;
    GSearchPath = _g_FRSearchPath;
    GSwitches = _g_FRSwitches;
    }
    else {
    GFileSpec = _g_FFileSpec;
    GSearchPath = _g_FSearchPath;
    GSwitches = _g_FSwitches;
    }

    // Set value for search path str
    GetWindowText( GetDlgItem( Window, id_sr_PathStr ), TStr, 256 );
    Set_Global_Str( GSearchPath, TStr );

    // Set value for filespec str
    GetWindowText( GetDlgItem( Window, id_sr_FileSpecStr ), TStr, 256 );
    Set_Global_Str( GFileSpec, TStr );

    TStr = “”;
    if ( !SenddlgItemMessage( Window, id_sr_RegExpCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “X”;
    }
    if ( !SendDlgItemMessage( Window, id_sr_CaseCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “I”;
    }
    if ( SendDlgItemMessage( Window, id_sr_SearchDirCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “S”;
    }
    if ( SendDlgItemMessage( Window, id_sr_ProjectSrchCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “J”;
    }
    if ( SearchMode ) {
    if ( SendDlgItemMessage( Window, id_sr_LeaveOpenCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “O”;
    }
    }
    else {
    if ( SendDlgItemMessage( Window, id_sr_ShowAllCB, bm_GetCheck, 0, 0 ) ) {
    TStr += “L”;
    }
    }
    switch ( SendDlgItemMessage( Window, id_sr_ArchiveCB, bm_GetCheck, 0, 0 ) ) {

    case 0 : // bst_Unchecked
    TStr += “-1”;
    break;

    case 1 : // bst_Checked
    TStr += “+1”;
    break;
    }
    switch ( SendDlgItemMessage( Window, id_sr_HiddenCB, bm_GetCheck, 0, 0 ) ) {

    case 0 :
    TStr += “-2”;
    break;

    case 1 :
    TStr += “+2”;
    break;
    }
    switch ( SendDlgItemMessage( Window, id_sr_ReadOnlyCB, bm_GetCheck, 0, 0 ) ) {

    case 0 :
    TStr += “-3”;
    break;

    case 1 :
    TStr += “+3”;
    break;
    }
    switch ( SendDlgItemMessage( Window, id_sr_SystemCB, bm_GetCheck, 0, 0 ) ) {

    case 0 :
    TStr += “-4”;
    break;

    case 1 :
    TStr += “+4”;
    break;
    }
    Set_Global_Str( GSwitches, TStr );
    ret;

    _HideParent: // Hide parent dialog
    ShowWindow( Parent, sw_Hide );
    ret;

    _CloseParent: // Close parent dialog
    PostMessage( Parent, wm_SysCommand, sc_Close, 0 );
    ret;

    _SetDefaults:

    // Reset the options to the defaults
    if ( SearchMode ) {
    TStr = g_DefFrSearchPath;
    SetWindowText( GetdlgItem( Window, id_sr_PathStr ), TStr );
    TStr = g_DefFrSwitches;
    Jx = XPos( “O”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_LeaveOpenCB, bm_SetCheck, Jx, 0 );
    }
    else {
    TStr = g_DefFSearchPath;
    SetWindowText( GetdlgItem( Window, id_sr_PathStr ), TStr );
    TStr = g_DefFsSwitches;
    Jx = XPos( “L”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_ShowallCB, bm_SetCheck, Jx, 0 );
    }
    Jx = XPos( “X”, TStr, 1 ) == 0;
    SendDlgItemMessage( Window, id_sr_RegExpCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “I”, TStr, 1 ) == 0;
    SendDlgItemMessage( Window, id_sr_CaseCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “S”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_SearchDirCB, bm_SetCheck, Jx, 0 );

    Jx = XPos( “J”, TStr, 1 );
    SendDlgItemMessage( Window, id_sr_ProjectSrchCB, bm_SetCheck, Jx, 0 );

    Jx = 2;
    if ( XPos( “+1”, TStr, 1 ) ) {
    Jx = 1;
    }
    else if ( XPos( “-1”, TStr, 1 ) ) {
    Jx = 0;
    }
    SendDlgItemMessage( Window, id_sr_ArchiveCB, bm_SetCheck, Jx, 0 );

    Jx = 2;
    if ( XPos( “+2”, TStr, 1 ) ) {
    Jx = 1;
    }
    else if ( XPos( “-2”, TStr, 1 ) ) {
    Jx = 0;
    }
    SendDlgItemMessage( Window, id_sr_HiddenCB, bm_SetCheck, Jx, 0 );

    Jx = 2;
    if ( XPos( “+3”, TStr, 1 ) ) {
    Jx = 1;
    }
    else if ( XPos( “-3”, TStr, 1 ) ) {
    Jx = 0;
    }
    SendDlgItemMessage( Window, id_sr_ReadOnlyCB, bm_SetCheck, Jx, 0 );

    Jx = 2;
    if ( XPos( “+4”, TStr, 1 ) ) {
    Jx = 1;
    }
    else if ( XPos( “-4”, TStr, 1 ) ) {
    Jx = 0;
    }
    SendDlgItemMessage( Window, id_sr_SystemCB, bm_SetCheck, Jx, 0 );
    ret;

    #ifdef __Project_sh__

    _EnableProject:

    // Enable/Disable the fields not used by Search Project option
    Jx = !SendDlgItemMessage( Window, id_sr_ProjectSrchCB, bm_GetCheck, 0, 0 );
    // EnableWindow( GetDlgItem( Window, id_sr_FileSpecStr ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_PathStr ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_DirBtn ), Jx );
    EnableWindow( GetDlgItem( Window, id_sr_SearchDirCB ), Jx );
    ret;
    #endif

    } // _FileSearchDlgProc

    /*——————————————————————————

    Function: Called by the SearchTab macro to display the Global Expression
    Highlighting dialog.

    Entry : /SETUP=1 – Set True to only show the customize fields
    Author : Dan Hughes

    ——————————————————————–( ldh )–*/
    void _GHighlightDlg(
    int M = Parse_Int( “/M=”, MParm_Str ),
    int Dlg = Parse_Int( “/DLG=”, MParm_Str ),
    int Result = Parse_Int( “/RES=”, MParm_Str ),
    int SetupOnly = Parse_Int( “/SETUP=”, MParm_Str )
    ) trans2
    {
    TTRACE_ENTER( “Search”, TDBG_Trace, “_GHighlightDlg(%d, %d, %d, %d)”, M, Dlg, Result, SetupOnly );

    str GFlags;

    if ( SetupOnly ) {
    GFlags = _g_DefHiliteFlags;
    }
    else {
    GFlags = _g_HighlightFlags;
    }
    switch ( M ) {

    case 1 :
    call _BuildCtrls;
    break;

    case 2 :
    call _EndDlg;
    break;
    }
    TTRACE_LEAVE( “_GHighlightDlg()” );
    return ( );

    // Internal Routines ———————————————————–

    _BuildCtrls:

    int SearchFlags = Global_Int( GFlags );
    int Prompted = SearchFlags & 0x10;
    int StrWidth = 57;
    int X;
    int Y;

    str SearchStr = g_SearchStr;
    str TStr;
    str HelpContext = Parse_Str( “/H=”, MParm_Str );

    if ( Svl( HelpContext ) == 0 ) {
    HelpContext = hc_GEHighlight;
    }
    if ( !SearchFlags ) {
    SearchFlags = 0x80000000;
    TStr = g_DefSwitches;
    if ( !XPos( “I”, TStr, 1 ) ) {
    SearchFlags |= 1;
    }
    if ( !XPos( “X”, TStr, 1 ) ) {
    SearchFlags |= 6;
    }
    }

    X = 1;
    Y = dlg_Units;

    // *indent-on*
    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_Static, “Hi&ghlight:”,
    X, Y,
    0, 0,
    -1, 0, “” );
    DlgAddCtrl( Dlg, dlg_Text, g_SearchStr,
    dlg_PosOffset + 14, dlg_PosOffset,
    StrWidth, 0,
    id_sr_SearchStr , 0,
    “/ML=255/HISTORY=Search_History/SHOWH0=” +
    Str( g_DefSearchOpts & _so_ShowHis0 ) );

    DlgAddCtrl( Dlg, dlg_BitmapBtn, “LARROW”,
    dlg_PosOffset + StrWidth + 1, dlg_PosOffset + 0,
    dlg_Units + 11, dlg_Units + 9,
    id_sr_SrchRegExBtn, 0,
    “/M=FindShowRegExMenu /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=2” );

    Y = dlg_PosOffset + 1;
    }
    DlgAddCtrl( Dlg, dlg_GroupBox, “Options”,
    X, Y,
    71, 3,
    id_sr_OptionGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Regular &expressions”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_RegExpCB, 0, “” );
    DlgSetInt( Dlg, id_sr_RegExpCB, ( SearchFlags & 6 ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Case sensiti&ve”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sr_CaseCB, 0, “” );
    DlgSetInt( Dlg, id_sr_CaseCB, SearchFlags & 1 );

    DlgAddCtrl( Dlg, dlg_GroupBox, “Mode”,
    dlg_NegOffset + 1, dlg_PosOffset | dlg_Units_5QLines,
    71, 2,
    id_sr_ModeGrp, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Pr&ompted search”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sr_PromptSrchCB, 0, “” );
    DlgSetInt( Dlg, id_sr_PromptSrchCB, Prompted != 0 );

    if ( !SetupOnly ) {
    DlgAddCtrl( Dlg, dlg_PushButton, “Al&ias”,
    _stab_Width – 33, dlg_Units | ( ( ( _stab_Height – 3 ) * 12 ) + 3 ),
    dlg_StanBtnWidth, 0,
    id_sr_AliasBtn, 0,
    “/M=SearchGetAlias /ID=” + Str( id_sr_SearchStr ) + “/FLAGS=2” );

    DlgAddCtrl( Dlg, dlg_PushButton, “Reg Ex &Help”,
    dlg_PosOffset | dlg_StanBtnWidth + 2, dlg_PosOffset,
    dlg_StanBtnWidth + 4, 0,
    id_sr_RegExpHlpBtn, 0,
    “/M=RegExpHelp” );
    }
    Return_Str = “/H=” + HelpContext;
    if ( !SetupOnly ) {
    Return_Str = “/H=” + HelpContext + “/HOOK=_GHighlightDlgProc”;
    }
    // *indent-on*
    ret;

    _EndDlg:
    if ( !SetupOnly ) {
    Result = True; // Always save settings
    }
    if ( Result ) {
    if ( g_SaveSearchStr ) {

    // Add items to search history list
    Return_Str = DlgGetStr( Dlg, id_sr_SearchStr );
    g_SearchStr = Return_Str;
    Rm( “History_List /M=1/HISTORY=SEARCH_HISTORY” );
    g_SaveSearchStr = False;
    }
    SearchFlags = DlgGetInt( Dlg, id_sr_CaseCB ) | 0x80000000;
    if ( DlgGetInt( Dlg, id_sr_RegExpCB ) ) {
    switch ( g_RegExStyle ) {

    case esClassic :
    SearchFlags |= 0x04;
    break;

    case esUnix :
    SearchFlags |= 0x02;
    break;

    case esPerl :
    SearchFlags |= 0x06;
    break;
    }
    }
    if ( DlgGetInt( Dlg, id_sr_PromptSrchCB ) ) {
    SearchFlags |= 0x10;
    }
    Set_Global_Int( GFlags, SearchFlags );
    }
    ret;

    } // _GHighlightDlg

    int _GHighlightDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    int Parent = GetParent( Window );
    int ExpOn;
    int CaseSen;
    int Prompted;
    int EnableFlag;
    int HideFlag;
    int Lock;

    str SearchStr;

    switch ( Message ) {

    case wm_Activate :
    if ( ( WParam & 0xFFFF ) != wa_Inactive ) {
    SetSearchHistory( “”, True, Window, id_sr_SearchStr );
    }
    break;

    case wm_ShowWindow :
    if ( WParam ) {

    str TStr = “&Reset”;

    // Search button
    EnableWindow( GetDlgItem( Parent, id_sr_SearchBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_SearchBtn ), sw_Show );

    // Reset button
    SendMessageStr( GetDlgItem( Parent, id_sr_ReplaceBtn ), wm_SetText, 0,
    TStr );
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), sw_Show );

    // All button
    EnableWindow( GetDlgItem( Parent, id_sr_AllBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_AllBtn ), sw_Hide );

    // Direction Switch button
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );

    // Defaults button
    EnableWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), True );
    ShowWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), sw_Show );
    }
    else if ( g_SrCollapsed ) {
    call _Collapse;
    }
    break;

    case wm_SysCommand :
    switch ( WParam & 0xfff0 ) {

    case sc_Maximize :
    call _Collapse;
    RetVal = 0;
    return ( 1 );

    case sc_Restore :
    RetVal = 0;
    return ( 1 );
    }
    break;

    case wm_Command :
    switch ( WParam & 0xffff ) {

    case dlg_WCmd_Init :
    SetFocus( GetDlgItem( Window, id_sr_SearchStr ) );
    g_SCaretPos = 0;
    // Subclass_With_Macro( GetWindow( GetDlgItem( Window, id_sr_SearchStr ),
    // gw_Child ), “SrchStringProc”, “” );
    break;

    case id_sr_SearchStr :
    switch ( WParam >> 16 ) {

    case cbn_SelChange :
    case cbn_EditChange :
    g_SaveSearchStr = True;
    break;

    case cbn_SelEndCancel :
    g_SCaretPos = SendMessage( LParam, cb_GetEditSel, 0, 0 );
    break;
    }
    break;

    // Main tab dlg buttons

    case id_sr_SearchBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _CloseParent;
    GlobalExpHighlight( SearchStr, ExpOn, CaseSen, False );
    }
    break;

    case id_sr_ReplaceBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    call _CloseParent;
    GlobalExpHighlight( “”, 0, 0, True );
    }
    break;

    case id_sr_DefaultsBtn :
    if ( ( WParam >> 16 ) == bn_Clicked ) {
    if ( g_SrCollapsed ) {
    call _Collapse;
    }
    call _SetDefaults;
    }
    break;
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    // Internal Routines ———————————————————–

    _Collapse:
    EnableFlag = g_SrCollapsed;
    if ( EnableFlag ) {
    HideFlag = sw_Show;
    }
    else {
    HideFlag = sw_Hide;
    SendDlgItemMessage( Window, id_sr_SearchStr, cb_ShowDropDown, False, 0 );
    }
    if ( Message != wm_ShowWindow ) {
    // SendMessage( Parent, wm_SetRedraw, False, 0);
    Lock = LockWindowUpdate( Parent );
    }
    else {
    Lock = False;
    }

    EnableWindow( GetDlgItem( Window, id_sr_OptionGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_OptionGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_RegExpCB), Enableflag );
    ShowWindow( GetDlgItem( Window, id_sr_RegExpCB ), HideFlag );

    EnableWindow( GetDlgItem (Window, id_sr_CaseCB), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_CaseCB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_ModeGrp ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_ModeGrp ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_PromptSrchCB ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_PromptSrchCB ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_AliasBtn ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_AliasBtn ), HideFlag );

    EnableWindow( GetDlgItem( Window, id_sr_RegExpHlpBtn ), EnableFlag );
    ShowWindow( GetDlgItem( Window, id_sr_RegExpHlpBtn ), HideFlag );

    struct TRect Rect;
    struct TPoint PParent;
    struct TPoint PTab;
    struct TPoint PWin;

    int Bottom;
    int HeightDiff;
    int CtrlWin;

    // Get resize location
    GetWindowRect( GetDlgItem( Window, id_sr_OptionGrp ), &Rect );
    Bottom = Rect.Top;

    // Get Parent window size
    GetWindowRect( Parent, &Rect );
    PParent.X = Rect.Right – Rect.Left;
    PParent.Y = Rect.Bottom – Rect.Top;

    // Get Highlight dialog window size
    GetWindowRect( Window, &Rect );
    PWin.X = Rect.Right – Rect.Left;
    PWin.Y = PParent.Y – ( Rect.Bottom – Rect.Top );

    // Get Tab ctrl window size
    GetWindowRect( GetDlgItem( Parent, id_st_TabBar ), &Rect );
    PTab.X = Rect.Right – Rect.Left;
    PTab.Y = PParent.Y – ( Rect.Bottom – Rect.Top );

    if ( EnableFlag ) {
    HeightDiff = -g_SrCollapsed;
    g_SrCollapsed = 0;
    }
    else {
    HeightDiff = Rect.Bottom – Bottom – 6;
    g_SrCollapsed = HeightDiff;
    }
    // Resize Highlight dialog
    SetWindowPos( Window, 0,
    0, 0,
    PWin.X, PParent.Y – PWin.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    // Resize TabBar control
    SetWindowPos( GetDlgItem( Parent, id_st_TabBar ), 0,
    0, 0,
    PTab.X, PParent.Y – PTab.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    // Move Search button
    CtrlWin = GetDlgItem( Parent, id_sr_SearchBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Reset button
    CtrlWin = GetDlgItem( Parent, id_sr_ReplaceBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Defaults button
    CtrlWin = GetDlgItem( Parent, id_sr_DefaultsBtn );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Cancel button
    CtrlWin = GetDlgItem( Parent, id_std_Close );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    // Move Help button
    CtrlWin = GetDlgItem( Parent, id_std_Help );
    GetWindowRect( CtrlWin, &Rect );
    ScreenToClient( Parent, &Rect );
    SetWindowPos( CtrlWin, 0, Rect.Left, Rect.Top – HeightDiff, 0, 0,
    swp_NoSize | swp_NoZOrder );

    if ( Message != wm_ShowWindow ) {
    // SendMessage( Parent, wm_SetRedraw, True, 0 ); // turn refresh of dialog back on
    if ( Lock ) {
    LockWindowUpdate( 0 );
    }
    }

    // Resize SearchTab dialog
    SetWindowPos( Parent, 0, 0, 0, PParent.X, PParent.Y – HeightDiff,
    swp_NoActivate | swp_NoZOrder | swp_NoMove );

    if ( Message != wm_ShowWindow ) {
    RedrawWindow( Parent, 0, 0, rdw_Invalidate | rdw_Erase | rdw_UpdateNow );
    }
    ret;

    _SetFlags:
    GetWindowText( GetDlgItem( Window, id_sr_SearchStr ), SearchStr, 256 );
    ExpOn = SendDlgItemMessage( Window, id_sr_RegExpCB, bm_GetCheck, 0, 0 );
    CaseSen = SendDlgItemMessage( Window, id_sr_CaseCB, bm_GetCheck, 0, 0 );
    Prompted = SendDlgItemMessage( Window, id_sr_PromptSrchCB, bm_GetCheck, 0, 0 );

    g_SearchStr = SearchStr;
    g_SaveSearchStr = False;
    g_HighlightFlags = CaseSen | 0x80000000 | ( Prompted * 0x10 );
    if ( ExpOn ) {
    switch ( g_RegExStyle ) {

    case esClassic :
    g_HighlightFlags |= 0x04;
    ExpOn = 2;
    break;

    case esUnix :
    g_HighlightFlags |= 0x02;
    ExpOn = 1;
    break;

    case esPerl :
    g_HighlightFlags |= 0x06;
    ExpOn = 3;
    break;
    }
    }
    RetVal = 0;
    ret;

    _CloseParent:
    call _SetFlags;
    if ( !Prompted ) {

    // Close parent dialog
    PostMessage( GetParent( Window ), wm_SysCommand, sc_Close, 0 );
    }
    else if ( !g_SrCollapsed ) {
    call _Collapse;
    }
    ret;

    _SetDefaults:

    // Reset the options to the defaults
    CaseSen = ( g_DefHiliteFlags & 0x01 ) != 0;
    SendDlgItemMessage( Window, id_sr_CaseCB, bm_SetCheck, CaseSen, 0 );

    ExpOn = ( g_DefHiliteFlags & 0x06 ) != 0;
    SendDlgItemMessage( Window, id_sr_RegExpCB, bm_SetCheck, ExpOn, 0 );

    Prompted = ( g_DefHiliteFlags & 0x10 ) != 0;
    SendDlgItemMessage( Window, id_sr_PromptSrchCB, bm_SetCheck, Prompted, 0 );
    ret;

    } // _GHighlightDlgProc

    void SrchOptionsDlg(
    int M = Parse_Int( “/M=”, MParm_Str ),
    int Dlg = Parse_Int( “/DLG=”, MParm_Str ),
    int Result = Parse_Int( “/RES=”, MParm_Str ),
    int SetupOnly = Parse_Int( “/SETUP=”, MParm_Str )
    ) trans2
    {
    TTRACE_ENTER( “Search”, TDBG_Trace, “SrchOptionsDlg(%d, %d, %d, %d)”, M, Dlg, Result, SetupOnly );

    str GOptions;

    GOptions = _g_DefSearchOpts;
    switch ( M ) {

    case 0 :
    Rm( “SearchTabDlg /T#=” + Str( _tab_sr_SearchOptions ) );
    break;

    case 1 :
    call _BuildCtrls;
    break;

    case 2 :
    call _EndDlg;
    break;
    }
    TTRACE_LEAVE( “SrchOptionsDlg()” );
    return ( );

    // Internal Routines ———————————————————–

    _BuildCtrls:

    int Options = Global_Int( GOptions );

    str HelpContext = Parse_Str( “/H=”, MParm_Str );

    if ( Svl( HelpContext ) == 0 ) {
    HelpContext = hc_SearchOptions;
    }
    // *indent-off*
    DlgAddCtrl( Dlg, dlg_Groupbox, “Regular E&xpression Type”,
    1, 1, 71, 2,
    id_sr_RegExLbl, 0, “” );

    DlgAddCtrl( Dlg, dlg_RadioButton, “Classic”,
    dlg_PosOffset + 1, dlg_PosOffset + 1, 0, 0,
    id_sr_REClassicRB, 0, “” );
    DlgSetInt( Dlg, id_sr_REClassicRB, g_RegExStyle == esClassic );

    DlgAddCtrl( Dlg, dlg_RadioButton, “Unix”,
    dlg_PosOffset + 12, dlg_PosOffset + 0, 0, 0,
    id_sr_REUnixRB, 0, “” );
    DlgSetInt( Dlg, id_sr_REUnixRB, g_RegExStyle == esUnix );

    DlgAddCtrl( Dlg, dlg_RadioButton, “Perl”,
    dlg_PosOffset + 10, dlg_PosOffset + 0, 0, 0,
    id_sr_REPerlRB, 0, “” );
    DlgSetInt( Dlg, id_sr_REPerlRB, g_RegExStyle == esPerl );

    DlgAddCtrl( Dlg, dlg_Groupbox, “Search Scope”,
    1, dlg_PosOffset + 1, 71, 5,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “All button searches &globally”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sopt_AllBtnCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_AllBtnCB, ( Options & _so_GlobalAllBtn ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Auto &wraps at beginning and end of file”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sopt_AutoWrapCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_AutoWrapCB, ( Options & _so_AutoWrap ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Prompt before wrapping search”,
    dlg_PosOffset + 3, dlg_PosOffset + 1,
    0, 0,
    id_sopt_NoWrapPromptCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_NoWrapPromptCB, ( Options & _so_NoWrapPrompt ) == 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&No restrict block check on activate”,
    dlg_NegOffset + 3, dlg_PosOffset + 1,
    0, 0,
    id_sopt_NoBlkChkCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_NoBlkChkCB, ( Options & _so_NoBlkChk ) != 0 );

    DlgAddCtrl( Dlg, dlg_Groupbox, “Options”,
    1, dlg_PosOffset + 1, 71, 6,
    -1, 0, “” );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Hide Find List pane after selecting an item from it”,
    dlg_PosOffset + 1, dlg_PosOffset + 1,
    0, 0,
    id_sopt_FindLstHideCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_FindLstHideCB, ( Options & _so_FindLstHide ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “C&lose Find List pane when empty”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sopt_FindLstCloseCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_FindLstCloseCB, ( Options & _so_FindLstClose ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “&Use Find/Replace default values from Customize dialog”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sopt_UseSrDefCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_UseSrDefCB, ( Options & _so_UseSrDef ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Use &File Find/Replace default values from Customize dialog”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sopt_UseFsDefCB, 0, “” );
    DlgSetInt( Dlg, id_sopt_UseFsDefCB, ( Options & _so_UseFsDef ) != 0 );

    DlgAddCtrl( Dlg, dlg_CheckBox, “Pr&e-load Search field with string under cursor”,
    dlg_PosOffset, dlg_PosOffset + 1,
    0, 0,
    id_sopt_ShowHis0CB, 0, “” );
    DlgSetInt( Dlg, id_sopt_ShowHis0CB, ( Options & _so_ShowHis0 ) != 0 );

    Return_Str = “/H=” + HelpContext;
    if ( !SetupOnly ) {
    Return_Str = “/H=” + HelpContext + “/HOOK=_SrchOptionsDlgProc”;
    }
    // *indent-on*
    ret;

    _EndDlg:

    int Options;

    g_RegExStyle = ( DlgGetInt( Dlg, id_sr_REPerlRB ) * esPerl ) | ( DlgGetInt( Dlg, id_sr_REUnixRB ) * esUnix );
    Options = DlgGetInt( Dlg, id_sopt_AllBtnCB ) * _so_GlobalAllBtn;
    Options |= DlgGetInt( Dlg, id_sopt_FindLstHideCB ) * _so_FindLstHide;
    Options |= DlgGetInt( Dlg, id_sopt_UseSrDefCB ) * _so_UseSrDef;
    Options |= DlgGetInt( Dlg, id_sopt_UseFsDefCB ) * _so_UseFsDef;
    Options |= DlgGetInt( Dlg, id_sopt_ShowHis0CB ) * _so_ShowHis0;
    Options |= DlgGetInt( Dlg, id_sopt_NoBlkChkCB ) * _so_NoBlkChk;
    Options |= DlgGetInt( Dlg, id_sopt_AutoWrapCB ) * _so_AutoWrap;
    Options |= ( DlgGetInt( Dlg, id_sopt_NoWrapPromptCB ) == 0 ) * _so_NoWrapPrompt;
    Options |= DlgGetInt( Dlg, id_sopt_FindLstCloseCB ) * _so_FindLstClose;
    Set_Global_Int( GOptions, Options );
    g_SetupChanged |= 0x01;
    ret;

    } // SrchOptionsDlg

    int _SrchOptionsDlgProc(
    int &RetVal,
    int Window,
    int Message,
    int WParam,
    int LParam,
    str Parms
    ) trans2 no_break
    {
    switch ( Message ) {

    case wm_ShowWindow :
    if ( WParam ) {

    int Parent = GetParent( Window );

    // Search button
    EnableWindow( GetDlgItem( Parent, id_sr_SearchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_SearchBtn ), sw_Hide );

    // Replace/Reset button
    EnableWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_ReplaceBtn ), sw_Hide );

    // All button
    EnableWindow( GetDlgItem( Parent, id_sr_AllBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_AllBtn ), sw_Hide );

    // Defaults button
    EnableWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DefaultsBtn ), sw_Hide );

    // Direction Switch button
    EnableWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), False );
    ShowWindow( GetDlgItem( Parent, id_sr_DirSwitchBtn ), sw_Hide );
    }
    break;

    case wm_SysCommand :
    switch ( WParam & 0xfff0 ) {

    case sc_Maximize :
    RetVal = 0;
    return ( 1 );

    case sc_Restore :
    RetVal = 0;
    return ( 1 );
    }
    break;

    case wm_Command :
    if ( ( WParam >> 16 ) == bn_Clicked ) {

    int Jx;

    switch ( WParam & 0xFFFF ) {

    case dlg_WCmd_Init :
    switch ( g_RegExStyle ) {

    case esClassic :
    SetFocus( GetDlgItem( Window, id_sr_REClassicRB ) );
    break;

    case esUnix :
    SetFocus( GetDlgItem( Window, id_sr_REUnixRB ) );
    break;

    case esPerl :
    SetFocus( GetDlgItem( Window, id_sr_REPerlRB ) );
    break;
    }
    break;

    case id_sr_REClassicRB :
    if ( SendDlgItemMessage( Window, id_sr_REClassicRB, bm_GetCheck, 0, 0 ) ) {
    g_RegExStyle = esClassic;
    g_SetupChanged |= 0x01;
    }
    break;

    case id_sr_REUnixRB :
    if ( SendDlgItemMessage( Window, id_sr_REUnixRB, bm_GetCheck, 0, 0 ) ) {
    g_RegExStyle = esUnix;
    g_SetupChanged |= 0x01;
    }
    break;

    case id_sr_REPerlRB :
    if ( SendDlgItemMessage( Window, id_sr_REPerlRB, bm_GetCheck, 0, 0 ) ) {
    g_RegExStyle = esPerl;
    g_SetupChanged |= 0x01;
    }
    break;

    case id_sopt_AllBtnCB :
    Jx = SendDlgItemMessage( Window, id_sopt_AllBtnCB, bm_GetCheck, 0, 0 );
    if ( Jx ) {
    g_DefSearchOpts |= _so_GlobalAllBtn;
    }
    else {
    g_DefSearchOpts &= 0xFFFFFFFF ^ _so_GlobalAllBtn;
    }
    g_SetupChanged |= 0x01;
    break;

    case id_sopt_NoBlkChkCB :
    Jx = SendDlgItemMessage( Window, id_sopt_NoBlkChkCB, bm_GetCheck, 0, 0 );
    if ( Jx ) {
    g_DefSearchOpts |= _so_NoBlkChk;
    }
    else {
    g_DefSearchOpts &= 0xFFFFFFFF ^ _so_NoBlkChk;
    }
    g_SetupChanged |= 0x01;
    break;

    case id_sopt_AutoWrapCB :
    case id_sopt_NoWrapPromptCB :
    case id_sopt_FindLstHideCB :
    case id_sopt_FindLstCloseCB :
    case id_sopt_UseSrDefCB :
    case id_sopt_UseFsDefCB :
    case id_sopt_ShowHis0CB :
    g_SetupChanged |= 0x01;
    break;
    }
    }
    break;
    }
    return ( DlgMessageProc( RetVal, Window, Message, WParam, LParam, Parms ) );

    } // _SrchOptionsDlgProc

    int SwitchBestFile(
    int ActiveWinId,
    str FileName
    ) trans2
    {
    int SRefresh = Refresh;
    int OrgWin = Window_Id;
    int FileOk = False;

    Refresh = False;
    if ( g_SWinMode ) {
    ActiveWinId = g_CurWindow;
    }
    if ( Switch_Win_Id( ActiveWinId ) ) {
    if ( Caps( FileName ) == Caps( File_Name ) ) {
    FileOk = True;
    }
    else {

    int ActScreenNum = Screen_Num;

    if ( ActScreenNum != 0 ) {
    do {
    Switch_Window( Cur_Window + 1 );
    if ( Screen_Num == ActScreenNum ) {
    if ( Caps( FileName ) == Caps( File_Name ) ) {
    FileOk = True;
    break;
    }
    }
    } while ( Window_Id != ActiveWinId );
    }
    }
    }
    if ( !FileOk ) {
    Switch_Win_Id( OrgWin );
    FileOk = Switch_File( FileName );
    }
    else if ( g_SWinMode ) {
    g_CurWindow = Window_Id;
    }
    Refresh = SRefresh;
    return ( FileOk );

    } // SwitchBestFile

    #21570

    Brad M.
    Participant

    This block of code is unusable. Browser or webserver has substituted characters that make it non-compilable, and the wrapping has created huge amounts of code which have ended up on a single line (and some of that code has a // in it, so most of the line is seen as comments. Code re-formatting doesn’t help either because it can’t tell where comments end and code begins.

    Can you post using the code tag? If not, please try that (example below)

    /*==============================================================================
                                 Multi-Edit Macro File
                                   29-Jan-08  12:04
    
      Function: Search related macros.
      Author  : Dan Hughes
    
      GlobalExpHighlight  -
      S_And_R             - The general purpose search and search/replace macro.
      Srch_Across_Line    - Performs Word/Phrase search
      Parse_Phrase        - Used by SRCH_ACROSS_LINE to ...
      Repl_Across_Line    - Performs Word/Phrase replace
      Search              - This is the user interface for a SEARCH.
      S_Repl              - This is the user interface for a SEARCH AND REPLACE.
      RepSrch             - This repeats the last search or search/replace.
      IncSrch             - Incremental search
      Fs                  - The interface to multi-file search
      SwitchBestFile      -
    
                 Copyright (C) 2002-2008 by Multi Edit Software, Inc.
     ====================================================================( ldh )==*/
    macro_file Search;
    
    //#define _UseTreeInsert_
    #include TDbg.sh
    
    TDBG_DEFINE_AREA( Search );
    
    #include Win32.sh
    #include Messages.sh
    #include ComCtlx.sh
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.