home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archivers / SignArch / source / begin.a < prev   
Encoding:
Text File  |  1996-09-27  |  5.2 KB  |  197 lines

  1.     include    'libraries/allofit_lvo.i'
  2.     include    'dos/dos.i'
  3.  
  4. ; This source is the source for each and every '-----BEGIN' file created.
  5. ; Returns RETURN_ERROR if something went wrong or the check failed.
  6. ; Will check that there indeed IS a blank line JUST after the ----BEGIN
  7. ; line first in the sumfile.
  8. ; There is still some room for optimizing, but doing things this way keeps
  9. ; the file more readable and easier to understand
  10.  
  11. ; The Code hunk is equal from file to file, but the REXX script modifies
  12. ; the Data hunk according to the name of the sumfile. Some magic, but
  13. ; it's not difficult at all, and it works...:)
  14.  
  15. ; © 1994 Jens T. Berger Thielemann
  16. ; Distributed under the GNU General Public License.
  17. ; To contact the author:
  18. ; <jensthi@ifi.uio.no>
  19. ; or
  20. ;   Jens Berger
  21. ;   Spektrumveien 4
  22. ;   N-0666 Oslo
  23. ;   Norway
  24. ; or
  25. ; Send   a   message   in   POST   to   J.    BERGER   on  Trashcan  (A)BBS
  26. ; [(+47) 22 25 74 78 or (+47) 22 25 88 22].
  27. ; NO WARRANTIES AT ALL FOR FUNCTIONALITY OR FITNESS FOR A SPECIFIC PURPOSE
  28.  
  29. ; This will make the program more easy to read
  30.  
  31. SumName        equr    d6
  32. ErrorCode    equr    d7
  33. FileHandle    equr    d4
  34.  
  35. StackNeeded    equ    40
  36.  
  37.     SECTION    "TEXT",CODE
  38.  
  39. Begin
  40.     moveq    #RETURN_FAIL,ErrorCode    ; Our current error status
  41.     move.l    4.w,a6            ; Execbase to a6
  42.     lea    dosname(pc),a1        ; Want to open dos.library
  43.     callib    OldOpenLibrary        ; Any version OK
  44.  
  45.     tst.l    d0            ; Did we get it?
  46.     beq.w    DosLibError        ; If no, return to shell
  47.  
  48.     move.l    d0,a6            ; DOSBase to a6
  49.  
  50.     moveq    #RETURN_ERROR,ErrorCode    ; At least we've got dos...
  51.  
  52.  
  53.       ***********   Get ptr to name of sumfile    ***********
  54.  
  55.                     ; A bit tricky, but only way to
  56.     move.l    Begin-4(pc),d1        ; have more than one hunk without
  57.     add.l    d1,d1            ; reloc hunks. Relies on SegLists &
  58.     add.l    d1,d1            ; BPTR's from LoadSeg. Gives a ptr
  59.     addq.l    #4,d1            ; to the sumfile's name in d1/d6.
  60.     move.l    d1,SumName        ; Look in DOS manuals to learn
  61.                     ; more.
  62.  
  63.     move.l    #MODE_OLDFILE,d2    ; Open non-destructively
  64.     callib    Open            ; Get a filehandle to the sumfile
  65.  
  66.     move.l    d0,FileHandle        ; Store it in d4
  67.     beq.b    OpenError        ; Abort if we didn't get it
  68.  
  69.  
  70.       ***********     Read the first lines        ***********
  71.  
  72.     lea    -StackNeeded(sp),sp    ; Reserve space on stack
  73.     move.l    d0,d1            ; Filehandle to d1
  74.     move.l    sp,d2            ; Stack space reserved to d2
  75.     moveq    #36,d3            ; We'll read 36 bytes
  76.     callib    Read            ; Read'em
  77.     cmp.l    d0,d3            ; Check that we actually GOT
  78.     bne.b    ReadError        ; 36 bytes, if not: Abort
  79.  
  80.     move.l    sp,a0            ; ptr to data read in a0
  81.     lea    begtxt(pc),a1        ; data to compare with in a1
  82.  
  83.  
  84.       ***********        Compare the texts        ***********
  85.  
  86.     moveq    #begend-begtxt-1,d2    ; This is how far we'll check
  87. CmpLoop
  88.     move.b    (a0)+,d0        ; get a 'read' byte into d0
  89.     cmp.b    (a1)+,d0        ; check it with the comparison
  90.     bne.b    ChkError        ; if not equal, abort and report
  91.     dbf    d2,CmpLoop        ; error, else, continue
  92.  
  93.     moveq    #RETURN_OK,ErrorCode    ; if they were equal, status = OK
  94.     bra.b    AllOK            ; close everything
  95.  
  96.  
  97.       ***********  Print eventual error messages  ***********
  98.  
  99. OpenError
  100.     lea    ErrTxt_FileOpen(pc),a0    ; text relevant into a0
  101.     pea    CloseDosLib(pc)        ; we wish to resume here
  102.     bra.b    PrintError        ; print it...
  103. ReadError
  104.     lea    ErrTxt_FileRead(pc),a0    ; da capo!
  105.     pea    CloseFH(pc)        ; we wish to resume here
  106.     bra.b    PrintError
  107. ChkError
  108.     lea    ErrTxt_Check(pc),a0    ; da capo once more...
  109.     pea    RestoreStack(pc)    ; we wish to resume here
  110. PrintError
  111.     bsr.b    PrintTxt        ; print nullterm. text
  112.     move.l    SumName,a0        ; name of sumfile in a0
  113.     bsr.b    PrintTxt        ; print it
  114.     lea    NewLine(pc),a0        ; simple linefeed
  115.     bra.b    PrintTxt        ; note that we'll return according
  116.                     ; to the pea above
  117.  
  118. AllOK                    ; no errors during execution
  119.  
  120.  
  121.       ***********        Close everything         ***********
  122.  
  123. RestoreStack
  124.     lea    StackNeeded(sp),sp    ; restore stack
  125.  
  126. CloseFH
  127.     move.l    FileHandle,d1        ; filehandle to d1
  128.     callib    Close            ; close the sumfile
  129.  
  130. CloseDosLib
  131.     move.l    a6,a1            ; DOSBase to a1
  132.     move.l    4.w,a6            ; ExecBase to a6
  133.     callib    CloseLibrary        ; Close dos.library
  134.  
  135.  
  136. DosLibError
  137.     move.l    ErrorCode,d0        ; return status to Shell
  138.     rts                ; bye!
  139.  
  140.  
  141.       ***********       Printing Subroutine       ***********
  142.  
  143. PrintTxt
  144.     move.l    a0,d2            ; ptr to text in d2
  145.     moveq    #-1,d3            ; count number of chars
  146. PrCountLoop                ; to be printed, works for
  147.     tst.b    (a0)+            ; text < 32kB
  148.     dbeq    d3,PrCountLoop        ; loop till NULL
  149.     not.l    d3            ; not it
  150.     callib    Output            ; get output handle
  151.     move.l    d0,d1            ; put it in d1
  152.     jmp    _LVOWrite(a6)        ; write & return
  153.  
  154. ; A valid PGP clearsigned message MUST begin with the text below and TWO
  155. ; linefeeds (as here). Used to compare with above
  156.  
  157. begtxt
  158.     dc.b    '-----BEGIN PGP SIGNED MESSAGE-----',10,10
  159. begend
  160.  
  161. ; name of dos.library.
  162.  
  163. dosname
  164.     dc.b    'dos.library',0
  165.  
  166. ; Text output if we can't open the sumfile
  167.  
  168. ErrTxt_FileOpen
  169.     dc.b    "Can't open sumfile ",'"',0
  170.  
  171. ; Text output if we can't read from the sumfile
  172.  
  173. ErrTxt_FileRead
  174.     dc.b    "Can't read from sumfile ",'"',0
  175.  
  176. ; Text output if the check fails
  177.  
  178. ErrTxt_Check
  179.     dc.b    'CHECK FAILED IN SUMFILE "',0
  180.  
  181. ; As all the error messages end with a '"', to which we concatenate the
  182. ; name of the sumfile, we must end it with an '"' and a linefeed.
  183.  
  184. NewLine
  185.     dc.b    '"',10,0
  186.  
  187.  
  188.     SECTION    "NAME",DATA
  189.  
  190. ; only for testing purposes, the REXX script automagically inserts a the
  191. ; name of the currently used sumfile. The hex output in the REXX script
  192. ; is without the contents of this hunk.
  193.  
  194. Name
  195.     dc.b    "foobar.sum",0
  196.     END
  197.