home *** CD-ROM | disk | FTP | other *** search
-
- /* ----------------------------------------------------------------------
- * FILE: rhcmds.c
- * (c) 1989 Ken Stauffer
- * This file contains the functions that do the evaluation of
- * the stack program.
- * These functions are simple, and behave like RPN operators, that is
- * they use the last two values on that stack, apply an operator
- * and push the result. Similarly for unary ops.
- *
- * ---------------------------------------------------------------------- */
-
- #include "rh.h"
- #include <sys/types.h>
- #include <sys/stat.h>
-
- c_or(i) long i; { Stack[SP-2]=Stack[SP-2] || Stack[SP-1]; SP--; }
- c_and(i) long i; { Stack[SP-2]=Stack[SP-2] && Stack[SP-1]; SP--; }
- c_le(i) long i; { Stack[SP-2]=Stack[SP-2] <= Stack[SP-1]; SP--; }
- c_lt(i) long i; { Stack[SP-2]=Stack[SP-2] < Stack[SP-1]; SP--; }
- c_ge(i) long i; { Stack[SP-2]=Stack[SP-2] >= Stack[SP-1]; SP--; }
- c_gt(i) long i; { Stack[SP-2]=Stack[SP-2] > Stack[SP-1]; SP--; }
- c_ne(i) long i; { Stack[SP-2]=Stack[SP-2] != Stack[SP-1]; SP--; }
- c_eq(i) long i; { Stack[SP-2]=Stack[SP-2] == Stack[SP-1]; SP--; }
- c_bor(i) long i; { Stack[SP-2]=Stack[SP-2] | Stack[SP-1]; SP--; }
- c_band(i) long i; { Stack[SP-2]=Stack[SP-2] & Stack[SP-1]; SP--; }
- c_bxor(i) long i; { Stack[SP-2]=Stack[SP-2] ^ Stack[SP-1]; SP--; }
- c_plus(i) long i; { Stack[SP-2]=Stack[SP-2] + Stack[SP-1];SP--; }
- c_mul(i) long i; { Stack[SP-2]=Stack[SP-2] * Stack[SP-1]; SP--; }
- c_minus(i)long i; { Stack[SP-2]=Stack[SP-2] - Stack[SP-1]; SP--; }
- c_div(i) long i; { Stack[SP-2]=Stack[SP-2] / Stack[SP-1]; SP--; }
- c_mod(i) long i; { Stack[SP-2]=Stack[SP-2] % Stack[SP-1]; SP--; }
- c_lshift(i) long i; { Stack[SP-2]=Stack[SP-2] << Stack[SP-1]; SP--; }
- c_rshift(i) long i; { Stack[SP-2]=Stack[SP-2] >> Stack[SP-1]; SP--; }
-
- /* unary instructions */
-
- c_not(i) long i; { Stack[SP-1]= ! Stack[SP-1]; }
- c_bnot(i) long i; { Stack[SP-1]= ~ Stack[SP-1]; }
- c_uniminus(i) long i; { Stack[SP-1]= - Stack[SP-1]; }
-
- /* trinary operator ?: */
-
- c_qm(i) long i; { PC = (Stack[SP-1]) ? PC : i; SP--; }
- c_colon(i) long i; { PC = i; }
- c_nop(i) long i; { }
-
- /* operand functions */
-
- c_number(i) long i; { Stack[SP++] = i; }
- c_atime(i) long i; { Stack[SP++] = globuf->st_atime; }
- c_ctime(i) long i; { Stack[SP++] = globuf->st_ctime; }
- c_dev(i) long i; { Stack[SP++] = globuf->st_dev; }
- c_gid(i) long i; { Stack[SP++] = globuf->st_gid; }
- c_ino(i) long i; { Stack[SP++] = globuf->st_ino; }
- c_mode(i) long i; { Stack[SP++] = globuf->st_mode; }
- c_mtime(i) long i; { Stack[SP++] = globuf->st_mtime; }
- c_nlink(i) long i; { Stack[SP++] = globuf->st_nlink; }
- c_rdev(i) long i; { Stack[SP++] = globuf->st_rdev; }
- c_size(i) long i; { Stack[SP++] = globuf->st_size; }
- c_uid(i) long i; { Stack[SP++] = globuf->st_uid; }
-
-
- /* ----------------------------------------------------------------------
- * star:
- * This implements the trivial regular expression stuff.
- * Since people may want to upgrade this, I will explain the
- * parameter. 'i' is an index into the array Startbuf[]. The
- * string contained there is the actual '\0' terminated
- * string that occured in the expression (eg "*.BAK" ), minus
- * the "'s.
- * The reasons for the simplistic regular expressions is
- * because it was easy, because lots of unix systems do
- * regexp() in lots of ways and this method is fairly fast.
- *
- */
-
- c_star(i)
- long i;
- {
-
- register int ri,ii;
-
- if( Starbuf[i]=='*') {
- ii=strlen(fname)-1;
- ri=strlen(Starbuf+i)-1+i;
- while( fname[ii]==Starbuf[ri] && ri>i ) {
- ri--; ii--;
- }
- Stack[SP++] = (ri==i);
- }
- else {
- int x=0;
- ii=0;
- while( fname[x] ) {
- if(fname[x]=='/') ii=x;
- x++;
- }
- ii++;
- ri=i;
- while( fname[ii]==Starbuf[ri] && Starbuf[ri]!='*'
- && fname[ii] && Starbuf[ri]) {
- ri++; ii++;
- }
- Stack[SP++]=!(fname[ii]+Starbuf[ri]) || Starbuf[ri]=='*';
- }
- }
-
-