* Rename top level ipkg directory to opkg
[project/opkg-lede.git] / user.c
1 /* user.c - the itsy package management system
2
3 Jamey Hicks
4
5 Copyright (C) 2002 Hewlett Packard Company
6 Copyright (C) 2001 University of Southern California
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17 */
18
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include "file_util.h"
22 #include "str_util.h"
23 #ifdef OPKG_LIB
24 #include "libopkg.h"
25 #endif
26
27
28 #ifdef OPKG_LIB
29 static char *question = NULL;
30 static int question_len = 255;
31 #endif
32 char *get_user_response(const char *format, ...)
33 {
34 int len = question_len;
35 va_list ap;
36 char *response;
37 va_start(ap, format);
38
39 #ifndef OPKG_LIB
40 vprintf(format, ap);
41 do {
42 response = file_read_line_alloc(stdin);
43 } while (response == NULL);
44 #else
45 do {
46 if (question == NULL || len > question_len) {
47 question = realloc(question, len + 1);
48 question_len = len;
49 }
50 len = vsnprintf(question,question_len,format,ap);
51 } while (len > question_len);
52 response = strdup(opkg_cb_response(question));
53 #endif
54 str_chomp(response);
55 str_tolower(response);
56
57 return response;
58 }