8ee2eb456a0bffddebc7a8e8194dfe4eb1c23cb1
[citadel.git] / webcit / serv_func.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include "webcit.h"
5
6 struct serv_info serv_info;
7
8 /*
9  * get info about the server we've connected to
10  */
11 void get_serv_info() {
12         char buf[256];
13         int a;
14
15         serv_printf("IDEN %d|%d|%d|%s|%s",
16                 DEVELOPER_ID,
17                 CLIENT_ID,
18                 CLIENT_VERSION,
19                 SERVER,
20                 ""              /* FIX find out where the user is */
21                 );
22         serv_gets(buf);
23
24         serv_puts("INFO");
25         serv_gets(buf);
26         if (buf[0]!='1') return;
27
28         a = 0;
29         while(serv_gets(buf), strcmp(buf,"000")) {
30             switch(a) {
31                 case 0:         serv_info.serv_pid = atoi(buf);
32                                 break;
33                 case 1:         strcpy(serv_info.serv_nodename,buf);
34                                 break;
35                 case 2:         strcpy(serv_info.serv_humannode,buf);
36                                 break;
37                 case 3:         strcpy(serv_info.serv_fqdn,buf);
38                                 break;
39                 case 4:         strcpy(serv_info.serv_software,buf);
40                                 break;
41                 case 5:         serv_info.serv_rev_level = atoi(buf);
42                                 break;
43                 case 6:         strcpy(serv_info.serv_bbs_city,buf);
44                                 break;
45                 case 7:         strcpy(serv_info.serv_sysadm,buf);
46                                 break;
47                 case 9:         strcpy(serv_info.serv_moreprompt,buf);
48                                 break;
49                 }
50             ++a;
51             }
52         }
53
54
55
56 /* 
57  * Function to spit out Citadel variformat text in HTML
58  * If fp is non-null, it is considered to be the file handle to read the
59  * text from.  Otherwise, text is read from the server.
60  */
61 void fmout(fp)
62 FILE *fp; {
63
64         int intext = 0;
65         int bq = 0;
66         int a;
67         char buf[256];
68
69         while(1) {
70                 if (fp==NULL) serv_gets(buf);
71                 if (fp!=NULL) {
72                         if (fgets(buf,256,fp)==NULL) strcpy(buf,"000");
73                         buf[strlen(buf)-1] = 0;
74                         }
75                 if (!strcmp(buf,"000")) {
76                         if (bq==1) wprintf("</I>");
77                         wprintf("<P>\n");
78                         return;
79                         }
80                 if ( (intext==1) && (isspace(buf[0])) ) {
81                         wprintf("<BR>");
82                         }
83                 intext = 1;
84
85                 /* Quoted text should be displayed in italics and in a
86                  * different colour.  This code understands both Citadel/UX
87                  * style " >" quotes and FordBoard-style " :-)" quotes.
88                  */
89                 if ((bq==0)&&
90                    ((!strncmp(buf," >",2))||(!strncmp(buf," :-)",4)))) {
91                         wprintf("<FONT COLOR=\"000044\"><I>");
92                         bq = 1;
93                         }
94                 else if ((bq==1)&&
95                      (strncmp(buf," >",2))&&(strncmp(buf," :-)",4))) {
96                         wprintf("</FONT></I>");
97                         bq = 0;
98                         }
99
100                 /* Activate embedded URL's */
101                 url(buf);
102
103                 escputs(buf);
104                 wprintf("\n");
105                 }
106         }
107