C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
enterstr.c File Reference

Enter a string from keyboard. More...

#include <cm.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
Include dependency graph for enterstr.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 allows the user to enter a string in cooked mode

Detailed Description

Enter a string from keyboard.

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file enterstr.c.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

allows the user to enter a string in cooked mode

Note
allows line editing and other features
writes the prompt to stderr and the user's input to stdout
handles signals to ensure that the terminal settings are restored if the program is interrupted.

Definition at line 32 of file enterstr.c.

32 {
33 struct termios new_tioctl;
34 char in_str[BUFSIZ];
35 char *in_ptr = in_str;
36 char *msg;
37 char errmsg[128];
38
39 if (argc < 2)
40 strcpy(errmsg, "input:");
41 else
42 strcpy(errmsg, argv[1]);
45 new_tioctl = shell_tioctl;
46 new_tioctl.c_lflag |= ICANON;
47 tcsetattr(2, TCSAFLUSH, &new_tioctl);
48 while (1) {
49 msg = errmsg;
50 while (*msg)
51 write(2, msg++, 1);
52 if (read(2, in_str, BUFSIZ) > -1)
53 break;
54 }
55 while (*in_ptr)
56 write(1, in_ptr++, 1);
59 exit(0);
60}
char errmsg[]
Definition futil.c:84
#define BUFSIZ
Definition view.h:29
char in_str[BUFSIZ+1]
Definition iloan.c:20
struct termios shell_tioctl
Definition scriou.c:22
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition scriou.c:43
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42
void sig_prog_mode()
Set up signal handlers for interrupt signals.
Definition sig.c:62

References capture_shell_tioctl(), restore_shell_tioctl(), shell_tioctl, sig_dfl_mode(), and sig_prog_mode().

Here is the call graph for this function: