sj3lib, sj3stat: KNF

Formatter: knfmt 4.2.0
Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
Masanori Ogino 2023-12-07 12:49:10 +09:00
commit 9d06a2203f
4 changed files with 1136 additions and 1040 deletions

View file

@ -16,18 +16,17 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Software Research
* Associates shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* Except as contained in this notice, the name of Software Research
* Associates shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization from Software Research Associates.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -37,42 +36,45 @@
#include "sj3lib.h"
int
main (int argc, char** argv)
main(int argc, char **argv)
{
SJ3_CLIENT_ENV clnt;
SJ3_WHO_STRUCT who[64];
char ver[256];
char pname[256];
SJ3_CLIENT_ENV clnt;
SJ3_WHO_STRUCT who[64];
char ver[256];
char pname[256];
char *hname;
char *uname;
int i, n;
char *p;
int i, n;
char *p;
if ((argc > 1 && argv[1][0] == '-') || argc > 2) {
fprintf (stderr, "usage: %s [server]\n", argv[0]);
exit (1);
fprintf(stderr, "usage: %s [server]\n", argv[0]);
exit(1);
}
hname = getenv ("SJ3SERV");
uname = getenv ("USER");
hname = getenv("SJ3SERV");
uname = getenv("USER");
if (argc > 1) hname = argv[1];
if (uname == NULL) uname = getlogin();
if (uname == NULL) uname = "unknown";
sprintf (pname, "%d.sj3stat", getpid());
if (argc > 1)
hname = argv[1];
if (uname == NULL)
uname = getlogin();
if (uname == NULL)
uname = "unknown";
sprintf(pname, "%d.sj3stat", getpid());
if (sj3_make_connection(&clnt, hname, uname, pname) == ERROR) {
char *server, *status;
extern int sj3_error_number;
char *server, *status;
extern int sj3_error_number;
server = hname ? hname : "localhost";
switch (sj3_error_number) {
case SJ3_ServerDown: status = "down"; break;
case SJ3_GetHostByName: status = "unknown"; break;
default: status = "dead"; break;
case SJ3_ServerDown: status = "down"; break;
case SJ3_GetHostByName: status = "unknown"; break;
default: status = "dead"; break;
}
fprintf (stderr, "Server '%s' is %s.\n", server, status);
fprintf(stderr, "Server '%s' is %s.\n", server, status);
return 1;
}
@ -80,22 +82,23 @@ main (int argc, char** argv)
n = sj3_who(&clnt, who, sizeof(who)/sizeof(who[0]));
for (p = ver; *p; p++) {
while (*p) putc(*p++, stdout);
fprintf (stdout, "%%, ");
while (*p)
putc(*p++, stdout);
fprintf(stdout, "%%, ");
}
fprintf (stdout, "%d users.\n", n);
fprintf(stdout, "%d users.\n", n);
/*
* Change hostname entry's length.
* Because it's so short.
* Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
*/
fprintf(stdout, "%-16s %-32s %-8s %s\n",
"(USER)", "(HOST)", "(FD)", "(CLIENT)");
fprintf(stdout, "%-16s %-32s %-8s %s\n",
"(USER)", "(HOST)", "(FD)", "(CLIENT)");
for (i = 0; i < n; i++) {
fprintf(stdout, "%-16s %-32s %-8d %s\n", who[i].username,
who[i].hostname, who[i].fd, who[i].progname);
fprintf(stdout, "%-16s %-32s %-8d %s\n", who[i].username,
who[i].hostname, who[i].fd, who[i].progname);
}
(void) sj3_erase_connection(&clnt);
(void)sj3_erase_connection(&clnt);
return 0;
}