|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T t ┃
Length: 3205 (0xc85) Types: TextFile Names: »trans.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen └─ ⟦this⟧ »cph85dist/stat/src/trans.c«
#include "unixstat.h" PGM(trans,transform columnar data,5.0,2/21/85) /* cc trans.o strings.o number.o checkio.o -lm */ main (argc, argv) char **argv; { ARGV0; setvalue (argc, argv); checkstdin (Argv0); trans (); exit (0); } #define MAXCOLS 100 #define MAXLEN 20 char Input[MAXCOLS][MAXLEN]; int Maxindex = 0; #define MAXOP 20 #define unary(c) (isalpha (c)) /* alphabetic operators are unary */ int Operator[MAXOP]; /* character operation names */ char *Operand[MAXOP]; /* pointers to operands */ int Noper; /* number of operations */ setvalue (argc, argv) char **argv; { int i; int operator; char *operand; for (i = 1; i < argc; i++) { operator = argv[i][0]; operand = argv[i]+1; if (!member (operator, "=-+/*^lLesafc")) ERRMSG1 (Illegal operator '%c', operator) if (!unary (operator) && !number (operand)) { if (*operand == 'x') /* address of input column */ { int cindex; operand++; if (!INTEGER (operand)) ERRMSG1 (Illegal column number 'x%s', operand) cindex = atoi (operand); if (cindex <= 0 || cindex > MAXCOLS) ERRMSG1 (Column number (%d) out of range, cindex) if (cindex > Maxindex) Maxindex = cindex; operand = Input[cindex-1]; } else ERRMSG1 (Unrecognized operand '%s', operand) } if (Noper == MAXOP) ERRMANY (operations on command line, MAXOP) Operator[Noper] = operator; Operand[Noper] = operand; Noper++; } if (Noper == 0) USAGE (OpValue ...) } member (c, s) int c; char *s; { if (s) while (*s) if (*s++ == c) return (1); return (0); } trans () { char line[BUFSIZ]; int ncols; double operand; double value; int inline = 0; int oper; double LOG10 = log (10.0); while (gets (line)) { inline++; ncols = sstrings (line, Input, MAXCOLS, MAXLEN); if (ncols < Maxindex) ERRMSG3 (Too few columns (%d) on line %d; need at least %d, ncols, inline, Maxindex) value = (double) inline; for (oper = 0; oper < Noper; oper++) { if (!unary (Operator[oper])) { if (!number (Operand[oper])) ERRNUM (Operand[oper],input value) operand = atof (Operand[oper]); } switch (Operator[oper]) { case '=': value = operand; break; case '+': value += operand; break; case '-': value -= operand; break; case '/': if (fzero (operand)) ERRMSG1 (Division by zero on line %d, inline) value /= operand; break; case '*': value *= operand; break; case '^': value = pow (value, operand); break; case 's': if (value < 0.0) ERRMSG1 (Root of negative value on line %d, inline) value = sqrt (value); break; case 'l': if (value <= FZERO) ERRMSG1 (Log of value <= 0 on line %d, inline) value = log (value); break; case 'L': if (value <= FZERO) ERRMSG1 (Log of value <= 0 on line %d, inline) value = log (value) / LOG10; break; case 'e': value = exp (value); break; case 'a': value = fabs (value); break; case 'f': value = floor (value); break; case 'c': value = ceil (value); break; default: ERRMSG1 (Illegal operator '%c', Operator[oper]) } } printf ("%g\n", value); } }