home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / misc / edu / WhirlDisc.lha / WhirlDisc / Source / general.c < prev    next >
C/C++ Source or Header  |  2000-08-10  |  3KB  |  146 lines

  1. /*
  2.  
  3. File: general.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2000 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24. #include "viewer.h"
  25.  
  26. #include "general_protos.h"
  27. #include <proto/exec.h>
  28. #include <proto/intuition.h>
  29.  
  30.  
  31. /* Function: GetLittleEndianUWord
  32.  * ==============================
  33.  * Reads a little-endian UWORD from memory.
  34.  */
  35.  
  36. UWORD GetLittleEndianUWord(UBYTE *data)
  37. {
  38.    return (*data+*(data+1)*0x100);
  39. }
  40.  
  41.  
  42.  
  43. /* Function: GetLittleEndianULong
  44.  * ==============================
  45.  * Reads a little-endian ULONG from memory.
  46.  */
  47.  
  48. ULONG GetLittleEndianULong(UBYTE *p)
  49. {
  50.    return *p|(*(p+1)<<8)|(*(p+2)<<16)|(*(p+3)<<24);
  51. }
  52.  
  53.  
  54.  
  55. /* Function: StripIntuiMessages
  56.  * ============================
  57.  */
  58.  
  59. VOID StripWindowMessages(struct Window *win)
  60. {
  61.    struct MsgPort *mp=win->UserPort;
  62.    struct IntuiMessage *msg;
  63.    struct Node *succ;
  64.  
  65.    msg=(struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  66.  
  67.    while(succ=msg->ExecMessage.mn_Node.ln_Succ)
  68.    {
  69.  
  70.       if(msg->IDCMPWindow==win)
  71.       {
  72.          Remove((struct Node *)msg);
  73.  
  74.          ReplyMsg((struct Message *)msg);
  75.       }
  76.  
  77.    msg=(struct IntuiMessage *)succ;
  78.    }
  79. }
  80.  
  81.  
  82.  
  83. /* Function: GetMinListNode
  84.  * ========================
  85.  */
  86.  
  87. struct MinNode *GetMinListNode(struct MinList *list,ULONG node_no)
  88. {
  89.    ULONG i;
  90.    struct MinNode *node=list->mlh_Head;
  91.  
  92. /*printf("node_no=%lu ((struct Node *)node)->ln_Name=%s\n",node_no,
  93.    ((struct Node *)node)->ln_Name);
  94. */
  95.  
  96.    for(i=0;i<node_no;i++)
  97.       node=node->mln_Succ;
  98.  
  99.    return node;
  100.  
  101. }
  102.  
  103.  
  104.  
  105. /* Function: ReportError
  106.  * =====================
  107.  */
  108.  
  109. ULONG ReportError(struct Window *window,UBYTE report_type,
  110.    TEXT *resource_name,UWORD version_no)
  111. {
  112.    ULONG result;
  113.    struct EasyStruct easy_struct;
  114.  
  115.    easy_struct.es_StructSize=sizeof(struct EasyStruct);
  116.    easy_struct.es_Flags=0;
  117.    easy_struct.es_Title="WhirlDisc";
  118.    easy_struct.es_GadgetFormat="OK";
  119.  
  120.    switch(report_type)
  121.    {
  122.    case ERROR_REPORT_MEM:
  123.       easy_struct.es_TextFormat="Not enough memory.";
  124.       result=EasyRequest(window,&easy_struct,NULL);
  125.       break;
  126.    case ERROR_REPORT_LIB:
  127.       easy_struct.es_TextFormat="Could not open \"%s\" version %lu or"
  128.          " greater.";
  129.       result=EasyRequest(window,&easy_struct,NULL,resource_name,version_no);
  130.       break;
  131.    case ERROR_REPORT_FILE:
  132.       easy_struct.es_TextFormat="Could not open file \"%s\".";
  133.       result=EasyRequest(window,&easy_struct,NULL,resource_name);
  134.       break;
  135.    case ERROR_REPORT_WIN:
  136.       easy_struct.es_TextFormat="Could not open window.";
  137.       result=EasyRequest(window,&easy_struct,NULL);
  138.       break;
  139.    }
  140.  
  141.    return result;
  142. }
  143.  
  144.  
  145.  
  146.