home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / novprt / novprt.asm next >
Assembly Source File  |  1988-03-21  |  11KB  |  479 lines

  1.     page    75,132
  2.     title    'Perform Print Queue Access on a Novell Network'
  3.  
  4. cr    equ    0dh
  5. lf    equ    0ah
  6.  
  7. STACK    segment para stack 'STACK'
  8.     db    100 dup('stack ')
  9. STACK    ends
  10.  
  11. psp_seg segment
  12.     org    128
  13. cmd_info    db    0
  14. psp_seg ends
  15.  
  16. _DATA    segment word public 'DATA'
  17. flag        db    0
  18. first_time    equ    1
  19. prt_spec    equ    2
  20. del_flag    equ    4
  21. cmd_flag    equ    8
  22.  
  23. cmd_info_sav    db    80 dup(0)    ; save area for command line
  24.  
  25. del_data_sav    db    8 dup(0)    ; save area for job number to delete
  26.  
  27. xlate_tbl    db    '0123456789ABCDEF'
  28. htoa_area    db    5 dup(0)    ; number conversion area
  29.  
  30. ps_req        dw    (ps_req_end-$)-2
  31.         db    6        ; function = get printer status
  32. ps_num        db    0        ; printer number
  33. ps_req_end    db    0h
  34.  
  35. ps_rep        dw    (ps_rep_end-$)-2
  36. ps_halt     db    0        ; Printer Halted
  37. ps_off        db    0        ; Printer Offline
  38. ps_form     db    0        ; Printer Form Type
  39.         db    0        ; Target Printer
  40. ps_rep_end    db    0h
  41.  
  42.  
  43. pq_req        dw    (pq_req_end-$)-2
  44.         db    4        ; function = get spool queue entry
  45. pr_num        db    0        ; printer number
  46. pr_jnum     db    0        ; job number
  47. pq_req_end    db    0h
  48.  
  49. pq_rep        dw    (pq_rep_end-$)-2
  50. pq_jnum     db    0        ; job number
  51.         db    0,0        ;...unused...
  52.         db    14 dup(' ')     ; filename
  53.         db    0        ; print volume
  54.         db    0        ; print flags
  55.         db    0        ; tab size
  56.         db    0        ; printer
  57. que_copies    db    0        ; copies
  58. que_forms    db    0        ; form type
  59. que_sta     db    0        ; station
  60.         db    6 dup(' ')      ; spool time
  61. que_username    db    15 dup(' ')     ; user name
  62.         db    14 dup(' ')     ; banner name
  63.         db    18 dup(' ')     ; path name
  64.         db    4 dup(' ')      ; userid
  65. pq_rep_end    db    0h
  66.  
  67. dl_req        dw    (dl_req_end-$)-2
  68.         db    5        ; function = kill queue entry
  69. dlr_num     db    0        ; printer number
  70. dlr_jobnum    db    0        ; job number
  71. dl_req_end    db    0h
  72.  
  73. dl_rep        dw    (dl_rep_end-$)-2
  74.         db    0
  75.         db    0
  76.         db    0
  77. dl_rep_end    db    0h
  78.  
  79. running     db    7,'Running'
  80. halted        db    7,'Halted '
  81. offline     db    7,'Offline'
  82. online        db    7,'Online '
  83.  
  84.  
  85. stat_disp    db    'Printer '
  86. stat_prt_num    db    '0',' '
  87. stat_prt_halt    db    'Running  '
  88. stat_prt_off    db    'On-line ','Form='
  89. stat_prt_form    db    '--',cr,lf,'$'
  90.  
  91. que_disp    db    'Username        Sta  Forms   Copies   Job Number ',cr,lf
  92.         db    '--------------- --- ------- -------- ------------',cr,lf,'$'
  93.  
  94. prt_username    db    '               '
  95.         db    ' '
  96. prt_sta     db    '   '
  97.         db    '   '
  98. prt_forms    db    '   '
  99.         db    '      '
  100. prt_copies    db    '  '
  101.         db    '         '
  102. prt_jnum    db    '    ',cr,lf,'$'
  103. nothing1    db    '.......... Nothing in Print Queue ............',cr,lf,'$'
  104. del_failed    db    '.............. Delete Failed .................',cr,lf,'$'
  105. del_success    db    '............. Delete Successful ..............',cr,lf,'$'
  106. _DATA    ends
  107.     page
  108. _TEXT    segment para public 'CODE'
  109.     assume    cs:_TEXT,ds:_DATA,ss:STACK
  110. start    proc    far
  111.     mov    ax,_data
  112.     mov    es,ax
  113.     call    get_cmd     ; see if any command line input
  114.     test    flag,del_flag    ; was deletion specified?
  115.     jz    st_02        ; no...
  116.     call    del_job     ; do the delete first
  117. st_02:
  118.     call    get_printer_status
  119.     mov    ah,4ch        ; return to DOS
  120.     int    21h        ; *
  121. start    endp
  122.     page
  123. get_cmd proc    near
  124.     mov    cl,cmd_info
  125.     or    cl,cl
  126.     jz    get_cmd_exit
  127.     sub    ch,ch
  128.     mov    dx,cx        ; save the count
  129.     lea    di,cmd_info_Sav ; point at area to save to
  130.     lea    si,cmd_info+1    ; point at area to save from
  131.     cld            ; forward
  132.     rep    movsb        ; save the string
  133.     mov    cx,dx        ; restore the count
  134.     push    es
  135.     pop    ds
  136.     lea    si,cmd_info_Sav ; point at save area
  137. cmd_scan:
  138.     lodsb            ; get a character
  139.     cmp    al,' '          ; blank ?
  140.     je    next_cmd_char    ; yes...
  141.     test    flag,cmd_flag    ; command being processed?
  142.     jnz    chk_cmd2    ; yes...
  143.     cmp    al,'0'          ; is it less than 0?
  144.     jb    next_cmd_char    ; yes...
  145.     cmp    al,'4'          ; is it GT than 4?
  146.     ja    chk_cmd     ; yes...
  147.     test    flag,prt_spec    ; printer specified yet ?
  148.     jnz    next_cmd_char    ; yes... ignore it
  149.     or    flag,prt_spec    ; indicate printer specified
  150.     and    al,255-'0'      ; make it binary
  151.     mov    ps_num,al    ; set all request buffers for this printer
  152.     mov    pr_num,al    ; *
  153.     mov    dlr_num,al    ; *
  154.     jmp    short next_cmd_char;
  155. get_cmd_exit:
  156.     push    es
  157.     pop    ds
  158.     ret
  159. chk_cmd:
  160.     and    al,255-20h    ; force uppercase
  161.     cmp    al,'D'          ; is it a delete request ?
  162.     jne    next_cmd_char    ; no... ignore it
  163.     or    flag,del_flag    ; set deletion flag
  164.     or    flag,cmd_flag    ; set command  flag
  165.     lea    di,del_data_sav ; point at save area
  166.     jmp    short next_cmd_char;
  167. chk_cmd2:
  168.     cmp    al,' '          ; is it a space ?
  169.     jne    chk_cmd3    ; no...
  170.     and    flag,255-cmd_flag; clear command processing
  171.     jmp    short next_cmd_char
  172. chk_cmd3:
  173.     cmp    al,'0'          ; is it less than 0?
  174.     jb    next_cmd_char    ; yes...
  175.     cmp    al,'9'          ; is it GT than 9?
  176.     ja    next_cmd_char    ; yes...
  177.     stosb            ; save the value
  178. next_cmd_char:
  179.     loop    cmd_scan
  180.     and    flag,255-cmd_flag; clear command processing
  181.     test    flag,del_flag    ; was a delete specified ?
  182.     jz    get_cmd_exit    ; no...
  183.     mov    al,del_data_sav ; get a byte
  184.     or    al,al        ; insure data
  185.     jnz    get_cmd_exit    ; ok...
  186.     and    flag,255-del_flag;clear delete flag
  187.     jmp    get_cmd_exit
  188. get_cmd endp
  189.     page
  190. del_job proc    near
  191.     lea    bx,del_data_sav ; point at job number to delete
  192.     call    atoi        ; make it binary (ret in DX)
  193.     mov    dlr_jobnum,dl    ; set up the job number
  194.     mov    ax,0e000h    ; printer functions
  195.     lea    si,dl_req
  196.     lea    di,dl_rep
  197.     int    21h        ; do the delete
  198.     lea    dx,del_success
  199.     or    al,al        ; see if it worked
  200.     jz    del_job_02
  201.     lea    dx,del_failed
  202. del_job_02:
  203.     call    disp_data
  204. del_job_exit:
  205.     ret
  206. del_job endp
  207.     page
  208. get_printer_status    proc    near
  209.     mov    cx,1        ; set one iteration
  210.     test    flag,prt_spec    ; was a printer specified ?
  211.     jnz    gps_loop    ; yes...
  212.     mov    al,0
  213.     mov    ps_num,al
  214.     mov    pr_num,al
  215.     mov    cx,5
  216. gps_loop:
  217.     call    acq_printer
  218.     call    disp_printer_status
  219.     call    get_queue_info
  220.     inc    ps_num
  221.     and    flag,255-first_time
  222.     loop    gps_loop
  223.     ret
  224. acq_printer:
  225.     mov    ax,0e000h    ;
  226.     lea    si,ps_req    ; point at request buffer
  227.     lea    di,ps_rep    ; point at reply   buffer
  228.     int    21h        ; do it
  229.     ret
  230. get_printer_status    endp
  231. get_queue_info    proc    near
  232.     call    access_queue_info; get an entry
  233.     or    al,al        ; did we get it ?
  234.     jnz    no_queue    ; nope
  235.     mov    al,pq_jnum    ; get the job number
  236.     or    al,al        ; no job number means not on network
  237.     jz    no_queue    ; then exit
  238.     mov    pr_jnum,al    ; put it in the request buffer
  239.     call    disp_queue_info ; display what we've got
  240.     jmp    get_queue_info    ; loop till all done
  241. no_queue:
  242.     test    flag,first_time ; first time ?
  243.     jnz    nq_01           ; no...
  244.     lea    dx,nothing1
  245.     call    disp_data
  246. nq_01:
  247.     ret
  248. access_queue_info:
  249.     mov    ax,0e000h    ;
  250.     lea    si,pq_req    ; point at request buffer
  251.     lea    di,pq_rep    ; point at reply   buffer
  252.     int    21h        ; do it
  253.     ret
  254. get_queue_info    endp
  255.     page
  256. ;-------------------------------------------------------------------------
  257. ;    Display Printer Status
  258. ;-------------------------------------------------------------------------
  259. disp_printer_status    proc    near
  260.     push    cx
  261.     mov    al,ps_num
  262.     or    al,30h
  263.     mov    stat_prt_num,al
  264.     lea    si,running
  265.     lea    di,stat_prt_halt
  266.     mov    al,ps_halt
  267.     or    al,al
  268.     jz    dp_01
  269.     lea    si,halted
  270. dp_01:
  271.     call    set_msg     ; put the message in the field
  272.     lea    si,online
  273.     lea    di,stat_prt_off
  274.     mov    al,ps_off
  275.     or    al,al
  276.     jz    dp_02
  277.     lea    si,offline
  278. dp_02:
  279.     sub    dx,dx
  280.     mov    dl,ps_form
  281.     call    hex_to_dec
  282.     mov    ax,word ptr htoa_area+2
  283.     mov    word ptr stat_prt_form,ax
  284.  
  285.     call    set_msg     ; put the message in the field
  286.     lea    dx,stat_disp    ; point at header
  287.     call    disp_data    ; display it
  288.     pop    cx
  289.     ret
  290. set_msg:
  291.     push    cx
  292.     cld            ; insure forward direction
  293.     lodsb            ; get the length to move
  294.     cbw            ; make it a word
  295.     mov    cx,ax        ; save it
  296.     rep    movsb        ; move the field
  297.     pop    cx
  298.     ret            ; return
  299. disp_printer_status    endp
  300.     page
  301. ;-------------------------------------------------------------------------
  302. ;    Display Printer Queue Status Info
  303. ;-------------------------------------------------------------------------
  304. disp_queue_info proc    near
  305.     push    cx
  306.     test    flag,first_time ; first time ?
  307.     jnz    dqi_01        ; no...
  308.     lea    dx,que_disp    ; point at header
  309.     call    disp_data    ; display it
  310.     or    flag,first_time
  311. dqi_01:
  312.     lea    si,que_username ; move the username
  313.     lea    di,prt_username ; *
  314.     mov    cx,15        ;
  315.     rep    movsb        ;
  316.     sub    dx,dx
  317.  
  318.     mov    dl,que_sta
  319.     call    hex_to_dec
  320.     mov    ax,word ptr htoa_area+2
  321.     mov    word ptr prt_sta,ax
  322.  
  323.     mov    dl,que_forms
  324.     call    hex_to_dec
  325.     mov    ax,word ptr htoa_area+2
  326.     mov    word ptr prt_forms,ax
  327.  
  328.     mov    dl,que_copies
  329.     call    hex_to_dec
  330.     mov    ax,word ptr htoa_area+2
  331.     mov    word ptr prt_copies,ax
  332.  
  333.     mov    dl,pq_jnum
  334.     call    hex_to_dec
  335.     mov    ax,word ptr htoa_area+2
  336.     mov    word ptr prt_jnum,ax
  337.  
  338.     lea    dx,prt_username ; point at header
  339.     call    disp_data    ; display it
  340.     pop    cx
  341.     ret
  342. disp_queue_info endp
  343.  
  344. disp_data:
  345.      mov     ah,9
  346.      int     21h
  347.      ret
  348.     page
  349. ;----------------------------------------------------------------------;
  350. ;    Converts an ASCII number to binary (integer)
  351. ;
  352. ;    Entry: BX => ASCII data
  353. ;    EXIT : DX == Binary value
  354. ;
  355. ;----------------------------------------------------------------------;
  356. atoi    proc    near            ;
  357.     push    ax
  358.     push    bx
  359.     push    cx
  360.     push    si
  361.     sub    dx,dx            ; zero tally reg
  362.     mov    si,bx            ; use si as base
  363. atoi_1:                 ;
  364.     lodsb                ; get a byte
  365.     CMP    AL,' '                  ; is it a space ?
  366.     je    atoi_1            ; if so, loop
  367.                     ;
  368. atoi_2:                 ;
  369.     CMP    AL,'0'                  ; is it less than 0 ?
  370.     jb    atoi_3            ; yes... done
  371.     CMP    AL,3AH            ; is it > 9 ?
  372.     jnb    atoi_3            ; yes... done
  373.     and    AL,0fH            ; strip the sign
  374.     cbw                ; clear ax
  375.     MOV    cx,6553         ; check limit
  376.     cmp    cx,dx            ; *
  377.     jb    atoi_4            ; error....
  378.     MOV    cx,dx            ; multiply by 10
  379.     shl    dx,1            ; *
  380.     shl    dx,1            ; *
  381.     add    dx,cx            ; *
  382.     shl    dx,1            ; *
  383.     add    dx,ax            ; add in new digit
  384.     lodsb                ; get next character
  385.     jmp    short atoi_2        ; go process it
  386.  
  387. ;    Good return
  388.  
  389. atoi_3:                 ;
  390.     mov    bx,si            ; restore BX
  391.     DEC    bx            ; back up by 1
  392.     OR    AL,AL            ; set CC
  393.     jmp    short atoi_5        ; exit
  394.  
  395. ;    Error - set carry and return
  396.  
  397. atoi_4:
  398.     STC                ; set carry (error) flag
  399. atoi_5:
  400.     pop    si            ; restore regs
  401.     pop    cx            ; *
  402.     pop    bx            ; *
  403.     pop    ax            ; *
  404.     RET                ; return to caller
  405. atoi    endp
  406.     page
  407. ;------------------------------------------------------------------------
  408. ;    Convert Hex to ASCII
  409. ;
  410. ;    Input  = DX
  411. ;    Output = htoa_area
  412. ;------------------------------------------------------------------------
  413. hex_to_ascii    proc    near
  414.     push    cx
  415.     push    bx
  416.     push    di
  417.     xor    ax,ax
  418.     lea    di,htoa_area+3    ; point at end of area
  419.     std            ; we want to decrement
  420.     mov    al,dl
  421.     and    al,0fh
  422.     lea    bx,xlate_tbl
  423.     xlat    xlate_tbl
  424.     stosb
  425.     mov    al,dl
  426.     mov    cl,4
  427.     shr    al,cl
  428.     xlat    xlate_tbl
  429.     stosb
  430.     mov    al,dh
  431.     and    al,0fh
  432.     xlat    xlate_tbl
  433.     stosb
  434.     mov    al,dh
  435.     mov    cl,4
  436.     shr    al,cl
  437.     xlat    xlate_tbl
  438.     stosb
  439.     cld
  440.     pop    di
  441.     pop    bx
  442.     pop    cx
  443.     ret
  444. hex_to_ascii    endp
  445. ;------------------------------------------------------------------------
  446. ;    Convert Hex to Decimal (Max 999)
  447. ;
  448. ;    Input  = DX
  449. ;    Output = htoa_area
  450. ;------------------------------------------------------------------------
  451. hex_to_dec    proc    near
  452.     push    cx
  453.     mov    ax,3030h    ;
  454.     mov    word ptr htoa_area,ax ; zero first 2 bytes
  455.     mov    word ptr htoa_area+2,ax ; zero next  2 bytes
  456.     mov    cx,100        ; assume nothing greater than 999
  457.     call    hex_to_dec_calc ; do the 100's
  458.     mov    htoa_area+1,al    ; store the 100's
  459.     mov    cx,10        ; now do the 10's
  460.     call    hex_to_dec_calc ; do the 10's
  461.     mov    htoa_area+2,al    ; store the 10's
  462.     mov    cx,1        ; now do the units
  463.     call    hex_to_dec_calc ; do the 1's
  464.     mov    htoa_area+3,al    ; store the units
  465.     pop    cx
  466.     ret            ; return to caller
  467. hex_to_dec_calc:
  468.     mov    al,-1        ; initialize
  469. htd_loop:            ;
  470.     inc    al        ; bump counter by 1
  471.     sub    dx,cx        ; see if occurs
  472.     jnc    htd_loop    ; yes... try again
  473.     add    dx,cx        ; else add it back in
  474.     or    al,30h        ; put in the sign
  475.     ret            ; return to caller
  476. hex_to_dec    endp
  477. _TEXT    ends
  478.     end    start
  479.