home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30A / EDREC.ASM < prev    next >
Assembly Source File  |  1994-11-15  |  32KB  |  1,320 lines

  1. ;***************************** EDREC.ASM   **********************************
  2. PAGE  70,132
  3. COMMENT 
  4.                               EDREC (Edit Records)
  5.                               Version 1.0
  6.                               --------------------
  7.  
  8.  
  9.      Purpose
  10.      -------
  11.  
  12.      EDREC is both a sample program and ALIB utility program.  Files
  13.      created by EDREC use ALIB database format which is also used by
  14.      hyper message and error displays.  This greatly simplifies the
  15.      process of creating a file of error messages or help screens.
  16.  
  17.      Using EDREC
  18.      -----------
  19.  
  20.      EDREC can be started by typing EDREC or by typing EDREC followed
  21.      with a file name.  If the file exists, EDREC will display the first
  22.      record and wait for input.  If the file does not exist the record
  23.      window will be blank.
  24.  
  25.      The data entered using EDREC is probably going to be displayed in
  26.      a window someday, so the window size should be selected to make
  27.      data entry easier.  The record window size is set by the "Config"
  28.      menu option.
  29.  
  30.      After setting the window size, select "Edit" to add or modify
  31.      records.
  32.      
  33.      Database Format
  34.      ---------------
  35.  
  36.      EDREC creates records in a window which can be configured to any size.
  37.      Each record is variable length and terminated by a null (hex 00 char).
  38.  
  39.      Compiling
  40.      ---------
  41.  
  42.      The MASM & LINK commands needed to build EDREC.EXE are:
  43.         masm edrec;
  44.         link edrec,edrec,,alib.lib;
  45.  
  46.      
  47. 
  48.  
  49.     include    mac.inc
  50.     include    common.inc
  51. ;-----------------------------------------------------------------------------
  52.     extrn    library_setup:far
  53.     extrn    lib_error_handler1:far
  54.     extrn    error_handler1:far
  55.     extrn    clear_screen:far
  56.     extrn    display_string:far
  57.     extrn    display_string_fill:far
  58.     extrn    put_crt_blk:far
  59.     extrn    repeat_put_crt:far
  60.     extrn    BREAK_KEY_INTERCEPT:far
  61.     extrn    change_path:far
  62.     extrn    MENU_SYSTEM:far
  63.     extrn    change_setup:far
  64.     extrn    restore_path:far
  65.     extrn    find_home_path:far
  66.     extrn    library_terminate:far
  67.     extrn    BREAK_KEY_RESTORE:far
  68.     extrn    parse_first:far
  69.     extrn    expand_filename:far
  70.     extrn    get_string:far
  71.     extrn    qget_string:far
  72.     extrn    DEC_STR_TO_WORD:far
  73.     extrn    WORD_TO_DEC_CRT:far
  74.     extrn    get_setup:far
  75.     extrn    save_window:far
  76.     extrn    restore_window:far
  77.     extrn    draw_box:far
  78.     extrn    box_shrink:far
  79.     extrn    window_string:far
  80.     extrn    yes_or_no:far
  81.     extrn    flush_keyboard:far
  82.     extrn    set_lib_colors:far
  83.     extrn    dbase_init:far
  84.     extrn    DBASE_READ:far
  85.     extrn    dbase_read_next:far
  86.     extrn    dbase_read_prev:far
  87.     extrn    dbase_append:far
  88.     extrn    dbase_replace:far
  89.     extrn    dbase_insert:far
  90.     extrn    DBASE_REMOVE:far
  91.     extrn    dbase_close:far    
  92.     extrn    window_edit:far
  93.     extrn    window_cstring:far
  94.     extrn    strlen3:far
  95.     extrn    to_upper:far
  96.     extrn    message:far
  97. ;------------------------------------------------------------------------------
  98. code        segment para public 'CODE'
  99.         assume    cs:code, ds:code
  100. ;-----------------------------------------------------------------------------
  101. edit1_msg    db    ' Current Record #',0
  102. edit3_msg    db    '(alt-H) for help ',0
  103. append_msg    db    'append',0 
  104. insert_msg    db    'insert',0
  105. modify_msg    db    'modify',0
  106. exit_msg    db    'EDREC exiting, do you wish to save the changes in memory? (Y/n)',0
  107. pspseg        dw    0
  108. lib_info_ptr    dw    0
  109. lib_info_seg    dw    0
  110.  
  111. current_operation    db    0    ;0=none 1=append 2=insert 3=replace
  112. current_record        dw    1
  113. current_record_ptr    dw    0
  114. current_Record_len    dw    0
  115. null_file_flag        db    0    ;0=file empty
  116.  
  117. file_asciiz        db    40 dup (0)
  118.  
  119. box_size        label    word
  120. box_cols        db    50    ;columns
  121. box_rows        db    5    ;rows
  122.  
  123. box_location        label    word
  124.             db    14    ;column
  125.             db    5    ;row
  126.  
  127. dirty_flag        db    0    ;1=changes have been made
  128. saved_flag        db    0    ;1=file has been saved
  129.  
  130. buffer_size    equ    1000        ;largest record size
  131. buffer            db    buffer_size dup (0)
  132. buffer_ptr        dw    buffer
  133. cursor_position        dw    0
  134.  
  135. file_create_flag    db    0    ;1=create is needed
  136. string1            db    3 dup (0)
  137. string2            db    3 dup (0)
  138.  
  139. help_asciiz        db    'EDREC.HLP',0
  140.  
  141. null_file_msg        db    'The database does not contain any records'
  142.             db    ' select the EDIT and APPEND options to add'
  143.             db    ' records, or CONFIG option to change setup.'
  144.             db    0dh,0ah,0dh,0ah,'Press any key to continue',0
  145. bad_rec_msg        db    'This record does not exist in the database'
  146.             db    '.  The APPEND function must be used to add'
  147.             db    ' records.',0dh,0ah,0dh,0ah
  148.             db    'Press any key to continue',0
  149. not_yet_msg        db    'This feature not implemented at present.  '
  150.             db    ' Press any key to continue',0
  151. ;-----------------------------------------------------------------------------
  152. start:
  153.     cli
  154.     mov    cs:pspseg,es    ;save PSP segment
  155.     mov    ax,cs        ;get CODE segment
  156.     mov    ss,ax
  157.     mov    ds,ax
  158.     mov    es,ax
  159.     mov    sp,offset stack_
  160.     sti
  161.     
  162. ; next, release memory beyond the end of the program
  163. ; The  definition for ZSEG marks the
  164. ; end of the program's code, data and stack area.
  165. ; When linking be sure ZSEG is at the end of the program.
  166.  
  167.     mov    ax,zseg
  168.  
  169.     mov    bx,cs:pspseg        ;
  170.     mov    es,bx
  171.     sub    bx,ax
  172.     neg    bx            ; size of program in paragraphs
  173.     mov    ah,4Ah            ; resize memory block
  174.     int    21h
  175.  
  176.     mov    ax,cs
  177.     mov    es,ax
  178. ;
  179. ; check if enough memory free to run program
  180. ;
  181.     mov    ax,pspseg        ;pass psp segment to setup
  182.     mov    bx,0            ;number of floating point variables
  183.     call    library_setup
  184.     mov    lib_info_ptr,si        ;save ptr to library info block
  185.     mov    lib_info_seg,es         ; see COMMON.INC or LIBRARY_SETUP
  186.     cmp    ax,128
  187.     jae    got_enough_mem        ;jmp if 128k of memory avail
  188.     mov    al,7
  189.     mov    ah,fatal_return
  190.     call    lib_error_handler1
  191.     jmp    exitx
  192.     
  193. got_enough_mem:
  194. ;
  195. ; clear the screen and display signon
  196. ;
  197.     mov    ah,app_text_color
  198.     mov    al,' '
  199.     call    clear_screen
  200. ;
  201. ; display copyright message
  202. ;
  203.     mov    si,offset copyright_msg
  204.     mov    ah,app_text_color
  205.     mov    dx,1008h        ;display row 16 column xx
  206.     call    display_string    
  207.     
  208.     
  209. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  210. ; Ctrl+Alt+Del key combinations
  211.  
  212. ;    call    BREAK_KEY_INTERCEPT
  213.  
  214. ;
  215. ; switch to home directory
  216. ;
  217.     push    es
  218.     call    find_home_path
  219.     mov    bx,di
  220.     call    change_path
  221.     pop    es
  222.     jnc    path_changed
  223.     mov    al,6
  224.     mov    ah,fatal_return
  225.     call    lib_error_handler1
  226.     jmp    exit2
  227. path_changed:
  228.     call    read_setup
  229.     call    establish_defaults    ;set colors & see if config file avail
  230.     call    ck_for_filename
  231. ;
  232. ; read the file (initialize the database)
  233. ;
  234. init_database:
  235.     mov    dx,offset file_asciiz
  236.     call    dbase_init
  237.     mov    es,bx            ;move selector to es:
  238. ;
  239. ; if file does not exist, then ask if create ok
  240. ;
  241.     cmp    al,1            ;check if file opened ok
  242.     jbe    clear_and_display
  243.     jmp    exit            ;jmp if error opening file
  244. ;
  245. ; clear the screen and display the box
  246. ;
  247. clear_and_display:
  248.     mov    ah,_msg_text_color
  249.     mov    al,' '
  250.     call    clear_screen
  251.     mov    dx,box_location
  252.     mov    bx,box_size
  253.     mov    ah,_msg_text_color
  254.     mov    al,0            ;single line frame
  255.     call    draw_box
  256. ;
  257. ; fill box with record info.
  258. ;
  259.     mov    dx,current_record
  260.     call    DBASE_READ
  261.     cmp    al,0
  262.     je    show_rec        ;jmp if record found
  263.     cmp    dx,1            ;check if this is record 1
  264.     jne    show_rec        ;jmp if database has records
  265. ;
  266. ; current database is empty
  267. ;
  268. null_file:
  269.     mov    si,offset null_file_msg
  270. bad_rec_number:    
  271.     apush    ds,es
  272.     mov    ax,cs
  273.     mov    ds,ax
  274.     mov    es,ax
  275.     mov    ah,cs:_msg_text_color
  276.     mov    al,0
  277.     mov    bx,0840h
  278.     mov    dx,0808h
  279.     mov    cx,1
  280.     mov    bp,msg_save_win+msg_restore_win+msg_anykey+msg_disp+msg_ram
  281.     call    message
  282.     apop    es,ds        
  283.     jmp    menu1            ;jmp if empty database
  284. ;
  285. ; this record is not present in the data base, ask for instructions
  286. ;
  287.  
  288. ;
  289. ; fill the box with current record contents
  290. ;   es:si point at data for display
  291. ;      cx = record length
  292. ;
  293. show_rec:
  294.     mov    null_file_flag,1    ;specify database has data
  295.     call    move_to_buffer
  296. ;
  297. ; setup to display buffer
  298. ;
  299. display_buffer:        
  300.     mov    bx,box_size
  301.     mov    dx,box_location
  302.     call    box_shrink
  303.     mov    ah,_msg_text_color    
  304.     mov    si,offset buffer
  305.     push    di
  306.     mov    di,0
  307.     call    window_cstring
  308.     pop    di
  309. ;
  310. ; display status line with record#
  311. ;
  312.     call    show_rec_status
  313. ;
  314. ; show menu bar and wait for selection
  315. ;
  316. menu1:    mov    bx,offset menu1_def
  317.     mov    ah,08h+20h        ;restore bar & return unknown keys
  318.     call    MENU_SYSTEM
  319.     cmp    cl,1            ;check if process key
  320.     jne    menu1_d2        ;jmp if not process hit
  321.     jmp    ax
  322.     jmp    menu1            ;go do it again
  323. menu1_d2:
  324.     cmp    cl,4            ;check if abort key
  325.     je    quit_j
  326.     cmp    cl,2
  327.     jne    menu1            ;jmp if unknown mouse or no key press
  328.     cmp    al,51h
  329.     je    pgdn_j
  330.     cmp    al,49h
  331.     je    pgup_j
  332.     jmp    menu1
  333.     
  334. quit_j:    jmp    quit    
  335. pgdn_j:    jmp    pgdn
  336. pgup_j:    jmp    pgup    
  337. ;---------------------------------------------------------------------------
  338. ; top level menu executables
  339. ;---------------------------------------------------------------------------
  340. edit_append:
  341.     mov    current_record,0
  342.     mov    current_operation,1        ;set append flag
  343.     call    clear_buffer
  344.     call    show_rec_status            ;show new append state
  345.     call    buffer_edit
  346.     push    ax
  347.     call    append_record
  348.     mov    current_operation,0
  349.     pop    ax
  350.     jc    edrec_errorj
  351.     mov    null_file_flag,1
  352.     jmp    display_buffer
  353. ;----------------------------
  354. edrec_errorj:
  355.     jmp    edrec_error
  356. ;----------------------------        
  357. edit_insert:
  358.     cmp    null_file_flag,0
  359.     je    null_filek            ;jmp if database empty
  360.     call    clear_buffer
  361.     mov    current_operation,2        ;set insert code
  362.     call    show_rec_status
  363.     call    buffer_edit
  364.     push    ax
  365.     call    insert_record
  366.     mov    current_operation,0
  367.     pop    ax
  368.     jc    clear_and_displayj
  369.     jmp    display_buffer
  370.  
  371. clear_and_displayj:
  372.     jmp    clear_and_display
  373.     
  374. get_rec_msg    db    'What record# do you want to view/edit?',0
  375. new_rec        dw    0
  376.     
  377. edit_selected:
  378.     cmp    null_file_flag,0
  379.     je    null_filek            ;jmp if database empty
  380.     call    get_rec
  381.     jc    es_abort    
  382.     mov    current_operation,3            
  383.     mov    dx,new_rec
  384.     call    fill_buffer
  385.     jnc    es_cont
  386. es_bad:    mov    si,offset bad_rec_msg
  387.     jmp    bad_rec_number
  388. es_cont:call    show_rec_status
  389.     call    buffer_edit
  390.     push    ax
  391.     call    replace_record
  392.     mov    current_operation,0
  393.     pop    ax
  394.     jmp    ed_common
  395. es_abort:    
  396.     jmp    display_buffer
  397. ;--------------------------
  398. null_filek:
  399.     jmp    null_file
  400. edrec_error:
  401.     jmp    exit
  402. ;--------------------------    
  403. edit_displayed:
  404.     cmp    null_file_flag,0
  405.     je    null_filek            ;jmp if database empty
  406.     mov    current_operation,3
  407.     call    show_rec_status
  408.     call    buffer_edit
  409.     push    ax
  410.     call    replace_record
  411.     mov    current_operation,0
  412.     pop    ax
  413.     
  414. ed_common:
  415.     jc    edrec_error
  416.     cmp    ax,0151h            ;check for pgdn
  417.     je    ed_pgdn
  418.     cmp    ax,0149h
  419.     jne    ed_exit
  420. ed_pgup:
  421.     mov    di,offset buffer
  422.     call    dbase_read_prev
  423.     jmp    ed_c
  424. ;-
  425. ed_pgdn:
  426.     mov    di,offset buffer
  427.     call    dbase_read_next
  428. ed_c:    cmp    al,0
  429.     jne    edit_displayed
  430. ed_d:    call    move_to_buffer
  431.     jmp    edit_displayed
  432. ed_exit:
  433.     jmp    display_buffer
  434. ;--------------------------
  435. find_record:
  436.     cmp    null_file_flag,0
  437.     je    null_filej            ;jmp if database empty
  438.     call    get_rec
  439.     jc    fr_abort    
  440.     mov    current_operation,0            
  441.     mov    dx,new_rec
  442.     call    fill_buffer
  443.     jnc    fr_abort
  444.     jmp    es_bad                ;jmp if record not found
  445. fr_abort:    
  446.     jmp    display_buffer
  447. ;-----------
  448. find_next:
  449.     jmp    pgdn
  450. find_prev:
  451.     jmp    pgup
  452. find_text:
  453.     call    not_yet
  454.     jmp    menu1
  455. ;--------------------------
  456. delete_record:
  457.     cmp    null_file_flag,0
  458.     je    null_filej            ;jmp if database empty
  459.     call    get_rec
  460.     jc    ed_exit                ;jmp if no record# entered
  461.     mov    dx,new_rec
  462.     jmp    delete_cont
  463. ;--------------------------------
  464. delete_displayed:
  465.     cmp    null_file_flag,0
  466.     je    null_filej            ;jmp if database empty
  467.     mov    dx,current_record
  468. delete_cont:
  469.     call    DBASE_REMOVE
  470.     mov    cs:dirty_flag,1
  471.     mov    dx,current_record
  472.     call    dbase_read
  473.     jnc    delete_cont2            ;jmp if record found
  474. ;
  475. ; check if deleted record was at end of the database and no records follow
  476. ;
  477.     dec    dx
  478.     call    dbase_read
  479.     jnc    delete_cont2            ;jmp if record found
  480.     mov    null_file_flag,1
  481.     jmp    clear_and_display
  482. delete_cont2:
  483.     call    fill_buffer
  484.     jmp    display_buffer
  485.  
  486. null_filej:
  487.     jmp    null_file        
  488. ;--------------------------
  489. move_record:
  490.     call    not_yet
  491.     jmp    menu1
  492. ;--------------------------
  493. help:    apush    ax,bx,cx,dx,si,di,bp,ds,es
  494.     mov    ax,cs
  495.     mov    ds,ax
  496.     mov    es,ax
  497.     mov    ah,cs:_msg_text_color
  498.     mov    al,0
  499.     mov    bx,1040h
  500.     mov    dx,0404h
  501.     mov    cx,1
  502.     mov    si,offset help_asciiz
  503.     mov    bp,msg_save_win+msg_restore_win+msg_hyper+msg_close+msg_open+msg_disp
  504.     call    message
  505.     apop    es,ds,bp,di,si,dx,cx,bx,ax
  506.     jmp    menu1
  507. ;--------------------------
  508. pgup:
  509.     cmp    null_file_flag,0
  510.     je    null_filej            ;jmp if database empty
  511.     mov    di,offset buffer
  512.     call    dbase_read_prev
  513.     cmp    al,0
  514.     jne    menu1_j
  515.     call    move_to_buffer
  516.     jmp    display_buffer
  517. ;--------------------------
  518. pgdn:
  519.     cmp    null_file_flag,0
  520.     je    null_filej            ;jmp if database empty
  521.     mov    di,offset buffer
  522.     call    dbase_read_next
  523.     cmp    al,0
  524.     jne    menu1_j
  525.     call    move_to_buffer
  526.     jmp    display_buffer
  527.  
  528. menu1_j:jmp    menu1
  529. ;--------------------------
  530.  
  531. ; setup - main menu entry to change the program configuration
  532. ;
  533. SETUP:    push    es
  534.     push    ds
  535.     pop    es
  536.     call    change_setup
  537.     call    establish_defaults
  538.     pop    es
  539.     jmp    clear_and_display
  540. ;--------------------------
  541. quit:    cmp    cs:dirty_flag,0        ;check if any changes make
  542.     je    exit            ; jmp if no changes make
  543. ;
  544. ; ask user if edits are to be saved or discarded
  545. ;    
  546.     mov    bh,4            ;rows in message
  547.     mov    bl,40            ;columns in message
  548.     mov    dx,0814h        ;message window location
  549.     mov    si,offset exit_msg    ;message text
  550.     mov    bp,msg_yesno+msg_disp+msg_ram
  551.     call    message            ;display message & wait for yes/no
  552.     cmp    al,'N'
  553.     je    exit            ;jmp if discarding changes
  554.     call    dbase_close
  555.     
  556. exit:
  557.     call    restore_path
  558.     jnc    exit2            ;jmp if no error
  559.     mov    al,6
  560.     mov    ah,fatal_return
  561.     call    lib_error_handler1
  562. exit2:    
  563. ;
  564. ; de-activate the Ctrl+Break trap
  565. ;    call    BREAK_KEY_RESTORE
  566.  
  567. ; normal program exit
  568.  
  569. exitx:    mov    ax,0
  570.     call    library_terminate
  571.     mov    ax,4C00h
  572.     int    21h
  573. ;
  574. ;---------------------------------------------------------------------------
  575. ;----------------------- local subroutines ---------------------------------
  576. ;---------------------------------------------------------------------------
  577. ; get_rec - ask user for record #
  578. ;   inputs: none
  579. ;   output: carry set if error
  580. ;
  581. get_rec:    
  582.     call    clear_string1
  583.     mov    si,offset get_rec_msg
  584.     mov    dx,1801h
  585.     mov    ah,_pick_color
  586.     mov    cx,79
  587.     call    display_string_fill
  588.     mov    dx,1830h
  589.     mov    cl,5
  590.     mov    di,offset string1
  591.     push    es
  592.     push    ds
  593.     pop    es
  594.     call    qget_string
  595.     pop    es
  596.     cmp    cx,-1
  597.     je    gr_abort            ;jmp if no string entered
  598.     jcxz    gr_abort
  599.     mov    si,offset string1
  600.     call    DEC_STR_TO_WORD
  601.     mov    new_rec,ax
  602.     jmp    gr_exit
  603. gr_abort:
  604.     stc
  605. gr_exit:        
  606.     ret
  607.     
  608. ; show_rec_status - display status for displayed record
  609. ;   inputs: none
  610. ;   outputs: none
  611. ;
  612. show_rec_status:
  613.     mov    si,offset edit1_msg
  614.     mov    dx,1800h        ;row 24 column 1
  615.     mov    ah,_bar_text_color
  616.     mov    cx,80            ;max display rows
  617.     call    display_string_fill
  618.  
  619.     mov    di,2*17+24*160            ;display offset
  620.     mov    ch,_bar_text_color
  621.     mov    ax,current_record
  622.     cmp    current_operation,1
  623.     je    srs_append            ;jmp if this is an append
  624.     cmp    current_operation,2
  625.     je    srs_insert
  626.     call    WORD_TO_DEC_CRT
  627.     jmp    srs_cont1
  628.  
  629. srs_append:
  630.     mov    dx,1811h
  631.     mov    si,offset append_msg
  632.     mov    ah,ch
  633.     call    display_string
  634.     jmp    srs_cont1
  635. srs_insert:        
  636.     mov    dx,1811h
  637.     mov    si,offset insert_msg
  638.     mov    ah,ch
  639.     call    display_string
  640. srs_cont1:
  641. ;
  642. ; clear the top line
  643. ;
  644.     mov    al,' '                ;char to clear with
  645.     mov    dx,0                ;display address
  646.     mov    cx,80                ;display width
  647.     call    repeat_put_crt
  648.     ret
  649. ;---------------------------------------------------------------------------
  650. ; clear_buffer - clear the buffer for editing
  651. ;   inputs: none
  652. ;   output: none
  653. ;
  654. clear_buffer:
  655.     push    es
  656.     mov    ax,ds
  657.     mov    es,ax
  658.     mov    buffer_ptr,offset buffer
  659.     mov    current_record_len,0
  660.     mov    cx,buffer_size
  661.     mov    di,offset buffer
  662.     cld
  663.     mov    al,0
  664.     rep    stosb
  665.     pop    es
  666.     ret
  667. ;---------------------------------------------------------------------------
  668. ; fill_buffer - move the record in dx,ah to buffer
  669. ;   inputs:  dx = record #
  670. ;  output:  dx = record#
  671. ;           cx = record length
  672. ;
  673. fill_buffer:
  674. ;
  675. ; this record is not the current record, call database
  676. ;
  677. fb_read:    call    DBASE_READ
  678.         jnc    move_to_buffer        ;jmp if read successful
  679.         mov    dx,current_record
  680.         jmp    fb_exit
  681. ;
  682. ; entry point follows, called as subroutine following calls to DBASE_READ,
  683. ;  dbase_read_prev, dbase_read_next
  684. ;
  685. move_to_buffer:
  686.         mov    current_record,dx
  687.         mov    current_record_len,cx
  688.         mov    current_record_ptr,si
  689. fb_fill:    apush    ds,es
  690.         apop    ds,es
  691.         mov    di,offset buffer
  692.         rep    movsb            ;move record to buffer
  693.         mov    byte ptr es:[di],0    ;put zero at end
  694.         apush    ds,es
  695.         apop    ds,es
  696. fb_exit:
  697.         mov    cx,current_record_len
  698.         ret
  699. ;---------------------------------------------------------------------------
  700. ; buffer_edit - edit the current buffer contents
  701. ;   inputs: buffer and database
  702. ;   output: ax=last key press
  703. ;
  704. edit_flag    db    0
  705.  
  706. buffer_edit:
  707.     mov    cs:edit_flag,0            ;not changes to this record yet
  708.     mov    si,offset buffer
  709.     mov    di,buffer_ptr
  710.     mov    bx,box_size
  711.     mov    dx,box_location
  712.     mov    cx,buffer_size
  713.     call    window_edit
  714.     jnc    be_exit
  715.     mov    cs:dirty_flag,1            ;the file was changed
  716.     mov    cs:edit_flag,1            ;the buffer was changed.
  717. be_exit:        
  718.     ret
  719. ;---------------------------------------------------------------------------
  720. ; append_record  -  append record to database
  721. ;
  722. append_record:
  723.     mov    bx,offset buffer
  724.     call    strlen3
  725.     mov    di,offset buffer
  726.     call    dbase_append
  727.     mov    current_record,dx
  728.     ret
  729. ;---------------------------------------------------------------------------
  730. ; replace_record  -  replace current record in database
  731. ;   inputs:  none
  732. ;   output:
  733. ;            dx = record #
  734. ;
  735. replace_record:
  736.     cmp    cs:edit_flag,0
  737.     je    rr_exit              ;jump if no changes make
  738.     mov    bx,offset buffer
  739.     call    strlen3
  740.     mov    di,offset buffer
  741.     mov    dx,current_record
  742.     call    dbase_replace
  743.     mov    current_record,dx
  744. rr_exit:ret
  745. ;---------------------------------------------------------------------------
  746. ; insert_record  -  insert before current record in database
  747. ;
  748. insert_record:
  749.     mov    bx,offset buffer
  750.     call    strlen3
  751.     mov    di,offset buffer
  752.     mov    dx,current_record
  753.     call    dbase_insert
  754.     mov    current_record,dx
  755.     ret
  756. ;---------------------------------------------------------------------------
  757. ; clear_string1 - clear input buffer
  758. ;  inputs: none
  759. ;  oputput: none
  760. ;
  761. clear_string1:
  762.     apush    ax,cx,di,es
  763.     mov    ax,ds
  764.     mov    es,ax
  765.     mov    di,offset string1
  766.     cld
  767.     mov    al,0
  768.     mov    cx,8
  769.     rep    stosb
  770.     apop    es,di,cx,ax
  771.     ret
  772. ;---------------------------------------------------------------------------
  773. ; ck_for_filename - get preliminary information from user
  774. ;   inputs:     none
  775. ;   outputs:    carry = aborting, insufficient info.
  776. ;            no carry = all questions answered ok
  777. ;
  778. ck_for_filename:
  779.     mov    ax,cs
  780.     mov    es,ax
  781.     mov    di,offset file_asciiz
  782.     call    parse_first
  783.     cmp    bh,0
  784.     je    aq_no_file         ;jmp if file not found
  785. aq_test_file:
  786.     mov    si,offset file_asciiz
  787.     call    expand_filename
  788.     jnc    aq_exit        ;jmp if file ok
  789.     jmp    aq_ask_create
  790. ;
  791. ; the filename was not specified on the command line, ask user for it
  792. ;
  793. aq_no_file:
  794.     mov    si,offset aq_msg2
  795.     mov    dx,0408h        ;row 4 column 8
  796.     mov    ah,_pick_color
  797.     call    display_string
  798.     call    flush_keyboard        ;clear out any keys
  799.     mov    dx,0432h
  800.     mov    cl,12
  801.     mov    di,offset file_asciiz
  802.     call    qget_string
  803.     jmp    aq_test_file
  804. ;
  805. ; specified file was not found, create or abort?
  806. ;
  807. aq_ask_create:
  808.     mov    si,offset aq_msg1
  809.     mov    dx,0308h        ;row 3 column 8
  810.     mov    ah,_pick_color
  811.     call    display_string        ;say file was not found
  812.     call    yes_or_no        ;ask if file create
  813.     cmp    al,'Y'
  814.     je    aq_create        ;jmp if file create
  815.     stc
  816.     jmp    aq_exit            ;abort    
  817. ;
  818. ; create a new file
  819. ;
  820. aq_create:
  821.     mov    file_create_flag,1
  822. aq_exit:
  823.     ret
  824. ;---------------------------------------------------------------------------
  825. aq_msg1    db 'The specified file was not found, do you want to create file? (Y/N)',0
  826. aq_msg2    db 'Enter edit file name ',0
  827. ;--------------------------------------------------------------------------
  828. ; read_setup - read setup block from disk if avail.
  829.  
  830. read_setup:
  831.     les    bx,dword ptr lib_info_ptr    ;get library info structure
  832.     cmp    es:[bx.mono_flag],0        ;check if mono display
  833.     jne    mono_setup
  834. ;
  835. ; set color attributes as default
  836. ;
  837.     mov    si,offset color_defaults
  838.     jmp    move_colors
  839. mono_setup:
  840.     mov    si,offset mono_defaults
  841. move_colors:
  842.     lodsb
  843.     mov    _bar_text_color,al
  844.     lodsb
  845.     mov    _bar_select_color,al
  846.     lodsb
  847.     mov    _bar_hotkey_color,al
  848.     lodsb
  849.     mov    _submenu_text_color,al
  850.     lodsb
  851.     mov    _submenu_select_color,al
  852.     lodsb
  853.     mov    _msg_text_color,al            
  854.     lodsb
  855.     mov    _msg_hyper_color,al
  856.     lodsb
  857.     mov    _pick_color,al
  858.     lodsb
  859.     mov    _pick_select_color,al
  860. ;
  861. ; get setup block from disk if present, if not then write defaults to disk
  862. ;    
  863.     mov    si,offset setup_block
  864.     call    get_setup
  865.     cmp    al,0            ;check if setup ok
  866.     je    setup_ok
  867.     
  868.     mov    al,2
  869.     mov    ah,fatal_return
  870.     call    lib_error_handler1
  871.  
  872. setup_ok:        
  873.  
  874.     ret
  875. ;--------------------------------------------------------------------------
  876. ; establish_defaults - compute setup info.
  877. ;
  878. establish_defaults:
  879.     push    cs
  880.     pop    ds
  881. ;
  882. ; set the display box size
  883. ;
  884.     mov    al,xbox_l
  885.     mov    cs:box_rows,al
  886.  
  887.     mov    al,xbox_w
  888.     mov    cs:box_cols,al
  889. ;
  890. ; center the box on the screen
  891. ;
  892.     push    es
  893.     les    si,dword ptr ds:lib_info_ptr
  894.     
  895.     sub    ax,ax
  896.     mov    al,es:[si].crt_rows
  897.     sub    al,byte ptr ds:box_size+1    ;compute free rows
  898.     shr    al,1
  899.     mov    byte ptr ds:box_location+1,al    ;store starting row
  900.  
  901.     mov    al,es:[si].crt_columns
  902.     sub    al,byte ptr ds:box_size        ;compute free rows
  903.     shr    al,1
  904.     mov    byte ptr ds:box_location,al
  905.     pop    es
  906.         
  907.     ret
  908.  
  909. ;---------------------------------------------------------------------------
  910. ; not_yet - display feature not available message
  911. ;
  912. not_yet:
  913.          apush    ax,bx,cx,dx,si,di,bp,ds,es
  914.     mov    ax,cs
  915.     mov    ds,ax
  916.     mov    es,ax
  917.     mov    ah,cs:_msg_text_color
  918.     mov    al,0
  919.     mov    bx,0840h
  920.     mov    dx,0808h
  921.     mov    si,offset not_yet_msg
  922.     mov    bp,msg_save_win+msg_restore_win+msg_anykey+msg_ram+msg_disp
  923.     call    message
  924.     apop    es,ds,bp,di,si,dx,cx,bx,ax
  925.  
  926.     ret
  927. ;---------------------------------------------------------------------------
  928.  
  929. stacksize    equ    1024
  930.     db    stacksize dup (0)
  931. stack_    label    word
  932. ;
  933. copyright_msg    label    byte
  934.  db 'Edit      Record',0dh,0ah
  935.  db '███████   █████▄     ████████   ████████   ████████',0dh,0ah
  936.  db '██        ██   ▀██   ██    ██   ██         ██      ',0dh,0ah
  937.  db '██        ██    ██   ██    ██   ██         ██      ',0dh,0ah
  938.  db '███████   ██    ██   ████████   ████████   ██      ',0dh,0ah
  939.  db '██        ██    ██   ████       ██         ██      ',0dh,0ah
  940.  db '██        ██   ▄██   ██ ███     ██         ██      ',0dh,0ah
  941.  db '███████   █████▀     ██   ███   ████████   ████████',0dh,0ah
  942.  db 'Copyright 1994 Owens Consulting',0dh,0ah
  943.  db 0
  944.  
  945.  
  946. menu1_def    label    byte
  947.     db    0            ;m_flag
  948.     db    0            ;top row
  949.     db    0            ;left column
  950.     db    1            ;total rows
  951.     db    80            ;total columns
  952.     db    7            ;menu options
  953.     dw    0            ;main selection
  954.     dw    0            ;sub selection
  955. ; main option #0 -EDIT-
  956.     db    4            ;e_count
  957.     db    16            ;e_sub_length
  958.     db    18            ;e_hot_key (alt-e)
  959.     db    4            ;e_length
  960.     dw    main_opt0_text        ;e_text_ptr
  961.     dw    sub0_struc        ;e_process
  962.     db    1            ;e_column
  963.     db    0            ;e_row
  964. ; main option #1 -FIND-
  965.     db    4            ;e_count
  966.     db    12            ;e_sub_length
  967.     db    33            ;e_hot_key (alt-f)
  968.     db    4            ;e_length
  969.     dw    main_opt1_text        ;e_text_ptr
  970.     dw    sub1_struc        ;e_process
  971.     db    7            ;e_column
  972.     db    0            ;e_row
  973. ; main option #2 -DELETE-
  974.     db    2            ;e_count
  975.     db    15            ;e_sub_length
  976.     db    32            ;e_hot_key (alt-d)
  977.     db    6            ;e_length
  978.     dw    main_opt2_text        ;e_text_ptr
  979.     dw    sub2_struc           ;e_process
  980.     db    13            ;e_column
  981.     db    0            ;e_row
  982. ; main option #3 -MOVE-
  983.     db    0            ;e_count
  984.     db    0            ;e_sub_length
  985.     db    50            ;e_hot_key (alt-m)
  986.     db    4            ;e_length
  987.     dw    main_opt3_text        ;e_text_ptr
  988.     dw    MOVE_RECORD        ;e_process
  989.     db    21            ;e_column
  990.     db    0            ;e_row
  991. ; main option #4 -CONFIG-
  992.     db    0            ;e_count
  993.     db    0            ;e_sub_length
  994.     db    46            ;e_hot_key (alt-c)
  995.     db    6            ;e_length
  996.     dw    main_opt4_text        ;e_text_ptr
  997.     dw    SETUP              ;e_process
  998.     db    27            ;e_column
  999.     db    0            ;e_row
  1000. ; main option #5 -HELP-
  1001.     db    0            ;e_count
  1002.     db    0            ;e_sub_length
  1003.     db    35            ;e_hot_key (alt-h)
  1004.     db    4            ;e_length
  1005.     dw    main_opt5_text        ;e_text_ptr
  1006.     dw    HELP               ;e_process
  1007.     db    35            ;e_column
  1008.     db    0            ;e_row
  1009. ; main option #6 -QUIT-
  1010.     db    0            ;e_count
  1011.     db    0            ;e_sub_length
  1012.     db    16            ;e_hot_key (alt-q)
  1013.     db    4            ;e_length
  1014.     dw    main_opt6_text        ;e_text_ptr
  1015.     dw    quit               ;e_process
  1016.     db    41            ;e_column
  1017.     db    0            ;e_row
  1018. ; main option #7 -PGUP-
  1019.     db    0            ;e_count
  1020.     db    0             ;e_sub_length
  1021.     db    49H            ;e_hot_key (pgup)
  1022.     db    5            ;e_length
  1023.     dw    main_opt7_text        ;e_text_ptr
  1024.     dw    pgup              ;e_process
  1025.     db    46            ;e_column
  1026.     db    0            ;e_row
  1027. ; main option #8 -PGDN-
  1028.     db    0            ;e_count
  1029.     db    0             ;e_sub_length
  1030.     db    51H            ;e_hot_key (pgdn)
  1031.     db    5            ;e_length
  1032.     dw    main_opt8_text        ;e_text_ptr
  1033.     dw    pgdn               ;e_process
  1034.     db    52            ;e_column
  1035.     db    0            ;e_row
  1036. ; main option end, dummy option
  1037.     db    0            ;e_count
  1038.     db    0            ;e_sub_length
  1039.     db    00            ;e_hot_key (none)
  1040.     db    0            ;e_length
  1041.     dw    0                     ;e_text_ptr
  1042.     dw    0            ;e_process
  1043.     db    0            ;e_column
  1044.     db    0            ;e_row
  1045.  
  1046. main_opt0_text     db 'Edit',0
  1047. main_opt1_text     db 'Find',0
  1048. main_opt2_text     db 'Delete',0
  1049. main_opt3_text     db 'Move',0
  1050. main_opt4_text     db 'Config',0
  1051. main_opt5_text     db 'Help',0
  1052. main_opt6_text     db 'Quit',0
  1053. main_opt7_text     db ' PGUP',0
  1054. main_opt8_text     db ' PGDN',0
  1055.  
  1056. sub0_struc    label    byte
  1057. ;                -EDIT DISPLAYED-
  1058.     db    0            ;e_count
  1059.     db    0            ;e_sub_length
  1060.     db    00h            ;e_hot_key (none)
  1061.     db    13            ;e_length
  1062.     dw    sub0_text4        ;e_text_ptr
  1063.     dw    edit_displayed        ;e_process
  1064.     db    2            ;e_column
  1065.     db    2            ;e_row
  1066. ;                -NEW APPEND-
  1067.     db    0            ;e_count
  1068.     db    0            ;e_sub_length
  1069.     db    00h            ;e_hot_key (none)
  1070.     db    10            ;e_length
  1071.     dw    sub0_text1        ;e_text_ptr
  1072.     dw    edit_append        ;e_process
  1073.     db    2            ;e_column
  1074.     db    3            ;e_row
  1075. ;                -NEW INSERT-
  1076.     db    0            ;e_count
  1077.     db    0            ;e_sub_length
  1078.     db    00h            ;e_hot_key (none)
  1079.     db    10            ;e_length
  1080.     dw    sub0_text2        ;e_text_ptr
  1081.     dw    edit_insert        ;e_process
  1082.     db    2            ;e_column
  1083.     db    4            ;e_row
  1084. ;                -SELECT RECORD#-
  1085.     db    0            ;e_count
  1086.     db    0            ;e_sub_length
  1087.     db    00h            ;e_hot_key (none)
  1088.     db    14            ;e_length
  1089.     dw    sub0_text3        ;e_text_ptr
  1090.     dw    edit_selected        ;e_process
  1091.     db    2            ;e_column
  1092.     db    5            ;e_row
  1093.  
  1094. sub0_text1      db      'Edit for append',0
  1095. sub0_text2      db      'Edit for insert',0
  1096. sub0_text3      db      'Select record',0
  1097. sub0_text4    db    'Edit displayed',0
  1098. ;------
  1099. sub1_struc    label    byte
  1100. ;                -RECORD #-
  1101.     db    0            ;e_count
  1102.     db    0            ;e_sub_length
  1103.     db    00h            ;e_hot_key (none)
  1104.     db    8             ;e_length
  1105.     dw    sub1_text1        ;e_text_ptr
  1106.     dw    find_record        ;e_process
  1107.     db    8            ;e_column
  1108.     db    2            ;e_row
  1109. ;                -NEXT (PGDN)-
  1110.     db    0            ;e_count
  1111.     db    0            ;e_sub_length
  1112.     db    00h            ;e_hot_key (none)
  1113.     db    11            ;e_length
  1114.     dw    sub1_text2        ;e_text_ptr
  1115.     dw    find_next        ;e_process
  1116.     db    8            ;e_column
  1117.     db    3            ;e_row
  1118. ;                -PREV (PGUP)-
  1119.     db    0            ;e_count
  1120.     db    0            ;e_sub_length
  1121.     db    00h            ;e_hot_key (none)
  1122.     db    11            ;e_length
  1123.     dw    sub1_text3        ;e_text_ptr
  1124.     dw    find_prev            ;e_process
  1125.     db    8            ;e_column
  1126.     db    4            ;e_row
  1127. ;                -TEXT-
  1128.     db    0            ;e_count
  1129.     db    0            ;e_sub_length
  1130.     db    00h            ;e_hot_key (none)
  1131.     db    04            ;e_length
  1132.     dw    sub1_text4        ;e_text_ptr
  1133.     dw    find_text        ;e_process
  1134.     db    8            ;e_column
  1135.     db    5            ;e_row
  1136.  
  1137. sub1_text1      db      'Record #',0
  1138. sub1_text2      db      'Next (pgdn)',0
  1139. sub1_text3      db      'Prev (pgup)',0
  1140. sub1_text4    db    'text',0
  1141. ;------
  1142. sub2_struc    label    byte
  1143. ;                -DISPLAYED-
  1144.     db    0            ;e_count
  1145.     db    0            ;e_sub_length
  1146.     db    00h            ;e_hot_key (none)
  1147.     db    09            ;e_length
  1148.     dw    sub2_text2        ;e_text_ptr
  1149.     dw    delete_displayed    ;e_process
  1150.     db    14            ;e_column
  1151.     db    2            ;e_row
  1152. ;                -RECORD #-
  1153.     db    0            ;e_count
  1154.     db    0            ;e_sub_length
  1155.     db    00h            ;e_hot_key (none)
  1156.     db    8             ;e_length
  1157.     dw    sub2_text1        ;e_text_ptr
  1158.     dw    delete_record        ;e_process
  1159.     db    14            ;e_column
  1160.     db    3            ;e_row
  1161.  
  1162. sub2_text1      db      'Record #',0
  1163. sub2_text2      db      'Displayed',0
  1164. ;------
  1165.  
  1166. ;
  1167. ; default colors for mono display
  1168. ;
  1169. mono_defaults    label    byte
  1170.      Db      07h       ;bar text color
  1171.      db      70h       ;bar select color
  1172.      db      0fh       ;bar hotkey color
  1173.      db      0fh       ;submenu text color
  1174.      db      07h       ;submenu select color
  1175.      db      07h       ;msg text color
  1176.      db      70h       ;msg hyper color
  1177.      db      0fh       ;pick color
  1178.      db      70h       ;pick select color
  1179.  
  1180.      db      07h       ;appication color
  1181.           
  1182. color_defaults    label    byte
  1183.      Db      1fh       ;bar text color
  1184.      db      3eh       ;bar select color
  1185.      db      3ch       ;bar hotkey color
  1186.      db      1eh       ;submenu text color
  1187.      db      70h       ;submenu select color
  1188.      db      07h       ;msg text color
  1189.      db      70h       ;msg hyper color
  1190.      db      0fh       ;pick color
  1191.      db      70h       ;pick select color
  1192.  
  1193.      db      07h       ;applicaton color
  1194. ;--------------------------------------------------------------------------
  1195. ;
  1196. ; Note: This data has a disk image which can be modified by the user
  1197. ;
  1198. setup_block    label    byte
  1199. ;-----------------
  1200. ; colors - The first 9 colors which follow are used by library display
  1201. ;       routines and can not be removed or the order changed.  This
  1202. ;       program can utilize these colors or add additional colors at
  1203. ;       end.
  1204. ;
  1205. ;-----------------
  1206.         db      '<<COLORS - use right/left arrow to change>>',0
  1207. ;
  1208.             db    4        ;data type = 4 (color)
  1209.             db    1        ;data length = 1 byte
  1210.             db    0        ;minimum value
  1211.             db    0ffh        ;maximum value
  1212. _bar_text_color        Db    07,'menu text color',0
  1213. ;
  1214.             db    4        ;data type = 4 (color)
  1215.             db    1        ;data length = 1 byte
  1216.             db    0        ;minimum value
  1217.             db    0ffh        ;maximum value
  1218. _bar_select_color    db    70h,'menu select color',0
  1219. ;
  1220.             db    4        ;data type = 4 (color)
  1221.             db    1        ;data length = 1 byte
  1222.             db    0        ;minimum value
  1223.             db    0ffh        ;maximum value
  1224. _bar_hotkey_color    db    0fh,'hotkey color',0
  1225. ;
  1226.             db    4        ;data type = 4 (color)
  1227.             db    1        ;data length = 1 byte
  1228.             db    0        ;minimum value
  1229.             db    0ffh        ;maximum value
  1230. _submenu_text_color    db    0fh,'submenu color',0
  1231. ;
  1232.             db    4        ;data type = 4 (color)
  1233.             db    1        ;data length = 1 byte
  1234.             db    0        ;minimum value
  1235.             db    0ffh        ;maximum value
  1236. _submenu_select_color    db    70h,'submenu select color',0
  1237. ;
  1238.             db    4        ;data type = 4 (color)
  1239.             db    1        ;data length = 1 byte
  1240.             db    0        ;minimum value
  1241.             db    0ffh        ;maximum value
  1242. _msg_text_color        db    07h,'message window text color',0
  1243. ;
  1244.             db    4        ;data type = 4 (color)
  1245.             db    1        ;data length = 1 byte
  1246.             db    0        ;minimum value
  1247.             db    0ffh        ;maximum value
  1248. _msg_hyper_color    db    70h,'message window hyper key color',0
  1249. ;
  1250.             db    4        ;data type = 4 (color)
  1251.             db    1        ;data length = 1 byte
  1252.             db    0        ;minimum value
  1253.             db    0ffh        ;maximum value
  1254. _pick_color        db    07h,'pick from list, window color',0
  1255. ;
  1256.             db    4        ;data type = 4 (color)
  1257.             db    1        ;data length = 1 byte
  1258.             db    0        ;minimum value
  1259.             db    0ffh        ;maximum value
  1260. _pick_select_color    db    70h,'pick from list, window select color',0
  1261.  
  1262. ; the following color has been defined by EDREC and is not used by
  1263. ; library functions.
  1264.  
  1265.             db    4        ;data type = 4 (color)
  1266.             db    1        ;data length = 1 byte
  1267.             db    0        ;minimum value
  1268.             db    0ffh        ;maximum value
  1269. app_text_color        db    07h,'background color',0
  1270.  
  1271.  
  1272. ;------------------
  1273. ; setup strings
  1274. ;------------------
  1275.         db      '<<MISC program settings>>',0
  1276. ;
  1277.             db    3        ;data type = 3 (decimal value)
  1278.             db    1        ;data length = 1 byte
  1279.             db    5        ;minimum value
  1280.             db    78        ;maximum value
  1281. xbox_w            db    60        ;current setting (default)
  1282.             db    'displayed record, box width ',0
  1283.     
  1284. ;
  1285.             db    3        ;data type = 3 (decimal value)
  1286.             db    1        ;data length = 1 byte
  1287.             db    3        ;minimum value
  1288.             db    21        ;maximum value
  1289. xbox_l            db    8        ;current setting (default)
  1290.             db    'displayed record, box lenght',0
  1291. ;
  1292.             db    1        ;data type = 1 (boolean flag)
  1293.             db    1        ;data length = 1 byte
  1294.             db    0        ;minimum value
  1295.             db    1        ;maximum value
  1296. sounds            db    1        ;current setting (on)
  1297.             db    'Error sounds (ON or OFF)',0
  1298.         db      '<<end>>',0
  1299. ;
  1300.     
  1301. code        ends
  1302. ;-------------------------------------------------------------------------
  1303. ;
  1304. ; This segment definition is needed so linker will put the LIBSEG here
  1305. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  1306. ; work correctly.
  1307. ;
  1308. LIBSEG           segment byte public 'LIB'
  1309. LIBSEG    ENDS
  1310. ;-------------------------------------------------------------------------
  1311. ; zseg must be at the end of the program for memory allocation from
  1312. ; DOS.
  1313. ;
  1314. zseg    segment    para public 'ZZ'
  1315.  
  1316. zseg    ends
  1317.  
  1318.         end    start
  1319.