Scippy

SCIP

Solving Constraint Integer Programs

dialog.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file dialog.c
17  * @ingroup OTHER_CFILES
18  * @brief methods for user interface dialog
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <assert.h>
25 #include <string.h>
26 #include <ctype.h>
27 
28 #include "scip/scip.h"
29 #include "scip/def.h"
30 #include "blockmemshell/memory.h"
31 #include "scip/set.h"
32 #include "scip/pub_misc.h"
33 #include "scip/dialog.h"
34 
35 #include "scip/struct_dialog.h"
36 
37 #ifdef SCIP_WITH_READLINE
38 #include <stdio.h>
39 #include <readline/readline.h>
40 #include <readline/history.h>
41 #endif
42 
43 
44 
45 /*
46  * read line methods
47  */
48 
49 #ifdef SCIP_WITH_READLINE
50 
51 /** reads a line of input from stdin */
52 static
54  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
55  const char* prompt, /**< prompt to display */
56  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
57  )
58 {
59  char* s;
60 
61  assert(endoffile != NULL);
62 
63  s = readline(prompt);
64  if( s != NULL )
65  {
66  (void)SCIPstrncpy(&dialoghdlr->buffer[dialoghdlr->bufferpos], s, dialoghdlr->buffersize - dialoghdlr->bufferpos);
67  free(s);
68  *endoffile = FALSE;
69  }
70  else
71  *endoffile = TRUE;
72 
73  return SCIP_OKAY;
74 }
75 
76 /** puts the given string on the command history */
77 static
79  const char* s /**< string to add to the command history */
80  )
81 {
82  add_history(s);
83 
84  return SCIP_OKAY;
85 }
86 
87 /** returns the current length of the history list */
88 static
90  void
91  )
92 {
93 #ifndef NO_REMOVE_HISTORY
94  return history_length;
95 #else
96  return 0;
97 #endif
98 }
99 
100 /** removes a single element from the history list */
101 static
103  int pos /**< list position of history entry to remove */
104  )
105 {
106 #ifndef NO_REMOVE_HISTORY
107  HIST_ENTRY* entry;
108 
109  entry = remove_history(pos);
110 
111  /* Free readline/history storage: there seem to be differences in the versions (and the amount of
112  * data to be freed). The following should be a good approximation; if it doesn't work define
113  * NO_REMOVE_HISTORY - see the INSTALL file. This will produce minor memory leaks.
114  */
115 #if RL_VERSION_MAJOR >= 5
116  (void)free_history_entry(entry);
117 #else
118  if( entry != NULL )
119  {
120  free((void*)entry->line);
121  free(entry);
122  }
123 #endif
124 #endif
125 
126  return SCIP_OKAY;
127 }
128 
129 /** writes command history into file of the specified name */
130 static
132  const char* filename /**< name of file to (over)write history to */
133  )
134 {
135  int retval = write_history(filename);
136 
137  if( retval == 0 )
138  return SCIP_OKAY;
139  else
140  return SCIP_FILECREATEERROR;
141 }
142 
143 #else
144 
145 /** reads a line of input from stdin */
146 static
148  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
149  const char* prompt, /**< prompt to display */
150  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
151  )
152 {
153  char* s;
154 
155  assert(dialoghdlr != NULL);
156  assert(dialoghdlr->buffer != NULL);
157  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
158  assert(dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
159  assert(endoffile != NULL);
160 
161  /* check for EOF (due to CTRL-D or unexpected end of piped-in file) */
162  if( feof(stdin) )
163  *endoffile = TRUE;
164  else
165  {
166  char* result;
167 
168  /* display prompt */
169  printf("%s", prompt);
170 
171  /* read line from stdin */
172  result = fgets(&dialoghdlr->buffer[dialoghdlr->bufferpos], dialoghdlr->buffersize - dialoghdlr->bufferpos, stdin);
173  assert(result != NULL);
174  (void) result; /* disable compiler warning [-Wunused-result] */
175 
176  /* replace newline with \0 */
177  s = strchr(&dialoghdlr->buffer[dialoghdlr->bufferpos], '\n');
178  if( s != NULL )
179  *s = '\0';
180  *endoffile = FALSE;
181  }
182 
183  return SCIP_OKAY;
184 }
185 
186 /** puts the given string on the command history */ /*lint -e715*/
187 static
189  const char* s /**< string to add to the command history */
190  )
191 { /*lint --e{715}*/
192  /* nothing to do here */
193  return SCIP_OKAY;
194 }
195 
196 /** returns the current length of the history list */
197 static
199  void
200  )
201 {
202  return 0;
203 }
204 
205 /** removes a single element from the history list */ /*lint -e715*/
206 static
208  int pos /**< list position of history entry to remove */
209  )
210 { /*lint --e{715}*/
211  /* nothing to do here */
212  return SCIP_OKAY;
213 }
214 
215 
216 /** writes command history into file of the specified name */
217 static
219  const char* filename /**< name of file to (over)write history to */
220  )
221 { /*lint --e{715}*/
222  assert(filename != NULL);
223 
224  /* nothing to do here */
225  return SCIP_OKAY;
226 }
227 
228 #endif
229 
230 /** frees a single linelist entry, but not its successors */
231 static
233  SCIP_LINELIST** linelist /**< pointer to line list */
234  )
235 {
236  assert(linelist != NULL);
237 
238  BMSfreeMemoryArray(&(*linelist)->inputline);
239  BMSfreeMemory(linelist);
240 }
241 
242 /** frees a linelist entry and all of its successors */
243 static
245  SCIP_LINELIST** linelist /**< pointer to line list */
246  )
247 {
248  assert(linelist != NULL);
249 
250  while( *linelist != NULL )
251  {
252  SCIP_LINELIST* nextline;
253 
254  nextline = (*linelist)->nextline;
255  linelistFree(linelist);
256  *linelist = nextline;
257  }
258 }
259 
260 /** reads a line of input from stdin or from the stored input lines in the input list */
261 static
263  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
264  const char* prompt, /**< prompt to display */
265  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
266  )
267 {
268  assert(dialoghdlr != NULL);
269  assert(dialoghdlr->buffer != NULL);
270  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
271  assert(dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
272  assert(endoffile != NULL);
273 
274  *endoffile = FALSE;
275 
276  if( dialoghdlr->inputlist == NULL )
277  {
278  /* read a line from stdin */
279  SCIP_CALL( readLine(dialoghdlr, prompt, endoffile) );
280  }
281  else
282  {
283  SCIP_LINELIST* nextline;
284 
285  /* copy the next input line into the input buffer */
286  (void)SCIPstrncpy(&dialoghdlr->buffer[dialoghdlr->bufferpos], dialoghdlr->inputlist->inputline, dialoghdlr->buffersize - dialoghdlr->bufferpos);
287 
288  /* free the input line */
289  nextline = dialoghdlr->inputlist->nextline;
290  if( dialoghdlr->inputlistptr == &(dialoghdlr->inputlist->nextline) )
291  dialoghdlr->inputlistptr = &dialoghdlr->inputlist;
292  linelistFree(&dialoghdlr->inputlist);
293  dialoghdlr->inputlist = nextline;
294  assert(dialoghdlr->inputlistptr != NULL);
295  assert(*dialoghdlr->inputlistptr == NULL);
296  }
297 
298  return SCIP_OKAY;
299 }
300 
301 
302 
303 
304 /*
305  * dialog handler
306  */
307 
308 /** copies the given dialog to a new scip */
310  SCIP_DIALOG* dialog, /**< dialog */
311  SCIP_SET* set /**< SCIP_SET of SCIP to copy to */
312  )
313 {
314  assert(dialog != NULL);
315  assert(set != NULL);
316  assert(set->scip != NULL);
317 
318  if( dialog->dialogcopy != NULL )
319  {
320  SCIPsetDebugMsg(set, "including dialog %s in subscip %p\n", SCIPdialogGetName(dialog), (void*)set->scip);
321  SCIP_CALL( dialog->dialogcopy(set->scip, dialog) );
322  }
323  return SCIP_OKAY;
324 }
325 
326 /** creates a dialog handler */
328  SCIP_SET* set, /**< global SCIP settings */
329  SCIP_DIALOGHDLR** dialoghdlr /**< pointer to store dialog handler */
330  )
331 { /*lint --e{715}*/
332 #ifdef SCIP_WITH_READLINE
333  char readlineversion[20];
334 #endif
335 
336  assert(set != NULL);
337  assert(dialoghdlr != NULL);
338 
339  SCIP_ALLOC( BMSallocMemory(dialoghdlr) );
340  (*dialoghdlr)->rootdialog = NULL;
341  (*dialoghdlr)->inputlist = NULL;
342  (*dialoghdlr)->inputlistptr = &(*dialoghdlr)->inputlist;
343  (*dialoghdlr)->buffersize = SCIP_MAXSTRLEN;
344  (*dialoghdlr)->nprotectedhistelems = -1;
345  SCIP_ALLOC( BMSallocMemoryArray(&(*dialoghdlr)->buffer, (*dialoghdlr)->buffersize) );
346 
347  SCIPdialoghdlrClearBuffer(*dialoghdlr);
348 
349 #ifdef SCIP_WITH_READLINE
350  (void) SCIPsnprintf(readlineversion, sizeof(readlineversion), "Readline %s", rl_library_version);
351  SCIP_CALL( SCIPsetIncludeExternalCode(set, readlineversion, "GNU library for command line editing (gnu.org/s/readline)") );
352 #endif
353 
354  return SCIP_OKAY;
355 }
356 
357 /** frees a dialog handler and it's dialog tree */
359  SCIP* scip, /**< SCIP data structure */
360  SCIP_DIALOGHDLR** dialoghdlr /**< pointer to dialog handler */
361  )
362 {
363  assert(dialoghdlr != NULL);
364  if( *dialoghdlr == NULL )
365  return SCIP_OKAY;
366 
367  SCIP_CALL( SCIPdialoghdlrSetRoot(scip, *dialoghdlr, NULL) );
368  linelistFreeAll(&(*dialoghdlr)->inputlist);
369  BMSfreeMemoryArray(&(*dialoghdlr)->buffer);
370  BMSfreeMemory(dialoghdlr);
371 
372  return SCIP_OKAY;
373 }
374 
375 /** executes the root dialog of the dialog handler */
377  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
378  SCIP_SET* set /**< global SCIP settings */
379  )
380 {
381  SCIP_DIALOG* dialog;
382 
383  assert(dialoghdlr != NULL);
384  assert(dialoghdlr->buffer != NULL);
385 
386  /* clear the buffer, start with the root dialog */
387  SCIPdialoghdlrClearBuffer(dialoghdlr);
388  dialog = dialoghdlr->rootdialog;
389 
390  /* execute dialogs until a NULL is returned as next dialog */
391  while( dialog != NULL )
392  {
393  SCIP_CALL( SCIPdialogExec(dialog, set, dialoghdlr, &dialog) );
394 
395  /* reset buffer, it is was consumed completely */
396  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0' )
397  SCIPdialoghdlrClearBuffer(dialoghdlr);
398  }
399 
400  return SCIP_OKAY;
401 }
402 
403 /** makes given dialog the root dialog of dialog handler; captures dialog and releases former root dialog */
405  SCIP* scip, /**< SCIP data structure */
406  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
407  SCIP_DIALOG* dialog /**< dialog to be the root */
408  )
409 {
410  assert(dialoghdlr != NULL);
411 
412  if( dialoghdlr->rootdialog != NULL )
413  {
414  SCIP_CALL( SCIPdialogRelease(scip, &dialoghdlr->rootdialog) );
415  }
416  assert(dialoghdlr->rootdialog == NULL);
417 
418  dialoghdlr->rootdialog = dialog;
419 
420  if( dialog != NULL )
421  SCIPdialogCapture(dialog);
422 
423  return SCIP_OKAY;
424 }
425 
426 /** returns the root dialog of the dialog handler */
428  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
429  )
430 {
431  assert(dialoghdlr != NULL);
432 
433  return dialoghdlr->rootdialog;
434 }
435 
436 /** clears the input command buffer of the dialog handler */
438  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
439  )
440 {
441  assert(dialoghdlr != NULL);
442 
443  dialoghdlr->buffer[0] = '\0';
444  dialoghdlr->bufferpos = 0;
445 }
446 
447 /** returns TRUE iff input command buffer is empty */
449  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
450  )
451 {
452  assert(dialoghdlr != NULL);
453  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
454 
455  return (dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
456 }
457 
458 /** returns the next line in the handler's command buffer; if the buffer is empty, displays the given prompt or the
459  * current dialog's path and asks the user for further input; the user must not free or modify the returned string
460  */
462  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
463  SCIP_DIALOG* dialog, /**< current dialog */
464  const char* prompt, /**< prompt to display, or NULL to display the current dialog's path */
465  char** inputline, /**< pointer to store the complete line in the handler's command buffer */
466  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
467  )
468 {
469  char path[SCIP_MAXSTRLEN+1];
470  char p[SCIP_MAXSTRLEN];
471 
472  assert(dialoghdlr != NULL);
473  assert(dialoghdlr->buffer != NULL);
474  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
475  assert(inputline != NULL);
476 
477  /* get input from the user, if the buffer is empty */
478  if( SCIPdialoghdlrIsBufferEmpty(dialoghdlr) )
479  {
480  int len;
481 
482  /* clear the buffer */
483  SCIPdialoghdlrClearBuffer(dialoghdlr);
484 
485  if( prompt == NULL )
486  {
487  /* use current dialog's path as prompt */
488  SCIPdialogGetPath(dialog, '/', path);
489  (void) SCIPsnprintf(p, SCIP_MAXSTRLEN, "%s> ", path);
490  prompt = p;
491  }
492 
493  /* read command line from stdin or from the input line list */
494  SCIP_CALL( readInputLine(dialoghdlr, prompt, endoffile) );
495 
496  /* strip trailing spaces */
497  len = (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
498  if( len > 0 )
499  {
500  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1]) )
501  {
502  dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1] = '\0';
503  len--;
504  }
505  }
506 
507  /* insert command in command history */
508  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
509  {
510  SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, NULL, &dialoghdlr->buffer[dialoghdlr->bufferpos], FALSE) );
511  }
512  }
513 
514  /* the last character in the buffer must be a '\0' */
515  dialoghdlr->buffer[dialoghdlr->buffersize-1] = '\0';
516 
517  /* skip leading spaces: find start of first word */
518  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
519  dialoghdlr->bufferpos++;
520 
521  /* copy the complete line */
522  *inputline = &dialoghdlr->buffer[dialoghdlr->bufferpos];
523 
524  /* go to the end of the line */
525  dialoghdlr->bufferpos += (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
526 
527  if( dialoghdlr->buffer[dialoghdlr->buffersize-1] == '\0' )
528  *endoffile = TRUE;
529 
530  return SCIP_OKAY;
531 }
532 
533 
534 /** returns the next word in the handler's command buffer; if the buffer is empty, displays the given prompt or the
535  * current dialog's path and asks the user for further input; the user must not free or modify the returned string
536  */
538  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
539  SCIP_DIALOG* dialog, /**< current dialog */
540  const char* prompt, /**< prompt to display, or NULL to display the current dialog's path */
541  char** inputword, /**< pointer to store the next word in the handler's command buffer */
542  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
543  )
544 {
545  char path[SCIP_MAXSTRLEN+1];
546  char p[SCIP_MAXSTRLEN];
547  char* firstword;
548  int pos;
549 
550  assert(dialoghdlr != NULL);
551  assert(dialoghdlr->buffer != NULL);
552  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
553  assert(inputword != NULL);
554  assert(endoffile != NULL);
555 
556  *endoffile = FALSE;
557 
558  /* get input from the user, if the buffer is empty */
559  if( SCIPdialoghdlrIsBufferEmpty(dialoghdlr) )
560  {
561  int len;
562 
563  /* clear the buffer */
564  SCIPdialoghdlrClearBuffer(dialoghdlr);
565 
566  if( prompt == NULL )
567  {
568  /* use current dialog's path as prompt */
569  SCIPdialogGetPath(dialog, '/', path);
570  (void) SCIPsnprintf(p, SCIP_MAXSTRLEN, "%s> ", path);
571  prompt = p;
572  }
573 
574  /* read command line from stdin or from the input line list */
575  SCIP_CALL( readInputLine(dialoghdlr, prompt, endoffile) );
576 
577  /* strip trailing spaces */
578  len = (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
579  if( len > 0 )
580  {
581  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1]) )
582  {
583  dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1] = '\0';
584  len--;
585  }
586  }
587 
588  /* insert command in command history */
589  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
590  {
591  SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, NULL, &dialoghdlr->buffer[dialoghdlr->bufferpos], FALSE) );
592  }
593  }
594 
595  /* the last character in the buffer must be a '\0' */
596  dialoghdlr->buffer[dialoghdlr->buffersize-1] = '\0';
597 
598  /* skip leading spaces: find start of first word */
599  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
600  dialoghdlr->bufferpos++;
601  firstword = &dialoghdlr->buffer[dialoghdlr->bufferpos];
602 
603  pos = dialoghdlr->bufferpos;
604  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && !isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
605  {
606  assert(pos <= dialoghdlr->bufferpos);
607 
608  switch( dialoghdlr->buffer[dialoghdlr->bufferpos] )
609  {
610  case '"':
611  dialoghdlr->bufferpos++;
612  /* read characters as they are until the next " */
613  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && dialoghdlr->buffer[dialoghdlr->bufferpos] != '"' )
614  {
615  /* watch out for \" and \\ which should be treated as " and \, respectively */
616  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\\'
617  && (dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '"'
618  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\\') )
619  {
620  dialoghdlr->bufferpos++;
621  }
622  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
623  pos++;
624  dialoghdlr->bufferpos++;
625  }
626  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '"' )
627  dialoghdlr->bufferpos++; /* skip final " */
628  break;
629  case '\'':
630  dialoghdlr->bufferpos++;
631  /* read characters as they are until the next ' */
632  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && dialoghdlr->buffer[dialoghdlr->bufferpos] != '\'' )
633  {
634  /* watch out for \' and \\ which should be treated as ' and \, respectively */
635  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\\'
636  && (dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\''
637  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\\') )
638  {
639  dialoghdlr->bufferpos++;
640  }
641  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
642  pos++;
643  dialoghdlr->bufferpos++;
644  }
645  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\'' )
646  dialoghdlr->bufferpos++; /* skip final ' */
647  break;
648  case '\\':
649  /* if the next character is a space, a ", or a ', read next character as it is;
650  * otherwise, treat the \ as normal character
651  */
652  if( dialoghdlr->buffer[dialoghdlr->bufferpos+1] == ' '
653  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '"'
654  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\'' )
655  {
656  dialoghdlr->bufferpos++;
657  }
658  /*lint -fallthrough*/
659  default:
660  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
661  pos++;
662  dialoghdlr->bufferpos++;
663  break;
664  }
665  }
666  assert(pos <= dialoghdlr->bufferpos);
667 
668  /* move buffer to the next position */
669  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
670  dialoghdlr->bufferpos++;
671 
672  /* truncate the command word in the buffer */
673  if( dialoghdlr->buffer[pos] != '\0' )
674  dialoghdlr->buffer[pos] = '\0';
675 
676  /* remove additional spaces */
677  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
678  dialoghdlr->bufferpos++;
679 
680  *inputword = firstword;
681 
682  SCIPdebugMessage("next word: <%s>\n", *inputword);
683 
684  return SCIP_OKAY;
685 }
686 
687 /** adds a single line of input to the dialog handler which is treated as if the user entered the command line */
689  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
690  const char* inputline /**< input line to add */
691  )
692 {
693  SCIP_LINELIST* linelist;
694  SCIP_RETCODE retcode = SCIP_OKAY;
695 
696  assert(dialoghdlr != NULL);
697  assert(dialoghdlr->inputlistptr != NULL);
698  assert(*dialoghdlr->inputlistptr == NULL);
699  assert(inputline != NULL);
700 
701  SCIP_ALLOC( BMSallocMemory(&linelist) );
702  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&linelist->inputline, inputline, strlen(inputline)+1), TERMINATE );
703  linelist->nextline = NULL;
704  *dialoghdlr->inputlistptr = linelist;
705  dialoghdlr->inputlistptr = &linelist->nextline;
706 
707  TERMINATE:
708  if( retcode != SCIP_OKAY )
709  BMSfreeMemory(&linelist);
710 
711  return retcode;
712 }
713 
714 /** adds a command to the command history of the dialog handler; if a dialog is given, the command is preceeded
715  * by the dialog's command path; if no command is given, only the path to the dialog is added to the command history
716  */
718  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
719  SCIP_DIALOG* dialog, /**< current dialog, or NULL */
720  const char* command, /**< command string to add to the command history, or NULL */
721  SCIP_Bool escapecommand /**< should special characters in command be prefixed by an escape char? */
722  )
723 {
724  char s[SCIP_MAXSTRLEN];
725  char h[SCIP_MAXSTRLEN+1];
726  SCIP_Bool cleanuphistory;
727 
728  assert(dialoghdlr != NULL);
729 
730  /* the current history list should be cleaned up if a dialog is given (i.e. the command is not partial) */
731  cleanuphistory = (dialog != NULL);
732 
733  /* generate the string to add to the history */
734  s[SCIP_MAXSTRLEN-1] = '\0';
735 
736  if( command != NULL )
737  {
738  if( escapecommand )
739  SCIPescapeString(h, SCIP_MAXSTRLEN, command);
740  else
741  (void)SCIPstrncpy(h, command, SCIP_MAXSTRLEN);
742  }
743  else
744  h[0] = '\0';
745 
746  while( dialog != NULL && dialog != dialoghdlr->rootdialog )
747  {
748  if( h[0] == '\0' )
749  (void)SCIPstrncpy(h, dialog->name, SCIP_MAXSTRLEN);
750  else
751  {
752  (void)SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s %s", dialog->name, h);
753  (void)SCIPstrncpy(h, s, SCIP_MAXSTRLEN);
754  }
755  dialog = dialog->parent;
756  }
757 
758  /* clean up the unmarked history entries */
759  if( cleanuphistory )
760  {
761  int i;
762 
763  for( i = getHistoryLength()-1; i >= dialoghdlr->nprotectedhistelems; --i )
764  {
765  SCIP_CALL( removeHistory(i) );
766  }
767  }
768 
769  /* add command to history */
770  if( h[0] != '\0' )
771  {
772  SCIP_CALL( addHistory(h) );
773  }
774 
775  /* if the history string was a full command line, protect the history entry from future cleanups */
776  if( cleanuphistory )
777  {
778  dialoghdlr->nprotectedhistelems = getHistoryLength();
779  }
780 
781  return SCIP_OKAY;
782 }
783 
784 
785 
786 
787 /*
788  * dialog
789  */
790 
791 /** ensures, that sub-dialogs array can store at least the given number of sub-dialogs */
792 static
794  SCIP_DIALOG* dialog, /**< dialog */
795  SCIP_SET* set, /**< global SCIP settings */
796  int num /**< minimal storage size for sub-dialogs */
797  )
798 {
799  assert(dialog != NULL);
800 
801  if( num > dialog->subdialogssize )
802  {
803  int newsize;
804 
805  newsize = SCIPsetCalcMemGrowSize(set, num);
806  SCIP_ALLOC( BMSreallocMemoryArray(&(dialog->subdialogs), newsize) );
807  dialog->subdialogssize = newsize;
808  }
809  assert(num <= dialog->subdialogssize);
810 
811  return SCIP_OKAY;
812 }
813 
814 /** creates and captures a user interface dialog */
816  SCIP_DIALOG** dialog, /**< pointer to store the dialog */
817  SCIP_DECL_DIALOGCOPY ((*dialogcopy)), /**< copy method of dialog or NULL if you don't want to copy your plugin into sub-SCIPs */
818  SCIP_DECL_DIALOGEXEC ((*dialogexec)), /**< execution method of dialog */
819  SCIP_DECL_DIALOGDESC ((*dialogdesc)), /**< description output method of dialog, or NULL */
820  SCIP_DECL_DIALOGFREE ((*dialogfree)), /**< destructor of dialog to free user data, or NULL */
821  const char* name, /**< name of dialog: command name appearing in parent's dialog menu */
822  const char* desc, /**< description of dialog used if description output method is NULL */
823  SCIP_Bool issubmenu, /**< is the dialog a sub-menu? */
824  SCIP_DIALOGDATA* dialogdata /**< user defined dialog data */
825  )
826 {
827  SCIP_RETCODE retcode;
828 
829  assert(dialog != NULL);
830  assert(name != NULL);
831 
832  retcode = SCIP_OKAY;
833 
834  SCIP_ALLOC( BMSallocMemory(dialog) );
835  (*dialog)->dialogcopy = dialogcopy;
836  (*dialog)->dialogexec = dialogexec;
837  (*dialog)->dialogdesc = dialogdesc;
838  (*dialog)->dialogfree = dialogfree;
839 
840  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&(*dialog)->name, name, strlen(name)+1), TERMINATE );
841  if( desc != NULL )
842  {
843  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&(*dialog)->desc, desc, strlen(desc)+1), TERMINATE );
844  }
845  else
846  (*dialog)->desc = NULL;
847 
848  (*dialog)->issubmenu = issubmenu;
849  (*dialog)->parent = NULL;
850  (*dialog)->subdialogs = NULL;
851  (*dialog)->nsubdialogs = 0;
852  (*dialog)->subdialogssize = 0;
853  (*dialog)->nuses = 0;
854  (*dialog)->dialogdata = dialogdata;
855 
856  /* capture dialog */
857  SCIPdialogCapture(*dialog);
858 
859  TERMINATE:
860  if( retcode != SCIP_OKAY )
861  {
862  BMSfreeMemoryArrayNull(&(*dialog)->name);
863  BMSfreeMemory(dialog);
864  }
865 
866  return retcode;
867 }
868 
869 /** frees dialog and all of its sub-dialogs */
870 static
872  SCIP* scip, /**< SCIP data structure */
873  SCIP_DIALOG** dialog /**< pointer to dialog */
874  )
875 {
876  int i;
877 
878  assert(dialog != NULL);
879  assert(*dialog != NULL);
880  assert((*dialog)->nuses == 0);
881 
882  /* call destructor of dialog */
883  if( (*dialog)->dialogfree != NULL )
884  {
885  SCIP_CALL( (*dialog)->dialogfree(scip, *dialog) );
886  }
887 
888  /* release sub-dialogs */
889  for( i = 0; i < (*dialog)->nsubdialogs; ++i )
890  {
891  SCIP_CALL( SCIPdialogRelease(scip, &(*dialog)->subdialogs[i]) );
892  }
893  BMSfreeMemoryArrayNull(&(*dialog)->subdialogs);
894 
895  BMSfreeMemoryArrayNull(&(*dialog)->name);
896  BMSfreeMemoryArrayNull(&(*dialog)->desc);
897  BMSfreeMemory(dialog);
898 
899  return SCIP_OKAY;
900 }
901 
902 /** captures a dialog */
904  SCIP_DIALOG* dialog /**< dialog */
905  )
906 {
907  assert(dialog != NULL);
908 
909  dialog->nuses++;
910 }
911 
912 /** releases a dialog */
914  SCIP* scip, /**< SCIP data structure */
915  SCIP_DIALOG** dialog /**< pointer to dialog */
916  )
917 {
918  assert(dialog != NULL);
919 
920  (*dialog)->nuses--;
921  if( (*dialog)->nuses == 0 )
922  {
923  SCIP_CALL( dialogFree(scip, dialog) );
924  }
925 
926  return SCIP_OKAY;
927 }
928 
929 /** executes dialog */
931  SCIP_DIALOG* dialog, /**< dialog */
932  SCIP_SET* set, /**< global SCIP settings */
933  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
934  SCIP_DIALOG** nextdialog /**< pointer to store the next dialog to process */
935  )
936 {
937  assert(dialog != NULL);
938  assert(dialog->dialogexec != NULL);
939  assert(set != NULL);
940  assert(nextdialog != NULL);
941 
942  SCIP_CALL( dialog->dialogexec(set->scip, dialog, dialoghdlr, nextdialog) );
943 
944  return SCIP_OKAY;
945 }
946 
947 /** comparison method for sorting dialogs w.r.t. to their name */
948 static
950 {
951  return strcmp( SCIPdialogGetName((SCIP_DIALOG*)elem1), SCIPdialogGetName((SCIP_DIALOG*)elem2) );
952 }
953 
954 /** adds a sub-dialog to the given dialog as menu entry and captures the sub-dialog */
956  SCIP_DIALOG* dialog, /**< dialog */
957  SCIP_SET* set, /**< global SCIP settings */
958  SCIP_DIALOG* subdialog /**< sub-dialog to add as menu entry in dialog */
959  )
960 {
961  assert(dialog != NULL);
962  assert(subdialog != NULL);
963 
964  /* check, if sub-dialog already exists */
965  if( SCIPdialogHasEntry(dialog, SCIPdialogGetName(subdialog)) )
966  {
967  SCIPerrorMessage("dialog entry with name <%s> already exists in dialog <%s>\n",
968  SCIPdialogGetName(subdialog), SCIPdialogGetName(dialog));
969  return SCIP_INVALIDDATA;
970  }
971 
972  /* resize the sub-dialogs array */
973  SCIP_CALL( ensureSubdialogMem(dialog, set, dialog->nsubdialogs+1) );
974 
975  /* link the dialogs as parent-child pair; the sub-dialogs are sorted non-decreasing w.r.t. their name */
976  SCIPsortedvecInsertPtr((void**)dialog->subdialogs, dialogComp, (void*)subdialog, &dialog->nsubdialogs, NULL);
977  subdialog->parent = dialog;
978 
979  /* capture sub-dialog */
980  SCIPdialogCapture(subdialog);
981 
982  return SCIP_OKAY;
983 }
984 
985 /** returns TRUE iff a dialog entry matching exactly the given name is existing in the given dialog */
987  SCIP_DIALOG* dialog, /**< dialog */
988  const char* entryname /**< name of the dialog entry to find */
989  )
990 {
991  SCIP_DIALOG** subdialogs;
992  int nsubdialogs;
993  int i;
994 
995  assert(dialog != NULL);
996  assert(entryname != NULL);
997 
998  /* check entryname w.r.t. available dialog options */
999  subdialogs = SCIPdialogGetSubdialogs(dialog);
1000  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1001  for( i = 0; i < nsubdialogs; ++i )
1002  {
1003  /* check, if the sub-dialog's name matches entryname */
1004  if( strcmp(entryname, SCIPdialogGetName(subdialogs[i])) == 0 )
1005  return TRUE;
1006  }
1007 
1008  return FALSE;
1009 }
1010 
1011 /** searches the dialog for entries corresponding to the given name;
1012  * If a complete match is found, the entry is returned as "subdialog" and
1013  * the return value is 1.
1014  * If no dialog entry completely matches the given "entryname", the number
1015  * of entries with names beginning with "entryname" is returned. If this
1016  * number is 1, the single match is returned as "subdialog". Otherwise,
1017  * "subdialog" is set to NULL.
1018  */
1020  SCIP_DIALOG* dialog, /**< dialog */
1021  const char* entryname, /**< name of the dialog entry to find */
1022  SCIP_DIALOG** subdialog /**< pointer to store the found dialog entry */
1023  )
1024 {
1025  SCIP_DIALOG** subdialogs;
1026  unsigned int namelen;
1027  int nsubdialogs;
1028  int nfound;
1029  int i;
1030 
1031  assert(dialog != NULL);
1032  assert(entryname != NULL);
1033  assert(subdialog != NULL);
1034 
1035  *subdialog = NULL;
1036 
1037  /* check entryname w.r.t. available dialog options */
1038  subdialogs = SCIPdialogGetSubdialogs(dialog);
1039  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1040  namelen = (unsigned int) strlen(entryname);
1041  nfound = 0;
1042  for( i = 0; i < nsubdialogs; ++i )
1043  {
1044  /* check, if the beginning of the sub-dialog's name matches entryname */
1045  if( strncmp(entryname, SCIPdialogGetName(subdialogs[i]), namelen) == 0 )
1046  {
1047  *subdialog = subdialogs[i];
1048  nfound++;
1049 
1050  /* if entryname exactly matches the sub-dialog's name, use this sub-dialog */
1051  if( namelen == (unsigned int) strlen(SCIPdialogGetName(subdialogs[i])) )
1052  return 1;
1053  }
1054  }
1055 
1056  if( nfound != 1 )
1057  *subdialog = NULL;
1058 
1059  return nfound;
1060 }
1061 
1062 /** displays the dialog's menu */
1064  SCIP_DIALOG* dialog, /**< dialog */
1065  SCIP* scip /**< SCIP data structure */
1066  )
1067 {
1068  int i;
1069 
1070  assert(dialog != NULL);
1071 
1072  /* display the dialog's sub menus */
1073  for( i = 0; i < dialog->nsubdialogs; ++i )
1074  {
1075  if( SCIPdialogIsSubmenu(dialog->subdialogs[i]) )
1076  {
1077  SCIP_CALL( SCIPdialogDisplayMenuEntry(dialog->subdialogs[i], scip) );
1078  }
1079  }
1080 
1081  /* display the dialog's menu options */
1082  for( i = 0; i < dialog->nsubdialogs; ++i )
1083  {
1084  if( !SCIPdialogIsSubmenu(dialog->subdialogs[i]) )
1085  {
1086  SCIP_CALL( SCIPdialogDisplayMenuEntry(dialog->subdialogs[i], scip) );
1087  }
1088  }
1089 
1090  if( dialog->nsubdialogs == 0 )
1091  SCIPdialogMessage(scip, NULL, "<no options available>\n");
1092 
1093  return SCIP_OKAY;
1094 }
1095 
1096 /** displays the entry for the dialog in it's parent's menu */
1098  SCIP_DIALOG* dialog, /**< dialog */
1099  SCIP* scip /**< SCIP data structure */
1100  )
1101 {
1102  char name[SCIP_MAXSTRLEN];
1103 
1104  assert(dialog != NULL);
1105 
1106  /* display the dialog's name */
1107  if( dialog->issubmenu )
1108  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "<%s>", dialog->name);
1109  else
1110  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", dialog->name);
1111  SCIPdialogMessage(scip, NULL, " %-21s ", name);
1112  if( strlen(name) > 21 )
1113  {
1114  /* break the line, and start the description in the next line */
1115  SCIPdialogMessage(scip, NULL, "\n --> ");
1116  }
1117 
1118  /* display the dialog's description */
1119  if( dialog->dialogdesc != NULL )
1120  {
1121  SCIP_CALL( dialog->dialogdesc(scip, dialog) );
1122  }
1123  else
1124  SCIPdialogMessage(scip, NULL, "%s",dialog->desc);
1125  SCIPdialogMessage(scip, NULL, "\n");
1126 
1127  return SCIP_OKAY;
1128 }
1129 
1130 /** displays all dialog entries with names starting with the given "entryname" */
1132  SCIP_DIALOG* dialog, /**< dialog */
1133  SCIP* scip, /**< SCIP data structure */
1134  const char* entryname /**< name of the dialog entry to find */
1135  )
1136 {
1137  SCIP_DIALOG** subdialogs;
1138  unsigned int namelen;
1139  int nsubdialogs;
1140  int i;
1141 
1142  assert(dialog != NULL);
1143  assert(entryname != NULL);
1144 
1145  /* check entryname w.r.t. available dialog options */
1146  subdialogs = SCIPdialogGetSubdialogs(dialog);
1147  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1148  namelen = (unsigned int) strlen(entryname);
1149  for( i = 0; i < nsubdialogs; ++i )
1150  {
1151  /* check, if the beginning of the sub-dialog's name matches entryname */
1152  if( strncmp(entryname, SCIPdialogGetName(subdialogs[i]), namelen) == 0 )
1153  {
1154  SCIP_CALL( SCIPdialogDisplayMenuEntry(subdialogs[i], scip) );
1155  }
1156  }
1157 
1158  return SCIP_OKAY;
1159 }
1160 
1161 /** gets the name of the current path in the dialog tree, separated by the given character */
1163  SCIP_DIALOG* dialog, /**< dialog */
1164  const char sepchar, /**< separation character to insert in path */
1165  char* path /**< string buffer to store the path */
1166  )
1167 {
1168  char s[SCIP_MAXSTRLEN];
1169 
1170  assert(dialog != NULL);
1171 
1172  (void)SCIPstrncpy(path, dialog->name, SCIP_MAXSTRLEN);
1173 
1174  dialog = dialog->parent;
1175  while( dialog != NULL )
1176  {
1177  (void)SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s%c%s", dialog->name, sepchar, path);
1178  (void)SCIPstrncpy(path, s, SCIP_MAXSTRLEN);
1179  dialog = dialog->parent;
1180  }
1181 }
1182 
1183 /** gets the command name of the dialog */
1184 const char* SCIPdialogGetName(
1185  SCIP_DIALOG* dialog /**< dialog */
1186  )
1187 {
1188  assert(dialog != NULL);
1189 
1190  return dialog->name;
1191 }
1192 
1193 /** gets the description of the dialog */
1194 const char* SCIPdialogGetDesc(
1195  SCIP_DIALOG* dialog /**< dialog */
1196  )
1197 {
1198  assert(dialog != NULL);
1199 
1200  return dialog->desc;
1201 }
1202 
1203 /** returns whether the dialog is a sub menu */
1205  SCIP_DIALOG* dialog /**< dialog */
1206  )
1207 {
1208  assert(dialog != NULL);
1209 
1210  return dialog->issubmenu;
1211 }
1212 
1213 /** gets the parent dialog of the given dialog */
1215  SCIP_DIALOG* dialog /**< dialog */
1216  )
1217 {
1218  assert(dialog != NULL);
1219 
1220  return dialog->parent;
1221 }
1222 
1223 /** gets the array of sub-dialogs associated with the given dialog */
1225  SCIP_DIALOG* dialog /**< dialog */
1226  )
1227 {
1228  assert(dialog != NULL);
1229 
1230  return dialog->subdialogs;
1231 }
1232 
1233 /** gets the number of sub-dialogs associated with the given dialog */
1235  SCIP_DIALOG* dialog /**< dialog */
1236  )
1237 {
1238  assert(dialog != NULL);
1239 
1240  return dialog->nsubdialogs;
1241 }
1242 
1243 /** gets the user defined data associated with the given dialog */
1245  SCIP_DIALOG* dialog /**< dialog */
1246  )
1247 {
1248  assert(dialog != NULL);
1249 
1250  return dialog->dialogdata;
1251 }
1252 
1253 /** sets user data of dialog; user has to free old data in advance! */
1255  SCIP_DIALOG* dialog, /**< dialog */
1256  SCIP_DIALOGDATA* dialogdata /**< new dialog user data */
1257  )
1258 {
1259  assert(dialog != NULL);
1260 
1261  dialog->dialogdata = dialogdata;
1262 }
1263 
1264 /** writes command history to specified filename */
1266  const char* filename /**< file name for (over)writing history */
1267  )
1268 {
1269  return writeHistory(filename);
1270 }
void SCIPescapeString(char *t, int bufsize, const char *s)
Definition: misc.c:10562
SCIP_RETCODE SCIPdialoghdlrGetWord(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *prompt, char **inputword, SCIP_Bool *endoffile)
Definition: dialog.c:537
static SCIP_RETCODE dialogFree(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:871
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:140
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:182
SCIP_Bool SCIPdialoghdlrIsBufferEmpty(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:448
SCIP_RETCODE SCIPdialogRelease(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:913
#define SCIP_DECL_DIALOGCOPY(x)
Definition: type_dialog.h:53
SCIP_RETCODE SCIPdialogExec(SCIP_DIALOG *dialog, SCIP_SET *set, SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG **nextdialog)
Definition: dialog.c:930
void SCIPdialogGetPath(SCIP_DIALOG *dialog, const char sepchar, char *path)
Definition: dialog.c:1162
SCIP_RETCODE SCIPdialogDisplayMenuEntry(SCIP_DIALOG *dialog, SCIP *scip)
Definition: dialog.c:1097
#define SCIP_MAXSTRLEN
Definition: def.h:273
SCIP_DIALOGDATA * SCIPdialogGetData(SCIP_DIALOG *dialog)
Definition: dialog.c:1244
SCIP_RETCODE SCIPdialoghdlrAddInputLine(SCIP_DIALOGHDLR *dialoghdlr, const char *inputline)
Definition: dialog.c:688
data structures for user interface dialog
#define FALSE
Definition: def.h:73
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5573
SCIP_LINELIST * nextline
Definition: struct_dialog.h:57
static void linelistFree(SCIP_LINELIST **linelist)
Definition: dialog.c:232
#define BMSallocMemoryArray(ptr, num)
Definition: memory.h:115
struct SCIP_DialogData SCIP_DIALOGDATA
Definition: type_dialog.h:42
static void linelistFreeAll(SCIP_LINELIST **linelist)
Definition: dialog.c:244
#define SCIPdebugMessage
Definition: pub_message.h:87
char * inputline
Definition: struct_dialog.h:56
SCIP_RETCODE SCIPdialoghdlrGetLine(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *prompt, char **inputline, SCIP_Bool *endoffile)
Definition: dialog.c:461
#define BMSfreeMemory(ptr)
Definition: memory.h:137
SCIP_DIALOG * SCIPdialoghdlrGetRoot(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:427
Definition: heur_padm.c:125
static SCIP_RETCODE ensureSubdialogMem(SCIP_DIALOG *dialog, SCIP_SET *set, int num)
Definition: dialog.c:793
void SCIPdialogCapture(SCIP_DIALOG *dialog)
Definition: dialog.c:903
int SCIPdialogGetNSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1234
#define SCIP_DECL_DIALOGDESC(x)
Definition: type_dialog.h:73
static SCIP_RETCODE writeHistory(const char *filename)
Definition: dialog.c:218
SCIP_EXPORT void SCIPsortedvecInsertPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *keyval, int *len, int *pos)
int SCIPstrncpy(char *t, const char *s, int size)
Definition: misc.c:10633
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:139
SCIP_RETCODE SCIPdialoghdlrAddHistory(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *command, SCIP_Bool escapecommand)
Definition: dialog.c:717
SCIP_DIALOG ** subdialogs
Definition: struct_dialog.h:45
#define SCIPerrorMessage
Definition: pub_message.h:55
static SCIP_RETCODE addHistory(const char *s)
Definition: dialog.c:188
SCIP_RETCODE SCIPdialogDisplayCompletions(SCIP_DIALOG *dialog, SCIP *scip, const char *entryname)
Definition: dialog.c:1131
SCIP_DIALOG * parent
Definition: struct_dialog.h:44
SCIP_RETCODE SCIPdialogWriteHistory(const char *filename)
Definition: dialog.c:1265
SCIP_RETCODE SCIPdialoghdlrCreate(SCIP_SET *set, SCIP_DIALOGHDLR **dialoghdlr)
Definition: dialog.c:327
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:364
SCIP_VAR * h
Definition: circlepacking.c:59
SCIP_DIALOG ** SCIPdialogGetSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1224
const char * SCIPdialogGetDesc(SCIP_DIALOG *dialog)
Definition: dialog.c:1194
SCIP_Bool issubmenu
Definition: struct_dialog.h:50
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:135
SCIP_LINELIST * inputlist
Definition: struct_dialog.h:64
int subdialogssize
Definition: struct_dialog.h:48
const char * SCIPdialogGetName(SCIP_DIALOG *dialog)
Definition: dialog.c:1184
public data structures and miscellaneous methods
SCIP_RETCODE SCIPdialogCreate(SCIP_DIALOG **dialog, SCIP_DECL_DIALOGCOPY((*dialogcopy)), SCIP_DECL_DIALOGEXEC((*dialogexec)), SCIP_DECL_DIALOGDESC((*dialogdesc)), SCIP_DECL_DIALOGFREE((*dialogfree)), const char *name, const char *desc, SCIP_Bool issubmenu, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:815
SCIP_DIALOGDATA * dialogdata
Definition: struct_dialog.h:46
internal methods for user interface dialog
#define SCIP_Bool
Definition: def.h:70
static int getHistoryLength(void)
Definition: dialog.c:198
SCIP_RETCODE SCIPsetIncludeExternalCode(SCIP_SET *set, const char *name, const char *description)
Definition: set.c:5054
SCIP_Bool SCIPdialogHasEntry(SCIP_DIALOG *dialog, const char *entryname)
Definition: dialog.c:986
static SCIP_DECL_SORTPTRCOMP(dialogComp)
Definition: dialog.c:949
SCIP_LINELIST ** inputlistptr
Definition: struct_dialog.h:65
#define SCIPsetDebugMsg
Definition: set.h:1721
SCIP_RETCODE SCIPdialoghdlrSetRoot(SCIP *scip, SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog)
Definition: dialog.c:404
#define SCIP_DECL_DIALOGFREE(x)
Definition: type_dialog.h:61
#define SCIP_DECL_DIALOGEXEC(x)
Definition: type_dialog.h:87
SCIP_RETCODE SCIPdialogCopyInclude(SCIP_DIALOG *dialog, SCIP_SET *set)
Definition: dialog.c:309
int SCIPdialogFindEntry(SCIP_DIALOG *dialog, const char *entryname, SCIP_DIALOG **subdialog)
Definition: dialog.c:1019
SCIP_DIALOG * rootdialog
Definition: struct_dialog.h:63
SCIP_DIALOG * SCIPdialogGetParent(SCIP_DIALOG *dialog)
Definition: dialog.c:1214
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10590
static SCIP_RETCODE readLine(SCIP_DIALOGHDLR *dialoghdlr, const char *prompt, SCIP_Bool *endoffile)
Definition: dialog.c:147
static SCIP_RETCODE readInputLine(SCIP_DIALOGHDLR *dialoghdlr, const char *prompt, SCIP_Bool *endoffile)
Definition: dialog.c:262
#define BMSallocMemory(ptr)
Definition: memory.h:111
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:119
SCIP_RETCODE SCIPdialogAddEntry(SCIP_DIALOG *dialog, SCIP_SET *set, SCIP_DIALOG *subdialog)
Definition: dialog.c:955
void SCIPdialogSetData(SCIP_DIALOG *dialog, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:1254
SCIP_Bool SCIPdialogIsSubmenu(SCIP_DIALOG *dialog)
Definition: dialog.c:1204
SCIP_RETCODE SCIPdialoghdlrExec(SCIP_DIALOGHDLR *dialoghdlr, SCIP_SET *set)
Definition: dialog.c:376
common defines and data types used in all packages of SCIP
SCIP_RETCODE SCIPdialoghdlrFree(SCIP *scip, SCIP_DIALOGHDLR **dialoghdlr)
Definition: dialog.c:358
#define SCIP_ALLOC_TERMINATE(retcode, x, TERM)
Definition: def.h:395
SCIP_RETCODE SCIPdialogDisplayMenu(SCIP_DIALOG *dialog, SCIP *scip)
Definition: dialog.c:1063
#define SCIP_ALLOC(x)
Definition: def.h:375
static SCIP_RETCODE removeHistory(int pos)
Definition: dialog.c:207
SCIP callable library.
void SCIPdialoghdlrClearBuffer(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:437
memory allocation routines