Import (slightly modified) ru.koi8-r.win.kbd:1.1 from FreeBSD (fjoe):
[dragonfly.git] / contrib / gdb / gdb / main.c
1 /* Top level stuff for GDB, the GNU debugger.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3    Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include <setjmp.h>
23 #include <unistd.h>
24 #include "top.h"
25 #include "target.h"
26 #include "inferior.h"
27 #include "call-cmds.h"
28
29 #include "getopt.h"
30
31 #include <sys/types.h>
32 #include "gdb_stat.h"
33 #include <ctype.h>
34
35 #include "gdb_string.h"
36
37 /* Temporary variable for SET_TOP_LEVEL.  */
38
39 static int top_level_val;
40
41 /* Do a setjmp on error_return and quit_return.  catch_errors is
42    generally a cleaner way to do this, but main() would look pretty
43    ugly if it had to use catch_errors each time.  */
44
45 #define SET_TOP_LEVEL() \
46   (((top_level_val = SIGSETJMP (error_return)) \
47     ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (SIGJMP_BUF))) \
48    , top_level_val)
49
50 /* If nonzero, display time usage both at startup and for each command.  */
51
52 int display_time;
53
54 /* If nonzero, display space usage both at startup and for each command.  */
55
56 int display_space;
57
58 /* Whether this is the command line version or not */
59 int tui_version = 0;
60
61 /* Whether xdb commands will be handled */
62 int xdb_commands = 0;
63
64 /* Whether dbx commands will be handled */
65 int dbx_commands = 0;
66
67 GDB_FILE *gdb_stdout;
68 GDB_FILE *gdb_stderr;
69
70 /* Whether to enable writing into executable and core files */
71 extern int write_files;
72
73 static void print_gdb_help PARAMS ((GDB_FILE *));
74 extern void gdb_init PARAMS ((char *));
75
76 /* These two are used to set the external editor commands when gdb is farming
77    out files to be edited by another program. */
78
79 extern int enable_external_editor;
80 extern char * external_editor_command;
81
82 #ifdef __CYGWIN__
83 #include <windows.h> /* for MAX_PATH */
84 #include <sys/cygwin.h> /* for cygwin32_conv_to_posix_path */
85 #endif
86
87 int
88 main (argc, argv)
89      int argc;
90      char **argv;
91 {
92   int count;
93   static int quiet = 0;
94   static int batch = 0;
95
96   /* Pointers to various arguments from command line.  */
97   char *symarg = NULL;
98   char *execarg = NULL;
99   char *corearg = NULL;
100   char *cdarg = NULL;
101   char *ttyarg = NULL;
102
103   /* These are static so that we can take their address in an initializer.  */
104   static int print_help;
105   static int print_version;
106
107   /* Pointers to all arguments of --command option.  */
108   char **cmdarg;
109   /* Allocated size of cmdarg.  */
110   int cmdsize;
111   /* Number of elements of cmdarg used.  */
112   int ncmd;
113
114   /* Indices of all arguments of --directory option.  */
115   char **dirarg;
116   /* Allocated size.  */
117   int dirsize;
118   /* Number of elements used.  */
119   int ndir;
120   
121   struct stat homebuf, cwdbuf;
122   char *homedir, *homeinit;
123
124   register int i;
125
126   long time_at_startup = get_run_time ();
127
128   int gdb_file_size;
129
130   START_PROGRESS (argv[0], 0);
131
132 #ifdef MPW
133   /* Do all Mac-specific setup. */
134   mac_init ();
135 #endif /* MPW */
136
137   /* This needs to happen before the first use of malloc.  */
138   init_malloc ((PTR) NULL);
139
140 #if defined (ALIGN_STACK_ON_STARTUP)
141   i = (int) &count & 0x3;
142   if (i != 0)
143     alloca (4 - i);
144 #endif
145
146   /* If error() is called from initialization code, just exit */
147   if (SET_TOP_LEVEL ()) {
148     exit(1);
149   }
150
151   cmdsize = 1;
152   cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
153   ncmd = 0;
154   dirsize = 1;
155   dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
156   ndir = 0;
157
158   quit_flag = 0;
159   line = (char *) xmalloc (linesize);
160   line[0] = '\0';               /* Terminate saved (now empty) cmd line */
161   instream = stdin;
162
163   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
164   current_directory = gdb_dirbuf;
165
166   gdb_file_size = sizeof(GDB_FILE);
167
168   gdb_stdout = (GDB_FILE *)xmalloc (gdb_file_size);
169   gdb_stdout->ts_streamtype = afile;
170   gdb_stdout->ts_filestream = stdout;
171   gdb_stdout->ts_strbuf = NULL;
172   gdb_stdout->ts_buflen = 0;
173
174   gdb_stderr = (GDB_FILE *)xmalloc (gdb_file_size);
175   gdb_stderr->ts_streamtype = afile;
176   gdb_stderr->ts_filestream = stderr;
177   gdb_stderr->ts_strbuf = NULL;
178   gdb_stderr->ts_buflen = 0;
179
180   /* Parse arguments and options.  */
181   {
182     int c;
183     /* When var field is 0, use flag field to record the equivalent
184        short option (or arbitrary numbers starting at 10 for those
185        with no equivalent).  */
186     static struct option long_options[] =
187       {
188 #if defined(TUI)
189         {"tui", no_argument, &tui_version, 1},
190 #endif
191         {"xdb", no_argument, &xdb_commands, 1},
192         {"dbx", no_argument, &dbx_commands, 1},
193         {"readnow", no_argument, &readnow_symbol_files, 1},
194         {"r", no_argument, &readnow_symbol_files, 1},
195         {"mapped", no_argument, &mapped_symbol_files, 1},
196         {"m", no_argument, &mapped_symbol_files, 1},
197         {"quiet", no_argument, &quiet, 1},
198         {"q", no_argument, &quiet, 1},
199         {"silent", no_argument, &quiet, 1},
200         {"nx", no_argument, &inhibit_gdbinit, 1},
201         {"n", no_argument, &inhibit_gdbinit, 1},
202         {"batch", no_argument, &batch, 1},
203         {"epoch", no_argument, &epoch_interface, 1},
204
205         /* This is a synonym for "--annotate=1".  --annotate is now preferred,
206            but keep this here for a long time because people will be running
207            emacses which use --fullname.  */
208         {"fullname", no_argument, 0, 'f'},
209         {"f", no_argument, 0, 'f'},
210
211         {"annotate", required_argument, 0, 12},
212         {"help", no_argument, &print_help, 1},
213         {"se", required_argument, 0, 10},
214         {"symbols", required_argument, 0, 's'},
215         {"s", required_argument, 0, 's'},
216         {"exec", required_argument, 0, 'e'},
217         {"e", required_argument, 0, 'e'},
218         {"core", required_argument, 0, 'c'},
219         {"c", required_argument, 0, 'c'},
220         {"command", required_argument, 0, 'x'},
221         {"version", no_argument, &print_version, 1},
222         {"x", required_argument, 0, 'x'},
223         {"directory", required_argument, 0, 'd'},
224         {"cd", required_argument, 0, 11},
225         {"tty", required_argument, 0, 't'},
226         {"baud", required_argument, 0, 'b'},
227         {"b", required_argument, 0, 'b'},
228         {"nw", no_argument, &use_windows, 0},
229         {"nowindows", no_argument, &use_windows, 0},
230         {"w", no_argument, &use_windows, 1},
231         {"windows", no_argument, &use_windows, 1},
232         {"statistics", no_argument, 0, 13},
233         {"write", no_argument, &write_files, 1},
234 /* Allow machine descriptions to add more options... */
235 #ifdef ADDITIONAL_OPTIONS
236         ADDITIONAL_OPTIONS
237 #endif
238         {0, no_argument, 0, 0}
239       };
240
241     while (1)
242       {
243         int option_index;
244
245         c = getopt_long_only (argc, argv, "",
246                               long_options, &option_index);
247         if (c == EOF)
248           break;
249
250         /* Long option that takes an argument.  */
251         if (c == 0 && long_options[option_index].flag == 0)
252           c = long_options[option_index].val;
253
254         switch (c)
255           {
256           case 0:
257             /* Long option that just sets a flag.  */
258             break;
259           case 10:
260             symarg = optarg;
261             execarg = optarg;
262             break;
263           case 11:
264             cdarg = optarg;
265             break;
266           case 12:
267             /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
268             annotation_level = atoi (optarg);
269             break;
270           case 13:
271             /* Enable the display of both time and space usage.  */
272             display_time = 1;
273             display_space = 1;
274             break;
275           case 'f':
276             annotation_level = 1;
277 /* We have probably been invoked from emacs.  Disable window interface.  */
278             use_windows = 0;
279             break;
280           case 's':
281             symarg = optarg;
282             break;
283           case 'e':
284             execarg = optarg;
285             break;
286           case 'c':
287             corearg = optarg;
288             break;
289           case 'x':
290             cmdarg[ncmd++] = optarg;
291             if (ncmd >= cmdsize)
292               {
293                 cmdsize *= 2;
294                 cmdarg = (char **) xrealloc ((char *)cmdarg,
295                                              cmdsize * sizeof (*cmdarg));
296               }
297             break;
298           case 'd':
299             dirarg[ndir++] = optarg;
300             if (ndir >= dirsize)
301               {
302                 dirsize *= 2;
303                 dirarg = (char **) xrealloc ((char *)dirarg,
304                                              dirsize * sizeof (*dirarg));
305               }
306             break;
307           case 't':
308             ttyarg = optarg;
309             break;
310           case 'q':
311             quiet = 1;
312             break;
313           case 'b':
314             {
315               int i;
316               char *p;
317
318               i = strtol (optarg, &p, 0);
319               if (i == 0 && p == optarg)
320
321                 /* Don't use *_filtered or warning() (which relies on
322                    current_target) until after initialize_all_files(). */
323
324                 fprintf_unfiltered
325                   (gdb_stderr,
326                    "warning: could not set baud rate to `%s'.\n", optarg);
327               else
328                 baud_rate = i;
329             }
330           case 'l':
331             {
332               int i;
333               char *p;
334
335               i = strtol (optarg, &p, 0);
336               if (i == 0 && p == optarg)
337
338                 /* Don't use *_filtered or warning() (which relies on
339                    current_target) until after initialize_all_files(). */
340
341                 fprintf_unfiltered
342                   (gdb_stderr,
343                    "warning: could not set timeout limit to `%s'.\n", optarg);
344               else
345                 remote_timeout = i;
346             }
347             break;
348
349 #ifdef ADDITIONAL_OPTION_CASES
350           ADDITIONAL_OPTION_CASES
351 #endif
352           case '?':
353             fprintf_unfiltered (gdb_stderr,
354                      "Use `%s --help' for a complete list of options.\n",
355                      argv[0]);
356             exit (1);
357           }
358       }
359
360     /* If --help or --version, disable window interface.  */
361     if (print_help || print_version)
362       {
363         use_windows = 0;
364 #ifdef TUI
365         /* Disable the TUI as well.  */
366         tui_version = 0;
367 #endif
368       }
369
370 #ifdef TUI
371     /* An explicit --tui flag overrides the default UI, which is the
372        window system.  */
373     if (tui_version)
374       use_windows = 0;
375 #endif      
376
377     /* OK, that's all the options.  The other arguments are filenames.  */
378     count = 0;
379     for (; optind < argc; optind++)
380       switch (++count)
381         {
382         case 1:
383           symarg = argv[optind];
384           execarg = argv[optind];
385           break;
386         case 2:
387           corearg = argv[optind];
388           break;
389         case 3:
390           fprintf_unfiltered (gdb_stderr,
391                    "Excess command line arguments ignored. (%s%s)\n",
392                    argv[optind], (optind == argc - 1) ? "" : " ...");
393           break;
394         }
395     if (batch)
396       quiet = 1;
397   }
398
399 #if defined(TUI)
400   if (tui_version)
401     init_ui_hook = tuiInit;
402 #endif
403   gdb_init (argv[0]);
404
405   /* Do these (and anything which might call wrap_here or *_filtered)
406      after initialize_all_files.  */
407   if (print_version)
408     {
409       print_gdb_version (gdb_stdout);
410       wrap_here ("");
411       printf_filtered ("\n");
412       exit (0);
413     }
414
415   if (print_help)
416     {
417       print_gdb_help (gdb_stdout);
418       fputs_unfiltered ("\n", gdb_stdout);
419       exit (0);
420     }
421
422   if (!quiet)
423     {
424       /* Print all the junk at the top, with trailing "..." if we are about
425          to read a symbol file (possibly slowly).  */
426       print_gdb_version (gdb_stdout);
427       if (symarg)
428         printf_filtered ("..");
429       wrap_here("");
430       gdb_flush (gdb_stdout);           /* Force to screen during slow operations */
431     }
432
433   error_pre_print = "\n\n";
434   quit_pre_print = error_pre_print;
435
436   /* We may get more than one warning, don't double space all of them... */
437   warning_pre_print = "\nwarning: ";
438
439   /* Read and execute $HOME/.gdbinit file, if it exists.  This is done
440      *before* all the command line arguments are processed; it sets
441      global parameters, which are independent of what file you are
442      debugging or what directory you are in.  */
443 #ifdef __CYGWIN32__
444   {
445     char * tmp = getenv ("HOME");
446     
447     if (tmp != NULL)
448       {
449         homedir = (char *) alloca (MAX_PATH+1);
450         cygwin32_conv_to_posix_path (tmp, homedir);
451       }
452     else
453       homedir = NULL;
454   }
455 #else
456   homedir = getenv ("HOME");  
457 #endif
458   if (homedir)
459     {
460       homeinit = (char *) alloca (strlen (homedir) +
461                                   strlen (gdbinit) + 10);
462       strcpy (homeinit, homedir);
463       strcat (homeinit, "/");
464       strcat (homeinit, gdbinit);
465
466       if (!inhibit_gdbinit)
467         {
468           if (!SET_TOP_LEVEL ())
469             source_command (homeinit, 0);
470         }
471       do_cleanups (ALL_CLEANUPS);
472
473       /* Do stats; no need to do them elsewhere since we'll only
474          need them if homedir is set.  Make sure that they are
475          zero in case one of them fails (this guarantees that they
476          won't match if either exists).  */
477       
478       memset (&homebuf, 0, sizeof (struct stat));
479       memset (&cwdbuf, 0, sizeof (struct stat));
480       
481       stat (homeinit, &homebuf);
482       stat (gdbinit, &cwdbuf); /* We'll only need this if
483                                        homedir was set.  */
484     }
485
486   /* Now perform all the actions indicated by the arguments.  */
487   if (cdarg != NULL)
488     {
489       if (!SET_TOP_LEVEL ())
490         {
491           cd_command (cdarg, 0);
492         }
493     }
494   do_cleanups (ALL_CLEANUPS);
495
496   for (i = 0; i < ndir; i++)
497     if (!SET_TOP_LEVEL ())
498       directory_command (dirarg[i], 0);
499   free ((PTR)dirarg);
500   do_cleanups (ALL_CLEANUPS);
501
502   if (execarg != NULL
503       && symarg != NULL
504       && STREQ (execarg, symarg))
505     {
506       /* The exec file and the symbol-file are the same.  If we can't open
507          it, better only print one error message.  */
508       if (!SET_TOP_LEVEL ())
509         {
510           exec_file_command (execarg, !batch);
511           symbol_file_command (symarg, 0);
512         }
513     }
514   else
515     {
516       if (execarg != NULL)
517         if (!SET_TOP_LEVEL ())
518           exec_file_command (execarg, !batch);
519       if (symarg != NULL)
520         if (!SET_TOP_LEVEL ())
521           symbol_file_command (symarg, 0);
522     }
523   do_cleanups (ALL_CLEANUPS);
524
525   /* After the symbol file has been read, print a newline to get us
526      beyond the copyright line...  But errors should still set off
527      the error message with a (single) blank line.  */
528   if (!quiet)
529     printf_filtered ("\n");
530   error_pre_print = "\n";
531   quit_pre_print = error_pre_print;
532   warning_pre_print = "\nwarning: ";
533
534   if (corearg != NULL)
535     {
536       if (!SET_TOP_LEVEL ())
537         core_file_command (corearg, !batch);
538       else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ())
539         attach_command (corearg, !batch);
540     }
541   do_cleanups (ALL_CLEANUPS);
542
543   if (ttyarg != NULL)
544     if (!SET_TOP_LEVEL ())
545       tty_command (ttyarg, !batch);
546   do_cleanups (ALL_CLEANUPS);
547
548 #ifdef ADDITIONAL_OPTION_HANDLER
549   ADDITIONAL_OPTION_HANDLER;
550 #endif
551
552   /* Error messages should no longer be distinguished with extra output. */
553   error_pre_print = NULL;
554   quit_pre_print = NULL;
555   warning_pre_print = "warning: ";
556
557   /* Read the .gdbinit file in the current directory, *if* it isn't
558      the same as the $HOME/.gdbinit file (it should exist, also).  */
559   
560   if (!homedir
561       || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
562     if (!inhibit_gdbinit)
563       {
564         if (!SET_TOP_LEVEL ())
565           source_command (gdbinit, 0);
566       }
567   do_cleanups (ALL_CLEANUPS);
568
569   for (i = 0; i < ncmd; i++)
570     {
571       if (!SET_TOP_LEVEL ())
572         {
573           if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
574             read_command_file (stdin);
575           else
576             source_command (cmdarg[i], !batch);
577           do_cleanups (ALL_CLEANUPS);
578         }
579     }
580   free ((PTR)cmdarg);
581
582   /* Read in the old history after all the command files have been read. */
583   init_history();
584
585   if (batch)
586     {
587       /* We have hit the end of the batch file.  */
588       exit (0);
589     }
590
591   /* Do any host- or target-specific hacks.  This is used for i960 targets
592      to force the user to set a nindy target and spec its parameters.  */
593
594 #ifdef BEFORE_MAIN_LOOP_HOOK
595   BEFORE_MAIN_LOOP_HOOK;
596 #endif
597
598   END_PROGRESS (argv[0]);
599
600   /* Show time and/or space usage.  */
601
602   if (display_time)
603     {
604       long init_time = get_run_time () - time_at_startup;
605
606       printf_unfiltered ("Startup time: %ld.%06ld\n",
607                          init_time / 1000000, init_time % 1000000);
608     }
609
610   if (display_space)
611     {
612 #ifdef HAVE_SBRK
613       extern char **environ;
614       char *lim = (char *) sbrk (0);
615
616       printf_unfiltered ("Startup size: data size %ld\n",
617                          (long) (lim - (char *) &environ));
618 #endif
619     }
620
621   /* The default command loop. 
622      The WIN32 Gui calls this main to set up gdb's state, and 
623      has its own command loop. */
624 #if !defined _WIN32 || defined __GNUC__
625   while (1)
626     {
627       if (!SET_TOP_LEVEL ())
628         {
629           do_cleanups (ALL_CLEANUPS);           /* Do complete cleanup */
630           /* GUIs generally have their own command loop, mainloop, or whatever.
631              This is a good place to gain control because many error
632              conditions will end up here via longjmp(). */
633           if (command_loop_hook)
634             command_loop_hook ();
635           else
636             command_loop ();
637           quit_command ((char *)0, instream == stdin);
638         }
639     }
640
641   /* No exit -- exit is through quit_command.  */
642 #endif
643
644 }
645
646 /* Don't use *_filtered for printing help.  We don't want to prompt
647    for continue no matter how small the screen or how much we're going
648    to print.  */
649
650 static void
651 print_gdb_help (stream)
652   GDB_FILE *stream;
653 {
654       fputs_unfiltered ("\
655 This is the GNU debugger.  Usage:\n\n\
656     gdb [options] [executable-file [core-file or process-id]]\n\n\
657 Options:\n\n\
658 ", stream);
659       fputs_unfiltered ("\
660   -b BAUDRATE        Set serial port baud rate used for remote debugging.\n\
661   --batch            Exit after processing options.\n\
662   --cd=DIR           Change current directory to DIR.\n\
663   --command=FILE     Execute GDB commands from FILE.\n\
664   --core=COREFILE    Analyze the core dump COREFILE.\n\
665 ", stream);
666       fputs_unfiltered ("\
667   --dbx              DBX compatibility mode.\n\
668   --directory=DIR    Search for source files in DIR.\n\
669   --epoch            Output information used by epoch emacs-GDB interface.\n\
670   --exec=EXECFILE    Use EXECFILE as the executable.\n\
671   --fullname         Output information used by emacs-GDB interface.\n\
672   --help             Print this message.\n\
673 ", stream);
674       fputs_unfiltered ("\
675   --mapped           Use mapped symbol files if supported on this system.\n\
676   --nw               Do not use a window interface.\n\
677   --nx               Do not read .gdbinit file.\n\
678   --quiet            Do not print version number on startup.\n\
679   --readnow          Fully read symbol files on first access.\n\
680 ", stream);
681       fputs_unfiltered ("\
682   --se=FILE          Use FILE as symbol file and executable file.\n\
683   --symbols=SYMFILE  Read symbols from SYMFILE.\n\
684   --tty=TTY          Use TTY for input/output by the program being debugged.\n\
685 ", stream);
686 #if defined(TUI)
687       fputs_unfiltered ("\
688   --tui              Use a terminal user interface.\n\
689 ", stream);
690 #endif
691       fputs_unfiltered ("\
692   --version          Print version information and then exit.\n\
693   -w                 Use a window interface.\n\
694   --write            Set writing into executable and core files.\n\
695   --xdb              XDB compatibility mode.\n\
696 ", stream);
697 #ifdef ADDITIONAL_OPTION_HELP
698       fputs_unfiltered (ADDITIONAL_OPTION_HELP, stream);
699 #endif
700       fputs_unfiltered ("\n\
701 For more information, type \"help\" from within GDB, or consult the\n\
702 GDB manual (available as on-line info or a printed manual).\n\
703 Report bugs to \"bug-gdb@prep.ai.mit.edu\".\
704 ", stream);
705 }
706
707 \f
708 void
709 init_proc ()
710 {
711 }
712
713 void
714 proc_remove_foreign (pid)
715      int pid;
716 {
717 }
718
719 /* All I/O sent to the *_filtered and *_unfiltered functions eventually ends up
720    here.  The fputs_unfiltered_hook is primarily used by GUIs to collect all
721    output and send it to the GUI, instead of the controlling terminal.  Only
722    output to gdb_stdout and gdb_stderr are sent to the hook.  Everything else
723    is sent on to fputs to allow file I/O to be handled appropriately.  */
724
725 void
726 fputs_unfiltered (linebuffer, stream)
727      const char *linebuffer;
728      GDB_FILE *stream;
729 {
730 #if defined(TUI)
731   extern int tui_owns_terminal;
732 #endif
733   /* If anything (GUI, TUI) wants to capture GDB output, this is
734    * the place... the way to do it is to set up 
735    * fputs_unfiltered_hook.
736    * Our TUI ("gdb -tui") used to hook output, but in the
737    * new (XDB style) scheme, we do not do that anymore... - RT
738    */
739   if (fputs_unfiltered_hook
740       && (stream == gdb_stdout
741           || stream == gdb_stderr))
742     fputs_unfiltered_hook (linebuffer, stream);
743   else
744     {
745 #if defined(TUI)
746       if (tui_version && tui_owns_terminal) {
747         /* If we get here somehow while updating the TUI (from
748          * within a tuiDo(), then we need to temporarily 
749          * set up the terminal for GDB output. This probably just
750          * happens on error output.
751          */
752
753         if (stream->ts_streamtype == astring) {
754            gdb_file_adjust_strbuf(strlen(linebuffer), stream);
755            strcat(stream->ts_strbuf, linebuffer);
756         } else {
757            tuiTermUnsetup(0, (tui_version) ? cmdWin->detail.commandInfo.curch : 0);
758            fputs (linebuffer, stream->ts_filestream);
759            tuiTermSetup(0);
760            if (linebuffer[strlen(linebuffer) - 1] == '\n')
761               tuiClearCommandCharCount();
762            else
763               tuiIncrCommandCharCountBy(strlen(linebuffer));
764         }
765       } else {
766         /* The normal case - just do a fputs() */
767         if (stream->ts_streamtype == astring) {
768            gdb_file_adjust_strbuf(strlen(linebuffer), stream);
769            strcat(stream->ts_strbuf, linebuffer);
770         } else fputs (linebuffer, stream->ts_filestream);
771       }
772  
773
774 #else
775       if (stream->ts_streamtype == astring) {
776            gdb_file_adjust_strbuf(strlen(linebuffer), stream);
777            strcat(stream->ts_strbuf, linebuffer);
778         } else fputs (linebuffer, stream->ts_filestream);
779 #endif
780     }
781 }