home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 552.lha / PatchReq_v1.4 / PatchReq-Seg.c < prev    next >
C/C++ Source or Header  |  1991-09-08  |  6KB  |  256 lines

  1. /*
  2.  *    PatchReq-Seg.c - Copyright © 1991 by Devil's child.
  3.  *
  4.  *    Created:    27 Jan 1991  19:32:31
  5.  *    Modified:    25 Jul 1991  19:47:22
  6.  *
  7.  *    Make>> cc -qf -ps -m0b -md -so -sb -wu -wd -wp -hi ram:small.sym <file>.c
  8.  *    Make>> ln <file>.o -lreql
  9.  *
  10.  *    MUST be compiled in LARGE_DATA model to allow access to global data from
  11.  *    different processes and loader.
  12.  */
  13.  
  14.  
  15. #define BUFSIZE 2000
  16. #define SOFTWARE_ERROR    "Software error"
  17. #define ERROR_STR_LEN    14
  18.  
  19.  
  20. /* defined in loader too */
  21. #define    DIR_CACHE    1
  22. #define NOAUTOREQ    2
  23.  
  24.  
  25. struct ExtendedFileReq {
  26.     struct FileReq Freq;
  27.     char File[REQ_FCHARS+1];
  28.     char Dir[REQ_DSIZE+1];
  29.     char Path[REQ_DSIZE+REQ_FCHARS+2];
  30. };
  31.  
  32.  
  33. struct ExecBase *SysBase;
  34. struct ArpBase *ArpBase;
  35. struct ReqLib *ReqBase;
  36. struct IntuitionBase *IntuitionBase;
  37. PVF FuncTab[3];
  38.  
  39. /* directory cache handling variables */
  40. struct ExtendedFileReq *LastEFR;
  41. short Usage;
  42. short PatchFlags; 
  43. long (*OldTextRequest)();
  44. long (*OldAutoRequest)();
  45.  
  46. void setmem(void *mem, size_t size, long value);
  47.  
  48.  
  49. long AsmOldAutoReq(struct Window *Window, struct IntuiText *Body, struct IntuiText *PText, struct IntuiText *NText, long PFlag, long NFlag, long W, long H);
  50. #pragma regcall(AsmOldAutoReq(a0,a1,a2,a3,d0,d1,d2,d3))
  51.  
  52. long NewAutoRequest(struct Window *Window, struct IntuiText *Body, struct IntuiText *PText, struct IntuiText *NText, long PFlag, long NFlag, long W, long H);
  53. #pragma regcall(NewAutoRequest(a0,a1,a2,a3,d0,d1,d2,d3))
  54.  
  55. long NewTextRequest(struct TRStructure *TRS);
  56. #pragma regcall(NewTextRequest(a0))
  57.  
  58. long NewFileRequest(struct FileRequester *);
  59. #pragma regcall(NewFileRequest(a0))
  60.  
  61.  
  62. PVF *Setup(struct ArpBase *Arp, struct ReqLib *Req, long (*OldTR)(), long (*OldAR)(), short Flags)
  63. {
  64.     SysBase = *((struct ExecBase **)4L);
  65.     ArpBase = Arp;
  66.     ReqBase = Req;
  67.     IntuitionBase = ReqBase->IntuiLib;
  68.     OldTextRequest = OldTR;
  69.     OldAutoRequest = OldAR;
  70.     PatchFlags = Flags;
  71.     FuncTab[0] = (PVF)NewAutoRequest;
  72.     FuncTab[1] = (PVF)NewTextRequest;
  73.     FuncTab[2] = (PVF)NewFileRequest;
  74.     return FuncTab;
  75. }
  76.  
  77.  
  78. char *WideText(char *Text, char *buf)
  79. {
  80.     if (strlen(Text) <= 3) {
  81.         Format(buf, " %s ", Text);
  82.         return buf;
  83.     }
  84.     else
  85.         return Text;
  86. }
  87.  
  88.  
  89. long NewAutoRequest(struct Window *Window, struct IntuiText *Body, struct IntuiText *PText, struct IntuiText *NText, long PFlag, long NFlag, long W, long H)
  90. {
  91.     struct Process *ThisProc;
  92.     struct IntuiText *IT;
  93.     struct TRStructure TRS;
  94.     char nbuf[6],pbuf[6],ProcName[40],CliNum[30],space[10];
  95.     char *s,*d;
  96.     long RC;
  97.     BOOL Guru = FALSE;
  98.     short i;
  99.  
  100.     if (!Strncmp((char *)Body->IText, SOFTWARE_ERROR, ERROR_STR_LEN))
  101.         Guru = TRUE;
  102.     else if (PatchFlags & NOAUTOREQ)
  103.         return AsmOldAutoReq(Window, Body, PText, NText, PFlag, NFlag, W, H);
  104.     setmem(&TRS, sizeof(struct TRStructure), 0);
  105.     TRS.Text = d = AllocMem(BUFSIZE, MEMF_PUBLIC);
  106.     TRS.Window = Window;
  107.     if (PText) TRS.PositiveText = WideText((char *)PText->IText, pbuf);
  108.     if (NText) TRS.NegativeText = WideText((char *)NText->IText, nbuf);
  109.     TRS.Title = "System Request";
  110.     TRS.KeyMask = 0xFFFF;
  111.     TRS.textcolor = 1;
  112.     TRS.detailcolor = (Window) ? Window->DetailPen : 0;
  113.     TRS.blockcolor = (Window) ? Window->BlockPen : 1;
  114.     if (Guru) {
  115.         TRS.PositiveText = "Suspend";
  116.         ThisProc = (struct Process *)SysBase->ThisTask;
  117.         if (ThisProc->pr_Task.tc_Node.ln_Type == NT_TASK || !ThisProc->pr_CLI) {
  118.             s = ThisProc->pr_Task.tc_Node.ln_Name;
  119.             CliNum[0] = 0;
  120.         }
  121.         else {
  122.             BtoCStr(ProcName, ((struct CommandLineInterface *)(ThisProc->pr_CLI << 2))->cli_CommandName, 80);
  123.             s = BaseName(ProcName);
  124.             Format(CliNum, "\n        CLI Number %ld", ThisProc->pr_TaskNum);
  125.         }
  126.         strcpy(space, "        ");
  127.         i = 16-strlen(s);
  128.         space[(i>0) ? i>>1 : 0] = '\0';
  129.         Format(d, "       Software error\n%sTask \"%s\" held%s\n ", space, s, CliNum);
  130.         d += strlen(d);
  131.         IT = Body->NextText;
  132.     }
  133.     else
  134.         IT = Body;
  135.     while(IT) {
  136.         s = (char *)IT->IText;
  137.         while(*d++ = *s++);
  138.         *(d-1) = '\n';
  139.         *d = '\0';
  140.         IT = IT->NextText;
  141.     }
  142.     *(d-1) = '\0';
  143.     RC = TextRequest(&TRS);
  144.     FreeMem(TRS.Text, BUFSIZE);
  145.     if (Guru == TRUE && RC)
  146.         Wait(0L);
  147.     else
  148.         return RC;
  149. }
  150.  
  151.  
  152. long NewFileRequest(struct FileRequester *ArpFR)
  153. {
  154.     struct ExtendedFileReq *EFR;
  155.     long RC;
  156.     BOOL KeepIt = FALSE;
  157.  
  158.     if (strlen(ArpFR->fr_Dir) == 0)
  159.         PathName(((struct Process *)SysBase->ThisTask)->pr_CurrentDir, ArpFR->fr_Dir, LONG_DSIZE);
  160.     Forbid();
  161.     if (!(EFR = LastEFR) || Usage != 0)
  162.         EFR = AllocMem(sizeof(struct ExtendedFileReq), MEMF_PUBLIC|MEMF_CLEAR);
  163.     if ((PatchFlags & DIR_CACHE) && Usage == 0) {
  164.         Usage = 1;
  165.         KeepIt = TRUE;
  166.         LastEFR = EFR;                        /* needed first call */
  167.         EFR->Freq.Flags = FRQCACHINGM;        /* needed first call */
  168.         if (Strcmp(EFR->Dir, ArpFR->fr_Dir))
  169.             PurgeFiles((struct FileReq *)EFR);
  170.     }
  171.     Permit();
  172.     if (!EFR)
  173.         return 0;
  174.     EFR->Freq.Dir = EFR->Dir;
  175.     EFR->Freq.File = EFR->File;
  176.     EFR->Freq.PathName = EFR->Path;
  177.     EFR->Freq.Flags |= FRQINFOGADGETM;
  178.     EFR->Freq.dirnamescolor = 3;
  179.     EFR->Freq.devicenamescolor = 3;
  180.     EFR->Freq.stringnamecolor = 2;
  181.     EFR->Freq.stringgadgetcolor = 2;
  182.     EFR->Freq.boxbordercolor = 2;
  183.     EFR->Freq.gadgetboxcolor = 2;
  184.     EFR->Freq.Window = ArpFR->fr_Window;
  185.     strcpy(EFR->Dir, ArpFR->fr_Dir);
  186.     strcpy(EFR->File, ArpFR->fr_File);
  187.     EFR->Freq.Title = ArpFR->fr_Hail;
  188.     RC = FileRequester((struct FileReq *)EFR);
  189.     if (RC) {
  190.         strcpy(ArpFR->fr_Dir, EFR->Dir);
  191.         strcpy(ArpFR->fr_File, EFR->File);
  192.     }
  193.     if ((PatchFlags & DIR_CACHE) && KeepIt)
  194.         Usage = 0;
  195.     else
  196.         FreeMem(EFR, sizeof(struct ExtendedFileReq));
  197.     return RC;
  198. }
  199.  
  200.  
  201. #asm
  202.  
  203. ThisTask        equ        276
  204. pr_WindowPtr    equ        184
  205. WBenchToFront    equ        -342
  206. Window            equ        8
  207.  
  208.         far     data                ; large data model
  209.  
  210.         xdef    _Format
  211.         xdef    _NewTextRequest
  212.         xdef    _AsmOldAutoReq
  213.  
  214. _NewTextRequest:
  215.         movem.l    a3/a6,-(sp)
  216.         move.l    a0,a3                ; save TRS
  217.         move.l    _SysBase,a0
  218.         move.l    ThisTask(a0),a1
  219.         tst.l    Window(a3)
  220.         bne        EndIf
  221.         tst.l    pr_WindowPtr(a1)
  222.         bne        EndIf
  223.         move.l    _IntuitionBase,a6
  224.         jsr        WBenchToFront(a6)
  225. EndIf
  226.         move.l    a3,a0                ; give back TRS to a0
  227.         move.l    _OldTextRequest,a1
  228.         move.l    _ReqBase,a6
  229.         jsr        (a1)
  230.         movem.l    (sp)+,a3/a6
  231.         rts
  232.  
  233.  
  234. _AsmOldAutoReq:
  235.         movem.l    a4/a6,-(sp)
  236.         move.l    _IntuitionBase,a6
  237.         move.l    _OldAutoRequest,a4
  238.         jsr        (a4)
  239.         movem.l    (sp)+,a4/a6
  240.         rts        
  241.  
  242.  
  243.         public _setmem
  244.  
  245. _setmem
  246.         move.l    4(sp),a0
  247.         movem.l    8(sp),d0/d1
  248.         bra        .l2
  249. .l1
  250.         move.b    d1,(a0)+
  251. .l2
  252.         dbra    d0,.l1
  253.         rts
  254.  
  255. #endasm
  256.