]> the.earth.li Git - sersniff.git/blob - disp_basic.c
Use socklen_t rather than int for the length of the socket address.
[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 #include <string.h>
25
26 #include "disp_basic.h"
27
28 /* Which port did we display last? */
29 static int last=-1;
30 /* Count of chars so far this line */
31 static int wrap=WRAPINIT;
32
33
34 /* Initialise the display, ie do nothing */
35 int disp_init()
36 {
37         return 0;
38 }
39
40 /* Close the display, ie do nothing */
41 int disp_close()
42 {
43         return 0;
44 }
45
46 /* Output a status string about what's happening */
47 void disp_outputstatus(char *string)
48 {
49         printf("\n%s\n\t", string);
50         last=-1;
51         wrap=WRAPINIT;
52 }
53
54 /* Output a string from the port. */
55 void disp_outputstr(int port, char *string,
56                 long usec_threshold, long usec_waited, char *name1, char *name2)
57 {
58         if (usec_waited>usec_threshold) {
59                 /* report how long we waited between the last port */
60                 if (wrap!=WRAPINIT) printf("\n");
61                 printf("\t<waited %0ld.%0ld seconds>\n",
62                         usec_waited / USEC,
63                         usec_waited % USEC);
64                 wrap=WRAPINIT;
65         }
66
67         if (last!=port) {
68                 /* If we didn't just send a CR, we need to now */
69                 if (wrap!=WRAPINIT) printf("\n");
70                 //printf("\nPort%d:\t", port);
71                 if (port == 1)
72                         printf("\n%s:\t",name1);
73                 else
74                         printf("\n%s:\t",name2);
75                 last=port;
76                 wrap=WRAPINIT;
77         } else if (wrap==WRAPINIT) {
78                 /* We should indent since we're continuing the same port
79                         as last time */
80                 printf("\t");
81         }
82
83         /* If we'd go over the line end, wrap */
84         if (strlen(string)+wrap > SCREEN_WIDTH) {
85                 wrap=WRAPINIT;
86                 printf("\n\t");
87         }
88
89         wrap+=strlen(string);
90         printf("%s", string);
91
92         if (wrap % SCREEN_WIDTH == 0) {
93                 /* we hit the edge of the screen */
94                 wrap=WRAPINIT;
95                 printf("\n");
96         }
97         
98         /* flush all the time */
99         fflush(NULL);
100 }