1 /* Dump WRTTMP file - This is a debugging command which prints out the current
2  * contents of the wrttmp file in a human-readable format.  Since it is rather
3  * cryptic, I wouldn't recommend installing it for general use.
4  */
5 
6 #include "orville.h"
7 
8 /* Return a pointer to a string of n dashes.  No more than MAXDASH allowed. */
dashes(n)9 char *dashes(n)
10 int n;
11 {
12 #define MAXDASH 30
13 static char *d= "------------------------------";  /* Exactly MAXDASH -'s */
14 
15 	return(n<=MAXDASH ? d+(MAXDASH-n) : d);
16 }
17 
main(int argc,char ** argv)18 main(int argc, char **argv)
19 {
20 FILE *fp;
21 struct wrttmp w;
22 struct wrthdr wt_head;
23 int slot= 0;
24 long x;
25 
26 	progname= leafname(argv[0]);
27 	readconfig(NULL);
28 
29 	if ((fp= fopen(f_wrttmp,"r")) == NULL)
30 	{
31 		printf("cannot open %s\n",f_wrttmp);
32 		exit(1);
33 	}
34 
35 	if (!fread(&wt_head,sizeof(struct wrthdr),1,fp))
36 	{
37 		printf("%s exists, but has no header\n",f_wrttmp);
38 		exit(1);
39 	}
40 	printf("HEAD SIZE = %ld   ENTRY SIZE = %ld\n\n",
41 		wt_head.hdr_size, wt_head.tmp_size);
42 
43 	printf("--line%s --what%s --last%s * E  P M H R B --pid-- ---login time---\n",
44 		dashes(UT_LINESIZE-6),
45 		dashes(UT_NAMESIZE-6),
46 		dashes(UT_NAMESIZE-6));
47 	for (;;)
48 	{
49 		x= wrttmp_offset(slot++);
50 		fseek(fp,x,0);
51 		if (!fread(&w,sizeof(struct wrttmp),1,fp))
52 			break;
53 
54 		printf("%-*.*s %-*.*s %-*.*s %c %c %2d %c %c %c %c %7d  %15.15s\n",
55 			UT_LINESIZE,UT_LINESIZE,w.wrt_line,
56 			UT_NAMESIZE,UT_NAMESIZE,w.wrt_what,
57 			UT_NAMESIZE,UT_NAMESIZE,w.wrt_last,
58 #ifndef TTYPERMS
59 			isprint(w.wrt_mesg) ? w.wrt_mesg : '#',
60 #else
61 			' ',
62 #endif
63 			isprint(w.wrt_except) ? w.wrt_except : '#',
64 			w.wrt_telpref,
65 			isprint(w.wrt_modepref) ? w.wrt_modepref : '#',
66 			isprint(w.wrt_help) ? w.wrt_help : '#',
67 			isprint(w.wrt_modepref) ? w.wrt_record : '#',
68 			isprint(w.wrt_bells) ? w.wrt_bells : '#',
69 			w.wrt_pid,
70 			ctime(&w.wrt_time)+4);
71 	}
72 }
73