Codecleanup for nodelist

This commit is contained in:
Michiel Broek 2004-07-10 11:46:35 +00:00
parent d7a6aeb162
commit 19ad88a5db
3 changed files with 135 additions and 139 deletions

View File

@ -139,12 +139,11 @@ struct icmp_filter {
* *
* Defines * Defines
*/ */
#define PRODCODE 0x11ff /* Official MBSE FTSC product code */
#define Max_passlen 14 /* Define maximum passwd length */
#define SS_BUFSIZE 1024 /* Socket buffersize */
#define MAXNLLINELEN 1024 /* Maximum nodelist line length */
#define PRODCODE 0x11ff /* Official MBSE FTSC product code */
#define Max_passlen 14 /* Define maximum passwd length */
#define SS_BUFSIZE 1024 /* Socket buffersize */
/* /*

View File

@ -7,7 +7,6 @@
#define MAXNAME 35 #define MAXNAME 35
#define MAXUFLAGS 16 #define MAXUFLAGS 16
#define MAXNLLINELEN 1024
/* /*

View File

@ -35,8 +35,8 @@
typedef struct _nl_list { typedef struct _nl_list {
struct _nl_list *next; struct _nl_list *next;
struct _nlidx idx; struct _nlidx idx;
} nl_list; } nl_list;
@ -62,18 +62,18 @@ time_t t_end; /* End time */
*/ */
void Help(void) void Help(void)
{ {
do_quiet = FALSE; do_quiet = FALSE;
ProgName(); ProgName();
colour(11, 0); colour(LIGHTCYAN, BLACK);
printf("\nUsage: mbindex <options>\n\n"); printf("\nUsage: mbindex <options>\n\n");
colour(9, 0); colour(LIGHTBLUE, BLACK);
printf(" Options are:\n\n"); printf(" Options are:\n\n");
colour(3, 0); colour(CYAN, BLACK);
printf(" -quiet Quiet mode\n"); printf(" -quiet Quiet mode\n");
colour(7, 0); colour(LIGHTGRAY, BLACK);
printf("\n"); printf("\n");
die(MBERR_COMMANDLINE); die(MBERR_COMMANDLINE);
} }
@ -83,14 +83,14 @@ void Help(void)
*/ */
void ProgName(void) void ProgName(void)
{ {
if (do_quiet) if (do_quiet)
return; return;
colour(15, 0); colour(WHITE, BLACK);
printf("\nMBINDEX: MBSE BBS %s Nodelist Index Compiler\n", VERSION); printf("\nMBINDEX: MBSE BBS %s Nodelist Index Compiler\n", VERSION);
colour(14, 0); colour(YELLOW, BLACK);
printf(" %s\n", COPYRIGHT); printf(" %s\n", COPYRIGHT);
colour(3, 0); colour(CYAN, BLACK);
} }
@ -103,7 +103,7 @@ void die(int onsig)
ulockprogram((char *)"mbindex"); ulockprogram((char *)"mbindex");
if (!do_quiet) { if (!do_quiet) {
colour(3, 0); colour(CYAN, BLACK);
show_log = TRUE; show_log = TRUE;
} }
@ -121,7 +121,7 @@ void die(int onsig)
Syslog(' ', "MBINDEX finished in %s", t_elapsed(t_start, t_end)); Syslog(' ', "MBINDEX finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) if (!do_quiet)
colour(7, 0); colour(LIGHTGRAY, BLACK);
ExitClient(onsig); ExitClient(onsig);
} }
@ -197,167 +197,165 @@ int main(int argc,char *argv[])
void tidy_nllist(nl_list **fap) void tidy_nllist(nl_list **fap)
{ {
nl_list *tmp, *old; nl_list *tmp, *old;
for (tmp = *fap; tmp; tmp = old) { for (tmp = *fap; tmp; tmp = old) {
old = tmp->next; old = tmp->next;
free(tmp); free(tmp);
} }
*fap = NULL; *fap = NULL;
} }
int in_nllist(struct _nlidx idx, nl_list **fap, int replace) int in_nllist(struct _nlidx idx, nl_list **fap, int replace)
{ {
nl_list *tmp; nl_list *tmp;
for (tmp = *fap; tmp; tmp = tmp->next) for (tmp = *fap; tmp; tmp = tmp->next) {
if ((tmp->idx.zone == idx.zone) && (tmp->idx.net == idx.net) && if ((tmp->idx.zone == idx.zone) && (tmp->idx.net == idx.net) &&
(tmp->idx.node == idx.node) && (tmp->idx.point == idx.point)) { (tmp->idx.node == idx.node) && (tmp->idx.point == idx.point)) {
if (replace) { if (replace) {
tmp->idx = idx; tmp->idx = idx;
entries++; entries++;
} }
regio = tmp->idx.region; regio = tmp->idx.region;
return TRUE; return TRUE;
} }
return FALSE; }
return FALSE;
} }
void fill_nllist(struct _nlidx idx, nl_list **fap) void fill_nllist(struct _nlidx idx, nl_list **fap)
{ {
nl_list *tmp; nl_list *tmp;
tmp = (nl_list *)malloc(sizeof(nl_list)); tmp = (nl_list *)malloc(sizeof(nl_list));
tmp->next = *fap; tmp->next = *fap;
tmp->idx = idx; tmp->idx = idx;
*fap = tmp; *fap = tmp;
total++; total++;
entries++; entries++;
} }
char *fullpath(char *fname) char *fullpath(char *fname)
{ {
static char path[PATH_MAX]; static char path[PATH_MAX];
sprintf(path, "%s/%s", CFG.nodelists, fname); sprintf(path, "%s/%s", CFG.nodelists, fname);
return path; return path;
} }
void sort_nllist(nl_list **fap) void sort_nllist(nl_list **fap)
{ {
nl_list *ta, **vector; nl_list *ta, **vector;
size_t n = 0, i; size_t n = 0, i;
if (*fap == NULL) if (*fap == NULL)
return;
for (ta = *fap; ta; ta = ta->next)
n++;
vector = (nl_list **)malloc(n * sizeof(nl_list *));
i = 0;
for (ta = *fap; ta; ta = ta->next) {
vector[i++] = ta;
}
qsort(vector, n, sizeof(nl_list *),
(int(*)(const void*, const void *))comp_node);
(*fap) = vector[0];
i = 1;
for (ta = *fap; ta; ta = ta->next) {
if (i < n)
ta->next = vector[i++];
else
ta->next = NULL;
}
free(vector);
return; return;
for (ta = *fap; ta; ta = ta->next)
n++;
vector = (nl_list **)malloc(n * sizeof(nl_list *));
i = 0;
for (ta = *fap; ta; ta = ta->next) {
vector[i++] = ta;
}
qsort(vector, n, sizeof(nl_list *), (int(*)(const void*, const void *))comp_node);
(*fap) = vector[0];
i = 1;
for (ta = *fap; ta; ta = ta->next) {
if (i < n)
ta->next = vector[i++];
else
ta->next = NULL;
}
free(vector);
return;
} }
int comp_node(nl_list **fap1, nl_list **fap2) int comp_node(nl_list **fap1, nl_list **fap2)
{ {
if ((*fap1)->idx.zone != (*fap2)->idx.zone) if ((*fap1)->idx.zone != (*fap2)->idx.zone)
return ((*fap1)->idx.zone - (*fap2)->idx.zone); return ((*fap1)->idx.zone - (*fap2)->idx.zone);
else if ((*fap1)->idx.net != (*fap2)->idx.net) else if ((*fap1)->idx.net != (*fap2)->idx.net)
return ((*fap1)->idx.net - (*fap2)->idx.net); return ((*fap1)->idx.net - (*fap2)->idx.net);
else if ((*fap1)->idx.node != (*fap2)->idx.node) else if ((*fap1)->idx.node != (*fap2)->idx.node)
return ((*fap1)->idx.node - (*fap2)->idx.node); return ((*fap1)->idx.node - (*fap2)->idx.node);
else else
return ((*fap1)->idx.point - (*fap2)->idx.point); return ((*fap1)->idx.point - (*fap2)->idx.point);
} }
int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short no) int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short no)
{ {
int num, i, rc = 0; int num, i, rc = 0, lineno, boss = FALSE, bossvalid = FALSE;
int lineno, boss = FALSE, bossvalid = FALSE; unsigned short upnet, upnode;
unsigned short upnet, upnode; char buf[MAXNLLINELEN], *p, *q;
char buf[256], *p, *q; faddr *tmpa;
faddr *tmpa; FILE *nl;
FILE *nl; struct _nlidx ndx;
struct _nlidx ndx; struct _nlusr udx;
struct _nlusr udx;
rc = 0; rc = 0;
if ((nl = fopen(fullpath(nlname), "r")) == NULL) { if ((nl = fopen(fullpath(nlname), "r")) == NULL) {
WriteError("$Can't open %s", fullpath(nlname)); WriteError("$Can't open %s", fullpath(nlname));
return 102; return 102;
} }
Syslog('+', "Compiling \"%s\" (%d)", nlname, filenr); Syslog('+', "Compiling \"%s\" (%d)", nlname, filenr);
IsDoing("Compile NL %d", filenr +1); IsDoing("Compile NL %d", filenr +1);
memset(&ndx, 0, sizeof(ndx)); memset(&ndx, 0, sizeof(ndx));
ndx.type = NL_NODE; ndx.type = NL_NODE;
ndx.fileno = filenr; ndx.fileno = filenr;
upnet = 0; upnet = 0;
upnode = 0; upnode = 0;
/*
* If zone is set, it is a overlay segment
*/
if (zo) {
ndx.zone = zo;
ndx.net = ne;
ndx.node = no;
ndx.point = 0;
}
entries = 0;
lineno = 0;
while (!feof(nl)) {
Nopper();
ndx.offset = ftell(nl);
lineno++;
if (fgets(buf, sizeof(buf)-1, nl) == NULL)
continue;
/* /*
* If zone is set, it is a overlay segment * Next check at <lf> and <eof> characters
*/ */
if (zo) { if ((*(buf+strlen(buf) -1) != '\n') && (*(buf + strlen(buf) -1) != '\012')) {
ndx.zone = zo; while (fgets(buf, sizeof(buf) -1, nl) && (*(buf + strlen(buf) -1) != '\n')) /*void*/;
ndx.net = ne; if (strlen(buf) > 1) /* Suppress EOF character */
ndx.node = no; Syslog('-', "Nodelist: too long line junked (%d)", lineno);
ndx.point = 0; continue;
} }
entries = 0;
lineno = 0;
while (!feof(nl)) {
Nopper();
ndx.offset = ftell(nl);
lineno++;
if (fgets(buf, sizeof(buf)-1, nl) == NULL)
continue;
/*
* Next check at <lf> and <eof> characters
*/
if ((*(buf+strlen(buf) -1) != '\n') && (*(buf + strlen(buf) -1) != '\012')) {
while (fgets(buf, sizeof(buf) -1, nl) &&
(*(buf + strlen(buf) -1) != '\n')) /*void*/;
if (strlen(buf) > 1) /* Suppress EOF character */
Syslog('-', "Nodelist: too long line junked (%d)", lineno);
continue;
}
if (*(p=buf+strlen(buf) -1) == '\n') if (*(p=buf+strlen(buf) -1) == '\n')
*p-- = '\0'; *p-- = '\0';