home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / workbench / gurulog / src / gurulog.e < prev    next >
Encoding:
Text File  |  1998-01-31  |  5.7 KB  |  193 lines

  1. -> GuruLog v1.0
  2. -> Keeps a log of software failures and recoverable alerts
  3.  
  4. OPT PREPROCESS,OSVERSION=37
  5.  
  6. MODULE 'dos/datetime', 'dos/dos', 'dos/dosextens', 'exec/alerts',
  7.        'exec/execbase', 'exec/memory', 'exec/nodes', 'exec/tasks',
  8.        'hardware/blit', 'hardware/custom', 'hardware/dmabits',
  9.        '*hex', '*clr'
  10.  
  11. #define TEMPLATE 'LOGFILE/A,GURUDAT,TASKNAME/S'
  12. ENUM OPT_FILE, OPT_DAT, OPT_TASK, OPT_COUNT
  13. RAISE "ARGS" IF ReadArgs()=NIL
  14.  
  15. DEF args[OPT_COUNT]:ARRAY OF LONG, rdargs=NIL,
  16.     gurucode, deadtask:PTR TO process
  17.  
  18. PROC main() HANDLE
  19.   DEF fh=NIL, by[128]:STRING, cause[256]:STRING, task[256]:STRING, s,l,
  20.       datebuf[LEN_DATSTRING]:STRING, timebuf[LEN_DATSTRING]:STRING,
  21.       daybuf[LEN_DATSTRING]:STRING, dt:datetime
  22.  
  23.   /* get the two vital bits of magic... */
  24.   gurucode:=steallong($100)
  25.   deadtask:=steallong($104)
  26.   IF (gurucode=0) OR (deadtask=0) THEN RETURN
  27.  
  28.   /* read in arguments */
  29.   clr(args,OPT_COUNT*4); rdargs:=ReadArgs(TEMPLATE,args,NIL)
  30.  
  31.   /* try to copy the task's name, if we are allowed to */
  32.   IF args[OPT_TASK]
  33.     s,l:=taskname(deadtask)
  34.     StrCopy(task,s,l)
  35.   ELSE
  36.     StrCopy(task,'Unknown')
  37.   ENDIF
  38.  
  39.   /* find out the date */
  40.   dt.strday:=daybuf; dt.strdate:=datebuf; dt.strtime:=timebuf; dt.flags:=0
  41.   DateStamp(dt); DateToStr(dt)
  42.  
  43.   /* attempt to describe the error */
  44.   StrCopy(by,'Unknown')
  45.   StrCopy(cause,'couldn\at load MCP.gurudat!')
  46.   IF args[OPT_DAT] THEN describe_error(by,cause,args[OPT_DAT])
  47.  
  48.   /* log the error */
  49.   IF fh:=Open(args[OPT_FILE],MODE_READWRITE)
  50.     /* if an empty/new file, then write a 'header',  */
  51.     /* otherwise seek to the end of the file         */
  52.     IF FileLength(args[OPT_FILE])<1
  53.       SetIoErr(0)
  54.       VfPrintf(fh,
  55.         '    MCP95 by PiRATEsCUM, producing crashtools for Work'+
  56.         'bench lusers since 1993.\n============================'+
  57.         '======================================================\n',
  58.       NIL)
  59.     ELSE
  60.       Seek(fh,0,OFFSET_END)
  61.     ENDIF
  62.     VfPrintf(fh,
  63.       'Date  : \s \s  \s\n'+
  64.       'Task  : \z\h[8] "\s"\n'+
  65.       'Error : \z\h[8] (\s)\n'+
  66.       'By    : \s\nCause : \s\n'+
  67.       '----------------------------------------'+
  68.       '----------------------------------------\n', [
  69.       daybuf, datebuf, timebuf,
  70.       deadtask, task,
  71.       gurucode, IF gurucode AND AT_DEADEND THEN 'DEADEND' ELSE 'Recoverable',
  72.        by, cause
  73.     ])
  74.   ENDIF
  75.  
  76.   Raise()
  77. EXCEPT
  78.   IF fh     THEN Close(fh)
  79.   IF rdargs THEN FreeArgs(rdargs)
  80.  
  81.   PrintFault(IoErr(),NIL)
  82.   CleanUp(IF exception THEN RETURN_ERROR ELSE RETURN_OK)
  83. ENDPROC
  84.  
  85. ->-----------------------------------------------------------------------------
  86.  
  87. -> looks for the name of the process/task - if it's valid!
  88. -> WARNING: probes memory whether it's owned by us or not
  89. PROC taskname(task:PTR TO process)
  90.   DEF type,n,name,valid,c,len,cli:PTR TO commandlineinterface
  91.   IF TypeOfMem(task)
  92.     type:=task.task.ln.type
  93.     IF type=NT_TASK
  94.       name:=task.task.ln.name
  95.       IF TypeOfMem(name)
  96.         n:=0
  97.         valid:=FALSE
  98.         REPEAT
  99.           c:=name[n]
  100.           IF c=0 THEN valid:=TRUE
  101.           INC n
  102.         UNTIL (n>255) OR ((c<32) AND (c<>0)) OR ((c>=128) AND (c<160))
  103.         IF valid THEN RETURN name,n
  104.       ENDIF
  105.     ENDIF
  106.     IF type=NT_PROCESS
  107.       cli:=BADDR(task.cli)
  108.       IF TypeOfMem(cli)
  109.         name:=BADDR(cli.commandname)
  110.         IF TypeOfMem(name)
  111.           len:=name[0]
  112.           n:=1
  113.           valid:=FALSE
  114.           REPEAT
  115.             c:=name[n]
  116.             IF n=len THEN valid:=TRUE
  117.             INC n
  118.           UNTIL (n>len) OR ((c<32) AND (c<>0)) OR ((c>=128) AND (c<160))
  119.           IF valid THEN RETURN name+1,len
  120.         ENDIF
  121.       ENDIF    
  122.     ENDIF
  123.   ENDIF
  124. ENDPROC 'Unknown',7
  125.  
  126. ->-----------------------------------------------------------------------------
  127.  
  128. /*
  129. *    +---------------+----------------+--------------------------------+
  130. *    |D|  SubSysId   |    General Error |    SubSystem Specific Error    |
  131. *    +---------------+----------------+--------------------------------+
  132. *     1    7 bits       8 bits           16 bits
  133. *
  134. *             D:  DeadEnd alert
  135. *          SubSysId:  indicates ROM subsystem number.
  136. *     General Error:  roughly indicates what the error was
  137. *    Specific Error:  indicates more detail
  138. */
  139.  
  140. PROC describe_error(by, cause, file)
  141.   DEF temp[300]:STRING, fh, code, ok,
  142.       general[256]:STRING, specific[256]:STRING,
  143.       subs, genc, spec, guru
  144.  
  145.   IF (fh:=Open(file, MODE_OLDFILE))=NIL THEN RETURN
  146.  
  147.   guru:=gurucode AND $7FFFFFFF
  148.   subs:=gurucode AND $7F000000
  149.   genc:=gurucode AND $00FF0000
  150.   spec:=gurucode AND $0000FFFF
  151.  
  152.   StrCopy(cause,'')
  153.   WHILE Fgets(fh, temp, StrMax(temp)-1)
  154.     SetStr(temp,StrLen(temp)-1)
  155.     IF StrLen(temp)>9
  156.       code,ok:=hex(temp)
  157.       code:=code AND $7FFFFFFF
  158.       IF ok
  159.         IF code=subs THEN StrCopy(by,temp+9)
  160.         IF code=guru THEN StrCopy(cause,temp+9)
  161.         IF code=genc AND genc THEN StrCopy(general,temp+9)
  162.         IF code=spec AND spec THEN StrCopy(specific,temp+9)
  163.       ENDIF
  164.     ENDIF
  165.   ENDWHILE
  166.   IF (StrLen(cause)=0) AND StrLen(general) THEN StringF(cause, '\s\s\s',
  167.     general,
  168.     IF StrLen(specific) THEN ' '      ELSE '',
  169.     IF StrLen(specific) THEN specific ELSE ''
  170.   )
  171.   Close(fh)
  172. ENDPROC
  173.  
  174. ->-----------------------------------------------------------------------------
  175.  
  176. -> a highly cut-down version of stealchip.e
  177. PROC steallong(src)
  178.   DEF mem, c:PTR TO custom, ret
  179.   IF (mem:=AllocVec(8,MEMF_CHIP))=NIL THEN RETURN 0
  180.   OwnBlitter(); WaitBlit()
  181.   c:=CUSTOMADDR
  182.   c.dmacon:=DMAF_SETCLR OR DMAF_MASTER OR DMAF_BLITTER
  183.   c.bltcon0:=BC0F_SRCA OR BC0F_DEST OR A_TO_D
  184.   c.bltcon1:=0
  185.   c.bltafwm:=-1; c.bltalwm:=-1
  186.   c.bltamod:=0;  c.bltdmod:=0
  187.   c.bltapt:=src
  188.   c.bltdpt:=mem
  189.   c.bltsize:=$81 -> Shl(4/2,6) OR 1
  190.   WaitBlit(); DisownBlitter(); ret:=Long(mem); FreeVec(mem)
  191. ENDPROC ret
  192.  
  193. CHAR '$VER GuruLog 1.0 (31.01.98)\0'