home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / com020 / internal.h < prev    next >
C/C++ Source or Header  |  1995-01-15  |  3KB  |  135 lines

  1. /* INTERNAL.H
  2.  * internal functions for Free DOS
  3.  * Tim Norman
  4.  * 8-17-94
  5. */
  6.  
  7. #include "environ.h"
  8.  
  9. void SET (char *commandline)
  10. {
  11.    char *command;
  12.    unsigned char count;
  13.    int r;
  14.  
  15.    command = commandline;
  16.  
  17.    while (isspace (*command))    /* skip over "set" and whitespace */
  18.       command++;
  19.  
  20.    while (!isspace (*command))
  21.       command++;
  22.  
  23.    while (isspace (*command))
  24.       command++;
  25.  
  26.    strcpy (env_temp, command);
  27.  
  28.    count = strlen (env_temp) - 1;    /* remove trailing spaces */
  29.    while (env_temp[count] == ' ')
  30.       env_temp[count--] = 0;
  31.  
  32.    if (strstr (env_temp, "=") == NULL)
  33.    {
  34.       puts ("Syntax error");
  35.       return;
  36.    }
  37.  
  38.    /* capitalize name of env. var. */
  39.    for (count = 0; env_temp[count] != '=' && env_temp[count] != 0; count++)
  40.       env_temp[count] = toupper (env_temp[count]);
  41.  
  42.    r = addenv (env_temp);
  43.  
  44.    if (r == 1)
  45.       puts ("Syntax error");
  46.    else if (r == 2)
  47.       puts ("Out of environment space!");
  48. }
  49.  
  50. void CD (char *commandline, char *p[128], unsigned char args)
  51. {
  52.    switch (p[0][2])
  53.    {
  54.       case 0:
  55.      if (args > 2)
  56.         printf ("Too many parameters - %s\n", p[2]);
  57.      else
  58.      {
  59.         if (p[1][strlen (p[1]) - 1] == '\\') /* take off last \ */
  60.            p[1][strlen (p[1]) - 1] = 0;      /* this is incompatible */
  61.         if (chdir (p[1]) != 0)               /* with MS-DOS but makes */
  62.            puts ("Invalid directory");       /* filename completion */
  63.      }                                       /* more useful */
  64.  
  65.      break;
  66.  
  67.       case '\\':
  68.      if (args > 1)
  69.         printf ("Too many parameters - %s\n", p[1]);
  70.      else
  71.         if (chdir (&p[0][2]) != 0)
  72.            puts ("Invalid directory");
  73.  
  74.      break;
  75.       case '.':
  76.      if (args > 1)
  77.         printf ("Too many parameters - %s\n", p[1]);
  78.      else
  79.         if (chdir (&p[0][2]) != 0)
  80.            puts ("Invalid directory");
  81.  
  82.      break;
  83.    }
  84. }
  85.  
  86. void DIR (char *p[128], int args)
  87. {
  88.    int count;
  89.    struct ffblk file;
  90.    int done;
  91.    long files = 0, bytes = 0;
  92.    union REGS regs;
  93.  
  94.    if (args > 1)
  95.    {
  96.       printf ("Too many parameters -");
  97.       for (count = 1; count < args; count++)
  98.      printf (" %s", p[count]);
  99.  
  100.       puts ("");
  101.  
  102.       return;
  103.    }
  104.  
  105.    /* find all files by default */
  106.    done = findfirst (args == 0 ? "*.*" : p[0], &file, 0xFF);
  107.  
  108.    do
  109.    {
  110.       printf ("%-12s %15ld\n", file.ff_name, file.ff_fsize);
  111.  
  112.       files++;
  113.       bytes += file.ff_fsize;
  114.  
  115.       done = findnext (&file);
  116.  
  117.       if (files % 20 == 0)
  118.       {
  119.      puts ("Press any key to continue...");
  120.      getch ();
  121.       }
  122.    }
  123.    while (!done);
  124.  
  125.    printf ("    %5ld file%s %15ld byte%s\n", files, files == 1 ? "" : "s",
  126.        bytes, bytes == 1 ? "" : "s");
  127.  
  128.    regs.h.ah = 0x36;
  129.    regs.h.dl = 0;
  130.    int86 (0x21, ®s, ®s);
  131.  
  132.    printf ("              %s %15ld bytes free\n", files == 1 ? "" : " ",
  133.        (long)regs.x.ax * regs.x.cx * regs.x.bx);
  134. }
  135.