home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm.lzh / misc.c < prev    next >
Text File  |  1995-11-14  |  24KB  |  926 lines

  1. /* miscellaneous commands */
  2. /* file: misc.c           */
  3.  
  4. #include <stdio.h>
  5. #include <modes.h>
  6. #include <strings.h>
  7. #include <errno.h>
  8. #include <direct.h>
  9. #include <sgstat.h>
  10. #include "screen.h"
  11. #include "diskmaster.h"
  12.  
  13. commands()
  14. {
  15.        gotoxy(1,24);
  16.        flush_kbd();
  17.        cleol();
  18.        printf(" Attr Copy Rename Del Newdir Makdir mOve Tag/untag List Unarc Help Quit Shell");
  19.        foreground(RED);
  20.        gotoxy(2,24);
  21.        putc('A',stdout);
  22.        gotoxy(7,24);
  23.        putc('C',stdout);
  24.        gotoxy(12,24);
  25.        putc('R',stdout);
  26.        gotoxy(19,24);
  27.        putc('D',stdout);
  28.        gotoxy(23,24);
  29.        putc('N',stdout);
  30.        gotoxy(30,24);
  31.        putc('M',stdout);
  32.        gotoxy(38,24);
  33.        putc('O',stdout);
  34.        gotoxy(42,24);
  35.        putc('T',stdout);
  36.        gotoxy(52,24);
  37.        putc('L',stdout);
  38.        gotoxy(57,24);
  39.        putc('U',stdout);
  40.        gotoxy(63,24);
  41.        putc('H',stdout);
  42.        gotoxy(68,24);
  43.        putc('Q',stdout);
  44.        gotoxy(73,24);
  45.        putc('S',stdout);
  46.        gotoxy(1,24);
  47.        foreground(WHITE);
  48. }
  49.  
  50. char *
  51. getcwd(linebuf,len)
  52. char *linebuf;
  53. int len;
  54. {
  55.        char *command = "pd >/pipe/getcwdpipe";
  56.        char *getcwdpipe, *endln;
  57.        int pipe_path;
  58.        
  59.        /* create named pipe */
  60.        
  61.        getcwdpipe = index(command,'/');
  62.        
  63.        /* start up the command */
  64.        
  65.        system(command);
  66.        
  67.        /* pipe the output to string linebuf */
  68.        
  69.        if((pipe_path = open(getcwdpipe,S_IREAD)) == -1) {
  70.               open_err(getcwdpipe,errno);
  71.               return(NULL);
  72.        }
  73.        *linebuf = '\0';
  74.        read(pipe_path,linebuf,len);
  75.        if((endln = index(linebuf,'\n')) < linebuf + len) {
  76.               *endln = '\0';
  77.        }
  78.        
  79.        /* terminate */
  80.        
  81.        close(pipe_path);
  82.        unlink(getcwdpipe);
  83.        return(linebuf);
  84. }
  85.  
  86. tagfile(pos,tagged)
  87. int pos;
  88. int *tagged;
  89. {
  90.        extern short *attrptr;
  91.        
  92.        if(attrptr[pos] == TAG) {
  93.                attrptr[pos] &= 0xFF;
  94.                *tagged -= 1;
  95.        } else {
  96.                attrptr[pos] += TAG;
  97.                *tagged += 1;
  98.        }
  99. }
  100.  
  101. int
  102. copy(pos)
  103. int pos;
  104. {
  105.        extern char **nameptr;
  106.        extern short *attrptr;
  107.        char *copycmd;
  108.        char *copyparam, *malloc();
  109.        int ch;
  110.        int rewrite;
  111.        
  112.        gotoxy(1,24);
  113.        cleol();
  114.        
  115.        if((attrptr[pos] & 0x80) == 0x80) {
  116.               printf("%c     Can't copy directories",7);
  117.               sleep(5);
  118.               commands();
  119.               return(FAIL);
  120.        }
  121.        
  122.        copyparam = malloc(256);
  123.        copycmd = malloc(256);
  124.        strcpy(copycmd,"copy ");
  125.        printf("     %cCOPY %s TO: ",7,nameptr[pos]);
  126.        lineinput(copyparam,80);
  127.        if(*copyparam == '\0') {
  128.               free(copycmd);
  129.               free(copyparam);
  130.               commands();
  131.               return(FAIL);
  132.        }
  133.        
  134.        if(access(copyparam,S_IFDIR+S_IREAD+S_IWRITE) == 0) {
  135.               strcat(copyparam,"/");
  136.               strcat(copyparam,nameptr[pos]);
  137.               if(access(copyparam,S_IREAD+S_IWRITE) == 0) {
  138.                      gotoxy(1,24);
  139.                      cleol();
  140.                      printf("     %c%s EXISTS! Overwrite? (y/N)",7,copyparam);
  141.                      do {
  142.                             ch = toupper(getchar());
  143.                             flush_kbd();
  144.                      } while ((ch != 'Y') && (ch != 'N') && (ch != '\n'));
  145.                      if(ch == 'Y') {
  146.                             strcat(copycmd,"-r ");
  147.                      } else {
  148.                             free(copycmd);
  149.                             free(copyparam);
  150.                             commands();
  151.                             return(FAIL);
  152.                      }
  153.               }
  154.               *(rindex(copyparam,'/')) = '\0';
  155.               rewrite = FAIL;
  156.               strcat(copycmd,"-w=");
  157.               strcat(copycmd,copyparam);
  158.               strcat(copycmd," ");
  159.               strcat(copycmd,nameptr[pos]);
  160.        } else if (access(copyparam,S_IREAD+S_IWRITE) != 0) {
  161.               rewrite = PASS;
  162.               strcat(copycmd,nameptr[pos]);
  163.               strcat(copycmd," ");
  164.               strcat(copycmd,copyparam);
  165.        } else {
  166.               gotoxy(1,24);
  167.               cleol();
  168.               printf("     %c%s EXISTS! Overwrite? (y/N)",7,copyparam);
  169.               do {
  170.                      ch = toupper(getchar());
  171.                      flush_kbd();
  172.               } while ((ch != 'Y') && (ch != 'N') && (ch != '\n'));
  173.               if(ch == 'Y') {
  174.                      strcat(copycmd,"-r ");
  175.                      strcat(copycmd,nameptr[pos]);
  176.                      strcat(copycmd," ");
  177.                      strcat(copycmd,copyparam);
  178.                      if(index(copyparam,'/') != NULL) {
  179.                             rewrite = FAIL;
  180.                      }
  181.               } else {
  182.                      free(copycmd);
  183.                      free(copyparam);
  184.                      commands();
  185.                      return(FAIL);
  186.               }
  187.        }
  188.        strcat(copycmd," >>>/nil");
  189.  
  190.        system(copycmd);
  191.        free(copycmd);
  192.        free(copyparam);
  193.        commands();
  194.        return(rewrite);
  195. }
  196.  
  197. int
  198. lineinput(copyparam,len)
  199. char copyparam[];
  200. int len;
  201. {
  202.        int ch, i = 0;
  203.        
  204.        while (--len > 0 && (ch = getc(stdin)) != '\n' && ch != 0x1b) {
  205.                if (ch == '\b')  {
  206.                       if(--i >= 0) {
  207.                              putc(ch,stdout);
  208.                              putc(' ',stdout);
  209.                              putc(ch,stdout);
  210.                              len++;
  211.                              continue;
  212.                        } else {
  213.                               len++;
  214.                               continue;
  215.                        }
  216.                }
  217.                copyparam[i++] = ch;
  218.                putc(ch,stdout);
  219.        }
  220.        if(ch == 0x1b) {
  221.               *copyparam = '\0';
  222.               return(FAIL);
  223.        }
  224.        copyparam[i] = '\0';
  225.        return(PASS);
  226. }
  227.  
  228. int
  229. delete(pos)
  230. int pos;
  231. {
  232.        char *delcmd, *malloc();
  233.        char ch;
  234.        extern char **nameptr;
  235.        extern short *attrptr;
  236.        int dir = 0;
  237.        
  238.        if(pos == 0) {
  239.               gotoxy(1,24);
  240.               cleol();
  241.               printf("     %cCan't delete directory '..'",7);
  242.               sleep(5);
  243.               commands();
  244.               return(FAIL);
  245.        }
  246.        
  247.        delcmd = malloc(256);
  248.        if((attrptr[pos] & 0x80) == 0x80) {
  249.               strcpy(delcmd,"deldir -q ");
  250.               dir = 1;
  251.        } else {
  252.               strcpy(delcmd,"del ");
  253.        }
  254.        
  255.        gotoxy(1,24);
  256.        cleol();
  257.        printf("     %cDELETE %s ",7,(dir==0) ? "file" : "directory");
  258.        foreground(RED);
  259.        printf("%s",nameptr[pos]);
  260.        foreground(WHITE);
  261.        printf(" - ARE YOU SURE ? ");
  262.        ch = getc(stdin);
  263.        flush_kbd();
  264.        if(toupper(ch) != 'Y') {
  265.               free(delcmd);
  266.               commands();
  267.               return(FAIL);
  268.        }
  269.        gotoxy(1,24);
  270.        cleol();
  271.        printf("     DELETING: %s",nameptr[pos]);
  272.        if(dir == 1) {
  273.                  strcat(delcmd,nameptr[pos]);
  274.               strcat(delcmd," >>/nil");
  275.               system(delcmd);
  276.        } else {
  277.                  unlink(nameptr[pos]);
  278.        }
  279.        free(delcmd);
  280.        sleep(1);
  281.        commands();
  282.        return(PASS);
  283. }
  284.  
  285. int
  286. changedir(dirname,pos)
  287. char *dirname;
  288. int pos;
  289. {
  290.        extern char **nameptr;
  291.        extern short *attrptr;
  292.        
  293.        gotoxy(1,24);
  294.        cleol();
  295.        
  296.        if(pos != -1) {
  297.               if((attrptr[pos] & 0x80) != 0x80) {
  298.                      printf("%c     %s is not a directory",7,nameptr[pos]);
  299.                      sleep(5);
  300.                      commands();
  301.                      return(FAIL);
  302.               }
  303.        
  304.               strcpy(dirname,nameptr[pos]);
  305.               if(strcmp(dirname,"==PARENT==") == 0) {
  306.                      strcpy(dirname,"..");
  307.               }
  308.        }
  309.        chdir(dirname);
  310.        strcpy(dirname,".");
  311.        commands();
  312.        return(PASS);
  313. }
  314.  
  315. int
  316. logdev(dirname)
  317. char *dirname;
  318. {
  319.        char temp[32];
  320.        int success;
  321.        
  322.        gotoxy(1,24);
  323.        cleol();
  324.        printf("%c     Change Device to: ",7);
  325.        success = lineinput(temp,32);
  326.        if(success == FAIL) {
  327.               commands();
  328.               return(FAIL);
  329.        }
  330.        if(access(temp,S_IFDIR+S_IREAD) != 0) {
  331.               open_err(temp,errno);
  332.               commands();
  333.               return(FAIL);
  334.        }
  335.        strcpy(dirname,temp);
  336.        commands();
  337.        return(PASS);
  338. }
  339.  
  340. #define DIRPERM S_IFDIR+S_IREAD+S_IWRITE+S_IEXEC+S_IOREAD+S_IOWRITE+S_IOEXEC
  341.  
  342. int
  343. makedir()
  344. {
  345.        char *dirpath, *malloc();
  346.        int x, success;
  347.        
  348.        dirpath = malloc(256);
  349.        
  350.        gotoxy(1,24);
  351.        cleol();
  352.        printf("     Directory to create: ");
  353.        success = lineinput(dirpath,54);
  354.        if((success == FAIL) || (*dirpath == '\0')) {
  355.               free(dirpath);
  356.               commands();
  357.               return(FAIL);
  358.        }
  359.        if(access(dirpath,S_IREAD) != 0) {
  360.               if(access(dirpath,S_IFDIR+S_IREAD) != 0) {
  361.                      for(x=0;x<=strlen(dirpath);x++) {
  362.                             *(dirpath+x) = toupper(*(dirpath+x));
  363.                      }
  364.                      gotoxy(1,24);
  365.                      cleol();
  366.                      printf("     Creating directory: ");
  367.                      foreground(RED);
  368.                      printf("%s",dirpath);
  369.                      foreground(WHITE);
  370.                      if(makdir(dirpath,S_IREAD|S_IWRITE,DIRPERM) != 0) {
  371.                             creat_err(dirpath,errno);
  372.                             free(dirpath);
  373.                             commands();
  374.                             return(FAIL);
  375.                      } else {
  376.                             free(dirpath);
  377.                             sleep(1);
  378.                             commands();
  379.                             return(PASS);
  380.                      }
  381.               }
  382.        }
  383.        commands();
  384.        free(dirpath);
  385.        return(FAIL);
  386. }
  387.  
  388. int
  389. attr(pos)
  390. int pos;
  391. {
  392.        extern char **nameptr;
  393.        extern char **fildesptr;
  394.        struct fildes fdes, *fdptr;
  395.        char *attrcmd, *malloc();
  396.        char attr[9];
  397.        char *newattr;
  398.        char *pipe_file = "mdattrXXXXXX";
  399.        char *pipeptr;
  400.        int pipe_path, success, path;
  401.        
  402.        fdptr = &fdes;
  403.        attrcmd = malloc(80);
  404.        newattr = malloc(30);
  405.        mktemp(pipe_file);
  406.        strcpy(attrcmd,"attr ");
  407.        strcat(attrcmd,nameptr[pos]);
  408.        strcat(attrcmd," >/pipe/");
  409.        strcat(attrcmd,pipe_file);
  410.        
  411.        system(attrcmd);
  412.        
  413.        pipeptr = index(attrcmd,'/');
  414.        if((pipe_path = open(pipeptr,S_IREAD)) == -1) {
  415.               open_err(pipeptr,errno);
  416.               return(FAIL);
  417.        }
  418.        attr[0] = '\0';
  419.        read(pipe_path,attr,8);
  420.        attr[8] = '\0';
  421.        close(pipe_path);
  422.        unlink(pipeptr);
  423.        gotoxy(1,24);
  424.        cleol();
  425.        printf("     %cAttributes of %s are: %s. Change to: ",7,nameptr[pos],attr);
  426.        success = lineinput(newattr,30);
  427.        if((success == FAIL) || (*newattr == '\0')) {
  428.               free(attrcmd);
  429.               free(newattr);
  430.               commands();
  431.               return(FAIL);
  432.        }
  433.        if((index(newattr,'d') != NULL) || (index(newattr,'D') != NULL)) {
  434.               gotoxy(1,24);
  435.               cleol();
  436.               printf("     %cERROR: Can't add or remove directory attribute",7);
  437.               sleep(2);
  438.               free(attrcmd);
  439.               free(newattr);
  440.               commands();
  441.               return(FAIL);
  442.        }
  443.        strcpy(attrcmd,"attr ");
  444.        strcat(attrcmd,nameptr[pos]);
  445.        strcat(attrcmd," ");
  446.        strcat(attrcmd,newattr);
  447.        strcat(attrcmd," >>>/nil");
  448.        
  449.        system(attrcmd);
  450.        if((path = open(nameptr[pos],S_IREAD)) == -1) {
  451.                if((path = open(nameptr[pos],S_IFDIR+S_IREAD)) == -1) {
  452.                       ;
  453.                }
  454.        }
  455.        if(path != -1) {
  456.               _gs_gfd(path,fdptr,sizeof(fdes));
  457.               _strass(fildesptr[pos],fdptr,sizeof(fdes));
  458.               close(path);
  459.        }
  460.        get_info(pos);
  461.        commands();
  462.        free(attrcmd);
  463.        free(newattr);
  464.        return(PASS);
  465. }
  466.  
  467. int
  468. list(pos)
  469. int pos;
  470. {
  471.     FILE *infile, *fopen();
  472.     char filename[32];
  473.     int inchr, ch, x, count = 0;
  474.     char *buffer, *line;
  475.     extern char **nameptr;
  476.     extern struct sgbuf buff;
  477.     char *anykey = "Press any key...";
  478.     
  479.     if(pos == HELP) {
  480.         strcpy(filename,"/dd/sys/dm.hlp");
  481.     } else {
  482.         strcpy(filename,nameptr[pos]);
  483.     }
  484.  
  485.     if((infile = fopen(filename,"r")) == NULL) {
  486.         gotoxy(1,24);
  487.         cleol();
  488.         printf("     Can't open %s",filename);
  489.         sleep(2);
  490.         commands();
  491.         return(FAIL);
  492.     }
  493.  
  494.     gotoxy(1,24);
  495.     cleol();
  496.     if(pos == HELP) {
  497.         printf("     Help is on the way...");
  498.     } else {
  499.         printf("     Listing file: %s",nameptr[pos]);
  500.     }
  501.  
  502.     buffer = malloc(80);
  503.     line = buffer;
  504.  
  505.     while((inchr = fgetc(infile)) != EOF) {
  506.         if(inchr == '\t') {
  507.             if((line-buffer) > (78 - (int)(buff.sg_tabsiz))) {
  508.                 ungetc(inchr,infile);
  509.                 inchr = '\n';
  510.             } else {
  511.                 for(x=0;x<(int)(buff.sg_tabsiz);x++) {
  512.                     *(line++) = ' ';
  513.                 }
  514.                 continue;
  515.             }
  516.         }
  517.         if(inchr == '\l') {
  518.             if(line == buffer) {    /* ignore LF if it is after a CR */
  519.                 continue;
  520.             } else {
  521.                 inchr = '\n';        /* change it to CR if not */
  522.             }
  523.         }
  524.         if(inchr == '\f') {            /* ignore FF char */
  525.             continue;
  526.         }
  527.         if(inchr == '\n') {
  528.             *(line++) = '\0';
  529.             gotoxy(2,count+3);
  530.             printf("%s",buffer);
  531.             line = buffer;
  532.             if(++count > MAXCNT -2) {
  533.                 gotoxy(2,22);
  534.                 printf("%s",anykey);
  535.                 ch = waitkey();
  536.                 if((ch == 'Q') || (ch == 3) || (ch == 0x1b)) {
  537.                     fclose(infile);
  538.                     clearwin(2,3,78,20);
  539.                     commands();
  540.                     return(PASS);
  541.                 }
  542.                 count = 0;
  543.                 clearwin(2,3,78,20);
  544.             }
  545.             continue;
  546.         }
  547.         if((line - buffer) < 78) {
  548.             *(line++) = inchr;
  549.         } else {
  550.             ungetc(inchr,infile);
  551.             *(line++) = '\0';
  552.             gotoxy(2,count+3);
  553.             printf("%s",buffer);
  554.             if(++count > MAXCNT -2) {
  555.                 gotoxy(2,22);
  556.                 printf("%s",anykey);
  557.                 ch = waitkey();
  558.                 if((ch == 'Q') || (ch == 3) || (ch == 0x1b)){
  559.                     fclose(infile);
  560.                     clearwin(2,3,78,20);
  561.                     commands();
  562.                     return(PASS);
  563.                 }
  564.                 count = 0;
  565.                 clearwin(2,3,78,20);
  566.             }
  567.             line = buffer;
  568.         }
  569.     }
  570.     gotoxy(2,22);
  571.     printf("%s",anykey);
  572.     ch = waitkey();
  573.     fclose(infile);
  574.     clearwin(2,3,78,20);
  575.     commands();
  576.     return(PASS);
  577. }
  578.  
  579. int
  580. waitkey()
  581. {
  582.     int ch=0, lb=0, rb=0, mx, my;
  583.     extern int mouse;
  584.  
  585.     do {
  586.         if(_gs_rdy(STDIN) > 0) {
  587.             ch = toupper(getc(stdin));
  588.             flush_kbd();
  589.         } else {
  590.             if(!mouse) {
  591.                 if(MsReady()) {
  592.                     MsRdAbs(&lb, &rb, &mx, &my);
  593.                     gotoxy(mx,my);
  594.                 }
  595.             }
  596.         }
  597.     } while((ch == 0) && (!lb) && (!rb));
  598.     if(rb) return('Q');
  599.     if(lb) return(' ');
  600.     return(ch);
  601. }
  602.  
  603. int
  604. move(pos)
  605. int pos;
  606. {
  607.        extern char **nameptr;
  608.        extern short *attrptr;
  609.        
  610.        int dpath, success, ch;
  611.        char *olddev;
  612.        char *newdev;
  613.        char *olddir;
  614.        char *newdir;
  615.        char *movcmd;
  616.        char *destpath;
  617.        char *malloc();
  618.        
  619.        olddev = malloc(32);
  620.        newdev = malloc(32);
  621.        olddir = malloc(256);
  622.        newdir = malloc(256);
  623.        movcmd = malloc(256);
  624.        destpath = malloc(256);
  625.        
  626.        gotoxy(1,24);
  627.        cleol();
  628.        printf("     Move %s to: ",nameptr[pos]);
  629.        success = lineinput(newdir,80);
  630.        if((success == FAIL) || (*newdir == '\0')) {
  631.               free(olddev);
  632.               free(newdev);
  633.               free(olddir);
  634.               free(newdir);
  635.               free(movcmd);
  636.               return(FAIL);
  637.        }
  638.        getcwd(olddir,256);
  639.        dpath = open("@",S_IREAD);
  640.        _gs_devn(dpath,olddev);
  641.        close(dpath);
  642.        if(chdir(newdir) == FAIL) {
  643.               open_err(newdir,errno);
  644.               free(olddev);
  645.               free(newdev);
  646.               free(olddir);
  647.               free(newdir);
  648.               free(movcmd);
  649.               free(destpath);
  650.               return(FAIL);
  651.        }
  652.        dpath = open("@",S_IREAD);
  653.        _gs_devn(dpath,newdev);
  654.        close(dpath);
  655.        if(strcmp(olddev,newdev) != 0) {
  656.               gotoxy(1,24);
  657.               cleol();
  658.               printf("     %cCan't move to different device.",7);
  659.               sleep(5);
  660.               chdir(olddir);
  661.               commands();
  662.               free(olddev);
  663.               free(newdev);
  664.               free(olddir);
  665.               free(newdir);
  666.               free(movcmd);
  667.               free(destpath);
  668.               return(FAIL);
  669.        }
  670.        chdir(olddir);
  671.        strcpy(destpath,newdir);
  672.        strcat(destpath,"/");
  673.        strcat(destpath,nameptr[pos]);
  674.        if(access(destpath,S_IREAD+S_IWRITE) == 0) {
  675.               gotoxy(1,24);
  676.               cleol();
  677.               printf("     %cFile already exists at destination.",7);
  678.               sleep(5);
  679.               commands();
  680.               free(olddev);
  681.               free(newdev);
  682.               free(olddir);
  683.               free(newdir);
  684.               free(movcmd);
  685.               free(destpath);
  686.               return(FAIL);
  687.        }
  688.        strcpy(movcmd,"move ");
  689.        strcat(movcmd,nameptr[pos]);
  690.        strcat(movcmd," ");
  691.        strcat(movcmd,newdir);
  692.        strcat(movcmd," >>>/nil");
  693.        system(movcmd);
  694.        commands();
  695.        free(olddev);
  696.        free(newdev);
  697.        free(olddir);
  698.        free(newdir);
  699.        free(movcmd);
  700.        return(PASS);
  701. }
  702.  
  703. int
  704. renfile(pos)
  705. int pos;
  706. {
  707.        extern char **nameptr;
  708.        char *newname;
  709.        char *malloc();
  710.        int success;
  711.        
  712.        gotoxy(1,24);
  713.        cleol();
  714.        newname = malloc(32);
  715.        printf("     %cRENAME %s TO: ",7,nameptr[pos]);
  716.        lineinput(newname,32);
  717.        if(*newname == '\0') {
  718.               free(newname);
  719.               commands();
  720.               return(FAIL);
  721.        }
  722.        if(index(newname,'/') == NULL) {
  723.               success = rename(nameptr[pos],newname);
  724.               if(success != 0) {
  725.                          gotoxy(1,24);
  726.                          cleol();
  727.                          printf("     %cRename failed.",7);
  728.                          if(errno == 218) {
  729.                                 printf(" File already exists!");
  730.                          } else {
  731.                                 printf(" Error %d",errno);
  732.                          }
  733.                          sleep(1);
  734.                          free(newname);
  735.                          commands();
  736.                          return(FAIL);
  737.                } else {
  738.                          strcpy(nameptr[pos],newname);
  739.                          free(newname);
  740.                       commands();
  741.                       return(PASS);
  742.                }
  743.        }
  744.        gotoxy(1,24);
  745.        cleol();
  746.        printf("     Can't rename %s to %s",nameptr[pos],newname);
  747.        sleep(1);
  748.        commands();
  749.        free(newname);
  750.        return(FAIL);
  751. }
  752.  
  753. info_screen()
  754. {
  755.        gotoxy(48,2);
  756.        putc(DTOP_TEE,stdout);
  757.        gotoxy(48,23);
  758.        putc(DBOT_TEE,stdout);
  759.        vert_doub(48,3,20);
  760.        gotoxy(56,3);
  761.        foreground(GREEN);
  762.        printf("File Information");
  763.        gotoxy(60,5);
  764.        printf("Filename");
  765.        gotoxy(59,7);
  766.        printf("Attributes");
  767.        gotoxy(57,10);
  768.        printf("Creation date");
  769.        gotoxy(57,12);
  770.        printf("Last modified");
  771.        foreground(WHITE);
  772. }
  773.  
  774. union fsize {
  775.     char asize[4]; 
  776.     long lsize; 
  777. };
  778.  
  779. int
  780. get_info(pos)
  781. int pos;
  782. {
  783.        extern char **nameptr;
  784.        extern char **fildesptr;
  785.        int scr_x, i;
  786.        struct fildes fdes, *desptr;
  787.        int path;
  788.        char attr[9];
  789.        char *spaces = "                               ";
  790.        char *getattr();
  791.        char *filename, *length, *malloc();
  792.        union fsize f;
  793.        
  794.        strcpy(attr,"dsewrewr");
  795.        desptr = &fdes;
  796.        filename = malloc(32);
  797.        length = malloc(32);
  798.        if(strcmp(nameptr[pos],"==PARENT==") == 0) {
  799.               strcpy(filename,"..");
  800.        } else {
  801.               strcpy(filename,nameptr[pos]);
  802.        }
  803.        
  804.        _strass(desptr,fildesptr[pos],sizeof(fdes));
  805.        scr_x = 48 + ((32 - strlen(filename))/2);
  806.        gotoxy(49,6);
  807.        printf(spaces);
  808.        gotoxy(scr_x,6);
  809.        printf("%s",filename);
  810.        gotoxy(60,8);
  811.        printf("%s",getattr(attr,fdes.fd_att));
  812.        gotoxy(49,9);
  813.        printf(spaces);
  814.        for(i=0;i<4;i++) f.asize[i] = fdes.fd_fsize[i];
  815.        sprintf(length,"Length: %ld bytes",f.lsize);
  816.        scr_x = 48 + ((32 - strlen(length))/2);
  817.        gotoxy(scr_x,9);
  818.        foreground(GREEN);
  819.        printf("Length:");
  820.        length = index(length,' ');
  821.        foreground(WHITE);
  822.        printf("%s",length);
  823.        gotoxy(60,11);
  824.        printf("%02d/%02d/%02d",fdes.fd_dcr[0],fdes.fd_dcr[1],fdes.fd_dcr[2]);
  825.        gotoxy(57,13);
  826.        printf("%02d/%02d/%02d %02d:%02d",fdes.fd_date[0],fdes.fd_date[1],fdes.fd_date[2],fdes.fd_date[3],fdes.fd_date[4]);
  827.        free(length);
  828.        free(filename);
  829.        return(PASS);
  830. }
  831.  
  832. char *
  833. getattr(attr,byte)
  834. char *attr;
  835. char byte;
  836. {
  837.     int i, j, k;
  838.  
  839.     for (i=0, j=128;i<8;i++,j/=2) {
  840.         k = byte & j;
  841.         if(!(k))
  842.             attr[i] = '-';
  843.     }
  844.     return(attr);
  845. }
  846.  
  847. freedev()
  848. {
  849.     int dpath, in, ppath;
  850.     char *inline, *dev, *freecmd, *pipepath, *malloc();
  851.     char *chrptr;
  852.     char pipename[10];
  853.     char *blanks = "                              ";
  854.     
  855.     dev = malloc(32);
  856.     dpath = open("@",S_IREAD);
  857.     _gs_devn(dpath,dev);
  858.     close(dpath);
  859.     
  860.     freecmd = malloc(32);
  861.     inline = malloc(80);
  862.     strcpy(pipename,"dm_XXXXXX");
  863.     strcpy(freecmd,"free /");
  864.     strcat(freecmd,dev);
  865.     strcat(freecmd," ");
  866.     strcat(freecmd,">>/nil >/pipe/");
  867.     strcat(freecmd,mktemp(pipename));
  868.     strcat(freecmd,"&");
  869.     foreground(BLUE);    /* to hide the process number */
  870.     gotoxy(49,19);
  871.     system(freecmd);
  872.     foreground(WHITE);
  873.     
  874.     freecmd[strlen(freecmd)-1] = '\0';
  875.     pipepath = rindex(freecmd,'>') + 1;
  876.     ppath = open(pipepath,S_IREAD);
  877.     if(ppath == -1) {
  878.         free(freecmd);
  879.         free(inline);
  880.         gotoxy(50,19);
  881.         printf("     Can't get size of /%s",dev);
  882.         free(dev);
  883.         return(0);
  884.     }
  885.     in = readln(ppath,inline,80);
  886.     in = readln(ppath,inline,80);
  887.     *(inline + in) = '\0';
  888.     chrptr = index(inline,'(');
  889.     if(chrptr == NULL) {
  890.         close(ppath);
  891.         unlink(pipepath);
  892.         free(freecmd);
  893.         free(inline);
  894.         gotoxy(50,19);
  895.         printf("     Can't get size of /%s",dev);
  896.         free(dev);
  897.         return(0);
  898.     }
  899.     *(chrptr) = '\0';
  900.     gotoxy(49,19);
  901.     printf("%s",blanks);
  902.     gotoxy(49+((31-strlen(inline))/2),19);
  903.     printf("%s",inline);
  904.     in = readln(ppath,inline,80);
  905.     *(inline + in) = '\0';
  906.     *(index(inline,',')) = '\0';
  907.     gotoxy(49,20);
  908.     printf("%s",blanks);
  909.     gotoxy(49+((31-strlen(inline))/2),20);
  910.     printf("%s",inline);
  911.     in = readln(ppath,inline,80);
  912.     *(inline + in) = '\0';
  913.     *(index(inline,' ')) = '\0';
  914.     gotoxy(49,21);
  915.     printf("%s",blanks);
  916.     gotoxy(49+((31-(strlen(inline)+11))/2),21);
  917.     printf("%s free bytes",inline);
  918.     close(ppath);
  919.     unlink(pipepath);
  920.     free(dev);
  921.     free(freecmd);
  922.     free(inline);
  923. }
  924.  
  925. /* EOF misc.c */
  926.