~ubuntu-branches/ubuntu/natty/mawk/natty

« back to all changes in this revision

Viewing changes to bi_funct.c

  • Committer: Bazaar Package Importer
  • Author(s): James Troup
  • Date: 2001-07-18 20:40:37 UTC
  • Revision ID: james.westby@ubuntu.com-20010718204037-ktb1x8r3ukz5hp3h
Tags: 1.3.3-8
debian/rules (build): compile with -O1 on hppa to work around probable
compiler bug.  Thanks to LaMont Jones <lamont@ia.mmjgroup.com>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
#include "regexp.h"
75
75
#include "repl.h"
76
76
#include <math.h>
77
 
 
 
77
#include <unistd.h>
78
78
 
79
79
/* statics */
80
80
static STRING *PROTO(gsub, (PTR, CELL *, char *, int)) ;
81
81
static void PROTO(fplib_err, (char *, double, char *)) ;
82
82
 
83
 
 
84
83
/* global for the disassembler */
85
84
BI_REC bi_funct[] =
86
85
{                               /* info to load builtins */
87
86
 
88
 
   "length", bi_length, 0, 1,   /* special must come first */
89
 
   "index", bi_index, 2, 2,
90
 
   "substr", bi_substr, 2, 3,
91
 
   "sprintf", bi_sprintf, 1, 255,
92
 
   "sin", bi_sin, 1, 1,
93
 
   "cos", bi_cos, 1, 1,
94
 
   "atan2", bi_atan2, 2, 2,
95
 
   "exp", bi_exp, 1, 1,
96
 
   "log", bi_log, 1, 1,
97
 
   "int", bi_int, 1, 1,
98
 
   "sqrt", bi_sqrt, 1, 1,
99
 
   "rand", bi_rand, 0, 0,
100
 
   "srand", bi_srand, 0, 1,
101
 
   "close", bi_close, 1, 1,
102
 
   "system", bi_system, 1, 1,
103
 
   "toupper", bi_toupper, 1, 1,
104
 
   "tolower", bi_tolower, 1, 1,
105
 
   "fflush", bi_fflush, 0, 1,
 
87
   {"length", bi_length, 0, 1}, /* special must come first */
 
88
   {"index", bi_index, 2, 2},
 
89
   {"substr", bi_substr, 2, 3},
 
90
   {"sprintf", bi_sprintf, 1, 255},
 
91
   {"sin", bi_sin, 1, 1},
 
92
   {"cos", bi_cos, 1, 1},
 
93
   {"atan2", bi_atan2, 2, 2},
 
94
   {"exp", bi_exp, 1, 1},
 
95
   {"log", bi_log, 1, 1},
 
96
   {"int", bi_int, 1, 1},
 
97
   {"sqrt", bi_sqrt, 1, 1},
 
98
   {"rand", bi_rand, 0, 0},
 
99
   {"srand", bi_srand, 0, 1},
 
100
   {"close", bi_close, 1, 1},
 
101
   {"system", bi_system, 1, 1},
 
102
   {"toupper", bi_toupper, 1, 1},
 
103
   {"tolower", bi_tolower, 1, 1},
 
104
   {"fflush", bi_fflush, 0, 1},
106
105
 
107
 
   (char *) 0, (PF_CP) 0, 0, 0} ;
 
106
   {(char *) 0, (PF_CP) 0, 0, 0}} ;
108
107
 
109
108
 
110
109
/* load built-in functions in symbol table */
175
174
      case 2:
176
175
         {
177
176
            int k1 = key[1] ;
178
 
            while (target = strchr(target, k))
 
177
            while ((target = strchr(target, k)))
179
178
               if (target[1] == k1)  return target ;
180
179
               else  target++ ;
181
180
            /*failed*/
184
183
   }
185
184
 
186
185
   key_len-- ;
187
 
   while (target = strchr(target, k))
 
186
   while ((target = strchr(target, k)))
188
187
   {
189
188
      if (strncmp(target + 1, key + 1, key_len) == 0)  return target ;
190
189
      else  target++ ;
206
205
   sp-- ;
207
206
   if (TEST2(sp) != TWO_STRINGS)  cast2_to_s(sp) ;
208
207
 
209
 
   if (len = string(sp + 1)->len)
 
208
   if ((len = string(sp + 1)->len))
210
209
      idx = (p = str_str(string(sp)->str, string(sp + 1)->str, len))
211
210
         ? p - string(sp)->str + 1 : 0 ;
212
211
 
240
239
 
241
240
   if ((len = sval->len) == 0)  /* substr on null string */
242
241
   {
243
 
      if (n_args == 3)  cell_destroy(sp + 2) ;
 
242
      if (n_args == 3) { cell_destroy(sp + 2) ; }
244
243
      cell_destroy(sp + 1) ;
245
244
      return sp ;
246
245
   }
831
830
   if (sc.type < C_STRING)  cast1_to_s(&sc) ;
832
831
   front = string(&sc)->str ;
833
832
 
834
 
   if (middle = REmatch(front, sp->ptr, &middle_len))
 
833
   if ((middle = REmatch(front, sp->ptr, &middle_len)))
835
834
   {
836
835
      front_len = middle - front ;
837
836
      back = middle + middle_len ;