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