Mercurial > mplayer.hg
annotate libmenu/menu_console.c @ 22809:09f97d0161ba
Handle X-QT extradata in a slightly more correct way
| author | cehoyos |
|---|---|
| date | Mon, 26 Mar 2007 09:35:03 +0000 |
| parents | ac69ba536915 |
| children | 426c20bcfddf |
| rev | line source |
|---|---|
| 8197 | 1 |
| 16862 | 2 #include "config.h" |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
3 #include "mp_msg.h" |
|
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
4 #include "help_mp.h" |
| 8197 | 5 |
| 6 #include <stdlib.h> | |
| 7 #include <stdio.h> | |
| 8 #include <string.h> | |
| 9 #include <ctype.h> | |
| 8229 | 10 #include <sys/time.h> |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
11 #include <sys/types.h> |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
12 #ifndef __MINGW32__ |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
13 #include <sys/wait.h> |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
14 #endif |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
15 #include <unistd.h> |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
16 #include <errno.h> |
| 8197 | 17 |
|
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18858
diff
changeset
|
18 #include "libmpcodecs/img_format.h" |
|
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18858
diff
changeset
|
19 #include "libmpcodecs/mp_image.h" |
| 8197 | 20 |
| 16862 | 21 #include "m_struct.h" |
| 22 #include "m_option.h" | |
| 8197 | 23 #include "menu.h" |
| 24 | |
| 16862 | 25 #include "libvo/font_load.h" |
| 26 #include "osdep/keycodes.h" | |
| 27 #include "input/input.h" | |
| 28 #include "osdep/timer.h" | |
| 8197 | 29 |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
30 typedef struct history_st history_t; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
31 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
32 struct history_st { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
33 char* buffer; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
34 int size; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
35 history_t* next; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
36 history_t* prev; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
37 }; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
38 |
| 8197 | 39 struct menu_priv_s { |
| 40 char** lines; // Our buffer | |
| 41 int last_line; | |
| 42 int num_lines; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
43 int add_line; |
| 8197 | 44 unsigned int hide_ts; |
| 45 unsigned int show_ts; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
46 pid_t child; // Child process if we are running a shell cmd |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
47 int child_fd[3]; // The 3 default fd |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
48 char* prompt; |
| 8197 | 49 //int max_lines; // Max number of lines with the last mpi |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
50 history_t* history; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
51 history_t* cur_history; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
52 int history_size; |
| 8197 | 53 |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
54 char* mp_prompt; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
55 char* child_prompt; |
| 8197 | 56 int buf_lines; // Buffer size (in line) |
| 57 int height; // Display size in % | |
| 58 int minb; | |
| 59 int vspace; | |
|
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
60 int bg,bg_alpha; |
| 8197 | 61 unsigned int hide_time; |
| 62 unsigned int show_time; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
63 int history_max; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
64 int raw_child; |
| 8197 | 65 }; |
| 66 | |
| 67 static struct menu_priv_s cfg_dflt = { | |
| 68 NULL, | |
| 69 0, | |
| 70 0, | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
71 1, |
| 8197 | 72 0, |
| 73 0, | |
| 74 0, | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
75 { 0 , 0, 0 }, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
76 NULL, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
77 NULL, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
78 NULL, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
79 0, |
| 8197 | 80 |
| 81 "# ", | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
82 "$ ", |
| 8197 | 83 50, // lines |
| 84 33, // % | |
| 85 3, | |
| 86 3, | |
|
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
87 0x80,0x40, |
| 8197 | 88 500, |
| 89 500, | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
90 10, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
91 0 |
| 8197 | 92 }; |
| 93 | |
| 94 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
| 95 | |
| 96 static m_option_t cfg_fields[] = { | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
97 { "prompt", ST_OFF(mp_prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL }, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
98 { "child-prompt", ST_OFF(child_prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL }, |
| 8197 | 99 { "buffer-lines", ST_OFF(buf_lines), CONF_TYPE_INT, M_OPT_MIN, 5, 0, NULL }, |
| 100 { "height", ST_OFF(height), CONF_TYPE_INT, M_OPT_RANGE, 1, 100, NULL }, | |
| 101 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
| 102 { "vspace", ST_OFF(vspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
|
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
103 { "bg", ST_OFF(bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL }, |
|
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
104 { "bg-alpha", ST_OFF(bg_alpha), CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL }, |
| 8197 | 105 { "show-time",ST_OFF(show_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, |
| 106 { "hide-time",ST_OFF(hide_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
107 { "history-size",ST_OFF(history_max), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
108 { "raw-child", ST_OFF(raw_child), CONF_TYPE_FLAG, 0, 0, 1, NULL }, |
| 8197 | 109 { NULL, NULL, NULL, 0,0,0,NULL } |
| 110 }; | |
| 111 | |
| 112 #define mpriv (menu->priv) | |
| 113 | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
114 static void check_child(menu_t* menu); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
115 |
| 8197 | 116 static void add_line(struct menu_priv_s* priv, char* l) { |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
117 char* eol = strchr(l,'\n'); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
118 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
119 if(eol) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
120 if(eol != l) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
121 eol[0] = '\0'; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
122 add_line(priv,l); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
123 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
124 if(eol[1]) add_line(priv,eol+1); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
125 return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
126 } |
| 8197 | 127 |
| 128 if(priv->num_lines >= priv->buf_lines && priv->lines[priv->last_line]) | |
| 129 free(priv->lines[priv->last_line]); | |
| 130 else | |
| 131 priv->num_lines++; | |
| 132 | |
| 133 priv->lines[priv->last_line] = strdup(l); | |
| 134 priv->last_line = (priv->last_line + 1) % priv->buf_lines; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
135 priv->add_line = 1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
136 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
137 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
138 static void add_string(struct menu_priv_s* priv, char* l) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
139 char* eol = strchr(l,'\n'); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
140 int ll = priv->last_line > 0 ? priv->last_line - 1 : priv->buf_lines-1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
141 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
142 if(priv->num_lines <= 0 || priv->add_line || eol == l) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
143 add_line(priv,l); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
144 priv->add_line = 0; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
145 return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
146 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
147 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
148 if(eol) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
149 eol[0] = '\0'; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
150 add_string(priv,l); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
151 if(eol[1]) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
152 add_line(priv,eol+1); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
153 priv->add_line = 0; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
154 } else |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
155 priv->add_line = 1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
156 return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
157 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
158 priv->lines[ll] = realloc(priv->lines[ll],strlen(priv->lines[ll]) + strlen(l) + 1); |
| 12646 | 159 if ( priv->lines[ll] != NULL ) |
| 160 { | |
| 161 strcat(priv->lines[ll],l); | |
| 162 } | |
| 8197 | 163 } |
| 164 | |
| 165 static void draw(menu_t* menu, mp_image_t* mpi) { | |
| 166 int h = mpi->h*mpriv->height/100; | |
| 167 int w = mpi->w - 2* mpriv->minb; | |
| 168 int x = mpriv->minb, y; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
169 int lw,lh,i, ll; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
170 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
171 if(mpriv->child) check_child(menu); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
172 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
173 ll = mpriv->last_line - 1; |
| 8197 | 174 |
| 175 if(mpriv->hide_ts) { | |
| 176 unsigned int t = GetTimerMS() - mpriv->hide_ts; | |
| 177 if(t >= mpriv->hide_time) { | |
| 178 mpriv->hide_ts = 0; | |
| 179 menu->show = 0; | |
| 180 return; | |
| 181 } | |
| 182 h = mpi->h*(mpriv->height - (mpriv->height * t /mpriv->hide_time))/100; | |
| 183 } else if(mpriv->show_time && mpriv->show_ts == 0) { | |
| 184 mpriv->show_ts = GetTimerMS(); | |
| 185 return; | |
| 186 } else if(mpriv->show_ts > 0) { | |
| 187 unsigned int t = GetTimerMS() - mpriv->show_ts; | |
| 188 if(t > mpriv->show_time) | |
| 189 mpriv->show_ts = -1; | |
| 190 else | |
| 191 h = mpi->h*(mpriv->height * t /mpriv->hide_time)/100; | |
| 192 } | |
| 193 | |
| 194 y = h - mpriv->vspace; | |
| 195 | |
| 196 if(x < 0 || y < 0 || w <= 0 || h <= 0 ) | |
| 197 return; | |
| 198 | |
|
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
199 if(mpriv->bg >= 0) |
|
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
200 menu_draw_box(mpi,mpriv->bg,mpriv->bg_alpha,0,0,mpi->w,h); |
|
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
201 |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
202 if(!mpriv->child || !mpriv->raw_child){ |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
203 char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
204 sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
205 menu_text_size(input,w,mpriv->vspace,1,&lw,&lh); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
206 menu_draw_text_full(mpi,input,x,y,w,h,mpriv->vspace,1, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
207 MENU_TEXT_BOT|MENU_TEXT_LEFT, |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
208 MENU_TEXT_BOT|MENU_TEXT_LEFT); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
209 y -= lh + mpriv->vspace; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
210 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
211 |
| 8197 | 212 |
| 213 for( i = 0 ; y > mpriv->minb && i < mpriv->num_lines ; i++){ | |
| 214 int c = (ll - i) >= 0 ? ll - i : mpriv->buf_lines + ll - i; | |
| 215 menu_text_size(mpriv->lines[c],w,mpriv->vspace,1,&lw,&lh); | |
| 216 menu_draw_text_full(mpi,mpriv->lines[c],x,y,w,h,mpriv->vspace,1, | |
| 217 MENU_TEXT_BOT|MENU_TEXT_LEFT, | |
| 218 MENU_TEXT_BOT|MENU_TEXT_LEFT); | |
| 219 y -= lh + mpriv->vspace; | |
| 220 } | |
| 221 return; | |
| 222 } | |
| 223 | |
| 224 static void read_cmd(menu_t* menu,int cmd) { | |
| 225 switch(cmd) { | |
| 226 case MENU_CMD_UP: | |
| 227 break; | |
| 228 case MENU_CMD_DOWN: | |
| 229 case MENU_CMD_OK: | |
| 230 break; | |
| 231 case MENU_CMD_CANCEL: | |
| 232 menu->show = 0; | |
| 233 menu->cl = 1; | |
| 234 break; | |
| 235 } | |
| 236 } | |
| 237 | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
238 static void check_child(menu_t* menu) { |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
239 #ifndef __MINGW32__ |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
240 fd_set rfd; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
241 struct timeval tv; |
| 8297 | 242 int max_fd = mpriv->child_fd[2] > mpriv->child_fd[1] ? mpriv->child_fd[2] : |
| 243 mpriv->child_fd[1]; | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
244 int i,r,child_status,w; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
245 char buffer[256]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
246 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
247 if(!mpriv->child) return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
248 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
249 memset(&tv,0,sizeof(struct timeval)); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
250 FD_ZERO(&rfd); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
251 FD_SET(mpriv->child_fd[1],&rfd); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
252 FD_SET(mpriv->child_fd[2],&rfd); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
253 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
254 r = select(max_fd+1,&rfd, NULL, NULL, &tv); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
255 if(r == 0) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
256 r = waitpid(mpriv->child,&child_status,WNOHANG); |
| 13391 | 257 if(r < 0){ |
| 258 if(errno==ECHILD){ ///exiting childs get handled in mplayer.c | |
| 259 for(i = 0 ; i < 3 ; i++) | |
| 260 close(mpriv->child_fd[i]); | |
| 261 mpriv->child = 0; | |
| 262 mpriv->prompt = mpriv->mp_prompt; | |
| 263 //add_line(mpriv,"Child process exited"); | |
| 264 } | |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
265 else mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WaitPidError,strerror(errno)); |
| 13391 | 266 } |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
267 } else if(r < 0) { |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
268 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_SelectError); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
269 return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
270 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
271 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
272 w = 0; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
273 for(i = 1 ; i < 3 ; i++) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
274 if(FD_ISSET(mpriv->child_fd[i],&rfd)){ |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
275 if(w) mpriv->add_line = 1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
276 r = read(mpriv->child_fd[i],buffer,255); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
277 if(r < 0) |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
278 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReadErrorOnChilds, i == 1 ? "stdout":"stderr"); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
279 else if(r>0) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
280 buffer[r] = '\0'; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
281 add_string(mpriv,buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
282 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
283 w = 1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
284 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
285 } |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
286 #endif |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
287 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
288 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
289 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
290 #define close_pipe(pipe) close(pipe[0]); close(pipe[1]) |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
291 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
292 static int run_shell_cmd(menu_t* menu, char* cmd) { |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
293 #ifndef __MINGW32__ |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
294 int in[2],out[2],err[2]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
295 |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
296 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ConsoleRun,cmd); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
297 if(mpriv->child) { |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
298 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_AChildIsAlreadyRunning); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
299 return 0; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
300 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
301 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
302 pipe(in); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
303 pipe(out); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
304 pipe(err); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
305 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
306 mpriv->child = fork(); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
307 if(mpriv->child < 0) { |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
308 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ForkFailed); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
309 close_pipe(in); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
310 close_pipe(out); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
311 close_pipe(err); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
312 return 0; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
313 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
314 if(!mpriv->child) { // Chlid process |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
315 int err_fd = dup(2); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
316 FILE* errf = fdopen(err_fd,"w"); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
317 // Bind the std fd to our pipes |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
318 dup2(in[0],0); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
319 dup2(out[1],1); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
320 dup2(err[1],2); |
| 10333 | 321 execl("/bin/sh","sh","-c",cmd,(void*)NULL); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
322 fprintf(errf,"exec failed : %s\n",strerror(errno)); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
323 exit(1); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
324 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
325 // MPlayer |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
326 mpriv->child_fd[0] = in[1]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
327 mpriv->child_fd[1] = out[0]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
328 mpriv->child_fd[2] = err[0]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
329 mpriv->prompt = mpriv->child_prompt; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
330 //add_line(mpriv,"Child process started"); |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
331 #endif |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
332 return 1; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
333 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
334 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
335 static void enter_cmd(menu_t* menu) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
336 history_t* h; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
337 char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1]; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
338 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
339 sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
340 add_line(mpriv,input); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
341 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
342 if(mpriv->history == mpriv->cur_history) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
343 if(mpriv->history_size >= mpriv->history_max) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
344 history_t* i; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
345 for(i = mpriv->history ; i->prev ; i = i->prev) |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
346 /**/; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
347 i->next->prev = NULL; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
348 free(i->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
349 free(i); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
350 } else |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
351 mpriv->history_size++; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
352 h = calloc(1,sizeof(history_t)); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
353 h->size = 255; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
354 h->buffer = calloc(h->size,1); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
355 h->prev = mpriv->history; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
356 mpriv->history->next = h; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
357 mpriv->history = h; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
358 } else |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
359 mpriv->history->buffer[0] = '\0'; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
360 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
361 mpriv->cur_history = mpriv->history; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
362 //mpriv->input = mpriv->cur_history->buffer; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
363 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
364 |
| 8197 | 365 static void read_key(menu_t* menu,int c) { |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
366 if(!mpriv->child || !mpriv->raw_child) switch(c) { |
| 8197 | 367 case KEY_ESC: |
| 368 if(mpriv->hide_time) | |
| 369 mpriv->hide_ts = GetTimerMS(); | |
| 370 else | |
| 371 menu->show = 0; | |
| 372 mpriv->show_ts = 0; | |
| 373 return; | |
| 374 case KEY_ENTER: { | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
375 mp_cmd_t* c; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
376 if(mpriv->child) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
377 char *str = mpriv->cur_history->buffer; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
378 int l = strlen(str); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
379 while(l > 0) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
380 int w = write(mpriv->child_fd[0],str,l); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
381 if(w < 0) { |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
382 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
383 break; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
384 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
385 l -= w; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
386 str += w; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
387 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
388 if(write(mpriv->child_fd[0],"\n",1) < 0) |
|
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
389 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
390 enter_cmd(menu); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
391 return; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
392 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
393 c = mp_input_parse_cmd(mpriv->cur_history->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
394 enter_cmd(menu); |
| 8197 | 395 if(!c) |
| 396 add_line(mpriv,"Invalid command try help"); | |
| 397 else { | |
| 398 switch(c->id) { | |
| 399 case MP_CMD_CHELP: | |
| 12874 | 400 add_line(mpriv,"MPlayer console 0.01"); |
| 401 add_line(mpriv,"TODO: meaningful help message ;)"); | |
| 402 add_line(mpriv,"Enter any slave command"); | |
| 8197 | 403 add_line(mpriv,"exit close this console"); |
| 404 break; | |
| 405 case MP_CMD_CEXIT: | |
| 406 menu->show = 0; | |
| 407 menu->cl = 1; | |
| 408 break; | |
| 409 case MP_CMD_CHIDE: | |
| 410 if(mpriv->hide_time) | |
| 411 mpriv->hide_ts = GetTimerMS(); | |
| 412 else | |
| 413 menu->show = 0; | |
| 414 mpriv->show_ts = 0; | |
| 415 break; | |
| 14087 | 416 case MP_CMD_RUN: |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
417 run_shell_cmd(menu,c->args[0].v.s); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
418 break; |
| 8197 | 419 default: // Send the other commands to mplayer |
| 420 mp_input_queue_cmd(c); | |
| 421 } | |
| 422 } | |
| 423 return; | |
| 424 } | |
| 425 case KEY_DELETE: | |
| 426 case KEY_BS: { | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
427 unsigned int i = strlen(mpriv->cur_history->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
428 if(i > 0) |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
429 mpriv->cur_history->buffer[i-1] = '\0'; |
| 8197 | 430 return; |
| 431 } | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
432 case KEY_UP: |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
433 if(mpriv->cur_history->prev) |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
434 mpriv->cur_history = mpriv->cur_history->prev; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
435 break; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
436 case KEY_DOWN: |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
437 if(mpriv->cur_history->next) |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
438 mpriv->cur_history = mpriv->cur_history->next; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
439 break; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
440 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
441 |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
442 if(mpriv->child && mpriv->raw_child) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
443 write(mpriv->child_fd[0],&c,sizeof(int)); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
444 return; |
| 8197 | 445 } |
| 446 | |
| 447 if(isascii(c)) { | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
448 int l = strlen(mpriv->cur_history->buffer); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
449 if(l >= mpriv->cur_history->size) { |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
450 mpriv->cur_history->size += 255; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
451 mpriv->cur_history->buffer = realloc(mpriv->cur_history,mpriv->cur_history->size); |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
452 } |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
453 mpriv->cur_history->buffer[l] = (char)c; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
454 mpriv->cur_history->buffer[l+1] = '\0'; |
| 8197 | 455 } |
| 456 | |
| 457 } | |
| 458 | |
| 459 | |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
460 static int openMenu(menu_t* menu, char* args) { |
| 8197 | 461 |
| 462 | |
| 463 menu->draw = draw; | |
| 464 menu->read_cmd = read_cmd; | |
| 465 menu->read_key = read_key; | |
| 466 | |
| 467 mpriv->lines = calloc(mpriv->buf_lines,sizeof(char*)); | |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
468 mpriv->prompt = mpriv->mp_prompt; |
|
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
469 mpriv->cur_history = mpriv->history = calloc(1,sizeof(history_t)); |
| 18858 | 470 mpriv->cur_history->buffer = calloc(255,1); |
|
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
471 mpriv->cur_history->size = 255; |
| 8197 | 472 |
| 473 if(args) | |
| 474 add_line(mpriv,args); | |
| 475 | |
| 476 return 1; | |
| 477 } | |
| 478 | |
| 479 const menu_info_t menu_info_console = { | |
| 480 "MPlayer console", | |
| 481 "console", | |
| 482 "Albeu", | |
| 483 "", | |
| 484 { | |
| 485 "console_cfg", | |
| 486 sizeof(struct menu_priv_s), | |
| 487 &cfg_dflt, | |
| 488 cfg_fields | |
| 489 }, | |
|
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
490 openMenu, |
| 8197 | 491 }; |
