]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/readline/examples/manexamp.c
1 /* manexamp.c -- The examples which appear in the documentation are here. */
4 #include <readline/readline.h>
6 /* **************************************************************** */
8 /* How to Emulate gets () */
10 /* **************************************************************** */
12 /* A static variable for holding the line. */
13 static char *line_read
= (char *)NULL
;
15 /* Read a string, and return a pointer to it. Returns NULL on EOF. */
19 /* If the buffer has already been allocated, return the memory
24 line_read
= (char *)NULL
;
27 /* Get a line from the user. */
28 line_read
= readline ("");
30 /* If the line has any text in it, save it on the history. */
31 if (line_read
&& *line_read
)
32 add_history (line_read
);
37 /* **************************************************************** */
39 /* Writing a Function to be Called by Readline. */
41 /* **************************************************************** */
43 /* Invert the case of the COUNT following characters. */
44 invert_case_line (count
, key
)
47 register int start
, end
;
59 /* Find the end of the range to modify. */
60 end
= start
+ (count
* direction
);
62 /* Force it to be within range. */
78 /* Tell readline that we are modifying the line, so save the undo
80 rl_modifying (start
, end
);
82 for (; start
!= end
; start
+= direction
)
84 if (_rl_uppercase_p (rl_line_buffer
[start
]))
85 rl_line_buffer
[start
] = _rl_to_lower (rl_line_buffer
[start
]);
86 else if (_rl_lowercase_p (rl_line_buffer
[start
]))
87 rl_line_buffer
[start
] = _rl_to_upper (rl_line_buffer
[start
]);
90 /* Move point to on top of the last character changed. */
91 rl_point
= end
- direction
;