home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm14.lzh / misc.c < prev    next >
Text File  |  1996-08-31  |  26KB  |  1,036 lines

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