home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / irit / drawfn3s / dir-graf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-06  |  5.0 KB  |  157 lines

  1. /******************************************************************************
  2. * Procedures to print/change the current directory.                  *
  3. * Both routine assume the usage of GraphGen.c graphic module, and use the     *
  4. * MenuArea (MSG_AREA_X/Y) as i/o (print and read).                  *
  5. *                                          *
  6. *                Ver 0.2        Gershon Elber          May. 89 *
  7. ******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <dir.h>
  11. #include <dos.h>
  12. #include <ctype.h>
  13. #include <string.h>
  14. #include <graphics.h>
  15. #include "GraphGnG.h"
  16. #include "Dir-Graf.h"
  17.  
  18. #ifndef LINE_LEN
  19. #define LINE_LEN 128
  20. #endif
  21.  
  22. #define READ_COLOR  GREEN
  23.  
  24. /******************************************************************************
  25. * Procedure to print the current directory content in menu area:          *
  26. * Print file name and size in k bytes one per line. if page is full          *
  27. * (> ~20 lines) it pause and continue in next page. No sort is perform.       *
  28. * Note it is the responsibility of the caller to clean the menu area on exit. *
  29. ******************************************************************************/
  30. void PrintDir(char *FileToDir)
  31. {
  32.     int i, j;
  33.     char s[128], Ctemp;
  34.     double Ylevel = 0.9;
  35.     struct ffblk ffblk;
  36.  
  37.     GGClearMenuArea();
  38.     GGMySetColor(MAGENTA);
  39.  
  40.     if (FileToDir == NULL) FileToDir = DEFAULT_FILE_TO_DIR;
  41.  
  42.     getcwd(s, 127);               /* Might be 64 chars at the most. */
  43.     j = 0;
  44.     i = strlen(s);    /* Test if length greater than possible in one line. */
  45.     while (i > j) {
  46.     Ctemp = s[j+MAX_HELP_MENU_CHAR];
  47.     s[j+MAX_HELP_MENU_CHAR] = 0;        /* Put temporary NULL there. */
  48.     GGPutMsgXY(&s[j], MSG_AREA_X, Ylevel);
  49.     s[j+MAX_HELP_MENU_CHAR] = Ctemp;         /* Put the char back... */
  50.     j += MAX_HELP_MENU_CHAR;
  51.     Ylevel -= 0.09;
  52.     }
  53.     Ylevel -= 0.09;           /* Make some space from directory name... */
  54.  
  55.     GGMySetColor(GREEN);
  56.     if (!findfirst(FileToDir, &ffblk, 0))
  57.     do {
  58.         sprintf(s, "%3dk   %s", (int) ((ffblk.ff_fsize+1023)/1024),
  59.                                 ffblk.ff_name);
  60.         if (Ylevel < -0.7) {
  61.         GGPutErrorMsg("");
  62.         GGClearMenuArea();
  63.         GGMySetColor(GREEN);
  64.         Ylevel = 0.9;
  65.         }
  66.         GGPutMsgXY(s, MSG_AREA_X, Ylevel);
  67.         Ylevel -= 0.09;
  68.     }
  69.     while (!findnext(&ffblk));
  70.     else {
  71.     sprintf(s, "NO '%s' FILE(S)", FileToDir);
  72.     GGPutMsgXY(s, MSG_AREA_X, Ylevel);
  73.     Ylevel -= 0.09;
  74.     }
  75.  
  76.     if (!findfirst("*.*", &ffblk, FA_DIREC))
  77.     do {
  78.         switch (ffblk.ff_attrib) {
  79.         case FA_DIREC:                       /* Directory. */
  80.             sprintf(s, "<DIR>  %s", ffblk.ff_name);
  81.             if (Ylevel < -0.7) {
  82.             GGPutErrorMsg("");
  83.             GGClearMenuArea();
  84.             GGMySetColor(GREEN);
  85.             Ylevel = 0.9;
  86.             }
  87.             GGPutMsgXY(s, MSG_AREA_X, Ylevel);
  88.             Ylevel -= 0.09;
  89.             break;
  90.         }
  91.     }
  92.     while (!findnext(&ffblk));
  93.  
  94.     GGPutErrorMsg("");
  95. }
  96.  
  97. /*****************************************************************************
  98. *   Routine to change current directory                         *
  99. *****************************************************************************/
  100. void ChangeDir(void)
  101. {
  102.     int i, j;
  103.     char s[LINE_LEN], cwd[LINE_LEN], Ctemp, *sptr;
  104.     double Ylevel;
  105.  
  106.     GGMySetColor(READ_COLOR);
  107.     getcwd(cwd, LINE_LEN-1);           /* Might be 64 chars at the most. */
  108.     Ylevel = 0.38;
  109.     j = 0;
  110.     i = strlen(cwd);    /* Test if length greater than possible in one line. */
  111.     while (i>j) {
  112.     Ctemp = cwd[j+MAX_HELP_MENU_CHAR];
  113.     cwd[j+MAX_HELP_MENU_CHAR] = 0;        /* Put temporary NULL there. */
  114.     GGPutMsgXY(&cwd[j], MSG_AREA_X, MSG_AREA_Y+Ylevel);
  115.     cwd[j+MAX_HELP_MENU_CHAR] = Ctemp;         /* Put the char back... */
  116.     j += MAX_HELP_MENU_CHAR;
  117.     Ylevel -= 0.09;
  118.     }
  119.     GGPutMsgXY("Enter New Dir :", MSG_AREA_X, MSG_AREA_Y+0.2);
  120.  
  121.     s[0] = s[1] = s[2] = 0;   /* Make sure that no old data remains there... */
  122.     GGGetGraphicLine(MSG_AREA_X, MSG_AREA_Y, s, READ_COLOR);
  123.  
  124.     GGMySetColor(BLACK);
  125.     GGPutMsgXY("Enter New Dir :", MSG_AREA_X, MSG_AREA_Y+0.2);
  126.     Ylevel = 0.38;
  127.     j = 0;
  128.     i = strlen(cwd);    /* Test if length greater than possible in one line. */
  129.     while (i>j) {
  130.     Ctemp = cwd[j+MAX_HELP_MENU_CHAR];
  131.     cwd[j+MAX_HELP_MENU_CHAR] = 0;        /* Put temporary NULL there. */
  132.     GGPutMsgXY(&cwd[j], MSG_AREA_X, MSG_AREA_Y+Ylevel);
  133.     cwd[j+MAX_HELP_MENU_CHAR] = Ctemp;         /* Put the char back... */
  134.     j += MAX_HELP_MENU_CHAR;
  135.     Ylevel -= 0.09;
  136.     }
  137.  
  138.     if (s[1] == ':') sptr = &s[2];        /* sptr points on the path only. */
  139.     else sptr = s;
  140.  
  141.     if (strlen(sptr) != 0 && chdir(s)) GGPutErrorMsg("No Such Dir!");
  142.     else if (s[1] == ':') {
  143.     if (islower(s[0])) s[0] = toupper(s[0]);
  144.     setdisk(s[0] - 'A');                /* Move to the new disk. */
  145.     if (getdisk() != s[0] - 'A') GGPutErrorMsg("No Such Disk!");
  146.     }
  147.  
  148.     if (getcwd(s, LINE_LEN-1) == NULL) {      /* Test if directory is valid! */
  149.     GGPutErrorMsg("CD error - ignored");
  150.  
  151.     /* Restore old working directory: */
  152.     if (strlen(&cwd[2]) != 0) chdir(cwd); /* If directory is not root... */
  153.     if (islower(cwd[0])) cwd[0] = toupper(cwd[0]);
  154.     setdisk(cwd[0] - 'A');               /* Move to the original disk. */
  155.     }
  156. }
  157.