home *** CD-ROM | disk | FTP | other *** search
- /*=========================================================================
- Star6.c -- This module contains routines to initialize and send out a
- requester for getting names from the user. It is used for prompt for
- star and constellation names for searching. The name is converted to
- all upper case before it is returned.
-
- 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"
-
-
- #define OKBUTTON 1
- #define CANCELBUTTON 2
- #define NAMESTRGAD 3
-
- /*=========================================
- External declarations
- ==========================================*/
-
- extern struct Window *w;
- extern struct NewWindow nw;
- extern struct IntuiMessage *GetMsg();
-
- /*=========================================
- Border around the GetName requestor
- ==========================================*/
-
- SHORT req_pairs[] = {
- 0, 0,
- 257, 0,
- 257, 60,
- 0, 60,
- 0, 0
- };
-
- struct Border req_bord = {
- -1, -1,
- 7, 3, JAM2,
- 5,
- (SHORT *)&req_pairs,
- NULL
- };
-
-
- /*=========================================
- Gadgets, Borders, Etc to the getname
- requestor
- ==========================================*/
-
- SHORT Pairs_1[] = {
- 0, 0,
- 65, 0,
- 65, 10,
- 0, 10,
- 0, 0
- };
-
- struct Border bord_1 = {
- -1, -1,
- 7, 1, JAM2,
- 5,
- (SHORT *)&Pairs_1,
- NULL
- };
-
- struct IntuiText OKtext = {2,2,JAM1, 24, 1, NULL,
- (UBYTE *) "OK", NULL};
-
- struct Gadget OK_Gad = {
- NULL, 124, 39, 63, 10,
- GADGHCOMP,
- GADGIMMEDIATE | ENDGADGET | RELVERIFY,
- BOOLGADGET | REQGADGET,
- (APTR)&bord_1, (APTR)&bord_1,
- &OKtext, NULL,
- NULL, OKBUTTON, NULL
- };
-
- SHORT Pairs_2[] = {
- 0, 0,
- 63, 0,
- 63, 10,
- 0, 10,
- 0, 0
- };
- struct Border bord_2 = {
- -1, -1,
- 7, 1, JAM2,
- 5,
- (SHORT *)&Pairs_2,
- NULL
- };
-
- struct IntuiText CANCELtext = {2,2,JAM1, 9, 1, NULL,
- (UBYTE *) "CANCEL", NULL};
-
- struct Gadget Cancel_Gad = {
- &OK_Gad, 37, 39, 63, 10,
- GADGHCOMP,
- GADGIMMEDIATE | ENDGADGET | RELVERIFY,
- BOOLGADGET | REQGADGET,
- (APTR)&bord_2, (APTR)&bord_2,
- &CANCELtext, NULL,
- NULL, CANCELBUTTON, NULL,
- };
-
- SHORT Pairs_3[] = {
- 0, 0,
- 152, 0,
- 152, 10,
- 0, 10,
- 0, 0
- };
- struct Border bord_3 = {
- -1, -1,
- 1, 3, JAM2,
- 5,
- (SHORT *)&Pairs_3,
- NULL
- };
-
- UBYTE Name_String[60] = '\0';
-
- struct StringInfo NameStringInfo = {
- Name_String, NULL,
- 0, 60, 0,
- 0, 0,
- 0, 0, 0,
- 0, 0,
- 0
- };
-
- struct IntuiText req_name = {2,2, JAM1, 10, 10, NULL, NULL, NULL};
- struct IntuiText req_name1 = {2,2, JAM1, 10, 3, NULL, NULL, NULL};
- struct IntuiText req_name2 = {2,2, JAM1, 10, 11, NULL, NULL, &req_name1};
-
- struct Gadget NameStringGad = {
- &Cancel_Gad, 36, 21, 152, 10,
- GADGHCOMP,
- RELVERIFY | ENDGADGET,
- STRGADGET | REQGADGET,
- (APTR)&bord_3, (APTR)&bord_3,
- NULL,
- NULL,
- (APTR)&NameStringInfo, NAMESTRGAD, NULL
- };
-
- struct Requester name_req;
-
- /*======================================================================
- InitReq(req, gad, bord) - Initializes a requestor, req is a pointer to a
- previously allocated requestor. Later on, perhaps we can Allocate
- one and return a pointer to it, However, because cleaning up
- is tricky, I'm taking the easy way out
- =======================================================================*/
- initnamereq()
- {
- InitRequester(&name_req); /* Init the requestor */
- name_req.LeftEdge = 169;
- name_req.TopEdge = 44;
- name_req.Width = 257;
- name_req.Height = 60;
- name_req.ReqGadget = &NameStringGad; /* First Gadget */
- name_req.ReqText = NULL; /* First Intuitext */
- name_req.BackFill = 1; /* Backgnd color */
- name_req.Flags = 0; /* Must have at least one */
- name_req.ReqBorder = &req_bord; /* Outside border */
-
- }
-
- /* the getname routine */
- UBYTE *get_Star_Name(str1,str2)
- UBYTE *str1,*str2; /* Message strings "SAVE FILENAME AS:" */
- {
- int looping=TRUE;
- struct IntuiMessage *mes;
- struct StringInfo *si = NULL;
- struct Gadget *gad;
- ULONG class;
- ULONG iflags;
- UBYTE *c;
-
-
- /*-------- Initialize the requester structure---------*/
- initnamereq();
-
- /*-------- Set up the IntuiText for the requester -------*/
- if (str2 == NULL) {
- req_name.IText = str1;
- name_req.ReqText = &req_name;
- }
- else {
- req_name1.IText = str1;
- req_name2.IText = str2;
- name_req.ReqText = &req_name2;
- }
-
-
- iflags = nw.IDCMPFlags; /* Current flag settings */
-
- /*-------- Open up the requester $$$---------*/
- if ((Request(&name_req, w)) == 1L) {
- iflags |= REQSET;
- ModifyIDCMP(w, iflags);
- while (looping) {
- if ((mes = (struct IntuiMessage *)GetMsg(w->UserPort)) == NULL) {
- Wait(1L<<w->UserPort->mp_SigBit);
- continue;
- }
- class = mes->Class;
- gad = (struct Gadget *)mes->IAddress;
- ReplyMsg(mes);
-
- /*-------- Handle the case where requester clears --------*/
- if (class == GADGETDOWN && gad->GadgetID == CANCELBUTTON) {
- return(NULL);
- }
- if (class == REQSET) {
- ActivateGadget(&NameStringGad, w, &name_req);
- NameStringInfo.BufferPos = NameStringInfo.MaxChars;
- RefreshGadgets(&NameStringGad, w, &name_req);
- }
-
- if (class == GADGETDOWN && gad->GadgetID == OKBUTTON) {
- for(c=Name_String; *c; c++) *c = toupper(*c);
- return(Name_String);
- }
-
- if (class == GADGETUP && gad == &NameStringGad) {
- ModifyIDCMP(w, nw.IDCMPFlags);
- for(c=Name_String; *c; c++) *c = toupper(*c);
- return(Name_String);
- }
-
- if (class == REQCLEAR) {
- looping = FALSE;
- }
-
- } /* while */
- } /* if request */
- }
-
-
- /* get_number_req - This is a shell around the above requester to get a
- point number.
- */
- FLOAT get_num_req(str,oldnum,lowrange,highrange)
- UBYTE *str;
- FLOAT oldnum, lowrange,highrange;
- {
- BOOL OKNUM;
- FLOAT convertnum = 0.0;
- UBYTE *c;
-
- sprintf(Name_String,"%5.2f",oldnum);
- do
- { OKNUM = TRUE;
- c = get_Star_Name(str);
- for (; *c;c++)
- {if ((isdigit(*c)) || (*c == '.') || (isspace(*c))) /*do nothing*/ ;
- else OKNUM = FALSE;
- }
- if (OKNUM)
- { convertnum = atof(c);
- if ((convertnum < lowrange) || (convertnum > highrange))
- OKNUM = FALSE;
- }
- } while(OKNUM == FALSE);
-
- return(convertnum);
- }
-
-