home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #include "cus.h"
- #include "defines.h"
- #include "lbio.h"
-
- int inlsys(char *lsysfile, char *hostname)
- {
- int rc;
- FILE *fp = NULL;
- char *buf = NULL;
- long len;
- LB *lb = NULL;
- int i;
- char *p;
-
- if ((fp = fopen(lsysfile, "r")) == NULL)
- CU(ERR);
- if (fseek(fp, 0L, SEEK_END) == -1L)
- CU(ERR);
- if ((len = ftell(fp)) == -1L)
- CU(ERR);
- if (fseek(fp, 0L, SEEK_SET) == -1L)
- CU(ERR);
- if ((buf = (char *)malloc(len)) == NULL)
- CU(ERR);
- if ((fread(buf, len, 1, fp) != 1) && ferror(fp))
- CU(ERR);
- if ((lb = lbopen(buf, buf+len-1)) == NULL)
- CU(ERR);
- if (lbseek(lb, 0, LBSEEK_SET) == NULL)
- CU(ERR);
-
- do {
- if ((lb->lb_wLnCur != 0) && (*(lb->lb_cpLnCur) != '#')) {
- for (i=0, p = lb->lb_cpLnCur; i < lb->lb_wLnCur; i++, p++)
- if (*p == SP)
- break;
- if ((*p == SP) && (i == strlen(hostname)))
- if (!(strnicmp(lb->lb_cpLnCur, hostname, i)))
- CU(TRUE);
- }
- } while (lbseek(lb, 1, LBSEEK_CUR));
-
- rc = FALSE;
-
- CUS:
- if (lb) lbfree(lb);
- if (fp) fclose(fp);
- if (buf) free(buf);
- return rc;
- }
-
- int lsysbps(char *cpLsys, char *cpHost)
- {
- int rc;
- FILE *fp = NULL;
- char *buf = NULL;
- long len;
- LB *lb = NULL;
- int i;
- char *cp;
- int wHost;
-
- if ((fp = fopen(cpLsys, "r")) == NULL)
- CU(0);
- if (fseek(fp, 0L, SEEK_END) == -1L)
- CU(0);
- if ((len = ftell(fp)) == -1L)
- CU(0);
- if (fseek(fp, 0L, SEEK_SET) == -1L)
- CU(0);
- if ((buf = (char *)malloc(len)) == NULL)
- CU(0);
- if ((fread(buf, len, 1, fp) != 1) && ferror(fp))
- CU(0);
- if ((lb = lbopen(buf, buf+len-1)) == NULL)
- CU(0);
- if (lbseek(lb, 0, LBSEEK_SET) == NULL)
- CU(0);
-
- wHost = strlen(cpHost);
-
- do {
- if ( (lb->lb_wLnCur <= wHost)
- || (strnicmp(lb->lb_cpLnCur, cpHost, wHost) != 0) )
- continue;
- for (i = 0, cp = lb->lb_cpLnCur; cp != NULL; cp = strpbrk(cp, " \t"), i++) {
- if ( (*cp == ' ') || (*cp == '\t') )
- ++cp;
- if (i >= 3)
- break;
- }
- CU(atoi(cp));
-
- } while (lbseek(lb, 1, LBSEEK_CUR));
-
- rc = 0;
-
- CUS:
- if (lb)
- lbfree(lb);
- if (buf)
- free(buf);
- if (fp)
- fclose(fp);
- return rc;
- }
-
-