SDDSlib
Loading...
Searching...
No Matches
backspace.c
Go to the documentation of this file.
1/**
2 * @file backspace.c
3 * @brief Provides functionality to perform backspace operations by a specified number of characters.
4 *
5 * @copyright
6 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
7 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
8 *
9 * @license
10 * This file is distributed under the terms of the Software License Agreement
11 * found in the file LICENSE included with this distribution.
12 *
13 * @author C. Saunders, R. Soliday
14 */
15#include "mdb.h"
16
17/**
18 * @brief Backspace by a specified number of characters.
19 *
20 * This function outputs a specified number of backspace characters (`\b`) to the standard output.
21 * It dynamically allocates and reuses a buffer to store the backspace characters, optimizing
22 * memory usage for repeated calls with varying numbers of backspaces.
23 *
24 * @param n The number of characters to backspace.
25 */
26void backspace(long n) {
27 static char *bspace = NULL;
28 static long n_bspace = 0;
29
30 if (n > n_bspace) {
31 register long i;
32 bspace = trealloc(bspace, sizeof(*bspace) * (n + 1));
33 for (i = n_bspace; i < n; i++)
34 bspace[i] = '\b';
35 n_bspace = n;
36 }
37 bspace[n] = 0;
38 fputs(bspace, stdout);
39 bspace[n] = '\b';
40}
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181
void backspace(long n)
Backspace by a specified number of characters.
Definition backspace.c:26