Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

814 lines
20 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. libMenuBar.c
  5. Abstract:
  6. Definition of the Menu Bar for the text editor
  7. --*/
  8. #ifndef _LIB_MENU_BAR
  9. #define _LIB_MENU_BAR
  10. #include "libMisc.h"
  11. STATIC EFI_STATUS MenuInit (VOID);
  12. STATIC EFI_STATUS MenuCleanup (VOID);
  13. STATIC EFI_STATUS MenuRefresh (VOID);
  14. STATIC EFI_STATUS MenuHandleInput (EFI_INPUT_KEY*);
  15. STATIC EFI_STATUS MenuHide(VOID);
  16. STATIC EFI_STATUS NewFile (VOID);
  17. STATIC EFI_STATUS OpenFile(VOID);
  18. STATIC EFI_STATUS CloseFile(VOID);
  19. STATIC EFI_STATUS SaveFile(VOID);
  20. STATIC EFI_STATUS SaveFileAs(VOID);
  21. STATIC EFI_STATUS ExitEditor(VOID);
  22. STATIC EFI_STATUS CutLine(VOID);
  23. STATIC EFI_STATUS PasteLine(VOID);
  24. STATIC EFI_STATUS SearchFind(VOID);
  25. STATIC EFI_STATUS SearchReplace(VOID);
  26. STATIC EFI_STATUS GotoLine(VOID);
  27. STATIC EFI_STATUS SetupColors(VOID);
  28. STATIC EFI_STATUS SetupScreen(VOID);
  29. STATIC EFI_STATUS FileType(VOID);
  30. EFI_EDITOR_MENU_ITEM MainMenuItems[] = {
  31. { L"Open File", L"F1", OpenFile },
  32. { L"Save File", L"F2", SaveFile },
  33. { L"Exit", L"F3", ExitEditor },
  34. { L"Cut Line", L"F4", CutLine },
  35. { L"Paste Line", L"F5", PasteLine },
  36. { L"Go To Line", L"F6", GotoLine },
  37. { L"Search", L"F7", SearchFind },
  38. { L"Search/Replace", L"F8", SearchReplace },
  39. { L"File Type", L"F9", FileType },
  40. { L"", L"", NULL }
  41. };
  42. EFI_EDITOR_MENU_BAR MainMenuBar = {
  43. MainMenuItems,
  44. MenuInit,
  45. MenuCleanup,
  46. MenuRefresh,
  47. MenuHide,
  48. MenuHandleInput
  49. };
  50. extern EFI_STATUS FileBufferRefreshDown(VOID);
  51. extern EFI_STATUS FileBufferHome (VOID);
  52. #define FileIsModified() \
  53. MainEditor.FileModified
  54. STATIC BOOLEAN EditorIsExiting;
  55. #define IS_EDITOR_EXITING (EditorIsExiting == TRUE)
  56. STATIC EFI_EDITOR_LINE *MenuCutLine;
  57. STATIC
  58. EFI_STATUS
  59. MenuInit (
  60. VOID
  61. )
  62. {
  63. EditorIsExiting = FALSE;
  64. MenuCutLine = NULL;
  65. return EFI_SUCCESS;
  66. }
  67. STATIC
  68. EFI_STATUS
  69. MenuCleanup (
  70. VOID
  71. )
  72. {
  73. return EFI_SUCCESS;
  74. }
  75. STATIC
  76. EFI_STATUS
  77. MenuRefresh (
  78. VOID
  79. )
  80. {
  81. EFI_EDITOR_MENU_ITEM *Item;
  82. UINTN Col = 0;
  83. UINTN Row = MENU_BAR_LOCATION;
  84. UINTN Width;
  85. MenuHide();
  86. for (Item = MainMenuBar.MenuItems;Item->Function;Item++) {
  87. Width = max((StrLen(Item->Name)+6),20);
  88. if (((Col + Width) >= MAX_TEXT_COLUMNS)) {
  89. Row++;
  90. Col = 0;
  91. }
  92. PrintAt(Col,Row,L"%E%s%N %H%s%N ",Item->FunctionKey,Item->Name);
  93. Col += Width;
  94. }
  95. MainEditor.FileBuffer->RestorePosition();
  96. return EFI_SUCCESS;
  97. }
  98. STATIC
  99. EFI_STATUS
  100. MenuHandleInput (
  101. EFI_INPUT_KEY *Key
  102. )
  103. {
  104. EFI_EDITOR_MENU_ITEM *Item;
  105. EFI_STATUS Status;
  106. UINTN i = 0;
  107. UINTN NumItems = 0;
  108. NumItems = sizeof(MainMenuItems)/sizeof(EFI_EDITOR_MENU_ITEM) - 1;
  109. Item = MainMenuBar.MenuItems;
  110. i = Key->ScanCode - SCAN_CODE_F1;
  111. if (i > (NumItems - 1)) {
  112. return EFI_SUCCESS;
  113. }
  114. Item = &MainMenuBar.MenuItems[i];
  115. Status = Item->Function();
  116. MenuRefresh();
  117. return (IS_EDITOR_EXITING) ? EFI_LOAD_ERROR : EFI_SUCCESS;
  118. }
  119. STATIC
  120. EFI_STATUS
  121. OpenFile (
  122. VOID
  123. )
  124. {
  125. EFI_STATUS Status = EFI_SUCCESS;
  126. CHAR16 *Filename;
  127. MainEditor.InputBar->SetPrompt(L"File Name to Open: ");
  128. MainEditor.InputBar->SetStringSize (125);
  129. Status = MainEditor.InputBar->Refresh ();
  130. if ( EFI_ERROR(Status) ) {
  131. return EFI_SUCCESS;
  132. }
  133. Filename = MainEditor.InputBar->ReturnString;
  134. if ( Filename == NULL ) {
  135. MainEditor.StatusBar->SetStatusString(L"Filename was NULL");
  136. return EFI_SUCCESS;
  137. }
  138. Status = MainEditor.FileImage->SetFilename (Filename);
  139. if ( EFI_ERROR(Status) ) {
  140. EditorError(Status,L"Could Not Set Filename");
  141. return EFI_NOT_FOUND;
  142. }
  143. Status = MainEditor.FileImage->OpenFile ();
  144. if ( EFI_ERROR(Status) ) {
  145. EditorError(Status,L"Could Not Open File");
  146. return EFI_NOT_FOUND;
  147. }
  148. Status = MainEditor.FileImage->ReadFile ();
  149. if ( EFI_ERROR(Status) ) {
  150. EditorError(Status,L"Could Not Read File");
  151. return EFI_NOT_FOUND;
  152. }
  153. Status = MainEditor.FileBuffer->Refresh();
  154. if ( EFI_ERROR(Status) ) {
  155. EditorError(Status,L"Could Not Refresh");
  156. return EFI_NOT_FOUND;
  157. }
  158. MainEditor.FileBuffer->SetPosition(TEXT_START_ROW,TEXT_START_COLUMN);
  159. MainEditor.TitleBar->SetTitleString(Filename);
  160. MainEditor.Refresh();
  161. return EFI_SUCCESS;
  162. }
  163. STATIC
  164. EFI_STATUS
  165. CloseFile (
  166. VOID
  167. )
  168. {
  169. EFI_INPUT_KEY Key;
  170. EFI_STATUS Status;
  171. BOOLEAN Done = FALSE;
  172. if (FileIsModified()) {
  173. MenuHide();
  174. PrintAt(0,MENU_BAR_LOCATION,L"%EY%H Yes%N %EN%N %HNo%N %EQ%N %HCancel%N");
  175. MainEditor.StatusBar->SetStatusString(L"File Modified. Save? ");
  176. while (!Done) {
  177. WaitForSingleEvent(In->WaitForKey,0);
  178. Status = In->ReadKeyStroke(In,&Key);
  179. if ( EFI_ERROR(Status) || Key.ScanCode != 0 ) {
  180. continue;
  181. }
  182. switch (Key.UnicodeChar) {
  183. case 'q':
  184. case 'Q':
  185. Status = EFI_NOT_READY;
  186. Done = TRUE;
  187. break;
  188. case 'n':
  189. case 'N':
  190. Status = EFI_SUCCESS;
  191. Done = TRUE;
  192. break;
  193. case 'y':
  194. case 'Y':
  195. Status = SaveFile();
  196. Done = TRUE;
  197. break;
  198. default:
  199. break;
  200. }
  201. }
  202. MenuRefresh();
  203. }
  204. if (!EFI_ERROR(Status)) {
  205. MainEditor.FileImage->CloseFile();
  206. MainEditor.FileBuffer->Refresh ();
  207. MainEditor.TitleBar->SetTitleString(L"");
  208. } else {
  209. EditorIsExiting = FALSE;
  210. }
  211. MainEditor.StatusBar->Refresh();
  212. MenuRefresh();
  213. return EFI_SUCCESS;
  214. }
  215. STATIC
  216. EFI_STATUS
  217. SaveFile (
  218. VOID
  219. )
  220. {
  221. CHAR16 *Output;
  222. EFI_STATUS Status;
  223. if (!MainEditor.FileModified) {
  224. return EFI_SUCCESS;
  225. }
  226. Output = PoolPrint (L"File To Save: [%s]",MainEditor.FileImage->FileName);
  227. MainEditor.InputBar->SetPrompt(Output);
  228. MainEditor.InputBar->SetStringSize(100);
  229. Status = MainEditor.InputBar->Refresh();
  230. FreePool(Output);
  231. if (!EFI_ERROR(Status)) {
  232. if (MainEditor.InputBar->StringSize > 0) {
  233. MainEditor.FileImage->SetFilename(MainEditor.InputBar->ReturnString);
  234. FreePool(MainEditor.InputBar->ReturnString);
  235. }
  236. Status = MainEditor.FileImage->WriteFile();
  237. }
  238. return Status;
  239. }
  240. STATIC
  241. EFI_STATUS
  242. ExitEditor (
  243. VOID
  244. )
  245. {
  246. EditorIsExiting = TRUE;
  247. CloseFile();
  248. return EFI_SUCCESS;
  249. }
  250. STATIC
  251. EFI_STATUS
  252. MenuHide (
  253. VOID
  254. )
  255. {
  256. MainEditor.FileBuffer->ClearLine (MENU_BAR_LOCATION);
  257. MainEditor.FileBuffer->ClearLine (MENU_BAR_LOCATION+1);
  258. MainEditor.FileBuffer->ClearLine (MENU_BAR_LOCATION+2);
  259. return EFI_SUCCESS;
  260. }
  261. STATIC
  262. EFI_STATUS
  263. CutLine (
  264. VOID
  265. )
  266. {
  267. LIST_ENTRY *Link;
  268. LIST_ENTRY *Next;
  269. LIST_ENTRY *Prev;
  270. EFI_EDITOR_LINE *Line;
  271. Link = MainEditor.FileBuffer->CurrentLine;
  272. if (Link == MainEditor.FileImage->ListHead->Blink) {
  273. return EFI_SUCCESS;
  274. }
  275. if (MenuCutLine) {
  276. FreePool(MenuCutLine);
  277. }
  278. Line = CR(Link,EFI_EDITOR_LINE,Link,EFI_EDITOR_LINE_LIST);
  279. MenuCutLine = LineDup(Line);
  280. Next = Link->Flink;
  281. Prev = Link->Blink;
  282. Prev->Flink = Next;
  283. Next->Blink = Prev;
  284. Link->Flink = Link;
  285. Link->Blink = Link;
  286. MainEditor.FileImage->NumLines--;
  287. MainEditor.FileBuffer->CurrentLine = Next;
  288. FileBufferHome();
  289. FileBufferRefreshDown();
  290. FreePool(Line);
  291. if (!FileIsModified()) {
  292. MainEditor.FileModified = TRUE;
  293. MainEditor.TitleBar->Refresh();
  294. }
  295. return EFI_SUCCESS;
  296. }
  297. STATIC
  298. EFI_STATUS
  299. PasteLine (
  300. VOID
  301. )
  302. {
  303. LIST_ENTRY *Link;
  304. EFI_EDITOR_LINE *Line;
  305. if (!MenuCutLine) {
  306. return EFI_SUCCESS;
  307. }
  308. Line = LineDup(MenuCutLine);
  309. Link = MainEditor.FileBuffer->CurrentLine;
  310. Line->Link.Blink = Link->Blink;
  311. Line->Link.Flink = Link;
  312. Link->Blink->Flink = &Line->Link;
  313. Link->Blink = &Line->Link;
  314. MainEditor.FileImage->NumLines++;
  315. MainEditor.FileBuffer->CurrentLine = &Line->Link;
  316. FileBufferHome();
  317. FileBufferRefreshDown();
  318. return EFI_SUCCESS;
  319. }
  320. STATIC
  321. EFI_STATUS
  322. GotoLine (
  323. VOID
  324. )
  325. {
  326. CHAR16 *Str;
  327. UINTN Row;
  328. UINTN Current;
  329. UINTN RowRange;
  330. BOOLEAN Refresh = FALSE;
  331. MenuHide ();
  332. Str = PoolPrint(L"Go To Line: ");
  333. MainEditor.InputBar->SetPrompt(Str);
  334. FreePool(Str);
  335. MainEditor.InputBar->SetStringSize(5);
  336. MainEditor.InputBar->Refresh();
  337. if (MainEditor.InputBar->StringSize > 0 ) {
  338. Row = Atoi(MainEditor.InputBar->ReturnString);
  339. }
  340. if ( Row > MainEditor.FileImage->NumLines ) {
  341. return EFI_SUCCESS;
  342. }
  343. Current = MainEditor.FileBuffer->FilePosition.Row;
  344. RowRange = MainEditor.FileBuffer->MaxVisibleRows;
  345. if (Row == Current ) {
  346. return EFI_SUCCESS;
  347. }
  348. if (Row < Current) {
  349. LineRetreat(Current-Row);
  350. if ( Row < MainEditor.FileBuffer->LowVisibleRange.Row ) {
  351. MainEditor.FileBuffer->LowVisibleRange.Row = Row-1;
  352. MainEditor.FileBuffer->HighVisibleRange.Row = min(Row+RowRange-1,MainEditor.FileImage->NumLines);
  353. Refresh = TRUE;
  354. }
  355. } else {
  356. LineAdvance(Row - Current);
  357. if ( Row > MainEditor.FileBuffer->HighVisibleRange.Row ) {
  358. MainEditor.FileBuffer->LowVisibleRange.Row = Row - 1;
  359. MainEditor.FileBuffer->HighVisibleRange.Row = min(Row+RowRange-1,MainEditor.FileImage->NumLines);
  360. Refresh = TRUE;
  361. }
  362. }
  363. if (MainEditor.FileBuffer->LowVisibleRange.Column > TEXT_START_COLUMN ) {
  364. MainEditor.FileBuffer->LowVisibleRange.Column = TEXT_START_COLUMN;
  365. MainEditor.FileBuffer->HighVisibleRange.Column = MAX_TEXT_COLUMNS;
  366. Refresh = TRUE;
  367. }
  368. Current = MainEditor.FileBuffer->LowVisibleRange.Row;
  369. MainEditor.FileBuffer->FilePosition.Row = Row;
  370. MainEditor.FileBuffer->SetPosition(Row-Current+TEXT_START_ROW,TEXT_START_COLUMN);
  371. MainEditor.StatusBar->SetPosition(Row,TEXT_START_COLUMN+1);
  372. if ( Refresh = TRUE ) {
  373. MainEditor.FileBuffer->Refresh();
  374. }
  375. return EFI_SUCCESS;
  376. }
  377. STATIC
  378. EFI_STATUS
  379. SearchFind (
  380. VOID
  381. )
  382. {
  383. CHAR16 *Str;
  384. UINTN Pos;
  385. EFI_EDITOR_LINE *Line;
  386. UINTN LineNumber;
  387. UINTN MaxRows;
  388. UINTN NumLines;
  389. BOOLEAN Refresh = FALSE;
  390. BOOLEAN Found = FALSE;
  391. Str = PoolPrint(L"Enter Search String: ");
  392. MainEditor.InputBar->SetPrompt(Str);
  393. FreePool(Str);
  394. MainEditor.InputBar->SetStringSize(50);
  395. MainEditor.InputBar->Refresh();
  396. if (MainEditor.InputBar->StringSize == 0) {
  397. return EFI_SUCCESS;
  398. }
  399. Str = PoolPrint(L"%s\0",MainEditor.InputBar->ReturnString);
  400. Line = LineCurrent();
  401. MaxRows = MainEditor.FileBuffer->MaxVisibleRows;
  402. NumLines = MainEditor.FileImage->NumLines;
  403. LineNumber = MainEditor.FileBuffer->FilePosition.Row;
  404. while (TRUE) {
  405. Pos = 0;
  406. if (StrLen(Line->Buffer) != 0) {
  407. Pos = StrStr (Line->Buffer,Str);
  408. }
  409. if (Pos == 0) {
  410. if (LineNumber == MainEditor.FileImage->NumLines) {
  411. break;
  412. } else {
  413. LineNumber++;
  414. }
  415. Line = LineNext();
  416. continue;
  417. }
  418. MainEditor.FileBuffer->FilePosition.Row = LineNumber;
  419. MainEditor.FileBuffer->FilePosition.Column = Pos;
  420. MainEditor.StatusBar->SetPosition(LineNumber,Pos);
  421. LineAdvance(LineNumber-MainEditor.FileBuffer->FilePosition.Row);
  422. if (LineNumber > MainEditor.FileBuffer->HighVisibleRange.Row ||
  423. LineNumber < MainEditor.FileBuffer->LowVisibleRange.Row) {
  424. MainEditor.FileBuffer->LowVisibleRange.Row = LineNumber - 1;
  425. MainEditor.FileBuffer->HighVisibleRange.Row = min(LineNumber+MaxRows-2,NumLines);
  426. Refresh = TRUE;
  427. }
  428. if (Pos > MainEditor.FileBuffer->HighVisibleRange.Column ||
  429. Pos < MainEditor.FileBuffer->LowVisibleRange.Column) {
  430. MainEditor.FileBuffer->LowVisibleRange.Column = Pos - 1;
  431. MainEditor.FileBuffer->HighVisibleRange.Column = Pos + MAX_TEXT_COLUMNS - 1;
  432. Refresh = TRUE;
  433. }
  434. Pos = Pos - MainEditor.FileBuffer->LowVisibleRange.Column - 1;
  435. LineNumber = LineNumber - MainEditor.FileBuffer->LowVisibleRange.Row;
  436. MainEditor.FileBuffer->SetPosition(LineNumber+TEXT_START_ROW,Pos+TEXT_START_COLUMN);
  437. if (Refresh) {
  438. MainEditor.FileBuffer->Refresh();
  439. }
  440. Found = TRUE;
  441. break;
  442. }
  443. if (!Found) {
  444. MainEditor.StatusBar->SetStatusString(L"Search String Not Found");
  445. }
  446. FreePool(Str);
  447. return EFI_SUCCESS;
  448. }
  449. STATIC
  450. BOOLEAN
  451. CheckReplace (
  452. VOID
  453. )
  454. {
  455. EFI_INPUT_KEY Key;
  456. EFI_STATUS Status = EFI_SUCCESS;
  457. BOOLEAN Done = FALSE;
  458. MenuHide();
  459. PrintAt(0,MENU_BAR_LOCATION,L"%EY%N%H Yes%N %EN%N %HNo%N %EQ%N %HCancel%N");
  460. MainEditor.StatusBar->SetStatusString(L"Replace? ");
  461. while (!Done) {
  462. WaitForSingleEvent(In->WaitForKey,0);
  463. Status = In->ReadKeyStroke(In,&Key);
  464. if (EFI_ERROR(Status) || Key.ScanCode != 0) {
  465. continue;
  466. }
  467. switch (Key.UnicodeChar) {
  468. case 'y':
  469. case 'Y':
  470. Status = EFI_SUCCESS;
  471. Done = TRUE;
  472. break;
  473. case 'q':
  474. case 'Q':
  475. Status = EFI_NOT_READY;
  476. Done = TRUE;
  477. break;
  478. case 'n':
  479. case 'N':
  480. Status = EFI_NOT_READY;
  481. Done = TRUE;
  482. break;
  483. default:
  484. break;
  485. }
  486. }
  487. MenuRefresh();
  488. MainEditor.StatusBar->SetStatusString(L" ");
  489. return (Status == EFI_SUCCESS);
  490. }
  491. STATIC
  492. BOOLEAN
  493. GetInputStrings (
  494. OUT CHAR16 **Search,
  495. OUT CHAR16 **Replace
  496. )
  497. {
  498. CHAR16 *Str;
  499. Str = PoolPrint(L"Enter Search String: ");
  500. MainEditor.InputBar->SetPrompt(Str);
  501. FreePool(Str);
  502. MainEditor.InputBar->SetStringSize(50);
  503. MainEditor.InputBar->Refresh();
  504. if ( MainEditor.InputBar->StringSize == 0 ) {
  505. return FALSE;
  506. }
  507. *Search = PoolPrint(L"%s",MainEditor.InputBar->ReturnString);
  508. Str = PoolPrint(L"Replace With: ");
  509. MainEditor.InputBar->SetPrompt(Str);
  510. FreePool(Str);
  511. MainEditor.InputBar->SetStringSize(50);
  512. MainEditor.InputBar->Refresh();
  513. *Replace = PoolPrint(L"%s",MainEditor.InputBar->ReturnString);
  514. return TRUE;
  515. }
  516. STATIC
  517. EFI_STATUS
  518. SearchReplace (
  519. VOID
  520. )
  521. {
  522. CHAR16 *Search;
  523. CHAR16 *Replacement;
  524. UINTN SearchLength;
  525. UINTN ReplaceLength;
  526. UINTN LinePos;
  527. UINTN Pos;
  528. EFI_EDITOR_LINE *Line;
  529. UINTN LineNumber;
  530. UINTN MaxRows;
  531. BOOLEAN Refresh = FALSE;
  532. BOOLEAN Found = FALSE;
  533. if (!GetInputStrings(&Search,&Replacement)) {
  534. return EFI_SUCCESS;
  535. }
  536. Line = LineCurrent();
  537. MaxRows = MainEditor.FileBuffer->MaxVisibleRows;
  538. SearchLength = StrLen(Search);
  539. ReplaceLength = StrLen(Replacement);
  540. Pos = MainEditor.FileBuffer->FilePosition.Column - 1;
  541. LineNumber = MainEditor.FileBuffer->FilePosition.Row - 1;
  542. while (TRUE) {
  543. LinePos = StrStr (Line->Buffer+Pos,Search);
  544. if (LinePos == 0) {
  545. if (LineNumber == MainEditor.FileImage->NumLines) {
  546. break;
  547. } else {
  548. LineNumber++;
  549. }
  550. Line = LineNext();
  551. Pos = 0;
  552. continue;
  553. }
  554. Pos += LinePos;
  555. LinePos = Pos + SearchLength - 1;
  556. MainEditor.FileBuffer->FilePosition.Row = LineNumber;
  557. MainEditor.FileBuffer->FilePosition.Column = Pos;
  558. if (LineNumber > MainEditor.FileBuffer->HighVisibleRange.Row ||
  559. LineNumber < MainEditor.FileBuffer->LowVisibleRange.Row) {
  560. MainEditor.FileBuffer->LowVisibleRange.Row = LineNumber - 1;
  561. MainEditor.FileBuffer->HighVisibleRange.Row = min(LineNumber+MaxRows-2,MainEditor.FileImage->NumLines+1);
  562. Refresh = TRUE;
  563. }
  564. if (Pos > MainEditor.FileBuffer->HighVisibleRange.Column ||
  565. Pos < MainEditor.FileBuffer->LowVisibleRange.Column) {
  566. MainEditor.FileBuffer->LowVisibleRange.Column = Pos - 1;
  567. MainEditor.FileBuffer->HighVisibleRange.Column = Pos + MAX_TEXT_COLUMNS - 1;
  568. Refresh = TRUE;
  569. }
  570. Pos = Pos - MainEditor.FileBuffer->LowVisibleRange.Column - 1;
  571. MainEditor.FileBuffer->SetPosition(LineNumber-MainEditor.FileBuffer->LowVisibleRange.Row+TEXT_START_ROW,Pos+TEXT_START_COLUMN);
  572. if (Refresh) {
  573. MainEditor.FileBuffer->Refresh();
  574. }
  575. Found = TRUE;
  576. if (!CheckReplace()) {
  577. break;
  578. }
  579. {
  580. CHAR16 *Tail;
  581. UINTN Size = Line->Size*2;
  582. INTN Diff = ReplaceLength - SearchLength;
  583. if (Diff > 0) {
  584. Line->Buffer = ReallocatePool(Line->Buffer,Size,Size+2*Diff);
  585. }
  586. Tail = PoolPrint(L"%s%s",Replacement,Line->Buffer+LinePos);
  587. Size = LinePos - SearchLength;
  588. StrCpy(Line->Buffer+Size,Tail);
  589. FreePool(Tail);
  590. Line->Size += Diff;
  591. Pos = LinePos + Diff;
  592. }
  593. if (!MainEditor.FileModified) {
  594. MainEditor.FileModified = TRUE;
  595. MainEditor.TitleBar->Refresh();
  596. }
  597. MainEditor.FileBuffer->RefreshCurrentLine();
  598. }
  599. if (!Found) {
  600. MainEditor.StatusBar->SetStatusString(L"Search String Not Found");
  601. }
  602. return EFI_SUCCESS;
  603. }
  604. STATIC
  605. EFI_STATUS
  606. FileType (
  607. VOID
  608. )
  609. {
  610. CHAR16 *FT;
  611. CHAR16 *NewType;
  612. CHAR16 *A = L"ASCII";
  613. CHAR16 *U = L"UNICODE";
  614. EFI_INPUT_KEY Key;
  615. EFI_STATUS Status = EFI_SUCCESS;
  616. BOOLEAN Done = FALSE;
  617. BOOLEAN Choice;
  618. Choice = MainEditor.FileImage->FileType;
  619. if (Choice == ASCII_FILE) {
  620. NewType = A;
  621. } else {
  622. NewType = U;
  623. }
  624. FT = PoolPrint(L"File is %s",NewType);
  625. MainEditor.StatusBar->SetStatusString(FT);
  626. FreePool(FT);
  627. MenuHide();
  628. PrintAt(0,MENU_BAR_LOCATION,L"%E U %N%H Set as UNICODE File %N %E A %N %HSet As ASCII File%N %EQ%N %HCancel%N");
  629. while (!Done) {
  630. WaitForSingleEvent(In->WaitForKey,0);
  631. Status = In->ReadKeyStroke(In,&Key);
  632. if (EFI_ERROR(Status) || Key.ScanCode != 0) {
  633. continue;
  634. }
  635. switch (Key.UnicodeChar) {
  636. case 'u':
  637. case 'U':
  638. Choice = UNICODE_FILE;
  639. Done = TRUE;
  640. break;
  641. case 'a':
  642. case 'A':
  643. Choice = ASCII_FILE;
  644. Done = TRUE;
  645. break;
  646. case 'q':
  647. case 'Q':
  648. Done = TRUE;
  649. break;
  650. default:
  651. break;
  652. }
  653. }
  654. MenuRefresh();
  655. if (Choice != MainEditor.FileImage->FileType) {
  656. MainEditor.FileImage->FileType = Choice;
  657. NewType = (Choice == ASCII_FILE) ? A : U;
  658. FT = PoolPrint(L"File Type Changed to %s",NewType);
  659. MainEditor.StatusBar->SetStatusString(FT);
  660. FreePool(FT);
  661. }
  662. return EFI_SUCCESS;
  663. }
  664. #endif /* _LIB_MENU_BAR */