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