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-2017 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file dialog.c
17  * @brief methods for user interface dialog
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 #include <ctype.h>
26 
27 #ifdef WITH_READLINE
28 #include <stdio.h>
29 #include <readline/readline.h>
30 #include <readline/history.h>
31 #endif
32 
33 #include "scip/scip.h"
34 #include "scip/def.h"
35 #include "blockmemshell/memory.h"
36 #include "scip/set.h"
37 #include "scip/pub_misc.h"
38 #include "scip/dialog.h"
39 
40 #include "scip/struct_dialog.h"
41 
42 
43 
44 
45 /*
46  * read line methods
47  */
48 
49 #ifdef 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)strncpy(&dialoghdlr->buffer[dialoghdlr->bufferpos], s,
67  (unsigned int)(dialoghdlr->buffersize - dialoghdlr->bufferpos));
68  free(s);
69  *endoffile = FALSE;
70  }
71  else
72  *endoffile = TRUE;
73 
74  return SCIP_OKAY;
75 }
76 
77 /** puts the given string on the command history */
78 static
80  const char* s /**< string to add to the command history */
81  )
82 {
83  add_history(s);
84 
85  return SCIP_OKAY;
86 }
87 
88 /** returns the current length of the history list */
89 static
91  void
92  )
93 {
94 #ifndef NO_REMOVE_HISTORY
95  return history_length;
96 #else
97  return 0;
98 #endif
99 }
100 
101 /** removes a single element from the history list */
102 static
104  int pos /**< list position of history entry to remove */
105  )
106 {
107 #ifndef NO_REMOVE_HISTORY
108  HIST_ENTRY* entry;
109 
110  entry = remove_history(pos);
111 
112  /* Free readline/history storage: there seem to be differences in the versions (and the amount of
113  * data to be freed). The following should be a good approximation; if it doesn't work define
114  * NO_REMOVE_HISTORY - see the INSTALL file. This will produce minor memory leaks.
115  */
116 #if RL_VERSION_MAJOR >= 5
117  (void)free_history_entry(entry);
118 #else
119  if( entry != NULL )
120  {
121  free((void*)entry->line);
122  free(entry);
123  }
124 #endif
125 #endif
126 
127  return SCIP_OKAY;
128 }
129 
130 /** writes command history into file of the specified name */
131 static
133  const char* filename /**< name of file to (over)write history to */
134  )
135 {
136  int retval = write_history(filename);
137 
138  if( retval == 0 )
139  return SCIP_OKAY;
140  else
141  return SCIP_FILECREATEERROR;
142 }
143 
144 #else
145 
146 /** reads a line of input from stdin */
147 static
149  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
150  const char* prompt, /**< prompt to display */
151  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
152  )
153 {
154  char* s;
155 
156  assert(dialoghdlr != NULL);
157  assert(dialoghdlr->buffer != NULL);
158  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
159  assert(dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
160  assert(endoffile != NULL);
161 
162  /* check for EOF (due to CTRL-D or unexpected end of piped-in file) */
163  if( feof(stdin) )
164  *endoffile = TRUE;
165  else
166  {
167  char* result;
168 
169  /* display prompt */
170  printf("%s", prompt);
171 
172  /* read line from stdin */
173  result = fgets(&dialoghdlr->buffer[dialoghdlr->bufferpos], dialoghdlr->buffersize - dialoghdlr->bufferpos, stdin);
174  assert(result != NULL);
175  (void) result; /* disable compiler warning [-Wunused-result] */
176 
177  /* replace newline with \0 */
178  s = strchr(&dialoghdlr->buffer[dialoghdlr->bufferpos], '\n');
179  if( s != NULL )
180  *s = '\0';
181  *endoffile = FALSE;
182  }
183 
184  return SCIP_OKAY;
185 }
186 
187 /** puts the given string on the command history */
188 static
190  const char* s /**< string to add to the command history */
191  )
192 { /*lint --e{715}*/
193  /* nothing to do here */
194  return SCIP_OKAY;
195 }
196 
197 /** returns the current length of the history list */
198 static
200  void
201  )
202 {
203  return 0;
204 }
205 
206 /** removes a single element from the history list */
207 static
209  int pos /**< list position of history entry to remove */
210  )
211 { /*lint --e{715}*/
212  /* nothing to do here */
213  return SCIP_OKAY;
214 }
215 
216 
217 /** writes command history into file of the specified name */
218 static
220  const char* filename /**< name of file to (over)write history to */
221  )
222 { /*lint --e{715}*/
223  /* nothing to do here */
224  return SCIP_OKAY;
225 }
226 
227 #endif
228 
229 /** frees a single linelist entry, but not its successors */
230 static
232  SCIP_LINELIST** linelist /**< pointer to line list */
233  )
234 {
235  assert(linelist != NULL);
236 
237  BMSfreeMemoryArray(&(*linelist)->inputline);
238  BMSfreeMemory(linelist);
239 }
240 
241 /** frees a linelist entry and all of its successors */
242 static
244  SCIP_LINELIST** linelist /**< pointer to line list */
245  )
246 {
247  assert(linelist != NULL);
248 
249  while( *linelist != NULL )
250  {
251  SCIP_LINELIST* nextline;
252 
253  nextline = (*linelist)->nextline;
254  linelistFree(linelist);
255  *linelist = nextline;
256  }
257 }
258 
259 /** reads a line of input from stdin or from the stored input lines in the input list */
260 static
262  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
263  const char* prompt, /**< prompt to display */
264  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
265  )
266 {
267  assert(dialoghdlr != NULL);
268  assert(dialoghdlr->buffer != NULL);
269  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
270  assert(dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
271  assert(endoffile != NULL);
272 
273  *endoffile = FALSE;
274 
275  if( dialoghdlr->inputlist == NULL )
276  {
277  /* read a line from stdin */
278  SCIP_CALL( readLine(dialoghdlr, prompt, endoffile) );
279  }
280  else
281  {
282  SCIP_LINELIST* nextline;
283 
284  /* copy the next input line into the input buffer */
285  (void)strncpy(&dialoghdlr->buffer[dialoghdlr->bufferpos], dialoghdlr->inputlist->inputline,
286  (size_t)(dialoghdlr->buffersize - dialoghdlr->bufferpos)); /*lint !e571 !e776*/
287  dialoghdlr->buffer[dialoghdlr->buffersize-1] = '\0';
288 
289  /* free the input line */
290  nextline = dialoghdlr->inputlist->nextline;
291  if( dialoghdlr->inputlistptr == &(dialoghdlr->inputlist->nextline) )
292  dialoghdlr->inputlistptr = &dialoghdlr->inputlist;
293  linelistFree(&dialoghdlr->inputlist);
294  dialoghdlr->inputlist = nextline;
295  assert(dialoghdlr->inputlistptr != NULL);
296  assert(*dialoghdlr->inputlistptr == NULL);
297  }
298 
299  return SCIP_OKAY;
300 }
301 
302 
303 
304 
305 /*
306  * dialog handler
307  */
308 
309 /** copies the given dialog to a new scip */
311  SCIP_DIALOG* dialog, /**< dialog */
312  SCIP_SET* set /**< SCIP_SET of SCIP to copy to */
313  )
314 {
315  assert(dialog != NULL);
316  assert(set != NULL);
317  assert(set->scip != NULL);
318 
319  if( dialog->dialogcopy != NULL )
320  {
321  SCIPsetDebugMsg(set, "including dialog %s in subscip %p\n", SCIPdialogGetName(dialog), (void*)set->scip);
322  SCIP_CALL( dialog->dialogcopy(set->scip, dialog) );
323  }
324  return SCIP_OKAY;
325 }
326 
327 /** creates a dialog handler */
329  SCIP_SET* set, /**< global SCIP settings */
330  SCIP_DIALOGHDLR** dialoghdlr /**< pointer to store dialog handler */
331  )
332 { /*lint --e{715}*/
333 #ifdef WITH_READLINE
334  char readlineversion[20];
335 #endif
336 
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 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 
365  SCIP_CALL( SCIPdialoghdlrSetRoot(scip, *dialoghdlr, NULL) );
366  linelistFreeAll(&(*dialoghdlr)->inputlist);
367  BMSfreeMemoryArray(&(*dialoghdlr)->buffer);
368  BMSfreeMemory(dialoghdlr);
369 
370  return SCIP_OKAY;
371 }
372 
373 /** executes the root dialog of the dialog handler */
375  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
376  SCIP_SET* set /**< global SCIP settings */
377  )
378 {
379  SCIP_DIALOG* dialog;
380 
381  assert(dialoghdlr != NULL);
382  assert(dialoghdlr->buffer != NULL);
383 
384  /* clear the buffer, start with the root dialog */
385  SCIPdialoghdlrClearBuffer(dialoghdlr);
386  dialog = dialoghdlr->rootdialog;
387 
388  /* execute dialogs until a NULL is returned as next dialog */
389  while( dialog != NULL )
390  {
391  SCIP_CALL( SCIPdialogExec(dialog, set, dialoghdlr, &dialog) );
392 
393  /* reset buffer, it is was consumed completely */
394  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0' )
395  SCIPdialoghdlrClearBuffer(dialoghdlr);
396  }
397 
398  return SCIP_OKAY;
399 }
400 
401 /** makes given dialog the root dialog of dialog handler; captures dialog and releases former root dialog */
403  SCIP* scip, /**< SCIP data structure */
404  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
405  SCIP_DIALOG* dialog /**< dialog to be the root */
406  )
407 {
408  assert(dialoghdlr != NULL);
409 
410  if( dialoghdlr->rootdialog != NULL )
411  {
412  SCIP_CALL( SCIPdialogRelease(scip, &dialoghdlr->rootdialog) );
413  }
414  assert(dialoghdlr->rootdialog == NULL);
415 
416  dialoghdlr->rootdialog = dialog;
417 
418  if( dialog != NULL )
419  SCIPdialogCapture(dialog);
420 
421  return SCIP_OKAY;
422 }
423 
424 /** returns the root dialog of the dialog handler */
426  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
427  )
428 {
429  assert(dialoghdlr != NULL);
430 
431  return dialoghdlr->rootdialog;
432 }
433 
434 /** clears the input command buffer of the dialog handler */
436  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
437  )
438 {
439  assert(dialoghdlr != NULL);
440 
441  dialoghdlr->buffer[0] = '\0';
442  dialoghdlr->bufferpos = 0;
443 }
444 
445 /** returns TRUE iff input command buffer is empty */
447  SCIP_DIALOGHDLR* dialoghdlr /**< dialog handler */
448  )
449 {
450  assert(dialoghdlr != NULL);
451  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
452 
453  return (dialoghdlr->buffer[dialoghdlr->bufferpos] == '\0');
454 }
455 
456 /** returns the next line in the handler's command buffer; if the buffer is empty, displays the given prompt or the
457  * current dialog's path and asks the user for further input; the user must not free or modify the returned string
458  */
460  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
461  SCIP_DIALOG* dialog, /**< current dialog */
462  const char* prompt, /**< prompt to display, or NULL to display the current dialog's path */
463  char** inputline, /**< pointer to store the complete line in the handler's command buffer */
464  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
465  )
466 {
467  char path[SCIP_MAXSTRLEN];
468  char p[SCIP_MAXSTRLEN];
469 
470  assert(dialoghdlr != NULL);
471  assert(dialoghdlr->buffer != NULL);
472  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
473  assert(inputline != NULL);
474 
475  /* get input from the user, if the buffer is empty */
476  if( SCIPdialoghdlrIsBufferEmpty(dialoghdlr) )
477  {
478  int len;
479 
480  /* clear the buffer */
481  SCIPdialoghdlrClearBuffer(dialoghdlr);
482 
483  if( prompt == NULL )
484  {
485  /* use current dialog's path as prompt */
486  SCIPdialogGetPath(dialog, '/', path);
487  (void) SCIPsnprintf(p, SCIP_MAXSTRLEN, "%s> ", path);
488  prompt = p;
489  }
490 
491  /* read command line from stdin or from the input line list */
492  SCIP_CALL( readInputLine(dialoghdlr, prompt, endoffile) );
493 
494  /* strip trailing spaces */
495  len = (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
496  if( len > 0 )
497  {
498  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1]) )
499  {
500  dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1] = '\0';
501  len--;
502  }
503  }
504 
505  /* insert command in command history */
506  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
507  {
508  SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, NULL, &dialoghdlr->buffer[dialoghdlr->bufferpos], FALSE) );
509  }
510  }
511 
512  /* the last character in the buffer must be a '\0' */
513  dialoghdlr->buffer[dialoghdlr->buffersize-1] = '\0';
514 
515 
516  /* skip leading spaces: find start of first word */
517  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
518  dialoghdlr->bufferpos++;
519 
520  /* copy the complete line */
521  *inputline = &dialoghdlr->buffer[dialoghdlr->bufferpos];
522 
523  /* go to the end of the line */
524  dialoghdlr->bufferpos += (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
525 
526  if( dialoghdlr->buffer[dialoghdlr->buffersize-1] == '\0' )
527  *endoffile = TRUE;
528 
529  return SCIP_OKAY;
530 }
531 
532 
533 /** returns the next word in the handler's command buffer; if the buffer is empty, displays the given prompt or the
534  * current dialog's path and asks the user for further input; the user must not free or modify the returned string
535  */
537  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
538  SCIP_DIALOG* dialog, /**< current dialog */
539  const char* prompt, /**< prompt to display, or NULL to display the current dialog's path */
540  char** inputword, /**< pointer to store the next word in the handler's command buffer */
541  SCIP_Bool* endoffile /**< pointer to store whether the end of the input file was reached */
542  )
543 {
544  char path[SCIP_MAXSTRLEN];
545  char p[SCIP_MAXSTRLEN];
546  char* firstword;
547  int pos;
548 
549  assert(dialoghdlr != NULL);
550  assert(dialoghdlr->buffer != NULL);
551  assert(dialoghdlr->bufferpos < dialoghdlr->buffersize);
552  assert(inputword != NULL);
553  assert(endoffile != NULL);
554 
555  *endoffile = FALSE;
556 
557  /* get input from the user, if the buffer is empty */
558  if( SCIPdialoghdlrIsBufferEmpty(dialoghdlr) )
559  {
560  int len;
561 
562  /* clear the buffer */
563  SCIPdialoghdlrClearBuffer(dialoghdlr);
564 
565  if( prompt == NULL )
566  {
567  /* use current dialog's path as prompt */
568  SCIPdialogGetPath(dialog, '/', path);
569  (void) SCIPsnprintf(p, SCIP_MAXSTRLEN, "%s> ", path);
570  prompt = p;
571  }
572 
573  /* read command line from stdin or from the input line list */
574  SCIP_CALL( readInputLine(dialoghdlr, prompt, endoffile) );
575 
576  /* strip trailing spaces */
577  len = (int)strlen(&dialoghdlr->buffer[dialoghdlr->bufferpos]);
578  if( len > 0 )
579  {
580  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1]) )
581  {
582  dialoghdlr->buffer[dialoghdlr->bufferpos + len - 1] = '\0';
583  len--;
584  }
585  }
586 
587  /* insert command in command history */
588  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
589  {
590  SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, NULL, &dialoghdlr->buffer[dialoghdlr->bufferpos], FALSE) );
591  }
592  }
593 
594  /* the last character in the buffer must be a '\0' */
595  dialoghdlr->buffer[dialoghdlr->buffersize-1] = '\0';
596 
597  /* skip leading spaces: find start of first word */
598  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
599  dialoghdlr->bufferpos++;
600  firstword = &dialoghdlr->buffer[dialoghdlr->bufferpos];
601 
602  pos = dialoghdlr->bufferpos;
603  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && !isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
604  {
605  assert(pos <= dialoghdlr->bufferpos);
606 
607  switch( dialoghdlr->buffer[dialoghdlr->bufferpos] )
608  {
609  case '"':
610  dialoghdlr->bufferpos++;
611  /* read characters as they are until the next " */
612  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && dialoghdlr->buffer[dialoghdlr->bufferpos] != '"' )
613  {
614  /* watch out for \" and \\ which should be treated as " and \, respectively */
615  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\\'
616  && (dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '"'
617  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\\') )
618  {
619  dialoghdlr->bufferpos++;
620  }
621  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
622  pos++;
623  dialoghdlr->bufferpos++;
624  }
625  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '"' )
626  dialoghdlr->bufferpos++; /* skip final " */
627  break;
628  case '\'':
629  dialoghdlr->bufferpos++;
630  /* read characters as they are until the next ' */
631  while( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' && dialoghdlr->buffer[dialoghdlr->bufferpos] != '\'' )
632  {
633  /* watch out for \' and \\ which should be treated as ' and \, respectively */
634  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\\'
635  && (dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\''
636  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\\') )
637  {
638  dialoghdlr->bufferpos++;
639  }
640  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
641  pos++;
642  dialoghdlr->bufferpos++;
643  }
644  if( dialoghdlr->buffer[dialoghdlr->bufferpos] == '\'' )
645  dialoghdlr->bufferpos++; /* skip final ' */
646  break;
647  case '\\':
648  /* if the next character is a space, a ", or a ', read next character as it is;
649  * otherwise, treat the \ as normal character
650  */
651  if( dialoghdlr->buffer[dialoghdlr->bufferpos+1] == ' '
652  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '"'
653  || dialoghdlr->buffer[dialoghdlr->bufferpos+1] == '\'' )
654  {
655  dialoghdlr->bufferpos++;
656  }
657  /*lint -fallthrough*/
658  default:
659  dialoghdlr->buffer[pos] = dialoghdlr->buffer[dialoghdlr->bufferpos];
660  pos++;
661  dialoghdlr->bufferpos++;
662  break;
663  }
664  }
665  assert(pos <= dialoghdlr->bufferpos);
666 
667  /* move buffer to the next position */
668  if( dialoghdlr->buffer[dialoghdlr->bufferpos] != '\0' )
669  dialoghdlr->bufferpos++;
670 
671  /* truncate the command word in the buffer */
672  if( dialoghdlr->buffer[pos] != '\0' )
673  dialoghdlr->buffer[pos] = '\0';
674 
675  /* remove additional spaces */
676  while( isspace((unsigned char)dialoghdlr->buffer[dialoghdlr->bufferpos]) )
677  dialoghdlr->bufferpos++;
678 
679  *inputword = firstword;
680 
681  SCIPdebugMessage("next word: <%s>\n", *inputword);
682 
683  return SCIP_OKAY;
684 }
685 
686 /** adds a single line of input to the dialog handler which is treated as if the user entered the command line */
688  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
689  const char* inputline /**< input line to add */
690  )
691 {
692  SCIP_LINELIST* linelist;
693  SCIP_RETCODE retcode = SCIP_OKAY;
694 
695  assert(dialoghdlr != NULL);
696  assert(dialoghdlr->inputlistptr != NULL);
697  assert(*dialoghdlr->inputlistptr == NULL);
698  assert(inputline != NULL);
699 
700  SCIP_ALLOC( BMSallocMemory(&linelist) );
701  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&linelist->inputline, inputline, strlen(inputline)+1), TERMINATE );
702  linelist->nextline = NULL;
703  *dialoghdlr->inputlistptr = linelist;
704  dialoghdlr->inputlistptr = &linelist->nextline;
705 
706  TERMINATE:
707  if( retcode != SCIP_OKAY )
708  BMSfreeMemory(&linelist);
709 
710  return retcode;
711 }
712 
713 /** adds a command to the command history of the dialog handler; if a dialog is given, the command is preceeded
714  * by the dialog's command path; if no command is given, only the path to the dialog is added to the command history
715  */
717  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
718  SCIP_DIALOG* dialog, /**< current dialog, or NULL */
719  const char* command, /**< command string to add to the command history, or NULL */
720  SCIP_Bool escapecommand /**< should special characters in command be prefixed by an escape char? */
721  )
722 {
723  char s[SCIP_MAXSTRLEN];
724  char h[SCIP_MAXSTRLEN];
725  SCIP_Bool cleanuphistory;
726 
727  assert(dialoghdlr != NULL);
728 
729  /* the current history list should be cleaned up if a dialog is given (i.e. the command is not partial) */
730  cleanuphistory = (dialog != NULL);
731 
732  /* generate the string to add to the history */
733  s[SCIP_MAXSTRLEN-1] = '\0';
734  h[SCIP_MAXSTRLEN-1] = '\0';
735 
736  if( command != NULL )
737  {
738  if( escapecommand )
739  SCIPescapeString(h, SCIP_MAXSTRLEN, command);
740  else
741  (void)strncpy(h, command, SCIP_MAXSTRLEN-1);
742  }
743  else
744  h[0] = '\0';
745 
746  while( dialog != NULL && dialog != dialoghdlr->rootdialog )
747  {
748  if( h[0] == '\0' )
749  (void)strncpy(h, dialog->name, SCIP_MAXSTRLEN-1);
750  else
751  {
752  (void) SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s %s", dialog->name, h);
753  (void)strncpy(h, s, SCIP_MAXSTRLEN-1);
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)strncpy(path, dialog->name, SCIP_MAXSTRLEN);
1173  path[SCIP_MAXSTRLEN - 1] = '\0';
1174 
1175  dialog = dialog->parent;
1176  while( dialog != NULL )
1177  {
1178  (void)SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s%c%s", dialog->name, sepchar, path);
1179  (void)strncpy(path, s, SCIP_MAXSTRLEN);
1180  path[SCIP_MAXSTRLEN - 1] = '\0';
1181  dialog = dialog->parent;
1182  }
1183 }
1184 
1185 /** gets the command name of the dialog */
1186 const char* SCIPdialogGetName(
1187  SCIP_DIALOG* dialog /**< dialog */
1188  )
1189 {
1190  assert(dialog != NULL);
1191 
1192  return dialog->name;
1193 }
1194 
1195 /** gets the description of the dialog */
1196 const char* SCIPdialogGetDesc(
1197  SCIP_DIALOG* dialog /**< dialog */
1198  )
1199 {
1200  assert(dialog != NULL);
1201 
1202  return dialog->desc;
1203 }
1204 
1205 /** returns whether the dialog is a sub menu */
1207  SCIP_DIALOG* dialog /**< dialog */
1208  )
1209 {
1210  assert(dialog != NULL);
1211 
1212  return dialog->issubmenu;
1213 }
1214 
1215 /** gets the parent dialog of the given dialog */
1217  SCIP_DIALOG* dialog /**< dialog */
1218  )
1219 {
1220  assert(dialog != NULL);
1221 
1222  return dialog->parent;
1223 }
1224 
1225 /** gets the array of sub-dialogs associated with the given dialog */
1227  SCIP_DIALOG* dialog /**< dialog */
1228  )
1229 {
1230  assert(dialog != NULL);
1231 
1232  return dialog->subdialogs;
1233 }
1234 
1235 /** gets the number of sub-dialogs associated with the given dialog */
1237  SCIP_DIALOG* dialog /**< dialog */
1238  )
1239 {
1240  assert(dialog != NULL);
1241 
1242  return dialog->nsubdialogs;
1243 }
1244 
1245 /** gets the user defined data associated with the given dialog */
1247  SCIP_DIALOG* dialog /**< dialog */
1248  )
1249 {
1250  assert(dialog != NULL);
1251 
1252  return dialog->dialogdata;
1253 }
1254 
1255 /** sets user data of dialog; user has to free old data in advance! */
1257  SCIP_DIALOG* dialog, /**< dialog */
1258  SCIP_DIALOGDATA* dialogdata /**< new dialog user data */
1259  )
1260 {
1261  assert(dialog != NULL);
1262 
1263  dialog->dialogdata = dialogdata;
1264 }
1265 
1266 /** writes command history to specified filename */
1268  const char* filename /**< file name for (over)writing history */
1269  )
1270 {
1271  return writeHistory(filename);
1272 }
int SCIPdialogGetNSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1236
static SCIP_RETCODE dialogFree(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:871
void SCIPdialoghdlrClearBuffer(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:435
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:107
const char * SCIPdialogGetName(SCIP_DIALOG *dialog)
Definition: dialog.c:1186
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1319
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
#define SCIP_MAXSTRLEN
Definition: def.h:225
SCIP_DIALOG ** SCIPdialogGetSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1226
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
SCIP_RETCODE SCIPdialogDisplayCompletions(SCIP_DIALOG *dialog, SCIP *scip, const char *entryname)
Definition: dialog.c:1131
data structures for user interface dialog
#define FALSE
Definition: def.h:64
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:9340
#define TRUE
Definition: def.h:63
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5091
int SCIPdialogFindEntry(SCIP_DIALOG *dialog, const char *entryname, SCIP_DIALOG **subdialog)
Definition: dialog.c:1019
SCIP_LINELIST * nextline
Definition: struct_dialog.h:57
static void linelistFree(SCIP_LINELIST **linelist)
Definition: dialog.c:231
#define BMSallocMemoryArray(ptr, num)
Definition: memory.h:82
struct SCIP_DialogData SCIP_DIALOGDATA
Definition: type_dialog.h:42
static void linelistFreeAll(SCIP_LINELIST **linelist)
Definition: dialog.c:243
#define SCIPdebugMessage
Definition: pub_message.h:77
char * inputline
Definition: struct_dialog.h:56
#define BMSfreeMemory(ptr)
Definition: memory.h:104
SCIP_DIALOG * SCIPdialogGetParent(SCIP_DIALOG *dialog)
Definition: dialog.c:1216
static SCIP_RETCODE ensureSubdialogMem(SCIP_DIALOG *dialog, SCIP_SET *set, int num)
Definition: dialog.c:793
void SCIPdialogSetData(SCIP_DIALOG *dialog, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:1256
void SCIPdialogCapture(SCIP_DIALOG *dialog)
Definition: dialog.c:903
#define SCIP_DECL_DIALOGDESC(x)
Definition: type_dialog.h:73
static SCIP_RETCODE writeHistory(const char *filename)
Definition: dialog.c:219
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:106
SCIP_DIALOG ** subdialogs
Definition: struct_dialog.h:45
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPdialogWriteHistory(const char *filename)
Definition: dialog.c:1267
static SCIP_RETCODE addHistory(const char *s)
Definition: dialog.c:189
void SCIPescapeString(char *t, int bufsize, const char *s)
Definition: misc.c:9312
SCIP_DIALOG * parent
Definition: struct_dialog.h:44
SCIP_RETCODE SCIPdialogDisplayMenu(SCIP_DIALOG *dialog, SCIP *scip)
Definition: dialog.c:1063
SCIP_RETCODE SCIPdialoghdlrCreate(SCIP_SET *set, SCIP_DIALOGHDLR **dialoghdlr)
Definition: dialog.c:328
#define NULL
Definition: lpi_spx1.cpp:137
const char * SCIPdialogGetDesc(SCIP_DIALOG *dialog)
Definition: dialog.c:1196
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:316
SCIP_Bool issubmenu
Definition: struct_dialog.h:50
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:102
SCIP_LINELIST * inputlist
Definition: struct_dialog.h:64
int subdialogssize
Definition: struct_dialog.h:48
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:61
SCIP_Bool SCIPdialogHasEntry(SCIP_DIALOG *dialog, const char *entryname)
Definition: dialog.c:986
SCIP_RETCODE SCIPdialoghdlrAddInputLine(SCIP_DIALOGHDLR *dialoghdlr, const char *inputline)
Definition: dialog.c:687
static int getHistoryLength(void)
Definition: dialog.c:199
SCIP_Bool SCIPdialogIsSubmenu(SCIP_DIALOG *dialog)
Definition: dialog.c:1206
SCIP_RETCODE SCIPsetIncludeExternalCode(SCIP_SET *set, const char *name, const char *description)
Definition: set.c:4642
static SCIP_DECL_SORTPTRCOMP(dialogComp)
Definition: dialog.c:949
SCIP_LINELIST ** inputlistptr
Definition: struct_dialog.h:65
#define SCIPsetDebugMsg
Definition: set.h:1870
SCIP_RETCODE SCIPdialoghdlrSetRoot(SCIP *scip, SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog)
Definition: dialog.c:402
#define SCIP_DECL_DIALOGFREE(x)
Definition: type_dialog.h:61
SCIP_RETCODE SCIPdialoghdlrGetWord(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *prompt, char **inputword, SCIP_Bool *endoffile)
Definition: dialog.c:536
void SCIPsortedvecInsertPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *keyval, int *len, int *pos)
SCIP_RETCODE SCIPdialoghdlrAddHistory(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *command, SCIP_Bool escapecommand)
Definition: dialog.c:716
#define SCIP_DECL_DIALOGEXEC(x)
Definition: type_dialog.h:87
SCIP_DIALOG * SCIPdialoghdlrGetRoot(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:425
SCIP_RETCODE SCIPdialogCopyInclude(SCIP_DIALOG *dialog, SCIP_SET *set)
Definition: dialog.c:310
SCIP_DIALOG * rootdialog
Definition: struct_dialog.h:63
SCIP_Bool SCIPdialoghdlrIsBufferEmpty(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:446
static SCIP_RETCODE readLine(SCIP_DIALOGHDLR *dialoghdlr, const char *prompt, SCIP_Bool *endoffile)
Definition: dialog.c:148
static SCIP_RETCODE readInputLine(SCIP_DIALOGHDLR *dialoghdlr, const char *prompt, SCIP_Bool *endoffile)
Definition: dialog.c:261
#define BMSallocMemory(ptr)
Definition: memory.h:78
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:86
SCIP_RETCODE SCIPdialogAddEntry(SCIP_DIALOG *dialog, SCIP_SET *set, SCIP_DIALOG *subdialog)
Definition: dialog.c:955
SCIP_RETCODE SCIPdialoghdlrGetLine(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *prompt, char **inputline, SCIP_Bool *endoffile)
Definition: dialog.c:459
SCIP_RETCODE SCIPdialoghdlrExec(SCIP_DIALOGHDLR *dialoghdlr, SCIP_SET *set)
Definition: dialog.c:374
common defines and data types used in all packages of SCIP
SCIP_RETCODE SCIPdialoghdlrFree(SCIP *scip, SCIP_DIALOGHDLR **dialoghdlr)
Definition: dialog.c:358
SCIP_DIALOGDATA * SCIPdialogGetData(SCIP_DIALOG *dialog)
Definition: dialog.c:1246
#define SCIP_ALLOC_TERMINATE(retcode, x, TERM)
Definition: def.h:347
#define SCIP_ALLOC(x)
Definition: def.h:327
static SCIP_RETCODE removeHistory(int pos)
Definition: dialog.c:208
SCIP callable library.
memory allocation routines