home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / ME494-6.ZIP / SRC / DIRLIST.SRC < prev    next >
Encoding:
Text File  |  1990-05-16  |  12.5 KB  |  486 lines

  1. {*******************************************************************************
  2.                                                     MULTI-EDIT MACRO FILE
  3.  
  4. Name: DIRLIST
  5.  
  6. DIRLIST - A file list menu generator
  7. CREATEDIRLIST - Used by dirlist to create the list
  8.  
  9.                (C) Copyright 1989 by American Cybernetics, Inc.
  10. *******************************************************************************}
  11.  
  12. $MACRO DIRLIST;
  13. {*******************************************************************************
  14.                                                                 MULTI-EDIT MACRO
  15.  
  16. Name: DIRLIST
  17.  
  18. Description: File list menu generator.  Designed to be used with sets
  19.     of files that contain a common extension (like .SRC or .TAG).
  20.  
  21. Parameters:
  22.                     /X=n
  23.                     /Y=n
  24.  
  25.                     /P=str        Directory path and file mask (*.TAG for example);
  26.                                         If no directory is specified, then the Multi-Edit
  27.                                         directory is used.
  28.  
  29.                     /T=str        The title to use.
  30.  
  31.                     /CR=n     1 = Allow create option.    We assume that
  32.                                          the macro will know that if the file doesn't exist,
  33.                                         then it is to create it.
  34.  
  35.                     /PROTECT=str
  36.                                         Specifies a file that is to be protected from
  37.                                         deletion.
  38.  
  39.                     /COPY=str Specifies a file that is to be copied up use of the
  40.                                         create option.
  41.  
  42.  
  43.                     /DL=n            1 = Allow delete option.
  44.  
  45.                     /DE=n            1 = Display filename extensions.
  46.  
  47.                     /MO=n            1 = Allow modify option.
  48.  
  49.           /CP=n     1 = Allow copy option.
  50.  
  51.                     /PLAIN=1  Simple directory list.
  52.  
  53.                     /M=str        The macro to run upon selection of an item.
  54.                                         This MUST be the last item in the parameter string
  55.                                         (to allow for parameters to be passed to the macro).
  56.                                         If this parameter does not exist, then FLIST will
  57.                                         exit with RETURN_STR set to the file selected.
  58.                                         RETURN_INT will equal 1 for a select or 2 for a create.
  59.                                         The following parameters will automatically get passed
  60.                                         to the macro being run:
  61.                                             /X=n
  62.                                             /Y=n
  63.                                             /F=str        The filename that was selected (includes path)
  64.                                         Up returning from the macro, if RETURN_INT > 0 then
  65.                                         FLIST will exit.
  66.  
  67.                (C) Copyright 1989 by American Cybernetics, Inc.
  68. *******************************************************************************}
  69.  
  70.  
  71.   Def_Str( astr[20],TStr[120], Tstr2[120], cur_file_entry[100], path_str[80], create_str[80] );
  72.   Def_Str( protect_str[80], event_str[20], drive_str[32] );
  73.   Def_Int( x, y, attr, jx, jy, tbc, t_win, new_id, tcreate,tdelete, tcopy );
  74.   Def_Int( display_ext, t_undo, tmodify, old_attr, cur_drive );
  75.   Def_Int( event_count, column_mode, Separate_Dir );
  76.  
  77.   def_int( column_count, current_column, column_width, show_drives, drive_count );
  78.  
  79.     tbc := box_count;
  80.     refresh := false;
  81.     t_undo := undo_stat;
  82.     undo_stat := false;
  83.     t_win := window_id;
  84.   show_drives := TRUE;
  85.   IF show_drives THEN
  86.     call get_drive_count;
  87.   end;
  88.  
  89.   Separate_Dir := parse_int('/SD=', mparm_str);
  90.     path_str := parse_str('/P=',mparm_str);
  91.     if get_path(path_str) = '' then
  92.         path_str := me_path + path_str;
  93.     end;
  94.  
  95.     display_ext := parse_int('/DE=',mparm_str);
  96.  
  97.   tcopy := parse_int('/CP=', mparm_str );
  98.     tcreate := parse_int('/CR=', mparm_str );
  99.     create_str := parse_str('/COPY=', mparm_str);
  100.     if create_str <> '' then
  101.         if get_path(create_str) = '' then
  102.             create_str := me_path + create_str;
  103.         end;
  104.         create_str := fexpand(create_str);
  105.     end;
  106.  
  107.     protect_str := parse_str('/PROTECT=', mparm_str);
  108.     if protect_str <> '' then
  109.         if get_path(protect_str) = '' then
  110.             protect_str := me_path + protect_str;
  111.         end;
  112.         protect_str := fexpand(protect_str);
  113.     end;
  114.  
  115.     tdelete := parse_int('/DL=',mparm_str);
  116.     tmodify := parse_int('/MO=',mparm_str);
  117.     x := parse_int( '/X=', mparm_str );
  118.     y := parse_int( '/Y=', mparm_str );
  119.     if x = 0 then
  120.         x := 2;
  121.     end;
  122.     if y = 0 then
  123.         y := 3;
  124.     end;
  125.  
  126.   column_mode := 0;
  127.   call column_calc;
  128.  
  129.     column_width := 15;
  130.     column_count := (screen_width - x - 3) / column_width;
  131.     if column_count < 1 then
  132.         column_count := 1;
  133.     end;
  134.     current_column := 1;
  135.  
  136.     cur_file_entry := '';
  137.     switch_window( window_count );
  138.     create_window;
  139.     new_id := window_id;
  140.  
  141. again:
  142.     call generate_list;
  143.     cur_file_entry := truncate_path(cur_file_entry);
  144.     if display_ext = 0 then
  145.         cur_file_entry := truncate_extension(cur_file_entry);
  146.   end;
  147. again1:
  148.     tof;
  149.     if search_fwd(cur_file_entry,0) then
  150.     end;
  151. again2:
  152.     while box_count > tbc do
  153.         kill_box;
  154.     end;
  155.  
  156.   event_count := 4;
  157.   event_str := '@' + str(global_int('MENU_LEVEL')) + 'FLEV';
  158.  
  159.   Set_Global_Str(event_str + '1', '/T=Select/K1=13/K2=28/R=1/LL=1');
  160.   Set_Global_Str(event_str + '2', '/T=Cancel/K1=27/K2=1/R=0/LL=1');
  161.   Set_Global_Str(event_str + '3', '/T=Display/K1=9/K2=15/R=10/LL=1');
  162.   Set_Global_Str(event_str + '4', '/T=Dir of/K1=0/K2=64/R=6/FL=Dir');
  163.  
  164.   IF show_drives THEN
  165.     cur_drive := ASCII(copy(path_str,1,1)) - 64;
  166.     jx := 0;
  167.     While jx < Drive_Count DO
  168.       ++jx;
  169.       IF str_char( drive_str, jx ) <> ' ' THEN
  170.         IF jx = cur_drive THEN
  171.           astr := '|254';
  172.         ELSE
  173.           astr := '|240';
  174.         END;
  175.         ++event_count;
  176.         Set_Global_Str(event_str + str(event_count), '/T=' + CHAR(64 + jx) +
  177.                         ':/KC=' + astr + '/LL=2/K1=0/K2=0/R=' + str( 100 + jx ));
  178.       END;
  179.     END;
  180.   END;
  181.  
  182.   IF tcreate THEN
  183.     ++event_count;
  184.     Set_Global_Str(event_str + str(event_count), '/T=Create/K1=0/K2=82/R=2');
  185.   END;
  186.  
  187.   IF tdelete THEN
  188.     ++event_count;
  189.     Set_Global_Str(event_str + str(event_count), '/T=Delete/K1=0/K2=83/R=3');
  190.   END;
  191.  
  192.   IF tcopy THEN
  193.     ++event_count;
  194.     Set_Global_Str(event_str + str(event_count), '/T=Copy/K1=0/K2=62/R=5/FL=Copy');
  195.   END;
  196.  
  197.   IF tmodify THEN
  198.     ++event_count;
  199.     Set_Global_Str(event_str + str(event_count), '/T=Edit/K1=0/K2=61/R=4');
  200.   END;
  201.   tstr := time;
  202.   RM('USERIN^WMENU /X=' + str(x) + '/Y=' + str(y) +
  203.       '/W=25/MARK=1' +
  204.       '/CLW=' + str(column_width) + '/CL#=' + str(column_count) +
  205.       '/DBL=1/S=' + str(c_line) + '/CLC=' + str((c_col / column_width) + 1) +
  206.       '/OR=' + str( c_row ) +
  207.       '/T=' + {parse_str('/T=', mparm_str)} path_str +
  208.       '/H=' + Parse_Str('/H=',MParm_Str) +
  209.       '/NB=0' +
  210.       '/EV=' + event_str + '/EV#=' + str( event_count ) +
  211.       '/NK=1' );
  212.     jx := 0;
  213.   call get_file_name;
  214.  
  215.   {make_message('['+return_str+']'); }
  216.     cur_file_entry := fexpand(get_path(path_str) + return_str);
  217.     if return_int = 0 then
  218.         goto exit;
  219.     end;
  220.  
  221.   If return_int > 100 THEN
  222.     path_str := fexpand(char( (return_int - 100) + 64 ) + ':' + truncate_path(path_str));
  223.     goto again;
  224.   END;
  225.  
  226.   {Toggle display mode}
  227.   IF return_int = 10 THEN
  228.     column_mode := NOT( column_mode );
  229.     goto again;
  230.   END;
  231.  
  232.     {If create was selected and create_str is not nul then we will use
  233.         it as the template file}
  234.     if (return_int = 2) and (create_str <> '') then
  235.     COPY_FILE( create_str , cur_file_entry, false );
  236.     end;
  237.  
  238.     {We will run the macro both on select and on INSERT.  We assume that
  239.      the macro will know that if the file doesn't exist, then it is to
  240.      create it.}
  241.  
  242.     if (return_int = 1) THEN
  243.         if copy(return_str,length(return_str),1) = '\' THEN
  244.             cur_file_entry := '';
  245.             path_str := fexpand(get_path(path_str) + return_str + truncate_path(path_str));
  246.             goto again;
  247.         END;
  248.         IF tmodify = TRUE THEN
  249.             return_str := cur_file_entry;
  250.             goto exit;
  251.         ELSE
  252.             return_int := 2;
  253.         END;
  254.     END;
  255.  
  256.     IF (return_int = 4) OR (return_int = 2) then
  257.         jx := xpos('/M=',mparm_str, 1);
  258.         if jx <> 0 then
  259.             tstr := shorten_str(copy(mparm_str,jx +  3, 254 ));
  260.             RM(  tstr + ' /X=' + str(x + 3) + '/Y=' + str(y + 2) +
  261.                                         '/F=' + cur_file_entry );
  262.             if return_int > 0 then
  263.                 goto exit;
  264.             end;
  265.         else
  266.             return_str := cur_file_entry;
  267.             goto exit;
  268.         end;
  269.     end;
  270.  
  271.     {Delete was selected here}
  272.     if return_int = 3 then
  273.         working;
  274.         {Don't allow deletion of the create file or the protected file}
  275.         if (cur_file_entry = create_str) or (cur_file_entry = protect_str) then
  276.             RM('MEERROR^BEEPS /C=1');
  277.         else
  278.             del_file( cur_file_entry );
  279.         end;
  280.     end;
  281.  
  282.   {Copy file}
  283.   IF return_int = 5 THEN
  284.     working;
  285.     return_str := '';
  286.     RM('USERSTR /B=1/BL=COPY MARKED FILES TO WHERE?/H=DS/L=40/ML=120/W=40/X=' + str(x + 3) +
  287.         '/Y=' + str(y+2));
  288.     IF return_int THEN
  289.       mark_pos;
  290.       tstr2 := RETURN_STR;
  291.       TOF;
  292.       WHILE search_fwd('|16',0) DO
  293.         call get_file_name;
  294.         call Copy_File;
  295.       END;
  296.     ELSE
  297.       goto again2;
  298.     END;
  299.   END;
  300.  
  301.   IF return_int = 6 THEN
  302.     return_str := path_str;
  303.     RM('USERSTR /B=1/BL=INPUT DIRECTORY TO DISPLAY/H=DS/L=40/ML=120/W=40/X=' + str(x + 3) +
  304.         '/Y=' + str(y+2));
  305.     IF return_int THEN
  306.       path_str := return_str;
  307.       goto again;
  308.     ELSE
  309.       goto again2;
  310.     END;
  311.   END;
  312.     goto again;
  313.  
  314.  
  315. copy_file:
  316.  
  317.  
  318. get_file_name:
  319.   IF column_mode = 1 THEN
  320.     return_str := shorten_str(copy(get_line, c_col + 1, column_width - 1));
  321.   ELSE
  322.     return_str := shorten_str(copy(get_line, 2, 8));
  323.     tstr := shorten_str(copy(get_line,12,3));
  324.     IF tstr <> '' THEN
  325.       return_str := return_str + '.' + tstr;
  326.     END;
  327.     IF copy(get_line,18,5) = '<DIR>' THEN
  328.       return_str := return_str + '\';
  329.     END;
  330.   END;
  331.   ret;
  332.  
  333. column_calc:
  334.   IF column_mode = 0 THEN
  335.     column_width := 45;
  336.     column_count := 1;
  337.   ELSE
  338.     column_width := 15;
  339.     column_count := (screen_width - x - 1) / column_width;
  340.     if column_count < 1 then
  341.       column_count := 1;
  342.     end;
  343.     current_column := 1;
  344.   END;
  345.   RET;
  346.  
  347. generate_list:
  348.     return_str := path_str;
  349.     if switch_win_id( new_id ) then
  350.     end;
  351.   call column_calc;
  352.     RM('CreateDirList /CC=' + str( column_count ) +
  353.                                      '/CW=' + str( column_width ) +
  354.                                      '/CM=' + str( column_mode ) +
  355.                                      '/SD=' + str( Separate_Dir ) );
  356.     ret;
  357.  
  358. get_drive_count:
  359.   IF show_drives THEN
  360.     R_AX := $1900;
  361.     Intr($21);
  362.     jy := R_AX and $00FF;
  363.     R_DX := jy;
  364.     R_AX := $0E00;
  365.     Intr($21);
  366.     jx := 0;
  367.     drive_count := R_AX AND $00FF;
  368.     drive_str := '';
  369.     while jx < drive_count DO
  370.       R_DX := jx;
  371.       R_AX := $0E00;
  372.       Intr($21);
  373.       R_AX := $1900;
  374.       Intr($21);
  375.       IF (R_AX and $00FF) = jx THEN
  376.         ++jx;
  377.         drive_str := drive_str + char( jx + 64);
  378.       ELSE
  379.         ++jx;
  380.         drive_str := drive_str + ' ';
  381.       END;
  382.     END;
  383.     R_DX := jy;
  384.     R_AX := $0E00;
  385.     Intr($21);
  386.   END;
  387.   ret;
  388.  
  389. exit:
  390.     refresh := false;
  391.     undo_stat := t_undo;
  392.     if switch_win_id( new_id ) then
  393.         delete_window;
  394.     end;
  395.     while box_count > tbc do
  396.         kill_box;
  397.     end;
  398.     switch_win_id( t_win );
  399.   set_global_str('!DIRLIST_PATH!', path_str );
  400.  
  401. END_MACRO;
  402.  
  403. $MACRO CREATEDIRLIST;
  404. {*******************************************************************************
  405.                                                                 MULTI-EDIT MACRO
  406.  
  407. Name: CREATEDIRLIST
  408.  
  409. Description: Used by DIRLIST to create a list of files according to the desired
  410.                          directory mask.
  411.  
  412. Parameters:
  413.                          Return_Str        Contains the directory mask.  Defaults to *.*
  414.                          /CC=        The number of desired columns in the list.
  415.                          /CW=        The width of the columns in the list.
  416.                          /CM=
  417.                          /SD=
  418.  
  419.                (C) Copyright 1989 by American Cybernetics, Inc.
  420. *******************************************************************************}
  421.  
  422.     def_int(old_attr,
  423.                     current_column, column_count, column_width, column_mode,
  424.                     Separate_Dir );
  425.  
  426.   return_str := fexpand( return_str );
  427.   if truncate_path(return_str) = '' THEN
  428.     return_str := return_str + '*.*';
  429.   END;
  430.     column_count := parse_int( '/CC=', mparm_str );
  431.     column_width := parse_int( '/CW=', mparm_str );
  432.     column_mode := parse_int( '/CM=', mparm_str );
  433.     Separate_Dir := parse_int( '/SD=', mparm_str );
  434.     current_column := 0;
  435.     old_attr := File_Search_Attr;
  436.   File_Search_Attr := $31;
  437.  
  438.     refresh := false;
  439.     working;
  440.     erase_window;
  441.     tof;
  442.   entry_mode := column_mode;
  443.   IF Separate_Dir THEN
  444.     get_directory_list( Get_Path(return_str) + '*.*', 'N', 1 );
  445.         IF error_level <> 0 THEN
  446.             rm( 'meerror' );
  447.             error_level := 0;
  448.             goto exit;
  449.         END;
  450.     call build_list;
  451.     File_Search_Attr := $21;
  452.   END;
  453.   get_directory_list( return_str, '', 0 );
  454.     IF error_level <> 0 THEN
  455.         rm( 'meerror' );
  456.         error_level := 0;
  457.         goto exit;
  458.     END;
  459.   call build_list;
  460.  
  461.     tof;
  462.     File_Search_Attr := old_attr;
  463.     goto exit;
  464.  
  465. build_list:
  466.     if first_Entry = 0 then
  467.         goto build_exit;
  468.     end;
  469. build_loop:
  470.     ++current_column;
  471.     IF (current_column > column_count) THEN
  472.         down;
  473.         current_column := 1;
  474.     END;
  475.     goto_col( (column_width * (current_column - 1)) + 2 );
  476.     text( Entry_Name );
  477. get_next_file:
  478.     if Next_ENTRY then
  479.         goto build_loop;
  480.     end;
  481. build_exit:
  482.   RET;
  483.  
  484. EXIT:
  485.  
  486. END_MACRO;