home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 223.dms / 223.adf / Source / star6.c < prev    next >
C/C++ Source or Header  |  1988-07-25  |  7KB  |  294 lines

  1. /*=========================================================================
  2.   Star6.c -- This module contains routines to initialize and send out a
  3.   requester for getting names from the user. It is used for prompt for
  4.   star and constellation names for searching. The name is converted to
  5.   all upper case before it is returned.
  6.  
  7.   Credits for Star Chart:
  8.        Robert L. Hill of the Orange County, CA. Amiga Friends User Group
  9.                       wrote the original version of StarChart in AmigaBasic
  10.                       The star data and many of the main functions of this
  11.                       version are derived from that program.
  12.  
  13.        Ray R. Larson  wrote the c version 1.0 of StarChart, 'intuitionizing'
  14.                       and enhancing the speed and functions of the original.
  15.  
  16.   Copyright (c) 1986 by Ray R. Larson
  17.   
  18.   This program may be freely distributed and copied, but may not be sold
  19.   without the permission of the author. If you modify or enhance it, 
  20.   please include the above credits (and please send me a copy!).
  21.  
  22. Ray R. Larson
  23. 6425 Central Ave. #304
  24. El Cerrito, CA 94530
  25.  
  26. BitNet  LARSON@UCBCMSA
  27. =========================================================================*/
  28. /*------------Header file for all of the standard stuff----*/ 
  29. /*-------------plus definitions of global structures-------*/
  30. #include "star.h" 
  31.  
  32.  
  33. #define OKBUTTON    1
  34. #define CANCELBUTTON   2
  35. #define NAMESTRGAD   3
  36.  
  37. /*=========================================
  38.   External declarations
  39. ==========================================*/
  40.  
  41. extern struct Window *w;
  42. extern struct NewWindow nw;
  43. extern struct IntuiMessage *GetMsg();
  44.  
  45. /*=========================================
  46.   Border around the GetName requestor
  47. ==========================================*/
  48.  
  49. SHORT req_pairs[] = {
  50.   0,     0,
  51.   257,   0,
  52.   257,  60,
  53.   0,    60,
  54.   0,     0
  55. };
  56.  
  57. struct Border req_bord = {
  58.   -1,  -1,
  59.   7,  3,  JAM2,
  60.   5,
  61.   (SHORT *)&req_pairs,
  62.   NULL
  63. };
  64.  
  65.  
  66. /*=========================================
  67.   Gadgets, Borders, Etc to the getname
  68.   requestor
  69. ==========================================*/
  70.  
  71. SHORT Pairs_1[] = {
  72.   0,     0,
  73.   65,    0,
  74.   65,   10,
  75.   0,    10,
  76.   0,     0
  77. };
  78.  
  79. struct Border bord_1 = {
  80.   -1,  -1,
  81.   7,  1,  JAM2,
  82.   5,
  83.   (SHORT *)&Pairs_1,
  84.   NULL
  85. };
  86.  
  87. struct IntuiText OKtext = {2,2,JAM1, 24, 1, NULL,
  88.   (UBYTE *) "OK", NULL};
  89.  
  90. struct Gadget OK_Gad = {
  91.   NULL, 124, 39, 63, 10,
  92.   GADGHCOMP,
  93.   GADGIMMEDIATE | ENDGADGET | RELVERIFY,
  94.   BOOLGADGET | REQGADGET,
  95.   (APTR)&bord_1,  (APTR)&bord_1,
  96.   &OKtext, NULL,
  97.   NULL,   OKBUTTON, NULL
  98. };
  99.  
  100. SHORT Pairs_2[] = {
  101.   0,     0,
  102.   63,     0,
  103.   63,     10,
  104.   0,     10,
  105.   0,     0
  106. };
  107. struct Border bord_2 = {
  108.   -1,  -1,
  109.   7,  1,  JAM2,
  110.   5,
  111.   (SHORT *)&Pairs_2,
  112.   NULL
  113. };
  114.  
  115. struct IntuiText CANCELtext = {2,2,JAM1, 9, 1, NULL,
  116.   (UBYTE *) "CANCEL", NULL};
  117.  
  118. struct Gadget Cancel_Gad = {
  119.  &OK_Gad, 37, 39, 63, 10,
  120.  GADGHCOMP,
  121.  GADGIMMEDIATE | ENDGADGET | RELVERIFY,
  122.   BOOLGADGET | REQGADGET,
  123.   (APTR)&bord_2,  (APTR)&bord_2,
  124.   &CANCELtext, NULL,
  125.   NULL,   CANCELBUTTON, NULL,
  126. };
  127.  
  128. SHORT Pairs_3[] = {
  129.   0,     0,
  130.   152,     0,
  131.   152,     10,
  132.   0,     10,
  133.   0,     0
  134. };
  135. struct Border bord_3 = {
  136.   -1,  -1,
  137.   1,  3,  JAM2,
  138.   5,
  139.   (SHORT *)&Pairs_3,
  140.   NULL
  141. };
  142.  
  143. UBYTE Name_String[60] = '\0';
  144.  
  145. struct StringInfo NameStringInfo = {
  146.   Name_String, NULL,
  147.   0, 60, 0,
  148.   0, 0,
  149.   0, 0, 0,
  150.   0, 0,
  151.   0
  152. };
  153.  
  154. struct IntuiText req_name = {2,2, JAM1, 10, 10, NULL, NULL, NULL};
  155. struct IntuiText req_name1 = {2,2, JAM1, 10, 3, NULL, NULL, NULL};
  156. struct IntuiText req_name2 = {2,2, JAM1, 10, 11, NULL, NULL, &req_name1};
  157.  
  158. struct Gadget NameStringGad = {
  159.  &Cancel_Gad, 36, 21, 152, 10,
  160.  GADGHCOMP,
  161.   RELVERIFY | ENDGADGET,
  162.   STRGADGET | REQGADGET,
  163.   (APTR)&bord_3,  (APTR)&bord_3,
  164.   NULL,
  165.   NULL,
  166.   (APTR)&NameStringInfo,   NAMESTRGAD, NULL
  167. };
  168.  
  169. struct Requester name_req;
  170.  
  171. /*======================================================================
  172.   InitReq(req, gad, bord) - Initializes a requestor,  req is a pointer to a
  173.   previously allocated requestor.  Later on,  perhaps we can Allocate
  174.   one and return a pointer to it,   However,  because cleaning up
  175.   is tricky,   I'm taking the easy way out
  176. =======================================================================*/
  177. initnamereq()
  178. {
  179.     InitRequester(&name_req);      /* Init the requestor */
  180.     name_req.LeftEdge  = 169;
  181.     name_req.TopEdge   = 44;
  182.     name_req.Width     = 257;
  183.     name_req.Height    = 60;
  184.     name_req.ReqGadget = &NameStringGad;             /* First Gadget */
  185.     name_req.ReqText   = NULL;            /* First Intuitext */
  186.     name_req.BackFill  = 1;               /* Backgnd color */
  187.     name_req.Flags     = 0;               /* Must have at least one */
  188.     name_req.ReqBorder = &req_bord;            /* Outside border */
  189.     
  190. }
  191.  
  192. /* the getname routine */
  193. UBYTE *get_Star_Name(str1,str2)
  194. UBYTE *str1,*str2;                /* Message strings "SAVE FILENAME AS:" */
  195. {
  196.   int   looping=TRUE;
  197.   struct IntuiMessage *mes;
  198.   struct StringInfo *si = NULL;
  199.   struct Gadget *gad;     
  200.   ULONG class;
  201.   ULONG iflags;
  202.   UBYTE *c;
  203.  
  204.   
  205.   /*-------- Initialize the requester structure---------*/
  206.   initnamereq();
  207.  
  208.   /*-------- Set up the IntuiText for the requester -------*/
  209.   if (str2 == NULL) {
  210.       req_name.IText = str1;
  211.       name_req.ReqText = &req_name;
  212.      }
  213.   else {
  214.         req_name1.IText = str1;
  215.         req_name2.IText = str2;
  216.         name_req.ReqText = &req_name2;
  217.        }
  218.  
  219.  
  220.   iflags = nw.IDCMPFlags;         /* Current flag settings */
  221.  
  222.   /*-------- Open up the requester $$$---------*/
  223.   if ((Request(&name_req, w)) == 1L) {
  224.      iflags |= REQSET;
  225.      ModifyIDCMP(w, iflags);
  226.      while (looping) {
  227.          if ((mes = (struct IntuiMessage *)GetMsg(w->UserPort)) == NULL) {
  228.             Wait(1L<<w->UserPort->mp_SigBit);
  229.             continue;
  230.          }
  231.          class = mes->Class;
  232.          gad = (struct Gadget *)mes->IAddress;
  233.          ReplyMsg(mes);
  234.  
  235.         /*-------- Handle the case where requester clears --------*/
  236.         if (class == GADGETDOWN && gad->GadgetID == CANCELBUTTON) {
  237.             return(NULL);
  238.         }
  239.         if (class == REQSET) {
  240.            ActivateGadget(&NameStringGad, w, &name_req);
  241.            NameStringInfo.BufferPos = NameStringInfo.MaxChars;
  242.            RefreshGadgets(&NameStringGad, w, &name_req);
  243.         }
  244.  
  245.         if (class == GADGETDOWN && gad->GadgetID == OKBUTTON) {
  246.             for(c=Name_String; *c; c++) *c = toupper(*c);
  247.             return(Name_String);
  248.         }
  249.  
  250.         if (class == GADGETUP && gad == &NameStringGad) {
  251.            ModifyIDCMP(w, nw.IDCMPFlags);
  252.            for(c=Name_String; *c; c++) *c = toupper(*c);
  253.            return(Name_String);
  254.         }
  255.  
  256.         if (class == REQCLEAR) {
  257.             looping = FALSE;
  258.         }
  259.  
  260.      } /* while */
  261.   } /* if request */
  262. }
  263.  
  264.  
  265. /* get_number_req - This is a shell around the above requester to get a
  266.    point number.
  267. */
  268. FLOAT get_num_req(str,oldnum,lowrange,highrange)
  269. UBYTE *str;
  270. FLOAT oldnum, lowrange,highrange;
  271.   BOOL OKNUM;
  272.   FLOAT convertnum = 0.0;
  273.   UBYTE *c;
  274.  
  275.   sprintf(Name_String,"%5.2f",oldnum);
  276.   do
  277.     { OKNUM = TRUE;
  278.       c = get_Star_Name(str);
  279.       for (; *c;c++)
  280.         {if ((isdigit(*c)) || (*c == '.') || (isspace(*c))) /*do nothing*/ ;
  281.      else OKNUM = FALSE;
  282.     }
  283.      if (OKNUM)
  284.        { convertnum = atof(c);
  285.          if ((convertnum < lowrange) || (convertnum > highrange))
  286.             OKNUM = FALSE;
  287.        }
  288.     } while(OKNUM == FALSE);
  289.     
  290.  return(convertnum);
  291. }
  292.  
  293.