home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
b
/
bmh02src.zip
/
MISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-16
|
3KB
|
154 lines
/*
misc.c : Copyright Paul Healy, EI9GL, 1992.
Derived from bm.
Copyright 1986 Bdale Garbee, All Rights Reserved.
Permission granted for non-commercial copying and use, provided
this notice is retained.
Copyright 1987 1988 Dave Trulli NN2Z, All Rights Reserved.
Permission granted for non-commercial copying and use, provided
this notice is retained.
920603 : Created.
920802 : Cleaned up parse a little.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <io.h>
#include "misc.h"
#include "rc.h"
/*
* parse a line into argv array. Return argc, -1 on error.
*/
int
parse(char *line, char *argv[], int maxargs)
{
int argc = 0;
while ( argc < maxargs ) {
int qflag = 0;
while (isspace(*line) || (*line == ',') ) /* Skip leading white space */
line++;
if(*line == '\0')
break;
if(*line == '"') { /* Check for quoted token */
line++; /* Suppress quote */
qflag = 1;
}
argv[argc++] = line; /* Beginning of token */
/*
* Find terminating delimiter
*/
if (qflag) {
if ( (line = strchr(line, '"')) == NULL )
return -1;
*line++ = '\0';
}
else {
char *cp;
/* Find space or tab. If not present,
* then we've already found the last
* token.
* 920802 : note that bm would wrongly leave trailing tab chars
* after a token
*/
if( (cp = strpbrk(line, " \t,\n")) == NULL)
break;
*cp++ = '\0';
line = cp;
}
}
if (argc == maxargs)
return -1;
argv[argc] = NULL;
return argc;
}
/*
* replace terminating end of line marker with null
*/
char *
rip(char *s)
{
char *p = s;
for (; *s; s++)
if (*s == '\n') {
*s = '\0';
break;
}
return p;
}
int
wanted(int msg, int argc, char *argv[], int default_msg)
{
int i, m;
char *p;
if (argc == 1)
return msg == default_msg;
for (i=1; i<argc; i++)
if (isdigit(argv[i][0])) {
if ((m=atoi(argv[i])) == msg)
return 1;
if ( (p=strchr(argv[i], '-')) != NULL)
if ( (msg>=m) && (msg<=atoi(p+1)) )
return 1;
}
return 0;
}
int
setupbm(void)
{
static int done = 0;
if (done) /* don't keep loading config in bmh */
return 0;
else
done = 1;
if (loadconfig()==-1)
return -1;
if (/* isatty(fileno(stdout)) && */ (setvbuf(stdout, NULL, _IOFBF, 2048) != 0)) {
fprintf(stderr,"bm: can't buffer stdout\n");
return -1;
}
return 0;
}
#ifndef DEBUG
/*
* null checking taken from ka9q NOS
*/
static int oldNull;
void
null_init(void)
{
oldNull = *(unsigned short *)NULL;
}
void
null_check(char *s)
{
if(*(unsigned short *)NULL != oldNull)
fprintf(stderr, "null: location smashed at %s\n", s);
}
#endif