File: wt.c

package info (click to toggle)
orville-write 2.55-2.3
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 568 kB
  • ctags: 317
  • sloc: ansic: 3,494; sh: 2,978; makefile: 156
file content (72 lines) | stat: -rw-r--r-- 1,790 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Dump WRTTMP file - This is a debugging command which prints out the current
 * contents of the wrttmp file in a human-readable format.  Since it is rather
 * cryptic, I wouldn't recommend installing it for general use.
 */

#include "orville.h"

/* Return a pointer to a string of n dashes.  No more than MAXDASH allowed. */
char *dashes(n)
int n;
{
#define MAXDASH 30
static char *d= "------------------------------";  /* Exactly MAXDASH -'s */

	return(n<=MAXDASH ? d+(MAXDASH-n) : d);
}

main(int argc, char **argv)
{
FILE *fp;
struct wrttmp w;
struct wrthdr wt_head;
int slot= 0;
long x;
	
	progname= leafname(argv[0]);
	readconfig(NULL);

	if ((fp= fopen(f_wrttmp,"r")) == NULL)
	{
		printf("cannot open %s\n",f_wrttmp);
		exit(1);
	}

	if (!fread(&wt_head,sizeof(struct wrthdr),1,fp))
	{
		printf("%s exists, but has no header\n",f_wrttmp);
		exit(1);
	}
	printf("HEAD SIZE = %ld   ENTRY SIZE = %ld\n\n",
		wt_head.hdr_size, wt_head.tmp_size);

	printf("--line%s --what%s --last%s * E  P M H R B --pid-- ---login time---\n",
		dashes(UT_LINESIZE-6),
		dashes(UT_NAMESIZE-6),
		dashes(UT_NAMESIZE-6));
	for (;;)
	{
		x= wrttmp_offset(slot++);
		fseek(fp,x,0);
		if (!fread(&w,sizeof(struct wrttmp),1,fp))
			break;

		printf("%-*.*s %-*.*s %-*.*s %c %c %2d %c %c %c %c %7d  %15.15s\n",
			UT_LINESIZE,UT_LINESIZE,w.wrt_line,
			UT_NAMESIZE,UT_NAMESIZE,w.wrt_what,
			UT_NAMESIZE,UT_NAMESIZE,w.wrt_last,
#ifndef TTYPERMS
			isprint(w.wrt_mesg) ? w.wrt_mesg : '#',
#else
			' ',
#endif
			isprint(w.wrt_except) ? w.wrt_except : '#',
			w.wrt_telpref,
			isprint(w.wrt_modepref) ? w.wrt_modepref : '#',
			isprint(w.wrt_help) ? w.wrt_help : '#',
			isprint(w.wrt_modepref) ? w.wrt_record : '#',
			isprint(w.wrt_bells) ? w.wrt_bells : '#',
			w.wrt_pid,
			ctime(&w.wrt_time)+4);
	}
}