55{
56 char *result;
57 FILE *termin,
58 *termout;
59#if defined(HAVE_TERMIOS_H)
60 struct termios t_orig,
61 t;
62#elif defined(WIN32)
63 HANDLE t = NULL;
64 DWORD t_orig = 0;
65#endif
66
67#ifdef WIN32
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 termin = fopen("CONIN$", "w+");
88 termout = fopen("CONOUT$", "w+");
89#else
90
91
92
93
94
95 termin = fopen("/dev/tty", "r");
96 termout = fopen("/dev/tty", "w");
97#endif
98 if (!termin || !termout
99#ifdef WIN32
100
101
102
103
104
105
106
107 || (getenv("OSTYPE") && strcmp(getenv("OSTYPE"), "msys") == 0)
108#endif
109 )
110 {
111 if (termin)
112 fclose(termin);
113 if (termout)
114 fclose(termout);
115 termin = stdin;
116 termout = stderr;
117 }
118
119 if (!echo)
120 {
121#if defined(HAVE_TERMIOS_H)
122
123 tcgetattr(fileno(termin), &t);
124 t_orig = t;
125 t.c_lflag &= ~ECHO;
126 tcsetattr(fileno(termin), TCSAFLUSH, &t);
127#elif defined(WIN32)
128
129 t = (HANDLE) _get_osfhandle(_fileno(termin));
130
131
132 GetConsoleMode(t, &t_orig);
133
134
135 SetConsoleMode(t, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
136#endif
137 }
138
139 if (prompt)
140 {
141 fputs(
_(prompt), termout);
142 fflush(termout);
143 }
144
146
147
148 if (result == NULL)
150
151
153
154 if (!echo)
155 {
156
157#if defined(HAVE_TERMIOS_H)
158 tcsetattr(fileno(termin), TCSAFLUSH, &t_orig);
159 fputs("\n", termout);
160 fflush(termout);
161#elif defined(WIN32)
162 SetConsoleMode(t, t_orig);
163 fputs("\n", termout);
164 fflush(termout);
165#endif
166 }
167 else if (prompt_ctx && prompt_ctx->
canceled)
168 {
169
170 fputs("\n", termout);
171 fflush(termout);
172 }
173
174 if (termin != stdin)
175 {
176 fclose(termin);
177 fclose(termout);
178 }
179
180 return result;
181}
char * pg_strdup(const char *in)
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
int pg_strip_crlf(char *str)