home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
17 Bit Software 1: Collection A
/
17Bit_Collection_A.iso
/
files
/
223.dms
/
223.adf
/
Source
/
star5.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-25
|
8KB
|
256 lines
/*=========================================================================
Star5.c -- This module handles star and constellation selection. It is
invoked when the user clicks the right or left mouse button on a star.
It also includes the search algorithms and search table initialization
for searching by star and constellation name.
Credits for Star Chart:
Robert L. Hill of the Orange County, CA. Amiga Friends User Group
wrote the original version of StarChart in AmigaBasic
The star data and many of the main functions of this
version are derived from that program.
Ray R. Larson wrote the c version 1.0 of StarChart, 'intuitionizing'
and enhancing the speed and functions of the original.
Copyright (c) 1986 by Ray R. Larson
This program may be freely distributed and copied, but may not be sold
without the permission of the author. If you modify or enhance it,
please include the above credits (and please send me a copy!).
Ray R. Larson
6425 Central Ave. #304
El Cerrito, CA 94530
BitNet LARSON@UCBCMSA
=========================================================================*/
/*------------Header file for all of the standard stuff----*/
/*-------------plus definitions of global structures-------*/
#include "star.h"
/*------------------ Global search tables ---------*/
extern SHORT StarIndex[];
extern SHORT *ConstList[];
extern SHORT *GreekList[];
/*------------------ extern vars ------------------*/
extern struct star_rec StarTable[];
extern char *Greek[];
extern struct cons_rec Constel[];
extern struct Coord coords[];
extern struct RastPort *rp;
extern struct Window *w;
extern struct Screen *scr; /* pointer to the custom screen - RRL */
extern UBYTE WTMessage[];
extern UBYTE WinTitle[];
extern SHORT DisplayFlags, ConDispFlags; /* type of info display */
/**************************************************************************
* Handle mouse button clicks in the star display area
**************************************************************************/
Do_buttons(code,mousex,mousey)
USHORT code;
SHORT mousex, mousey;
{
SHORT stars, constindex, *starlist, hitlist[15], scancoords();
if(ONCHART((LONG)mousex,(LONG)mousey) == 0) return; /* mouse not in star area */
switch(code) {
case SELECTUP:
stars = scancoords((LONG)mousex,(LONG)mousey,hitlist,15);
if (stars) DisplayInfo(hitlist,stars,0,DisplayFlags);
break;
case MENUUP:
stars = scancoords((LONG)mousex,(LONG)mousey,hitlist,1);
if (stars)
{ constindex = StarTable[hitlist[0]].ConsNum;
sprintf(WTMessage,
"The Constellation of %s - The %s",
Constel[constindex].ConsName,
Constel[constindex].ConsMean);
SetWindowTitles(w,WTMessage,(UBYTE *)-1);
PlotConst(ConstList[constindex],1,ConDispFlags);
Delay(200L);
PlotConst(ConstList[constindex],0,ConDispFlags);
SetWindowTitles(w,WinTitle,(UBYTE *)-1);
}
break;
} /* end code switch */
}
/**************************************************************************
* SearchIndex - This function performs a binary search on the StarIndex
* table to locate a named star record. If successful, it returns a
* pointer to a star_rec structure for the matching star, if the star
* is not in the table, it returns NULL.
**************************************************************************/
SHORT SearchIndex(key)
char *key;
{
SHORT mid, low, high, compval;
BOOL found = FALSE;
low = 1;
high = NumStars; /* in star.h */
while (low <= high)
{ mid = (low + high)/2;
compval = strcmp(key,StarTable[StarIndex[mid]].StarName);
if (compval == 0) return(StarIndex[mid]);
else
{ if (compval < 0) high = mid-1;
else low = mid + 1;
}
}
/* if we get to here nothing was found */
return(0);
}
/**********************************************************************
* scancoords() - this function performs a simple sequential search of
* the coords array of coordinates for stars, it finds
* up to MaxCount objects located within +-2 pixels of
* the supplied findx and findy position on the starchart
* the indexes of the matching coords elements are added
* to the List array, and the total number found is returned
* as the result of the function.
*********************************************************************/
SHORT scancoords(findx,findy,list,maxcount)
LONG findx, findy;
SHORT list[], maxcount;
{
LONG xmax,xmin,ymax,ymin;
SHORT i, hitcount = 0;
xmax = findx + 3;
xmin = findx - 3;
ymax = findy + 3;
ymin = findy - 3;
for(i=1;(i <= NumStars) && (maxcount); i++)
{
if (INRANGE(coords[i].x,xmin,xmax))
{
if(INRANGE(coords[i].y,ymin,ymax))
{
list[hitcount] = i;
hitcount++;
maxcount--;
}
}
}
return(hitcount);
}
/**************************************************************************
* SearchConst - This function performs a binary search on the Constell
* table to locate a named constellation record. If successful, it returns
* the index of the found record. If the constellation name is not in the
* table, it returns NULL. It only performs partial matching of the names
**************************************************************************/
SHORT SearchConst(key)
char *key;
{
SHORT mid, low, high;
SHORT compval, complen;
low = 1;
high = NumCons; /* in star.h */
complen = strlen(key) - 2;
if (complen < 3) complen = strlen(key);
while (low <= high)
{ mid = (low + high)/2;
compval = strncmp(key,Constel[mid].ConsName,complen);
if (compval == 0) return(mid);
else
{ if (compval < 0) high = mid-1;
else low = mid + 1;
}
}
/* if we get to here nothing was found */
return(0);
}
/**************************************************************************
* SearchGreek - This function performs a sequential search on the Greek
* table to locate a named Greek letter record. If successful, it returns
* the index of the found record. If the key is not in the table,
* it returns NULL.
**************************************************************************/
SHORT SearchGreek(key)
char *key;
{
SHORT compval, i;
for (i = 1; i <= NumGreek; i++)
{
compval = strncmp(key,Greek[i],strlen(key));
if (compval == 0) return(i);
}
/* if we get to here nothing was found */
return(0);
}
/* the following routine extracts the first word */
firststr(str,first,rest)
char *str, *first, *rest;
{
char *blank;
extern char *index();
/* extract first word from input key */
while (isspace(*str)) str++;
strcpy(first,str); /* first non-blank chars */
blank = index(first,' ');
if (blank == NULL)
{ *rest = '\0';
return;
}
*blank = '\0';
blank++;
while(isspace(*blank)) blank++;
strcpy(rest, blank);
return;
}
/**********************************************************************
* AndLists - perform Boolean set intersection on two arrays of numbers
* this function returns the single number that the sets have in common
* (that is, it is pretty simple version of set intersection, could have
* it fill in another list with all the common members, but for this
* application that should not be needed.) Note that the first ([0])
* element in each list holds the number of array members in the rest
* of the list, and that each list is in ascending order of the values
* of the elements.
**********************************************************************/
SHORT AndLists(L1,L2)
SHORT L1[],L2[];
{
SHORT i, j, count1, count2;
count1 = L1[0];
count2 = L2[0];
i = j = 1;
while ((i <= count1) && (j <= count2))
{
if (L1[i] == L2[j]) return(L1[i]);
if (L1[i] < L2[j]) i++;
if (L1[i] > L2[j]) j++;
}
/* if we get to here there were no common elements */
return(0);
}