]> the.earth.li Git - sersniff.git/blob - disp_basic.c
d1c50150abe1d8380d5d01c795ca11b6bd766809
[sersniff.git] / disp_basic.c
1 /*
2         disp_basic.c - Routines to do basic output with no fanciness.
3         Copyright 2000 Project Purple. Written by Jonathan McDowell
4
5         This program is free software; you can redistribute it and/or
6         modify it under the terms of the GNU General Public License
7         as published by the Free Software Foundation; either version 2
8         of the License, or (at your option) any later version.
9
10         This program is distributed in the hope that it will be useful,
11         but WITHOUT ANY WARRANTY; without even the implied warranty of
12         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13         GNU General Public License for more details.
14
15         You should have received a copy of the GNU General Public License
16         along with this program; if not, write to the Free Software Foundation
17         Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18         http://www.gnu.org/copyleft/gpl.html
19
20         17/02/2000 - Started writing.
21 */
22
23 #include <stdio.h>
24
25 #include "disp_basic.h"
26
27 /* Which port did we display last? */
28 static int last=-1;
29 /* Count of chars so far this line */
30 static int wrap=WRAPINIT;
31
32
33 /* Initialise the display, ie do nothing */
34 int disp_init()
35 {
36         return 0;
37 }
38
39 /* Close the display, ie do nothing */
40 int disp_close()
41 {
42         return 0;
43 }
44
45 /* Output a status string about what's happening */
46 void disp_outputstatus(char *string)
47 {
48         printf("\n%s\n\t", string);
49         last=-1;
50         wrap=WRAPINIT;
51 }
52
53 /* Output a string from the port. */
54 void disp_outputstr(int port, char *string,
55                 long usec_threshold, long usec_waited, char *name1, char *name2)
56 {
57         if (usec_waited>usec_threshold) {
58                 /* report how long we waited between the last port */
59                 if (wrap!=WRAPINIT) printf("\n");
60                 printf("\t<waited %0ld.%0ld seconds>\n",
61                         usec_waited / USEC,
62                         usec_waited % USEC);
63                 wrap=WRAPINIT;
64         }
65
66         if (last!=port) {
67                 /* If we didn't just send a CR, we need to now */
68                 if (wrap!=WRAPINIT) printf("\n");
69                 //printf("\nPort%d:\t", port);
70                 if (port == 1)
71                         printf("\n%s:\t",name1);
72                 else
73                         printf("\n%s:\t",name2);
74                 last=port;
75                 wrap=WRAPINIT;
76         } else if (wrap==WRAPINIT) {
77                 /* We should indent since we're continuing the same port
78                         as last time */
79                 printf("\t");
80         }
81
82         /* If we'd go over the line end, wrap */
83         if (strlen(string)+wrap > SCREEN_WIDTH) {
84                 wrap=WRAPINIT;
85                 printf("\n\t");
86         }
87
88         wrap+=strlen(string);
89         printf("%s", string);
90
91         if (wrap % SCREEN_WIDTH == 0) {
92                 /* we hit the edge of the screen */
93                 wrap=WRAPINIT;
94                 printf("\n");
95         }
96         
97         /* flush all the time */
98         fflush(NULL);
99 }