home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / pastex14-beta-6 / specialhost / source / tools.c < prev    next >
C/C++ Source or Header  |  1994-08-03  |  12KB  |  553 lines

  1. /*
  2. **    SpecialHost for PasTeX
  3. **
  4. **    Copyright © by Olaf Barthel & Georg Heßmann
  5. */
  6.  
  7. #include "Global.h"
  8.  
  9. STATIC int UseFastMem = 0;    /* (hes) some kind of test: does SpecialHost work with Bitmap in FAST-RAM too?    */
  10.                 /* No! There are used some OS functions, which need CHIP-RAM!            */
  11.  
  12.  
  13. VOID __regargs
  14. FreeVecPooled(APTR Mem)
  15. {
  16.     if(Mem)
  17.     {
  18.         ULONG *Data = Mem;
  19.  
  20.         LibFreePooled(Pool,&Data[-1],Data[-1]);
  21.     }
  22. }
  23.  
  24. APTR __regargs
  25. AllocVecPooled(LONG Size,ULONG Flags)
  26. {
  27.     if(Size)
  28.     {
  29.         ULONG *Data;
  30.  
  31.         Size += sizeof(ULONG);
  32.  
  33.         if(Data = (ULONG *)LibAllocPooled(Pool,Size))
  34.         {
  35.             *Data++ = Size;
  36.  
  37.             if(Flags & MEMF_CLEAR)
  38.                 memset(Data,0,Size - sizeof(ULONG));
  39.  
  40.             return((APTR)Data);
  41.         }
  42.     }
  43.  
  44.     return(NULL);
  45. }
  46.  
  47. VOID __regargs
  48. ClearList(struct List *List)
  49. {
  50.     struct Node    *Node,
  51.             *Next;
  52.  
  53.     Node = List -> lh_Head;
  54.  
  55.     while(Next = Node -> ln_Succ)
  56.     {
  57.         FreeVecPooled(Node);
  58.  
  59.         Node = Next;
  60.     }
  61.  
  62.     NewList(List);
  63. }
  64.  
  65. struct ListEntry * __regargs
  66. NewEntry(STRPTR Title)
  67. {
  68.     struct ListEntry *Entry;
  69.  
  70.     if(Entry = (struct ListEntry *)AllocVecPooled(sizeof(struct ListEntry) + strlen(Title),MEMF_ANY))
  71.     {
  72.         Entry -> Title = (STRPTR)(Entry + 1);
  73.  
  74.         strcpy(Entry -> Title,Title);
  75.     }
  76.  
  77.     return(Entry);
  78. }
  79.  
  80. WORD __stdargs
  81. ShowRequest(struct Window *Window,STRPTR Text,STRPTR Gadgets,...)
  82. {
  83.     WORD Result;
  84.  
  85.     if(AP_Application)
  86.     {
  87.         va_list VarArgs;
  88.  
  89.         va_start(VarArgs,Gadgets);
  90.         Result = MUI_RequestA(AP_Application,WI_Main,NULL,"SpecialHost",Gadgets,Text,VarArgs);
  91.         va_end(VarArgs);
  92.     }
  93.     else
  94.     {
  95.         struct EasyStruct    Easy;
  96.         ULONG            IDCMP = NULL;
  97.         va_list             VarArgs;
  98.  
  99.         Easy . es_StructSize    = sizeof(struct EasyStruct);
  100.         Easy . es_Flags        = NULL;
  101.         Easy . es_Title        = "SpecialHost";
  102.         Easy . es_TextFormat    = Text;
  103.         Easy . es_GadgetFormat    = Gadgets;
  104.  
  105.         va_start(VarArgs,Gadgets);
  106.         Result = EasyRequestArgs(Window,&Easy,&IDCMP,VarArgs);
  107.         va_end(VarArgs);
  108.     }
  109.  
  110.     return(Result);
  111. }
  112.  
  113. STRPTR __regargs
  114. ShowError(LONG Primary,LONG Secondary,BOOL GetPrimary)
  115. {
  116.     STATIC struct { LONG Code; STRPTR Name; } LocalErrors[] =
  117.     {
  118.         ERR_NO_INTUITION,        "Error opening intuition.library v37",
  119.         ERR_NO_GRAPHICS,        "Error opening graphics.library v37",
  120.         ERR_NO_GADTOOLS,        "Error opening gadtools.library v37",
  121.         ERR_NO_ICON,            "Error opening icon.library v37",
  122.         ERR_NO_IFFPARSE,        "Error opening iffparse.library v37",
  123.         ERR_NO_UTILITY,            "Error opening utility.library v37",
  124.         ERR_NO_ASL,            "Error opening asl.library v37",
  125.         ERR_NO_MUI,            "Error opening muimaster.library",
  126.         ERR_NO_MATHFFP,            "Error opening mathieeedoubbas.library",
  127.         ERR_NO_MATHTRANS,        "Error opening mathieeedoubtrans.library",
  128.         ERR_NO_POOL,            "Error creating memory pool",
  129.         ERR_NO_GUI,            "Error opening window",
  130.         ERR_ALREADY_RUNNING,        "SpecialHost process already running",
  131.         ERR_NO_PORT,            "Error opening message port",
  132.         ERR_READ_ERROR,            "Error reading file",
  133.         ERR_NO_MEM,            "Out of memory",
  134.         ERR_FILE_FORMAT_ERROR,        "File format corrupt",
  135.         ERR_WEIRD_COMPRESSION,        "Image compression type not supported",
  136.         ERR_WRONG_IMAGE_FORMAT,        "Cannot handle picture file format",
  137.         ERR_TOO_LARGE,            "Requested image size is too large",
  138.         ERR_TOO_SMALL,            "Requested image size is too small",
  139.         ERR_NO_NIL,            "Error opening NIL: stream",
  140.         ERR_NO_POST,            "Error opening post.library v15",
  141.  
  142.         DTERROR_UNKNOWN_DATATYPE,    "Unknown file format",
  143.         DTERROR_COULDNT_SAVE,        "Could not store file",
  144.         DTERROR_COULDNT_OPEN,        "Could not open file",
  145.         DTERROR_COULDNT_SEND_MESSAGE,    "Internal send message error",
  146.         DTERROR_COULDNT_OPEN_CLIPBOARD,    "Could not open clipboard",
  147.         DTERROR_UNKNOWN_COMPRESSION,    "Compression method unknown",
  148.         DTERROR_NOT_ENOUGH_DATA,    "Not enough data available",
  149.         DTERROR_INVALID_DATA,        "Invalid data",
  150.  
  151.         19999,                "Postscript error: File not found",
  152.         20001,                "Postscript error: Dictionary full",
  153.         20002,                "Postscript error: Dictionary stack overflow",
  154.         20003,                "Postscript error: Dictionary stack underflow",
  155.         20004,                "Postscript error: Exec stack overflow",
  156.         20005,                "Postscript error: Interrupted",
  157.         20006,                "Postscript error: Invalid access",
  158.         20007,                "Postscript error: Invalid exit",
  159.         20008,                "Postscript error: Invalid file access",
  160.         20009,                "Postscript error: Invalid font",
  161.         20010,                "Postscript error: Invalid restore",
  162.         20011,                "Postscript error: Invalid stop",
  163.         20012,                "Postscript error: I/O error",
  164.         20013,                "Postscript error: Limit check trap",
  165.         20014,                "Postscript error: No current point",
  166.         20015,                "Postscript error: Range check trap",
  167.         20016,                "Postscript error: Stack overflow",
  168.         20017,                "Postscript error: Stack underflow",
  169.         20018,                "Postscript error: Syntax error",
  170.         20019,                "Postscript error: Timeout",
  171.         20020,                "Postscript error: Typecheck",
  172.         20021,                "Postscript error: Undefined",
  173.         20022,                "Postscript error: Undefined filename",
  174.         20023,                "Postscript error: Undefined result",
  175.         20024,                "Postscript error: Unmatched mark",
  176.         20025,                "Postscript error: Unregistered",
  177.         20026,                "Postscript error: Virtual memory error",
  178.         20027,                "Postscript error: Memory allocation error",
  179.         20028,                "Postscript error: Killed",
  180.         20029,                "Postscript error: Configuration",
  181.         20030,                "Postscript error: Undefined resource",
  182.  
  183.         IFFERR_NOMEM,            "Out of memory",
  184.         IFFERR_READ,            "File read error",
  185.         IFFERR_WRITE,            "File write error",
  186.         IFFERR_SEEK,            "File seek error",
  187.         IFFERR_MANGLED,            "File structure damaged",
  188.         IFFERR_NOTIFF,            "Not an IFF format file",
  189.  
  190.         0,                NULL
  191.     };
  192.  
  193.     STRPTR    PrimaryError    = NULL,
  194.         SecondaryError    = NULL;
  195.  
  196.     if(Primary)
  197.     {
  198.         LONG i;
  199.  
  200.         for(i = 0 ; LocalErrors[i] . Name ; i++)
  201.         {
  202.             if(LocalErrors[i] . Code == Primary)
  203.             {
  204.                 PrimaryError = LocalErrors[i] . Name;
  205.  
  206.                 break;
  207.             }
  208.         }
  209.  
  210.         if(!PrimaryError)
  211.         {
  212.             STATIC UBYTE __far Buffer[256];
  213.  
  214.             Fault(Primary,"",Buffer,256);
  215.  
  216.             PrimaryError = Buffer + 2;
  217.         }
  218.  
  219.         if(GetPrimary)
  220.             return(PrimaryError);
  221.     }
  222.  
  223.     if(Secondary)
  224.     {
  225.         LONG i;
  226.  
  227.         for(i = 0 ; LocalErrors[i] . Name ; i++)
  228.         {
  229.             if(LocalErrors[i] . Code == Secondary)
  230.             {
  231.                 SecondaryError = LocalErrors[i] . Name;
  232.  
  233.                 break;
  234.             }
  235.         }
  236.  
  237.         if(!SecondaryError)
  238.         {
  239.             STATIC UBYTE __far Buffer[256];
  240.  
  241.             Fault(Secondary,"",Buffer,256);
  242.  
  243.             SecondaryError = Buffer + 2;
  244.         }
  245.     }
  246.  
  247.     if(PrimaryError)
  248.     {
  249.         if(ThisProcess -> pr_CLI)
  250.         {
  251.             if(SecondaryError)
  252.                 Printf("SpecialHost: %s, %s\a\n",PrimaryError,SecondaryError);
  253.             else
  254.                 Printf("SpecialHost: %s\a\n",PrimaryError);
  255.         }
  256.         else
  257.         {
  258.             if(IntuitionBase)
  259.             {
  260.                 if(SecondaryError)
  261.                     ShowRequest(NULL,"%s\n%s","Continue",PrimaryError,SecondaryError);
  262.                 else
  263.                     ShowRequest(NULL,"%s","Continue",PrimaryError);
  264.             }
  265.         }
  266.     }
  267. }
  268.  
  269. VOID __regargs
  270. DeleteBitMap(struct BitMap *BitMap)
  271. {
  272.     if(GfxBase -> LibNode . lib_Version >= 39 && !UseFastMem)
  273.         FreeBitMap(BitMap);
  274.     else
  275.     {
  276.         LONG i;
  277.  
  278.         for(i = 0 ; i < BitMap -> Depth ; i++)
  279.         {
  280.             if(BitMap -> Planes[i])
  281.                 FreeVec(BitMap -> Planes[i]);
  282.         }
  283.  
  284.         FreeVecPooled(BitMap);
  285.     }
  286. }
  287.  
  288. struct BitMap * __regargs
  289. CreateBitMap(LONG Width,LONG Height,LONG Depth,ULONG Flags,struct BitMap *Friend)
  290. {
  291.     if(GfxBase -> LibNode . lib_Version < 39 || UseFastMem)
  292.     {
  293.         struct BitMap    *BitMap;
  294.         LONG         Plus;
  295.  
  296.         if(Depth > 8)
  297.             Plus = (Depth - 8) * sizeof(PLANEPTR);
  298.         else
  299.             Plus = 0;
  300.  
  301.         if(BitMap = (struct BitMap *)AllocVecPooled(sizeof(struct BitMap) + Plus,MEMF_ANY | MEMF_CLEAR))
  302.         {
  303.             LONG i,PageSize;
  304.  
  305.             InitBitMap(BitMap,Depth,Width,Height);
  306.  
  307.             PageSize = BitMap -> BytesPerRow * BitMap -> Rows;
  308.  
  309.             for(i = 0 ; i < BitMap -> Depth ; i++)
  310.             {
  311.                 if (UseFastMem)
  312.                 {
  313.                     BitMap -> Planes[i] = (PLANEPTR)AllocVec(PageSize,MEMF_ANY | ((Flags & BMF_CLEAR) ? MEMF_CLEAR : 0));
  314.                 }
  315.                 else
  316.                 {
  317.                     BitMap -> Planes[i] = (PLANEPTR)AllocVec(PageSize,MEMF_CHIP);
  318.                 }
  319.  
  320.                 if(!BitMap -> Planes[i])
  321.                 {
  322.                     LONG j;
  323.  
  324.                     for(j = 0 ; j < i ; j++)
  325.                         FreeVec(BitMap -> Planes[j]);
  326.  
  327.                     FreeVecPooled(BitMap);
  328.  
  329.                     return(NULL);
  330.                 }
  331.             }
  332.  
  333.             if((Flags & BMF_CLEAR) && !UseFastMem)
  334.                 BltBitMap(BitMap,0,0,BitMap,0,0,Width,Height,0x00,(1 << Depth) - 1,NULL);
  335.  
  336.             return(BitMap);
  337.         }
  338.     }
  339.     else
  340.         return(AllocBitMap(Width,Height,Depth,Flags,Friend));
  341. }
  342.  
  343. VOID __regargs
  344. DeleteTempLine(UBYTE *Line)
  345. {
  346.     FreeVecPooled(Line);
  347. }
  348.  
  349. UBYTE * __regargs
  350. CreateTempLine(LONG Width,LONG Height)
  351. {
  352.     return((UBYTE *)A