|
|
1.1 root 1: /* SBBSLIST.C */
2:
3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
4:
5: /* Converts Synchronet BBS List (SBL.DAB) to text file */
6:
7: #include "xsdk.h"
8: #include "sbldefs.h"
9:
10: char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
11: char *mon[]={"Jan","Feb","Mar","Apr","May","Jun"
12: ,"Jul","Aug","Sep","Oct","Nov","Dec"};
13: char *nulstr="";
14: char tmp[256];
15: struct date date;
16: struct time curtime;
17:
18: extern int daylight=0;
19: extern long timezone=0L;
20:
21: typedef struct {
22:
23: char str[13];
24: short offset;
25:
26: } sortstr_t;
27:
28:
29: int sortstr_cmp(sortstr_t **str1, sortstr_t **str2)
30: {
31: return(stricmp((*str1)->str,(*str2)->str));
32: }
33:
34: /****************************************************************************/
35: /* Generates a 24 character ASCII string that represents the time_t pointer */
36: /* Used as a replacement for ctime() */
37: /****************************************************************************/
38: char *timestr(time_t *intime)
39: {
40: static char str[256];
41: char mer[3],hour;
42: struct tm *gm;
43:
44: gm=localtime(intime);
45: if(gm->tm_hour>=12) {
46: if(gm->tm_hour==12)
47: hour=12;
48: else
49: hour=gm->tm_hour-12;
50: strcpy(mer,"pm"); }
51: else {
52: if(gm->tm_hour==0)
53: hour=12;
54: else
55: hour=gm->tm_hour;
56: strcpy(mer,"am"); }
57: sprintf(str,"%s %s %02d %4d %02d:%02d %s"
58: ,wday[gm->tm_wday],mon[gm->tm_mon],gm->tm_mday,1900+gm->tm_year
59: ,hour,gm->tm_min,mer);
60: return(str);
61: }
62:
63: /****************************************************************************/
64: /* Converts unix time format (long - time_t) into a char str MM/DD/YY */
65: /****************************************************************************/
66: char *unixtodstr(time_t unix, char *str)
67: {
68:
69: if(!unix)
70: strcpy(str,"00/00/00");
71: else {
72: unixtodos(unix,&date,&curtime);
73: if((unsigned)date.da_mon>12) { /* DOS leap year bug */
74: date.da_mon=1;
75: date.da_year++; }
76: if((unsigned)date.da_day>31)
77: date.da_day=1;
78: sprintf(str,"%02u/%02u/%02u",date.da_mon,date.da_day
79: ,date.da_year>=2000 ? date.da_year-2000 : date.da_year-1900); }
80: return(str);
81: }
82:
83:
84: void long_bbs_info(FILE *out, bbs_t bbs)
85: {
86: int i;
87:
88: fprintf(out,"BBS Name: %s since %s\r\n"
89: ,bbs.name,unixtodstr(bbs.birth,tmp));
90: fprintf(out,"Operator: ");
91: for(i=0;i<bbs.total_sysops && i<MAX_SYSOPS;i++) {
92: if(i) {
93: if(bbs.total_sysops>2)
94: fprintf(out,", ");
95: else
96: fputc(SP,out);
97: if(!(i%4))
98: fprintf(out,"\r\n ");
99: if(i+1==bbs.total_sysops)
100: fprintf(out,"and "); }
101: fprintf(out,"%s",bbs.sysop[i]); }
102: fprintf(out,"\r\n");
103: fprintf(out,"Software: %-15.15s Nodes: %-5u "
104: "Users: %-5u Doors: %u\r\n"
105: ,bbs.software,bbs.nodes,bbs.users,bbs.xtrns);
106: fprintf(out,"Download: %lu files in %u directories of "
107: "%luMB total space\r\n"
108: ,bbs.files,bbs.dirs,bbs.megs);
109: fprintf(out,"Messages: %lu messages in %u sub-boards\r\n"
110: ,bbs.msgs,bbs.subs);
111: fprintf(out,"Networks: ");
112: for(i=0;i<bbs.total_networks && i<MAX_NETS;i++) {
113: if(i) {
114: if(bbs.total_networks>2)
115: fprintf(out,", ");
116: else
117: fputc(SP,out);
118: if(!(i%3))
119: fprintf(out,"\r\n ");
120: if(i+1==bbs.total_networks)
121: fprintf(out,"and "); }
122: fprintf(out,"%s [%s]",bbs.network[i],bbs.address[i]); }
123: fprintf(out,"\r\n");
124: fprintf(out,"Terminal: ");
125: for(i=0;i<bbs.total_terminals && i<MAX_TERMS;i++) {
126: if(i) {
127: if(bbs.total_terminals>2)
128: fprintf(out,", ");
129: else
130: fputc(SP,out);
131: if(i+1==bbs.total_terminals)
132: fprintf(out,"and "); }
133: fprintf(out,"%s",bbs.terminal[i]); }
134: fprintf(out,"\r\n\r\n");
135: for(i=0;i<bbs.total_numbers && i<MAX_NUMBERS;i++)
136: fprintf(out,"%-30.30s %12.12s %5u %-15.15s "
137: "Minimum: %u\r\n"
138: ,i && !strcmp(bbs.number[i].location,bbs.number[i-1].location)
139: ? nulstr : bbs.number[i].location
140: ,bbs.number[i].number
141: ,bbs.number[i].max_rate,bbs.number[i].modem
142: ,bbs.number[i].min_rate);
143:
144: fprintf(out,"\r\n");
145: for(i=0;i<5;i++) {
146: if(!bbs.desc[i][0])
147: break;
148: fprintf(out,"%15s%s\r\n",nulstr,bbs.desc[i]); }
149:
150: fprintf(out,"\r\n");
151: fprintf(out,"Entry created on %s by %s\r\n"
152: ,timestr(&bbs.created),bbs.user);
153: if(bbs.updated && bbs.userupdated[0])
154: fprintf(out," Last updated on %s by %s\r\n"
155: ,timestr(&bbs.updated),bbs.userupdated);
156: if(bbs.verified && bbs.userverified[0])
157: fprintf(out,"Last verified on %s by %s\r\n"
158: ,timestr(&bbs.verified),bbs.userverified);
159: }
160:
161: int main(int argc, char **argv)
162: {
163: char str[128];
164: int i,j,file,ff;
165: FILE *in,*shrt,*lng;
166: bbs_t bbs;
167: sortstr_t **sortstr=NULL;
168:
169: if((i=open("SBL.DAB",O_RDONLY|O_BINARY|O_DENYNONE))==-1) {
170: printf("error opening SBL.DAB\n");
171: return(1); }
172:
173: if((in=fdopen(i,"rb"))==NULL) {
174: printf("error opening SBL.DAB\n");
175: return(1); }
176:
177: if((shrt=fopen("SBBS.LST","wb"))==NULL) {
178: printf("error opening/creating SBBS.LST\n");
179: return(1); }
180:
181: if((lng=fopen("SBBS_DET.LST","wb"))==NULL) {
182: printf("error opening/creating SBBS_DET.LST\n");
183: return(1); }
184:
185: fprintf(shrt,"Synchronet BBS List exported from Vertrauen on %s\r\n"
186: "======================================================="
187: "\r\n\r\n"
188: ,unixtodstr(time(NULL),str));
189:
190: fprintf(lng,"Detailed Synchronet BBS List exported from Vertrauen on %s\r\n"
191: "================================================================"
192: "\r\n\r\n"
193: ,unixtodstr(time(NULL),str));
194:
195: printf("Sorting...");
196: fseek(in,0L,SEEK_SET);
197: i=j=0;
198: while(1) {
199: if(!fread(&bbs,sizeof(bbs_t),1,in))
200: break;
201: j++;
202: printf("%4u\b\b\b\b",j);
203: if(!bbs.name[0] || strnicmp(bbs.software,"SYNCHRONET",10))
204: continue;
205: i++;
206: strcpy(str,bbs.number[0].number);
207: if((sortstr=(sortstr_t **)farrealloc(sortstr
208: ,sizeof(sortstr_t *)*i))==NULL) {
209: printf("\r\n\7Memory allocation error\r\n");
210: return(1); }
211: if((sortstr[i-1]=(sortstr_t *)farmalloc(sizeof(sortstr_t)
212: ))==NULL) {
213: printf("\r\n\7Memory allocation error\r\n");
214: return(1); }
215: strcpy(sortstr[i-1]->str,str);
216: sortstr[i-1]->offset=j-1; }
217:
218: qsort((void *)sortstr,i,sizeof(sortstr[0])
219: ,(int(*)(const void *, const void *))sortstr_cmp);
220:
221: printf("\nCreating index...");
222: sprintf(str,"SBBSSORT.NDX");
223: if((file=open(str,O_RDWR|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD))==-1) {
224: printf("\n\7Error creating %s\n",str);
225: return(1); }
226: for(j=0;j<i;j++)
227: write(file,&sortstr[j]->offset,2);
228: printf("\n");
229:
230: lseek(file,0L,SEEK_SET);
231: ff=0;
232: while(1) {
233: if(read(file,&i,2)!=2)
234: break;
235: fseek(in,(long)i*sizeof(bbs_t),SEEK_SET);
236: if(!fread(&bbs,sizeof(bbs_t),1,in))
237: break;
238: long_bbs_info(lng,bbs);
239: if(ff)
240: fprintf(lng,"\x0c\r\n");
241: else
242: fprintf(lng,"\r\n---------------------------------------------"
243: "----------------------------------\r\n\r\n");
244: ff=!ff;
245: for(i=0;i<bbs.total_numbers && i<MAX_NUMBERS;i++)
246: fprintf(shrt,"%-25.25s %-30.30s %12.12s %u\r\n"
247: ,i ? "" : bbs.name,bbs.number[i].location,bbs.number[i].number
248: ,bbs.number[i].max_rate);
249: }
250: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.