]> the.earth.li Git - sersniff.git/blob - disp_basic.c
39f4e36b6ecb54cf2a059eb7e2183340eb8288e8
[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)
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                 last=port;
71                 wrap=WRAPINIT;
72         } else if (wrap==WRAPINIT) {
73                 /* We should indent since we're continuing the same port
74                         as last time */
75                 printf("\t");
76         }
77
78         /* If we'd go over the line end, wrap */
79         if (strlen(string)+wrap > SCREEN_WIDTH) {
80                 wrap=WRAPINIT;
81                 printf("\n\t");
82         }
83
84         wrap+=strlen(string);
85         printf("%s", string);
86
87         if (wrap % SCREEN_WIDTH == 0) {
88                 /* we hit the edge of the screen */
89                 wrap=WRAPINIT;
90                 printf("\n");
91         }
92         
93         /* flush all the time */
94         fflush(NULL);
95 }