home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
f
/
frbts_20.zip
/
MISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-28
|
9KB
|
356 lines
/****************************************************************************/
/* */
/* Misc.c Version 2.0 By Craig Derouen */
/* Misc processsing module for Frobot.c */
/* */
/* */
/****************************************************************************/
#include "frobot.h"
#include <time.h>
#include "globals.h"
static char *dates[] = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
};
void showparms(void)
{
showvers();
if (!ShowActivity)
return;
printf("-------------------------------------------\n");
printf("\tOrigin Node: %d:%d/%d\n",Zone,Net,Node);
printf("\tOutbound directory %s\n",Outbdir);
printf("\tInbound directory %s\n",Inbdir);
printf("\tNetMail directory %s\n",Netmdir);
printf("\tScript control file: %s\n",ScriptFile);
if (LogFile[0])
printf("\tLog File: %s\n",LogFile);
printf("\tActivity displayed: ");
if (ShowActivity)
printf("Yes\n");
else printf("No\n");
printf("\tSend notify mail to host: ");
if (SysopMail)
printf("Yes\n");
else printf("No\n");
printf("\tSend notify mail to yourself: ");
if (SysopMail)
printf("Yes\n");
else printf("No\n");
printf("\tBells and whistles: ");
if (!Silent)
printf("Yes\n");
else printf("No\n");
printf("-------------------------------------------\n");
}
/* Parse out string containing Zone:Net/Node. Return values in ptrs,
return TRUE if error */
int parsenet(char *str,unsigned int *zone,unsigned int *net,unsigned int *node)
{
char *p1;
char tt[20];
/* This gets tricky, a Zone is optional, so.... */
p1 = strchr(str,':'); /* Check for Zone sep */
if (p1 != NULL) {
strcpy(tt,str);
*zone = atoi(strtok(tt,":"));
str = strchr(str,':') +1; /* bump past Zone sep */
}
else {
*zone = 1;
p1 = str;
}
p1 = strtok(str,"/"); /* Net/Node sep */
if (p1 != NULL) {
*net = atoi(p1);
*node = atoi(strtok(NULL," \t\n\r;"));
if (*net + *node)
return(FALSE);
}
return(TRUE);
}
void aborterror(int code,char *str)
{
switch (code) {
case NOMEM:
if (str == NULL)
strcpy(temp,"Out of memory");
else strcpy(temp,str);
case BADFILE:
if (str == NULL)
strcpy(temp,"File error");
else strcpy(temp,str);
}
warble();
strcat(temp,"\n");
printf(temp);
logit(temp,'!');
exit(1);
}
void warble()
{
int x;
for (x=0; x < 3; x++) {
utsound(500,2);
utsound(300,2);
}
}
void utsound(int freq,int time)
{
if (Silent)
return;
soundon(freq);
/* Delay specified time */
utsleep(time);
soundoff();
}
unsigned utsleep(unsigned period)
{
long initclk; /* Initial clock count. */
long nowclk; /* Moving clock count. */
unsigned elpticks; /* Elapsed tick count. */
/* Find out the current clock count and wait until period */
/* counts have passed. */
_disable();
utgetclk(&initclk);
for (elpticks = 0; elpticks < period; elpticks = (unsigned) (nowclk - initclk)) {
utgetclk(&nowclk);
if (nowclk < initclk) /* Must have wrapped past midnight. */
nowclk += 0x1800b0L;
}
_enable();
return(elpticks);
}
/* Construct far void pointer. */
#define uttofaru(seg,off) ((void _far *) \
((((unsigned long) (unsigned int) \
(seg)) << 16L) | \
((unsigned long) (unsigned int) (off))))
/* Address of PC BIOS clock tick count. */
#define UTCLOCKADDR (uttofaru (0x40, 0x6c))
/* Address of PC BIOS clock rollover flag. */
#define UTROLLADDR (uttofaru (0x40, 0x70))
/* Return byte pointed to by pointer. */
#define utpeekb(p) (*((const unsigned char _far *) (p)))
int utgetclk(long *pcount)
{
unsigned char rollover; /* Copy of BIOS's rollover flag. */
_disable();
_fmemcpy((void _far *) pcount,
(char _far *) UTCLOCKADDR,
sizeof (*pcount));
rollover = utpeekb (UTROLLADDR);
_enable();
return (rollover != 0);
}
void soundon(int freq)
{
_asm {
mov cx,freq ; get frequency
mov dx,12 ; upper part of numerator
mov ax,343eh ; lower part of numerator
div cx ; Divide specified frequency into
; 1,193,182 hz clock freq used by timer
mov cx,ax ; result in ax
mov al,cl ; lower byte out to timer
out 42h,al
mov al,ch ; high byte out to timer
out 42h,al
in al,61h ; get contents of system port b
or al,3 ; turn speaker and timer on
out 61h,al ; send out new values to port b
}
}
void soundoff(void)
{
_asm {
in al,61h ; get contents of system port b
and al,11111100b ; turn speaker and timer off
out 61h,al ; send out new values to port b
}
}
void strinsert(char *insstr,char *dest,int position)
{
int i;
int len;
len = strlen(insstr);
for(i = strlen(dest); i >= position; i--) /* Shift the text */
*(dest + len + i) = *(dest + i);
for(i = 0; i < len; i++) /* Now do an insert */
*(dest + position + i) = *(insstr + i);
}
/* Trim leading and trailing blanks on string */
void blanktrim(char *string)
{
int i;
char *p1,*p2;
for(i = strlen(string) - 1; ('!' > string[i]) && i >= 0; i--)
;
string[i+1] = '\x0';
if (*string) {
p1 = p2 = string;
while('!' > *p1)
p1++;
while(*p1 != '\x0')
*p2++ = *p1++;
*p2 = '\x0';
}
}
/* Compare passed date string (dd/mm/yy) with today's date
Return 0 if today, 1 if newer, -1 if older and -2 if bad date */
int datecheck(char *inpstr)
{
time_t curtime;
struct tm *ltime;
char timestr[38];
char *p,*dp;
int x,month,day,year;
int tmonth,tday,tyear;
time(&curtime);
ltime = localtime(&curtime);
p = asctime(ltime);
dp = strtok(p," "); /* Fetch day string */
if (strchr(inpstr,'/') == NULL) { /* Special dates */
if (strcmpi(inpstr,"NOW") == 0) /* Special token for today */
return(0);
strcpy(timestr,inpstr);
timestr[3] = 0; /* Use only the first 3 chars of day */
/* Now check and see if its today */
if (strcmpi(dp,timestr) == 0) /* We allow macros of Sun,Mon,etc. */
return(0);
return(-2); /* Invalid date then */
}
p = ctime(&curtime);
strcpy(timestr,p);
if (*timestr) { /* Valid time returned from computer */
/* construct a date str exactly formatted like inpstr */
p = strtok(timestr," "); /* Day */
p = strtok(NULL," "); /* Month */
for (month=0; strcmpi(p,dates[month]) != 0 && x < 12; month++)
;
month++; /* Months start at 1 */
p = strtok(NULL," "); /* day numeric string */
day = atoi(p);
p = strtok(NULL," "); /* Time string */
p = strtok(NULL," \n"); /* year string */
year = atoi(p) - 1900;
/* Okay now start the compares */
sscanf(inpstr,"%02d/%02d/%02d",&tmonth,&tday,&tyear);
if (tyear == 0 || tday == 0 || tmonth == 0)
return(-2);
if (tyear > year)
return(1);
if (tyear < year)
return(-1);
if (tmonth > month)
return(1);
if (tmonth < month)
return(-1);
if (tday > day)
return(1);
if (tday < day)
return(-1);
return(0); /* Its today! */
}
else return(-2);
}
/* Compare passed time string (hh:mm) with current time (in 24hour format)
Return 0 if now, 1 if newer, -1 if older and -2 if bad time */
int timecheck(char *inpstr)
{
time_t curtime;
char timestr[38];
char *p;
int hour,min;
int thour,tmin;
if (strcmpi(inpstr,"NOW") == 0) /* Special token for today */
return(0);
if (strlen(inpstr) != 5) /* Quick checking */
return(-2);
time(&curtime);
p = ctime(&curtime);
strcpy(timestr,p);
if (*timestr) { /* Valid time returned from computer */
/* construct a time str exactly formatted like inpstr */
p = strtok(timestr," "); /* Day */
p = strtok(NULL," "); /* Month */
p = strtok(NULL," "); /* day numeric string */
p = strtok(NULL," "); /* Time string */
/* Okay now start the compares */
sscanf(p,"%02d:%02d",&hour,&min);
sscanf(inpstr,"%02d:%02d",&thour,&tmin);
if (thour < hour)
return(-1);
if (thour > hour)
return(1);
/* Hour is the same */
if (tmin < min)
return(-1);
if (tmin > min)
return(1);
return(0); /* Its now! */
}
else return(-2);
}