1 /* @source  application
2 **
3 ** Displays information on the currently available servers
4 **
5 ** @author Copyright (C) Peter Rice (pmr@ebi.ac.uk)
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 ******************************************************************************/
22 
23 #include "emboss.h"
24 
25 
26 
27 static void showserverWidth (const AjPStr svrname,
28                              const AjPStr scope, const AjPStr type,
29                              const AjPStr methods, ajuint count,
30                              const AjPStr defined, const AjPStr version,
31                              const AjPStr cachefile, const AjPStr url,
32                              ajuint *maxname, ajuint *maxscope,
33                              ajuint *maxtype, ajuint *maxmethod,
34                              ajuint *maxcount, ajuint *maxfield,
35                              ajuint* maxdefined, ajuint *maxversion,
36                              ajuint *maxcachefile, ajuint *maxurl);
37 static void showserverHead (AjPFile outfile, AjBool html,
38                             AjBool doscope, AjBool dotype,
39                             AjBool doid, AjBool doqry, AjBool doall,
40                             AjBool domethod, AjBool docount,
41                             AjBool dofields, AjBool dodefined,
42                             AjBool docomment, AjBool doversion,
43                             AjBool docachefile, AjBool dourl,
44                             ajuint maxname, ajuint maxscope, ajuint maxtype,
45                             ajuint maxmethod, ajuint maxcount, ajuint maxfield,
46                             ajuint maxdefined, ajuint maxversion,
47                             ajuint maxcachefile, ajuint maxurl);
48 
49 static void   showserverOut(AjPFile outfile,
50                             const AjPStr svrname,
51                             const AjPStr scope, const AjPStr type,
52                             AjBool id, AjBool qry, AjBool all,
53                             const AjPStr methods, ajuint count,
54                             const AjPStr defined,
55                             const AjPStr comment, const AjPStr version,
56                             const AjPStr cachefile, const AjPStr url,
57                             AjBool html, AjBool doscope, AjBool dotype,
58                             AjBool doid, AjBool doqry, AjBool doall,
59                             AjBool domethod, AjBool docount,
60                             AjBool dofields, AjBool dodefined,
61                             AjBool docomment, AjBool doversion,
62                             AjBool docachefile, AjBool dourl,
63                             ajuint maxname, ajuint maxscope,
64                             ajuint maxtype, ajuint maxmethod, ajuint maxcount,
65                             ajuint maxfield, ajuint maxdefined,
66                             ajuint maxversion, ajuint maxcachefile,
67                             ajuint maxurl);
68 
69 static void   showserverGetFields(const AjPStr svrname, AjPStr* fields);
70 static int    showserverSortDefined(const void* str1, const void* str2);
71 static int    showserverSortType(const void* str1, const void* str2);
72 
73 
74 
75 
76 /* @prog showserver ***********************************************************
77 **
78 ** Displays information on the currently available servers
79 **
80 ******************************************************************************/
81 
main(int argc,char ** argv)82 int main(int argc, char **argv)
83 {
84     AjPStr sortby;
85     AjPStr *showtypes;
86     AjBool html;
87     AjBool doheader;
88     AjBool doscope;
89     AjBool dotype;
90     AjBool doid;
91     AjBool doqry;
92     AjBool doall;
93     AjBool domethod;
94     AjBool docount;
95     AjBool dofields;
96     AjBool dodefined;
97     AjBool doversion;
98     AjBool docachefile;
99     AjBool dourl;
100     AjBool docomment;
101 
102     AjPFile outfile = NULL;
103     AjPStr onesvrname   = NULL;		/* user-specified single server */
104     AjPStr nextsvrname   = NULL;	/* the next server name to look at */
105     AjPStr type     = NULL;
106     AjPStr scope    = NULL;
107     AjBool id;
108     AjBool qry;
109     AjBool all;
110     AjPStr methods = NULL;
111     AjPStr defined = NULL;
112     AjPStr version = NULL;
113     AjPStr cachefile = NULL;
114     AjPStr cachedir  = NULL;
115     AjPStr url = NULL;
116     AjPStr comment = NULL;
117     ajuint count = 0;
118 
119     AjPList svrnames = NULL;
120     AjIList iter = NULL;
121 
122     ajuint maxname = 14;
123     ajuint maxmethod = 6;
124     ajuint maxcount = 5;
125     ajuint maxfield = 6;
126     ajuint maxscope = 5;
127     ajuint maxtype = 4;
128     ajuint maxdefined = 7;
129     ajuint maxversion = 7;
130     ajuint maxcachefile = 9;
131     ajuint maxurl = 3;
132 
133     AjPTable showtable = NULL;
134     AjBool showtype = ajFalse;
135     AjBool doshow = ajTrue;
136 
137     int (*sortfunc) (const void* str1, const void* str2);
138 
139     AjPStrTok handle = NULL;
140     AjPStr nexttype = NULL;
141 
142     ajuint i;
143 
144     ajNamSetControl("namvalid");	/* validate server defs */
145 
146     embInit("showserver", argc, argv);
147 
148     onesvrname  = ajAcdGetString("servername");
149     outfile = ajAcdGetOutfile("outfile");
150 
151     html      = ajAcdGetBoolean("html");
152     showtypes = ajAcdGetList("showtypes");
153     sortby    = ajAcdGetListSingle("sortby");
154 
155     doheader  = ajAcdGetBoolean("heading");
156     doscope   = ajAcdGetBoolean("scope");
157     dotype    = ajAcdGetBoolean("type");
158     doid      = ajAcdGetBoolean("id");
159     doqry     = ajAcdGetBoolean("query");
160     doall     = ajAcdGetBoolean("all");
161     dofields  = ajAcdGetBoolean("fields");
162     dodefined = ajAcdGetBoolean("defined");
163     domethod  = ajAcdGetBoolean("methods");
164     docount   = ajAcdGetBoolean("count");
165     docomment = ajAcdGetBoolean("comment");
166     doversion = ajAcdGetBoolean("serverversion");
167     docachefile = ajAcdGetBoolean("cachefile");
168     dourl     = ajAcdGetBoolean("url");
169 
170     svrnames  = ajListstrNew();
171 
172     if(ajStrMatchC(sortby, "defined"))
173         sortfunc = &showserverSortDefined;
174     else if(ajStrMatchC(sortby, "type"))
175         sortfunc = &showserverSortType;
176     else
177         sortfunc = NULL;
178 
179     showtable = ajTablestrNew(10);
180     for(i=0; showtypes[i]; i++)
181         ajTablePut(showtable, ajStrNewS(showtypes[i]), &doshow);
182 
183 /* start the HTML table */
184     if(html)
185 	ajFmtPrintF(outfile, "<table border cellpadding=4 bgcolor="
186 		    "\"#FFFFF0\">\n");
187 
188 
189     /* Just one specified name to get details on? */
190     if(ajStrGetLen(onesvrname))
191     {
192 	if(ajNamSvrDetails(onesvrname, &type, &scope, &id, &qry, &all, &comment,
193                            &version, &methods, &defined, &cachedir,
194                            &cachefile, &url))
195         {
196             count = ajNamSvrCount(onesvrname);
197 	    showserverWidth(onesvrname, scope, type, methods, count,
198                             defined, version, cachefile, url,
199                             &maxname, &maxscope, &maxtype, &maxmethod,
200                             &maxcount, &maxfield, &maxdefined, &maxversion,
201                             &maxcachefile, &maxurl);
202         }
203 
204 	/* print the header information */
205         if(doheader)
206         {
207             showserverHead(outfile, html, doscope, dotype, doid, doqry,
208                            doall, domethod, docount, dofields, dodefined,
209                            docomment, doversion, docachefile, dourl,
210                            maxname, maxscope, maxtype, maxmethod,
211                            maxcount, maxfield,
212                            maxdefined, maxversion, maxcachefile, maxurl);
213 
214             showserverOut(outfile, onesvrname, scope, type, id, qry, all,
215                           methods, count, defined,
216                           comment, version, cachefile, url, html,
217                           doscope, dotype, doid, doqry, doall,
218                           domethod, docount, dofields, dodefined,
219                           docomment, doversion, docachefile, dourl,
220                           maxname, maxscope, maxtype,
221                           maxmethod, maxcount, maxfield, maxdefined,
222                           maxversion, maxcachefile, maxurl);
223 	}
224 	else
225 	    ajFatal("The server '%S' does not exist", onesvrname);
226     }
227     else
228     {
229 	/* get the list of server names */
230 	ajNamListListServers(svrnames);
231 
232 	/* sort it */
233 	/*ajListSort(svrnames, &ajStrCmp);*/
234         if(sortfunc)
235             ajListSort(svrnames, sortfunc);
236 
237 	/* iterate through the svrnames list */
238 	iter = ajListIterNewread(svrnames);
239 
240 	maxname = 14;
241 	maxmethod = 6;
242 	maxfield = 6;
243 	maxtype = 4;
244 	maxversion = 7;
245 
246 	/* find the field widths */
247 	while((nextsvrname = ajListIterGet(iter)) != NULL)
248 	{
249 	    if(ajNamSvrDetails(nextsvrname, &type, &scope,
250                                &id, &qry, &all, &comment,
251                                &version, &methods, &defined,
252                                &cachedir, &cachefile, &url))
253             {
254                 count = ajNamSvrCount(nextsvrname);
255                 showserverWidth(nextsvrname, scope, type, methods, count,
256                                 defined, version, cachefile, url,
257                                 &maxname, &maxscope, &maxtype, &maxmethod,
258                                 &maxcount, &maxfield, &maxdefined,
259                                 &maxversion, &maxcachefile, &maxurl);
260             }
261 	}
262 
263 	/* print the header information */
264 	if(doheader)
265 	    showserverHead(outfile, html, doscope, dotype, doid, doqry,
266                            doall, domethod, docount, dofields, dodefined,
267                            docomment, doversion, docachefile, dourl,
268                            maxname, maxscope, maxtype, maxmethod,
269                            maxcount, maxfield,
270                            maxdefined, maxversion, maxcachefile, maxurl);
271 
272 	ajListIterDel(&iter);
273 
274 	/* iterate through the svrnames list */
275 	iter = ajListIterNewread(svrnames);
276 
277 	/* write out servers */
278 	while((nextsvrname = ajListIterGet(iter)) != NULL)
279 	    if(ajNamSvrDetails(nextsvrname, &type,  &scope,
280                                &id, &qry, &all, &comment,
281                                &version, &methods, &defined,
282                                &cachedir, &cachefile, &url))
283 	    {
284                 showtype = ajFalse;
285                 count = ajNamSvrCount(nextsvrname);
286                 ajStrTokenAssignC(&handle, type, " ,;");
287 
288                 while(ajStrTokenNextParse(handle, &nexttype))
289                     if(ajTableMatchS(showtable,nexttype))
290                         showtype = ajTrue;
291 
292                 ajStrDel(&nexttype);
293                 ajStrTokenDel(&handle);
294 
295                 if(showtype)
296                     showserverOut(outfile, nextsvrname, scope, type,
297                                   id, qry, all,
298                                   methods, count, defined,
299                                   comment, version, cachefile, url,
300                                   html, doscope, dotype, doid,
301                                   doqry, doall, domethod,
302                                   docount, dofields, dodefined,
303                                   docomment, doversion, docachefile, dourl,
304                                   maxname, maxscope, maxtype, maxmethod,
305                                   maxcount, maxfield, maxdefined,
306                                   maxversion, maxcachefile, maxurl);
307 	    }
308 	    else
309 		ajFatal("The server '%S' does not exist", nextsvrname);
310 
311 
312 	/* reset the iterator */
313 	ajListIterDel(&iter);
314 
315     }
316 
317     /* end the HTML table */
318     if(html)
319 	ajFmtPrintF(outfile, "</table>\n");
320 
321     ajFileClose(&outfile);
322     ajStrDel(&onesvrname);
323     ajStrDel(&type);
324     ajStrDel(&scope);
325     ajStrDel(&methods);
326     ajStrDel(&defined);
327     ajStrDel(&cachedir);
328     ajStrDel(&cachefile);
329     ajStrDel(&url);
330     ajStrDel(&version);
331     ajStrDel(&comment);
332     ajStrDel(&sortby);
333 
334     ajListstrFree(&svrnames);
335 
336     ajTablestrFreeKey(&showtable);
337 
338     ajStrDelarray(&showtypes);
339 
340     embExit();
341 
342     return 0;
343 }
344 
345 
346 
347 
348 /* @funcstatic showserverWidth ************************************************
349 **
350 ** Update maximum width for variable length text
351 **
352 ** @param [r] svrname [const AjPStr] server name
353 ** @param [r] scope [const AjPStr] server scope
354 ** @param [r] type [const AjPStr] server type
355 ** @param [r] methods [const AjPStr] server access method(s)
356 ** @param [r] count [ajuint] Database count
357 ** @param [r] defined [const AjPStr] server definition file short name
358 ** @param [r] version [const AjPStr] server version number
359 ** @param [r] cachefile [const AjPStr] server cachefile name
360 ** @param [r] url [const AjPStr] server URL
361 ** @param [u] maxname [ajuint*] Maximum width for name
362 ** @param [u] maxtype [ajuint*] Maximum width for type
363 ** @param [u] maxscope [ajuint*] Maximum width for list of scopes
364 ** @param [u] maxmethod [ajuint*] Maximum width for list of access methods
365 ** @param [u] maxcount [ajuint*] Maximum width for database count
366 ** @param [u] maxfield [ajuint*] Maximum width for list of fields
367 ** @param [u] maxdefined [ajuint*] Maximum width for definition file
368 ** @param [u] maxversion [ajuint*] Maximum width for version number
369 ** @param [u] maxcachefile [ajuint*] Maximum width for cachefile name
370 ** @param [u] maxurl [ajuint*] Maximum width for URL
371 ******************************************************************************/
372 
showserverWidth(const AjPStr svrname,const AjPStr scope,const AjPStr type,const AjPStr methods,ajuint count,const AjPStr defined,const AjPStr version,const AjPStr cachefile,const AjPStr url,ajuint * maxname,ajuint * maxtype,ajuint * maxscope,ajuint * maxmethod,ajuint * maxcount,ajuint * maxfield,ajuint * maxdefined,ajuint * maxversion,ajuint * maxcachefile,ajuint * maxurl)373 static void showserverWidth (const AjPStr svrname, const AjPStr scope,
374                              const AjPStr type, const AjPStr methods,
375                              ajuint count,
376                              const AjPStr defined, const AjPStr version,
377                              const AjPStr cachefile, const AjPStr url,
378                              ajuint *maxname, ajuint* maxtype,
379                              ajuint* maxscope, ajuint *maxmethod,
380                              ajuint *maxcount,
381                              ajuint *maxfield, ajuint* maxdefined,
382                              ajuint *maxversion, ajuint *maxcachefile,
383                              ajuint *maxurl)
384 {
385     AjPStr fields = NULL;
386     ajuint i;
387     ajuint testcount;
388     ajuint testwidth = 0;
389 
390     if (MAJSTRGETLEN(svrname) > *maxname)
391 	*maxname = MAJSTRGETLEN(svrname);
392 
393     if (MAJSTRGETLEN(scope) > *maxscope)
394 	*maxscope = MAJSTRGETLEN(scope);
395 
396     if (MAJSTRGETLEN(type) > *maxtype)
397 	*maxtype = MAJSTRGETLEN(type);
398 
399     if (MAJSTRGETLEN(methods) > *maxmethod)
400 	*maxmethod = MAJSTRGETLEN(methods);
401 
402     testcount = count;
403     if(!count)
404         testcount++;
405 
406     for(testcount = count; testcount > 0; testcount /= 10)
407         testwidth++;
408 
409     if(testwidth > *maxcount)
410         *maxcount = testwidth;
411 
412     if (MAJSTRGETLEN(defined) > *maxdefined)
413 	*maxdefined = MAJSTRGETLEN(defined);
414 
415     if (MAJSTRGETLEN(version) > *maxversion)
416 	*maxversion = MAJSTRGETLEN(version);
417 
418     if (MAJSTRGETLEN(cachefile) > *maxcachefile)
419 	*maxcachefile = MAJSTRGETLEN(cachefile);
420 
421     if (MAJSTRGETLEN(url) > *maxurl)
422 	*maxurl = MAJSTRGETLEN(url);
423 
424     showserverGetFields(svrname, &fields);
425     i = MAJSTRGETLEN(fields);
426 
427     if (i > *maxfield)
428 	*maxfield = i;
429 
430     ajStrDel(&fields);
431 
432     return;
433 }
434 
435 
436 
437 
438 /* @funcstatic showserverHead *************************************************
439 **
440 ** Output header for server information
441 **
442 ** @param [w] outfile [AjPFile] outfile
443 ** @param [r] html [AjBool] do html
444 ** @param [r] doscope [AjBool] show scope
445 ** @param [r] dotype [AjBool] show type
446 ** @param [r] doid [AjBool] show id
447 ** @param [r] doqry [AjBool] show query status
448 ** @param [r] doall [AjBool] show everything
449 ** @param [r] domethod [AjBool] show access method(s)
450 ** @param [r] docount [AjBool] show database count
451 ** @param [r] dofields [AjBool] show query fields
452 ** @param [r] dodefined [AjBool] show definition file
453 ** @param [r] docomment [AjBool] show comment
454 ** @param [r] doversion [AjBool] show version
455 ** @param [r] docachefile [AjBool] show cachefile name
456 ** @param [r] dourl [AjBool] show URL
457 ** @param [r] maxname [ajuint] Maximum width for name
458 ** @param [r] maxscope [ajuint] Maximum width for scope
459 ** @param [r] maxtype [ajuint] Maximum width for type
460 ** @param [r] maxmethod [ajuint] Maximum width for access method
461 ** @param [r] maxcount [ajuint] Maximum width for databas count
462 ** @param [r] maxfield [ajuint] Maximum width for list of fields
463 ** @param [r] maxdefined [ajuint] Maximum width for definition file
464 ** @param [r] maxversion [ajuint] Maximum width for version number
465 ** @param [r] maxcachefile [ajuint] Maximum width for cachefile name
466 ** @param [r] maxurl [ajuint] Maximum width for URL
467 ******************************************************************************/
468 
showserverHead(AjPFile outfile,AjBool html,AjBool doscope,AjBool dotype,AjBool doid,AjBool doqry,AjBool doall,AjBool domethod,AjBool docount,AjBool dofields,AjBool dodefined,AjBool docomment,AjBool doversion,AjBool docachefile,AjBool dourl,ajuint maxname,ajuint maxscope,ajuint maxtype,ajuint maxmethod,ajuint maxcount,ajuint maxfield,ajuint maxdefined,ajuint maxversion,ajuint maxcachefile,ajuint maxurl)469 static void showserverHead (AjPFile outfile, AjBool html,
470                             AjBool doscope, AjBool dotype,
471                             AjBool doid, AjBool doqry, AjBool doall,
472                             AjBool domethod, AjBool docount,
473                             AjBool dofields, AjBool dodefined,
474                             AjBool docomment, AjBool doversion,
475                             AjBool docachefile, AjBool dourl,
476                             ajuint maxname, ajuint maxscope,
477                             ajuint maxtype, ajuint maxmethod, ajuint maxcount,
478                             ajuint maxfield, ajuint maxdefined,
479                             ajuint maxversion, ajuint maxcachefile,
480                             ajuint maxurl)
481 {
482     AjPStr understr = NULL;
483     ajuint maxlen = maxname;
484 
485     maxlen = AJMAX(maxlen, maxscope);
486     maxlen = AJMAX(maxlen, maxtype);
487     maxlen = AJMAX(maxlen, maxmethod);
488     maxlen = AJMAX(maxlen, maxcount);
489     maxlen = AJMAX(maxlen, maxfield);
490     maxlen = AJMAX(maxlen, maxdefined);
491     maxlen = AJMAX(maxlen, maxversion);
492     maxlen = AJMAX(maxlen, maxcachefile);
493     maxlen = AJMAX(maxlen, maxurl);
494 
495     ajStrAppendCountK(&understr, '=', maxlen);
496 
497     if(html)
498 	/* start the HTML table title line and output the Name header */
499 	ajFmtPrintF(outfile, "<tr><th>Name</th>");
500     else
501 	ajFmtPrintF(outfile, "# Name%*s", maxname-5, " ");
502 
503     if(doscope)
504     {
505 	if(html)
506 	    ajFmtPrintF(outfile, "<th>Scope</th>");
507 	else
508 	    ajFmtPrintF(outfile, "Scope%*s", maxscope-4, " ");
509     }
510 
511     if(dotype)
512     {
513 	if(html)
514 	    ajFmtPrintF(outfile, "<th>Type</th>");
515 	else
516 	    ajFmtPrintF(outfile, "Type%*s", maxtype-3, " ");
517     }
518 
519     if(doid)
520     {
521 	if(html)
522 	    ajFmtPrintF(outfile, "<th>ID</th>");
523 	else
524 	    ajFmtPrintF(outfile, "ID  ");
525     }
526 
527     if(doqry)
528     {
529 	if(html)
530 	    ajFmtPrintF(outfile, "<th>Qry</th>");
531 	else
532 	    ajFmtPrintF(outfile, "Qry ");
533     }
534 
535     if(doall)
536     {
537 	if(html)
538 	    ajFmtPrintF(outfile, "<th>All</th>");
539 	else
540 	    ajFmtPrintF(outfile, "All ");
541     }
542 
543     if(domethod)
544     {
545 	if(html)
546 	    ajFmtPrintF(outfile, "<th>Method</th>");
547 	else
548 	    ajFmtPrintF(outfile, "Method%*s", maxmethod-5, " ");
549     }
550 
551     if(docount)
552     {
553 	if(html)
554 	    ajFmtPrintF(outfile, "<th>Count</th>");
555 	else
556 	    ajFmtPrintF(outfile, "Count%*s", maxcount-4, " ");
557     }
558 
559     if(docachefile)
560     {
561 	if(html)
562 	    ajFmtPrintF(outfile, "<th>Cachefile</th>");
563 	else
564 	    ajFmtPrintF(outfile, "Cachefile%*s", maxcachefile-8, " ");
565     }
566 
567     if(dourl)
568     {
569 	if(html)
570 	    ajFmtPrintF(outfile, "<th>URL</th>");
571 	else
572 	    ajFmtPrintF(outfile, "URL%*s", maxurl-2, " ");
573     }
574 
575     if(dofields)
576     {
577 	if(html)
578 	    ajFmtPrintF(outfile, "<th>Fields</th>");
579 	else
580 	    ajFmtPrintF(outfile, "Fields%*s", maxfield-5, " ");
581     }
582 
583     if(dodefined)
584     {
585 	if(html)
586 	    ajFmtPrintF(outfile, "<th>Defined</th>");
587 	else
588 	    ajFmtPrintF(outfile, "Defined%*s", maxdefined-6, " ");
589     }
590 
591     if(doversion)
592     {
593 	if(html)
594 	    ajFmtPrintF(outfile, "<th>Version</th>");
595 	else
596 	    ajFmtPrintF(outfile, "Version%*s", maxversion-6, " ");
597     }
598 
599     if(docomment)
600     {
601 	if(html)
602 	    ajFmtPrintF(outfile, "<th>Comment</th>");
603 	else
604 	    ajFmtPrintF(outfile, "Comment");
605     }
606 
607     if(html)
608 	/* end the HTML table title line */
609 	ajFmtPrintF(outfile, "</tr>\n");
610     else
611     {
612 	ajFmtPrintF(outfile, "\n");
613 
614 	ajFmtPrintF(outfile, "# %.*S ", maxname-2, understr);
615 
616 	if(dotype)
617 	    ajFmtPrintF(outfile, "%.*S ", maxtype, understr);
618 
619 	if(doscope)
620 	    ajFmtPrintF(outfile, "%.*S ", maxscope, understr);
621 
622 	if(doid)
623 	    ajFmtPrintF(outfile, "==  ");
624 
625 	if(doqry)
626 	    ajFmtPrintF(outfile, "=== ");
627 
628 	if(doall)
629 	    ajFmtPrintF(outfile, "=== ");
630 
631 	if(domethod)
632 	    ajFmtPrintF(outfile, "%.*S ", maxmethod, understr);
633 
634 	if(docount)
635 	    ajFmtPrintF(outfile, "%.*S ", maxcount, understr);
636 
637 	if(docachefile)
638 	    ajFmtPrintF(outfile, "%.*S ", maxcachefile, understr);
639 
640 	if(dourl)
641 	    ajFmtPrintF(outfile, "%.*S ", maxurl, understr);
642 
643 	if(dofields)
644 	    ajFmtPrintF(outfile, "%.*S ", maxfield, understr);
645 
646 	if(dodefined)
647 	    ajFmtPrintF(outfile, "%.*S ", maxdefined, understr);
648 
649 	if(doversion)
650 	    ajFmtPrintF(outfile, "%.*S ", maxversion,  understr);
651 
652 	if(docomment)
653 	    ajFmtPrintF(outfile, "=======");
654 
655 	ajFmtPrintF(outfile, "\n");
656     }
657 
658     ajStrDel(&understr);
659 
660     return;
661 }
662 
663 
664 
665 
666 /* @funcstatic showserverOut **************************************************
667 **
668 ** Output server information
669 **
670 ** @param [w] outfile [AjPFile] outfile
671 ** @param [r] svrname [const AjPStr] server name
672 ** @param [r] scope [const AjPStr] scope
673 ** @param [r] type [const AjPStr] type
674 ** @param [r] id [AjBool] id
675 ** @param [r] qry [AjBool] queryable
676 ** @param [r] all [AjBool] all info
677 ** @param [r] methods [const AjPStr] server access method(s)
678 ** @param [r] count [ajuint] database count
679 ** @param [r] defined [const AjPStr] server definition file short name
680 ** @param [r] comment [const AjPStr] server comment
681 ** @param [r] version [const AjPStr] server version
682 ** @param [r] cachefile [const AjPStr] server cachefile name
683 ** @param [r] url [const AjPStr] server URL
684 ** @param [r] html [AjBool] do html
685 ** @param [r] doscope [AjBool] show scope
686 ** @param [r] dotype [AjBool] show type
687 ** @param [r] doid [AjBool] show id
688 ** @param [r] doqry [AjBool] show query status
689 ** @param [r] doall [AjBool] show everything
690 ** @param [r] domethod [AjBool] show access method(s)
691 ** @param [r] docount [AjBool] show database count
692 ** @param [r] dofields [AjBool] show query fields
693 ** @param [r] dodefined [AjBool] show access method(s)
694 ** @param [r] docomment [AjBool] show comment
695 ** @param [r] doversion [AjBool] show version
696 ** @param [r] docachefile [AjBool] show cachefile
697 ** @param [r] dourl [AjBool] show URL
698 ** @param [r] maxname [ajuint] Maximum width for name
699 ** @param [r] maxscope [ajuint] Maximum width for scope
700 ** @param [r] maxtype [ajuint] Maximum width for type
701 ** @param [r] maxmethod [ajuint] Maximum width for list of access methods
702 ** @param [r] maxcount [ajuint] Maximum width for database count
703 ** @param [r] maxfield [ajuint] Maximum width for list of fields
704 ** @param [r] maxdefined [ajuint] Maximum width for definition file
705 ** @param [r] maxversion [ajuint] Maximum width for version number
706 ** @param [r] maxcachefile [ajuint] Maximum width for cachefile name
707 ** @param [r] maxurl [ajuint] Maximum width for URL
708 ** @@
709 ******************************************************************************/
710 
showserverOut(AjPFile outfile,const AjPStr svrname,const AjPStr scope,const AjPStr type,AjBool id,AjBool qry,AjBool all,const AjPStr methods,ajuint count,const AjPStr defined,const AjPStr comment,const AjPStr version,const AjPStr cachefile,const AjPStr url,AjBool html,AjBool doscope,AjBool dotype,AjBool doid,AjBool doqry,AjBool doall,AjBool domethod,AjBool docount,AjBool dofields,AjBool dodefined,AjBool docomment,AjBool doversion,AjBool docachefile,AjBool dourl,ajuint maxname,ajuint maxscope,ajuint maxtype,ajuint maxmethod,ajuint maxcount,ajuint maxfield,ajuint maxdefined,ajuint maxversion,ajuint maxcachefile,ajuint maxurl)711 static void showserverOut(AjPFile outfile,
712                           const AjPStr svrname, const AjPStr scope,
713                           const AjPStr type,
714                           AjBool id, AjBool qry, AjBool all,
715                           const AjPStr methods, ajuint count,
716                           const AjPStr defined,
717                           const AjPStr comment, const AjPStr version,
718                           const AjPStr cachefile, const AjPStr url,
719                           AjBool html, AjBool doscope, AjBool dotype,
720                           AjBool doid, AjBool doqry, AjBool doall,
721                           AjBool domethod, AjBool docount,
722                           AjBool dofields, AjBool dodefined,
723                           AjBool docomment, AjBool doversion,
724                           AjBool docachefile, AjBool dourl,
725                           ajuint maxname, ajuint maxscope,
726                           ajuint maxtype, ajuint maxmethod, ajuint maxcount,
727                           ajuint maxfield, ajuint maxdefined,
728                           ajuint maxversion, ajuint maxcachefile,
729                           ajuint maxurl)
730 {
731     AjPStr fields = NULL;
732 
733     if(html)
734 	/* start table line and output name */
735 	ajFmtPrintF(outfile, "<tr><td>%S</td>", svrname);
736     else
737 	ajFmtPrintF(outfile, "%-*S ", maxname, svrname);
738 
739     if(doscope)
740     {
741 	if(html)
742 	    ajFmtPrintF(outfile, "<td>%S</td>", scope);
743 	else
744 	    ajFmtPrintF(outfile, "%-*S ", maxscope, scope);
745     }
746 
747     if(dotype)
748     {
749 	if(html)
750 	    ajFmtPrintF(outfile, "<td>%S</td>", type);
751 	else
752 	    ajFmtPrintF(outfile, "%-*S ", maxtype, type);
753     }
754 
755     if(doid)
756     {
757 	if(html)
758 	    ajFmtPrintF(outfile, "<td>");
759 
760 	if(id)
761 	    ajFmtPrintF(outfile, "%s", "OK  ");
762 	else
763 	    ajFmtPrintF(outfile, "%s", "-   ");
764 
765 	if(html)
766 	    ajFmtPrintF(outfile, "</td>");
767     }
768 
769     if(doqry)
770     {
771 	if(html)
772 	    ajFmtPrintF(outfile, "<td>");
773 
774 	if(qry)
775 	    ajFmtPrintF(outfile, "%s", "OK  ");
776 	else
777 	    ajFmtPrintF(outfile, "%s", "-   ");
778 
779 	if(html)
780 	    ajFmtPrintF(outfile, "</td>");
781     }
782 
783     if(doall)
784     {
785 	if(html)
786 	    ajFmtPrintF(outfile, "<td>");
787 
788 	if(all)
789 	    ajFmtPrintF(outfile, "%s", "OK  ");
790 	else
791 	    ajFmtPrintF(outfile, "%s", "-   ");
792 
793 	if(html)
794 	    ajFmtPrintF(outfile, "</td>");
795     }
796 
797     if(domethod)
798     {
799 	if(html)
800 	    ajFmtPrintF(outfile, "<td>");
801 
802         ajFmtPrintF(outfile, "%-*S ", maxmethod, methods);
803 
804 	if(html)
805 	    ajFmtPrintF(outfile, "</td>");
806     }
807 
808     if(docount)
809     {
810 	if(html)
811 	    ajFmtPrintF(outfile, "<td>");
812 
813         ajFmtPrintF(outfile, "%*d ", maxcount, count);
814 
815 	if(html)
816 	    ajFmtPrintF(outfile, "</td>");
817     }
818 
819     if(docachefile)
820     {
821 	if(html)
822 	    ajFmtPrintF(outfile, "<td>");
823 
824 	if(cachefile != NULL)
825 	    ajFmtPrintF(outfile, "%-*S ", maxcachefile, cachefile);
826 	else
827 	    ajFmtPrintF(outfile, "%-*s ", maxcachefile, "");
828 
829 	if(html)
830 	    ajFmtPrintF(outfile, "</td>");
831     }
832 
833 
834     if(dourl)
835     {
836 	if(html)
837 	    ajFmtPrintF(outfile, "<td>");
838 
839 	if(cachefile != NULL)
840 	    ajFmtPrintF(outfile, "%-*S ", maxurl, url);
841 	else
842 	    ajFmtPrintF(outfile, "%-*s ", maxurl, "");
843 
844 	if(html)
845 	    ajFmtPrintF(outfile, "</td>");
846     }
847 
848 
849     if(dofields)
850     {
851 	if(html)
852 	    ajFmtPrintF(outfile, "<td>");
853 
854         showserverGetFields(svrname, &fields);
855 	ajFmtPrintF(outfile, "%-*S ", maxfield, fields);
856 
857 	if(html)
858 	    ajFmtPrintF(outfile, "</td>");
859     }
860 
861     if(dodefined)
862     {
863 	if(html)
864 	    ajFmtPrintF(outfile, "<td>");
865 
866         ajFmtPrintF(outfile, "%-*S ", maxdefined, defined);
867 
868 	if(html)
869 	    ajFmtPrintF(outfile, "</td>");
870     }
871 
872     if(doversion)
873     {
874 	if(html)
875 	    ajFmtPrintF(outfile, "<td>");
876 
877 	if(version != NULL)
878 	    ajFmtPrintF(outfile, "%-*S ", maxversion, version);
879 	else
880 	    ajFmtPrintF(outfile, "%-*s ", maxversion, "");
881 
882 	if(html)
883 	    ajFmtPrintF(outfile, "</td>");
884     }
885 
886 
887     if(docomment)
888     {
889 	if(html)
890 	    ajFmtPrintF(outfile, "<td>");
891 
892 	if(comment != NULL)
893 	    ajFmtPrintF(outfile, "%S", comment);
894 	else
895 	    ajFmtPrintF(outfile, "-");
896 
897 	if(html)
898 	    ajFmtPrintF(outfile, "</td>");
899     }
900 
901     if(html)
902 	ajFmtPrintF(outfile, "</tr>\n");	/* end table line */
903     else
904 	ajFmtPrintF(outfile, "\n");
905 
906     ajStrDel(&fields);
907 
908     return;
909 }
910 
911 
912 
913 
914 /* @funcstatic showserverGetFields ********************************************
915 **
916 ** Get a server's valid query fields (apart from the default 'id' and 'acc')
917 **
918 ** @param [r] svrname [const AjPStr] server name
919 ** @param [w] fields [AjPStr*] the available search fields
920 ** @return [void]
921 ** @@
922 ******************************************************************************/
923 
showserverGetFields(const AjPStr svrname,AjPStr * fields)924 static void showserverGetFields(const AjPStr svrname, AjPStr* fields)
925 {
926     AjPQuery query;
927 
928     query = ajQueryNew(AJDATATYPE_UNKNOWN);
929 
930     ajStrAssignS(&query->SvrName, svrname);
931     ajNamSvrData(query,0);
932     ajStrAssignS(fields, query->DbFields);
933 
934     /* if there are no query fields, then change to a '_' */
935     if(!ajStrGetLen(*fields))
936   	ajStrAssignC(fields, "-     ");
937     else
938 	/* change spaces to commas to make the result one word */
939 	ajStrExchangeSetCC(fields, " ", ",");
940 
941     ajQueryDel(&query);
942     return;
943 }
944 
945 
946 
947 
948 /* @funcstatic showserverSortDefined *****************************************
949 **
950 ** Compares the value of two strings for use in sorting (e.g. ajListSort)
951 **
952 ** @param [r] str1 [const void*] First string
953 ** @param [r] str2 [const void*] Second string
954 ** @return [int] -1 if first string should sort before second, +1 if the
955 **         second string should sort first. 0 if they are identical
956 **         in length and content.
957 ** @category use [AjPStr] String compare
958 ** @@
959 ******************************************************************************/
960 
showserverSortDefined(const void * str1,const void * str2)961 static int showserverSortDefined(const void* str1, const void* str2)
962 {
963     const AjPStr svr1 = *(AjPStr const *) str1;
964     const AjPStr svr2 = *(AjPStr const *) str2;
965 
966     AjPStr methods = NULL;
967     AjPStr version = NULL;
968     AjPStr cachefile = NULL;
969     AjPStr cachedir  = NULL;
970     AjPStr url = NULL;
971     AjPStr comment = NULL;
972     AjPStr type    = NULL;
973     AjPStr scope    = NULL;
974     AjBool id;
975     AjBool qry;
976     AjBool all;
977     AjPStr defined1 = NULL;
978     AjPStr defined2 = NULL;
979     AjBool ok;
980 
981     int ret;
982 
983     ok = ajNamSvrDetails(svr1, &type, &scope,
984                          &id, &qry, &all, &comment,
985                          &version, &methods, &defined1, &cachedir,
986                          &cachefile, &url);
987     if(ok)
988 	ok = ajNamSvrDetails(svr2, &type, &scope,
989                              &id, &qry, &all, &comment,
990                              &version, &methods, &defined2, &cachedir,
991                              &cachefile, &url);
992     ajStrDel(&type);
993     ajStrDel(&scope);
994     ajStrDel(&comment);
995     ajStrDel(&version);
996     ajStrDel(&methods);
997     ajStrDel(&url);
998     ajStrDel(&cachedir);
999 
1000     if(ok)
1001     {
1002 	ret = ajStrCmpS(defined1, defined2);
1003 	ajDebug("Sorting1 %S:%S %S:%S %d\n",
1004                 svr1, svr2, defined1, defined2, ret);
1005 	ajStrDel(&defined1);
1006 	ajStrDel(&defined2);
1007 
1008 	if(ret)
1009             return ret;
1010     }
1011 
1012     ajStrDel(&defined1);
1013     ajStrDel(&defined2);
1014 
1015     ret = ajStrCmpS(svr1, svr2);
1016     ajDebug("Sorting2 %S:%S %d\n", svr1, svr2, ret);
1017 
1018     return ret;
1019 }
1020 
1021 
1022 
1023 
1024 /* @funcstatic showserverSortType *********************************************
1025 **
1026 ** Compares the value of two strings for use in sorting (e.g. ajListSort)
1027 **
1028 ** @param [r] str1 [const void*] First string
1029 ** @param [r] str2 [const void*] Second string
1030 ** @return [int] -1 if first string should sort before second, +1 if the
1031 **         second string should sort first. 0 if they are identical
1032 **         in length and content.
1033 ** @category use [AjPStr] String compare
1034 ** @@
1035 ******************************************************************************/
1036 
showserverSortType(const void * str1,const void * str2)1037 static int showserverSortType(const void* str1, const void* str2)
1038 {
1039     const AjPStr svr1 = NULL;
1040     const AjPStr svr2 = NULL;
1041 
1042     AjPStr methods   = NULL;
1043     AjPStr version   = NULL;
1044     AjPStr cachedir  = NULL;
1045     AjPStr cachefile = NULL;
1046     AjPStr comment   = NULL;
1047     AjPStr url = NULL;
1048     AjPStr type1  = NULL;
1049     AjPStr type2  = NULL;
1050     AjPStr scope1 = NULL;
1051     AjPStr scope2 = NULL;
1052     AjBool id;
1053     AjBool qry;
1054     AjBool all;
1055     AjPStr defined = NULL;
1056     AjBool ok;
1057 
1058     int ret;
1059 
1060     svr1 = *(AjPStr const *) str1;
1061     svr2 = *(AjPStr const *) str2;
1062 
1063     ok = ajNamSvrDetails(svr1, &type1, &scope1,
1064                          &id, &qry, &all, &comment,
1065                          &version, &methods, &defined, &cachedir,
1066                          &cachefile, &url);
1067     if(ok)
1068 	ok = ajNamSvrDetails(svr2, &type2, &scope2,
1069                              &id, &qry, &all, &comment,
1070                              &version, &methods, &defined, &cachedir,
1071                              &cachefile, &url);
1072 
1073     ajStrDel(&defined);
1074     ajStrDel(&comment);
1075     ajStrDel(&version);
1076     ajStrDel(&methods);
1077     ajStrDel(&cachedir);
1078     ajStrDel(&cachefile);
1079     ajStrDel(&url);
1080 
1081     if(ok)
1082     {
1083 	ret = ajStrCmpS(scope1, scope2);
1084 	ajDebug("Sorting1 %S:%S %S:%S %d\n",
1085                 svr1, svr2, scope1, scope2, ret);
1086 
1087 	if(!ret)
1088         {
1089             ret = ajStrCmpS(type1, type2);
1090             ajDebug("Sorting1 %S:%S %S:%S %d\n",
1091                     svr1, svr2, type1, type2, ret);
1092         }
1093 
1094 	if(ret)
1095         {
1096             ajStrDel(&scope1);
1097             ajStrDel(&scope2);
1098             ajStrDel(&type1);
1099             ajStrDel(&type2);
1100 
1101             return ret;
1102         }
1103     }
1104 
1105     ajStrDel(&scope1);
1106     ajStrDel(&scope2);
1107     ajStrDel(&type1);
1108     ajStrDel(&type2);
1109 
1110     ret = ajStrCmpS(svr1, svr2);
1111     ajDebug("Sorting2 %S:%S %d\n", svr1, svr2, ret);
1112 
1113     return ret;
1114 }
1115