home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD1.img / d1xx / d164 / c-functions / makeautoreq.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  7KB  |  213 lines

  1.  
  2. /* Program for generating simple requesters dynamicaly */
  3. /* (C)Copyright 1988 by Lars Thuring */
  4.  
  5. /* May be freely distributed and used for any purpose as long as
  6.    the Copyright notice is left unchanged. */
  7.  
  8. /* Fri 13 nov 1987 V1.0 Make #2 */
  9. /*     24 nov 1987 V1.1 Library version */
  10. /*     18 jan 1988 V1.2 Adjusted for standard return values */
  11. /*     19 feb 1988 V1.3 *Data[] must be concluded by NULL pointer */
  12. /*     24 apr 1988 V1.4 j*=10+p[++i]-'0'; does not compile correct,
  13.                         Renamed from MakeSimpleReq.c */
  14. /*     17 may 1988 V1.5 01:22 "Bug" found in mb.c also here -
  15.                         adjust with i-- after ++i failed ... */
  16. /*     11 sep 1988 V1.6 Rendering of yes/no text. Thanks AutoDocs. */
  17.  
  18. #include <exec/types.h>
  19. #include <intuition/intuition.h>
  20.  
  21. #define THETEXT 0x01
  22. #define YESTXT  0x02
  23. #define NOTXT   0x04
  24. #define STRUCTSIZE sizeof(struct IntuiText)
  25.  
  26. int MakeAutoRequest();     /* Purpose of this ... */
  27.  
  28.    /* No Globals */
  29.  
  30. int MakeAutoRequest(w,Data)  /* Make a requester in window w */
  31. struct Window *w;              /* Return -1 if couldn't make it */
  32. UBYTE  *Data[];                /* Else return TRUE or FALSE */
  33.    {
  34. USHORT IntuiTextLength();     /* Return length of txt in pixels */
  35. BOOL   Adigit();              /* Return TRUE if ASCII digit */
  36. UBYTE *MyMem,*AllocMem();     /* Our buffer somwhere */
  37. USHORT MyMemorySize;          /* Size of memory area */
  38.  
  39. USHORT OpCode,link,i,j;       /* OpCode, mode and trash */
  40. USHORT ix=0;                  /* Loop index for Data[] */
  41. USHORT strings=0;             /* Number of string passed as argument */
  42. UBYTE  *p, *p2;               /* Data pointers */
  43. USHORT OptStart,OptEnd;       /* Area of options */
  44. USHORT ReqW=10, ReqH=10;      /* Physical parameters */
  45. USHORT WidestText=0;          /* To determine min width of requester */
  46.  
  47. UBYTE  FrontPen=AUTOFRONTPEN,BackPen=AUTOBACKPEN; /* Default defaults */
  48. SHORT  LeftEdge=AUTOLEFTEDGE,TopEdge=AUTOTOPEDGE;
  49. SHORT  Xtxt=LeftEdge, Ytxt=TopEdge;                   /* Init offsets */
  50. USHORT Yc = 8;                                        /* Linespacing  */
  51. USHORT DrawMode=AUTODRAWMODE;
  52. struct TextAttr *MyTextFont=NULL;         /* Not likely to be changed */
  53.  
  54. struct IntuiText *them;                   /* "Casted" into place later */
  55. struct IntuiText *Body=NULL,*Plus=NULL,*Minus=NULL;
  56. struct IntuiText *Previous=NULL;
  57. USHORT PFlags=NULL,MFlags=NULL;           /* For terminating requester */
  58.  
  59. /* Function: count strings, set values and write them into structs */
  60.  
  61.  
  62.    FOREVER                                /* Count strings passed */
  63.       if (NOT Data[strings++] ) break;
  64.  
  65.    MyMemorySize = STRUCTSIZE * strings;      /* The necessary area */
  66.    MyMem = AllocMem( MyMemorySize, 0 );      /* Get it from anywhere */
  67.    if (MyMem)
  68.       them = (struct IntuiText *) MyMem;     /* */
  69.    else
  70.       return (-1);            /* If couldn't get memory return error */
  71.  
  72.    while (--strings)
  73.       {
  74.       p=p2=Data[ix];                      /* Pointers to the text data */
  75.       OptStart=strinstr( p, '[' )-1;      /* Start of options...       */
  76.       OptEnd=strinstr( p, ']' )-1;        /*               ...and end  */
  77.       p[OptEnd]='\0';                     /* Split string into 2 strings */
  78.  
  79.       while (*p2++);                      /* Point at text to be shown */
  80.       p[OptEnd]=']';
  81.  
  82.    /* Set the defaults */
  83.  
  84.       link = TRUE;            /* Untill Positive- / Negative- text */
  85.       OpCode = THETEXT;
  86.  
  87.    /* Now determine parameters and fill in current structs */
  88.  
  89.       for (i=OptStart; i<OptEnd; i++)     /* Find user needs */
  90.          {
  91.          switch ( p[i] )
  92.             {
  93.          case 'B':                        /* Select new BackPen */
  94.             j=0;
  95.             while (Adigit(p[++i]))        /* if followed by ASCII digit */
  96.                j=j*10+p[i]-'0';           /* Add digit */
  97.             BackPen=j;                    /* Future: check against rp */
  98.             i--;                          /* Adjust for Adigit() */
  99.             break;
  100.  
  101.          case 'F':                        /* Select new FrontPen */
  102.             j=0;
  103.             while (Adigit(p[++i]))        /* if followed by ASCII digit */
  104.                j=j*10+p[i]-'0';           /* Add digit */
  105.             FrontPen=j;                   /* Future: check against rp */
  106.             i--;                          /* Adjust for Adigit() */
  107.             break;
  108.  
  109.          case 'J':                        /* Select new drawing mode */
  110.             if (p[++i] == '2')
  111.                DrawMode = JAM2;
  112.             else
  113.                DrawMode = JAM1;
  114.             break;
  115.  
  116.          case 'L':                        /* Set new Linespacing */
  117.             j=0;
  118.             while (Adigit(p[++i]))        /* if followed by ASCII digit */
  119.                j=j*10+p[i]-'0';           /* Add digit */
  120.             Yc=j;                         /* No check on validity */
  121.             i--;                          /* Adjust for Adigit() */
  122.             break;
  123.  
  124.          case 'N':                        /* Negative text */
  125.             link = NULL;
  126.             OpCode = NOTXT;
  127.             Minus = them;
  128.             break;
  129.  
  130.          case 'P':                        /* Positive text */
  131.             link = NULL;
  132.             OpCode = YESTXT;
  133.             Plus = them;
  134.             break;
  135.  
  136.          case 'T':                        /* Information text */
  137.             if (Body)
  138.                break;
  139.             OpCode = THETEXT;
  140.             Body = them;
  141.             break;
  142.  
  143.          default:
  144.             break;
  145.             }
  146.          }
  147.  
  148.       them->FrontPen    = FrontPen;          /* Text pen */
  149.       them->BackPen     = BackPen;           /* Paper pen */
  150.       them->DrawMode    = DrawMode;          /* JAM1 or JAM2 */
  151.       them->LeftEdge    = Xtxt;              /* X for this string */
  152.       them->TopEdge     = Ytxt;              /* Y for this string */
  153.       them->ITextFont   = MyTextFont;        /* NULL */
  154.       them->IText       = p2;                /* Characters */
  155.       them->NextText    = NULL;              /* May change later */
  156.       if (link && ix)                        /* Never link 1st text */
  157.          Previous->NextText = them;
  158.  
  159.  
  160.       if (OpCode == THETEXT)
  161.          {
  162.          Ytxt += Yc;
  163.          j = IntuiTextLength(them)+4*LeftEdge; /* Get length and compare */
  164.          if (j > WidestText)
  165.             WidestText=j;
  166.          }
  167.  
  168.  
  169.       Previous = them;
  170.       them++;
  171.       ix++;                /* Process next string */
  172.       }
  173.  
  174.    j = WidestText+LeftEdge+LeftEdge;
  175.    if (j > ReqW)
  176.       ReqW=j;
  177.  
  178.    j = Ytxt+3*(Yc+TopEdge)+TopEdge;
  179.    if(j > ReqH)
  180.       ReqH=j;
  181.  
  182.    if (Plus)
  183.       {
  184.       Plus->LeftEdge = LeftEdge;
  185.       Plus->TopEdge = 3;
  186.       }
  187.  
  188.    if (Minus)
  189.       {
  190.       Minus->LeftEdge = LeftEdge;
  191.       Minus->TopEdge = 3;
  192.       }
  193.  
  194.  
  195.    i = AutoRequest(w,Body,Plus,Minus,PFlags,MFlags,ReqW,ReqH);
  196.  
  197.    FreeMem( MyMem, MyMemorySize );
  198.  
  199.    return (int)(i);
  200.  
  201.    }  /* End of MakeSimpleRequest() */
  202.  
  203.  
  204.  
  205.  
  206. BOOL Adigit( c )    /* Return true if c is ASCII digit */
  207. UBYTE c;
  208.    {
  209.    return (BOOL) ( c>='0' && c<='9' ? TRUE : FALSE);
  210.    }
  211.  
  212.  
  213.