home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / fileutil / rh / rhcmds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-13  |  4.1 KB  |  128 lines

  1.  
  2. /* ----------------------------------------------------------------------
  3.  * FILE: rhcmds.c
  4.  * VERSION: 2
  5.  * Written by: Ken Stauffer
  6.  * This file contains the functions that do the evaluation of
  7.  * the stack program.
  8.  * These functions are simple, and behave like RPN operators, that is
  9.  * they use the last two values on the stack, apply an operator
  10.  * and push the result. Similarly for unary ops.
  11.  *
  12.  * ---------------------------------------------------------------------- */
  13.  
  14. #include "rh.h"
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17.  
  18. c_or(i)     long i;   { Stack[SP-2]=Stack[SP-2] || Stack[SP-1]; SP--; }
  19. c_and(i)    long i;   { Stack[SP-2]=Stack[SP-2] && Stack[SP-1]; SP--; }
  20. c_le(i)     long i;   { Stack[SP-2]=Stack[SP-2] <= Stack[SP-1]; SP--; }
  21. c_lt(i)     long i;   { Stack[SP-2]=Stack[SP-2] < Stack[SP-1]; SP--;  }
  22. c_ge(i)     long i;   { Stack[SP-2]=Stack[SP-2] >= Stack[SP-1]; SP--; }
  23. c_gt(i)     long i;   { Stack[SP-2]=Stack[SP-2] > Stack[SP-1]; SP--;  }
  24. c_ne(i)     long i;   { Stack[SP-2]=Stack[SP-2] != Stack[SP-1]; SP--; }
  25. c_eq(i)     long i;   { Stack[SP-2]=Stack[SP-2] == Stack[SP-1]; SP--; }
  26. c_bor(i)    long i;   { Stack[SP-2]=Stack[SP-2] | Stack[SP-1]; SP--;  }
  27. c_band(i)   long i;   { Stack[SP-2]=Stack[SP-2] & Stack[SP-1]; SP--;  }
  28. c_bxor(i)   long i;   { Stack[SP-2]=Stack[SP-2] ^ Stack[SP-1]; SP--;  }
  29. c_lshift(i) long i;   { Stack[SP-2]=Stack[SP-2] << Stack[SP-1]; SP--; }
  30. c_rshift(i) long i;   { Stack[SP-2]=Stack[SP-2] >> Stack[SP-1]; SP--; }
  31. c_plus(i)   long i;   { Stack[SP-2]=Stack[SP-2] + Stack[SP-1]; SP--;  }
  32. c_mul(i)    long i;   { Stack[SP-2]=Stack[SP-2] * Stack[SP-1]; SP--;  }
  33. c_minus(i)  long i;   { Stack[SP-2]=Stack[SP-2] - Stack[SP-1]; SP--;  }
  34. c_div(i)    long i;   { Stack[SP-2]=Stack[SP-2] / Stack[SP-1]; SP--;  }
  35. c_mod(i)    long i;   { Stack[SP-2]=Stack[SP-2] % Stack[SP-1]; SP--;  }
  36.  
  37.  
  38. /* unary instructions */
  39.  
  40. c_not(i)      long i; { Stack[SP-1] = ! Stack[SP-1]; }
  41. c_bnot(i)     long i; { Stack[SP-1] = ~ Stack[SP-1]; }
  42. c_uniminus(i) long i; { Stack[SP-1] = - Stack[SP-1]; }
  43.  
  44. /* trinary operator ?: */
  45.  
  46. c_qm(i)    long i; { PC = (Stack[SP-1]) ?  PC : i; SP--; }
  47. c_colon(i) long i; { PC = i; }
  48.  
  49. /* accessing a parameter */
  50.  
  51. c_param(i)
  52. long i;
  53. {
  54.     Stack[ SP++ ] = Stack[ FP + i ];
  55. }
  56.  
  57. /* calling a function */
  58.  
  59. c_func(i)
  60. long i;
  61. {
  62.     Stack[ SP++ ] = PC;
  63.     Stack[ SP++] = FP;
  64.     PC = i;
  65.     FP = SP-(StackProgram[PC].value+2);
  66. }
  67.  
  68. /* returning from a function */
  69.  
  70. c_return(i)
  71. long i;
  72. {
  73.     PC = Stack[ SP-3 ];
  74.     FP = Stack[ SP-2 ];
  75.     Stack[ SP-(3+i) ] = Stack[ SP-1 ];
  76.     SP -= (2+i);
  77. }
  78.  
  79. /* operand functions */
  80.  
  81. c_number(i) long i; { Stack[SP++] = i;                  }
  82. c_atime(i)  long i; { Stack[SP++] = attr.buf->st_atime; }
  83. c_ctime(i)  long i; { Stack[SP++] = attr.buf->st_ctime; }
  84. c_dev(i)    long i; { Stack[SP++] = attr.buf->st_dev;   }
  85. c_gid(i)    long i; { Stack[SP++] = attr.buf->st_gid;   }
  86. c_ino(i)    long i; { Stack[SP++] = attr.buf->st_ino;   }
  87. c_mode(i)   long i; { Stack[SP++] = attr.buf->st_mode;  }
  88. c_mtime(i)  long i; { Stack[SP++] = attr.buf->st_mtime; }
  89. c_nlink(i)  long i; { Stack[SP++] = attr.buf->st_nlink; }
  90. c_rdev(i)   long i; { Stack[SP++] = attr.buf->st_rdev;  }
  91. c_size(i)   long i; { Stack[SP++] = attr.buf->st_size;  }
  92. c_uid(i)    long i; { Stack[SP++] = attr.buf->st_uid;   }
  93. c_depth(i)  long i; { Stack[SP++] = attr.depth;         }
  94. c_prune(i)  long i; { Stack[SP++] = 0; attr.prune = 1;  }
  95.  
  96. /* calculate the filename length */
  97.  
  98. c_baselen(i)
  99. long i;
  100. {
  101.     char *c; register int len;
  102.  
  103.     len = 0;
  104.     for(c=attr.fname; *c; c++ )
  105.         if( *c == '/' ) len = 0;
  106.         else len += 1;
  107.     Stack[SP++] = len;
  108. }
  109.  
  110. /* ----------------------------------------------------------------------
  111.  * c_str:
  112.  *    This implements the regular expression stuff.
  113.  *    'i' is an index into the array Strbuf[]. The
  114.  *    string contained there is the actual '\0' terminated
  115.  *    string that occured in the expression (eg "*.BAK" ), minus
  116.  *    the quotes "".
  117.  */
  118.  
  119. c_str(i)
  120. long i;
  121. {
  122.     char *tail,*strrchr();
  123.  
  124.     tail = strrchr(attr.fname, '/');
  125.     tail = (tail) ? tail+1 : attr.fname;
  126.     Stack[SP++] = glob_match(&Strbuf[i], tail, 1);
  127. }
  128.