home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / directry / tcfm / fm.c next >
Encoding:
C/C++ Source or Header  |  1987-12-02  |  22.5 KB  |  1,001 lines

  1. #include <stdio.h>
  2. #include <bios.h>
  3. #include <dir.h>
  4. #include <tcutil.h>
  5. #include <dos.h>
  6. #include <process.h>
  7. #include <ctype.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include <string.h>
  11. long calc_tots(char *);
  12.  
  13. char *split_arg(char *);
  14. char auto_key_ext[10][4] ={"ARC",     /*format is ext,command*/
  15.                              "DOC",
  16.                            "C",        
  17.                            "\x00",        
  18.                            "\x00",        
  19.                            "\x00",        
  20.                            "\x00",        
  21.                            "\x00",        
  22.                            "\x00",        
  23.                            "\x00",};        
  24.  
  25.  
  26. char auto_key_cmd[10][20] ={"LARK",     /*format is ext,command*/
  27.                               "LIST",
  28.                             "Q",        
  29.                             "\x00",        
  30.                             "\x00",        
  31.                             "\x00",        
  32.                             "\x00",        
  33.                             "\x00",        
  34.                             "\x00",        
  35.                             "\x00",};        
  36.  
  37.  
  38. char fkeyp[10][5] = {"HELP",     /*format is ext,command*/
  39.                       "LIST",
  40.                     "\x00",        
  41.                     "\x00",        
  42.                     "\x00",        
  43.                     "\x00",        
  44.                     "NAME",        
  45.                     "EXT",        
  46.                     "SIZE",        
  47.                     "DATE",};        
  48.  
  49. char fkeyc[10][20] = {"HELP",     /*format is ext,command*/
  50.                      "LIST",        
  51.                      "\x00",
  52.                      "\x00",        
  53.                      "\x00",        
  54.                      "\x00",        
  55.                      "SORT BY NAME",
  56.                      "SORT BY EXTSION",
  57.                      "SORT BY SIZE",
  58.                      "SORT BY DATE"};
  59.  
  60. char afkeyp[10][5] ={"\x00",     /*format is ext,command*/
  61.                        "\x00",
  62.                     "\x00",        
  63.                     "\x00",        
  64.                     "\x00",        
  65.                     "\x00",        
  66.                     "\x00",        
  67.                     "\x00",        
  68.                     "\x00",        
  69.                     "\x00",};        
  70.  
  71.  
  72. char afkeyc[10][20] ={"\x00",     /*format is ext,command*/
  73.                          "\x00",
  74.                       "\x00",        
  75.                       "\x00",        
  76.                       "\x00",        
  77.                       "\x00",        
  78.                       "\x00",        
  79.                       "\x00",        
  80.                       "\x00",        
  81.                       "\x00",};        
  82.  
  83.  
  84. char cfkeyp[10][5] ={"\x00",     /*format is ext,command*/
  85.                        "\x00",
  86.                     "\x00",        
  87.                     "\x00",        
  88.                     "\x00",        
  89.                     "\x00",        
  90.                     "\x00",        
  91.                     "\x00",        
  92.                     "\x00",        
  93.                     "\x00",};        
  94.  
  95.  
  96. char cfkeyc[10][20] ={"\x00",     /*format is ext,command*/
  97.                          "\x00",
  98.                       "\x00",        
  99.                       "\x00",        
  100.                       "\x00",        
  101.                       "\x00",        
  102.                       "\x00",        
  103.                       "\x00",        
  104.                       "\x00",        
  105.                       "\x00",};        
  106.  
  107.  
  108. struct tablk {
  109.     char my_attr;
  110.     unsigned my_sec:5;
  111.     unsigned my_min:6;
  112.     unsigned my_hour:5;
  113.     unsigned my_day:5;
  114.     unsigned my_month:4;
  115.     unsigned my_year:7;
  116.     long my_size;
  117.     char my_name[13];
  118.     char my_ext[5];
  119.     char my_fn[9];
  120. } tblk[500];
  121.  
  122. char cmd_line[500][45];
  123. struct myblk {
  124.     char my_res[21];
  125.     struct tablk move;
  126. };
  127. struct myblk dta;
  128.  
  129. int normal = setatr(CYAN,BLACK,0,0);
  130. int reverse = setatr(BLACK,CYAN,0,0);
  131. int file_a = setatr(GREEN,BLACK,0,0);
  132. int highlite = setatr(WHITE,BLUE,0,BOLD);
  133. int foot_a = setatr(BLACK,RED,0,0);
  134. int foot_ah = setatr(BLACK,GREEN,0,0);
  135. int foot_a2 = setatr(BLACK,WHITE,0,0);
  136. int foot_a3 = setatr(BLACK,YELLOW,0,0);
  137.  
  138. char foot[81], foota[81], footc[81];
  139. char *foot_fmt ="F1=%-4.4s F2=%-4.4s F3=%-4.4s F4=%-4.4s F5=%-4.4s F6=%-4.4s F7=%-4.4s F8=%-4.4s F9=%-4.4s F10=%-4.4s";
  140.  
  141.  
  142. char b_line[81], quit_flag;
  143. char outline[81], curr_dir[68], org_dir[68];
  144. char mask[13], sort_type;
  145. int org_drive, curr_drive, disk_err, orow, ocol;
  146. char am_pm, pattr[5], drive[3], dir[66], fname[9], fext[6];
  147. char fattr[6];
  148. char *rattr="    ";
  149. int max=0;
  150. unsigned long int dir_size;
  151. int pending;
  152.  
  153. char tline[81], inline[45], save_screen[4000], first_screen[4000];
  154.  
  155.  
  156. int err_hand(int errval, int ax, int bp, int si)
  157. {
  158. #define win_size setsize_w(8,22,14,57)
  159.     static    char line[33], win_save[win_size], resp;
  160.     static    char *emes[] = {"Disk is Write Protected",
  161.                             "Unknown Unit",
  162.                             "Drive is not Ready",
  163.                             "Unknown Command",
  164.                             "Bad CRC",
  165.                             "Bad Request Structure Length",
  166.                             "Seek Error",
  167.                             "Unknown Media Type",
  168.                             "Sector Not Found",
  169.                             "Printer out of Paper",
  170.                             "Write Fault",
  171.                             "Read Fault",
  172.                             "General Failure"};
  173.     int attr = setatr(BLACK,RED,0,0), drive;
  174.  
  175.     if(ax < 0) {
  176.         bdosptr(0x09,"Device error program aborting.$",0);
  177.         hardresume(2);
  178.     }
  179.  
  180.     drive = (ax & 0x00ff);
  181.     save_scr(8,22,14,57,win_save);
  182.     make_window(8,22,14,57,attr,attr,0,"DISK ERROR","");
  183.             
  184.     sprintf(line,"Error on Drive %c:",'A' + drive);
  185.     writef(9,23,attr,line);
  186.     writef(10,23,attr,"ERROR MESSAGE IS");
  187.     writef(11,23,attr,emes[errval]);
  188.     writef(13,23,attr,"PRESS R TO RETRY A TO ABORT");
  189.     hide_cur();
  190.     get_akey(&resp,"RA");
  191.     show_cur(1);
  192.     rest_scr(8,22,14,57,win_save);
  193.     if(resp=='R') hardresume(1);
  194.     disk_err=1;
  195.     hardretn(2);
  196. }
  197.  
  198.  
  199. sort_ext(el1,el2)
  200.     struct tablk *el1, *el2;
  201. {
  202.     char ext1[15], ext2[15];
  203.     strcpy(ext1,el1->my_ext);
  204.     strcpy(ext2,el2->my_ext);
  205.     if(el1->my_attr & 0x10) strcpy(ext1,"\x01");
  206.     if(el2->my_attr & 0x10) strcpy(ext2,"\x01");
  207.     strcat(ext1,el1->my_fn);
  208.     strcat(ext2,el2->my_fn);
  209.     return(stricmp(&ext1,&ext2));
  210. }
  211.  
  212. sort_name(el1,el2)
  213.     struct tablk *el1, *el2;
  214. {
  215.     return(stricmp(el1->my_name,el2->my_name));
  216. }
  217.  
  218.  
  219. sort_size(el1,el2)
  220.     struct tablk *el1, *el2;
  221. {
  222.     if(el1->my_size > el2->my_size) return(1);
  223.     if(el1->my_size < el2->my_size) return(-1);
  224.     return(0);
  225. }
  226.  
  227.  
  228. sort_date(el1,el2)
  229.     struct tablk *el1, *el2;
  230. {
  231.     if(el1->my_year > el2->my_year) return(1);
  232.     if(el1->my_year < el2->my_year) return(-1);
  233.     if(el1->my_month > el2->my_month) return(1);
  234.     if(el1->my_month < el2->my_month) return(-1);
  235.     if(el1->my_day > el2->my_day) return(1);
  236.     if(el1->my_day < el2->my_day) return(-1);
  237.     return(0);
  238. }
  239.  
  240. void common_exit()
  241. {
  242.     rest_scr(0,0,24,79,first_screen);
  243.     locate(orow,ocol);
  244.     if(quit_flag == 'q') {
  245.         setdisk(curr_drive);
  246.         chdir(&curr_dir);
  247.     }
  248.     else {
  249.         setdisk(org_drive);
  250.         chdir(&org_dir);
  251.     }
  252. }
  253.  
  254.  
  255. main(int argc, char *argv[])
  256. {
  257.     char *head = "NAME     TYPE------------------COMMAND------------RHSA        SIZE   TIME   DATE";
  258.     struct dfree disks;
  259.     char *mask_pt, cfg_pt, *pt_cga, *pt_bios;
  260.     extern int cga, bios;
  261.     int point, scr_row, term_ch, idx;
  262.     unsigned long int disk_tot, disk_aval;
  263.  
  264.     pending=0;
  265.     quit_flag=' ';
  266.  
  267.     strcpy(&mask,"*.*");
  268.     sort_type = '\x00';
  269.     memset(&b_line,' ',80);
  270.     b_line[80]=0x00;
  271.     video_type();
  272.  
  273.     pt_cga=getenv("CGA");
  274.     if(pt_cga && toupper(*pt_cga)=='N') cga=0;
  275.     pt_bios=getenv("BIOS");
  276.     if(pt_bios && toupper(*pt_bios)=='Y') bios=1;
  277.  
  278.     save_scr(0,0,24,79,first_screen);
  279.     get_cur(&orow,&ocol);
  280.     getcwd(curr_dir,68);
  281.     strupr(curr_dir);
  282.     strcpy(org_dir,curr_dir);
  283.     org_drive = org_dir[0] - 'A';
  284.     curr_drive = org_drive;
  285.     harderr(err_hand);
  286.     atexit(common_exit);
  287.     if(argc > 1)  {
  288.         mask_pt=split_arg(argv[1]);
  289.         if(mask_pt != NULL) strcpy(&mask,mask_pt);
  290.     }
  291.     get_cfg_file();
  292.     clr(normal);
  293.     sprintf(foot,foot_fmt,
  294.         fkeyp[0],fkeyp[1],fkeyp[2],fkeyp[3],fkeyp[4],fkeyp[5],fkeyp[6],
  295.         fkeyp[7],fkeyp[8],fkeyp[9]);
  296.     sprintf(foota,foot_fmt,
  297.         afkeyp[0],afkeyp[1],afkeyp[2],afkeyp[3],afkeyp[4],afkeyp[5],afkeyp[6],
  298.         afkeyp[7],afkeyp[8],afkeyp[9]);
  299.     sprintf(footc,foot_fmt,
  300.         cfkeyp[0],cfkeyp[1],cfkeyp[2],cfkeyp[3],cfkeyp[4],cfkeyp[5],cfkeyp[6],
  301.         cfkeyp[7],cfkeyp[8],cfkeyp[9]);
  302. restart:
  303.     clrarea(0,0,3,79,reverse);
  304.     writef(3,0,reverse,head);
  305.     writef(24,0,foot_a,foot);
  306.     highlite_foot();
  307.     writef(0,0,reverse,"CURRENT DIR=>");
  308.     writef(0,13,reverse,curr_dir);
  309.     writef(1,0,reverse,"FILE MASK===>");
  310.     writef(1,13,reverse,&mask);
  311.     getdfree(0,&disks);
  312.     disk_tot = (unsigned long) disks.df_total * disks.df_bsec * disks.df_sclus;
  313.     sprintf(&tline,"TOTAL DISK SPACE=%9lu",disk_tot);
  314.     writef(0,54,reverse,&tline);
  315. re_read:
  316.     reset_cmd_line();
  317.     point=0;
  318.     get_names();
  319.     if(sort_type) do_sort();
  320. re_show:
  321.     getdfree(0,&disks);
  322.     disk_aval = (unsigned long) disks.df_avail * disks.df_bsec * disks.df_sclus;
  323.     sprintf(&tline,"AVAILABLE  SPACE=%9lu",disk_aval);
  324.     writef(1,54,reverse,&tline);
  325.     sprintf(&tline,"BYTES IN DIR    =%9lu",dir_size);
  326.     writef(2,54,reverse,&tline);
  327.     sprintf(&tline,"NUM FILES===>%-d",max+1);
  328.     writef(2,0,reverse,&tline);
  329.  
  330.     scr_row=4;
  331. get_commands:
  332.     show_em(point);
  333. get_commands2:
  334.     locate(scr_row,13);
  335.     rcolor(scr_row,0,highlite,13);
  336.     rcolor(scr_row,49,highlite,31);
  337.     while(!bioskey(1)) do_foot();
  338.     idx=(scr_row - 4) + point;    
  339.     inline[0]=0x00;
  340.     strcpy(&inline,cmd_line[idx]);
  341.     term_ch=get_line(&inline,44,file_a,35);
  342.     if(strlen(&inline)>0) pending++;
  343.     rcolor(scr_row,0,file_a,13);
  344.     rcolor(scr_row,49,file_a,31);
  345.     strcpy(cmd_line[idx],&inline);
  346.     switch (term_ch) {
  347.         case(K_ENTER):
  348.             if(strlen(&inline) < 1 || inline[0]=='*' || inline[0]==' ') {
  349.                 if(tblk[idx].my_attr & 0x10) {
  350.                     switch_dir(idx);
  351.                     goto restart;
  352.                 }
  353.                 else {
  354.                     if(pending) {exe_the_cmd(); goto get_commands;}
  355.                     else  goto get_commands2;
  356.                 }
  357.             }
  358.             exe_the_cmd();
  359.             goto get_commands;
  360.         case(K_DOWN):
  361.             scr_row++;
  362.             if(scr_row - 4 + point > max) {
  363.                 scr_row--;
  364.                 goto get_commands2;
  365.             }
  366.             if(scr_row > 23) {
  367.                 scr_row=23;
  368.                 point=point+1;
  369.                 scroll_up(4,0,23,79,file_a,1);
  370.                 format_line(point+19);
  371.                 writef(23,0,file_a,&outline);
  372.                 goto get_commands2;    
  373.             }
  374.             if(point > max) point=point-20;
  375.             if(scr_row > 4) goto get_commands2;
  376.             goto get_commands;
  377.         case(K_UP):
  378.             scr_row--;
  379.             if(scr_row < 4) {
  380.                 scr_row=4;
  381.                 if(point ==0) goto get_commands2;
  382.                 scroll_dn(4,0,23,79,file_a,1);
  383.                 point--;
  384.                 format_line(point);
  385.                 writef(4,0,file_a,&outline);
  386.                 goto get_commands2;
  387.             }
  388.             goto get_commands2;    
  389.         case(K_CPGUP):
  390.             scr_row=4;
  391.             point=0;
  392.             goto get_commands;
  393.         case(K_CPGDN):
  394.             scr_row=4;
  395.             point=max-19;
  396.             goto get_commands;
  397.         case(K_PGDN):
  398.             scr_row=4;
  399.             if(point + 20 > max) goto get_commands2;
  400.             point=point+20;
  401.             if(point > max) point=max-19;
  402.             if(max < 20) point=0;
  403.             goto get_commands;
  404.         case(K_PGUP):
  405.             scr_row=4;
  406.             if(point == 0) goto get_commands2;
  407.             if(point > 19) point=point-20;
  408.             else point=0;
  409.             goto get_commands;
  410.         case(K_F1):
  411.             help();
  412.             goto get_commands2;
  413.         case(K_F2):
  414.         case(K_F3):
  415.         case(K_F4):
  416.         case(K_F5):
  417.         case(K_F6):
  418.             term_ch = term_ch - K_F1;
  419.             if(fkeyc[term_ch][0]) {
  420.                 strcpy(cmd_line[idx],fkeyc[term_ch]);
  421.                 exe_the_cmd();
  422.             }
  423.             goto get_commands;
  424.         case(K_F7):
  425.             sort_type='n';
  426.             do_sort();
  427.             point=0; scr_row=4;
  428.             highlite_foot();
  429.             goto get_commands;
  430.         case(K_F8):
  431.             sort_type='e';
  432.             do_sort();
  433.             point=0; scr_row=4;
  434.             highlite_foot();
  435.             goto get_commands;
  436.         case(K_F9):
  437.             sort_type='s';
  438.             do_sort();
  439.             point=0; scr_row=4;
  440.             highlite_foot();
  441.             goto get_commands;
  442.         case(K_F10):
  443.             sort_type='d';
  444.             do_sort();
  445.             point=0; scr_row=4;
  446.             highlite_foot();
  447.             goto get_commands;
  448.         case(K_AF1):
  449.         case(K_AF2):
  450.         case(K_AF3):
  451.         case(K_AF4):
  452.         case(K_AF5):
  453.         case(K_AF6):
  454.         case(K_AF7):
  455.         case(K_AF8):
  456.         case(K_AF9):
  457.         case(K_AF10):
  458.             term_ch = term_ch - K_AF1;
  459.             if(afkeyc[term_ch][0]) {
  460.                 strcpy(cmd_line[idx],afkeyc[term_ch]);
  461.                 exe_the_cmd();
  462.             }
  463.             goto get_commands;
  464.         case(K_CF1):
  465.         case(K_CF2):
  466.         case(K_CF3):
  467.         case(K_CF4):
  468.         case(K_CF5):
  469.         case(K_CF6):
  470.         case(K_CF7):
  471.         case(K_CF8):
  472.         case(K_CF9):
  473.         case(K_CF10):
  474.             term_ch = term_ch - K_CF1;
  475.             if(cfkeyc[term_ch][0]) {
  476.                 strcpy(cmd_line[idx],cfkeyc[term_ch]);
  477.                 exe_the_cmd();
  478.             }
  479.             goto get_commands;
  480.         case(K_ALTX):
  481.             dos_shell();
  482.             goto get_commands;
  483.         case(K_ALTA):
  484.             do_auto_key(idx);
  485.             exe_the_cmd();
  486.             goto get_commands;
  487.         case(K_ALTM):
  488.             rcolor(1,13,normal,12);
  489.             locate(1,13);
  490.             get_line(&mask,12,normal,12);
  491.             if(!strlen(&mask)) strcpy(&mask,"*.*");
  492.             goto restart;
  493.         case(K_ALTP):
  494.             do_pgm(idx);
  495.             goto get_commands;        
  496.         case(K_ALTQ):
  497.             quit_flag='q';
  498.             goto quit_it;
  499.         case(K_ALTR):
  500.             sort_type=' ';
  501.             goto re_read;
  502.         case(K_ALTS):
  503.             do_tots();
  504.             goto get_commands;
  505.         case(K_ALTT):
  506.             tag_all();
  507.             goto get_commands;
  508.         case(K_ALTD):
  509.             rcolor(0,13,normal,40);
  510.             locate(0,13);
  511.             get_line(&curr_dir,67,normal,40);
  512.             mask_pt=split_arg(&curr_dir);
  513.             if(mask_pt != NULL) strcpy(&mask,mask_pt);
  514.             goto restart;
  515.         case(K_TAB):
  516.             if(tblk[idx].my_attr & 0x10) goto get_commands2;
  517.             strcpy(fattr,"    ");
  518.             locate(scr_row,50);
  519.             rcolor(scr_row,50,reverse,4);
  520.             term_ch=get_line(&fattr,4,reverse,4);
  521.             if(term_ch != K_ENTER) goto get_commands2;
  522.             strupr(fattr);
  523.             set_file_atr(idx);
  524.             goto get_commands;
  525.     case(K_ESC):
  526.             goto quit_it;
  527.         default:
  528.             goto get_commands2;
  529.     }
  530.  
  531. quit_it:
  532.     exit(0);
  533. }
  534.  
  535. do_pgm(int idx)
  536. {
  537.     int orow, ocol;
  538.     save_scr(0,0,24,79,save_screen);
  539.     get_cur(&orow,&ocol);
  540.     clr(normal);
  541.     spawnlp(P_WAIT,tblk[idx].my_name,tblk[idx].my_name,NULL);
  542.     rest_scr(0,0,24,79,save_screen);
  543.     locate(&orow,&ocol);
  544. }
  545.  
  546.  
  547. dos_shell()
  548. {
  549.     int orow, ocol;
  550.     save_scr(0,0,24,79,save_screen);
  551.     get_cur(&orow,&ocol);
  552.     clr(normal);
  553.     put_sa("Exiting to DOS. Type EXIT and press enter to return\n",file_a);
  554.     spawnlp(P_WAIT,"command.com","command.com",NULL);
  555.     rest_scr(0,0,24,79,save_screen);
  556.     locate(&orow,&ocol);
  557. }
  558.  
  559. do_auto_key(int idx)
  560. {
  561.     int x;
  562.     for(x=0;x<10;x++) {
  563.         if(!(stricmp(auto_key_ext[x],tblk[idx].my_ext))) {
  564.             strcpy(&cmd_line[idx],&auto_key_cmd[x]);
  565.             break;
  566.         }
  567.     }
  568. }
  569.  
  570. tag_all()
  571. {
  572.     int idx;
  573.     for(idx=0;idx<=max;idx++) {
  574.         if(tblk[idx].my_attr & 0x10) continue;
  575.         else strcpy(cmd_line[idx],"=");
  576.     }
  577. }
  578.  
  579. do_tots()
  580. {
  581.     int idx, x;
  582.     char work_dir[69];
  583.     for(idx=0;idx<=max;idx++) {
  584.         if(tblk[idx].my_attr & 0x10) {
  585.             if(tblk[idx].my_name[0] !=  '.') {
  586.                 strcpy(work_dir,curr_dir);
  587.                 x=strlen(work_dir) -1;
  588.                 if(work_dir[x] != '\\')
  589.                     strcat(work_dir,"\\");
  590.                 strcat(work_dir,&tblk[idx].my_name);
  591.                 tblk[idx].my_size=calc_tots(work_dir);
  592.             }
  593.             else continue;
  594.         }
  595.         else continue;
  596.     }
  597. }
  598. exe_the_cmd()
  599. {
  600.     static char work_line[40], work_line2[40];
  601.     static int first=1;
  602.     int orow, ocol, idx, x, no_pause;
  603.     char work_cmd[128], work_file[81], *pt;
  604.     no_pause=0; pending=0;
  605.     if(first) {work_line[0]=0x00; work_line2[0]=0x00; first=0;}    
  606.     save_scr(0,0,24,79,save_screen);
  607.     get_cur(&orow,&ocol);
  608.     clr(normal);
  609.     for(idx=0;idx <=max;idx++) {
  610.         if(cmd_line[idx][0]=='\x00' || cmd_line[idx][0]=='*' || cmd_line[idx][0] == ' ')
  611.             continue;
  612.         strcpy(&work_line,&cmd_line[idx]);
  613.         if(work_line[0]=='=')
  614.             strcpy(&work_line,&work_line2);
  615.         else
  616.             strcpy(&work_line2,&work_line);
  617.         if(work_line[0]=='=' || work_line[0]=='\x00') {
  618.             strcpy(cmd_line[idx],"*?");
  619.             continue;
  620.         }
  621.         if(work_line[0]=='/') {
  622.             s_str_lf(1,&work_line);
  623.             put_sa(&work_line,file_a);
  624.             cputs("\r\n");
  625.             system(&work_line);
  626.             cmd_line[idx][0]='*';
  627.             no_pause=1;
  628.             put_sa("\nStrike a key to continue..",file_a);
  629.             bioskey(0);
  630.             continue;
  631.         }
  632.         cmd_line[idx][0]='*';
  633.         strcpy(&work_file,&curr_dir);
  634.         if(strlen(&curr_dir) > 3)
  635.             strcat(&work_file,"\\");
  636.         strcat(&work_file,&tblk[idx].my_name);
  637.         strip(&work_file,' ');
  638.         if(work_line[0]=='@') {
  639.             no_pause=1;
  640.             s_str_lf(1,&work_line);
  641.         }
  642.         pt=(char *)strtok(&work_line," ");
  643.         strcpy(&work_cmd,pt);
  644.         strcat(&work_cmd," ");
  645.         strcat(&work_cmd,&work_file);
  646.         pt=(char *)strtok(NULL," ");
  647.         while(pt) {
  648.             strcat(&work_cmd," ");
  649.             strcat(&work_cmd,pt);
  650.             pt=(char *)strtok(NULL," ");
  651.         }
  652.         put_sa(&work_cmd,file_a);
  653.         cputs("\r\n");
  654.         system(&work_cmd);
  655.     }
  656.  
  657.     if(!no_pause) {
  658.         put_sa("\nStrike a key to continue..",file_a);
  659.         bioskey(0);
  660.     }
  661.     rest_scr(0,0,24,79,save_screen);
  662.     locate(&orow,&ocol);
  663. }
  664.  
  665.  
  666. switch_dir(int idx)
  667. {
  668.     char *wpt;
  669.     int x;
  670.     if(stricmp(&tblk[idx].my_name,"..")) {
  671.         x=strlen(curr_dir) -1;
  672.         if(curr_dir[x] != '\\')
  673.             strcat(curr_dir,"\\");
  674.         strcat(curr_dir,&tblk[idx].my_name);
  675.     }
  676.     else {
  677.         wpt=strrchr(curr_dir,'\\');
  678.         if(wpt) {
  679.             if(*(wpt-1) != ':') *wpt=0x00;
  680.             else *(wpt+1)=0x00;
  681.         }
  682.     }
  683. }
  684.  
  685. get_names()
  686. {
  687.     extern int errno, _doserrno;
  688.     char f_dir[80];
  689.     int done, x;
  690.     max=0;
  691.     dir_size=0;
  692.     disk_err=0;
  693.     strcpy(f_dir,curr_dir);
  694.     x=strlen(curr_dir) -1;
  695.     if(f_dir[x] != '\\')
  696.         strcat(f_dir,"\\");
  697.     strcat(f_dir,&mask);
  698.     done=findfirst(&f_dir,(struct ffblk *)&dta,0xf7);
  699.     if(done) {
  700.         getcwd(curr_dir,67);
  701.         strcpy(f_dir,curr_dir);
  702.         x=strlen(curr_dir) -1;
  703.            if(f_dir[x] != '\\')
  704.             strcat(f_dir,"\\");
  705.         strcat(f_dir,&mask);
  706.         writef_n(0,13,reverse,b_line,67);
  707.         writef(0,13,reverse,curr_dir);
  708.     }
  709.     done=findfirst(&f_dir,(struct ffblk *)&dta,0xf7);
  710.     if(disk_err==1) exit(0);
  711.     while(!done) {
  712.         memcpy(&tblk[max],&dta.move,sizeof(dta.move));
  713.         dir_size = dir_size + tblk[max].my_size;
  714.         fnsplit(&tblk[max].my_name,drive,dir,fname,fext);
  715.         if(fext[0] == '.') s_str_lf(1,fext);
  716.         strip(&fext,' ');
  717.         if(tblk[max].my_attr & 0x10) {
  718.             strcpy(fname,&tblk[max].my_name);
  719.             strcpy(fext,"<DR>");
  720.         }
  721.         strcpy(&tblk[max].my_ext,fext);
  722.         strcpy(&tblk[max].my_fn,fname);
  723.         done=findnext((struct ffblk *)&dta);
  724.         max++;        
  725.         if(max > 499) {
  726.             printf("OUT OF MEMORY TO MANY FILES\n");
  727.             bioskey(0);
  728.             exit(0);
  729.         }
  730.     }
  731.     max--;
  732. }
  733.  
  734. show_em(int curr)
  735. {
  736.     int srow=4;
  737.     while(1) {
  738.         format_line(curr);
  739.         writef(srow,0,file_a,&outline);        
  740.         curr++; srow++;
  741.         if(curr > max) break;
  742.         if(srow > 23) return;
  743.     }
  744.     while(srow < 24) {
  745.         writef(srow,0,file_a,&b_line);
  746.         srow++;
  747.     }    
  748.     return;
  749. }
  750.  
  751. format_line(int curr)
  752. {
  753.         strcpy(pattr,rattr);        
  754.         if(tblk[curr].my_hour==00) {
  755.             tblk[curr].my_hour=12;
  756.             am_pm='p';                          
  757.         }
  758.         if(tblk[curr].my_hour > 12) {
  759.             am_pm='a';
  760.             tblk[curr].my_hour = tblk[curr].my_hour - 12;
  761.         }
  762.         else am_pm='p';
  763.         strcpy(pattr,"----");
  764.         if(tblk[curr].my_attr & 0x10)  strcpy(pattr,"    ");
  765.         if(tblk[curr].my_attr & 0x01)  pattr[0]='R';
  766.         if(tblk[curr].my_attr & 0x02)  pattr[1]='H';
  767.         if(tblk[curr].my_attr & 0x04)  pattr[2]='S';
  768.         if(tblk[curr].my_attr & 0x20)  pattr[3]='A';
  769.         sprintf(&outline,"%-8.8s %-4.4s%-36.36s %4.4s %10li  %2.2i:%2.2i%c %2.2i%2.2i%2.2i",
  770.             tblk[curr].my_fn,tblk[curr].my_ext,cmd_line[curr],pattr,tblk[curr].my_size,
  771.             tblk[curr].my_hour,tblk[curr].my_min,am_pm,
  772.             tblk[curr].my_month,tblk[curr].my_day,tblk[curr].my_year+80);
  773. }
  774.  
  775.  
  776. char *split_arg(char *cmd_arg)
  777. {
  778.     static char imask[15];
  779.     int idx;
  780.     disk_err=0;
  781.     strupr(cmd_arg);
  782.  
  783.     fnsplit(cmd_arg,&drive,&dir,&fname,&fext);
  784.     if(drive[0] != 0x00)
  785.         curr_drive=drive[0] - 'A';
  786.     else {
  787.         curr_drive=getdisk();
  788.         drive[0]=curr_drive + 'A';
  789.         drive[1]=':';
  790.         drive[2]=0x00;
  791.     }
  792.  
  793.     if(dir[0] != 0x00) {
  794.         idx=strlen(&dir) - 1;
  795.         if(idx>0) {
  796.             if(dir[idx] == '\\') {dir[idx]=0x00;}
  797.             if((fext[0]==0x00) && (fname[0] != 0x00)) {
  798.                 strcat(dir,"\\");
  799.                 strcat(dir,fname);
  800.                 fname[0]='\x00';
  801.             }
  802.         }
  803.         else {
  804.             if(fname[0] !=0x00) {
  805.                 strcat(dir,fname);
  806.                 fname[0]=0x00;
  807.             }
  808.         }
  809.     }
  810.  
  811.     strcpy(curr_dir,drive);
  812.     strcat(curr_dir,dir);
  813.  
  814.     if(fname[0] != 0x00) {
  815.         strcpy(&imask,&fname);
  816.         strcat(&imask,&fext);
  817.         return(&imask);
  818.     }
  819.     else return(NULL);
  820. }
  821.  
  822. do_sort()
  823. {
  824.     reset_cmd_line();
  825.     switch(sort_type) {
  826.         case('e'):
  827.             qsort(&tblk[0],max+1,sizeof(tblk[0]),sort_ext);
  828.             break;
  829.         case('n'):
  830.             qsort(&tblk[0],max+1,sizeof(tblk[0]),sort_name);
  831.             break;
  832.         case('s'):
  833.             qsort(&tblk[0],max+1,sizeof(tblk[0]),sort_size);
  834.             break;
  835.         case('d'):
  836.             qsort(&tblk[0],max+1,sizeof(tblk[0]),sort_date);
  837.             break;
  838.     }
  839. }
  840.  
  841. do_foot()
  842. {
  843.     static int okey_stat = 3;
  844.     static int ckey_stat = 3;
  845.     if(bioskey(2) & 0x08) ckey_stat=1;
  846.     else
  847.         if(bioskey(2) & 0x04) ckey_stat=2;
  848.     else
  849.         ckey_stat=0;
  850.     if(ckey_stat == okey_stat)
  851.         return;
  852.     okey_stat = ckey_stat;
  853.     if(ckey_stat==1) writef(24,0,foot_a2,foota);
  854.     else
  855.     if(ckey_stat==2) writef(24,0,foot_a3,footc);
  856.     else {
  857.         writef(24,0,foot_a,foot);
  858.         highlite_foot();
  859.     }
  860. }
  861.  
  862. highlite_foot()
  863. {
  864.     rcolor(24,48,foot_a,32);
  865.     switch (sort_type) {
  866.         case 'n':
  867.             rcolor(24,48,foot_ah,8);
  868.             break;
  869.         case 'e':
  870.             rcolor(24,56,foot_ah,8);
  871.             break;
  872.         case 's':
  873.             rcolor(24,64,foot_ah,8);
  874.             break;
  875.         case 'd':
  876.             rcolor(24,72,foot_ah,8);
  877.             break;
  878.     }
  879. }
  880.  
  881. set_file_atr(int idx)
  882. {
  883.     char new_attr;
  884.     int x;
  885.     new_attr=0x00;
  886.     for(x=0;x<4;x++) {
  887.         if(fattr[x]=='H') new_attr=new_attr | FA_HIDDEN;
  888.         if(fattr[x]=='R') new_attr=new_attr | FA_RDONLY;
  889.         if(fattr[x]=='S') new_attr=new_attr | FA_SYSTEM;
  890.         if(fattr[x]=='A') new_attr=new_attr | FA_ARCH;
  891.     }
  892.     tblk[idx].my_attr=_chmod(&tblk[idx].my_name,1,new_attr);
  893. }
  894.     
  895. reset_cmd_line()
  896. {
  897.     int idx;
  898.     for(idx=0;idx < 500;idx++) cmd_line[idx][0]=0x00;
  899. }
  900.  
  901.  
  902. get_cfg_file()
  903. {
  904.     char *pt1, *pt2, *pt3;
  905.     char *buff, *path;
  906.     int idx, type;
  907.     FILE *in;
  908.     path=(char *)searchpath("fm.cfg");
  909.     if(!path) return;
  910.     buff=(char *)malloc(200);
  911.     in=fopen(path,"rt");
  912.     while(fgets(buff,100,in)) {    
  913.         if(*buff=='*') {
  914.             continue;
  915.         }
  916.         strupr(buff);
  917.         pt1=(char *)strtok(buff,"#");
  918.         pt2=(char *)strtok(NULL,"#");
  919.         pt3=(char *)strtok(NULL,"#");
  920.         if(pt1==NULL | pt2==NULL | pt3==NULL) continue;
  921.         if(!strncmp(pt1,"AF",2)) type=3;
  922.         else
  923.             if(!strncmp(pt1,"CF",2)) type=4;
  924.         else
  925.             if(*pt1=='F') type=2;
  926.         else
  927.             if(*pt1=='A') type=1;
  928.         else type=0;
  929.         switch (type) {
  930.             case(1):
  931.                 idx=atoi(pt1+1)-1;
  932.                 if(idx < 0 | idx > 9) break;
  933.                 strcpy(auto_key_ext[idx],pt2);
  934.                 strcpy(auto_key_cmd[idx],pt3);
  935.                 break;
  936.             case(2):
  937.                 idx=atoi(pt1+1) - 1;
  938.                 if(idx < 0 | idx > 6) break;
  939.                 strcpy(fkeyp[idx],pt2);
  940.                 strcpy(fkeyc[idx],pt3);
  941.                 break;
  942.             case(3):
  943.                 idx=atoi(pt1+2)-1;
  944.                 if(idx < 0 | idx > 9) break;
  945.                 strcpy(afkeyp[idx],pt2);
  946.                 strcpy(afkeyc[idx],pt3);
  947.                 break;
  948.             case(4):
  949.                 idx=atoi(pt1+2)-1;
  950.                 if(idx < 0 | idx > 9) break;
  951.                 strcpy(cfkeyp[idx],pt2);
  952.                 strcpy(cfkeyc[idx],pt3);
  953.                 break;
  954.         }                
  955.     }
  956.     fclose(in);
  957.     free(buff);
  958. }
  959.  
  960.  
  961. help()
  962. {    
  963.     int orow, ocol, x;
  964.     save_scr(0,0,24,79,save_screen);
  965.     get_cur(&orow,&ocol);
  966.     clr(normal);
  967.     locate(0,0);
  968.     printf("Current Function Key Definitions\n");
  969.     for(x=0;x<10;x++) {
  970.         printf("F%-2.2d = %-4.4s = %-19.19s\n",x+1,fkeyp[x],fkeyc[x]);
  971.     }
  972.     printf("\nCurrent ALT Function Key Definitions\n");
  973.     for(x=0;x<10;x++) {
  974.         printf("F%-2.2d = %-4.4s = %-19.19s\n",x+1,afkeyp[x],afkeyc[x]);
  975.     }
  976.     locate(0,38);
  977.     printf("│Current Auto-commands ALT-A");
  978.     for(x=0;x<10;x++) {
  979.         locate(x+1,38);
  980.         printf("│EXT=%3.3s CMD=%-19.19s",auto_key_ext[x],auto_key_cmd[x]);
  981.     }
  982.     rcolor(0,0,foot_ah,80);
  983.     locate(12,38);printf("│PERMANENT KEY DEFITIONS");
  984.     locate(13,38);printf("│ALT-A = Exit to DOS");
  985.     locate(14,38);printf("│ALT-D = Change Directory");
  986.     locate(15,38);printf("│ALT-M = Change file mask");
  987.     locate(16,38);printf("│ALT-P = Execute highlited file");
  988.     locate(17,38);printf("│ALT-Q = Exit to current DIR");
  989.     locate(18,38);printf("│ALT-R = Re-Read the Directory");
  990.     locate(19,38);printf("│ALT-T = Tag all files");
  991.     locate(20,38);printf("│ALT-S = Calc DIR Sizes");
  992.     locate(21,38);printf("│ALT-X = Exit to DOS");
  993.     locate(22,38);printf("│TAB   = Modify File ATTRS");
  994.     locate(23,38);printf("│ESC   = Quit FM");
  995.     rcolor(12,0,foot_ah,80);
  996.     locate(24,20);printf("Strike any key to continue");
  997.     bioskey(0);    
  998.     rest_scr(0,0,24,79,save_screen);
  999.     locate(&orow,&ocol);
  1000. }
  1001.