1
0

sed.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. sed.h
  5. Abstract:
  6. This header contains internal definitions for the sed (stream editor)
  7. utility.
  8. Author:
  9. Evan Green 11-Jul-2013
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #include <minoca/lib/types.h>
  15. #include <regex.h>
  16. #include <stdio.h>
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. #define SED_VERSION_MAJOR 1
  21. #define SED_VERSION_MINOR 0
  22. #define SED_USAGE \
  23. "usage: sed [-n] script [file...]\n" \
  24. " sed [-n] [-e script]... [-f scriptfile]... [file]...\n" \
  25. "The sed (stream editor) utility processes text. Options are:\n" \
  26. " -e, --expression <expression> -- Use the given argument as a sed " \
  27. "script.\n" \
  28. " -f, --file <file> -- Read in the sed script contained in the given " \
  29. "file.\n" \
  30. " -n, --quiet, --silent -- Suppress the default printing of input \n" \
  31. " lines to standard out.\n\n" \
  32. " --help -- Display this help screen and exit.\n" \
  33. " --version -- Display the application version and exit.\n\n" \
  34. "Script format:\n" \
  35. " [address1[,address2]]function\n\n" \
  36. "Addresses can be:\n" \
  37. " Nothing, which matches every line in the input.\n" \
  38. " A decimal line number, which matches a single line.\n" \
  39. " A basic regular expression in the form /BRE/, which will match any \n" \
  40. " line that the expression matches.\n\n" \
  41. "If two addresses are supplied, the function is executing for all lines \n"\
  42. "in between the two addresses, inclusive.\n\n" \
  43. "Available functions:\n" \
  44. " { function...} -- Groups a block of functions together.\n" \
  45. " a\\\n" \
  46. " text -- Write text to standard out at the end of the current line.\n" \
  47. " b[label] -- Branch to the ':' function bearing the given label.\n" \
  48. " c\\\n" \
  49. " text -- Delete the pattern space. With zero or one addresses, or at \n" \
  50. " the end of the range for two addresses, print the given " \
  51. "text.\n" \
  52. " d -- Delete the pattern space and start the next cycle.\n" \
  53. " D -- Delete the pattern space up to the first newline and start the \n" \
  54. " next cycle.\n" \
  55. " g -- Replace the pattern space with the hold space.\n" \
  56. " G -- Append a newline plus the hold space to the pattern space.\n" \
  57. " h -- Replace the hold space with the pattern space.\n" \
  58. " H -- Append a newline plus the pattern space to the hold space.\n" \
  59. " i\\\n" \
  60. " text -- Write the text to standard out.\n" \
  61. " l -- Write the pattern space to standard out in a visually \n" \
  62. " unambiguous way. Non-printable characters are escaped, long \n" \
  63. " lines are folded, and a $ is written at the end of every line.\n" \
  64. " n -- Write the pattern space to standard out (unless -n is \n" \
  65. " specified), and replace the pattern space with the next line \n" \
  66. " less its ending newline.\n" \
  67. " N -- Append the next line of input less its trailing newline to the\n" \
  68. " pattern space, embedding a newline before the appended text.\n" \
  69. " p -- Write the pattern space to standard out.\n" \
  70. " P -- Write the pattern space up to the first newline to standard out.\n"\
  71. " q -- Branch to the end of the script and quit.\n" \
  72. " r rfile -- Copy the contents of rfile to standard out. If rfile \n" \
  73. " cannot be opened, treat it like an empty file.\n" \
  74. " s/BRE/replacement/flags -- Replace the first occurrence of text \n" \
  75. " matching the regular expression BRE in the hold space with the \n" \
  76. " given replacement text. Use & in the replacement to specify the\n" \
  77. " input text matching the BRE. Use \n (where n is 1 through 9) to \n"\
  78. " specify the text matching the given subexpression. Flags are:\n" \
  79. " n -- Substitute only the nth occurrence.\n" \
  80. " g -- Substitute every non-overlapping occurrence.\n" \
  81. " p -- Write to standard out if a replacement was made.\n" \
  82. " w wfile -- Append (write) to the given wfile if a replacement \n" \
  83. " was made.\n" \
  84. " t[label] -- Branch to the given label if any substitutions have been \n"\
  85. " made since reading an input line or executing a t.\n" \
  86. " w wfile -- Append (write) the pattern space to the given wfile.\n" \
  87. " x -- Exchange the pattern and hold spaces.\n" \
  88. " y/string1/string2 -- Replace all occurrences of characters in string1\n"\
  89. " with characters from string2. Use \\n for newline.\n" \
  90. " :label -- Do nothing. This denotes a label that can be jumped to.\n" \
  91. " = -- Write the current line number to standard out.\n" \
  92. " # -- Comment. Ignore anything after this unless the first two \n" \
  93. " characters of a script are #n, which is equivalent to turning on\n"\
  94. " the -n option.\n\n"
  95. #define SED_OPTIONS_STRING "ne:f:"
  96. #define SED_INITIAL_STRING_SIZE 32
  97. #define SED_SUBSTITUTE_FLAG_GLOBAL 0x00000001
  98. #define SED_SUBSTITUTE_FLAG_PRINT 0x00000002
  99. #define SED_SUBSTITUTE_FLAG_WRITE 0x00000004
  100. //
  101. // ------------------------------------------------------ Data Type Definitions
  102. //
  103. typedef enum _SED_ADDRESS_TYPE {
  104. SedAddressInvalid,
  105. SedAddressNumber,
  106. SedAddressExpression,
  107. SedAddressLastLine,
  108. } SED_ADDRESS_TYPE, *PSED_ADDRESS_TYPE;
  109. typedef enum _SED_FUNCTION_TYPE {
  110. SedFunctionInvalid,
  111. SedFunctionGroup, // {
  112. SedFunctionPrintTextAtLineEnd, // a
  113. SedFunctionBranch, // b
  114. SedFunctionDeleteAndPrintText, // c
  115. SedFunctionDelete, // d
  116. SedFunctionDeleteToNewline, // D
  117. SedFunctionReplacePatternWithHold, // g
  118. SedFunctionAppendHoldToPattern, // G
  119. SedFunctionReplaceHoldWithPattern, // h
  120. SedFunctionAppendPatternToHold, // H
  121. SedFunctionPrintText, // i
  122. SedFunctionWritePatternEscaped, // l
  123. SedFunctionMoveToNextLine, // n
  124. SedFunctionAppendNextLine, // N
  125. SedFunctionWritePattern, // p
  126. SedFunctionWritePatternToNewline, // P
  127. SedFunctionQuit, // q
  128. SedFunctionReadFile, // r
  129. SedFunctionSubstitute, // s
  130. SedFunctionTest, // t
  131. SedFunctionWriteFile, // w
  132. SedFunctionExchangePatternAndHold, // x
  133. SedFunctionSubstituteCharacters, // y
  134. SedFunctionLabel, // :
  135. SedFunctionWriteLineNumber, // =
  136. SedFunctionNop, // #
  137. SedFunctionCount,
  138. } SED_FUNCTION_TYPE, *PSED_FUNCTION_TYPE;
  139. typedef struct _SED_COMMAND SED_COMMAND, *PSED_COMMAND;
  140. /*++
  141. Structure Description:
  142. This structure defines a mutable string in the sed utility.
  143. Members:
  144. Data - Supplies a pointer to the malloced string buffer itself.
  145. Size - Supplies the number of valid bytes in the buffer including the
  146. null terminator if there is one.
  147. Capacity - Supplies the size of the buffer allocation.
  148. --*/
  149. typedef struct _SED_STRING {
  150. PSTR Data;
  151. UINTN Size;
  152. UINTN Capacity;
  153. } SED_STRING, *PSED_STRING;
  154. /*++
  155. Structure Description:
  156. This structure defines a sed address, which is used to determine if the
  157. given command should be processed or not.
  158. Members:
  159. Type - Stores the type of address (line number, last line, or regular
  160. expression).
  161. Expression - Stores the regular expression for expression based addresses.
  162. Line - Stores the line number for line based addresses.
  163. --*/
  164. typedef struct _SED_ADDRESS {
  165. SED_ADDRESS_TYPE Type;
  166. union {
  167. regex_t Expression;
  168. LONGLONG Line;
  169. } U;
  170. } SED_ADDRESS, *PSED_ADDRESS;
  171. /*++
  172. Structure Description:
  173. This structure defines a sed write file entry.
  174. Members:
  175. ListEntry - Stores pointers to the next and previous write file entries.
  176. File - Stores the open file descriptor.
  177. Name - Stores a pointer to the file name.
  178. LineTerminated - Stores a boolean indicating whether the previous line
  179. written to this file was terminated or not.
  180. --*/
  181. typedef struct _SED_WRITE_FILE {
  182. LIST_ENTRY ListEntry;
  183. FILE *File;
  184. PSED_STRING Name;
  185. BOOL LineTerminated;
  186. } SED_WRITE_FILE, *PSED_WRITE_FILE;
  187. /*++
  188. Structure Description:
  189. This structure defines the parameters for a sed substitute (s) command.
  190. Members:
  191. Expression - Stores the regular expression to substitute.
  192. Replacement - Stores the replacement string.
  193. Flags - Stores the flags coming with the substitute command. See
  194. SED_SUBSTITUTE_FLAG_* definitions.
  195. OccurrenceNumber - Stores the occurrence number to replace if supplied. Set
  196. to zero if none was supplied.
  197. WriteFile - Stores a pointer to the write file structure if there is a
  198. write file.
  199. Matches - Stores a pointer to an array of match structures to be used when
  200. executing the regular expression.
  201. MatchCount - Stores the number of elements in the match array.
  202. --*/
  203. typedef struct _SED_SUBSTITUTE {
  204. regex_t Expression;
  205. PSED_STRING Replacement;
  206. ULONG Flags;
  207. ULONG OccurrenceNumber;
  208. PSED_WRITE_FILE WriteFile;
  209. regmatch_t *Matches;
  210. ULONG MatchCount;
  211. } SED_SUBSTITUTE, *PSED_SUBSTITUTE;
  212. /*++
  213. Structure Description:
  214. This structure defines the parameters for a sed characater substitute (y)
  215. command.
  216. Members:
  217. Character - Stores a pointer to the string containing the characters to
  218. replace.
  219. Replacement - Stores a pointer to the replacement characters corresponding
  220. to each character.
  221. --*/
  222. typedef struct _SED_CHARACTER_SUBSTITUTE {
  223. PSED_STRING Characters;
  224. PSED_STRING Replacement;
  225. } SED_CHARACTER_SUBSTITUTE, *PSED_CHARACTER_SUBSTITUTE;
  226. /*++
  227. Structure Description:
  228. This structure defines the parameters for a sed characater substitute (y)
  229. command.
  230. Members:
  231. ListEntry - Stores the list entry of the next and previous commands on
  232. the context's append list.
  233. StringOrPath - Stores either the string to append or the path of the file
  234. to read.
  235. --*/
  236. typedef struct _SED_APPEND_ENTRY {
  237. LIST_ENTRY ListEntry;
  238. SED_FUNCTION_TYPE Type;
  239. PSED_STRING StringOrPath;
  240. } SED_APPEND_ENTRY, *PSED_APPEND_ENTRY;
  241. /*++
  242. Structure Description:
  243. This structure defines a sed action.
  244. Members:
  245. Type - Stores the type of the function.
  246. ChildList - Stores the list of children for a group of functions.
  247. StringArgument - Stores the argument for functions that take a single
  248. string argument (a, c, i, b, t, :, r, w).
  249. Substitute - Stores the paramters for a substitute command.
  250. CharacterSubstitute - Stores the parameters for a character substituteion
  251. (y) command.
  252. WriteFile - Stores a pointer to the open file for write file operations.
  253. --*/
  254. typedef struct _SED_FUNCTION {
  255. SED_FUNCTION_TYPE Type;
  256. union {
  257. LIST_ENTRY ChildList;
  258. PSED_STRING StringArgument;
  259. SED_SUBSTITUTE Substitute;
  260. SED_CHARACTER_SUBSTITUTE CharacterSubstitute;
  261. PSED_WRITE_FILE WriteFile;
  262. } U;
  263. } SED_FUNCTION, *PSED_FUNCTION;
  264. /*++
  265. Structure Description:
  266. This structure defines a single sed command.
  267. Members:
  268. ListEntry - Stores pointers to the next and previous commands in the cycle.
  269. Parent - Stores a pointer to the parent sed command, or NULL if this is the
  270. dummy command.
  271. AddressCount - Stores the number of valid addresses in the command.
  272. Address - Stores the start and ending addresses for the command.
  273. Active - Stores a boolean indicating if the current command has been
  274. activated by its start address range and is now looking for the stop
  275. address to deactivate.
  276. AddressNegated - Stores a boolean indicating that the function should be
  277. executed when the address does not match.
  278. Function - Stores the primary function represented by this command.
  279. --*/
  280. struct _SED_COMMAND {
  281. LIST_ENTRY ListEntry;
  282. PSED_COMMAND Parent;
  283. ULONG AddressCount;
  284. SED_ADDRESS Address[2];
  285. BOOL Active;
  286. BOOL AddressNegated;
  287. SED_FUNCTION Function;
  288. };
  289. /*++
  290. Structure Description:
  291. This structure defines a sed input file.
  292. Members:
  293. ListEntry - Stores pointers to the next and previous input entries.
  294. File - Stores the open file pointer, or NULL if the file could not be
  295. opened.
  296. --*/
  297. typedef struct _SED_INPUT {
  298. LIST_ENTRY ListEntry;
  299. FILE *File;
  300. } SED_INPUT, *PSED_INPUT;
  301. /*++
  302. Structure Description:
  303. This structure defines a portion of a sed script, either an expression
  304. from the command line (-e), or an input file (-f).
  305. Members:
  306. ListEntry - Stores pointers to the next and previous script fragments.
  307. ExpressionNumber - Stores the expression number if this scrap came from the
  308. command line. If it did not, this will be zero.
  309. FileName - Stores the name of the file if this scrap came form a script
  310. file. If it did not, this will be NULL.
  311. Offset - Stores the character offset where the fragment begins in the
  312. global script, inclusive.
  313. Size - Stores the number of bytes in the script fragment.
  314. --*/
  315. typedef struct _SED_SCRIPT_FRAGMENT {
  316. LIST_ENTRY ListEntry;
  317. ULONG ExpressionNumber;
  318. PSTR FileName;
  319. UINTN Offset;
  320. UINTN Size;
  321. } SED_SCRIPT_FRAGMENT, *PSED_SCRIPT_FRAGMENT;
  322. /*++
  323. Structure Description:
  324. This structure defines the context for an instantiation of the sed
  325. application.
  326. Members:
  327. PrintLines - Stores a boolean indicating whether or not to print each line.
  328. This is enabled by default and is shut off with the -n argument.
  329. LineNumber - Stores the line number, either of the input file being
  330. processed or the script file.
  331. CharacterNumber - Stores the character index of the script expression
  332. being processed.
  333. CommandLineExpressionCount - Stores the number of expressions that were
  334. entered via the command line.
  335. PreviousRegularExpression - Stores a pointer to the previous regular
  336. expression used in a context address or substitution. If a given
  337. regular expression is empty, this previous one is used.
  338. StandardOut - Stores the write file representing standard out.
  339. HeadCommand - Stores the initial group command that contains all other
  340. commands.
  341. ScriptList - Stores the head of the list of script fragments.
  342. ScriptString - Stores the complete script string.
  343. InputList - Stores the head of the list of input files.
  344. CurrentInputFile - Stores a pointer to the current input file.
  345. PatternSpace - Stores a pointer to the pattern space string.
  346. HoldSpace - Stores a pointer to the hold space string.
  347. AppendList - Stores the head of the list of things to append to the end of
  348. the line after further processing is complete.
  349. WriteFileList - Stores the head of the list of write file entries.
  350. NextCommand - Stores a pointer to the next command to be executed.
  351. TestResult - Stores a boolean indicating if a test command executed now
  352. would succeed.
  353. LastLine - Stores a boolean indicating whether this is the last line of
  354. the input or not.
  355. LineTerminator - Stores the stripped terminating character for this line, or
  356. EOF if there was none.
  357. Quit - Stores a boolean indicating if a quit command was executed.
  358. Done - Stores a boolean indicating if there is no more input left.
  359. SkipPrint - Stores a boolean indicating if the main routine should skip
  360. printing the line (assuming the print lines boolean is on).
  361. --*/
  362. typedef struct _SED_CONTEXT {
  363. BOOL PrintLines;
  364. ULONGLONG LineNumber;
  365. ULONGLONG CharacterNumber;
  366. ULONG CommandLineExpressionCount;
  367. PSED_STRING PreviousRegularExpression;
  368. SED_WRITE_FILE StandardOut;
  369. SED_COMMAND HeadCommand;
  370. LIST_ENTRY ScriptList;
  371. PSED_STRING ScriptString;
  372. LIST_ENTRY InputList;
  373. PSED_INPUT CurrentInput;
  374. PSED_STRING PatternSpace;
  375. PSED_STRING HoldSpace;
  376. LIST_ENTRY AppendList;
  377. LIST_ENTRY WriteFileList;
  378. PSED_COMMAND NextCommand;
  379. BOOL TestResult;
  380. BOOL LastLine;
  381. INT LineTerminator;
  382. BOOL Quit;
  383. BOOL Done;
  384. BOOL SkipPrint;
  385. } SED_CONTEXT, *PSED_CONTEXT;
  386. typedef
  387. INT
  388. (*PSED_EXECUTE_FUNCTION) (
  389. PSED_CONTEXT Context,
  390. PSED_COMMAND Command
  391. );
  392. /*++
  393. Routine Description:
  394. This routine executes a sed function.
  395. Arguments:
  396. Context - Supplies a pointer to the application context.
  397. Command - Supplies a pointer to the command to execute.
  398. Return Value:
  399. 0 on success.
  400. Non-zero error code on failure.
  401. --*/
  402. //
  403. // -------------------------------------------------------------------- Globals
  404. //
  405. extern PSED_EXECUTE_FUNCTION SedFunctionTable[SedFunctionCount];
  406. //
  407. // -------------------------------------------------------- Function Prototypes
  408. //
  409. //
  410. // Application level functions
  411. //
  412. INT
  413. SedReadLine (
  414. PSED_CONTEXT Context
  415. );
  416. /*++
  417. Routine Description:
  418. This routine reads a new line into the pattern space, sans its trailing
  419. newline.
  420. Arguments:
  421. Context - Supplies a pointer to the application context.
  422. Return Value:
  423. 0 on success.
  424. Non-zero on failure.
  425. --*/
  426. //
  427. // Parsing functions
  428. //
  429. BOOL
  430. SedAddScriptFile (
  431. PSED_CONTEXT Context,
  432. PSTR Path
  433. );
  434. /*++
  435. Routine Description:
  436. This routine loads a sed script contained in the file at the given path.
  437. Arguments:
  438. Context - Supplies a pointer to the application context.
  439. Path - Supplies a pointer to a string containing the file path of the
  440. script file to load.
  441. Return Value:
  442. TRUE on success.
  443. FALSE on failure.
  444. --*/
  445. BOOL
  446. SedAddScriptString (
  447. PSED_CONTEXT Context,
  448. PSTR Script
  449. );
  450. /*++
  451. Routine Description:
  452. This routine loads a sed script into the current context.
  453. Arguments:
  454. Context - Supplies a pointer to the application context.
  455. Script - Supplies a pointer to the null terminated string containing the
  456. script to load.
  457. Return Value:
  458. TRUE on success.
  459. FALSE on failure.
  460. --*/
  461. BOOL
  462. SedParseScript (
  463. PSED_CONTEXT Context,
  464. PSTR Script
  465. );
  466. /*++
  467. Routine Description:
  468. This routine loads a sed script into the current context.
  469. Arguments:
  470. Context - Supplies a pointer to the application context.
  471. Script - Supplies a pointer to the null terminated string containing the
  472. script to load.
  473. Return Value:
  474. TRUE on success.
  475. FALSE on failure.
  476. --*/
  477. VOID
  478. SedDestroyCommands (
  479. PSED_CONTEXT Context
  480. );
  481. /*++
  482. Routine Description:
  483. This routine destroys any commands on the given context.
  484. Arguments:
  485. Context - Supplies a pointer to the application context.
  486. Return Value:
  487. None.
  488. --*/
  489. //
  490. // Utility functions
  491. //
  492. PSED_STRING
  493. SedReadFileIn (
  494. PSTR Path,
  495. BOOL MustSucceed
  496. );
  497. /*++
  498. Routine Description:
  499. This routine reads a file into a null terminated sed string.
  500. Arguments:
  501. Path - Supplies a pointer to a string containing the path of the file to
  502. read in.
  503. MustSucceed - Supplies a boolean indicating whether or not the open and
  504. read calls must succeed, or should return a partial or empty string
  505. on failure.
  506. Return Value:
  507. Returns a pointer to the string containing the contents of the file on
  508. success.
  509. NULL on failure.
  510. --*/
  511. PSED_STRING
  512. SedCreateString (
  513. PSTR Data,
  514. UINTN Size,
  515. BOOL NullTerminate
  516. );
  517. /*++
  518. Routine Description:
  519. This routine creates a sed string.
  520. Arguments:
  521. Data - Supplies an optional pointer to the initial data. This data will be
  522. copied.
  523. Size - Supplies the size of the initial data. Supply 0 if no data was
  524. supplied.
  525. NullTerminate - Supplies a boolean indicating if the string should be
  526. null terminated if it is not already.
  527. Return Value:
  528. Returns a pointer to the allocated string structure on success. The caller
  529. is responsible for destroying this string structure.
  530. NULL on allocation failure.
  531. --*/
  532. BOOL
  533. SedAppendString (
  534. PSED_STRING String,
  535. PSTR Data,
  536. UINTN Size
  537. );
  538. /*++
  539. Routine Description:
  540. This routine appends a string of characters to the given string. If the
  541. original string was null terminated, the resulting string will also be
  542. null terminated on success.
  543. Arguments:
  544. String - Supplies a pointer to the string to append to.
  545. Data - Supplies a pointer to the bytes to append.
  546. Size - Supplies the number of bytes to append.
  547. Return Value:
  548. TRUE on success.
  549. FALSE on failure.
  550. --*/
  551. VOID
  552. SedDestroyString (
  553. PSED_STRING String
  554. );
  555. /*++
  556. Routine Description:
  557. This routine destroys a sed string structure.
  558. Arguments:
  559. String - Supplies a pointer to the string to destroy.
  560. Return Value:
  561. None.
  562. --*/
  563. INT
  564. SedOpenWriteFile (
  565. PSED_CONTEXT Context,
  566. PSED_STRING Path,
  567. PSED_WRITE_FILE *WriteFile
  568. );
  569. /*++
  570. Routine Description:
  571. This routine opens up a write file, sharing descriptors between
  572. duplicate write file names.
  573. Arguments:
  574. Context - Supplies a pointer to the application context.
  575. Path - Supplies a pointer to the string containing the path of the write
  576. file.
  577. WriteFile - Supplies a pointer where the pointer to the write file will
  578. be returned on success.
  579. Return Value:
  580. 0 on success.
  581. Error code on failure.
  582. --*/
  583. INT
  584. SedPrint (
  585. PSED_CONTEXT Context,
  586. PSTR String,
  587. INT LineTerminator
  588. );
  589. /*++
  590. Routine Description:
  591. This routine prints a null terminated string to standard out.
  592. Arguments:
  593. Context - Supplies a pointer to the application context.
  594. String - Supplies the null terminated string to print.
  595. LineTerminator - Supplies the character that terminates this line. If this
  596. is EOF, then that tells this routine the line is not terminated.
  597. Return Value:
  598. 0 on success.
  599. Non-zero error code on failure.
  600. --*/
  601. INT
  602. SedWrite (
  603. PSED_WRITE_FILE WriteFile,
  604. PVOID Buffer,
  605. UINTN Size,
  606. INT LineTerminator
  607. );
  608. /*++
  609. Routine Description:
  610. This routine write the given buffer out to the given file descriptor.
  611. Arguments:
  612. WriteFile - Supplies a pointer to the file to write to.
  613. Buffer - Supplies the buffer to write.
  614. Size - Supplies the number of characters in the buffer.
  615. LineTerminator - Supplies the character that terminates this line. If this
  616. is EOF, then that tells this routine the line is not terminated.
  617. Return Value:
  618. 0 on success.
  619. Non-zero error code on failure.
  620. --*/