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  /* cppcheck-suppress unusedLabel */
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];
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  h[SCIP_MAXSTRLEN-1] = '\0';
736 
737  if( command != NULL )
738  {
739  if( escapecommand )
740  SCIPescapeString(h, SCIP_MAXSTRLEN, command);
741  else
742  (void)strncpy(h, command, SCIP_MAXSTRLEN-1);
743  }
744  else
745  h[0] = '\0';
746 
747  while( dialog != NULL && dialog != dialoghdlr->rootdialog )
748  {
749  if( h[0] == '\0' )
750  (void)strncpy(h, dialog->name, SCIP_MAXSTRLEN-1);
751  else
752  {
753  (void) SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s %s", dialog->name, h);
754  (void)strncpy(h, s, SCIP_MAXSTRLEN-1);
755  }
756  dialog = dialog->parent;
757  }
758 
759  /* clean up the unmarked history entries */
760  if( cleanuphistory )
761  {
762  int i;
763 
764  for( i = getHistoryLength()-1; i >= dialoghdlr->nprotectedhistelems; --i )
765  {
766  SCIP_CALL( removeHistory(i) );
767  }
768  }
769 
770  /* add command to history */
771  if( h[0] != '\0' )
772  {
773  SCIP_CALL( addHistory(h) );
774  }
775 
776  /* if the history string was a full command line, protect the history entry from future cleanups */
777  if( cleanuphistory )
778  {
779  dialoghdlr->nprotectedhistelems = getHistoryLength();
780  }
781 
782  return SCIP_OKAY;
783 }
784 
785 
786 
787 
788 /*
789  * dialog
790  */
791 
792 /** ensures, that sub-dialogs array can store at least the given number of sub-dialogs */
793 static
795  SCIP_DIALOG* dialog, /**< dialog */
796  SCIP_SET* set, /**< global SCIP settings */
797  int num /**< minimal storage size for sub-dialogs */
798  )
799 {
800  assert(dialog != NULL);
801 
802  if( num > dialog->subdialogssize )
803  {
804  int newsize;
805 
806  newsize = SCIPsetCalcMemGrowSize(set, num);
807  SCIP_ALLOC( BMSreallocMemoryArray(&(dialog->subdialogs), newsize) );
808  dialog->subdialogssize = newsize;
809  }
810  assert(num <= dialog->subdialogssize);
811 
812  return SCIP_OKAY;
813 }
814 
815 /** creates and captures a user interface dialog */
817  SCIP_DIALOG** dialog, /**< pointer to store the dialog */
818  SCIP_DECL_DIALOGCOPY ((*dialogcopy)), /**< copy method of dialog or NULL if you don't want to copy your plugin into sub-SCIPs */
819  SCIP_DECL_DIALOGEXEC ((*dialogexec)), /**< execution method of dialog */
820  SCIP_DECL_DIALOGDESC ((*dialogdesc)), /**< description output method of dialog, or NULL */
821  SCIP_DECL_DIALOGFREE ((*dialogfree)), /**< destructor of dialog to free user data, or NULL */
822  const char* name, /**< name of dialog: command name appearing in parent's dialog menu */
823  const char* desc, /**< description of dialog used if description output method is NULL */
824  SCIP_Bool issubmenu, /**< is the dialog a sub-menu? */
825  SCIP_DIALOGDATA* dialogdata /**< user defined dialog data */
826  )
827 {
828  SCIP_RETCODE retcode;
829 
830  assert(dialog != NULL);
831  assert(name != NULL);
832 
833  retcode = SCIP_OKAY;
834 
835  SCIP_ALLOC( BMSallocMemory(dialog) );
836  (*dialog)->dialogcopy = dialogcopy;
837  (*dialog)->dialogexec = dialogexec;
838  (*dialog)->dialogdesc = dialogdesc;
839  (*dialog)->dialogfree = dialogfree;
840 
841  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&(*dialog)->name, name, strlen(name)+1), TERMINATE );
842  if( desc != NULL )
843  {
844  SCIP_ALLOC_TERMINATE( retcode, BMSduplicateMemoryArray(&(*dialog)->desc, desc, strlen(desc)+1), TERMINATE );
845  }
846  else
847  (*dialog)->desc = NULL;
848 
849  (*dialog)->issubmenu = issubmenu;
850  (*dialog)->parent = NULL;
851  (*dialog)->subdialogs = NULL;
852  (*dialog)->nsubdialogs = 0;
853  (*dialog)->subdialogssize = 0;
854  (*dialog)->nuses = 0;
855  (*dialog)->dialogdata = dialogdata;
856 
857  /* capture dialog */
858  SCIPdialogCapture(*dialog);
859 
860  /* cppcheck-suppress unusedLabel */
861  TERMINATE:
862  if( retcode != SCIP_OKAY )
863  {
864  BMSfreeMemoryArrayNull(&(*dialog)->name);
865  BMSfreeMemory(dialog);
866  }
867 
868  return retcode;
869 }
870 
871 /** frees dialog and all of its sub-dialogs */
872 static
874  SCIP* scip, /**< SCIP data structure */
875  SCIP_DIALOG** dialog /**< pointer to dialog */
876  )
877 {
878  int i;
879 
880  assert(dialog != NULL);
881  assert(*dialog != NULL);
882  assert((*dialog)->nuses == 0);
883 
884  /* call destructor of dialog */
885  if( (*dialog)->dialogfree != NULL )
886  {
887  SCIP_CALL( (*dialog)->dialogfree(scip, *dialog) );
888  }
889 
890  /* release sub-dialogs */
891  for( i = 0; i < (*dialog)->nsubdialogs; ++i )
892  {
893  SCIP_CALL( SCIPdialogRelease(scip, &(*dialog)->subdialogs[i]) );
894  }
895  BMSfreeMemoryArrayNull(&(*dialog)->subdialogs);
896 
897  BMSfreeMemoryArrayNull(&(*dialog)->name);
898  BMSfreeMemoryArrayNull(&(*dialog)->desc);
899  BMSfreeMemory(dialog);
900 
901  return SCIP_OKAY;
902 }
903 
904 /** captures a dialog */
906  SCIP_DIALOG* dialog /**< dialog */
907  )
908 {
909  assert(dialog != NULL);
910 
911  dialog->nuses++;
912 }
913 
914 /** releases a dialog */
916  SCIP* scip, /**< SCIP data structure */
917  SCIP_DIALOG** dialog /**< pointer to dialog */
918  )
919 {
920  assert(dialog != NULL);
921 
922  (*dialog)->nuses--;
923  if( (*dialog)->nuses == 0 )
924  {
925  SCIP_CALL( dialogFree(scip, dialog) );
926  }
927 
928  return SCIP_OKAY;
929 }
930 
931 /** executes dialog */
933  SCIP_DIALOG* dialog, /**< dialog */
934  SCIP_SET* set, /**< global SCIP settings */
935  SCIP_DIALOGHDLR* dialoghdlr, /**< dialog handler */
936  SCIP_DIALOG** nextdialog /**< pointer to store the next dialog to process */
937  )
938 {
939  assert(dialog != NULL);
940  assert(dialog->dialogexec != NULL);
941  assert(set != NULL);
942  assert(nextdialog != NULL);
943 
944  SCIP_CALL( dialog->dialogexec(set->scip, dialog, dialoghdlr, nextdialog) );
945 
946  return SCIP_OKAY;
947 }
948 
949 /** comparison method for sorting dialogs w.r.t. to their name */
950 static
952 {
953  return strcmp( SCIPdialogGetName((SCIP_DIALOG*)elem1), SCIPdialogGetName((SCIP_DIALOG*)elem2) );
954 }
955 
956 /** adds a sub-dialog to the given dialog as menu entry and captures the sub-dialog */
958  SCIP_DIALOG* dialog, /**< dialog */
959  SCIP_SET* set, /**< global SCIP settings */
960  SCIP_DIALOG* subdialog /**< sub-dialog to add as menu entry in dialog */
961  )
962 {
963  assert(dialog != NULL);
964  assert(subdialog != NULL);
965 
966  /* check, if sub-dialog already exists */
967  if( SCIPdialogHasEntry(dialog, SCIPdialogGetName(subdialog)) )
968  {
969  SCIPerrorMessage("dialog entry with name <%s> already exists in dialog <%s>\n",
970  SCIPdialogGetName(subdialog), SCIPdialogGetName(dialog));
971  return SCIP_INVALIDDATA;
972  }
973 
974  /* resize the sub-dialogs array */
975  SCIP_CALL( ensureSubdialogMem(dialog, set, dialog->nsubdialogs+1) );
976 
977  /* link the dialogs as parent-child pair; the sub-dialogs are sorted non-decreasing w.r.t. their name */
978  SCIPsortedvecInsertPtr((void**)dialog->subdialogs, dialogComp, (void*)subdialog, &dialog->nsubdialogs, NULL);
979  subdialog->parent = dialog;
980 
981  /* capture sub-dialog */
982  SCIPdialogCapture(subdialog);
983 
984  return SCIP_OKAY;
985 }
986 
987 /** returns TRUE iff a dialog entry matching exactly the given name is existing in the given dialog */
989  SCIP_DIALOG* dialog, /**< dialog */
990  const char* entryname /**< name of the dialog entry to find */
991  )
992 {
993  SCIP_DIALOG** subdialogs;
994  int nsubdialogs;
995  int i;
996 
997  assert(dialog != NULL);
998  assert(entryname != NULL);
999 
1000  /* check entryname w.r.t. available dialog options */
1001  subdialogs = SCIPdialogGetSubdialogs(dialog);
1002  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1003  for( i = 0; i < nsubdialogs; ++i )
1004  {
1005  /* check, if the sub-dialog's name matches entryname */
1006  if( strcmp(entryname, SCIPdialogGetName(subdialogs[i])) == 0 )
1007  return TRUE;
1008  }
1009 
1010  return FALSE;
1011 }
1012 
1013 /** searches the dialog for entries corresponding to the given name;
1014  * If a complete match is found, the entry is returned as "subdialog" and
1015  * the return value is 1.
1016  * If no dialog entry completely matches the given "entryname", the number
1017  * of entries with names beginning with "entryname" is returned. If this
1018  * number is 1, the single match is returned as "subdialog". Otherwise,
1019  * "subdialog" is set to NULL.
1020  */
1022  SCIP_DIALOG* dialog, /**< dialog */
1023  const char* entryname, /**< name of the dialog entry to find */
1024  SCIP_DIALOG** subdialog /**< pointer to store the found dialog entry */
1025  )
1026 {
1027  SCIP_DIALOG** subdialogs;
1028  unsigned int namelen;
1029  int nsubdialogs;
1030  int nfound;
1031  int i;
1032 
1033  assert(dialog != NULL);
1034  assert(entryname != NULL);
1035  assert(subdialog != NULL);
1036 
1037  *subdialog = NULL;
1038 
1039  /* check entryname w.r.t. available dialog options */
1040  subdialogs = SCIPdialogGetSubdialogs(dialog);
1041  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1042  namelen = (unsigned int) strlen(entryname);
1043  nfound = 0;
1044  for( i = 0; i < nsubdialogs; ++i )
1045  {
1046  /* check, if the beginning of the sub-dialog's name matches entryname */
1047  if( strncmp(entryname, SCIPdialogGetName(subdialogs[i]), namelen) == 0 )
1048  {
1049  *subdialog = subdialogs[i];
1050  nfound++;
1051 
1052  /* if entryname exactly matches the sub-dialog's name, use this sub-dialog */
1053  if( namelen == (unsigned int) strlen(SCIPdialogGetName(subdialogs[i])) )
1054  return 1;
1055  }
1056  }
1057 
1058  if( nfound != 1 )
1059  *subdialog = NULL;
1060 
1061  return nfound;
1062 }
1063 
1064 /** displays the dialog's menu */
1066  SCIP_DIALOG* dialog, /**< dialog */
1067  SCIP* scip /**< SCIP data structure */
1068  )
1069 {
1070  int i;
1071 
1072  assert(dialog != NULL);
1073 
1074  /* display the dialog's sub menus */
1075  for( i = 0; i < dialog->nsubdialogs; ++i )
1076  {
1077  if( SCIPdialogIsSubmenu(dialog->subdialogs[i]) )
1078  {
1079  SCIP_CALL( SCIPdialogDisplayMenuEntry(dialog->subdialogs[i], scip) );
1080  }
1081  }
1082 
1083  /* display the dialog's menu options */
1084  for( i = 0; i < dialog->nsubdialogs; ++i )
1085  {
1086  if( !SCIPdialogIsSubmenu(dialog->subdialogs[i]) )
1087  {
1088  SCIP_CALL( SCIPdialogDisplayMenuEntry(dialog->subdialogs[i], scip) );
1089  }
1090  }
1091 
1092  if( dialog->nsubdialogs == 0 )
1093  SCIPdialogMessage(scip, NULL, "<no options available>\n");
1094 
1095  return SCIP_OKAY;
1096 }
1097 
1098 /** displays the entry for the dialog in it's parent's menu */
1100  SCIP_DIALOG* dialog, /**< dialog */
1101  SCIP* scip /**< SCIP data structure */
1102  )
1103 {
1104  char name[SCIP_MAXSTRLEN];
1105 
1106  assert(dialog != NULL);
1107 
1108  /* display the dialog's name */
1109  if( dialog->issubmenu )
1110  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "<%s>", dialog->name);
1111  else
1112  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", dialog->name);
1113  SCIPdialogMessage(scip, NULL, " %-21s ", name);
1114  if( strlen(name) > 21 )
1115  {
1116  /* break the line, and start the description in the next line */
1117  SCIPdialogMessage(scip, NULL, "\n --> ");
1118  }
1119 
1120  /* display the dialog's description */
1121  if( dialog->dialogdesc != NULL )
1122  {
1123  SCIP_CALL( dialog->dialogdesc(scip, dialog) );
1124  }
1125  else
1126  SCIPdialogMessage(scip, NULL, "%s",dialog->desc);
1127  SCIPdialogMessage(scip, NULL, "\n");
1128 
1129  return SCIP_OKAY;
1130 }
1131 
1132 /** displays all dialog entries with names starting with the given "entryname" */
1134  SCIP_DIALOG* dialog, /**< dialog */
1135  SCIP* scip, /**< SCIP data structure */
1136  const char* entryname /**< name of the dialog entry to find */
1137  )
1138 {
1139  SCIP_DIALOG** subdialogs;
1140  unsigned int namelen;
1141  int nsubdialogs;
1142  int i;
1143 
1144  assert(dialog != NULL);
1145  assert(entryname != NULL);
1146 
1147  /* check entryname w.r.t. available dialog options */
1148  subdialogs = SCIPdialogGetSubdialogs(dialog);
1149  nsubdialogs = SCIPdialogGetNSubdialogs(dialog);
1150  namelen = (unsigned int) strlen(entryname);
1151  for( i = 0; i < nsubdialogs; ++i )
1152  {
1153  /* check, if the beginning of the sub-dialog's name matches entryname */
1154  if( strncmp(entryname, SCIPdialogGetName(subdialogs[i]), namelen) == 0 )
1155  {
1156  SCIP_CALL( SCIPdialogDisplayMenuEntry(subdialogs[i], scip) );
1157  }
1158  }
1159 
1160  return SCIP_OKAY;
1161 }
1162 
1163 /** gets the name of the current path in the dialog tree, separated by the given character */
1165  SCIP_DIALOG* dialog, /**< dialog */
1166  const char sepchar, /**< separation character to insert in path */
1167  char* path /**< string buffer to store the path */
1168  )
1169 {
1170  char s[SCIP_MAXSTRLEN];
1171 
1172  assert(dialog != NULL);
1173 
1174  (void)strncpy(path, dialog->name, SCIP_MAXSTRLEN);
1175  path[SCIP_MAXSTRLEN - 1] = '\0';
1176 
1177  dialog = dialog->parent;
1178  while( dialog != NULL )
1179  {
1180  (void)SCIPsnprintf(s, SCIP_MAXSTRLEN, "%s%c%s", dialog->name, sepchar, path);
1181  (void)strncpy(path, s, SCIP_MAXSTRLEN);
1182  path[SCIP_MAXSTRLEN - 1] = '\0';
1183  dialog = dialog->parent;
1184  }
1185 }
1186 
1187 /** gets the command name of the dialog */
1188 const char* SCIPdialogGetName(
1189  SCIP_DIALOG* dialog /**< dialog */
1190  )
1191 {
1192  assert(dialog != NULL);
1193 
1194  return dialog->name;
1195 }
1196 
1197 /** gets the description of the dialog */
1198 const char* SCIPdialogGetDesc(
1199  SCIP_DIALOG* dialog /**< dialog */
1200  )
1201 {
1202  assert(dialog != NULL);
1203 
1204  return dialog->desc;
1205 }
1206 
1207 /** returns whether the dialog is a sub menu */
1209  SCIP_DIALOG* dialog /**< dialog */
1210  )
1211 {
1212  assert(dialog != NULL);
1213 
1214  return dialog->issubmenu;
1215 }
1216 
1217 /** gets the parent dialog of the given dialog */
1219  SCIP_DIALOG* dialog /**< dialog */
1220  )
1221 {
1222  assert(dialog != NULL);
1223 
1224  return dialog->parent;
1225 }
1226 
1227 /** gets the array of sub-dialogs associated with the given dialog */
1229  SCIP_DIALOG* dialog /**< dialog */
1230  )
1231 {
1232  assert(dialog != NULL);
1233 
1234  return dialog->subdialogs;
1235 }
1236 
1237 /** gets the number of sub-dialogs associated with the given dialog */
1239  SCIP_DIALOG* dialog /**< dialog */
1240  )
1241 {
1242  assert(dialog != NULL);
1243 
1244  return dialog->nsubdialogs;
1245 }
1246 
1247 /** gets the user defined data associated with the given dialog */
1249  SCIP_DIALOG* dialog /**< dialog */
1250  )
1251 {
1252  assert(dialog != NULL);
1253 
1254  return dialog->dialogdata;
1255 }
1256 
1257 /** sets user data of dialog; user has to free old data in advance! */
1259  SCIP_DIALOG* dialog, /**< dialog */
1260  SCIP_DIALOGDATA* dialogdata /**< new dialog user data */
1261  )
1262 {
1263  assert(dialog != NULL);
1264 
1265  dialog->dialogdata = dialogdata;
1266 }
1267 
1268 /** writes command history to specified filename */
1270  const char* filename /**< file name for (over)writing history */
1271  )
1272 {
1273  return writeHistory(filename);
1274 }
int SCIPdialogGetNSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1238
static SCIP_RETCODE dialogFree(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:873
void SCIPdialoghdlrClearBuffer(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:435
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:103
const char * SCIPdialogGetName(SCIP_DIALOG *dialog)
Definition: dialog.c:1188
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1319
SCIP_RETCODE SCIPdialogRelease(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:915
#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:932
#define SCIP_MAXSTRLEN
Definition: def.h:215
SCIP_DIALOG ** SCIPdialogGetSubdialogs(SCIP_DIALOG *dialog)
Definition: dialog.c:1228
void SCIPdialogGetPath(SCIP_DIALOG *dialog, const char sepchar, char *path)
Definition: dialog.c:1164
SCIP_RETCODE SCIPdialogDisplayMenuEntry(SCIP_DIALOG *dialog, SCIP *scip)
Definition: dialog.c:1099
SCIP_RETCODE SCIPdialogDisplayCompletions(SCIP_DIALOG *dialog, SCIP *scip, const char *entryname)
Definition: dialog.c:1133
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:5096
int SCIPdialogFindEntry(SCIP_DIALOG *dialog, const char *entryname, SCIP_DIALOG **subdialog)
Definition: dialog.c:1021
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:78
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:100
SCIP_DIALOG * SCIPdialogGetParent(SCIP_DIALOG *dialog)
Definition: dialog.c:1218
static SCIP_RETCODE ensureSubdialogMem(SCIP_DIALOG *dialog, SCIP_SET *set, int num)
Definition: dialog.c:794
void SCIPdialogSetData(SCIP_DIALOG *dialog, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:1258
void SCIPdialogCapture(SCIP_DIALOG *dialog)
Definition: dialog.c:905
#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:102
SCIP_DIALOG ** subdialogs
Definition: struct_dialog.h:45
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPdialogWriteHistory(const char *filename)
Definition: dialog.c:1269
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:1065
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:1198
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:306
SCIP_Bool issubmenu
Definition: struct_dialog.h:50
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:98
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:816
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:988
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:1208
SCIP_RETCODE SCIPsetIncludeExternalCode(SCIP_SET *set, const char *name, const char *description)
Definition: set.c:4647
static SCIP_DECL_SORTPTRCOMP(dialogComp)
Definition: dialog.c:951
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:717
#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:74
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:82
SCIP_RETCODE SCIPdialogAddEntry(SCIP_DIALOG *dialog, SCIP_SET *set, SCIP_DIALOG *subdialog)
Definition: dialog.c:957
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:1248
#define SCIP_ALLOC_TERMINATE(retcode, x, TERM)
Definition: def.h:337
#define SCIP_ALLOC(x)
Definition: def.h:317
static SCIP_RETCODE removeHistory(int pos)
Definition: dialog.c:208
SCIP callable library.
memory allocation routines