home *** CD-ROM | disk | FTP | other *** search
/ BBS 1 / BBS#1.iso / maximus / bbslimit.arj / LIMITCNV.ASM < prev    next >
Assembly Source File  |  1991-05-12  |  12KB  |  531 lines

  1. .model tiny
  2. .code
  3. .startup
  4. .286
  5.  
  6. check_file struc
  7. req_name dw ?            ; pointer on end of requested name
  8. chg_name dw ?            ; pointer on end of name to change
  9. chg_size db ?            ; size of chg_name
  10. day      db ?            ; binary package for checked days
  11.                          ; all,mon,sun,sat,fri,the,wed,tue
  12. time_from dw ?           ; begin changing in BCD
  13. time_to   dw ?           ; end changing   in BCD
  14. ends
  15.  
  16.         jmp begin
  17.  
  18. days     db 'ALL'
  19.          db 'MON'
  20.          db 'SUN'
  21.          db 'SAT'
  22.          db 'FRI'
  23.          db 'THU'
  24.          db 'WED'
  25.          db 'TUE'
  26.  
  27. name_pointer dw offset filenames        ;pointer on end of current filename
  28. struct_counter dw 0      ;number of fully filled structure
  29. inc_size     dw 0        ;size of compiled filename (current)
  30. token db '[]: ',13    ;control characters
  31.  
  32. file_position dw 0       ;current position in file buffer
  33. file_segment dw 0        ;segment of loaded file
  34. file_size    dw 0        ;size of file
  35. file_name    db 'limits.ext',0 ;input  filename
  36. out_name     db 'limits.use',0 ;output filename
  37.  
  38. little_buffer db 0       ;buffer for get_token
  39. position     dw 0        ;position in current string
  40. string_number dw 0       ;current_string
  41. error_message dw 0
  42. get_token proc near
  43.         push ds
  44.         push si
  45.         lds si,dword ptr cs:file_position
  46.         cld
  47.         lodsb
  48.     mov cs:file_position,si
  49.         inc word ptr cs:position   ;next position in line
  50.         cmp si,cs:file_size             ;EOF?
  51.         ja end_of_file
  52. gt_1:
  53.         pop si
  54.         pop ds
  55.         mov little_buffer,al
  56.         ret
  57. end_of_file:
  58.         mov al,-2    ;end of file reached
  59.         jmp gt_1
  60. endp
  61. wait_for proc near
  62. ;procedure for first pass
  63. ; input al == requested token
  64. ; reading, while token comes or EOL
  65.     mov dl,al
  66. wf3:
  67.         call get_token
  68.         cmp al,-2               ;EOF?
  69.         je wf1
  70.         cmp al,dl
  71.         je token_accepted
  72.         cmp al,0dH
  73.         jne wf3
  74.         call error
  75. token_accepted:
  76.         cmp al,0dH
  77.         jne wf2
  78.         mov position,0      ;new line
  79.         inc word ptr string_number
  80.         call get_token      ;discard 0aH
  81.         mov al,0dH
  82. wf2:
  83.     clc
  84.         ret
  85. wf1:
  86.         stc
  87.         ret
  88. endp
  89.  
  90. toupper proc near
  91.         cmp al,'A'
  92.         jb do_nothing
  93.         cmp al,'z'
  94.         ja do_nothing
  95.         and al,11011111B
  96. do_nothing:
  97.         ret
  98. endp
  99.  
  100. input_while proc near
  101. ; input while requested control character comes
  102. ; al == requested ctrl-char
  103. ; ds:si == buffer to output
  104.         mov dx,ax
  105.         push cs
  106.         pop es
  107.         cld
  108. next_token:
  109.         mov di,offset token
  110.         mov cx,5                ;number of control character
  111.         call get_token
  112.         cmp dl,al               ;is this requested token?
  113.         je iw_ok
  114.         cmp dh,al
  115.         je iw_ok
  116.   repne scasb
  117.         je error_in_file
  118.         call toupper
  119.         mov ds:[si],al          ;store character in buffer
  120.         inc si
  121.         jmp next_token
  122. error_in_file:
  123.         cmp al,' '              ;is this SPACE
  124.         je next_token
  125.         cmp al,0dH
  126.         je next_token
  127.         call error
  128. iw_ok:
  129.         ret
  130. endp
  131. check_char proc near
  132.         mov si,name_pointer
  133.         mov ah,0ffH
  134.         call input_while
  135.         cmp si,name_pointer
  136.         jne cc_ok
  137.         mov error_message,offset empty_field
  138.         call error
  139. cc_ok:
  140.     ret
  141. endp
  142. check_token proc near
  143.         mov error_message,offset missing
  144.         call wait_for
  145.         jnc ct1
  146.         call error
  147. ct1:
  148.         ret
  149. endp
  150. error proc near
  151.         push cs
  152.         pop ds
  153.         mov dx,error_message
  154.         mov ah,9
  155.         int 21H
  156.         int 20h
  157. endp
  158. pass_one proc near
  159.         mov cx,2
  160. po1:
  161.         push cx
  162.         mov al,'['
  163.         call check_token
  164.         mov al,']'
  165.         call check_char
  166.         pop cx
  167.         loop po1                ;check filenames
  168.         mov al,'['
  169.         call check_token
  170.         mov al,']'
  171.         call check_char         ;check days
  172.         mov cx,2
  173. check_date:
  174.         push cx
  175.         mov al,'['
  176.         call check_token
  177.         mov al,':'
  178.         call check_char
  179.         mov al,']'
  180.         call check_char
  181.         pop cx
  182.         loop check_date
  183.         inc word ptr struct_counter
  184.         mov al,13               ;check EOL
  185.         call wait_for
  186.         jc po_ok
  187.         mov al,'['              ;pre-check
  188.     mov ah,-2
  189.         call input_while
  190.     dec word ptr cs:file_position
  191.         cmp al,-2
  192.         jne pass_one
  193. po_ok:
  194.     ret
  195. endp
  196. set_day_bits proc near
  197.         mov di,80H              ;place of day (in ASCII)
  198.         mov si,offset days
  199.         mov dl,80H
  200.         cld
  201. next_day:
  202.         push si
  203.         mov cx,3
  204.    repe cmpsb
  205.         pop si
  206.         je day_found
  207.         add si,3
  208.         mov di,80H
  209.         shr dl,1
  210.         jnc next_day
  211.         mov error_message,offset unk_day
  212.         call error
  213. day_found:
  214.         or bx[day],dl
  215.         ret
  216. endp
  217. get_hour proc near
  218.         mov error_message,offset bad_time_format
  219.         mov si,80H
  220.         cld
  221.         lodsb
  222.         sub al,30H
  223.         cmp al,2
  224.         jbe gh1
  225.         call error
  226. gh1:
  227.         mov cl,4
  228.         shl al,cl
  229.         mov ah,al
  230.         lodsb
  231.         sub al,30h
  232.         cmp al,9
  233.         jbe gh2
  234.         call error
  235. gh2:
  236.         or ah,al
  237.     cmp ah,0
  238.     jne gh3
  239.     mov ah,24H
  240. gh3:
  241.         mov byte ptr bx[time_from+1],ah
  242.         cmp ah,24H
  243.         jbe gh_ok
  244.         call error
  245. gh_ok:
  246.         ret
  247. endp
  248. get_min proc near
  249.         mov error_message,offset bad_time_format
  250.         mov si,80H
  251.         cld
  252.         lodsb
  253.         sub al,30H
  254.         cmp al,6
  255.         jbe gm1
  256.         call error
  257. gm1:
  258.         mov cl,4
  259.         shl al,cl
  260.         mov ah,al
  261.         lodsb
  262.         sub al,30h
  263.         cmp al,9
  264.         jbe gm2
  265.         call error
  266. gm2:
  267.         or ah,al
  268.         mov byte ptr bx[time_from],ah
  269.         cmp ah,60H
  270.         jb gh_ok
  271.         call error
  272. gm_ok:
  273.  
  274.         ret
  275. endp
  276. pass_two proc near
  277.         mov bx,offset headers
  278. pt_again:
  279.         mov al,'['
  280.         call check_token       ;begin 1st name
  281.         mov al,']'
  282.         call check_char
  283.         dec si
  284.         mov bx[req_name],si              ;store current pointer on fname
  285.         sub bx[req_name],offset filenames
  286.         inc si
  287.         mov ax,si
  288.         sub ax,name_pointer    ;si == size of name
  289.         mov name_pointer,si
  290.         mov bx[chg_size],al    ;store size of name
  291.  
  292.         mov al,'['
  293.         call check_token      ;begin 2nd name
  294.         mov al,']'
  295.         call check_char
  296.         mov ax,si
  297.         dec ax
  298.         mov bx[chg_name],ax   ;pointer on changing name
  299.         sub bx[chg_name],offset filenames
  300.         inc ax
  301.         sub ax,name_pointer   ;get size of 2nd filename
  302.         mov name_pointer,si   ;store new filenames pointer
  303.         cmp al,bx[chg_size]
  304.         je pt1
  305.         mov error_message,offset size_mismatch
  306.         call error
  307. pt1:                    ;first two field processed!
  308. ;*************** GET WEEK DAY *************
  309.         mov al,'['
  310.         call check_token
  311. pt3:
  312.         mov al,']'              ;read while ] or SPACE comes
  313.         mov ah,' '
  314.         mov si,80H
  315.         call input_while
  316.         push ax
  317.         call set_day_bits
  318.         pop ax
  319.         cmp al,']'              ;is it end of fields
  320.         je pt2
  321.         jmp pt3
  322.  
  323. ;************** GET TIME ******************
  324. pt2:
  325.         mov bp,2
  326. pt4:
  327.         mov al,'['
  328.         call check_token
  329.         mov al,':'
  330.         mov ah,0ffh
  331.         mov si,80H
  332.         call input_while
  333.         call get_hour
  334.         mov al,']'
  335.         mov ah,0ffH
  336.         mov si,80H
  337.         call input_while
  338.         call get_min
  339.  
  340.         add bx,2                ;next time field
  341.         dec bp
  342.         jnz pt4
  343.         sub bx,4
  344. ;check time
  345.         mov ax,bx[time_from]
  346.         cmp ah,24H
  347.         jne pt5
  348.         mov ah,0
  349. pt5:
  350.         mov error_message,offset incorrect_time
  351.     mov dx,bx[time_to]
  352.     cmp dh,24H
  353.     jne pt7
  354.     mov dh,0
  355. pt7:
  356.         cmp ax,dx
  357.         jbe pt6
  358.         call error
  359. pt6:
  360.     jne pt8
  361.     or bx[time_from],8000H
  362. pt8:
  363.         dec byte ptr struct_counter
  364.         jz pt_ok
  365.         mov al,13               ;check EOL
  366.         call wait_for
  367.         mov al,'['              ;pre-check
  368.         call input_while
  369.     dec word ptr cs:file_position
  370.  
  371.         add bx,10
  372.         jmp pt_again
  373. pt_ok:
  374.     ret
  375.  
  376. endp
  377. adjust_offset proc near
  378.         mov bx,offset headers
  379.         mov ax,struct_counter
  380.         push ax
  381.         mov cl,10
  382.         mul cl
  383.         mov dx,ax
  384.         pop cx
  385. next_struct:
  386.         add bx[req_name],dx
  387.         add bx[chg_name],dx
  388.         add bx,10
  389.         loop next_struct
  390.         ret
  391. endp
  392. write_file proc near
  393.         mov error_message,offset error_write
  394.         mov ah,3cH
  395.         mov dx,offset out_name
  396.         mov cx,20H
  397.         int 21H
  398.         jnc wrf1
  399.         call error
  400. wrf1:
  401.     mov bx,ax
  402.     mov ah,40H
  403.     mov cx,2
  404.     mov dx,offset struct_counter
  405.     int 21H
  406.     jnc wrf4
  407.     call error
  408. wrf4:
  409.         mov ax,struct_counter
  410.         mov cl,10
  411.         mul cl
  412.         mov cx,ax
  413.         mov dx,offset headers
  414.         mov ah,40H
  415.         int 21H
  416.         jnc wrf2
  417.         call error
  418. wrf2:
  419.         mov cx,name_pointer
  420.         sub cx,offset filenames
  421.         mov dx,offset filenames
  422.         mov ah,40H
  423.         int 21H
  424.         jnc wrf3
  425.         call error
  426. wrf3:
  427.         mov ah,3eH
  428.         int 21H
  429.         ret
  430. endp
  431. begin:
  432.     mov ah,9
  433.     mov dx,offset copyright
  434.     int 21H
  435.         mov error_message,offset file_not_found
  436.         mov ax,3d12H
  437.         mov dx,offset file_name
  438.         int 21H
  439.         jnc open_ok
  440.         call error
  441. open_ok:
  442.     mov bx,ax
  443.         xor cx,cx
  444.         xor dx,dx
  445.         mov ax,4202H
  446.         int 21H
  447.         jnc m1
  448.         call error
  449. m1:
  450.         mov error_message,offset file_to_big
  451.         or dx,dx
  452.         je m2
  453.         call error
  454. m2:
  455.         mov file_size,ax
  456.         mov cx,ax
  457.         mov ax,ds
  458.         add ax,1000H
  459.         mov error_message,offset not_memory
  460.         mov ds,ax
  461.         mov cs:file_segment,ax
  462.     push cx
  463.     shr cx,1
  464.     shr cx,1
  465.     shr cx,1
  466.     shr cx,1
  467.         add ax,cx       ;check_memory
  468.     pop cx
  469.         cmp ax,9fffH
  470.         jna m3
  471.         call error
  472. m3:
  473.     mov ax,4200H
  474.     xor cx,cx
  475.     xor dx,dx
  476.     int 21H
  477.     mov cx,cs:file_size
  478.         mov ah,3fH
  479.         mov dx,0
  480.         int 21H
  481.         jnc m4
  482.         call error
  483. m4:
  484.         mov ah,3eH
  485.         int 21H
  486.     push cs
  487.     pop ds
  488.     mov ah,9
  489.     mov dx,offset pass1
  490.     int 21H
  491.         call pass_one
  492.     mov ah,9
  493.     mov dx,offset ok
  494.     int 21H
  495.         mov dx,offset pass2
  496.         mov ah,9
  497.         int 21H
  498.         mov word ptr file_position,0
  499.         mov position,0
  500.         mov string_number,0
  501.         mov name_pointer,offset filenames
  502.         push word ptr struct_counter
  503.         call pass_two
  504.         mov ah,9
  505.         mov dx,offset ok
  506.         int 21h
  507.         pop ax
  508.     mov struct_counter,ax
  509.         call adjust_offset
  510.         call write_file
  511.         int 20H
  512. empty_field db 'Empty Field!',10,13,24H
  513. missing     db 'Control Character missing!',10,13,24H
  514. file_not_found db 'Input File not found!',10,13,24H
  515. file_to_big db 'File too big!',10,13,24H
  516. bad_time_format db 'BAD Time format !',10,13,24H
  517. size_mismatch db 'Size of filenames not equal!',10,13,24H
  518. not_memory  db 'Not Enough memory!',10,13,24H
  519. unk_day     db 'Unknown Day!',10,13,24H
  520. incorrect_time db 'Incorrect time setting!',10,13,24H
  521. error_write db 'Write error!',10,13,24H
  522. pass1        db 10,13,'Pass one...',24H
  523. pass2       db 'Pass two...',24H
  524. ok        db 'Ok!',10,13,24H
  525. copyright   db "Dynamical BBS's access file converter. Copyright (C) AlexQ 1991.",10,13
  526.             db '               Red Rat Club Moscow,Russia.',10,13
  527.             db '                           Free!',10,13,24H
  528. headers label word
  529.         org 10*100 + offset headers
  530. filenames label word
  531. end