Annotation of freem/src/expr.c, revision 1.12

1.1       snw         1: /*
1.12    ! snw         2:  *   $Id: expr.c,v 1.11 2025/03/30 01:36:58 snw Exp $
1.1       snw         3:  *    expression parser
                      4:  *
                      5:  *  
1.4       snw         6:  *   Author: Serena Willis <snw@coherent-logic.com>
1.1       snw         7:  *    Copyright (C) 1998 MUG Deutschland
1.5       snw         8:  *    Copyright (C) 2020, 2023, 2025 Coherent Logic Development LLC
1.1       snw         9:  *
                     10:  *
                     11:  *   This file is part of FreeM.
                     12:  *
                     13:  *   FreeM is free software: you can redistribute it and/or modify
                     14:  *   it under the terms of the GNU Affero Public License as published by
                     15:  *   the Free Software Foundation, either version 3 of the License, or
                     16:  *   (at your option) any later version.
                     17:  *
                     18:  *   FreeM is distributed in the hope that it will be useful,
                     19:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     20:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     21:  *   GNU Affero Public License for more details.
                     22:  *
                     23:  *   You should have received a copy of the GNU Affero Public License
                     24:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
                     25:  *
1.6       snw        26:  *   $Log: expr.c,v $
1.12    ! snw        27:  *   Revision 1.11  2025/03/30 01:36:58  snw
        !            28:  *   Make it easier to bring back fma_gedit, fix double-free in global handler, limit $CHAR to 7-bit ASCII
        !            29:  *
1.11      snw        30:  *   Revision 1.10  2025/03/24 04:13:11  snw
                     31:  *   Replace action macro dat with fra_dat to avoid symbol conflict on OS/2
                     32:  *
1.10      snw        33:  *   Revision 1.9  2025/03/24 01:32:22  snw
                     34:  *   Guard declaration of time function in expr.c for portability
                     35:  *
1.9       snw        36:  *   Revision 1.8  2025/03/22 04:47:18  snw
                     37:  *   Silently truncate long names in STRING exprs when  evaluates to an obsolete MDC standard
                     38:  *
1.8       snw        39:  *   Revision 1.7  2025/03/22 03:39:23  snw
                     40:  *   Fix reverse query polyfill call-in from C side and make NAME exprs silently truncate long names in obsolete MDC dialects
                     41:  *
1.7       snw        42:  *   Revision 1.6  2025/03/22 03:05:19  snw
                     43:  *   Comply with X11-96/13 portable length of names
                     44:  *
1.6       snw        45:  *   Revision 1.5  2025/03/09 19:14:24  snw
                     46:  *   First phase of REUSE compliance and header reformat
                     47:  *
1.5       snw        48:  *
                     49:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
                     50:  * SPDX-License-Identifier: AGPL-3.0-or-later 
1.1       snw        51:  **/
                     52: 
                     53: #if !defined(__osf__)
                     54: #include <sys/types.h>
                     55: #endif
                     56: #if !defined(__OpenBSD__) && !defined(__FreeBSD__)
                     57: # include <sys/timeb.h>
                     58: #endif
                     59: #include <stdlib.h>
                     60: #include <string.h>
                     61: #include <ctype.h>
                     62: 
                     63: /* mumps expression evaluator */
                     64: 
                     65: #include "mpsdef.h"
                     66: #include "transact.h"
                     67: #include "merr.h"
                     68: #include "mtok.h"
                     69: #include "version.h"
                     70: #if defined(HAVE_STDINT_H)
                     71: # include <stdint.h>
                     72: #endif
                     73: #if !defined(__osf__) && !defined(_AIX)
                     74: # define _XOPEN_SOURCE
                     75: #endif
                     76: 
                     77: #if defined(USE_SYS_TIME_H) && !defined(MSDOS) && !defined(__osf__)
                     78: # include <sys/time.h>
                     79: #else
                     80: # include <time.h> 
                     81: #endif
                     82: 
                     83: #if defined(MSDOS) || defined(__linux__)
                     84: # include <time.h>
                     85:   char *strptime(const char *restrict s, const char *restrict format, struct tm *restrict tm);
                     86: #endif
                     87: 
                     88: #include "mref.h"
                     89: #include "journal.h"
                     90: #include "datatypes.h"
                     91: #include "objects.h"
                     92: 
                     93: #define OPERAND       1
                     94: #define ARRAY         2
                     95: #define FNUMBER       3
                     96: #define REVERSE       4
                     97: #define TRANSLATE     5
                     98: #define QLENGTH       6
                     99: #define QSUBSCRIPT    7
                    100: #define TYPE          31
                    101: #define INSTANCEOF    32
                    102: 
                    103: #define ZCRC          8
                    104: #define ZDATA         9
                    105: #define ZLSD         11
                    106: #define ZNEXT        12
                    107: #define ZPREVIOUS    17
                    108: #define ZTRAP        18
                    109: 
                    110: #define SVNsystem    19
                    111: #define SVNtimezone  20
                    112: #define SVNtlevel    22
                    113: #define SVNtrollback 23
                    114: #define SVNecode     24
                    115: #define SVNestack    25
                    116: #define SVNetrap     26
                    117: #define SVNstack     27
                    118: #define SVNpdisplay   28
                    119: #define SVNdialect    29
                    120: #define SVNzut 30
                    121: 
                    122: #define OR                '!'
                    123: #define MODULO            '#'
                    124: #define DIVIDE            '/'
                    125: #define AND               '&'
                    126: #define NOT               '\''
                    127: #define XOR               '~'
                    128: #define MULTIPLY          '*'
                    129: #define POWER             ' '
                    130: #define PLUS              '+'
                    131: #define MINUS             '-'
                    132: #define LESS              '<'
                    133: #define EQUAL             '='
                    134: #define GREATER           '>'
                    135: #define PATTERN           '?'
                    136: #define INDIRECT          '@'
                    137: #define CONTAINS          '['
                    138: #define INTDIVIDE         '\\'
                    139: #define FOLLOWS           ']'
                    140: #define CONCATENATE       '_'
                    141: #define SORTSAFTER        '.'
                    142: #define EQFOLLOWS         ','
                    143: #define EQSORTS           ';'
                    144: #define MAXOP             ':'
                    145: #define MINOP             '%'
                    146: 
                    147: #define GET               'Y'
                    148: #define GETX              ':'
                    149: 
1.9       snw       150: #if !defined(__OpenBSD__) && !defined(_AIX) && !defined(__osf__) && !defined(MSDOS) && !defined(__vax__) && !defined(__OS2__)
1.1       snw       151: long    time ();
                    152: #endif
1.2       snw       153: void cond_round (char *a, int digits);
                    154: void zkey (char *a, long type);
                    155: int levenshtein (char *word1, char *word2);
1.1       snw       156: time_t     horolog_to_unix (char *horo);
                    157: extern int xecline(int typ);
                    158: short      rbuf_slot_from_name(char *);
                    159: 
                    160: 
                    161: short obj_field = FALSE;
                    162: char object_instance[50];
                    163: char object_class[50];
                    164: 
                    165: 
                    166: /*
                    167:  * expr():  expression parser
                    168:  *  extyp:  type of expression; one of:
                    169:  *          STRING
                    170:  *          NAME
                    171:  *          LABEL
                    172:  *          OFFSET
                    173:  *          ARGIND
                    174:  */
                    175: void expr (short extyp)
                    176: {
                    177:     char op_stck[PARDEPTH + 1]; /* operator/operandflag stack */
                    178:     short spx;          /* stack pointer:             */
                    179:     short zexflag;          /* z 'intrinsic' function flag */
                    180:     int atyp, btyp;         /* DM/EUR currency types */
                    181:     char *a;                /* pointer to current (left) argument */
                    182:     char *b;                /* pointer to right hand argument     */
                    183:     char tmp[256];
                    184:     int refsx;          /* zref/zloc stack_counter  */
                    185:     char *refsav[PARDEPTH];     /* zref/zloc stack          */
                    186:     
                    187: 
                    188:     register int i = 0;
                    189:     register int j = 0;
                    190:     register int f = 0;
                    191:     volatile int ch = 0;
                    192:     
                    193:     short   group;          /* flag to scan grouped patterns */
1.6       snw       194: 
                    195:     int  max_namlen = 255;
                    196: 
                    197:     if ((rtn_dialect () == D_MDS) || (rtn_dialect () == D_M5) || (rtn_dialect () == D_FREEM)) {
                    198:         max_namlen = 255;
                    199:     }
                    200:     else {
                    201:         max_namlen = 8;
                    202:     }
1.1       snw       203:     
                    204: #ifdef DEBUG_NEWPTR
                    205:     int loop;
                    206: #endif
                    207: 
                    208:     refsx = 0;
                    209: 
                    210:     if (extyp == NAME) {
                    211: 
                    212:         f = *codptr;
                    213:         varnam[0] = f;
                    214:         
                    215:         if ((f >= 'A' && f <= 'Z') || (f >= 'a' && f <= 'z') || f == '^' || f == '$' || f == '%') {
                    216:             
                    217:             i = 1;
                    218:             
                    219:             while (((ch = *++codptr) >= 'A' && ch <= 'Z') ||
                    220:                    (ch >= 'a' && ch <= 'z') ||
                    221:                    (ch >= '0' && ch <= '9' && (i > 1 || f != '^')) ||
                    222:                    f == '^' &&
                    223:                    (((ch == '%' || ch == '$') && i == 1) ||
                    224:                     (ch == '|') ||
                    225:                     (standard == 0 &&
                    226:                      (ch == '.' ||
                    227:                       (ch == '/' && i == 1) ||
                    228:                       (((ch == '/' && varnam[i - 1] != '/') ||
                    229:                         (ch == '%' && varnam[i - 1] == '/')) &&
                    230:                        (varnam[1] == '.' || varnam[1] == '/'))))) || (f != '^') && (ch == '.')) {
                    231: 
1.6       snw       232:                 if ((i + 1) <= max_namlen) {
                    233:                     varnam[i++] = ch;
                    234:                 }
                    235:                 else {
1.7       snw       236:                     if ((rtn_dialect () == D_M77) ||
                    237:                         (rtn_dialect () == D_M84) ||
                    238:                         (rtn_dialect () == D_M90) ||
                    239:                         (rtn_dialect () == D_M95)) {
                    240:                         /* silently truncate... yeah, the standard is stupid af */
                    241:                         continue;
                    242:                     }
                    243:                     else {
                    244:                         merr_raise (M56);
                    245:                         return;
                    246:                     }
1.6       snw       247:                 }                
1.1       snw       248:                 
                    249:             }
                    250: 
1.7       snw       251:             varnam[i] = EOL;
                    252: 
                    253:             #if 0
                    254:             {
                    255:                 char gooby[256];
                    256:                 stcpy (gooby, varnam);
                    257:                 stcnv_m2c (gooby);
                    258:                 printf ("name = '%s'\r\n", gooby);
                    259:             }
                    260:             #endif
1.1       snw       261:             
                    262:             if (ch == '(') {        /* it's an array */
                    263:                 
                    264:                 op_stck[0] = 0;
                    265:                 op_stck[1] = ARRAY;
                    266:                 spx = 1;
                    267:                 a = argptr;
                    268:                 
                    269:                 if ((argstck[1] = a) >= s) {
                    270:                     
                    271:                     char   *bak;
                    272: 
                    273:                     bak = partition;
                    274: 
                    275:                     if (getpmore () == 0) {
                    276:                         merr_raise (STKOV);
                    277:                         return;
                    278:                     }
                    279:                     
                    280:                     a = a - bak + partition;
                    281:                     b = b - bak + partition;
                    282: 
                    283:                 }
                    284: 
                    285:                 a += stcpy (a, varnam) + 1;
                    286:                 
                    287:                 arg = 1;
                    288:                 codptr++;
                    289:                 
                    290:                 goto nextchr;
                    291:             }
                    292: 
                    293:             codptr--;
                    294: 
                    295:             if (i == 1 && f == '^') {
                    296:                 merr_raise (INVEXPR);
                    297:             }
                    298: 
                    299:             return;
                    300: 
                    301:         }
                    302: 
                    303:         if (f != '@') {
                    304:             merr_raise (INVREF);
                    305:             return;
                    306:         }
                    307:     
                    308:     }                   /* end if (extyp ==NAME) */
                    309: 
                    310:     arg = 0;
                    311:     spx = 0;                /* initialisation */
                    312:     op_stck[0] = 0;
                    313:     a = argptr;
                    314: 
                    315:     nextchr:
                    316:     ch = *codptr;
                    317: 
                    318:     if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '%') {
                    319: 
                    320: 
                    321: scan_name:        
                    322: 
                    323:         varnam[0] = ch;
                    324:         i = 1;
                    325:         
                    326:         if (ch == '^') {        /* global variable name */
                    327: 
                    328:             int vb_ct;
                    329:             int qt_ct;
                    330:             char lastch;
                    331:             char nextch;
                    332:             
                    333:             vb_ct = 0;
                    334:             qt_ct = 0;
                    335:             
                    336:             lastch = ' ';
                    337:             
                    338:             while (((ch = *++codptr) >= 'A' && ch <= 'Z') ||
                    339:                    (ch >= 'a' && ch <= 'z') ||
                    340:                    (ch >= '0' && ch <= '9' && i > 1) ||
                    341:                    (ch == '|') || (ch == '%') || (ch == '\"') ||
                    342:                    (((ch == '%' || ch == '$') && i == 1) ||
                    343:                     (standard == 0 &&
                    344:                      (ch == '.' ||
                    345:                       (ch == '/' && i == 1) ||
                    346:                       (((ch == '/' && varnam[i - 1] != '/') ||
                    347:                         (ch == '%' && varnam[i - 1] == '/')) &&
                    348:                        (varnam[1] == '.' || varnam[1] == '/')))))) {
                    349: 
                    350:                 nextch = *(codptr + 1);
                    351:                 
                    352:                 if (ch == '|') vb_ct++;
                    353: 
                    354:                 if (ch == '\"') {
                    355:                     qt_ct++;
                    356:                     
                    357:                     if ((lastch != '|') && (nextch != '|')) {
                    358:                         merr_raise (INVEXPR);
                    359:                         return;
                    360:                     }
                    361:                     
                    362:                 }
                    363: 
                    364:                 if ((ch == '|') && ((nextch != '\"') && (lastch != '\"'))) {
                    365: 
                    366:                     if ((qt_ct == 1) && (vb_ct == 2)) {
                    367:                         merr_raise (QUOTER);
                    368:                         return;
                    369:                     }
                    370:                     else if ((vb_ct == 2) && (qt_ct == 1)){
                    371:                         merr_raise (INVEXPR);
                    372:                         return;
                    373:                     }
                    374:                     
                    375:                 }
                    376:                 
                    377:                 if (vb_ct > 2) {
                    378:                     merr_raise (INVEXPR);
                    379:                     return;
                    380:                 }
1.8       snw       381: 
                    382:                 if ((i + 1) <= max_namlen) {
                    383:                     varnam[i++] = ch;
                    384:                 }
                    385:                 else {
                    386:                     if ((rtn_dialect () == D_M77) ||
                    387:                         (rtn_dialect () == D_M84) ||
                    388:                         (rtn_dialect () == D_M90) ||
                    389:                         (rtn_dialect () == D_M95)) {
                    390:                         /* silently truncate... yeah, the standard is stupid af */
                    391:                         continue;
                    392:                     }
                    393:                     else {
                    394:                         merr_raise (M56);
                    395:                         return;
                    396:                     }
                    397:                 }                
1.1       snw       398: 
                    399:                 lastch = ch;
                    400:             }
                    401: 
                    402:             varnam[i] = EOL;          
                    403:             
                    404:             if (i == 1 && ch != '(') {
                    405:                 merr_raise (INVEXPR);
                    406:                 return;
                    407:             }
                    408: 
                    409:         } 
                    410:         else {          /* local variable name */
                    411: 
                    412:             while (isalnum (ch = *++codptr)) {
1.8       snw       413:                 
                    414:                 if ((i + 1) <= max_namlen) {
                    415:                     varnam[i++] = ch;
                    416:                 }
                    417:                 else {
                    418:                     if ((rtn_dialect () == D_M77) ||
                    419:                         (rtn_dialect () == D_M84) ||
                    420:                         (rtn_dialect () == D_M90) ||
                    421:                         (rtn_dialect () == D_M95)) {
                    422:                         /* silently truncate... yeah, the standard is stupid af */
                    423:                         continue;
                    424:                     }
                    425:                     else {
                    426:                         merr_raise (M56);
                    427:                         return;
                    428:                     }
                    429:                 }                
                    430:                 
1.1       snw       431:             }
                    432:         
                    433:             varnam[i] = EOL;
                    434: 
                    435:             
                    436:             if (*codptr == '.') {
                    437:                 if (*(codptr + 1) == '$') {
                    438:                     codptr++;
                    439: 
                    440:                     obj_field = TRUE;
                    441:                     stcpy (object_instance, varnam);
                    442:                     stcnv_m2c (object_instance);
                    443:                     obj_get_attribute (object_instance, "CLASS", object_class);
                    444: 
                    445:                     stcnv_m2c (object_instance);
                    446:                     stcnv_c2m (object_class);
                    447:                     
                    448:                     expr (STRING);
                    449:                     return;
                    450:                 }
                    451:                 else {
                    452:                     merr_raise (INVEXPR);
                    453:                     return;
                    454:                 }
                    455:             }
                    456:             
                    457:         }
                    458:         
                    459:         if (ch == '(') {        /* it's an array */
                    460:             
                    461:             if (extyp == LABEL) {
                    462:                 codptr--;
                    463:                 return;
                    464:             }
                    465: 
                    466:             if (++spx >= PARDEPTH) {
                    467:                 merr_raise (STKOV);
                    468:                 return;
                    469:             }
                    470: 
                    471:             op_stck[spx] = ARRAY;
                    472:             
                    473:             if ((argstck[++arg] = a) >= s) {
                    474:                 
                    475:                 char   *bak;
                    476:                 bak = partition;
                    477: 
                    478:                 if (getpmore () == 0) {
                    479:                     merr_raise (STKOV);
                    480:                     return;
                    481:                 }
                    482:                 
                    483:                 a = a - bak + partition;
                    484:                 b = b - bak + partition;
                    485: 
                    486:             }
                    487: 
                    488:             a += stcpy (a, varnam) + 1;
                    489:             codptr++;
                    490:             
                    491:             goto nextchr;
                    492: 
                    493:         }
                    494: 
                    495:         if (spx == 0) {
                    496:             
                    497:             if (extyp != STRING && extyp != ARGIND && extyp != OFFSET) {
                    498:                 codptr--;
                    499:                 return;
                    500:             }
                    501: 
                    502:             if (varnam[0] != '^') {
                    503:                 symtab (get_sym, varnam, a);
                    504:             }
                    505:             else if (varnam[1] != '$') {
                    506:                 global (get_sym, varnam, a);
                    507:             }
                    508:             else {
                    509:                 ssvn (get_sym, varnam, a);
                    510:             }
                    511:             
                    512:             if (merr () != OK) {
                    513: 
                    514:                 stcpy (varerr, varnam);
                    515:                 
                    516:                 if (merr () == UNDEF || merr () == M6 || merr () == M7) {
                    517:                     arg = 1;
                    518:                     codptr--;
                    519:                     
                    520:                     goto undefglvn;
                    521:                 }
                    522: 
                    523:             }
                    524: 
                    525:             if (ch == EOL || ch == SP || (extyp == ARGIND) || ch == ',' || ch == ':' || ch == ')' || ch == '@' || (merr () > OK)) {
                    526:                 return;
                    527:             }
                    528: 
                    529:             arg = 1;
                    530:             argstck[1] = a;
                    531:             f = OPERAND;
                    532:             op_stck[1] = f;
                    533:             spx = 2;
                    534: 
                    535:             goto op10;          /* shortcut: following char is garbage or operator */
                    536: 
                    537:         }
                    538: 
                    539:         codptr--;
                    540:         
                    541:         if ((argstck[++arg] = a) >= s) {
                    542:             
                    543:             char   *bak;
                    544:             bak = partition;
                    545: 
                    546:             if (getpmore () == 0) {
                    547:                 merr_raise (STKOV);
                    548:                 return;
                    549:             }
                    550: 
                    551:             a = a - bak + partition;
                    552:             b = b - bak + partition;
                    553: 
                    554:         }
                    555: 
                    556:         /* evaluate glvn or $_(glvn) */
                    557: 
                    558: var1:
                    559:         
                    560:         if (op_stck[spx] == '$') {
                    561: 
                    562:             f = op_stck[spx - 1];
                    563: 
                    564:             
                    565:             switch (f) {
                    566: 
                    567: 
                    568:                 case 'd':           /* $DATA */
                    569:                     
1.10      snw       570:                     ch = fra_dat;
1.1       snw       571: 
                    572: glv_fcn:
                    573: 
                    574:                     if (varnam[0] != '^') {
                    575:                         symtab (ch, varnam, a);
                    576:                     }
                    577:                     else if (varnam[1] != '$'){
                    578:                         global  (ch, varnam, a);
                    579:                     }
                    580:                     else {
                    581:                         ssvn (ch, varnam, a);
                    582:                     }
                    583: 
                    584: d_o_n:
                    585: 
                    586:                     if (*++codptr != ')') merr_raise (INVEXPR);
                    587: 
                    588:                     if (merr () > OK) {
                    589:                         stcpy (varerr, varnam);
                    590:                         return;
                    591:                     }
                    592: 
                    593:                     spx -= 2;
                    594:                     
                    595:                     goto nxt_operator;
                    596: 
                    597: 
                    598:                 case 'o':           /* $ORDER */
                    599: 
                    600:                     if (rtn_dialect () == D_M77) {
                    601:                         merr_raise (NOSTAND);
                    602:                         return;
                    603:                     }
                    604:                     
                    605:                     ch = fra_order;
                    606:                     ordercnt = 1L;
                    607:                     
                    608:                     if (*(codptr + 1) != ',') {
                    609:                         ordercounter = 0;
                    610:                         goto glv_fcn;
                    611:                     }
                    612: 
                    613:                     if (++spx > PARDEPTH) {
                    614:                         merr_raise (STKOV);
                    615:                         return;
                    616:                     }
                    617: 
                    618:                     stcpy (a, varnam);
                    619:                     
                    620:                     op_stck[spx] = OPERAND;
                    621:                     codptr++;
                    622:                     
                    623:                     goto nextchr;
                    624: 
                    625: 
                    626:                 case 'n':           /* $NEXT */
                    627: 
                    628:                     ordercnt = 1L;
                    629:                     ordercounter = 0;
                    630:                     
                    631:                     if (varnam[0] != '^') {
                    632:                         symtab (fra_order, varnam, a);
                    633:                     }
                    634:                     else if (varnam[1] != '$') {
                    635:                         global  (fra_order, varnam, a);
                    636:                     }
                    637:                     else {
                    638:                         ssvn (fra_order, varnam, a);
                    639:                     }
                    640: 
                    641:                     if (a[0] == EOL) {
                    642:                         a[0] = '-';
                    643:                         a[1] = '1';
                    644:                         a[2] = EOL;
                    645:                     }
                    646: 
                    647:                     goto d_o_n;
                    648: 
                    649: 
                    650:                 case 'q':           /* $QUERY */
                    651:                 case 'O':           /* $ZORDER */
                    652:                 
                    653:                     ch = fra_query;
                    654:                     ordercnt = 1L;
                    655:                     
                    656:                     if (*(codptr + 1) != ',') goto glv_fcn;
                    657: 
                    658:                     if (++spx > PARDEPTH) {
                    659:                         merr_raise (STKOV);
                    660:                         return;
                    661:                     }
                    662: 
                    663:                     stcpy (a, varnam);
                    664:                     
                    665:                     op_stck[spx] = OPERAND;
                    666:                     codptr++;
                    667:                     
                    668:                     goto nextchr;
                    669: 
                    670: 
                    671:                 case ZNEXT:     /* $ZNEXT */
                    672: 
                    673:                     ordercnt = 1L;
                    674:                     
                    675:                     if (varnam[0] != '^') {
                    676:                         symtab (fra_query, varnam, a);
                    677:                     }
                    678:                     else if (varnam[1] != '$') {
                    679:                         global  (fra_query, varnam, a);
                    680:                     }
                    681:                     else {
                    682:                         ssvn (fra_query, varnam, a);
                    683:                     }
                    684:                     
                    685:                     if (a[0] == EOL) {
                    686:                         a[0] = '-';
                    687:                         a[1] = '1';
                    688:                         a[2] = EOL;
                    689:                     }
                    690: 
                    691:                     goto d_o_n;
                    692: 
                    693: 
                    694:                 case 'N':           /* $NAME */
                    695: 
                    696:                     /* resolve naked reference */
                    697:                     if (varnam[0] == '^' && varnam[1] == DELIM) {
                    698:                         
                    699:                         stcpy (a, zref);
                    700:                         ch = stlen (a);
                    701:                         
                    702:                         while (a[ch--] != DELIM) {
                    703:                         
                    704:                             if (ch <= 0) {
                    705:                                 merr_raise (NAKED);
                    706:                                 return;
                    707:                             }
                    708:                         
                    709:                         }
                    710: 
                    711:                         stcpy (&a[++ch], &varnam[1]);
                    712:                         stcpy (varnam, a);
                    713: 
                    714:                     }
                    715: 
                    716:                     if (*(codptr + 1) != ',') {
                    717:                         zname (a, varnam);
                    718:                         goto d_o_n;
                    719:                     }
                    720: 
                    721:                     if (++spx > PARDEPTH) {
                    722:                         merr_raise (STKOV);
                    723:                         return;
                    724:                     }
                    725: 
                    726:                     stcpy (a, varnam);
                    727:                     
                    728:                     op_stck[spx] = OPERAND;
                    729:                     codptr++;
                    730:                     
                    731:                     goto nextchr;
                    732: 
                    733: 
                    734:                 case ZPREVIOUS:     /* $ZPREVIOUS */
                    735: 
                    736:                     ordercnt = (-1L);
                    737:                     ordercounter = 0;
                    738:                     ch = fra_order;
                    739:                     
                    740:                     goto glv_fcn;
                    741: 
                    742: 
                    743:                 case ZDATA:     /* $ZDATA */
                    744: 
                    745:                     ch = zdata;
                    746:                     goto glv_fcn;
                    747: 
                    748: 
                    749:                 case 'g':           /* $GET */
                    750:                     
                    751:                     if (varnam[0] != '^') {
                    752:                         symtab (get_sym, varnam, a);
                    753:                     }
                    754:                     else if (varnam[1] != '$') {
                    755:                         global (get_sym, varnam, a);
                    756:                     }
                    757:                     else {
                    758:                         ssvn (get_sym, varnam, a);
                    759:                     }
                    760: 
                    761:                     if (merr () == M7 || merr () == M6) merr_raise (UNDEF);
                    762: 
                    763:                     if (merr () > OK) {
                    764: 
                    765:                         stcpy (varerr, varnam);
                    766:                     
                    767:                         if (merr () != UNDEF) return;
                    768:                     }
                    769:                     
                    770:                     if (merr () == UNDEF) {
                    771: 
1.12    ! snw       772:                         /* smw 15 nov 2023 merr_raise (ierr < 0 ? OK - CTRLB : OK); */
1.1       snw       773:                         merr_clear ();
                    774:                         
                    775:                         if (*++codptr == ',') {
                    776: 
                    777:                             if (standard) {
                    778:                                 merr_raise (NOSTAND);
                    779:                                 return;
                    780:                             }
                    781: 
                    782:                             op_stck[spx - 1] = GET;     /* dummy function for $GET */
                    783:                             arg--;
                    784:                             codptr++;
                    785:                             
                    786:                             goto nextchr;
                    787:                         
                    788:                         } 
                    789:                         else {
                    790: 
                    791:                             if (*codptr != ')') {
                    792:                                 merr_raise (INVEXPR);
                    793:                                 return;
                    794:                             }
                    795: 
                    796:                             *a = EOL;
                    797: 
                    798:                         }
                    799: 
                    800:                     } 
                    801:                     else {        /* glvn was defined */
                    802:                         
                    803:                         if (*++codptr == ',') { /* skip second argument */
                    804:                             
                    805:                             i = 0;      /* quote flag */                            
                    806:                             f = 0;      /* bracket counter */
                    807: 
                    808:                             for (;;) {
                    809: 
                    810:                                 ch = *++codptr;
                    811:                                 
                    812:                                 if (ch == EOL) {
                    813:                                     merr_raise (INVEXPR);
                    814:                                     return;
                    815:                                 }
                    816: 
                    817:                                 if (ch == '"') {
                    818:                                     i = !i;
                    819:                                     continue;
                    820:                                 }
                    821: 
                    822:                                 if (i) continue;
                    823:                                 
                    824:                                 if (ch == '(') {
                    825:                                     f++;
                    826:                                     continue;
                    827:                                 }
                    828: 
                    829:                                 if (ch == ')') {
                    830:                                     if (--f < 0) break;
                    831:                                 }
                    832: 
                    833:                             }
                    834: 
                    835:                         } 
                    836:                         else if (*codptr != ')') {
                    837:                             merr_raise (INVEXPR);
                    838:                             return;
                    839:                         }
                    840: 
                    841:                     }
                    842: 
                    843:                     spx -= 2;
                    844:                     goto nxt_operator;
                    845: 
                    846:                 case 'i':           /* $INCREMENT */
                    847:                     
                    848:                     if (varnam[0] != '^') {
                    849:                         symtab (getinc, varnam, a);
                    850:                     }
                    851:                     else {
                    852:                         
                    853:                         int setopsav;
                    854: 
                    855:                         setopsav = setop;
                    856:                         setop = '+';
                    857:                         a[0] = '1';
                    858:                         a[1] = EOL;
                    859:                         
                    860:                         if (varnam[1] != '$') {
                    861:                             global  (set_sym, varnam, a);
                    862:                         }
                    863:                         else {
                    864:                             ssvn (set_sym, varnam, a);
                    865:                         }
                    866: 
                    867:                         setop = setopsav;
                    868: 
                    869:                     }
                    870: 
                    871:                     goto d_o_n;
                    872: 
                    873: 
                    874:                 case OPERAND:       /* three arguments $TEXT */
                    875: 
                    876:                     if (spx >= 6 && op_stck[spx - 5] == 't' && op_stck[spx - 4] == '$' && op_stck[spx - 2] == '$') {
                    877:                         
                    878:                         stcpy (a, &varnam[varnam[0]=='^']); /* third argument */
                    879:                         
                    880:                         if (++spx > PARDEPTH) {
                    881:                             merr_raise (STKOV);
                    882:                             return;
                    883:                         }
                    884: 
                    885:                         op_stck[spx] = OPERAND;
                    886:                         codptr++;
                    887:                         
                    888:                         goto nextchr;
                    889: 
                    890:                     }
                    891: 
                    892:             }               /* end switch */
                    893:         }
                    894:         
                    895:         /* retrieve look-up */
                    896: 
                    897:         if (varnam[0] != '^') {
                    898:             symtab (get_sym, varnam, a);
                    899:         }
                    900:         else if (varnam[1] != '$') {
                    901:             global  (get_sym, varnam, a);
                    902:         }
                    903:         else {
                    904:             ssvn (get_sym, varnam, a);
                    905:         }
                    906: 
                    907: 
                    908: undefglvn:
                    909: 
                    910: 
                    911:         if (merr ()) stcpy (varerr, varnam);
                    912:         
                    913:         if ((merr () == M6) || (merr () == M7) || (merr () == UNDEF)) {
                    914:             
                    915:             stcpy (tmp, codptr + 1);
                    916:             
                    917:             if (varnam[0] == '^') { /* is there a default expression?? */
                    918:                 
                    919:                 if (gvndefault[0] == EOL) return;
                    920:                 
                    921:                 stcpy (&code[1], gvndefault);
                    922: 
                    923:             } 
                    924:             else {
                    925: 
                    926:                 if (lvndefault[0] == EOL) return;
                    927:             
                    928:                 stcpy (&code[1], lvndefault);
                    929:             
                    930:             }
                    931:             
                    932:             /* simulate a $GET function */
                    933:             code[0] = SP;
                    934:             
                    935:             stcat (code, ")\201");
                    936:             stcat (code, tmp);
                    937:             
                    938:             codptr = &code[1];
                    939:             
                    940:             if (((++spx) + 1) > PARDEPTH) {
                    941:                 merr_raise (STKOV);
                    942:                 return;
                    943:             }
                    944: 
                    945:             op_stck[spx] = GETX;    /* dummy function for $GET */
                    946:             op_stck[++spx] = '$';
                    947:             
                    948:             /* stack $ZREFERENCE and $ZLOCAL */
                    949:             if ((refsav[refsx] = calloc (1, 2 * 256)) == NULL) {
                    950:                 merr_raise (STKOV);
                    951:                 return;
                    952:             }               /* could not allocate stuff...     */
                    953:             
                    954:             stcpy (refsav[refsx], zref);
                    955:             stcpy (refsav[refsx++] + 256, zloc);
                    956:             
1.12    ! snw       957:             ierr -= M7; 
1.1       snw       958:             arg--;
                    959:             
                    960:             goto nextchr;
                    961: 
                    962:         }
                    963: 
                    964:         if (merr () > OK) return;
                    965: 
                    966:         if (spx == 0) {
                    967: 
                    968:             if ((ch = *++codptr) == EOL || ch == SP || ch == ',' || ch == ':') return;
                    969: 
                    970:             if (++spx > PARDEPTH) {
                    971:                 merr_raise (STKOV);
                    972:                 return;
                    973:             }
                    974: 
                    975:             op_stck[spx] = OPERAND;
                    976:             
                    977:             goto next10;
                    978: 
                    979:         }
                    980: 
                    981:         f = op_stck[spx];
                    982:         
                    983:         if (f == ARRAY || f == '(') {
                    984:             
                    985:             if (++spx > PARDEPTH) {
                    986:                 merr_raise (STKOV);
                    987:                 return;
                    988:             }
                    989: 
                    990:             op_stck[spx] = OPERAND;
                    991:             codptr++;
                    992:             
                    993:             goto nextchr;
                    994: 
                    995:         }
                    996: 
                    997:         if (f == INDIRECT && (extyp == STRING || extyp == ARGIND || extyp == OFFSET)) {
                    998:             spx--;
                    999:             goto indirect;      /* VARIABLE indirection */
                   1000:         }
                   1001: 
                   1002:         goto nxt_expr;
                   1003: 
                   1004:     }
                   1005: 
                   1006:     if (ch >= '0' && ch <= '9') {
                   1007: 
                   1008:         if (extyp == LABEL) goto scan_name;     /* scan_label */
                   1009: 
                   1010:         /* scan number */
                   1011:         i = 0;              /* point flag */
                   1012:         j = 0;              /* exp flag */
                   1013:         f = ch;             /* first character */
                   1014: 
                   1015:         if ((argstck[++arg] = a) >= s) {
                   1016:             
                   1017:             char   *bak;
                   1018:             bak = partition;
                   1019:             
                   1020:             if (getpmore () == 0) {
                   1021:                 merr_raise (STKOV);
                   1022:                 return;
                   1023:             }
                   1024: 
                   1025:             a = a - bak + partition;
                   1026: 
                   1027:         }
                   1028: 
                   1029:         b = a;
                   1030: 
                   1031: p_entry:           /* entry point if first character was a point */
                   1032:         
                   1033:         for (;;) {
                   1034: 
                   1035:             if (ch < '0') {
                   1036: 
                   1037:                 if (ch != '.' || i || j) break;
                   1038:             
                   1039:                 i++;
                   1040: 
                   1041:             } 
                   1042:             else if (ch > '9') {
                   1043: 
                   1044:                 if (j) break;
                   1045:                 if (ch != 'E' && (lowerflag == FALSE || ch != 'e')) break;
                   1046:                 
                   1047:                 if (ch == 'E') {
                   1048:                     if ((*(codptr + 1) == 'U') && (*(codptr + 2) == 'R')) break;
                   1049:                     if ((*(codptr + 1) == 'S') && (*(codptr + 2) == 'P')) break;
                   1050:                 }
                   1051: 
                   1052:                 j++;
                   1053:                 
                   1054:                 do {
                   1055: 
                   1056:                     *b++ = ch;
                   1057:                     ch = *++codptr;
                   1058: 
                   1059:                 } while (ch == '+' || ch == '-');
                   1060: 
                   1061:             }
                   1062: 
                   1063:             *b++ = ch;
                   1064:             ch = *++codptr;
                   1065: 
                   1066:         }
                   1067: 
                   1068: #ifdef EUR2DEM
                   1069: 
                   1070:         switch (ch) {
                   1071: 
                   1072:             case 'E':
                   1073:                 
                   1074:                 if ((*(codptr + 1) == 'U') && (*(codptr + 2) == 'R')) {
                   1075:                     *b++ = ch;
                   1076:                     *b++ = *++codptr;
                   1077:                     *b++ = *++codptr;
                   1078:                     ch = *++codptr;
                   1079:                     j = 1;
                   1080:                     
                   1081:                     break;
                   1082:                 }
                   1083: 
                   1084:                 if ((*(codptr + 1) == 'S') && (*(codptr + 2) == 'P')) {
                   1085:                     *b++ = ch;
                   1086:                     *b++ = *++codptr;
                   1087:                     *b++ = *++codptr;
                   1088:                     ch = *++codptr;
                   1089:                     j = 1;
                   1090:                 }
                   1091: 
                   1092:                 break;
                   1093: 
                   1094: 
                   1095:             case 'D':
                   1096: 
                   1097:                 if (*(codptr + 1) == 'M') {
                   1098:                     *b++ = ch;
                   1099:                     *b++ = *++codptr;
                   1100:                     ch = *++codptr;
                   1101:                     j = 1;
                   1102: 
                   1103:                     break;
                   1104:                 }
                   1105: 
                   1106:                 if (*(codptr + 1) == 'E' && *(codptr + 2) == 'M') {
                   1107:                     *b++ = ch;
                   1108:                     *b++ = *++codptr;
                   1109:                     *b++ = *++codptr;
                   1110:                     ch = *++codptr;
                   1111:                     j = 1;
                   1112:                 }
                   1113: 
                   1114:                 break;
                   1115:             
                   1116: 
                   1117:             case 'A':
                   1118: 
                   1119:                 if (*(codptr + 1) == 'T' && *(codptr + 2) == 'S') {
                   1120:                     *b++ = ch;
                   1121:                     *b++ = *++codptr;
                   1122:                     *b++ = *++codptr;
                   1123:                     ch = *++codptr;
                   1124:                     j = 1;
                   1125:                 }
                   1126: 
                   1127:                 break;
                   1128:             
                   1129: 
                   1130:             case 'B':
                   1131:                 
                   1132:                 if (*(codptr + 1) == 'F' && *(codptr + 2) == 'R') {
                   1133:                     *b++ = ch;
                   1134:                     *b++ = *++codptr;
                   1135:                     *b++ = *++codptr;
                   1136:                     ch = *++codptr;
                   1137:                     j = 1;
                   1138:                 }
                   1139:                 
                   1140:                 break;
                   1141: 
                   1142: 
                   1143:             case 'F':
                   1144: 
                   1145:                 if (*(codptr + 1) == 'F') {
                   1146:                     *b++ = ch;
                   1147:                     *b++ = *++codptr;
                   1148:                     ch = *++codptr;
                   1149:                     j = 1;
                   1150: 
                   1151:                     break;
                   1152:                 }
                   1153: 
                   1154:                 if (*(codptr + 1) == 'M' && *(codptr + 2) == 'K') {
                   1155:                     *b++ = ch;
                   1156:                     *b++ = *++codptr;
                   1157:                     *b++ = *++codptr;
                   1158:                     ch = *++codptr;
                   1159:                     j = 1;
                   1160:                     
                   1161:                     break;
                   1162:                 }
                   1163: 
                   1164:                 if (*(codptr + 1) == 'R' && *(codptr + 2) == 'F') {
                   1165:                     *b++ = ch;
                   1166:                     *b++ = *++codptr;
                   1167:                     *b++ = *++codptr;
                   1168:                     ch = *++codptr;
                   1169:                     j = 1;
                   1170:                 }
                   1171: 
                   1172:                 break;
                   1173:             
                   1174: 
                   1175:             case 'I':
                   1176: 
                   1177:                 if (*(codptr + 1) == 'E' && *(codptr + 2) == 'P') {
                   1178:                     *b++ = ch;
                   1179:                     *b++ = *++codptr;
                   1180:                     *b++ = *++codptr;
                   1181:                     ch = *++codptr;
                   1182:                     j = 1;
                   1183: 
                   1184:                     break;
                   1185:                 }
                   1186: 
                   1187:                 if (*(codptr + 1) == 'T' && *(codptr + 2) == 'L') {
                   1188:                     *b++ = ch;
                   1189:                     *b++ = *++codptr;
                   1190:                     *b++ = *++codptr;
                   1191:                     ch = *++codptr;
                   1192:                     j = 1;
                   1193:                 }
                   1194: 
                   1195:                 break;
                   1196:             
                   1197: 
                   1198:             case 'N':
                   1199:                 
                   1200:                 if (*(codptr + 1) == 'L' && *(codptr + 2) == 'G') {
                   1201:                     *b++ = ch;
                   1202:                     *b++ = *++codptr;
                   1203:                     *b++ = *++codptr;
                   1204:                     ch = *++codptr;
                   1205:                     j = 1;
                   1206:                 }
                   1207: 
                   1208:                 break;
                   1209:             
                   1210: 
                   1211:             case 'P':
                   1212: 
                   1213:                 if (*(codptr + 1) == 'T' && *(codptr + 2) == 'E') {
                   1214:                     *b++ = ch;
                   1215:                     *b++ = *++codptr;
                   1216:                     *b++ = *++codptr;
                   1217:                     ch = *++codptr;
                   1218:                     j = 1;
                   1219:                 }
                   1220: 
                   1221: 
                   1222:         }
                   1223: 
                   1224: #endif /* EUR2DEM */
                   1225: 
                   1226:         *b = EOL;
                   1227: 
                   1228:         if (j || f == '0' || (i && ((*(b - 1)) < '1'))) {   /* <'1' eqiv. to '.' || '0' */
                   1229:             atyp = numlit (a);
                   1230:             if (atyp) stcat (a, WHR[atyp]);
                   1231:         }
                   1232: 
                   1233:         
                   1234:         if (spx) {
                   1235:             codptr--;
                   1236:             goto exec;
                   1237:         }
                   1238: 
                   1239:         if (ch == EOL || ch == SP || ch == ',' || ch == ':' || (ch == '^' && extyp == OFFSET)) return;
                   1240:         
                   1241:         spx = 1;
                   1242:         op_stck[1] = OPERAND;
                   1243: 
                   1244:     }
                   1245: 
                   1246:     if (ch != '"') goto next10;
                   1247: 
                   1248:     /* scan string */
                   1249:     if ((argstck[++arg] = a) >= s) {
                   1250: 
                   1251:         char *bak;
                   1252: 
                   1253:         bak = partition;
                   1254:         
                   1255:         if (getpmore () == 0) {
                   1256:             merr_raise (STKOV);
                   1257:             return;
                   1258:         }
                   1259: 
                   1260:         a = a - bak + partition;
                   1261:         b = b - bak + partition;
                   1262: 
                   1263:     }
                   1264: 
                   1265:     i = 0;
                   1266: 
                   1267:     for (;;) {
                   1268: 
                   1269:         while ((ch = *++codptr) > '"') {
                   1270:             a[i++] = ch;
                   1271:         }
                   1272:         
                   1273:         /* we make use of the fact that */
                   1274:         /* EOL < "any ASCII character" */
                   1275:         if (ch == '"' && (ch = *++codptr) != '"') {
                   1276: 
                   1277:             if (ch == '_' && *(codptr + 1) == '"') {
                   1278:                 codptr++;
                   1279:                 continue;
                   1280:             }
                   1281:             
                   1282:             a[i] = EOL;
                   1283:             
                   1284:             if (spx) {
                   1285:                 codptr--;
                   1286:                 goto exec;
                   1287:             }
                   1288:             
                   1289:             if (ch == EOL || ch == SP || ch == ',' || ch == ':') return;
                   1290:             
                   1291:             spx = 1;
                   1292:             op_stck[1] = OPERAND;
                   1293:             
                   1294:             goto next10;
                   1295: 
                   1296:         }
                   1297: 
                   1298:         if (ch == EOL) {
                   1299:             merr_raise (QUOTER);
                   1300:             return;
                   1301:         }
                   1302: 
                   1303:         a[i++] = ch;
                   1304: 
                   1305:     }
                   1306: 
                   1307: next05:
                   1308:     
                   1309:     ch = *(++codptr);
                   1310: 
                   1311: next10:
                   1312: 
                   1313:     switch (ch) {
                   1314: 
                   1315:         
                   1316:         case EOL:
                   1317:         case SP:
                   1318: 
                   1319:             if (op_stck[1] == OPERAND && spx == 1) return;
                   1320:         
                   1321:             merr_raise (INVEXPR);
                   1322:             return;
                   1323: 
                   1324: 
                   1325:         case ',':
                   1326: 
                   1327:             if (spx == 0) {
                   1328:                 merr_raise (ARGER);
                   1329:                 return;
                   1330:             }
                   1331: 
                   1332: 
                   1333: comma:
                   1334: 
                   1335:             f = op_stck[spx - 1];
                   1336: 
                   1337:             /* f= (spx>0 ? op_stck[spx-1] : 0);
                   1338:             * if (f) */ 
                   1339:             switch (f) {
                   1340: 
                   1341:                 case '$':           /* first arg of $function */
                   1342:                     
                   1343:                     if (op_stck[spx - 2] == 's') {  /* we already have one valid arg */
                   1344:                         
                   1345:                         i = 0;          /* quote *//* and skip rest of select */
                   1346:                         j = 0;          /* bracket */
                   1347:                         
                   1348:                         for (;;) {
                   1349: 
                   1350:                             ch = *++codptr;
                   1351:                             
                   1352:                             if (ch == '"') {
                   1353:                                 toggle (i);
                   1354:                                 continue;
                   1355:                             }
                   1356: 
                   1357:                             if (i) {
                   1358:                                 if (ch != EOL) continue;
                   1359:                                 
                   1360:                                 merr_raise (QUOTER);
                   1361:                                 return;
                   1362:                             }
                   1363: 
                   1364:                             if (ch == ')') {
                   1365:                                 
                   1366:                                 if (j--) continue;
                   1367:                                 
                   1368:                                 spx -= 3;
                   1369:                                 
                   1370:                                 goto nxt_operator;
                   1371:                             }
                   1372: 
                   1373:                             if (ch == '(') {
                   1374:                                 j++;
                   1375:                                 continue;
                   1376:                             }
                   1377: 
                   1378:                             if (ch == EOL) {
                   1379:                                 merr_raise (SELER);
                   1380:                                 return;
                   1381:                             }
                   1382:                         }
                   1383: 
                   1384:                     }
                   1385: 
                   1386:                     /* function argument */
                   1387:                     /* put comma on the stack */
                   1388:                     if (++spx > PARDEPTH) {
                   1389:                         merr_raise (STKOV);
                   1390:                         return;
                   1391:                     }
                   1392: 
                   1393:                     op_stck[spx] = f;       /* '$' */
                   1394: 
                   1395:                     /*       a+=stlen(a)+1; */ 
                   1396:                     
                   1397:                     while (*a++ != EOL);
                   1398: 
                   1399:                     codptr++;
                   1400:                     
                   1401:                     goto nextchr;
                   1402: 
                   1403: 
                   1404:                 case ARRAY:         /* array subscript */
                   1405: 
                   1406:                     *(a - 1) = DELIM;
                   1407:                     arg--;
                   1408:                     spx--;
                   1409: 
                   1410:                     while (*a++ != EOL) ;
                   1411: 
                   1412:                     codptr++;
                   1413: 
                   1414:                     goto nextchr;
                   1415: 
                   1416: 
                   1417:                 default:
                   1418: 
                   1419:                     if ((extyp == NAME) || (spx > 1)) {
                   1420:                         merr_raise (INVEXPR);
                   1421:                         return;
                   1422:                     }
                   1423:                 
                   1424:                     return;
                   1425: 
                   1426:             }
                   1427: 
                   1428:         case '^':
                   1429: 
                   1430:             if (extyp == LABEL || extyp == OFFSET) break;
                   1431:             
                   1432: uparrow:
                   1433:         
                   1434:             if (spx >= 5) {         /* take care of $TEXT with three args */
                   1435:                 
                   1436:                 if (op_stck[spx - 4] == 't' && op_stck[spx - 3] == '$' && op_stck[spx - 1] == '$') {
                   1437: 
                   1438:                     if (++spx > PARDEPTH) {
                   1439:                         merr_raise (STKOV);
                   1440:                         return;
                   1441:                     }
                   1442: 
                   1443:                     op_stck[spx] = '$';
                   1444:                     
                   1445:                     while (*a++ != EOL);
                   1446:                     
                   1447:                     if (*(codptr+1)=='@') goto next05;
                   1448: 
                   1449:                 }
                   1450: 
                   1451:             }
                   1452: 
                   1453:             goto scan_name;
                   1454:     
                   1455: 
                   1456:         case '.':
                   1457: 
                   1458:             if ((ch = *++codptr) < '0' || ch > '9') {
                   1459:                 merr_raise (INVEXPR);
                   1460:                 return;
                   1461:             }
                   1462: 
                   1463:             if ((argstck[++arg] = a) >= s) {
                   1464:                 
                   1465:                 char   *bak;
                   1466:                 bak = partition;
                   1467:                 
                   1468:                 if (getpmore () == 0) {
                   1469:                     merr_raise (STKOV);
                   1470:                     return;
                   1471:                 }
                   1472: 
                   1473:                 a = a - bak + partition;
                   1474:                 b = b - bak + partition;
                   1475: 
                   1476:             }
                   1477:             
                   1478:             i = 1;              /* point flag */
                   1479:             j = 0;              /* exp flag */
                   1480:             f = '.';            /* first character */
                   1481:             b = a;
                   1482:             *b++ = f;
                   1483:             
                   1484:             goto p_entry;
                   1485: 
                   1486: 
                   1487:         case ')':
                   1488: 
                   1489:             if (spx <= 1) {
                   1490: 
                   1491:                 if (setpiece) return;
                   1492: 
                   1493:                 if (spx == 0) {
                   1494:                     merr_raise (BRAER);
                   1495:                     return;
                   1496:                 }
                   1497: 
                   1498:             }
                   1499: 
                   1500:             if (op_stck[spx] != OPERAND) {
                   1501:                 merr_raise (INVEXPR);
                   1502:                 return;
                   1503:             }
                   1504: 
                   1505:             if ((f = op_stck[spx - 1]) == ARRAY) {  /* array return */
                   1506:                 
                   1507:                 *--a = DELIM;
                   1508:                 stcpy (varnam, a = argstck[--arg]);
                   1509:             
                   1510:                 if ((spx -= 2) <= 0 && extyp != STRING && extyp != ARGIND) return;
                   1511:                 
                   1512:                 goto var1;
                   1513:             
                   1514:             }
                   1515:             
                   1516:             /* precedence close parenthesis */
                   1517:             if (f == '(') {
                   1518:                 spx -= 2;
                   1519:                 goto nxt_operator;
                   1520:             }
                   1521: 
                   1522:             if (spx <= 2) {
                   1523:                 merr_raise (BRAER);
                   1524:                 return;
                   1525:             }               /* unmatched ')' */
                   1526: 
                   1527: 
                   1528:             /**
                   1529:             * *********** function evaluation ******************************************
                   1530:             * 
                   1531:             * Note: Input for function() is found in 'partition':
                   1532:             * There are 'f' arguments to be found at 'a'
                   1533:             * The arguments are separated by an EOL character.
                   1534:             * There is a list of the addresses of the arguments
                   1535:             * in 'a==argstck[arg], argstck[arg+1], argstck[arg+f-1]'
                   1536:             * Result is returned at a==argstck[arg]
                   1537:             * 
                   1538:             */
                   1539:             f = 1;              /* f == number of arguments */
                   1540:             if (op_stck[spx -= 2] == OPERAND) {
                   1541: 
                   1542:                 do {
                   1543:                     f++;
                   1544:                     arg--;
                   1545:                 } while (op_stck[spx -= 2] == OPERAND);
                   1546:                 
                   1547:                 a = argstck[arg];
                   1548: 
                   1549:             }
                   1550: 
                   1551:             i = op_stck[spx--];
                   1552:         
                   1553:             switch (i) {            /* function select */
                   1554:                 
                   1555: 
                   1556:                 case 'e':           /* $EXTRACT */
                   1557: 
                   1558:                     switch (f) {
                   1559: 
                   1560: 
                   1561:                         case 1:
                   1562:                         
                   1563:                             a[1] = EOL;
                   1564:                             goto nxt_operator;
                   1565:                         
                   1566: 
                   1567:                         case 2:
                   1568:                         
                   1569:                             b = argstck[arg + 1];
                   1570:                             i = intexpr (b) - 1;    /* numeric value of 2nd argument */
                   1571: 
                   1572:                             /*set_io (UNIX);
                   1573:                             printf ("i = %d a = '%s'\n", i, a[i]);
                   1574:                             set_io (MUMPS);*/
                   1575:                             
                   1576:                             if (merr () == MXNUM) {
                   1577:                                 merr_raise (OK);
                   1578:                                 if (i >= 0) i = 256;
                   1579:                             }
                   1580: 
                   1581:                             f = b - a - 1;      /* length of first argument */
                   1582:                             
                   1583:                             if (i > f || i < 0) {
                   1584:                                 if (i > f) {
                   1585:                                     a[0] = EOL;
                   1586:                                     goto nxt_operator;
                   1587:                                 }
                   1588:                                 if (i < 0) {
                   1589:                                     if (en_revstrf && !standard) {
                   1590:                                         a[0] = a[f - (abs(i) - 1)];
                   1591:                                         a[1] = EOL;
                   1592:                                     }
                   1593:                                     else {
                   1594:                                         a[0] = EOL;
                   1595:                                     }
                   1596:                                 }
                   1597:                             }
                   1598:                             else {
                   1599:                                 /* out of range */
                   1600:                                 a[0] = a[i];
                   1601:                                 a[1] = EOL;
                   1602:                             }           /* get character */
                   1603:                             
                   1604:                             goto nxt_operator;
                   1605: 
                   1606: 
                   1607:                         case 3:
                   1608: 
                   1609:                         {
                   1610:                             char tstr[STRLEN];
                   1611:                             long int e_length;
                   1612:                             long int e_start;
                   1613:                             long int e_end;
                   1614: 
                   1615:                             stcpy (tstr, a);
                   1616: 
                   1617:                             e_start = intexpr (argstck[arg + 1]) - 1;
                   1618:                             e_end = intexpr (argstck[arg + 2]);
                   1619:                             e_length = stlen(tstr);
                   1620: 
                   1621:                             if (e_start < 0) {
                   1622: 
                   1623:                                 if (en_revstrf && !standard) {
                   1624:                                     e_start = e_length - abs(e_start) + 1;
                   1625:                                 }
                   1626:                                 else {
                   1627:                                     a[0] = EOL;
                   1628:                                     goto nxt_operator;
                   1629:                                 }
                   1630: 
                   1631:                             }
                   1632:                             
                   1633:                             if (e_end < 0) {
                   1634: 
                   1635:                                 if (en_revstrf && !standard) {
                   1636:                                     e_end = e_length - abs(e_end) + 1;
                   1637:                                 }
                   1638:                                 else {
                   1639:                                     a[0] = EOL;
                   1640:                                     goto nxt_operator;
                   1641:                                 }
                   1642: 
                   1643:                             }
                   1644: 
                   1645:                             tstr[e_end] = EOL;
                   1646:                             stcpy (a, &(tstr[e_start]));
                   1647: 
                   1648:                             goto nxt_operator;
                   1649:                             
                   1650:                         }
                   1651:                             
                   1652:                         default:
                   1653:                             merr_raise (FUNARG); 
                   1654:                                 
                   1655:                             {
                   1656:                                 return;
                   1657:                             }
                   1658: 
                   1659:                     }
                   1660: 
                   1661:                 case 'a':           /* $ASCII */
                   1662: 
                   1663:                     if (f == 1) {
                   1664:                         intstr (a, (*a != EOL ? UNSIGN ((int) *a) : -1));
                   1665:                         goto nxt_operator;
                   1666:                     }
                   1667: 
                   1668:                     if (f > 2) {
                   1669:                         merr_raise (FUNARG);
                   1670:                         return;
                   1671:                     }
                   1672: 
                   1673:                     b = argstck[arg + 1];
                   1674:                     i = intexpr (b);
                   1675: 
                   1676:                     /* ascii number of selected character or -1 if out of range */
                   1677:                     intstr (a, (i >= (b - a)) || i <= 0 ? -1 : UNSIGN ((int) a[i - 1]));
                   1678:                     
                   1679:                     goto nxt_operator;
                   1680: 
                   1681: 
                   1682:                 case 'c':           /* $CHARACTER */
                   1683: 
1.11      snw      1684:                     {                        
                   1685:                         char chrtmp[256];
                   1686:                         long pnum;
1.1       snw      1687:                         short l, l1, m, n;
                   1688: 
                   1689:                         l1 = f;
                   1690:                         i = 0;
                   1691:                         f = 0;
                   1692:                         j = 0;
                   1693:                         m = 0;
                   1694:                         n = 1;
                   1695:                         l = 0;
                   1696: 
1.11      snw      1697:                         stcpy (chrtmp, a);
                   1698:                         stcnv_m2c (chrtmp);
                   1699:                         pnum = atol (chrtmp);
                   1700: 
                   1701:                         if (pnum > 127) {
                   1702:                             merr_raise (MXNUM);
                   1703:                             return;
                   1704:                         }
                   1705:                         
1.1       snw      1706:                         for (;;) {
                   1707:                             
                   1708:                             if ((ch = a[i++]) == EOL) {
                   1709: 
                   1710:                                 if (m == 0) {
                   1711: 
                   1712:                                     if (j > DEL) {
                   1713:                                     
                   1714:                                         if (standard) {
                   1715:                                             merr_raise (NOSTAND);
                   1716:                                             return;
                   1717:                                         }
                   1718:                                     
                   1719:                                         if (eightbit) {
                   1720:                                             j &= 0377;
                   1721:                                             if ((((char) j) == EOL) || (((char) j) == DELIM)) j = NUL;
                   1722:                                         } 
                   1723:                                         else {
                   1724:                                             j &= 0177;
                   1725:                                         }
                   1726: 
                   1727:                                     }
                   1728: 
                   1729:                                     if (f >= STRLEN) {
                   1730:                                         a[f] = EOL;
                   1731:                                         merr_raise (M75);
                   1732:                                     
                   1733:                                         return;
                   1734:                                     }
                   1735: 
                   1736:                                     a[f++] = j;
                   1737: 
                   1738:                                 }
                   1739: 
                   1740:                                 if (++l >= l1) break;
                   1741: 
                   1742:                                 j = 0;
                   1743:                                 m = 0;
                   1744:                                 n = 1;
                   1745:                                 
                   1746:                                 continue;
                   1747: 
                   1748:                             }
                   1749: 
                   1750:                             if (n == 0) continue;
                   1751:                             
                   1752:                             if (ch >= '0' && ch <= '9') {
                   1753:                                 j *= 10;
                   1754:                                 j += ch - '0';
                   1755:                             
                   1756:                                 continue;
                   1757:                             }
                   1758: 
                   1759:                             if (ch == '-') {
                   1760:                                 m |= 01;
                   1761:                                 continue;
                   1762:                             }
                   1763: 
                   1764:                             if (ch != '+') n = 0;
                   1765: 
                   1766:                         }
                   1767: 
                   1768:                         a[f] = EOL;
                   1769: 
                   1770:                     }
                   1771:                     
                   1772:                     goto nxt_operator;
                   1773: 
                   1774: 
                   1775:                 case 'p':           /* $PIECE */
                   1776: 
                   1777:                     {
                   1778:                         long l, l1, m, n;
                   1779: 
                   1780:                         b = argstck[arg + 1];
                   1781:                         l1 = b - a - 1;     /* length of 1st argument */
                   1782: 
                   1783:                         switch (f) {
                   1784: 
                   1785: 
                   1786:                             case 2:
                   1787: 
                   1788:                                 f = 1;
                   1789:                                 l = 1;
                   1790: 
                   1791:                                 break;
                   1792:                             
                   1793: 
                   1794:                             case 3:
                   1795: 
                   1796:                                 f = intexpr (argstck[arg + 2]);
                   1797:                                 
                   1798:                                 if (merr () == MXNUM) {
                   1799:                                     merr_raise (OK);
                   1800:                                     if (j >= 0) f = 256;
                   1801:                                 }
                   1802: 
                   1803:                                 if (f <= 0) {
                   1804:                                     a[0] = EOL;
                   1805:                                     goto nxt_operator;
                   1806:                                 }
                   1807: 
                   1808:                                 l = f;
                   1809:                                 
                   1810:                                 break;
                   1811:                             
                   1812: 
                   1813:                             case 4:
                   1814: 
                   1815:                                 l = intexpr (argstck[arg + 3]);
                   1816:                                 
                   1817:                                 if (merr () == MXNUM) {
                   1818:                                     merr_raise (OK);
                   1819:                                     if (l >= 0) l = 256;
                   1820:                                 }
                   1821: 
                   1822:                                 if ((f = intexpr (argstck[arg + 2])) <= 0) f = 1;
                   1823: 
                   1824:                                 if (merr () == MXNUM) {
                   1825:                                     merr_raise (OK);
                   1826:                                     if (f >= 0) f = 256;
                   1827:                                 }
                   1828: 
                   1829:                                 if (f > l) {
                   1830:                                     a[0] = EOL;
                   1831:                                     goto nxt_operator;
                   1832:                                 }
                   1833: 
                   1834:                                 break;
                   1835:                             
                   1836: 
                   1837:                             default:
                   1838: 
                   1839:                                 merr_raise (FUNARG);
                   1840:                                 return;
                   1841:                         }
                   1842: 
                   1843:                         i = 0;
                   1844:                         m = 0;
                   1845:                         ch = 0;
                   1846:                         
                   1847:                         while (b[ch] != EOL) ch++;       /* $l of 2nd arg */
                   1848: 
                   1849:                         if (ch == 1) {
                   1850: 
                   1851:                             ch = b[0];
                   1852:                             j = 1;
                   1853:                             
                   1854:                             if (f > 1) {
                   1855: 
                   1856:                                 while (i < l1) {    /* scan 1st string ... */
                   1857:                                 
                   1858:                                     if (a[i++] != ch) continue;   /* ... for occurence of 2nd */
                   1859:                                 
                   1860:                                     if (++j == f) {
                   1861:                                         m = i;
                   1862:                                         goto p10;
                   1863:                                     }
                   1864: 
                   1865:                                 }
                   1866: 
                   1867:                                 a[0] = EOL;
                   1868:                                 goto nxt_operator;
                   1869:                             
                   1870:                             }
                   1871:                             
                   1872: p10:
                   1873:                             for (; i < l1; i++) {
                   1874: 
                   1875:                                 if (a[i] != ch) continue;
                   1876:                                 
                   1877:                                 if (j == l) {
                   1878:                                     a[i] = EOL;
                   1879:                                     break;
                   1880:                                 }
                   1881: 
                   1882:                                 j++;
                   1883: 
                   1884:                             }
                   1885: 
                   1886:                             if (m > 0) stcpy (a, &a[m]);
                   1887: 
                   1888:                             goto nxt_operator;
                   1889: 
                   1890:                         }
                   1891:                         
                   1892:                         if (ch == 0) {
                   1893:                             a[0] = EOL;
                   1894:                             goto nxt_operator;
                   1895:                         }           /* 2nd arg is empty */
                   1896:                         
                   1897:                         /* else (ch>1) */
                   1898:                         n = 1;
                   1899:                         
                   1900:                         if (f > 1) {
                   1901: 
                   1902:                             while (i < l1) {    /* scan 1st string ... */
                   1903:                                 j = 0;
                   1904:                                 
                   1905: p20:
                   1906: 
                   1907:                                 if (a[i + j] != b[j]) {
                   1908:                                     i++;
                   1909:                                     continue;
                   1910:                                 }       /* ... for occurence of 2nd */
                   1911:                                 
                   1912:                                 if (++j < ch) goto p20;
                   1913: 
                   1914:                                 i += ch;    /* skip delimiter */
                   1915:                                 
                   1916:                                 if (++n == f) {
                   1917:                                     m = i;
                   1918:                                     goto p30;
                   1919:                                 }
                   1920:                             }
                   1921:                             
                   1922:                             a[0] = EOL;
                   1923:                             
                   1924:                             goto nxt_operator;
                   1925:                         
                   1926:                         }
                   1927: p30:                    
                   1928:                         while (i < l1) {
                   1929:                             j = 0;
                   1930:                             
                   1931: p40:
                   1932: 
                   1933:                             if (a[i + j] != b[j]) {
                   1934:                                 i++;
                   1935:                                 continue;
                   1936:                             }
                   1937: 
                   1938:                             if (++j < ch) goto p40;
                   1939:                             
                   1940:                             if (n == l) {
                   1941:                                 a[i] = EOL;
                   1942:                                 break;
                   1943:                             }           /* last $piece: done! */
                   1944:                             
                   1945:                             i += ch;
                   1946:                             n++;
                   1947: 
                   1948:                         }
                   1949: 
                   1950:                         if (m > 0) stcpy (a, &a[m]);
                   1951:                         
                   1952:                         goto nxt_operator;
                   1953:                     
                   1954:                     }
                   1955: 
                   1956:                 case 'l':           /* $LENGTH */
                   1957: 
                   1958:                     if (f == 1) {
                   1959:                         lintstr (a, stlen (a));
                   1960:                         goto nxt_operator;
                   1961:                     }
                   1962: 
                   1963:                     if (f > 2) {
                   1964:                         merr_raise (FUNARG);
                   1965:                         return;
                   1966:                     }
                   1967: 
                   1968:                     i = 0;
                   1969:                     j = 0;
                   1970:                     ch = 0;
                   1971:                     b = argstck[arg + 1];
                   1972:                     
                   1973:                     if ((f = stlen (b))) {
                   1974: 
                   1975:                         f--;
                   1976:                         
                   1977:                         while ((i = find (&a[ch], b)) > 0) {
                   1978:                         j++;
                   1979:                         ch += i + f;
                   1980:                         }
                   1981:                         
                   1982:                         j++;
                   1983: 
                   1984:                     }
                   1985: 
                   1986:                     intstr (a, j);
                   1987: 
                   1988:                     goto nxt_operator;
                   1989: 
                   1990:                 case 'f':           /* $FIND */
                   1991: 
                   1992:                     {
                   1993:                         short l1;
                   1994: 
                   1995:                         if (f < 2 || f > 3) {
                   1996:                             merr_raise (FUNARG);
                   1997:                             return;
                   1998:                         }
                   1999: 
                   2000:                         if (f == 3) {
                   2001: 
                   2002:                             i = intexpr (argstck[arg + 2]);
                   2003:                             
                   2004:                             if (merr () == MXNUM) {
                   2005:                                 
                   2006:                                 if (i > 0) i = 256;
                   2007:                                 
                   2008:                                 merr_raise (OK);
                   2009:                                 
                   2010:                                 /* important special case:
                   2011:                                 * $FIND("","",number) ::= $S(number<1:1,1:integer(number))
                   2012:                                 * needs special treatment so that it does not yield wrong
                   2013:                                 * results on large values of number.
                   2014:                                 */
                   2015:                                 if ((argstck[arg + 1][0] == EOL) && (i > 0)) {
                   2016: 
                   2017:                                     numlit (argstck[arg + 2]);
                   2018:                                     
                   2019:                                     i = 0;
                   2020:                                     
                   2021:                                     while ((a[i] = argstck[arg + 2][i]) != EOL) {
                   2022: 
                   2023:                                         if (a[i] == '.') {
                   2024:                                             a[i] = EOL;
                   2025:                                             break;
                   2026:                                         }
                   2027: 
                   2028:                                         i++;
                   2029: 
                   2030:                                     }
                   2031: 
                   2032:                                     goto nxt_operator;
                   2033: 
                   2034:                                 }
                   2035:                             }
                   2036: 
                   2037:                             i--;
                   2038:                             
                   2039:                             if (i < 0) i = 0;
                   2040: 
                   2041:                         } 
                   2042:                         else {
                   2043:                             i = 0;
                   2044:                         }
                   2045: 
                   2046:                         b = argstck[arg + 1];
                   2047:                         j = b - a - 1;      /* length of first argument */
                   2048:                         
                   2049:                         if ((l1 = stlen (b)) == 0) {
                   2050:                             i++;
                   2051:                             goto f20;
                   2052:                         }
                   2053: 
                   2054:                         for (f = i; f < j; f++) {
                   2055:                             
                   2056:                             for (ch = 0; ch < l1; ch++) {
                   2057:                                 if (a[f + ch] != b[ch]) goto f10;
                   2058:                             }
                   2059: 
                   2060:                             i = (++f) + l1;
                   2061:                             
                   2062:                             goto f20;
                   2063: 
                   2064: f10:
                   2065:                             ; /* null statement to avoid compiler error
                   2066:                                  due to having a label at the end of a
                   2067:                                  block */
                   2068: 
                   2069:                         }
                   2070: 
                   2071:                         i = 0;
                   2072:                         
                   2073: f20:
                   2074: 
                   2075:                         lintstr (a, i);
                   2076: 
                   2077:                     }
                   2078: 
                   2079:                     goto nxt_operator;
                   2080: 
                   2081: 
                   2082:                 case 'j':           /* $JUSTIFY */
                   2083: 
                   2084:                     if (f < 2 || f > 3) {
                   2085:                         merr_raise (FUNARG);
                   2086:                         return;
                   2087:                     } 
                   2088: 
                   2089:                     {
                   2090:                         long l, l1;
                   2091: 
                   2092:                         l = intexpr (b = argstck[arg + 1]); /* 2nd arg */
                   2093:                         if (merr () == MXNUM) return; /* $J() arg number overflow */
                   2094:                         
                   2095:                         if (l > STRLEN) {
                   2096:                             /* $J() width string too long   */
                   2097:                             merr_raise (M75);
                   2098:                             return;
                   2099:                         }
                   2100: 
                   2101:                         if (f == 2) {
                   2102:                             f = b - a - 1;
                   2103:                         } 
                   2104:                         else {
                   2105: 
                   2106:                             f = intexpr (argstck[arg + 2]); /* 3rd arg */
                   2107: 
                   2108:                             if (merr () == MXNUM) return;  /* $J() arg number overflow */
                   2109: 
                   2110:                             if (f > (STRLEN - 2)) {
                   2111:                                 /* $J() .precision too long */
                   2112:                                 merr_raise (M75);
                   2113:                                 return;
                   2114:                             }
                   2115: 
                   2116:                             numlit (a);
                   2117:                             
                   2118:                             if (f < 0) {
                   2119:                                 merr_raise (ARGER);
                   2120:                                 return;
                   2121:                             }
                   2122: 
                   2123:                             /* s j=$l(a),i=$f(a,".")-1 */
                   2124:                             j = (a[0] == '-');
                   2125:                             
                   2126:                             if (a[j] == '.') {  /* insert leading zero */
                   2127:                                 
                   2128:                                 i = j;
                   2129:                                 
                   2130:                                 while (a[i++] != EOL);
                   2131:                                 
                   2132:                                 while (i > j) {
                   2133:                                     a[i] = a[i - 1];
                   2134:                                     i--;
                   2135:                                 }
                   2136: 
                   2137:                                 a[j] = '0';
                   2138: 
                   2139:                             }
                   2140: 
                   2141:                             i = (-1);
                   2142:                             j = 0;
                   2143:                             
                   2144:                             while (a[j] != EOL) {
                   2145:                                 if (a[j] == '.') i = j;
                   2146:                                 j++;
                   2147:                             }
                   2148: 
                   2149:                             if (i < 0) {
                   2150:                                 a[i = j] = '.';
                   2151:                                 a[j + 1] = EOL;
                   2152:                             } 
                   2153:                             else {
                   2154:                                 j--;
                   2155:                             }
                   2156:                             
                   2157:                             if (j - i > f) {    /* rounding required */
                   2158:                                 
                   2159:                                 if ((l1 = f + i + 1) > STRLEN) {
                   2160:                                     merr_raise (M75);
                   2161:                                     return;
                   2162:                                 }
                   2163:                                 
                   2164:                                 if (a[l1] > '4') {
                   2165: 
                   2166:                                     do {
                   2167:                                         
                   2168:                                         if (a[--l1] == '.') l1--;
                   2169: 
                   2170:                                         if (l1 < (a[0] == '-')) {
                   2171: 
                   2172:                                             for (l1 = f + i + 1; l1 > 0; l1--) a[l1] = a[l1 - 1];
                   2173:                                             
                   2174:                                             a[a[0] == '-'] = '1';
                   2175:                                             i++;
                   2176:                                             
                   2177:                                             break;
                   2178:                                         
                   2179:                                         }
                   2180:                                         
                   2181:                                         a[l1]++;
                   2182:                                         
                   2183:                                         if (a[l1] == ':') a[l1] = '0';
                   2184: 
                   2185:                                     } while (a[l1] == '0');
                   2186: 
                   2187:                                 }
                   2188: 
                   2189:                                 a[f + i + 1] = EOL;
                   2190:                                 
                   2191:                                 if (a[0] == '-' && a[1] == '0') {
                   2192:                                     
                   2193:                                     l1 = 2;
                   2194:                                     
                   2195:                                     while (a[l1] != EOL) {
                   2196:                                         
                   2197:                                         if (a[l1] >= '1' && a[l1] <= '9') {
                   2198:                                             l1 = 0;
                   2199:                                             break;
                   2200:                                         }
                   2201:                                         
                   2202:                                         l1++;
                   2203: 
                   2204:                                     }
                   2205: 
                   2206:                                     if (l1) {
                   2207: 
                   2208:                                         i--;
                   2209:                                         l1 = 0;
                   2210:                                         
                   2211:                                         while ((a[l1] = a[l1 + 1]) != EOL) l1++;
                   2212: 
                   2213:                                     }
                   2214:                                 }
                   2215: 
                   2216:                             }
                   2217:                             else { /* rounding not required */
                   2218: 
                   2219:                                 if (f + i + 1 > STRLEN) {
                   2220:                                     merr_raise (M75);
                   2221:                                     return;
                   2222:                                 }
                   2223: 
                   2224:                                 while (j < f + i) a[++j] = '0';
                   2225: 
                   2226:                                 a[++j] = EOL;
                   2227:                             
                   2228:                             }
                   2229:                             
                   2230:                             if (f == 0) a[i] = EOL;
                   2231: 
                   2232:                         }           /* end of 3 arg-form */
                   2233:                         
                   2234:                         if (f < l) {
                   2235: 
                   2236:                             i = stlen (a) + 1;
                   2237:                             
                   2238:                             if (++l <= i) goto nxt_operator;
                   2239: 
                   2240:                             while (i >= 0) a[l--] = a[i--];
                   2241:                             while (l >= 0) a[l--] = SP;
                   2242: 
                   2243:                         }
                   2244: 
                   2245:                     }
                   2246:                     
                   2247:                     goto nxt_operator;
                   2248:                 
                   2249: 
                   2250:                 /* case 'd': *//* $DATA */
                   2251:                 /* case 'g': *//* $GET */
                   2252:                 /* case 'i': *//* $INCREMENT */
                   2253:                 /* case 'n': *//* $NEXT */
                   2254:                 /* case ZNEXT: *//* $ZNEXT */
                   2255:                 /* case ZPREVIOUS: *//* $ZPREVIOUS */
                   2256:                 case 'o':           /* $ORDER */
                   2257: 
                   2258:                     if (f > 2) {
                   2259:                         merr_raise (FUNARG);
                   2260:                         return;
                   2261:                     }
                   2262:                     
                   2263:                     stcpy (varnam, argstck[arg]);
                   2264:                     ordercnt = intexpr (argstck[arg + 1]);
                   2265:                     ordercounter = 0;
                   2266:                     
                   2267:                     if (varnam[0] != '^') {
                   2268:                         symtab (fra_order, varnam, a);
                   2269:                     }
                   2270:                     else if (varnam[1] != '$') {
                   2271:                         global  (fra_order, varnam, a);
                   2272:                     }
                   2273:                     else {
                   2274:                         ssvn (fra_order, varnam, a);
                   2275:                     }
                   2276:                     
                   2277:                     goto nxt_operator;
                   2278: 
                   2279: 
                   2280:                 case 'q':           /* $QUERY */
                   2281:                     
                   2282:                     if (f > 2) {
                   2283:                         merr_raise (FUNARG);
                   2284:                         return;
                   2285:                     }
                   2286: 
                   2287:                     stcpy (varnam, argstck[arg]);
                   2288:                     ordercnt = intexpr (argstck[arg + 1]);
                   2289: 
                   2290:                     if (varnam[0] == '^' && varnam[1] == '$') {
                   2291:                         ssvn (fra_query, varnam, a);
                   2292:                     }
                   2293:                     else if (ordercnt == 1) {
                   2294:                         if (varnam[0] != '^') {
                   2295:                             symtab (fra_query, varnam, a);
                   2296:                         }
                   2297:                         else {
                   2298:                             global (fra_query, varnam, a);
                   2299:                         }
                   2300:                     }
                   2301:                     else {
                   2302:                         char qryarg_ext[256];
                   2303: 
                   2304:                         freem_ref_t *revq_ref = (freem_ref_t *) malloc (sizeof (freem_ref_t));
                   2305: 
                   2306:                         /* convert the $QUERY argument from internal to external format */
                   2307:                         mref_init (revq_ref, MREF_RT_GLOBAL, "scratch");
                   2308:                         internal_to_mref (revq_ref, varnam);
                   2309:                         mref_to_external (revq_ref, qryarg_ext);
                   2310: 
                   2311:                         stcnv_c2m (qryarg_ext);
                   2312: 
                   2313:                         /* put the $QUERY argument into the local variable %INT.REVQ */
1.7       snw      2314:                         symtab (set_sym, "%INTREVQ\201\201", qryarg_ext);
1.1       snw      2315: 
                   2316:                         /* set up for calling into polyfill wrapper */
                   2317:                         code[0] = '\201';
                   2318:                         stcpy (code, "$^%ZREVQRY\201");
                   2319: 
                   2320:                         codptr = code;
                   2321: 
                   2322:                         f = '$';
                   2323: 
                   2324:                         zexflag = TRUE;
                   2325: 
                   2326:                         /* run the polyfill wrapper */
                   2327:                         goto extra_fun;
                   2328:                     }
                   2329: 
                   2330:                     goto nxt_operator;
                   2331: 
                   2332: 
                   2333:                 case 'N':           /* $NAME */
                   2334: 
                   2335:                     if (f > 2) {
                   2336:                         merr_raise (FUNARG);
                   2337:                         return;
                   2338:                     }
                   2339: 
                   2340:                     f = intexpr (argstck[arg + 1]);
                   2341:                     
                   2342:                     if (f < 0) {
                   2343:                         merr_raise (ARGER);
                   2344:                         return;
                   2345:                     }
                   2346: 
                   2347:                     i = 0;
                   2348:                     
                   2349:                     while (a[++i] != EOL) {
                   2350:                         if (a[i] == DELIM && --f < 0) {
                   2351:                             break;
                   2352:                         }
                   2353:                     }
                   2354:                     
                   2355:                     a[i] = EOL;
                   2356: 
                   2357:                     stcpy (varnam, a);
                   2358:                     zname (a, varnam);
                   2359: 
                   2360:                     goto nxt_operator;
                   2361: 
                   2362: 
                   2363:                 case QLENGTH:           /* $QLENGTH */
                   2364: 
                   2365:                     if (f != 1) {
                   2366:                         merr_raise (FUNARG);
                   2367:                         return;
                   2368:                     }
                   2369: 
                   2370:                     f = 0;
                   2371:                     i = 0;
                   2372:                     
                   2373:                     {
                   2374:                         int ch, quote;
                   2375: 
                   2376:                         quote = 0;
                   2377:                         
                   2378:                         while ((ch = a[i++]) != EOL) {
                   2379: 
                   2380:                             if (ch == '"') quote = !quote;
                   2381:                             if (quote) continue;
                   2382:                             if (ch == '(' && f == 0) f = 1;
                   2383:                             if (ch == ',') f++;
                   2384:                         
                   2385:                         }
                   2386:                     
                   2387:                     }
                   2388:                     
                   2389:                     intstr (a, f);
                   2390:                     
                   2391:                     goto nxt_operator;
                   2392: 
                   2393: 
                   2394:                 case QSUBSCRIPT: /* $QSUBSCRIPT */
                   2395: 
                   2396:                     if (f != 2) {
                   2397:                         merr_raise (FUNARG);
                   2398:                         return;
                   2399:                     }
                   2400: 
                   2401:                     if ((f = intexpr (argstck[arg+1])) < -1) {
                   2402:                         merr_raise (ARGER);
                   2403:                         return;
                   2404:                     }
                   2405: 
                   2406:                     { 
                   2407:                         int ch, env, quote, count, startsub;
                   2408:                         
                   2409:                         if (f == -1) { /* get environment */
                   2410:                             
                   2411:                             quote = 0; 
                   2412:                             env = FALSE; 
                   2413:                             count = 0; 
                   2414:                             startsub = 0; 
                   2415:                             i = 0;
                   2416: 
                   2417:                             while ((ch = a[i++]) != EOL) {
                   2418: 
                   2419:                                 if (ch == '"') quote= !quote;
                   2420:                                 if (quote) continue;
                   2421: 
                   2422:                                 if (ch == '|') {
                   2423:                                     
                   2424:                                     if (env) {
                   2425:                                         a[i-1] = EOL;
                   2426:                                         stcpy (a, &a[startsub]);
                   2427:                                     
                   2428:                                         break;
                   2429:                                     
                   2430:                                     }
                   2431:                                     else {
                   2432:                                         startsub = i;
                   2433:                                         env = TRUE;
                   2434:                                     }
                   2435: 
                   2436:                                 }
                   2437: 
                   2438:                             }
                   2439: 
                   2440:                             if (!env) *a= EOL;
                   2441: 
                   2442:                         }
                   2443:                         else {
                   2444: 
                   2445:                             quote = 0; 
                   2446:                             env = FALSE; 
                   2447:                             count = 0; 
                   2448:                             startsub = 0; 
                   2449:                             i = 0;
                   2450: 
                   2451:                             while ((ch=a[i++])!=EOL) {
                   2452: 
                   2453:                                 if (ch == '"') quote = !quote;
                   2454:                                 if (quote) continue;
                   2455: 
                   2456:                                 if (ch == '|' && count == 0) {
                   2457:                                 
                   2458:                                     if (env) {
                   2459: 
                   2460:                                         if (*a == '^') a[--i] = '^';
                   2461:                                         
                   2462:                                         startsub = i;
                   2463: 
                   2464:                                     }
                   2465:                                     else {  
                   2466:                                         env = TRUE;
                   2467:                                     }
                   2468: 
                   2469:                                 }
                   2470:                                 
                   2471:                                 if (ch == '(' || ch == ',' || ch == ')') {
                   2472:                                     
                   2473:                                     if (count == f) { 
                   2474:                                         a[i-1] = EOL; 
                   2475:                                         break; 
                   2476:                                     }
                   2477:                                     
                   2478:                                     count++; 
                   2479:                                     startsub = i;
                   2480: 
                   2481:                                 }
                   2482: 
                   2483:                             }
                   2484:                             
                   2485:                             if (startsub) stcpy (a, &a[startsub]);
                   2486:                             
                   2487:                             if (count < f) *a = EOL;
                   2488: 
                   2489:                         }
                   2490:                         if (a[0] == '"') { /* un-quote */
                   2491: 
                   2492:                             quote = 1; 
                   2493:                             i = 1; 
                   2494:                             f = 0;
                   2495:                             
                   2496:                             while ((ch = a[i++]) != EOL) {
                   2497: 
                   2498:                                 if (ch == '"') quote = !quote;
                   2499:                                 
                   2500:                                 if (quote) a[f++] = ch;
                   2501: 
                   2502:                             }
                   2503: 
                   2504:                             a[f] = EOL;
                   2505: 
                   2506:                         }
                   2507: 
                   2508:                     }
                   2509: 
                   2510:                 /* goto nxt_operator; */
                   2511: 
                   2512: 
                   2513:                 case 's':           /* $SELECT */
                   2514:                 
                   2515:                     goto nxt_operator;
                   2516: 
                   2517:                     
                   2518:                 case SVNstack:          /* $STACK() */
                   2519: 
                   2520:                     if (f > 2) {
                   2521:                         merr_raise (FUNARG);
                   2522:                         return;
                   2523:                     }
                   2524: 
                   2525:                     if (f == 1) {
                   2526: 
                   2527:                         char iex_buf[256];
                   2528:                         int iexp;
                   2529:                         
                   2530:                         stcpy (iex_buf, argstck[arg]);
                   2531:                         iexp = atoi (iex_buf);
                   2532: 
                   2533:                         /*set_io (UNIX);
                   2534:                         printf ("iexp = %d\n", iexp);
                   2535:                         set_io (MUMPS);
                   2536:                         */
                   2537:                         
                   2538:                         if (iexp == -1) {                            
                   2539:                             intstr (a, merr_topstk);
                   2540:                         }
                   2541:                         else if (iexp == 0) {
                   2542:                             stcpy (a, stack0);
                   2543:                         }
                   2544:                         else if (iexp > 0 && iexp <= merr_topstk) {
                   2545: 
                   2546:                             if (merr_topstk > nstx) {
                   2547:                                 stcpy (a, merr_stack[merr_topstk].ECODE);
                   2548:                             }
                   2549:                             else {
                   2550:                                 if (nestc[iexp] == '$') {
                   2551:                                     stcpy (a, "$$\201");
                   2552:                                 }
                   2553:                                 else {
                   2554:                                     if ((mtok_token_to_command (a, nestc[iexp])) != 1) {
                   2555:                                         stcpy (a, "???");
                   2556:                                     }
                   2557:                                 }
                   2558:                             }
                   2559:                             
                   2560:                         }
                   2561:                         else {
                   2562:                             merr_raise (FUNARG);
                   2563:                             return;
                   2564:                         }
                   2565: 
                   2566:                     }                
                   2567: 
                   2568:                     if (f == 2) {
                   2569: 
                   2570:                         int stkidx;
                   2571:                         char sub[255];
                   2572:                         char indst[255];
                   2573:                         stcpy (indst, argstck[arg]);
                   2574:                         stcnv_m2c (indst);
                   2575: 
                   2576:                         stkidx = atoi (indst);
                   2577: 
                   2578:                         if (stkidx > NESTLEVLS || stkidx < 0) {
                   2579:                             merr_raise (FUNARG);
                   2580:                             return;
                   2581:                         }
                   2582: 
                   2583:                         stcpy (sub, argstck[2]);
                   2584:                         stcnv_m2c (sub);
                   2585: 
                   2586:                         if (strcmp (sub, "MCODE") == 0) {
                   2587:                             strcpy (a, merr_stack[stkidx].MCODE);
                   2588:                         }
                   2589:                         else if (strcmp (sub, "ECODE") == 0) {
                   2590:                             strcpy (a, merr_stack[stkidx].ECODE);
                   2591:                         }
                   2592:                         else if (strcmp (sub, "PLACE") == 0) {
                   2593:                             strcpy (a, merr_stack[stkidx].PLACE);
                   2594:                         }
                   2595:                         else {
                   2596:                             merr_raise (SYNTERR);
                   2597:                             return;
                   2598:                         }
                   2599: 
                   2600:                         stcnv_c2m (a);
                   2601: 
                   2602:                     }
                   2603: 
                   2604:         
                   2605:                     goto nxt_operator;
                   2606: 
                   2607: 
                   2608:                 case FNUMBER:           /* $FNUMBER */
                   2609: 
                   2610:                     if (f < 2 || f > 3) {
                   2611:                         merr_raise (FUNARG);
                   2612:                         return;
                   2613:                     } 
                   2614: 
                   2615:                     {
                   2616: 
                   2617:                         short l1;
                   2618:                         short Pflag;
                   2619:                         short Tflag;
                   2620:                         short commaflag;
                   2621:                         short plusflag;
                   2622:                         short minusflag;
                   2623:                         short EuroFlag;
                   2624:                         short IsZero;
                   2625:                         
                   2626:                         Pflag = FALSE,
                   2627:                         Tflag = FALSE,
                   2628:                         commaflag = FALSE,
                   2629:                         plusflag = FALSE,
                   2630:                         minusflag = FALSE,
                   2631:                         EuroFlag = FALSE,
                   2632:                         IsZero = FALSE;
                   2633: 
                   2634:                         b = argstck[arg + 1];
                   2635: 
                   2636:                         while ((i = *b++) != EOL) { /* evaluate options */
                   2637: 
                   2638:                             switch (i) {
                   2639:                         
                   2640: 
                   2641:                                 case 'P':
                   2642: 
                   2643:                                     Pflag = TRUE;
                   2644:                                     continue;
                   2645:                         
                   2646: 
                   2647:                                 case 'p':
                   2648: 
                   2649:                                     if (lowerflag) Pflag = TRUE;
                   2650:                                     continue;
                   2651:                         
                   2652: 
                   2653:                                 case 'T':
                   2654: 
                   2655:                                     Tflag = TRUE;
                   2656:                                     continue;
                   2657:                         
                   2658: 
                   2659:                                 case 't':
                   2660: 
                   2661:                                     if (lowerflag) Tflag = TRUE;
                   2662:                                     continue;
                   2663:                         
                   2664: 
                   2665:                                 case ',':
                   2666: 
                   2667:                                     commaflag = TRUE;
                   2668:                                     continue;
                   2669:                             
                   2670: 
                   2671:                                 case '.':
                   2672: 
                   2673:                                     EuroFlag = TRUE;
                   2674:                                     continue;
                   2675:                         
                   2676: 
                   2677:                                 case '+':
                   2678: 
                   2679:                                     plusflag = TRUE;
                   2680:                                     continue;
                   2681:                         
                   2682: 
                   2683:                                 case '-':
                   2684: 
                   2685:                                     minusflag = TRUE;
                   2686: 
                   2687: 
                   2688:                             }
                   2689:                         }
                   2690: 
                   2691:                         if (Pflag && (Tflag || plusflag || minusflag)) {
                   2692:                             merr_raise (ARGER);
                   2693:                             return;
                   2694:                         }
                   2695: 
                   2696:                         if (f == 3) j = intexpr (argstck[arg + 2]); /* 3rd arg */
                   2697:                         
                   2698:                         if (merr () == MXNUM) {
                   2699:                         
                   2700:                             if (j >= 0) j = 256;
                   2701:                         
                   2702:                             merr_raise (OK);
                   2703:                         
                   2704:                         }
                   2705: 
                   2706:                         numlit (a);
                   2707:                         IsZero = (a[0] == '0');
                   2708: 
                   2709:                         if (f == 3) {
                   2710: 
                   2711:                             f = j;
                   2712:                             
                   2713:                             if (f < 0) {
                   2714:                                 merr_raise (ARGER);
                   2715:                                 return;
                   2716:                             }
                   2717: 
                   2718:                             if (f > STRLEN) {
                   2719:                                 merr_raise (M75);
                   2720:                                 return;
                   2721:                             }
                   2722: 
                   2723:                             /* s j=$l(a),i=$f(a,".")-1 */
                   2724:                             j = (a[0] == '-');
                   2725:                             
                   2726:                             if (a[j] == '.') {  /* insert leading zero */
                   2727: 
                   2728:                                 i = j;
                   2729:                             
                   2730:                                 while (a[i++] != EOL);
                   2731: 
                   2732:                                 while (i > j) {
                   2733:                                     a[i] = a[i - 1];
                   2734:                                     i--;
                   2735:                                 }
                   2736: 
                   2737:                                 a[j] = '0';
                   2738: 
                   2739:                             }
                   2740: 
                   2741:                             i = (-1);
                   2742:                             j = 0;
                   2743: 
                   2744:                             while (a[j] != EOL) {
                   2745: 
                   2746:                                 if (a[j] == '.') i = j;
                   2747:                                 
                   2748:                                 j++;
                   2749:                             
                   2750:                             }
                   2751: 
                   2752:                             if (i < 0) {
                   2753:                                 a[i = j] = '.';
                   2754:                                 a[j + 1] = EOL;
                   2755:                             } 
                   2756:                             else {
                   2757:                                 j--;
                   2758:                             }
                   2759: 
                   2760:                             if (j - i > f) {    /* rounding required */
                   2761: 
                   2762:                                 l1 = f + i + 1;
                   2763: 
                   2764:                                 if (a[l1] > '4') {
                   2765: 
                   2766:                                     do {
                   2767: 
                   2768:                                         if (a[--l1] == '.') l1--;
                   2769: 
                   2770:                                         if (l1 < 0) {
                   2771: 
                   2772:                                             for (l1 = f + i + 1; l1 > 0; l1--) {
                   2773:                                                 a[l1] = a[l1 - 1];
                   2774:                                             }
                   2775:                                             
                   2776:                                             a[0] = '1';
                   2777:                                             i++;
                   2778:                                             
                   2779:                                             break;
                   2780: 
                   2781:                                         }
                   2782: 
                   2783:                                         a[l1]++;
                   2784: 
                   2785:                                         if (a[l1] == ':') a[l1] = '0';
                   2786: 
                   2787:                                     } while (a[l1] == '0');
                   2788: 
                   2789:                                 }
                   2790: 
                   2791:                                 a[f + i + 1] = EOL;
                   2792:                                 
                   2793:                                 if (a[0] == '-' && a[1] == '0') {
                   2794: 
                   2795:                                     l1 = 2;
                   2796:                                     
                   2797:                                     while (a[l1] != EOL) {
                   2798: 
                   2799:                                         if (a[l1] >= '1' && a[l1] <= '9') {
                   2800:                                             l1 = 0;
                   2801:                                             break;
                   2802:                                         }
                   2803: 
                   2804:                                         l1++;
                   2805: 
                   2806:                                     }
                   2807: 
                   2808:                                     if (l1) {
                   2809: 
                   2810:                                         i--;
                   2811:                                         l1 = 0;
                   2812:                                         
                   2813:                                         while ((a[l1] = a[l1 + 1]) != EOL) l1++;
                   2814: 
                   2815:                                     }
                   2816: 
                   2817:                                 }
                   2818: 
                   2819:                             } 
                   2820:                             else {
                   2821:                             
                   2822:                                 if (f + i > STRLEN) {
                   2823:                                     merr_raise (M75);
                   2824:                                     return;
                   2825:                                 }
                   2826: 
                   2827:                                 while (j < f + i) a[++j] = '0';
                   2828: 
                   2829:                                 a[++j] = EOL;
                   2830:                             }
                   2831:                                 
                   2832:                             if (f == 0) a[i] = EOL;
                   2833: 
                   2834:                         }           /* end of 3 arg-form */
                   2835:                         
                   2836:                         if (commaflag) {
                   2837: 
                   2838:                             i = 0;
                   2839:                             
                   2840:                             while ((f = a[i]) != '.' && f != EOL) i++;
                   2841:                             
                   2842:                             if (a[0] == '-') {
                   2843: 
                   2844:                                 f = (i + 1) % 3;
                   2845:                                 j = 1;
                   2846:                                 i = 1;
                   2847:                                 tmp[0] = '-';
                   2848: 
                   2849:                             } 
                   2850:                             else {
                   2851: 
                   2852:                                 f = (i + 2) % 3;
                   2853:                                 j = 0;
                   2854:                                 i = 0;
                   2855: 
                   2856:                             }
                   2857: 
                   2858:                             while ((tmp[j++] = a[i]) != EOL) {
                   2859: 
                   2860:                                 if (j >= STRLEN) {
                   2861:                                     merr_raise (M75);
                   2862:                                     return;
                   2863:                                 }
                   2864:                                 
                   2865:                                 if (a[i++] == '.') f = -1; /* do not insert comma after point */
                   2866: 
                   2867:                                 if (f-- == 0 && a[i] != EOL && a[i] != '.') {
                   2868:                                     f = 2;
                   2869:                                     tmp[j++] = ',';
                   2870:                                 }
                   2871: 
                   2872:                             }
                   2873: 
                   2874:                             stcpy (a, tmp);
                   2875: 
                   2876:                         }
                   2877: 
                   2878:                         if (EuroFlag && !standard) {    /* exchange point and comma */
                   2879:                             
                   2880:                             i = 0;
                   2881:                             
                   2882:                             while ((f = a[i]) != EOL) {
                   2883: 
                   2884:                                 if (f == '.') a[i] = ',';
                   2885:                                 if (f == ',') a[i] = '.';
                   2886: 
                   2887:                                 i++;
                   2888: 
                   2889:                             }
                   2890: 
                   2891:                         }
                   2892: 
                   2893:                         if (Tflag) {
                   2894: 
                   2895:                             i = stcpy (tmp, a);
                   2896:                             
                   2897:                             if (plusflag && tmp[0] != '-' && !IsZero) {
                   2898:                             
                   2899:                                 tmp[i] = '+';
                   2900:                                 tmp[++i] = EOL;
                   2901:                                 stcpy (a, tmp);
                   2902:                             
                   2903:                             } 
                   2904:                             else if (tmp[0] == '-') {
                   2905:                             
                   2906:                                 tmp[i] = minusflag ? SP : '-';
                   2907:                                 tmp[++i] = EOL;
                   2908:                                 stcpy (a, &tmp[1]);
                   2909:                             
                   2910:                             } 
                   2911:                             else {
                   2912:                             
                   2913:                                 tmp[i] = SP;
                   2914:                                 tmp[++i] = EOL;
                   2915:                                 stcpy (a, tmp);
                   2916:                             
                   2917:                             }
                   2918: 
                   2919:                             goto nxt_operator;
                   2920: 
                   2921:                         }
                   2922: 
                   2923:                         if (Pflag) {
                   2924: 
                   2925:                             i = stcpy (&tmp[1], a);
                   2926:                             
                   2927:                             if (a[0] == '-') {
                   2928:                             
                   2929:                                 a[0] = '(';
                   2930:                                 a[i] = ')';
                   2931:                                 a[++i] = EOL;
                   2932:                             
                   2933:                             } 
                   2934:                             else {
                   2935:                             
                   2936:                                 tmp[0] = SP;
                   2937:                                 tmp[++i] = SP;
                   2938:                                 tmp[++i] = EOL;
                   2939: 
                   2940:                                 stcpy (a, tmp);
                   2941:                             }
                   2942: 
                   2943:                             goto nxt_operator;
                   2944: 
                   2945:                         }
                   2946: 
                   2947:                         if (plusflag && a[0] != '-' && !IsZero) {
                   2948:                             stcpy (tmp, a);
                   2949:                             a[0] = '+';
                   2950:                             stcpy (&a[1], tmp);
                   2951:                         }
                   2952: 
                   2953:                         if (minusflag && a[0] == '-') {
                   2954:                             stcpy (tmp, &a[1]);
                   2955:                             stcpy (a, tmp);
                   2956:                         }
                   2957: 
                   2958:                     }
                   2959: 
                   2960:                     goto nxt_operator;
                   2961: 
                   2962: 
                   2963:                 case REVERSE:           /* $REVERSE */
                   2964: 
                   2965:                     if (f != 1) {
                   2966:                         merr_raise (FUNARG);
                   2967:                         return;
                   2968:                     }
                   2969: 
                   2970:                     i = stlen (a) - 1;
                   2971:                     j = i / 2;
                   2972:                     i = i - j;
                   2973:                     
                   2974:                     while (j >= 0) {
                   2975:                         f = a[j];
                   2976:                         a[j--] = a[i];
                   2977:                         a[i++] = f;
                   2978:                     }
                   2979: 
                   2980:                     goto nxt_operator;
                   2981: 
                   2982: 
                   2983:                 case 't':           /* $TEXT */
                   2984: 
                   2985:                     {
                   2986:                         long l1, rouoldc;
                   2987:                         short reload = FALSE;
                   2988: 
                   2989:                         if (f > 3) {
                   2990:                             merr_raise (FUNARG);
                   2991:                             return;
                   2992:                         }
                   2993: 
                   2994:                         i = 0;
                   2995:                         
                   2996:                         if (f > 1) {
                   2997:                             stcpy (tmp, argstck[arg + 1]);
                   2998:                             i = intexpr (tmp);
                   2999:                         }
                   3000: 
                   3001:                         if (a[0] == EOL) {
                   3002: 
                   3003:                             if (i < 0) {
                   3004:                                 merr_raise (ARGER);
                   3005:                                 return;
                   3006:                             }
                   3007: 
                   3008:                             /* $T(+0) returns routine name */
                   3009:                             if (i == 0) {
                   3010: 
                   3011:                                 if (f != 3) {
                   3012:                                     stcpy (a, rou_name);
                   3013:                                 } 
                   3014:                                 else {
                   3015:                                     stcpy (a, argstck[arg + 2]);
                   3016:                                 }                                
                   3017: 
                   3018:                                 goto nxt_operator;
                   3019: 
                   3020:                             }
                   3021: 
                   3022:                         }
                   3023: 
                   3024:                         if (f == 3) {
                   3025: 
                   3026:                             reload = TRUE;  /* load routine; */
                   3027:                             f = mcmnd;
                   3028:                             mcmnd = 'd';    /* make load use standard-path */
                   3029:                             
                   3030:                             stcpy (tmp, argstck[arg + 2]);
                   3031:                             
                   3032:                             rouoldc = roucur - rouptr;
                   3033:                             
                   3034:                             zload (tmp);
                   3035:                             
                   3036:                             mcmnd = f;
                   3037:                             
                   3038:                             if (merr () > OK) {
                   3039: 
                   3040:                                 zload (rou_name);
                   3041:                                 
                   3042:                                 if (merr () == NOPGM) {
                   3043:                                     ierr -= NOPGM; /* smw 15 nov 2023 TODO HUH?? */
                   3044:                                     *a = EOL;
                   3045: 
                   3046:                                     goto nxt_operator;
                   3047:                                 }
                   3048: 
                   3049:                                 return;
                   3050: 
                   3051:                             }
                   3052: 
                   3053:                         }
                   3054: 
                   3055:                         j = 0;
                   3056:                         f = 1;
                   3057:                         
                   3058:                         if (a[0] != EOL) {  /* 1st arg == label */
                   3059: 
                   3060:                             for (;;) {
                   3061:                         
                   3062:                                 if (j >= (rouend - rouptr)) {
                   3063:                                     a[0] = EOL;
                   3064:                                     goto t_end;
                   3065:                                 }
                   3066: 
                   3067:                                 l1 = j;
                   3068:                                 f = 0;
                   3069:                                 
                   3070:                                 while (*(rouptr + (++l1)) == a[f++]);
                   3071:                                 
                   3072:                                 if (a[--f] == EOL && (*(rouptr + l1) == TAB || *(rouptr + l1) == SP || *(rouptr + l1) == '(')) break;
                   3073: 
                   3074:                                 j += (UNSIGN (*(rouptr + j)) + 2);  /* skip line */
                   3075: 
                   3076:                             }
                   3077: 
                   3078:                             f = 0;
                   3079: 
                   3080:                         }
                   3081: 
                   3082:                         if (i > 0) {
                   3083: 
                   3084:                             while (f < i) {
                   3085: 
                   3086:                                 if ((j = j + (UNSIGN (*(rouptr + j))) + 2) >= (rouend - rouptr)) {
                   3087:                                     a[0] = EOL;
                   3088:                                     goto t_end;
                   3089:                                 }
                   3090:                                 
                   3091:                                 f++;
                   3092: 
                   3093:                             }
                   3094: 
                   3095:                         }
                   3096: 
                   3097:                         if (i < 0) {
                   3098: 
                   3099:                             j--;
                   3100:                             
                   3101:                             while (f != i) {
                   3102: 
                   3103:                                 while (*(rouptr + (--j)) != EOL && j >= 0);
                   3104:                                 
                   3105:                                 if (--f != i && j < 1) {
                   3106:                                     a[0] = EOL;
                   3107:                                     goto t_end;
                   3108:                                 }
                   3109: 
                   3110:                             }
                   3111: 
                   3112:                             j++;
                   3113: 
                   3114:                         }
                   3115: 
                   3116:                         f = (-1);
                   3117:                         j++;
                   3118: 
                   3119:                         while ((a[++f] = (*(rouptr + (j++)))) != EOL) {
                   3120:                             if (a[f] == TAB || a[f] == SP)
                   3121:                             break;
                   3122:                         }
                   3123: 
                   3124:                         if (j >= (rouend - rouptr - 1)) {
                   3125:                             a[0] = EOL;
                   3126:                         } 
                   3127:                         else {
                   3128: 
                   3129:                             a[f] = SP;
                   3130:                             
                   3131:                             while ((*(rouptr + j)) == TAB || (*(rouptr + j)) == SP) {
                   3132:                                 j++;
                   3133:                                 a[++f] = SP;
                   3134:                             }
                   3135: 
                   3136:                             stcpy (&a[++f], rouptr + j);
                   3137: 
                   3138:                         }
                   3139: 
                   3140: t_end:
                   3141:                         if (reload) {
                   3142:                             zload (rou_name);
                   3143:                             roucur = rouptr + rouoldc;
                   3144:                         }           /* reload routine; */
                   3145: 
                   3146:                     }
                   3147:                     
                   3148:                     goto nxt_operator;
                   3149: 
                   3150: 
                   3151:                 case TRANSLATE:     /* $TRANSLATE */
                   3152: 
                   3153:                     if (f > 3 || f < 2) {
                   3154:                         merr_raise (FUNARG);
                   3155:                         return;
                   3156:                     } 
                   3157: 
                   3158:                     {
                   3159:                         short   l1, m;
                   3160:                         char   *c;
                   3161: 
                   3162:                         b = argstck[arg + 1];
                   3163:                         c = argstck[arg + 2];
                   3164: 
                   3165:                         if (f == 2) {
                   3166:                             l1 = 0;
                   3167:                         }
                   3168:                         else {
                   3169:                             l1 = stlen (c); /* $l of 3rd arg */
                   3170:                         }
                   3171: 
                   3172:                         m = 0;
                   3173:                         f = 0;
                   3174:                         
                   3175:                         while ((ch = a[f++]) != EOL) {
                   3176: 
                   3177:                             j = 0;
                   3178:                             
                   3179:                             while (b[j] != EOL) {
                   3180: 
                   3181:                                 if (ch == b[j]) {
                   3182: 
                   3183:                                     if (j < l1) {
                   3184:                                         ch = c[j];
                   3185:                                     }
                   3186:                                     else {
                   3187:                                         ch = EOL;
                   3188:                                     }
                   3189: 
                   3190:                                     break;
                   3191: 
                   3192:                                 }
                   3193: 
                   3194:                                 j++;
                   3195: 
                   3196:                             }
                   3197: 
                   3198:                             if (ch != EOL) a[m++] = ch;
                   3199: 
                   3200:                         }
                   3201: 
                   3202:                         a[m] = EOL;
                   3203: 
                   3204:                     }
                   3205: 
                   3206:                     goto nxt_operator;
                   3207: 
                   3208:                 case TYPE:
                   3209:                 {
                   3210:                     char piv[255];
                   3211:                     
                   3212:                     if (f != 1) {
                   3213:                         merr_raise (FUNARG);
                   3214:                         return;
                   3215:                     }
                   3216: 
                   3217:                     stcpy (piv, argstck[arg]);
                   3218:                     stcnv_m2c (piv);
                   3219: 
                   3220:                     obj_get_attribute (piv, "CLASS", a);
                   3221:                     stcnv_c2m (a);
                   3222:                     
                   3223:                     goto nxt_operator;
                   3224:                 }
                   3225: 
                   3226:                 case INSTANCEOF:
                   3227:                 {
                   3228:                     char io_inst[255];
                   3229:                     char io_cls[255];
                   3230:                     short io_res;
                   3231:                     
                   3232:                     if (f != 2) {
                   3233:                         merr_raise (FUNARG);
                   3234:                         return;
                   3235:                     }
                   3236: 
                   3237:                     stcpy (io_inst, argstck[arg]);
                   3238:                     stcpy (io_cls, argstck[arg + 1]);
                   3239: 
                   3240:                     stcnv_m2c (io_inst);
                   3241:                     stcnv_m2c (io_cls);
                   3242: 
                   3243:                     io_res = obj_instance_of (io_inst, io_cls);
                   3244:                     
                   3245:                     intstr (a, (int) io_res);
                   3246:                     
                   3247:                     goto nxt_operator;
                   3248:                 }
                   3249:                 case 'r':           /* $RANDOM */
                   3250: 
                   3251:                     if (f != 1) {
                   3252:                         merr_raise (FUNARG);
                   3253:                         return;
                   3254:                     } 
                   3255: 
                   3256:                     {
                   3257:                         long ilong;
                   3258: 
                   3259:                         nrandom = (ran_a * nrandom + ran_b) % ran_c;
                   3260: 
                   3261:                         if ((i = intexpr (a)) < 1) {
                   3262:                             merr_raise (ARGER);
                   3263:                             return;
                   3264:                         }
                   3265: 
                   3266:                         ilong = (nrandom * i) / ran_c;
                   3267:                         
                   3268:                         if (ilong < 0) ilong += i;
                   3269: 
                   3270:                         lintstr (a, ilong);
                   3271: 
                   3272:                     }
                   3273: 
                   3274:                     goto nxt_operator;
                   3275: 
                   3276: 
                   3277:                 /* $VIEW */
                   3278:                 case 'v':
                   3279: 
                   3280:                     view_fun (f, a);
                   3281: 
                   3282:                     if (merr () > 0) return;
                   3283:                     
                   3284:                     goto nxt_operator;
                   3285: 
                   3286: 
                   3287:                 /* $ZBOOLEAN */
                   3288:                 case 'B':
                   3289: 
                   3290:                     if (f != 3) {
                   3291:                         merr_raise (FUNARG);
                   3292:                         return;
                   3293:                     }
                   3294: 
                   3295:                     i = 0;
                   3296:                     ch = intexpr (argstck[arg + 2]) % 16;
                   3297:                     b = argstck[arg + 1];
                   3298:                     
                   3299:                     if (*b == EOL) {
                   3300:                         *b = 0;
                   3301:                         b[1] = 0;
                   3302:                     }
                   3303: 
                   3304:                     f = 0;
                   3305:                     
                   3306:                     switch (ch) {
                   3307: 
                   3308:                         
                   3309:                         /* 1: A AND B */
                   3310:                         case 1:
                   3311:                         
                   3312:                             while (a[i] != EOL) {
                   3313: 
                   3314:                                 a[i] &= b[f];
                   3315:                                 i++;
                   3316: 
                   3317:                                 if (b[++f] == EOL) f = 0;
                   3318: 
                   3319:                             }
                   3320: 
                   3321:                             break;
                   3322: 
                   3323: 
                   3324:                         /* 7: A OR B */                    
                   3325:                         case 7:
                   3326:                         
                   3327:                             while (a[i] != EOL) {
                   3328: 
                   3329:                                 a[i] |= b[f];
                   3330:                                 i++;
                   3331:                                 
                   3332:                                 if (b[++f] == EOL) f = 0;
                   3333: 
                   3334:                             }
                   3335: 
                   3336:                             break;
                   3337:                         
                   3338: 
                   3339:                         /* 6: A XOR B */
                   3340:                         case 6:
                   3341:                         
                   3342:                             while (a[i] != EOL) {
                   3343:                                 
                   3344:                                 a[i] = (a[i] ^ b[f]) & (eightbit ? 0377 : 0177);
                   3345:                                 i++;
                   3346: 
                   3347:                                 if (b[++f] == EOL) f = 0;
                   3348: 
                   3349:                             }
                   3350: 
                   3351:                             break;
                   3352:                         
                   3353: 
                   3354:                         /* 14: A NAND B */
                   3355:                         case 14:
                   3356:                         
                   3357:                             while (a[i] != EOL) {
                   3358:                                 
                   3359:                                 a[i] = ~(a[i] & b[f]) & (eightbit ? 0377 : 0177);
                   3360:                                 i++;
                   3361: 
                   3362:                                 if (b[++f] == EOL) f = 0;
                   3363: 
                   3364:                             }
                   3365: 
                   3366:                             break;
                   3367:                         
                   3368: 
                   3369:                         /* 8: A NOR B */
                   3370:                         case 8:
                   3371:                         
                   3372:                             while (a[i] != EOL) {
                   3373: 
                   3374:                                 a[i] = ~(a[i] | b[f]) & (eightbit ? 0377 : 0177);
                   3375:                                 i++;
                   3376: 
                   3377:                                 if (b[++f] == EOL) f = 0;
                   3378: 
                   3379:                             }
                   3380: 
                   3381:                             break;
                   3382:                         
                   3383: 
                   3384:                         /* 9: A EQUALS B */
                   3385:                         case 9:
                   3386:                         
                   3387:                             while (a[i] != EOL) {
                   3388: 
                   3389:                                 a[i] = ~(a[i] ^ b[f]) & (eightbit ? 0377 : 0177);
                   3390:                                 i++;
                   3391: 
                   3392:                                 if (b[++f] == EOL) f = 0;
                   3393: 
                   3394:                             }
                   3395: 
                   3396:                             break;
                   3397:                         
                   3398: 
                   3399:                         /* 2: A AND NOT B */
                   3400:                         case 2:
                   3401:                         
                   3402:                             while (a[i] != EOL) {
                   3403: 
                   3404:                                 a[i] &= ~b[f];
                   3405:                                 i++;
                   3406:                                 
                   3407:                                 if (b[++f] == EOL) f = 0;
                   3408: 
                   3409:                             }
                   3410: 
                   3411:                             break;
                   3412:                         
                   3413: 
                   3414:                         /* 11: A OR NOT B */
                   3415:                         case 11:
                   3416:                         
                   3417:                             while (a[i] != EOL) {
                   3418:                                 
                   3419:                                 a[i] = (a[i] | ~b[f]) & (eightbit ? 0377 : 0177);
                   3420:                                 i++;
                   3421: 
                   3422:                                 if (b[++f] == EOL) f = 0;
                   3423:                             
                   3424:                             }
                   3425:                             
                   3426:                             break;
                   3427:                         
                   3428: 
                   3429:                         /* 13: NOT A OR B */
                   3430:                         case 13:
                   3431:                         
                   3432:                             while (a[i] != EOL) {
                   3433: 
                   3434:                                 a[i] = (~a[i] | b[f]) & (eightbit ? 0377 : 0177);
                   3435:                                 i++;
                   3436:                                 
                   3437:                                 if (b[++f] == EOL) f = 0;
                   3438:                             
                   3439:                             }
                   3440:                             
                   3441:                             break;
                   3442:                         
                   3443: 
                   3444:                         /* 4: NOT A AND B */
                   3445:                         case 4:
                   3446:                         
                   3447:                             while (a[i] != EOL) {
                   3448: 
                   3449:                                 a[i] = ~a[i] & b[f];
                   3450:                                 i++;
                   3451:                                 
                   3452:                                 if (b[++f] == EOL) f = 0;
                   3453: 
                   3454:                             }
                   3455: 
                   3456:                             break;
                   3457:                         
                   3458: 
                   3459:                         /* 5: B */
                   3460:                         case 5:
                   3461:                         
                   3462:                             while (a[i] != EOL) {
                   3463: 
                   3464:                                 a[i++] = b[f];
                   3465:                                 
                   3466:                                 if (b[++f] == EOL) f = 0;
                   3467:                             
                   3468:                             }
                   3469:                             
                   3470:                             break;
                   3471:                         
                   3472: 
                   3473:                         /* 10: NOT B */
                   3474:                         case 10:
                   3475:                         
                   3476:                             while (a[i] != EOL) {
                   3477:                                 
                   3478:                                 a[i++] = ~b[f] & 0177;
                   3479:                                 
                   3480:                                 if (b[++f] == EOL) f = 0;
                   3481:                             
                   3482:                             }
                   3483:                             
                   3484:                             break;
                   3485:                         
                   3486: 
                   3487:                         /* 12: NOT A */
                   3488:                         case 12:
                   3489:                         
                   3490:                             while (a[i] != EOL) {
                   3491: 
                   3492:                                 a[i] = ~a[i] & 0177;
                   3493:                                 i++;
                   3494: 
                   3495:                                 if (b[++f] == EOL) f = 0;
                   3496: 
                   3497:                             }
                   3498: 
                   3499:                             break;
                   3500: 
                   3501: 
                   3502:                         /* 0: always FALSE */
                   3503:                         case 0:
                   3504:                         
                   3505:                             while (a[i] != EOL)
                   3506:                             a[i++] = 0;
                   3507:                             break;
                   3508: 
                   3509: 
                   3510:                         /* 15: always TRUE */
                   3511:                         case 15:
                   3512:                         
                   3513:                             ch = (char) 0177;
                   3514:                             while (a[i] != EOL)
                   3515:                             a[i++] = ch;
                   3516:                             /* 3: A */
                   3517: 
                   3518:                     }
                   3519: 
                   3520:                     goto nxt_operator;
                   3521: 
                   3522: 
                   3523:                 /* ZCRC "cyclic redundancy check" check sums */
                   3524:                 case ZCRC:
                   3525: 
                   3526:                     if (f == 1) {
                   3527:                         f = 0;          /* missing 2nd arg defaults to "0" */
                   3528:                     }
                   3529:                     else {
                   3530: 
                   3531:                         if (f != 2) {
                   3532:                             merr_raise (FUNARG);
                   3533:                             return;
                   3534:                         }
                   3535:                         
                   3536:                         if ((f = intexpr (argstck[arg + 1])) != 0 && f != 1) {
                   3537:                             merr_raise (ARGER);
                   3538:                             return;
                   3539:                         }
                   3540: 
                   3541:                     }
                   3542: 
                   3543:                     i = 0;
                   3544:                     
                   3545:                     if (f == 0) {       /* XORing */
                   3546: 
                   3547:                         f = 0;
                   3548:                     
                   3549:                         while (a[i] != EOL) f ^= a[i++];
                   3550: 
                   3551:                         f = f & 0377;
                   3552: 
                   3553:                     } 
                   3554:                     else {            /* ASCII sum */
                   3555: 
                   3556:                         f = 0;
                   3557:                     
                   3558:                         while (a[i] != EOL) f += a[i++];
                   3559: 
                   3560:                     }
                   3561: 
                   3562:                     intstr (a, f);
                   3563:                     
                   3564:                     goto nxt_operator;
                   3565: 
                   3566: 
                   3567:                 /* $ZFUNCTIONKEY */
                   3568:                 case 'F':
                   3569: 
                   3570:                     if (f != 1) {
                   3571:                         merr_raise (FUNARG);
                   3572:                         return;
                   3573:                     }
                   3574:                     
                   3575:                     if ((i = intexpr (a)) < 1 || i > 44) {
                   3576:                         merr_raise (FUNARG);
                   3577:                         return;
                   3578:                     }
                   3579:                     
                   3580:                     stcpy (a, zfunkey[i - 1]);
                   3581:                     
                   3582:                     goto nxt_operator;
                   3583: 
                   3584: 
                   3585:                 case 'P':           /* $ZPIECE */
                   3586: 
                   3587:                     /* Similar to $PIECE                                    */
                   3588:                     /* The difference is, that stuff within quotes is not   */
                   3589:                     /* counted as delimiter. nor is stuff within brackets   */
                   3590: 
                   3591:                     {
                   3592:                         short l, l1, m, n;
                   3593:                         short quo = 0;    /* quotes */
                   3594:                         short bra = 0;    /* brackets */
                   3595:                         char ch0;
                   3596: 
                   3597:                         b = argstck[arg + 1];
                   3598:                         l1 = b - a - 1;     /* length of 1st argument */
                   3599: 
                   3600:                         switch (f) {
                   3601:                             
                   3602: 
                   3603:                             case 2:
                   3604: 
                   3605:                                 f = 1;
                   3606:                                 l = 1;
                   3607:                             
                   3608:                                 break;
                   3609:                             
                   3610: 
                   3611:                             case 3:
                   3612:                                 
                   3613:                                 if ((f = intexpr (argstck[arg + 2])) <= 0) {
                   3614:                                     a[0] = EOL;
                   3615:                                     goto nxt_operator;
                   3616:                                 }
                   3617: 
                   3618:                                 if (merr () == MXNUM) {
                   3619:                                     if (f >= 0) f = 256;
                   3620:                                     merr_raise (OK);
                   3621:                                 }
                   3622:                                 
                   3623:                                 l = f;
                   3624:                                 break;
                   3625:                             
                   3626: 
                   3627:                             case 4:
                   3628:                                 
                   3629:                                 l = intexpr (argstck[arg + 3]);
                   3630:                                 
                   3631:                                 if (merr () == MXNUM) {
                   3632:                                     
                   3633:                                     if (l >= 0) l = 256;
                   3634:                                 
                   3635:                                     merr_raise (OK);
                   3636:                                 
                   3637:                                 }
                   3638: 
                   3639:                                 if ((f = intexpr (argstck[arg + 2])) <= 0) f = 1;
                   3640: 
                   3641:                                 if (merr () == MXNUM) {
                   3642:                                     
                   3643:                                     if (f >= 0) f = 256;
                   3644:                                     
                   3645:                                     merr_raise (OK);
                   3646:                                 
                   3647:                                 }
                   3648:                                 
                   3649:                                 if (f > l) {
                   3650:                                     a[0] = EOL;
                   3651:                                     goto nxt_operator;
                   3652:                                 }
                   3653: 
                   3654:                                 break;
                   3655: 
                   3656: 
                   3657:                             default:
                   3658:                             
                   3659:                                 merr_raise (FUNARG);
                   3660:                                 return;
                   3661: 
                   3662:                         }
                   3663: 
                   3664:                         i = 0;
                   3665:                         m = 0;
                   3666:                         ch = 0;
                   3667: 
                   3668:                         while (b[ch] != EOL) ch++;       /* $l of 2nd arg */
                   3669: 
                   3670:                         if (ch == 1) {
                   3671: 
                   3672:                             ch = b[0];
                   3673:                             j = 1;
                   3674:                             
                   3675:                             if (f > 1) {
                   3676: 
                   3677:                                 while (i < l1) {    /* scan 1st string ... */
                   3678:                                     
                   3679:                                     ch0 = a[i++];
                   3680:                                     
                   3681:                                     if (ch != '"') {
                   3682: 
                   3683:                                         if (ch0 == '"') {
                   3684:                                             toggle (quo);
                   3685:                                             continue;
                   3686:                                         }
                   3687: 
                   3688:                                         if (quo) continue;
                   3689: 
                   3690:                                     }
                   3691: 
                   3692:                                     if (ch0 == '(') bra++;
                   3693:                                     if (ch0 == ')') bra--;
                   3694: 
                   3695:                                     if (ch0 != ch) continue;
                   3696:                                     if (bra > 1) continue;
                   3697:                                     if ((ch0 != '(') && bra) continue;
                   3698:                                     
                   3699:                                     if (++j == f) {
                   3700:                                         m = i;
                   3701:                                         goto zp10;
                   3702:                                     }
                   3703: 
                   3704:                                 }
                   3705: 
                   3706:                                 /* if(j<f) */ 
                   3707:                                 a[0] = EOL;
                   3708: 
                   3709:                                 goto nxt_operator;
                   3710: 
                   3711:                             }
                   3712: 
                   3713: zp10:
                   3714: 
                   3715:                             for (; i < l1; i++) {
                   3716: 
                   3717:                                 ch0 = a[i];
                   3718:                                 
                   3719:                                 if (ch != '"') {
                   3720: 
                   3721:                                     if (ch0 == '"') {
                   3722:                                         toggle (quo);
                   3723:                                         continue;
                   3724:                                     }
                   3725:                                     
                   3726:                                     if (quo) continue;
                   3727: 
                   3728:                                 }
                   3729: 
                   3730:                                 if (ch0 == '(') bra++;
                   3731:                                 if (ch0 == ')') bra--;
                   3732:                                 if (ch0 != ch) continue;
                   3733:                                 if (bra > 1) continue;
                   3734:                                 if ((ch0 != '(') && bra) continue;
                   3735: 
                   3736:                                 if (j == l) {
                   3737:                                     a[i] = EOL;
                   3738:                                     break;
                   3739:                                 }
                   3740: 
                   3741:                                 j++;
                   3742: 
                   3743:                             }
                   3744: 
                   3745:                             if (m > 0) stcpy (a, &a[m]);
                   3746: 
                   3747:                             goto nxt_operator;
                   3748: 
                   3749:                         }
                   3750: 
                   3751:                         if (ch == 0) {
                   3752:                             a[0] = EOL;
                   3753:                             goto nxt_operator;
                   3754:                         }           /* 2nd arg is empty */
                   3755: 
                   3756:                         /* else (ch>1) $Length of Delimiter>1 */
                   3757:                         n = 1;
                   3758: 
                   3759:                         if (f > 1) {
                   3760: 
                   3761:                             while (i < l1) {    /* scan 1st string ... */
                   3762: 
                   3763:                                 j = 0;
                   3764:                             
                   3765:                                 if ((ch0 = a[i]) == '"') {
                   3766:                                     toggle (quo);
                   3767:                                     i++;
                   3768:                             
                   3769:                                     continue;
                   3770:                                 }
                   3771:                             
                   3772:                                 if (quo) {
                   3773:                                     i++;
                   3774:                                     continue;
                   3775:                                 }
                   3776:                                 
                   3777:                                 if (ch0 == '(') {
                   3778:                                     bra++;
                   3779:                                     i++;
                   3780:                                 
                   3781:                                     continue;
                   3782:                                 }
                   3783:                                 
                   3784:                                 if (ch0 == ')') {
                   3785:                                     bra--;
                   3786:                                     i++;
                   3787:                                 
                   3788:                                     continue;
                   3789:                                 }
                   3790: 
                   3791:                                 if (bra) {
                   3792:                                     i++;
                   3793:                                     continue;
                   3794:                                 }
                   3795: 
                   3796: zp20:
                   3797:                                 if (a[i + j] != b[j]) {
                   3798:                                     i++;
                   3799:                                     continue;
                   3800:                                 }       /* ... for occurence of 2nd */
                   3801:                                 
                   3802:                                 if (++j < ch) goto zp20;
                   3803:                                 
                   3804:                                 i += ch;    /* skip delimiter */
                   3805:                                 
                   3806:                                 if (++n == f) {
                   3807:                                     m = i;
                   3808:                                     goto zp30;
                   3809:                                 }
                   3810:                             }
                   3811:                             
                   3812:                             /* if(n<f) */ a[0] = EOL;
                   3813:                             
                   3814:                             goto nxt_operator;
                   3815:                         }
                   3816: 
                   3817: zp30:
                   3818: 
                   3819:                         while (i < l1) {
                   3820:                             
                   3821:                             j = 0;
                   3822:                             
                   3823:                             if ((ch0 = a[i]) == '"') {
                   3824:                                 toggle (quo);
                   3825:                                 i++;
                   3826:                             
                   3827:                                 continue;
                   3828:                             }
                   3829:                             
                   3830:                             if (quo) {
                   3831:                                 i++;
                   3832:                                 continue;
                   3833:                             }
                   3834: 
                   3835:                             if (ch0 == '(') {
                   3836:                                 bra++;
                   3837:                                 i++;
                   3838:                             
                   3839:                                 continue;
                   3840:                             }
                   3841: 
                   3842:                             if (ch0 == ')') {
                   3843:                                 bra--;
                   3844:                                 i++;
                   3845:                             
                   3846:                                 continue;
                   3847:                             }
                   3848: 
                   3849:                             if (bra) {
                   3850:                                 i++;
                   3851:                                 continue;
                   3852:                             }
                   3853: 
                   3854: zp40:                       
                   3855:                             if (a[i + j] != b[j]) {
                   3856:                                 i++;
                   3857:                                 continue;
                   3858:                             }
                   3859:                             
                   3860:                             if (++j < ch) goto zp40;
                   3861:                                 
                   3862:                             if (n == l) {
                   3863:                                 a[i] = EOL;
                   3864:                                 break;
                   3865:                             }           /* last $zpiece: done! */
                   3866:                             
                   3867:                             i += ch;
                   3868:                             n++;
                   3869: 
                   3870:                         }
                   3871: 
                   3872:                         if (m > 0) stcpy (a, &a[m]);
                   3873: 
                   3874:                         goto nxt_operator;
                   3875:                     
                   3876:                     }
                   3877: 
                   3878:                 case 'L':           /* $ZLENGTH */
                   3879: 
                   3880:                     /* Similar to $LENGTH with two arguments                */
                   3881:                     /* The difference is, that stuff within quotes is not   */
                   3882:                     /* counted as delimiter. nor is stuff within brackets   */
                   3883: 
                   3884:                     if (f != 2) {
                   3885:                         merr_raise (FUNARG);
                   3886:                         return;
                   3887:                     }
                   3888: 
                   3889:                     i = 0;
                   3890:                     j = 0;
                   3891:                     
                   3892:                     b = argstck[arg + 1];
                   3893:                     
                   3894:                     if ((f = stlen (b))) {
                   3895:                         int     quo,
                   3896:                         bra,
                   3897:                         ch0;
                   3898: 
                   3899:                         quo = 0;
                   3900:                         bra = 0;
                   3901: 
                   3902:                         if (f == 1) {       /* length of delimiter =1 char */
                   3903: 
                   3904:                             ch = b[0];
                   3905:                             j = 0;
                   3906:                         
                   3907:                             for (;;) {
                   3908: 
                   3909:                                 ch0 = a[i++];
                   3910: 
                   3911:                                 if (ch0 == EOL) break;
                   3912:                                 
                   3913:                                 if (ch != '"') {
                   3914:                                     
                   3915:                                     if (ch0 == '"') {
                   3916:                                         toggle (quo);
                   3917:                                         continue;
                   3918:                                     }
                   3919: 
                   3920:                                     if (quo) continue;
                   3921: 
                   3922:                                 }
                   3923: 
                   3924:                                 if (ch0 == '(') bra++;
                   3925:                                 if (ch0 == ')') bra--;
                   3926:                                 if (ch0 != ch) continue;
                   3927:                                 if (bra > 1) continue;
                   3928:                                 if ((ch0 != '(') && bra) continue;
                   3929:                                 
                   3930:                                 j++;
                   3931:                             }
                   3932: 
                   3933:                             
                   3934:                             j++;
                   3935:                             
                   3936:                         } 
                   3937:                         else {
                   3938: 
                   3939:                             int n;
                   3940: 
                   3941:                             j = 1;
                   3942: 
                   3943:                             for (;;) {
                   3944: 
                   3945:                                 n = 0;
                   3946: 
                   3947:                                 if ((ch0 = a[i]) == '"') {                                
                   3948:                                     toggle (quo);
                   3949:                                     i++;
                   3950:                                     
                   3951:                                     continue;
                   3952:                                 }
                   3953: 
                   3954:                                 if (ch0 == EOL) break;
                   3955: 
                   3956:                                 if (quo) {
                   3957:                                     i++;
                   3958:                                     continue;
                   3959:                                 }
                   3960: 
                   3961:                                 if (ch0 == '(') {
                   3962:                                     bra++;
                   3963:                                     i++;
                   3964:                                 
                   3965:                                     continue;
                   3966:                                 }
                   3967: 
                   3968:                                 if (ch0 == ')') {
                   3969:                                     bra--;
                   3970:                                     i++;
                   3971:                                     
                   3972:                                     continue;
                   3973:                                 }
                   3974: 
                   3975:                                 if (bra) {
                   3976:                                     i++;
                   3977:                                     continue;
                   3978:                                 }
                   3979: 
                   3980: zl10:                           
                   3981: 
                   3982:                                 if (a[i + n] != b[n]) {
                   3983:                                     i++;
                   3984:                                     continue;
                   3985:                                 }
                   3986: 
                   3987:                                 if (++n < f) goto zl10;
                   3988:                                 
                   3989:                                 i += f;     /* skip delimiter */
                   3990:                                 j++;
                   3991:                             
                   3992:                             }
                   3993:                         }
                   3994:                     }
                   3995: 
                   3996:                     intstr (a, j);
                   3997:                     goto nxt_operator;
                   3998: 
                   3999:                 case ZLSD:          /* $ZLSD levenshtein function */
                   4000:                     
                   4001:                     if (f != 2) {
                   4002:                         merr_raise (FUNARG);
                   4003:                         return;
                   4004:                     }
                   4005: 
                   4006:                     f = levenshtein (a, argstck[arg + 1]);
                   4007:                     intstr (a, f);
                   4008:                     
                   4009:                     goto nxt_operator;
                   4010: 
                   4011: 
                   4012:                 /* $ZKEY */
                   4013:                 /* transform a string to be used as a key in an array so   */
                   4014:                 /* the result string will collate in the desired way       */
                   4015:                 /* according to the production rule specified by VIEW 93   */
                   4016:                 case 'K':
                   4017:                     
                   4018:                     if (f == 2) {
                   4019:                         zkey (a, intexpr (argstck[arg + 1]));
                   4020:                     }
                   4021:                     else if (f == 1) {
                   4022:                         zkey (a, v93);
                   4023:                     }
                   4024:                     else {
                   4025:                         merr_raise (FUNARG);
                   4026:                     }
                   4027:                     
                   4028:                     if (merr () > OK) return;
                   4029: 
                   4030:                     goto nxt_operator;
                   4031: 
                   4032: 
                   4033:                 /* $ZREPLACE */
                   4034:                 /* Replace in first argument non overlapping occurences    */
                   4035:                 /* of the second argument by the third argument.           */
                   4036:                 /* if the third argument is missing, assume it to be empty */
                   4037:                 case 'R':
                   4038:                     
                   4039:                     if (f == 3) {
                   4040:                         zreplace (a, argstck[arg + 1], argstck[arg + 2]);
                   4041:                     }
                   4042:                     else if (f == 2) {
                   4043:                         zreplace (a, argstck[arg + 1], "\201");
                   4044:                     }
                   4045:                     else {
                   4046:                         merr_raise (FUNARG);
                   4047:                     }
                   4048: 
                   4049:                     if (merr () > OK) return;
                   4050: 
                   4051:                     goto nxt_operator;
                   4052: 
                   4053: 
                   4054:                 /* $ZSYNTAX */
                   4055: 
                   4056:                 case 'S':
                   4057: 
                   4058:                     if (f != 1) {
                   4059:                         merr_raise (FUNARG);
                   4060:                         return;
                   4061:                     }
                   4062: 
                   4063:                     zsyntax (a);
                   4064:                     
                   4065:                     if (merr () > OK) return;
                   4066: 
                   4067:                     goto nxt_operator;
                   4068: 
                   4069: 
                   4070:                 /* $ZTIME()/$ZDATE() */
                   4071:                 case 'T':
                   4072:                 case 'D':
                   4073: 
                   4074:                     {
                   4075:                         time_t unix_epoch;
                   4076:                         char *horo_time = a;
                   4077:                         char fmt_string[120];
                   4078:                         struct tm *zdate_time;                        
                   4079:                         
                   4080:                         if (f > 2) {
                   4081:                             merr_raise (FUNARG);
                   4082:                             return;
                   4083:                         }
                   4084: 
                   4085:                         if (!is_horolog (horo_time)) {
                   4086:                             merr_raise (ZINVHORO);
                   4087:                             return;
                   4088:                         }
                   4089:                         
                   4090:                         if (f == 2) {
                   4091:                             stcpy (fmt_string, argstck[arg + 1]);
                   4092:                         }
                   4093:                         else if (f == 1) {
                   4094:                             char zdf_key[50];
                   4095: 
                   4096:                             switch (i) {
                   4097:                                 
                   4098:                                 case 'D':
                   4099:                                     sprintf (zdf_key, "^$JOB\202%d\202ZDATE_FORMAT\201", pid);
                   4100:                                     break;
                   4101: 
                   4102:                                 case 'T':
                   4103:                                     sprintf (zdf_key, "^$JOB\202%d\202ZTIME_FORMAT\201", pid);
                   4104:                                     break;
                   4105: 
                   4106:                             }
                   4107:                                                                 
                   4108:                             ssvn (get_sym, zdf_key, fmt_string);
                   4109:                         }
                   4110:                         
                   4111:                         stcnv_m2c (fmt_string);
                   4112:                                 
                   4113:                         unix_epoch = horolog_to_unix (horo_time);
                   4114:                         zdate_time = localtime (&unix_epoch);
                   4115: 
                   4116:                         strftime (a, 255, fmt_string, zdate_time);
                   4117:                         
                   4118:                         stcnv_c2m (a);
                   4119: 
                   4120:                         goto nxt_operator;
                   4121:                     }
                   4122:                     
                   4123: 
                   4124:                 /* $ZHOROLOG() */
                   4125:                 /* convert string date to $H format */
                   4126:                 case 'H':
                   4127:                     {
                   4128:                         char *time_str = a;
                   4129:                         char *fmt_string = argstck[arg + 1];
                   4130:                         struct tm zhoro_tm;
                   4131:                         unsigned long ilong;
                   4132:                         unsigned long ilong1;
                   4133:                         
                   4134:                         if (f != 2) {
                   4135:                             merr_raise (FUNARG);
                   4136:                             return;
                   4137:                         }
                   4138: 
                   4139:                         strptime (time_str, fmt_string, &zhoro_tm);
                   4140: 
                   4141:                         ilong1 = mktime (&zhoro_tm) + tzoffset;
                   4142:                         ilong = ilong1 / 86400;
                   4143: 
                   4144:                         lintstr (a, ilong + 47117);
                   4145:                         i = stlen (a);
                   4146: 
                   4147:                         a[i++] = ',';
                   4148:                         ilong = ilong1 - (ilong * 86400) + 43200;
                   4149: 
                   4150:                         lintstr (&a[i], ilong);                       
                   4151: 
                   4152:                         goto nxt_operator;
                   4153:                         
                   4154:                     }
                   4155:                     
                   4156:                     
                   4157:                 case GETX:          /* dummy function for implicit $GET */
                   4158: 
                   4159:                     /* un-stack $ZREFERENCE and $ZLOCAL */
                   4160:                     stcpy (zref, refsav[--refsx]);
                   4161:                     stcpy (zloc, refsav[refsx] + 256);
                   4162:                     
                   4163:                     free (refsav[refsx]);
                   4164:                 
                   4165:                 
                   4166:                 case GET:           /* dummy function for $GET with two args */
                   4167:                 
                   4168:                     goto nxt_operator;
                   4169: 
                   4170:                 
                   4171:                 case 'E':           /* ZEDIT */
                   4172:                 
                   4173:                     if (f > 4) {
                   4174:                         merr_raise (FUNARG);
                   4175:                         return;
                   4176:                     } 
                   4177: 
                   4178:                     {
                   4179: 
                   4180:                         int k, l, rev, esc;
                   4181: 
                   4182:                         if (f == 1) {
                   4183:                             rev = TRUE;
                   4184:                             goto reverse;
                   4185:                         }
                   4186: 
                   4187:                         j = (f == 4 ? intexpr (argstck[arg + 3]) : 1);  /* type of action */
                   4188:                         
                   4189:                         if ((rev = j < 0)) j = (-j);
                   4190:                         if ((esc = j / 10) == 1 || esc == 2) j = j % 10;
                   4191: 
                   4192:                         if (j < 1 || j > 3) {
                   4193:                             merr_raise (ARGER);
                   4194:                             return;
                   4195:                         }
                   4196: 
                   4197:                         f = (f >= 3 ? intexpr (argstck[arg + 2]) : 0);  /* target length */
                   4198:                         
                   4199:                         if (f > 255) merr_raise (ARGER);
                   4200:                         
                   4201:                         if (merr () > OK) return;
                   4202: 
                   4203:                         if (esc == 1) {     /* remove ESC-Sequences */
                   4204:                             
                   4205:                             stcpy (tmp, a);
                   4206:                             
                   4207:                             i = 0;
                   4208:                             k = 0;
                   4209:                             l = 1;
                   4210:                             esc = 0;
                   4211:                             
                   4212:                             while ((a[k] = tmp[i++]) != EOL) {
                   4213: 
                   4214:                                 if (l) {
                   4215:                                     if (a[k] != ESC) {
                   4216:                                         k++;
                   4217:                                         continue;
                   4218:                                     }
                   4219:                             
                   4220:                                     if ((a[k] = tmp[i++]) != '[') continue;
                   4221: 
                   4222:                                     l = 0;
                   4223:                                     
                   4224:                                     continue;
                   4225:                                 }
                   4226: 
                   4227:                                 if (a[k] >= '@') l = 1;
                   4228: 
                   4229:                             }
                   4230: 
                   4231:                         }
                   4232: 
                   4233:                         /* anything to be done ??? */
                   4234:                         if (argstck[arg + 1][0] == EOL) goto reverse;
                   4235:                         
                   4236:                         stcpy (tmp, argstck[arg + 1]);
                   4237:                         
                   4238:                         if (j != 1) {       /* remove leading characters */
                   4239:                             
                   4240:                             i = 0;
                   4241:                             k = 0;
                   4242:                             
                   4243:                             while (a[i] != EOL) {
                   4244: 
                   4245:                                 if (a[i] == tmp[k]) {
                   4246:                                     i++;
                   4247:                                     k = 0;
                   4248:                                 
                   4249:                                     continue;
                   4250:                                 }
                   4251:                                 
                   4252:                                 if (tmp[k++] == EOL) break;
                   4253:                             
                   4254:                             }
                   4255:                             
                   4256:                             if (i) stcpy (a, &a[i]);
                   4257: 
                   4258:                         }
                   4259: 
                   4260:                         if (j != 3) {       /* remove trailing characters */
                   4261: 
                   4262:                             i = stlen (a) - 1;
                   4263:                             k = 0;
                   4264:                         
                   4265:                             while (i >= 0) {
                   4266:                                 
                   4267:                                 if (a[i] == tmp[k]) {
                   4268:                                     i--;
                   4269:                                     k = 0;
                   4270: 
                   4271:                                     continue;
                   4272:                                 }
                   4273:                                 
                   4274:                                 if (tmp[k++] == EOL) break;
                   4275: 
                   4276:                             }
                   4277: 
                   4278:                             a[i + 1] = EOL;
                   4279: 
                   4280:                         }
                   4281: 
                   4282:                         i = stlen (a);
                   4283:                         
                   4284:                         if ((f -= i) > 0) { /* characters to append */
                   4285:                             
                   4286:                             if (esc == 2) { /* ignore ESC-Sequences */
                   4287:                                 
                   4288:                                 k = 0;
                   4289:                                 l = 1;
                   4290: 
                   4291:                                 while (a[k] != EOL) {
                   4292: 
                   4293:                                     if (l) {
                   4294: 
                   4295:                                         if (a[k++] == ESC) {
                   4296:                                         
                   4297:                                             f += 2;
                   4298:                                             
                   4299:                                             if (a[k++] == '[') l = 0;
                   4300:                                         
                   4301:                                         }
                   4302:                                     } 
                   4303:                                     else {
                   4304:                                     
                   4305:                                         f++;
                   4306:                                     
                   4307:                                         if (a[k++] >= '@') l = 1;
                   4308: 
                   4309:                                     }
                   4310: 
                   4311:                                 }
                   4312: 
                   4313:                             }
                   4314: 
                   4315:                             k = 0;
                   4316:                             
                   4317:                             if (j == 1) {
                   4318:                                 k = f;
                   4319:                                 f = 0;
                   4320:                             }
                   4321: 
                   4322:                             if (j == 2) {
                   4323:                                 k = f - f / 2;
                   4324:                                 f -= k;
                   4325:                             }
                   4326: 
                   4327:                             l = stlen (tmp);
                   4328:                             
                   4329:                             if (k) {        /* append on right side */
                   4330:                                 
                   4331:                                 a[k += i] = EOL;
                   4332:                                 j = l;
                   4333:                                 
                   4334:                                 while (--k >= i) {
                   4335: 
                   4336:                                     a[k] = tmp[--j];
                   4337:                                     
                   4338:                                     if (j <= 0) j = l;
                   4339: 
                   4340:                                 }
                   4341: 
                   4342:                             }
                   4343: 
                   4344:                             if (f) {        /* append on left side */
                   4345:                                 
                   4346:                                 i = 0;
                   4347:                                 
                   4348:                                 while (l < f) tmp[l++] = tmp[i++];
                   4349: 
                   4350:                                 stcpy (&tmp[l], a);
                   4351:                                 stcpy (a, tmp);
                   4352: 
                   4353:                             }
                   4354: 
                   4355:                         }
                   4356: 
                   4357: reverse: 
                   4358:                         
                   4359:                         if (rev) {
                   4360:                             
                   4361:                             i = stlen (a) - 1;
                   4362:                             j = 0;
                   4363:                             f = i / 2;
                   4364:                         
                   4365:                             while (j <= f) {
                   4366:                                 k = a[j];
                   4367:                                 a[j++] = a[i];
                   4368:                                 a[i--] = k;
                   4369:                             }
                   4370: 
                   4371:                         }
                   4372: 
                   4373:                     }
                   4374: 
                   4375:                     goto nxt_operator;
                   4376: 
                   4377:                 default:
                   4378:                     merr_raise (ILLFUN);
                   4379:                     return;
                   4380: 
                   4381: 
                   4382:             }
                   4383: 
                   4384:             /* end of function evaluation section */
                   4385: 
                   4386: nxt_operator:
                   4387: 
                   4388:             if (spx > 0 && (f = op_stck[spx]) != ARRAY && f != '(') {
                   4389:                 goto nxt_expr;
                   4390:             }
                   4391:             /* push answer */
                   4392: 
                   4393:             op_stck[++spx] = OPERAND;
                   4394:             codptr++;
                   4395:             
                   4396:             goto nextchr;
                   4397: 
                   4398: 
                   4399:     case '$':               /* scan function name convert upper to lower */
                   4400: 
                   4401:         if (op_stck[spx] == OPERAND) goto m_operator;
                   4402:         if ((f = *++codptr) >= 'A' && f <= 'Z') f += 32;
                   4403: 
                   4404:         if (f == 'z' && standard) {
                   4405:             merr_raise (NOSTAND);
                   4406:             return;
                   4407:         }
                   4408: 
                   4409:         if (f == '$' || f == '%') {         /* extrinsic function/extrinsic variable */
                   4410:             
                   4411:             zexflag = FALSE;
                   4412: 
                   4413: extra_fun:
                   4414: 
                   4415: 
                   4416:             {
                   4417:                 short   savmcmnd, savsetp;    /* stuff to be saved */
                   4418:                 char    savarnam[256];
                   4419:                 char   *savdofr;
                   4420:                 long    savlen;
                   4421:                 short   savtest;
                   4422:                 short   savop;
                   4423:                 char   *savargs = NULL;
                   4424:                 int     savarg;
                   4425:                 char   *savastck;
                   4426:                 char   *savpart;
                   4427:                 char   *b;
                   4428:                 char   *namold;
                   4429:                 long    rouoldc;
                   4430:                 char    label[255],
                   4431:                 routine[255];
                   4432:                 short   errex;      /* FLAG: error exit */
                   4433:                 short   libcall;
                   4434:                 libcall = FALSE;
                   4435: 
                   4436:                 for (i = 0; i < 255; i++) {
                   4437:                     routine[i] = '\201';
                   4438:                 }
                   4439:                 
                   4440:                 if (f == '%') libcall = TRUE;
                   4441:                 
                   4442:                 savmcmnd = mcmnd;
                   4443:                 savsetp = setpiece;
                   4444:                 savop = setop;
                   4445:                 savtest = test;
                   4446:                 stcpy (savarnam, varnam);
                   4447:                 savdofr = dofram0;
                   4448:                 errex = FALSE;
                   4449:                 
                   4450:                 if ((argstck[++arg] = a) >= s) {
                   4451:                     
                   4452:                     char   *bak;
                   4453:                     bak = partition;
                   4454:                     
                   4455:                     if (getpmore () == 0) {
                   4456:                         merr_raise (STKOV);
                   4457:                         return;
                   4458:                     }
                   4459: 
                   4460:                     a = a - bak + partition;
                   4461:                     b = b - bak + partition;
                   4462: 
                   4463:                 }
                   4464: 
                   4465:                 savlen = a - argptr;
                   4466:                 savpart = partition;
                   4467:                 
                   4468:                 if (spx > 0) {
                   4469: 
                   4470:                     if ((savargs = calloc ((unsigned) (savlen + 256L), 1)) == NULL) {
                   4471:                         merr_raise (STKOV);
                   4472:                         return;
                   4473:                     }           /* could not allocate stuff...     */
                   4474:                     
                   4475:                     stcpy0 (savargs, argptr, savlen + 256L);
                   4476:                     argptr = partition;
                   4477: 
                   4478:                 }
                   4479: 
                   4480:                 savarg = arg;
                   4481: 
                   4482:                 if ((savastck = calloc ((unsigned) (arg + 1), sizeof (char *))) == NULL) {
                   4483:                     merr_raise (STKOV);
                   4484:                     return;
                   4485:                 }           /* could not allocate stuff...     */
                   4486: 
                   4487:                 stcpy0 (savastck, (char *) argstck, (long) ((arg + 1) * sizeof (char *)));
                   4488: 
                   4489:                 b = label;      /* parse label */
                   4490:                 
                   4491:                 if ((ch = *++codptr) == '%') {
                   4492:                     *b++ = ch;
                   4493:                     codptr++;
                   4494:                 }
                   4495: 
                   4496:                 while (((ch = *codptr) >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
                   4497:                     *b++ = ch;
                   4498:                     codptr++;
                   4499:                 }
                   4500: 
                   4501:                 *b = EOL;
                   4502:                 b = routine;               
                   4503: 
                   4504:                 
                   4505:                 if (obj_field) {                    
                   4506:                     strcpy (b, &(object_class[1]));
                   4507:                     stcnv_c2m (b);
                   4508:                     b += strlen (object_class) - 1;
                   4509:                     *++b = EOL;
                   4510:                 }
                   4511:                 
                   4512:                 
                   4513: 
                   4514:                 if (ch == '^') {    /* parse routine name */
                   4515: 
                   4516: 
                   4517:                     
                   4518:                     if (((ch = *++codptr) >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '%') {
                   4519:                         *b++ = ch;
                   4520:                     }
                   4521:                     
                   4522:                     while (((ch = *++codptr) >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
                   4523:                         *b++ = ch;
                   4524:                     }
                   4525: 
                   4526:                     if (libcall) {
                   4527:                         char newnam[255];
                   4528:                         
                   4529:                         for (i = 0; i < stlen (routine); i++) {
                   4530:                             routine[i] = tolower (routine[i]);
                   4531:                         }
                   4532: 
                   4533:                         newnam[0] = '%';
                   4534:                         newnam[1] = 'u';
                   4535:                         newnam[2] = 'l';
                   4536:                         newnam[3] = '\201';
                   4537: 
                   4538:                         stcat (newnam, routine);
                   4539:                         
                   4540:                         routine[0] = EOL;
                   4541:                         stcpy (routine, newnam);
                   4542: 
                   4543:                         b = b + 3;                        
                   4544:                     }
                   4545: 
                   4546:                     
                   4547:                     if (routine[0] == EOL) {
                   4548:                         merr_raise (ILLFUN);
                   4549:                         errex = TRUE;
                   4550:                         
                   4551:                         goto errexfun;
                   4552:                     }
                   4553: 
                   4554:                 }
                   4555: 
                   4556:                 
                   4557:                 
                   4558:                 {
                   4559:                     char nrou[255];
                   4560:                     char ntag[255];
                   4561:                     char nbuf[255];
                   4562: 
                   4563:                     stcpy (nrou, routine);
                   4564:                     stcpy (ntag, label);
                   4565: 
                   4566:                     stcnv_m2c (nrou);
                   4567:                     stcnv_m2c (ntag);
                   4568:                     
                   4569: 
                   4570:                     if (rtn_resolve (nrou, ntag, nbuf) != NULL) {
                   4571:                         strcpy (routine, nbuf);
                   4572:                         stcnv_c2m (routine);
                   4573:                     }
                   4574:                     else {
                   4575:                         merr_raise (LBLUNDEF);
                   4576:                         return;
                   4577:                     }
                   4578:                 }
                   4579:                 
                   4580:                 
                   4581:                 *b = EOL;
                   4582:                 
                   4583:                 /* something must be specified */
                   4584:                 if (label[0] == EOL && routine[0] == EOL) {
                   4585:                     merr_raise (ILLFUN);
                   4586:                     errex = TRUE;
                   4587:                     
                   4588:                     goto errexfun;
                   4589:                 }
                   4590: 
                   4591:                 
                   4592:                 if (obj_field) {
                   4593:                     char t_objf[255];
                   4594: 
                   4595:                     snprintf (t_objf, 254, "%s\201", object_instance);
                   4596:                     
                   4597:                     dofram0 = dofrmptr;
                   4598:                     *dofrmptr++ = DELIM;
                   4599:                     dofrmptr += stcpy (dofrmptr, t_objf) + 1;
                   4600:                 }
                   4601:                 
                   4602:                 
                   4603:                 if (*codptr == '(' && *(codptr + 1) != ')') {
                   4604: 
                   4605:                     
                   4606:                     if (!obj_field) dofram0 = dofrmptr;
                   4607:                     obj_field = FALSE;
                   4608:                     
                   4609: 
1.12    ! snw      4610:                     /* dofram0 = dofrmptr; */
1.1       snw      4611:                     
                   4612:                     i = 0;
                   4613:                     codptr++;
                   4614:                     
                   4615:                     for (;;) {
                   4616: 
                   4617:                         setpiece = TRUE;    /* to avoid error on closing bracket */
                   4618:                         
                   4619:                         if (*codptr == '.' && (*(codptr + 1) < '0' || *(codptr + 1) > '9')) {
                   4620:                             
                   4621:                             codptr++;
                   4622:                             
                   4623:                             expr (NAME);
                   4624:                             codptr++;
                   4625:                             *dofrmptr++ = DELIM;    /* to indicate call by name */
                   4626:                             dofrmptr += stcpy (dofrmptr, varnam) + 1;
                   4627:                         
                   4628:                         } 
                   4629:                         else {
                   4630:                             expr (STRING);
                   4631:                             dofrmptr += stcpy (dofrmptr, argptr) + 1;
                   4632:                         }
                   4633: 
                   4634:                         setpiece = FALSE;
                   4635:                         i++;
                   4636:                         
                   4637:                         if (merr () > OK) {
                   4638:                             dofrmptr = dofram0;
                   4639:                             errex = TRUE;
                   4640:                             
                   4641:                             goto errexfun;
                   4642:                         }
                   4643: 
                   4644:                         ch = *codptr++;
                   4645:                         
                   4646:                         if (ch == ',') continue;
                   4647: 
                   4648:                         if (ch != ')') {
                   4649:                             merr_raise (COMMAER);
                   4650:                             dofrmptr = dofram0;
                   4651:                             errex = TRUE;
                   4652: 
                   4653:                             goto errexfun;
                   4654:                         }
                   4655: 
                   4656:                         ch = *codptr;
                   4657:                         
                   4658:                         break;
                   4659: 
                   4660:                     }
                   4661: 
                   4662:                 } 
                   4663:                 else {
                   4664: 
                   4665:                     
                   4666:                     if (!obj_field) {
                   4667:                         dofram0 = 0;                    
                   4668:                     }
                   4669: 
                   4670:                     obj_field = FALSE;
                   4671:                     
1.12    ! snw      4672:                     /* dofram0 = 0; */
1.1       snw      4673:                     if (*codptr == '(') codptr += 2;
                   4674:                 
                   4675:                 }
                   4676: 
                   4677:                 rouoldc = roucur - rouptr;
                   4678:                 namold = 0;
                   4679: 
                   4680:                 if (routine[0] != EOL) {    /* load routine */                    
                   4681:                     
                   4682:                     dosave[0] = EOL;
                   4683:                     loadsw = TRUE;
                   4684:                     
                   4685:                     while ((*(namptr++)) != EOL);
                   4686:                     
                   4687:                     namold = namptr;
                   4688:                     
                   4689:                     stcpy (namptr, rou_name);
                   4690:                     zload (routine);
                   4691:                     
                   4692:                     if (merr () > OK) {
                   4693:                         errex = TRUE;
                   4694:                         goto errexfun;
                   4695:                     }
                   4696: 
                   4697:                 } 
                   4698: 
                   4699:                 {
                   4700: 
                   4701:                     char *reg, *reg1;
                   4702: 
                   4703:                     reg1 = rouptr;
                   4704:                     reg = reg1;
                   4705:                     
                   4706:                     if (label[0] != EOL) {
                   4707: 
                   4708:                         while (reg < rouend) {
                   4709:                         
                   4710:                             reg++;
                   4711:                             j = 0;
                   4712:                         
                   4713:                             while (*reg == label[j]) {
                   4714:                                 reg++;
                   4715:                                 j++;
                   4716:                             }
                   4717:                         
                   4718:                             if (label[j] == EOL) {
                   4719: 
                   4720:                                 if (*reg == ':') {
                   4721:                                     char return_type[255];
                   4722:                                     short ret_type;
                   4723:                                     register int typei;
                   4724: 
                   4725:                                     /* we got a return type. parse it. */
                   4726:                                     reg++; /* skip over the colon */
                   4727: 
                   4728:                                     typei = 0;
                   4729:                                     
                   4730:                                     while (isalpha ((ch = *reg++))) {
                   4731:                                         return_type[typei++] = toupper (ch);
                   4732:                                     }
                   4733:                                     
                   4734:                                     reg--; /* back up to the previous char so that parsing of the entry point can resume later */
                   4735:                                     return_type[typei] = '\0';
                   4736: 
                   4737:                                     ret_type = dt_get_type (return_type);
                   4738:                                     if (ret_type == DT_INVALID) {
                   4739:                                         merr_raise (INVTYPE);
                   4740:                                         errex = TRUE;
                   4741: 
                   4742:                                         goto errexfun;
                   4743:                                     }
                   4744: 
                   4745:                                     /* save off the return type to be checked by QUIT code */
                   4746:                                     extr_types[nstx + 1] = ret_type; 
                   4747:                                     
1.12    ! snw      4748:                                     /* printf ("return_type = '%s' *reg = '%c'\r\n", return_type, *reg); */
1.1       snw      4749:                                 }
                   4750:                                 
                   4751:                                 if (*reg == TAB || *reg == SP) goto off;
                   4752:                                 /* call of procedure without specifying a parameter list */
                   4753: 
                   4754:                                 if (*reg == '(') {
                   4755: 
                   4756:                                     if (dofram0 == 0) dofram0 = dofrmptr;
                   4757:                                 
                   4758:                                     goto off;
                   4759: 
                   4760:                                 }
                   4761: 
                   4762:                             }
                   4763: 
                   4764:                             reg = (reg1 = reg1 + UNSIGN (*reg1) + 2);
                   4765: 
                   4766:                         }
                   4767: 
                   4768:                         {
                   4769: 
                   4770:                             merr_raise (LBLUNDEF);
                   4771:                             stcpy (varerr, label);  /* to be included in error message */
                   4772: 
                   4773:                             if (dofram0) dofrmptr = dofram0; /* reset frame pointer */
                   4774: 
                   4775:                             zload (rou_name);
                   4776:                             
                   4777:                             errex = TRUE;
                   4778:                             
                   4779:                             goto errexfun;
                   4780: 
                   4781:                         }
                   4782:                     }
                   4783: 
                   4784: off:
                   4785:                     
                   4786:                     roucu0 = reg1;
                   4787:                 
                   4788:                 }
                   4789:                 
                   4790:                 if (roucu0 >= rouend) {
                   4791: 
                   4792:                     merr_raise (LBLUNDEF);
                   4793:                     stcpy (varerr, label);  /* to be included in error message */
                   4794:                     
                   4795:                     if (dofram0) dofrmptr = dofram0; /* reset frame pointer */
                   4796:                     
                   4797:                     zload (rou_name);
                   4798:                     errex = TRUE;
                   4799: 
                   4800:                     goto errexfun;
                   4801: 
                   4802:                 }
                   4803: 
                   4804:                 if (routine[0] != EOL) stcpy (rou_name, routine);
                   4805: 
                   4806:                 roucu0++;
                   4807:                 forsw = FALSE;
                   4808: 
                   4809: #ifdef DEBUG_NEWSTACK
                   4810:                 printf("Stack PUSH in expr.c!\r\n");
                   4811: #endif
                   4812: 
                   4813:                 if (++nstx > NESTLEVLS) {
                   4814:                     nstx--;
                   4815:                     merr_raise (STKOV);
                   4816:                     errex = TRUE;
                   4817: 
                   4818:                     goto errexfun;
                   4819:                 }
                   4820:                 else {
                   4821:                     estack++;
                   4822:                 }
                   4823: 
                   4824:                 nestc[nstx] = '$';
                   4825: 
                   4826: #ifdef DEBUG_NEWSTACK
                   4827:                 if(!cmdptr) printf("CMDPTR is ZERO!\r\n");
                   4828: #endif
                   4829: 
                   4830:                 nestp[nstx] = cmdptr;
                   4831:                 nestn[nstx] = namold;
                   4832:                 nestr[nstx] = rouoldc;
                   4833:                 nestnew[nstx] = 0;
                   4834:                 nestlt[nstx] = level;
                   4835:                 level = 0;      /* push level ; clr level */
                   4836:                 ztrap[nstx][0] = EOL;
                   4837: 
                   4838:                 cmdptr += stcpy (cmdptr, codptr - 1) + 1;
                   4839:                 roucur = roucu0;
                   4840: 
                   4841:                 if (dofram0) {
                   4842:                     
                   4843:                     char *reg, *reg1;
                   4844: 
                   4845:                     reg = roucu0;
                   4846:                     reg1 = dofram0;
                   4847: 
                   4848:                     while ((ch = (*reg++)) != '(') {
                   4849: 
                   4850:                         if (ch == SP || ch == TAB || ch == EOL) {
                   4851:                             break;
                   4852:                         }
                   4853: 
                   4854:                     }
                   4855:                     
                   4856:                     if (ch != '(') {
                   4857: 
                   4858:                         merr_raise (TOOPARA);
                   4859:                         dofrmptr = dofram0;
                   4860:                         errex = TRUE;
                   4861:                         
                   4862: #ifdef DEBUG_NEWSTACK
                   4863:                         printf("Cheesy Stack POP in expr.c\r\n");
                   4864: #endif
                   4865: 
                   4866: 
                   4867: 
                   4868:                         nstx--;
                   4869:                         estack--;
                   4870: 
                   4871:                         goto errexfun;
                   4872: 
                   4873:                     }
                   4874: 
                   4875:                     j = 0;
                   4876: 
                   4877:                     if (*reg == ')') {
                   4878:                         reg++;
                   4879:                     }
                   4880:                     else {
                   4881:                         /* PARSE FORMALLIST */
                   4882:                         short fl_type;
1.12    ! snw      4883:                         /* re-enable following 3 later */
        !          4884:                         /*short fl_mandatory;*/
        !          4885:                         /*short fl_byref;*/
        !          4886:                         /*short lastparm;*/                        
1.1       snw      4887:                         char fl_typestr[255];
                   4888:                         char fl_mand;
                   4889:                         short dtcheck_result;                        
                   4890:                         register short typei;
                   4891:                         short gotparm;
                   4892:                         int paramct;
                   4893:                         
                   4894:                         fl_type = DT_AUTO;
1.12    ! snw      4895:                         /* re-enable following 3 later */
        !          4896:                         /*fl_mandatory = TRUE;*/
        !          4897:                         /*fl_byref = FALSE;*/
        !          4898:                         /*lastparm = FALSE;*/                        
1.1       snw      4899:                         dtcheck_result = FALSE;
                   4900:                         gotparm = FALSE;
                   4901:                         paramct = 0;
                   4902:                         
                   4903:                         while ((ch = (*reg++)) != EOL) {
                   4904:                             
                   4905:                             gotparm = FALSE;
                   4906:                             
                   4907:                             if ((ch == ':') && j) {
                   4908:                                 
                   4909:                                 /* we have a type specification */
                   4910:                                 typei = 0;
                   4911: 
                   4912:                                 while ((ch = (*reg++)) != EOL) {
                   4913:                                     /* parse it */
                   4914:                                     if (isalpha (ch)) {
                   4915:                                         fl_typestr[typei++] = ch;
                   4916:                                     }
                   4917:                                     else if (ch == ':') {
                   4918:                                         /* we have an "optional" part */
                   4919:                                         fl_typestr[typei] = '\0';
                   4920:                                         fl_mand = *(reg + 1);
                   4921: 
1.12    ! snw      4922:                                         /*
1.1       snw      4923:                                         if ((fl_mand == 'o') || (fl_mand == 'O')) {
                   4924:                                             fl_mandatory = FALSE;
                   4925:                                         }
                   4926:                                         else {
                   4927:                                             merr_raise (INVLIBOPT);
                   4928:                                             dofrmptr = dofram0;
                   4929: 
                   4930:                                             errex = TRUE;
                   4931: 
                   4932:                                             nstx--;
                   4933:                                             estack--;
                   4934: 
                   4935:                                             goto errexfun;
                   4936:                                         }
1.12    ! snw      4937:                                         */
        !          4938: 
        !          4939:                                         if ((fl_mand != 'o') && (fl_mand != 'O')) {
        !          4940:                                             merr_raise (INVLIBOPT);
        !          4941:                                             dofrmptr = dofram0;
        !          4942: 
        !          4943:                                             errex = TRUE;
        !          4944: 
        !          4945:                                             nstx--;
        !          4946:                                             estack--;
        !          4947: 
        !          4948:                                             goto errexfun;
        !          4949:                                         }
        !          4950:                                             
        !          4951:                                         
1.1       snw      4952:                                     }
                   4953:                                     else if ((ch == ',') || (ch == ')')) {
                   4954: 
1.12    ! snw      4955:                                         /* re-enable later
1.1       snw      4956:                                         if (ch == ')') {
                   4957:                                             lastparm = TRUE;
                   4958:                                         }
1.12    ! snw      4959:                                         */
1.1       snw      4960: 
                   4961:                                         gotparm = TRUE;
                   4962:                                         paramct++;
                   4963:                                         
                   4964:                                         fl_typestr[typei] = '\0';
                   4965:                                         fl_type = dt_get_type (fl_typestr);
                   4966: 
                   4967:                                         if (fl_type == DT_INVALID) {
                   4968: 
                   4969:                                             merr_raise (INVTYPE);
                   4970:                                             dofrmptr = dofram0;     /* reset frame pointer */
                   4971:                                             errex = TRUE;
                   4972:                                             
                   4973:                                             nstx--;
                   4974:                                             estack--;
                   4975: 
                   4976:                                             goto errexfun;
                   4977: 
                   4978:                                         }
                   4979:                                         
                   4980:                                         break;
                   4981:                                     }
                   4982:                                 }                                
                   4983:                             }
                   4984:                             
                   4985:                             if (gotparm == TRUE) {
                   4986: 
                   4987:                                 if (reg1[0] == DELIM) {
                   4988:                                     dtcheck_result = dt_check (fl_type, reg1 + 1, paramct);
                   4989:                                 }
                   4990:                                 else {
                   4991:                                     dtcheck_result = dt_check (fl_type, reg1, paramct);
                   4992:                                 }
                   4993:                             
                   4994:                                 if (dtcheck_result == FALSE) {
                   4995:                                     merr_raise (TYPMISMATCH);
1.12    ! snw      4996:                                     dofrmptr = dofram0;     /* reset frame pointer */
1.1       snw      4997: 
                   4998:                                     errex = TRUE;
                   4999: 
                   5000:                                     nstx--;
                   5001:                                     estack--;
                   5002: 
                   5003:                                     goto errexfun;
                   5004:                                 }
                   5005:                             }
                   5006:                             
                   5007:                             if ((ch == ',' || ch == ')') && j) {
                   5008:                             
                   5009:                                 varnam[j] = EOL;
                   5010: 
                   5011: #if 0
                   5012:                     printf("01 [nstx] nstx is (%d) in expr.c\r\n",nstx);
                   5013:                     printf("[nestnew[nstx]] is (%d) in expr.c\r\n",nestnew[nstx]);
                   5014:                     printf("[newptr] newptr is [");
                   5015:                     for(loop=0; loop<50; loop++) 
                   5016:                     printf("%c", (newptr[loop] == EOL) ? '!' : newptr[loop]);
                   5017:                     printf("] in expr.c\r\n");
                   5018: #endif
                   5019: 
                   5020:                                 if (nestnew[nstx] == 0) nestnew[nstx] = newptr;
                   5021: 
                   5022:                                 if (reg1 < dofrmptr) {
                   5023: 
                   5024:                                     if (*reg1 == DELIM) {   /* call by reference */
                   5025: 
                   5026:                                         if (stcmp (reg1 + 1, varnam)) {     /* are they different?? */
                   5027:                                             symtab (new_sym, varnam, "");
                   5028:                                             symtab (m_alias, varnam, reg1 + 1);
                   5029:                                         }
                   5030: 
                   5031:                                     } 
                   5032:                                     else {
                   5033:                                         symtab (new_sym, varnam, "");   /* call by value */
                   5034:                                         symtab (set_sym, varnam, reg1);
                   5035:                                     }
                   5036: 
                   5037:                                     reg1 += stlen (reg1) + 1;
                   5038: 
                   5039:                                 } 
                   5040:                                 else {
                   5041:                                     symtab (new_sym, varnam, "");
                   5042:                                 }
                   5043:                                 
                   5044:                                 if (ch == ')') break;
                   5045:                                 
                   5046:                                 j = 0;
                   5047:                                 continue;
                   5048:                             }
                   5049: 
                   5050:                             if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9' && j) || (ch == '%' && j == 0)) {
                   5051:                                 varnam[j++] = ch;
                   5052:                                 continue;
                   5053:                             }
                   5054:                             
                   5055:                             merr_raise (ARGLIST);
                   5056:                             dofrmptr = dofram0;     /* reset frame pointer */
                   5057:                             errex = TRUE;
                   5058: 
                   5059:                             nstx--;
                   5060:                             estack--;
                   5061: 
                   5062:                             goto errexfun;
                   5063: 
                   5064:                         }
                   5065: 
                   5066:                     }
                   5067: 
                   5068:                     if (reg1 < dofrmptr) {
                   5069:                         merr_raise (TOOPARA);
                   5070:                         dofrmptr = dofram0; /* reset frame pointer */
                   5071:                         errex = TRUE;
                   5072:                         nstx--;
                   5073:                         estack--;                    
                   5074: 
                   5075:                         goto errexfun;
                   5076:                     }
                   5077: 
                   5078:                     dofrmptr = dofram0;
                   5079:                 
                   5080:                 }
                   5081: 
                   5082:                 xecline (0);
                   5083: 
                   5084:                 if (repQUIT) {      /* repeat QUIT */
                   5085: 
                   5086:                     stcpy (code, " V 26:\201");
                   5087: 
                   5088: #ifdef DEBUG_NEWSTACK
                   5089:                     printf("Trying to get at nstx in expr.c (2)\r\n");
                   5090: #endif
                   5091: 
                   5092:                     intstr (&code[6], nstx - repQUIT);
                   5093:                     repQUIT = 0;
                   5094:                     codptr = code;
                   5095: 
                   5096:                     return;
                   5097: 
                   5098:                 }
                   5099: 
                   5100:                 stcpy (tmp, argptr);
                   5101: 
                   5102: errexfun:
                   5103: 
                   5104:                 mcmnd = savmcmnd;
                   5105:                 setpiece = savsetp;
                   5106:                 setop = savop;
                   5107:                 test = savtest;
                   5108:                 
                   5109:                 stcpy (varnam, savarnam);
                   5110:                 
                   5111:                 dofram0 = savdofr;
                   5112:                 argptr = partition;
                   5113:                 a = argptr;
                   5114:                 
                   5115:                 if (spx > 0) {
                   5116:                     stcpy0 (argptr, savargs, savlen + 256L);
                   5117:                     free (savargs);
                   5118:                 }
                   5119:                 
                   5120:                 arg = savarg;
                   5121:                 stcpy0 ((char *) argstck, savastck, (long) ((arg + 1) * sizeof (char *)));
                   5122: 
                   5123:                 free (savastck);
                   5124:                 a = savlen + argptr;
                   5125:                 
                   5126:                 if (savpart != partition) { /* autoadjust may have changed that */
                   5127:                     
                   5128:                     f = 0;
                   5129: 
                   5130:                     while (f <= arg) {
                   5131: 
                   5132:                         if (argstck[f]) argstck[f] = argstck[f] - savpart + partition;
                   5133:                     
                   5134:                         f++;
                   5135: 
                   5136:                     }
                   5137: 
                   5138:                 }
                   5139: 
                   5140:                 if (errex) {
                   5141: 
                   5142:                     if (zexflag && (merr () == NOPGM || merr () == LBLUNDEF)) merr_raise (ILLFUN);
                   5143:                     return;
                   5144:                 
                   5145:                 }
                   5146: 
                   5147:                 if (merr () != OK) return;
                   5148: /*                if (ierr != OK && ierr != (OK - CTRLB)) return;*/
                   5149: 
                   5150:                 stcpy (a, tmp);
                   5151:                 
                   5152:                 goto exec;
                   5153:             
                   5154:             }               /* end of extrinsic function/variable section */
                   5155:         
                   5156:         } 
                   5157:         else if (((ch = *++codptr) >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
                   5158: 
                   5159:             if (ch < 'a') ch += 32;
                   5160: 
                   5161:             tmp[0] = SP;
                   5162:             tmp[1] = f;
                   5163:             tmp[2] = ch;
                   5164:             b = &tmp[3];
                   5165:             
                   5166:             while (((ch = *++codptr) >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) *b++ = ch | 0140;
                   5167: 
                   5168:             *b++ = SP;
                   5169:             *b = EOL;
                   5170:             
                   5171:             if (ch == '(') {        /* function */
                   5172: 
                   5173:                 if (f != 'z') {     /* standard instrinsic functions */
                   5174: 
                   5175:                     if (find (" ascii char data extract find fn fnumber get increment ins instanceof justify length na name next order piece \
                   5176:                     query qlength ql qsubscript qs random re reverse select st stack text tr translate ty type view ", tmp) == FALSE) {
                   5177:                         merr_raise (ILLFUN);
                   5178:                         return;
                   5179:                     }
                   5180: 
                   5181:                     if (f == 'f' && tmp[2] == 'n') f = FNUMBER;
                   5182:                     else if (f == 'q' && tmp[2] == 'l') f = QLENGTH;
                   5183:                     else if (f == 'q' && tmp[2] == 's') f = QSUBSCRIPT;
                   5184:                     else if (f == 'r' && tmp[2] == 'e') f = REVERSE;
                   5185:                     else if (f == 's' && tmp[2] == 't') f = SVNstack;
                   5186:                     else if (f == 't' && tmp[2] == 'r') f = TRANSLATE;
                   5187:                     else if (f == 'n' && tmp[2] == 'a') f = 'N';
                   5188:                     else if (f == 't' && tmp[2] == 'y') f = TYPE;
                   5189:                     else if (f == 'i' && tmp[3] == 's') f = INSTANCEOF;                   
                   5190: 
                   5191:                 } 
                   5192:                 else {
                   5193: 
                   5194:                     /* userdefined intrinsic: process as extrinsic */
                   5195:                     if ((find (zfunctions, tmp) == FALSE) && (tmp[2] != 'f' || tmp[3] != SP)) {
                   5196:                         
                   5197:                         f = stlen (tmp) - 1;
                   5198:                         stcpy (&tmp[f], codptr);
                   5199:                         
                   5200:                         code[0] = '$';
                   5201:                         code[1] = '^';
                   5202:                         code[2] = '%';
                   5203:                         code[3] = 'Z';
                   5204:                         
                   5205:                         stcpy (&code[4], &tmp[2]);
                   5206:                         
                   5207:                         codptr = code;
                   5208:                         f = '$';
                   5209:                         zexflag = TRUE;
                   5210:                         
                   5211:                         goto extra_fun;
                   5212: 
                   5213:                     }
                   5214: 
                   5215:                     f = tmp[2] - 32;
                   5216: 
                   5217:                     if (tmp[3] == SP) {
                   5218: 
                   5219:                         if (f == 'S' && s_fun_flag == FALSE) f = 'o';    /* ZSORT(=$ORDER) instead of ZSYNTAX */
                   5220:                         if (f == 'P' && p_fun_flag == FALSE) f = ZPREVIOUS;  /* ZPREVIOUS instead of ZPIECE */
                   5221:                         if (f == 'D' && d_fun_flag == FALSE) f = ZDATA;  /* ZDATA instead of ZDATE */
                   5222:                         if (f == 'N' && n_fun_flag == FALSE) f = ZNEXT;  /* ZNEXT instead of ZNAME */
                   5223:                         
                   5224:                     } 
                   5225:                     else {
                   5226: 
                   5227:                         switch (f) {
                   5228: 
                   5229: 
                   5230:                             case 'C':
                   5231:                                 if ((stcmp (" zcrc \201", tmp) == 0) ||
                   5232:                                 (stcmp (" zcr \201", tmp) == 0))
                   5233:                                 f = ZCRC;
                   5234:                                 break;
                   5235: 
                   5236: 
                   5237:                             case 'D':
                   5238:                                 if (stcmp (" zdata \201", tmp) == 0)
                   5239:                                 f = ZDATA;
                   5240:                                 break;
                   5241: 
                   5242: 
                   5243:                             case 'L':
                   5244:                                 if (stcmp (" zlsd \201", tmp) == 0)
                   5245:                                 f = ZLSD;
                   5246:                                 break;
                   5247: 
                   5248: 
                   5249:                             case 'N':
                   5250:                                 if (stcmp (" znext \201", tmp) == 0)
                   5251:                                 f = ZNEXT;
                   5252:                                 break;
                   5253: 
                   5254: 
                   5255:                             case 'P':
                   5256:                                 if (stcmp (" zprevious \201", tmp) == 0)
                   5257:                                 f = ZPREVIOUS;
                   5258:                                 break;
                   5259: 
                   5260:                             case 'S':
                   5261:                                 if (stcmp (" zsort \201", tmp) == 0)
                   5262:                                 f = 'o';    /* process $ZSORT as $ORDER */
                   5263:                                 break;
                   5264:                                                         
                   5265: 
                   5266:                         }
                   5267: 
                   5268:                     }
                   5269:                 }
                   5270:             } 
                   5271:             else {            /* special variable */
                   5272: 
                   5273:                 if (f != 'z') {
                   5274:                     
                   5275:                     if (find (" di dialect ec ecode es estack et etrap device horolog io job key pd pdisplay principal quit reference st stack storage sy system test ti timezone tl tlevel tr trollback wi with ", tmp) == FALSE) {
                   5276:                         merr_raise (ILLFUN);
                   5277:                         return;
                   5278:                     }
                   5279: 
                   5280:                     if (f == 's') {
                   5281: 
                   5282:                         if (tmp[2] == 'y') f = SVNsystem;
                   5283:                         if (tmp[2] == 't') f = SVNstack;
                   5284: 
                   5285:                     }
                   5286: 
                   5287:                     if (f == 'd') {
                   5288:                         f = SVNdialect;
                   5289:                     }
                   5290:                     
                   5291:                     if (f == 'e') {
                   5292:                         
                   5293:                         if (tmp[2] == 'c') f = SVNecode;
                   5294:                         if (tmp[2] == 's') f = SVNestack;
                   5295:                         if (tmp[2] == 't') f = SVNetrap;
                   5296: 
                   5297:                     }
                   5298: 
                   5299:                     if (f == 'p' && tmp[2] == 'd') f = SVNpdisplay;                        
                   5300: 
                   5301:                     if (f == 't') {
                   5302:                         
                   5303:                         if (tmp[2] == 'i') f = SVNtimezone;
                   5304:                         if (tmp[2] == 'l') f = SVNtlevel;
                   5305:                         if (tmp[2] == 'r') f = SVNtrollback;
                   5306: 
                   5307:                     }
                   5308: 
                   5309:                 } 
                   5310:                 else {
                   5311: 
                   5312:                     if (find (zsvn, tmp) == FALSE) {
                   5313:                         *(--b) = EOL;   /* there's a SPace we don't need */
                   5314:                         f = ' ';    /* user defined svn */
                   5315:                     } 
                   5316:                     else {
                   5317: 
                   5318:                         f = tmp[2] - 32;
                   5319: 
                   5320:                         if (f == 'T' && tmp[3] == 'r' && (tmp[4] == SP || (stcmp (" ztrap \201", tmp) == 0))) f = ZTRAP;
                   5321: 
                   5322:                         if (f == 'M') { /* loadable match */
                   5323: 
                   5324:                             if ((f = tmp[3]) >= 'a' && f <= 'z') f -= 32;
                   5325: 
                   5326:                             f -= 64;
                   5327: 
                   5328:                         }
                   5329: 
                   5330:                         if (f == 'U' && tmp[3] == 't') f = SVNzut;
                   5331:                             
                   5332:                     }
                   5333:                 }
                   5334:             }
                   5335:         }
                   5336: 
                   5337:         if (ch != '(') {        /* 'special variable' */
                   5338:         
                   5339:             codptr--;
                   5340:         
                   5341:             if (extyp != STRING && extyp != ARGIND && spx == 0) {
                   5342:                 return;
                   5343:             }
                   5344: 
                   5345:             if ((argstck[++arg] = a) >= s) {
                   5346: 
                   5347:                 char   *bak;
                   5348:                 bak = partition;
                   5349: 
                   5350:                 if (getpmore () == 0) {
                   5351:                     merr_raise (STKOV);
                   5352:                     return;
                   5353:                 }
                   5354: 
                   5355:                 a = a - bak + partition;
                   5356:                 b = b - bak + partition;
                   5357: 
                   5358:             }
                   5359: 
                   5360:             /************* special variable evaluation ************************************/
                   5361:             switch (f) {
                   5362: 
                   5363: 
                   5364:                 /* $ZUUID */
                   5365:                 case 'U':
                   5366: 
                   5367:                     uuid_v4 (a);
                   5368:                     stcnv_c2m (a);
                   5369:                     
                   5370:                     goto exec;
                   5371: 
                   5372: #if !defined(__osf__)
                   5373:                 case SVNzut:
                   5374:                 {
                   5375:                     unsigned long long res;
                   5376:                     
                   5377:                     struct timeval tv;
                   5378:                     gettimeofday(&tv, NULL);
                   5379: 
                   5380:                     res = tv.tv_sec * 1000000 + tv.tv_usec;
                   5381: 
                   5382:                     sprintf (a, "%llu\201", res);
                   5383: 
                   5384:                     goto exec;
                   5385:                 }
                   5386: #endif
                   5387:                 
                   5388:                 /* $JOB */
                   5389:                 case 'j':
                   5390: 
                   5391:                     lintstr (a, pid);
                   5392: 
                   5393:                     goto exec;
                   5394: 
                   5395: 
                   5396:                 /* $IO */
                   5397:                 case 'i':
                   5398: 
                   5399:                     intstr (a, io);
                   5400:                     i = stlen (a);
                   5401:                     a[i++] = ':';
                   5402:                     a[i++] = '"';
                   5403:                     i += stcpy (&a[i], dev[io]);
                   5404:                     a[i++] = '"';
                   5405:                     a[i] = EOL;
                   5406: 
                   5407:                     goto exec;
                   5408:                     
                   5409:                 case SVNdialect:
                   5410:                 {
                   5411:                     short rb_slot;
                   5412:                     rb_slot = rbuf_slot_from_name (rou_name);
                   5413: 
                   5414:                     switch (rbuf_flags[rb_slot].dialect) {
                   5415: 
                   5416:                         case D_FREEM:
                   5417:                             sprintf (a, "FREEM\201");
                   5418:                             break;
                   5419:                             
                   5420:                         case D_MDS:
                   5421:                             sprintf (a, "MDS\201");
                   5422:                             break;
                   5423: 
                   5424:                         case D_M77:
                   5425:                             sprintf (a, "M77\201");
                   5426:                             break;
                   5427: 
                   5428:                         case D_M84:
                   5429:                             sprintf (a, "M84\201");
                   5430:                             break;
                   5431: 
                   5432:                         case D_M90:
                   5433:                             sprintf (a, "M90\201");
                   5434:                             break;
                   5435: 
                   5436:                         case D_M95:
                   5437:                             sprintf (a, "M95\201");
                   5438:                             break;
                   5439: 
                   5440:                         case D_M5:
                   5441:                             sprintf (a, "M5\201");
                   5442:                             break;
                   5443:                     }
                   5444: 
                   5445:                     goto exec;
                   5446:                             
                   5447:                 }
                   5448: 
                   5449:                 /* $PDISPLAY */
                   5450:                 case SVNpdisplay:
                   5451: 
                   5452:                     if (getenv ("DISPLAY") != NULL) {
                   5453:                         char *mwapi_display;
                   5454:                         char disp_temp[255];
                   5455: 
                   5456:                         mwapi_display = getenv ("DISPLAY");
                   5457:                         strncpy (disp_temp, mwapi_display, 255);
                   5458:                         stcnv_c2m (disp_temp);
                   5459:                         stcpy (a, disp_temp);
                   5460:                     }
                   5461:                     else {
                   5462:                         intstr (a, 0);
                   5463:                     }
                   5464:                     goto exec;
                   5465: 
                   5466:                 /* $PRINCIPAL */
                   5467:                 case 'p':
                   5468: 
                   5469:                     a[0] = '0';
                   5470:                     a[1] = ':';
                   5471:                     a[2] = '"';
                   5472:                     i = 3 + stcpy (&a[3], dev[HOME]);
                   5473:                     a[i++] = '"';
                   5474:                     a[i] = EOL;
                   5475: 
                   5476:                     goto exec;
                   5477: 
                   5478: 
                   5479:                 /* $QUIT */
                   5480:                 case 'q':
                   5481: 
                   5482:                     a[0] = '0' | (nestc[nstx] == '$');
                   5483: 
                   5484: 
                   5485: 
                   5486:                     a[1] = EOL;
                   5487: 
                   5488:                     goto exec;
                   5489: 
                   5490: 
                   5491:                 /* $TEST */
                   5492:                 case 't':
                   5493:                     
                   5494:                     a[0] = '0' | test;
                   5495:                     a[1] = EOL;
                   5496: 
                   5497:                     goto exec;
                   5498: 
                   5499: 
                   5500:                 /* $HOROLOG */
                   5501:                 case 'h':
                   5502: 
                   5503:                     {
                   5504: 
                   5505:                         unsigned long ilong, ilong1;
                   5506: 
                   5507:                         ilong1 = time (0L) + tzoffset;  /* make $H local time */
                   5508:                         ilong = ilong1 / 86400;
                   5509:                         
                   5510:                         lintstr (a, ilong + 47117);
                   5511:                         i = stlen (a);
                   5512:                         
                   5513:                         a[i++] = ',';
                   5514:                         ilong = ilong1 - (ilong * 86400);
                   5515:                         
                   5516:                         lintstr (&a[i], ilong);
                   5517:                         
                   5518:                         goto exec;
                   5519: 
                   5520:                     }
                   5521: 
                   5522: 
                   5523:                 /* $ZHOROLOG() */
                   5524:                 case 'H':
                   5525:                     {
                   5526: 
                   5527:                         unsigned long ilong, ilong1;
                   5528:                     
                   5529: #if defined(USE_GETTIMEOFDAY) && !defined(__osf__)
                   5530:                     
                   5531:                         struct timeval timebuffer;
                   5532:                         gettimeofday (&timebuffer, NULL);
                   5533:                         
                   5534:                         ilong1 = timebuffer.tv_sec + tzoffset;  /* make $ZH local time */
                   5535:                     
                   5536: #else
                   5537: 
                   5538:                         struct timeb timebuffer;
                   5539:                         ftime (&timebuffer);
                   5540:                         ilong1 = timebuffer.time + tzoffset;    /* make $ZH local time */
                   5541:                     
                   5542: #endif
                   5543:                     
                   5544:                         ilong = ilong1 / 86400;
                   5545:                         lintstr (a, ilong + 47117);
                   5546:                         i = stlen (a);
                   5547:                         a[i++] = ',';
                   5548:                         ilong = ilong1 - (ilong * 86400);
                   5549:                         lintstr (&a[i], ilong);
                   5550: 
                   5551: #if defined(USE_GETTIMEOFDAY) && !defined(__osf__)
                   5552:                         if ((ilong = timebuffer.tv_usec)) 
                   5553: #else
                   5554:                         if ((ilong = timebuffer.millitm)) 
                   5555: #endif
                   5556:                         {
                   5557:                             char doggie_bag[50];
                   5558: 
                   5559:                             snprintf (doggie_bag, 49, ".%ld\201", ilong);
                   5560:                             stcat (a, doggie_bag);
                   5561:                         }
                   5562:                     }
                   5563:                     goto exec;
                   5564: 
                   5565: 
                   5566:                 case SVNsystem:
                   5567: 
                   5568:                     snprintf (a, 512, "%d,\"%s\"\201", MDC_VENDOR_ID, jour_hostid); 
                   5569:                     goto exec;
                   5570: 
                   5571: 
                   5572:                 case SVNtimezone:
                   5573: 
                   5574:                     lintstr (a, tzoffset);
                   5575:                     goto exec;
                   5576: 
                   5577: 
                   5578:                 case SVNtlevel:
                   5579: 
                   5580:                     snprintf (a, 255, "%d\201", tp_level);
                   5581:                     goto exec;
                   5582: 
                   5583: 
                   5584:                 case SVNtrollback:
                   5585: 
                   5586:                     a[0] = '0';
                   5587:                     a[1] = EOL;
                   5588:                     goto exec;
                   5589: 
                   5590: 
                   5591:                 case SVNecode:    
                   5592: 
1.12    ! snw      5593:                     /* write_m ("in SVNecode\r\n\201"); */
1.1       snw      5594: 
                   5595:                     if (stlen (user_ecode)) {
                   5596:                         stcpy (a, user_ecode);
                   5597:                     }
                   5598:                     else {
                   5599:                         stcpy (a, ecode);
                   5600:                     }
                   5601:                     
                   5602:                     goto exec;
                   5603: 
                   5604: 
                   5605:                 case SVNestack:
                   5606:                     {
                   5607:                         char esbuf[256];
                   5608:                         snprintf (esbuf, 255, "%d\201", estack);
                   5609: 
                   5610:                         stcpy (a, esbuf);
                   5611:                         goto exec;
                   5612: 
                   5613:                     }
                   5614: 
                   5615: 
                   5616:                 case SVNetrap:
1.12    ! snw      5617: /*                    write_m ("in SVNetrap\r\n\201"); */
1.1       snw      5618:                     stcpy (a, etrap);
                   5619:                     goto exec;
                   5620: 
                   5621: 
                   5622:                 case SVNstack:
                   5623:                     
                   5624:                     intstr (a, nstx);
                   5625: 
                   5626:                     goto exec;
                   5627: 
                   5628:                    
                   5629:                 /* $KEY */
                   5630:                 case 'k':
                   5631: 
                   5632:                    stcpy (a, zb);
                   5633:                    if (*a >= SP && *a < DEL) *a = EOL;
                   5634: 
                   5635:                    goto exec;
                   5636: 
                   5637:                    
                   5638:                 /* $DEVICE */
                   5639:                 case 'd':
                   5640:                     if (devstat[io].mdc_err == 0) {
                   5641:                         snprintf (a, 3, "0\201\0");              
                   5642:                     }
                   5643:                     else {
                   5644:                         snprintf (a, 120, "%d,%d,%s\201\0", devstat[io].mdc_err, devstat[io].frm_err, devstat[io].err_txt);
                   5645:                     }
                   5646: 
                   5647:                     goto exec;
                   5648:                    
                   5649:                 /* $STORAGE */
                   5650:                 case 's':
1.3       snw      5651:                    snprintf (a, 255 , "%ld\201", DEFPSIZE);
1.1       snw      5652:                    goto exec;
                   5653: 
                   5654:                /* $WITH */
                   5655:                case 'w':
                   5656:                    stcpy (a, i_with);
                   5657:                    goto exec;
                   5658:                    
                   5659:                 /* $X */
                   5660:                 case 'x':
                   5661: 
                   5662:                    intstr (a, xpos[io]);
                   5663:                    goto exec;
                   5664: 
                   5665:                    
                   5666:                 /* $Y */
                   5667:                 case 'y':
                   5668: 
                   5669:                    intstr (a, ypos[io]);
                   5670:                    goto exec;
                   5671: 
                   5672:                    
                   5673:                 /* non-standard special variables */
                   5674: 
                   5675:                 /* $ZA - on HOME device dummy, else byte offset to begin of file */
                   5676:                 case 'A':
                   5677:                    if (io == HOME) {
                   5678:                        a[0] = '0';
                   5679:                        a[1] = EOL;
                   5680:                    }
                   5681:                    else {
                   5682:                        lintstr (a, ftell (opnfile[io]));
                   5683:                    }
                   5684:                    goto exec;
                   5685: 
                   5686:                    
                   5687:                 /* $ZB - last keystroke */
                   5688:                 case 'B':
                   5689:                    stcpy (a, zb);
                   5690:                    goto exec;
                   5691: 
                   5692:                    
                   5693:                 /* $ZCONTROLC flag */
                   5694:                 case 'C':
                   5695:                    a[0] = '0' | zcc;
                   5696:                    zcc = FALSE;
                   5697:                    a[1] = EOL;
                   5698:                    goto exec;
                   5699: 
                   5700: 
1.12    ! snw      5701:                 /* $ZX (number of columns) */
        !          5702:                 case 'X':
        !          5703:                     intstr (a, n_columns);
        !          5704:                     goto exec;
        !          5705: 
        !          5706:                 /* $ZY (number of rows) */
        !          5707:                 case 'Y':
        !          5708:                     intstr (a, n_lines);
        !          5709:                     goto exec;
1.1       snw      5710: 
                   5711:                 /* $ZERROR */
                   5712:                 case 'E':
                   5713:                    stcpy (a, zerror);
                   5714:                    goto exec;
                   5715: 
                   5716:                    
                   5717:                 /* $ZTRAP */
                   5718:                 case ZTRAP:
                   5719: 
                   5720:                    stcpy (a, ztrap[nstx]);
                   5721: 
                   5722:                    goto exec;
                   5723: 
                   5724:                    
                   5725:                 /* $ZPRECISION */
                   5726:                 case 'P':
                   5727:                    intstr (a, zprecise);
                   5728:                    goto exec;
                   5729: 
                   5730:                    
                   5731:                 /* $ZSYSTEM */
                   5732:                 case 'S':
                   5733:                    intstr (a, zsystem);
                   5734:                    goto exec;
                   5735: 
                   5736:                    
                   5737:                 /* $ZVERSION */
                   5738:                 case 'V':
                   5739:                    stcpy (&a[stcpy (a, "FreeM \201")], FREEM_VERSION_STR);
                   5740:                    goto exec;
                   5741: 
                   5742:                    
                   5743:                 /* $ZNAME */
                   5744:                 case 'N':
                   5745:                     /*
                   5746:                    i = 0;
                   5747:                    while ((a[i] = rou_name[i]) != EOL) {
                   5748:                        if (rou_name[i] == '.') break;
                   5749:                        i++;
                   5750:                    }
                   5751:                    a[i] = EOL;
                   5752:                     */
                   5753:                     stcpy (a, rou_name);
                   5754:                    goto exec;
                   5755: 
                   5756:                    
                   5757:                 /* $ZI, INTERRUPT ENABLE/DISABLE */
                   5758:                 case 'I':
                   5759:                    a[0] = '0' | breakon;
                   5760:                    a[1] = EOL;
                   5761:                    goto exec;
                   5762: 
                   5763:                    
                   5764:                 /* $ZDATE */                
                   5765:                 case 'D':
                   5766:                     {
                   5767:                        time_t ilong;
                   5768:                         struct tm *zdate_time;
                   5769:                         char zdf_key[50];
                   5770:                         char fmt_string[128];
                   5771: 
                   5772:                         snprintf (zdf_key, 49, "^$JOB\202%d\202ZDATE_FORMAT\201", pid);
                   5773:                         ssvn (get_sym, zdf_key, fmt_string);
                   5774:                         stcnv_c2m (fmt_string);
                   5775:                         
                   5776:                        ilong = time (0L);                      
                   5777: 
                   5778:                         zdate_time = localtime (&ilong);
                   5779: 
                   5780:                         strftime (a, 255, fmt_string, zdate_time);
                   5781:                         stcnv_c2m (a);                        
                   5782:                    }
                   5783:                    
                   5784:                    goto exec;
                   5785: 
                   5786:                    
                   5787:                 /* $ZTIME */
                   5788:                 case 'T':
                   5789:                     {
                   5790:                        time_t ilong;
                   5791:                         struct tm *zdate_time;
                   5792:                         
                   5793:                        ilong = time (0L);                      
                   5794: 
                   5795:                         zdate_time = localtime (&ilong);
                   5796: 
                   5797:                         strftime (a, 255, "%X", zdate_time);
                   5798:                         stcnv_c2m (a);                        
                   5799:                    }
                   5800:                    
                   5801:                    goto exec;
                   5802: 
                   5803:                    
                   5804:                 /* $ZJOB - value of JOB number (of father process) */
                   5805:                 case 'J':
                   5806:                    if (father) {
                   5807:                        lintstr (a, father);
                   5808:                    }
                   5809:                    else {
                   5810:                        stcpy (a, "\201");
                   5811:                    }
                   5812: 
                   5813:                    goto exec;
                   5814: 
                   5815:                    
                   5816:                 /* $ZORDER - value of physically next global reference @$ZO(@$ZR) */
                   5817:                 case 'O':
                   5818:                    global  (getnext, tmp, a);
                   5819: 
                   5820:                    if (merr () > 0) return;
                   5821: 
                   5822:                    goto exec;
                   5823: 
                   5824:                    
                   5825:                 /* $ZLOCAL - last local reference */
                   5826:                 case 'L':
                   5827:                    zname (a, zloc);
                   5828:                    if (merr () > OK) return;
                   5829: 
                   5830:                    goto exec;
                   5831: 
                   5832:                    
                   5833:                 /* $(Z)REFERENCE - last global reference */
                   5834:                 case 'r':
                   5835:                 case 'R':
                   5836:                    zname (a, zref);
                   5837:                    if (merr () > OK) return;
                   5838: 
                   5839:                    goto exec;
                   5840: 
                   5841:                    
                   5842:                 case 'C' - 64:
                   5843:                    stcpy (a, zmc);
                   5844:                    goto exec;      /* loadable match 'controls' */
                   5845: 
                   5846: 
                   5847:                case 'N' - 64:
                   5848:                    stcpy (a, zmn);
                   5849:                    goto exec;      /* loadable match 'numerics' */
                   5850: 
                   5851: 
                   5852:                case 'P' - 64:
                   5853:                    stcpy (a, zmp);
                   5854:                    goto exec;      /* loadable match 'punctuation' */
                   5855: 
                   5856: 
                   5857:                case 'A' - 64:
                   5858:                    stcpy (a, zmu);
                   5859:                    stcat (a, zml);
                   5860:                    goto exec;      /* loadable match 'alphabetic' */
                   5861: 
                   5862:                    
                   5863:                 case 'L' - 64:
                   5864:                    stcpy (a, zml);
                   5865:                    goto exec;      /* loadable match 'lowercase' */
                   5866: 
                   5867:                    
                   5868:                 case 'U' - 64:
                   5869:                    stcpy (a, zmu);
                   5870:                    goto exec;      /* loadable match 'uppercase' */
                   5871: 
                   5872:                    
                   5873:                 case 'E' - 64:
                   5874:                    for (i = NUL; i <= DEL; i++) a[i] = i;
                   5875:                    a[i] = EOL;
                   5876:                    goto exec;      /* 'loadable' match 'everything' */
                   5877: 
                   5878: 
                   5879:                case ' ':           /* user defined special variable */
                   5880: 
                   5881:                    udfsvn (get_sym, &tmp[2], a);
                   5882: 
                   5883:                    if (ierr <= OK) goto exec;
                   5884: 
                   5885:                    merr_raise (OK);
                   5886: 
                   5887:                     /* if not found in special variable table, process as extrinsic svn */
                   5888:                    /* $$^%Z... all uppercase */
                   5889: 
                   5890:                    f = 2;
                   5891: 
                   5892:                    while ((ch = tmp[f]) != EOL) {
                   5893: 
                   5894:                        if (ch >= 'a' && ch <= 'z') ch -= 32;
                   5895: 
                   5896:                        tmp[f++] = ch;
                   5897:                        
                   5898:                    }
                   5899:                    
                   5900:                    stcat (tmp, ++codptr);
                   5901: 
                   5902:                    code[0] = '$';
                   5903:                    code[1] = '^';
                   5904:                    code[2] = '%';
                   5905:                    code[3] = 'Z';
                   5906: 
                   5907:                    stcpy (&code[4], &tmp[2]);
                   5908: 
                   5909:                    codptr = code;
                   5910:                    f = '$';
                   5911:                    zexflag = TRUE;
                   5912:                    arg--;
                   5913: 
                   5914:                    goto extra_fun;
                   5915: 
                   5916:                 default:
                   5917:                    merr_raise (ILLFUN);
                   5918:                    return;
                   5919:                 }
                   5920:         /* end of specialvariable evaluation */
                   5921:         /******************************************************************************/
                   5922:        }
                   5923:        if (++spx >= PARDEPTH) {
                   5924:            merr_raise (STKOV);
                   5925:            return;
                   5926:        }
                   5927:        op_stck[spx] = f;
                   5928:        op_stck[++spx] = '$';
                   5929: 
                   5930:        
                   5931: text:
                   5932:        if (*(codptr + 1) != '@') {
                   5933:            f = op_stck[spx - 1];
                   5934:            /* f= (spx>0 ? op_stck[spx-1] : 0);
                   5935:             * if (f) */
                   5936: 
                   5937:            switch (f) {
                   5938:                case 't':           /* $TEXT is special */
                   5939: 
                   5940:                    if ((argstck[++arg] = a) >= s) {
                   5941:                        char   *bak;
                   5942: 
                   5943:                        bak = partition;
                   5944:                        if (getpmore () == 0) {
                   5945:                            merr_raise (STKOV);
                   5946:                            return;
                   5947:                        }
                   5948:                        
                   5949:                        a = a - bak + partition;
                   5950:                        b = b - bak + partition;
                   5951:                        
                   5952:                    }
                   5953:                    
                   5954:                    i = 0;
                   5955:                    
                   5956:                    while ((ch = *++codptr) != EOL) {
                   5957: 
                   5958:                        if (ch == ')') break;
                   5959: 
                   5960:                        if (ch == '+') {
                   5961: 
                   5962:                            a[i] = EOL;
                   5963: 
                   5964:                            if (++spx > PARDEPTH) {
                   5965:                                merr_raise (STKOV);
                   5966:                                return;
                   5967:                            }
                   5968:                            
                   5969:                            op_stck[spx] = OPERAND;
                   5970:                            goto comma;
                   5971: 
                   5972:                        }
                   5973: 
                   5974:                        if (ch == '^') {
                   5975:                            
                   5976:                            a[i] = EOL;
                   5977:                            
                   5978:                            if (++spx > PARDEPTH) {
                   5979:                                merr_raise (STKOV);
                   5980:                                return;
                   5981:                            }
                   5982:                            
                   5983:                            op_stck[spx] = OPERAND;
                   5984:                            a += i + 1;
                   5985:                            
                   5986:                            if (i == 0) {
                   5987:                                a[0] = '1';
                   5988:                                a[1] = EOL;
                   5989:                            }                       
                   5990:                            else {
                   5991:                                /* just routine name: */
                   5992:                                /* return first line  */
                   5993: 
                   5994:                                a[0] = EOL;
                   5995: 
                   5996:                            }
                   5997: 
                   5998:                            if ((argstck[++arg] = a) >= s) {
                   5999:                                char   *bak;
                   6000:                                
                   6001:                                bak = partition;
                   6002: 
                   6003:                                if (getpmore () == 0) {
                   6004:                                    merr_raise (STKOV);
                   6005:                                    return;
                   6006:                                }
                   6007:                                
                   6008:                                a = a - bak + partition;
                   6009:                                b = b - bak + partition;
                   6010:                                
                   6011:                            }
                   6012:                            
                   6013:                            if ((spx + 2) > PARDEPTH) {
                   6014:                                merr_raise (STKOV);
                   6015:                                return;
                   6016:                            }
                   6017:                            
                   6018:                            op_stck[++spx] = '$';
                   6019:                            op_stck[++spx] = OPERAND;
                   6020:                            
                   6021:                            goto uparrow;
                   6022:                        }
                   6023:                        
                   6024:                        if ((ch < '0' && ch != '%')     /* illegal character in $TEXT */
                   6025:                            ||ch > 'z' ||
                   6026:                            (ch < 'A' && ch > '9') ||
                   6027:                            (ch < 'a' && ch > 'Z')) {
                   6028: 
                   6029:                            merr_raise (INVREF);
                   6030:                            return;
                   6031:                            
                   6032:                        }
                   6033:                        
                   6034:                        a[i++] = ch;
                   6035: 
                   6036:                    }
                   6037:                    
                   6038:                    a[i] = EOL;
                   6039:                    codptr--;
                   6040:                    
                   6041:                    goto exec;
                   6042: 
                   6043:                case 'd':           /* $data() */
                   6044:                case 'o':           /* $order() */
                   6045:                case 'g':           /* $get() */
                   6046:                case 'n':           /* $next() */
                   6047:                case 'q':           /* $query() */
                   6048:                case 'O':           /* $zorder() */
                   6049:                case 'N':           /* $zname() */
                   6050:                case ZNEXT:     /* $znext() */
                   6051:                case ZPREVIOUS:     /* $zprevious() */
                   6052:                    {
                   6053: 
                   6054:                        if ((ch = *++codptr) >= 'A' && ch <= 'Z')
                   6055:                            goto scan_name;
                   6056: 
                   6057:                        if (ch >= 'a' && ch <= 'z')
                   6058:                            goto scan_name;
                   6059: 
                   6060:                        if (ch == '%' || ch == '^')
                   6061:                            goto scan_name;
                   6062:                        
                   6063:                        merr_raise (INVEXPR);
                   6064:                        
                   6065:                        return;
                   6066:                    }
                   6067:            }
                   6068:        }
                   6069:        
                   6070:        codptr++;
                   6071:        goto nextchr;
                   6072: 
                   6073:        
                   6074:        case ':':
                   6075:            /* colon: $select or delimiter */
                   6076:            if (spx < 2 || op_stck[spx - 2] != 's') {
                   6077:                
                   6078:                if (op_stck[1] == OPERAND && spx == 1)
                   6079:                    return;
                   6080: 
                   6081:                merr_raise (INVEXPR);
                   6082: 
                   6083:                return;
                   6084: 
                   6085:            }
                   6086:            
                   6087:            arg--;
                   6088:            spx--;
                   6089:            
                   6090:            if (tvexpr (a) == FALSE) {  /* skip next expr */
                   6091:                
                   6092:                i = 0;          /* quote */
                   6093:                j = 0;          /* bracket */
                   6094:                
                   6095:                for (;;) {
                   6096:                    
                   6097:                    ch = *++codptr;
                   6098:                    
                   6099:                    if (ch == '"') {
                   6100:                        toggle (i);
                   6101:                        continue;
                   6102:                    }
                   6103:                    
                   6104:                    if (i) {
                   6105:                        
                   6106:                        if (ch != EOL)
                   6107:                            continue;
                   6108: 
                   6109:                        merr_raise (QUOTER);
                   6110:                        return;
                   6111:                        
                   6112:                    }
                   6113:                    
                   6114:                    if (ch == ',' && !j) {
                   6115:                        codptr++;
                   6116:                        goto nextchr;
                   6117:                    }
                   6118:                    
                   6119:                    if (ch == '(') {
                   6120:                        j++;
                   6121:                        continue;
                   6122:                    }
                   6123:                    
                   6124:                    if (ch == ')') {
                   6125:                        
                   6126:                        if (j--)
                   6127:                            continue;
                   6128:                        
                   6129:                        merr_raise (SELER);
                   6130:                        return;
                   6131:                        
                   6132:                    }
                   6133:                    
                   6134:                    if (ch == EOL) {
                   6135:                        merr_raise (SELER);
                   6136:                        return;
                   6137:                    }
                   6138:                    
                   6139:                }
                   6140:            }
                   6141:            
                   6142:            codptr++;
                   6143:            goto nextchr;
                   6144: 
                   6145:     }
                   6146: 
                   6147: m_operator:
                   6148: 
                   6149:     if (extyp == ARGIND && spx == 1 /* && op_stck[2]!='(' */ )
                   6150:        return;
                   6151: 
                   6152:     f = op_stck[spx];
                   6153: 
                   6154:     if (++spx > PARDEPTH) {
                   6155:        merr_raise (STKOV);
                   6156:        return;
                   6157:     }
                   6158: 
                   6159:     
                   6160: op10:              /* entry for shortcut if first operator */
                   6161: 
                   6162:     /* check for NOT_OPERATOR */
                   6163:     if (ch == NOT) {
                   6164:        if (((ch = *++codptr) == '=' || ch == '<' || ch == '>' || ch == '?' || ch == '&' || ch == '!' || ch == '[' || ch == ']')) {
                   6165:            if (ch == ']' && *(codptr + 1) == ch) {
                   6166:                codptr++;
                   6167:                ch = SORTSAFTER;
                   6168:                if (*(codptr+1)=='=') { 
                   6169:                    codptr++; 
                   6170:                    ch=EQSORTS; 
                   6171:                }
                   6172:            }
                   6173:            if (ch == ']' && *(codptr + 1) == '=') {
                   6174:                codptr++;
                   6175:                ch = EQFOLLOWS;
                   6176:            }
                   6177:            if (ch == '!' && *(codptr + 1) == ch) {
                   6178:                codptr++;
                   6179:                ch = XOR;
                   6180:            }
                   6181:            
                   6182:            op_stck[spx] = SETBIT (ch);
                   6183:            if (ch == '?')
                   6184:                goto scan_pattern;
                   6185:            /*                     a+=stlen(a)+1; */
                   6186:            /* djw: does the while loop do the same as the commented out line above? */
                   6187:            /*      we should decide yes or no and get rid of the other code... */
                   6188: 
                   6189:            while (*a++ != EOL);
                   6190:            
                   6191:            codptr++;
                   6192:            goto nextchr;
                   6193:            
                   6194:        }
                   6195:        else {
                   6196:            op_stck[spx] = NOT;
                   6197:            goto nextchr;
                   6198:        }
                   6199:     }
                   6200: 
                   6201:     if (ch == '*' && *(codptr + 1) == ch) {
                   6202:        codptr++;
                   6203:        ch = POWER;
                   6204:     }
                   6205:     
                   6206:     if (ch == ']' && *(codptr + 1) == ch) {
                   6207:        codptr++;
                   6208:        ch = SORTSAFTER;
                   6209:     }
                   6210:     
                   6211:     if (ch == '<' && *(codptr + 1) == '=') {
                   6212:        codptr++;
                   6213:        ch = SETBIT ('>');
                   6214:     }
                   6215:     
                   6216:     if (ch == '>' && *(codptr + 1) == '=') {
                   6217:        codptr++;
                   6218:        ch = SETBIT ('<');
                   6219:     }
                   6220:     
                   6221:     if (ch == ']' && *(codptr + 1) == '=') {
                   6222:        codptr++;
                   6223:        ch = EQFOLLOWS;
                   6224:     }
                   6225:     
                   6226:     if (ch == SORTSAFTER && *(codptr + 1) == '=') {
                   6227:        codptr++;
                   6228:        ch = EQSORTS;
                   6229:     }
                   6230:     
                   6231:     if (ch == '$')
                   6232:        ch = MAXOP;
                   6233:     
                   6234:     if (ch == '^') {
                   6235:        codptr--;
                   6236:        return;
                   6237:     }
                   6238: 
                   6239:     if ((op_stck[spx] = ch) != PATTERN) {
                   6240: 
                   6241:        if (f == OPERAND) while (*a++ != EOL);       /* binary operator */
                   6242: 
                   6243:        codptr++;
                   6244:        goto nextchr;
                   6245:     }
                   6246:     
                   6247: scan_pattern:
                   6248:     if ((ch = *++codptr) == INDIRECT) { /*  a+=stlen(a)+1;  */
                   6249:        while (*a++ != EOL) ;
                   6250:        goto m_operator;
                   6251:     }
                   6252:     
                   6253:     if ((ch > '9' || ch < '0') && (ch != '.')) {
                   6254:        merr_raise (INVEXPR);
                   6255:        return;
                   6256:     }
                   6257:     
                   6258:     tmp[0] = ch;
                   6259:     i = 1;
                   6260:     f = '1';                /* 'previous' character */
                   6261:     j = 0;              /* point flag */
                   6262:     group = 0;              /* grouped pattern match */
                   6263: 
                   6264:     while ((ch = *++codptr) != EOL) {
                   6265: 
                   6266:        if ((ch >= '0') && (ch <= '9')) {
                   6267: 
                   6268:            tmp[i++] = ch;
                   6269:            f = '1';
                   6270: 
                   6271:            continue;
                   6272:            
                   6273:        }
                   6274:        
                   6275:     if (ch == '.') {
                   6276: 
                   6277:        if (j) {
                   6278:            merr_raise (INVEXPR);
                   6279:            return;
                   6280:        }
                   6281:        
                   6282:        j++;
                   6283:        tmp[i++] = ch;
                   6284:        f = '1';
                   6285:        
                   6286:        continue;
                   6287:     }
                   6288:     
                   6289:     j = 0;
                   6290:     if (ch == NOT) {        /* negation of pattern class ? */
                   6291: 
                   6292:        ch = *(codptr + 1);
                   6293: 
                   6294:        if ((ch == '"') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
                   6295:            tmp[i++] = NOT;
                   6296:        }
                   6297:        else {
                   6298:            ch = NOT;
                   6299:        }
                   6300: 
                   6301:     }
                   6302: 
                   6303:     if (ch == '"') {
                   6304: 
                   6305:        if (f != '1' && f != 'A') {
                   6306:            merr_raise (INVEXPR);
                   6307:            return;
                   6308:        }
                   6309:        
                   6310:        for (;;) {
                   6311:            
                   6312:            tmp[i++] = ch;
                   6313: 
                   6314:            if ((ch = *++codptr) == EOL) {
                   6315:                merr_raise (QUOTER);
                   6316:                return;
                   6317:            }
                   6318:            
                   6319:            if (ch == '"') {
                   6320:                
                   6321:                if ((f = *(codptr + 1)) != '"') {
                   6322:                    ch = DELIM;
                   6323:                    break;
                   6324:                }
                   6325:                
                   6326:                codptr++;
                   6327:            }
                   6328:        }
                   6329:        
                   6330:        tmp[i++] = ch;
                   6331:        f = '"';
                   6332:        
                   6333:        continue;
                   6334:        
                   6335:     }
                   6336:     
                   6337:     if (ch == '(') {
                   6338: 
                   6339:        if (f != '1') {
                   6340:            merr_raise (INVEXPR);
                   6341:            return;
                   6342:        }
                   6343:        
                   6344:        group++;
                   6345:        f = '(';
                   6346:        tmp[i++] = ch;
                   6347:        
                   6348:        continue;
                   6349:        
                   6350:     }
                   6351:     
                   6352:     if (group && (ch == ',' || ch == ')')) {
                   6353: 
                   6354:        if ((f == '1') || (f == '(')) {
                   6355:            merr_raise (INVEXPR);
                   6356:            return;
                   6357:        }
                   6358:        
                   6359:        if (ch == ',') {
                   6360: 
                   6361:            f = '(';
                   6362:            tmp[i++] = ch;
                   6363:            
                   6364:            continue;
                   6365: 
                   6366:        }
                   6367:        
                   6368:     if (ch == ')') {
                   6369:        group--;
                   6370:        tmp[i++] = ch;
                   6371: 
                   6372:        continue;
                   6373:     }
                   6374:     
                   6375:     } /* ??? formatting ??? */
                   6376:     
                   6377:     if (ch >= 'A' && ch <= 'Z') ch += 32;           /* lower case conversion */
                   6378: 
                   6379:     if (ch == 'z') {        /* loadable match, store as uppercase chars */
                   6380: 
                   6381:        if (standard) {
                   6382:            merr_raise (NOSTAND);
                   6383:            return;
                   6384:        }
                   6385:        
                   6386:        ch = *++codptr;
                   6387: 
                   6388:        if (ch == '"') {
                   6389:            
                   6390:            if (f != '1') {
                   6391:                merr_raise (INVEXPR);
                   6392:                return;
                   6393:            }
                   6394:            
                   6395:            codptr--;
                   6396:            tmp[i++] = 'z';
                   6397:            
                   6398:            continue;
                   6399:            
                   6400:        }
                   6401:        
                   6402:        if (ch == '(') {
                   6403: 
                   6404:            if (f != '1') {
                   6405:                merr_raise (INVEXPR);
                   6406:                return;
                   6407:            }
                   6408:            
                   6409:            codptr--;
                   6410:            continue;
                   6411:        }
                   6412:        
                   6413:        if (ch >= 'A' && ch <= 'Z') ch += 32;       /* lower case conversion */
                   6414: 
                   6415:        if (ch != 'e')
                   6416:            j = 1;          /* process 'ze' as 'e' */
                   6417:     }
                   6418: 
                   6419:     if (ch != 'c' && ch != 'n' &&  ch != 'p' && ch != 'a' && ch != 'l' && ch != 'u' && ch != 'e') break;
                   6420: 
                   6421:     if ((f != '1') && (f != 'A')) {
                   6422:        merr_raise (INVEXPR);
                   6423:        return;
                   6424:     }
                   6425:     
                   6426:     if (j) {
                   6427:        ch -= 32;
                   6428:        j = 0;
                   6429:     }
                   6430:     
                   6431:     tmp[i++] = ch;
                   6432:     f = 'A';
                   6433: 
                   6434:     }
                   6435: 
                   6436:     if ((f == '1') || group) {
                   6437:        merr_raise (INVEXPR);
                   6438:        return;
                   6439:     }
                   6440:     
                   6441:     tmp[i] = EOL;
                   6442: 
                   6443:     if ((*a = pattern (a, tmp)) > '1') {
                   6444:        merr_raise (INVEXPR);
                   6445:        return;
                   6446:     }
                   6447:     
                   6448:     if (UNSIGN (op_stck[spx--]) & 0200) toggle (*a);
                   6449:     
                   6450:     *(a + 1) = EOL;
                   6451: 
                   6452:     goto next10;
                   6453: 
                   6454:     /* process values on stack */
                   6455: 
                   6456:     
                   6457: exec:
                   6458: 
                   6459:     if (spx == 0) {
                   6460: 
                   6461:        if ((ch = *++codptr) == EOL || ch == SP || ch == ',' || ch == ':' || (ch == '^' && (extyp == LABEL || extyp == OFFSET))) return;
                   6462: 
                   6463:        op_stck[++spx] = OPERAND;
                   6464: 
                   6465:        goto next10;
                   6466: 
                   6467:     }
                   6468: 
                   6469:     f = op_stck[spx];
                   6470: 
                   6471:     if (f == ARRAY || f == '(') {
                   6472: 
                   6473:        if (++spx > PARDEPTH) {
                   6474:            merr_raise (STKOV);
                   6475:            return;
                   6476:        }
                   6477:        
                   6478:        op_stck[spx] = OPERAND;
                   6479:        codptr++;
                   6480:        
                   6481:        goto nextchr;
                   6482:        
                   6483:     }
                   6484:     
                   6485:     /* process operators */
                   6486: 
                   6487: nxt_expr:
                   6488: 
                   6489:     if (f == '$') {         /* push 'OPERAND' on stack */
                   6490:        
                   6491:        op_stck[++spx] = OPERAND;
                   6492:        codptr++;
                   6493: 
                   6494:        goto nextchr;
                   6495:        
                   6496:     }
                   6497:     
                   6498:     if (f == OPERAND) {
                   6499:        merr_raise (MISSOP);
                   6500:        return;
                   6501:     }
                   6502:     
                   6503:     if (op_stck[--spx] == OPERAND) {    /* binary operators */
                   6504: 
                   6505:        b = a;
                   6506:        a = argstck[--arg];
                   6507: 
                   6508:        switch (f & 0177) {     /* binary operators, NOT OMITTED */
                   6509: 
                   6510:            case PLUS:
                   6511: 
                   6512:                stcpy (tmp, b);
                   6513: 
                   6514: plus01:
                   6515: 
                   6516:                atyp = numlit (a);
                   6517:                btyp = numlit (tmp);
                   6518:                
                   6519: #ifdef EUR2DEM
                   6520:                
                   6521:                if (atyp != btyp) {
                   6522: 
                   6523:                    char    tmp2[256];
                   6524: 
                   6525:                    if ((atyp == 0) && (a[0] == '0')) atyp = btyp;    /* zero is any currency */
                   6526:                    if ((btyp == 0) && (tmp[0] == '0')) btyp = atyp;    /* zero is any currency */
                   6527: 
                   6528:                    if (atyp && btyp) {
                   6529:                        
                   6530:                        if (atyp > 1) {
                   6531:                            stcpy (tmp2, EUR2WHR[atyp]);
                   6532:                            mul (tmp, tmp2);
                   6533:                        }
                   6534:                        
                   6535:                        if (btyp > 1) {
                   6536:                            zprecise += 4;
                   6537:                            stcpy (tmp2, EUR2WHR[btyp]);
                   6538:                            mdiv (tmp, tmp2, '/');
                   6539:                            zprecise -= 4;
                   6540:                        }
                   6541:                        
                   6542:                    }
                   6543:                    else if (atyp != btyp && typemmflag) {
                   6544:                        merr_raise (TYPEMISMATCH);
                   6545:                        return;
                   6546:                    }
                   6547:                    
                   6548:                }
                   6549:                
                   6550: #endif /* EUR2DEM */
                   6551:                
                   6552:                add (a, tmp);
                   6553: plus02:
                   6554: 
                   6555: #ifdef EUR2DEM
                   6556: 
                   6557:                if (atyp == 0) goto next05;
                   6558:                if (atyp != btyp) cond_round (a, zprecise + 2);
                   6559:                
                   6560:                stcat (a, WHR[atyp]);
                   6561: 
                   6562: #endif /* EUR2EUR */
                   6563: 
                   6564:                goto next05;
                   6565: 
                   6566:                
                   6567:            case MINUS:
                   6568: 
                   6569:                tmp[0] = '-';
                   6570:                stcpy (&tmp[1], b);
                   6571:                goto plus01;
                   6572: 
                   6573:                
                   6574:            case MULTIPLY:
                   6575: 
                   6576:                stcpy (tmp, b);
                   6577:                atyp = numlit (a);
                   6578:                btyp = numlit (tmp);
                   6579: #ifdef EUR2DEM
                   6580:                if (btyp && (atyp == 0)) {
                   6581:                    atyp = btyp;
                   6582:                    btyp = 0;
                   6583:                }
                   6584:                
                   6585:                if (atyp && btyp) {
                   6586: 
                   6587:                    if (typemmflag) {
                   6588:                        merr_raise (TYPEMISMATCH);
                   6589:                        return;
                   6590:                    }
                   6591:                    
                   6592:                    atyp = btyp = 0;
                   6593:                    
                   6594:                }
                   6595:                
                   6596: #endif /* EUR2DEM */
                   6597: 
                   6598:                mul (a, tmp);
                   6599: 
                   6600: #ifdef EUR2DEM
                   6601:                
                   6602:                if (atyp == 0) goto next05;
                   6603: 
                   6604:                cond_round (a, zprecise + 2);
                   6605:                stcat (a, WHR[atyp]);
                   6606:                
                   6607: #endif /* EUR2DEM */
                   6608: 
                   6609:                goto next05;
                   6610: 
                   6611:                
                   6612:            case DIVIDE:
                   6613:            case INTDIVIDE:
                   6614:            case MODULO:
                   6615: 
                   6616:                stcpy (tmp, b);
                   6617:                atyp = numlit (a);
                   6618:                btyp = numlit (tmp);
                   6619: 
                   6620: #ifdef EUR2DEM
                   6621:                if (atyp != btyp) {
                   6622:                     char    tmp2[256];
                   6623: 
                   6624:                     if (atyp && btyp) {
                   6625:                         
                   6626:                         if (f == MODULO) {
                   6627: 
                   6628:                             if (atyp > 1) {
                   6629:                                 stcpy (tmp2, EUR2WHR[atyp]);
                   6630:                                 mul (tmp, tmp2);
                   6631:                             }
                   6632: 
                   6633:                             if (btyp > 1) {
                   6634:                                 stcpy (tmp2, EUR2WHR[btyp]);
                   6635:                                 mdiv (tmp, tmp2, '/');
                   6636:                             }
                   6637:                             
                   6638:                         }
                   6639:                         else {
                   6640:                             
                   6641:                             if (atyp > 1) {
                   6642:                                 stcpy (tmp2, EUR2WHR[atyp]);
                   6643:                                 mul (tmp, tmp2);
                   6644:                             }
                   6645: 
                   6646:                             if (btyp > 1) {
                   6647:                                 stcpy (tmp2, EUR2WHR[btyp]);
                   6648:                                 mul (a, tmp2);
                   6649:                             }
                   6650: 
                   6651:                             atyp = btyp = 0;
                   6652: 
                   6653:                         }
                   6654:                         
                   6655:                     } else if (btyp && typemmflag && (*a != '0' || f == MODULO)) {
                   6656:                         merr_raise (TYPEMISMATCH);                        
                   6657:                         return;
                   6658:                     }
                   6659:                 }
                   6660:                 else if (f != MODULO) {
                   6661:                     atyp = 0;
                   6662:                 }
                   6663:                 
                   6664: #endif /* EUR2DEM */
                   6665:                 
                   6666:                 if (tmp[0] == '0') {
                   6667:                     merr_raise (M9);
                   6668:                     return;
                   6669:                 }
                   6670:                 
                   6671:                 if (atyp != btyp) zprecise += 4;
                   6672:                 
                   6673:                 mdiv (a, tmp, f);
                   6674: 
                   6675:                 if (atyp != btyp) zprecise -= 4;
                   6676: 
                   6677:                 goto plus02;
                   6678: 
                   6679:                 
                   6680:             case CONCATENATE:
                   6681: 
                   6682:                 if (stcat (a, b)) goto next05;
                   6683:                 
                   6684:                 merr_raise (M75);
                   6685:                 return;
                   6686: 
                   6687:                 
                   6688:             case EQUAL:
                   6689: 
                   6690:                 if (stcmp (a, b)) {
                   6691:                     *a = '0';
                   6692:                 }
                   6693:                 else {
                   6694:                     *a = '1';
                   6695:                 }
                   6696:                 
                   6697:                 /* common entry point to reverse the logical value */
                   6698:                 /* of current expression               */
                   6699: 
                   6700: 
                   6701: notop:
                   6702:                 if (f & 0200) toggle (*a);        /* NOT_OPERAND */
                   6703: 
                   6704:                 a[1] = EOL;
                   6705:                 
                   6706:                 goto next05;
                   6707: 
                   6708:                 
                   6709:             case GREATER:
                   6710: 
                   6711:                 stcpy (tmp, b);
                   6712:                 atyp = numlit (a);
                   6713:                 btyp = numlit (tmp);
                   6714:                 
                   6715: #ifdef EUR2DEM
                   6716:                 if (atyp != btyp) {
                   6717:                     char tmp2[256];
                   6718: 
                   6719:                     if ((atyp == 0) && (a[0] == '0')) atyp = btyp;    /* zero is any currency */
                   6720:                     if ((btyp == 0) && (tmp[0] == '0')) btyp = atyp;    /* zero is any currency */
                   6721: 
                   6722:                     if (atyp && btyp) {
                   6723:                         
                   6724:                         if (atyp > 1) {
                   6725:                             stcpy (tmp2, EUR2WHR[atyp]);
                   6726:                             mul (tmp, tmp2);
                   6727:                         }
                   6728:                         
                   6729:                         if (btyp > 1) {
                   6730:                             stcpy (tmp2, EUR2WHR[btyp]);
                   6731:                             mul (a, tmp2);
                   6732:                         }
                   6733:                         
                   6734:                         cond_round (a, zprecise + 2);
                   6735:                         cond_round (tmp, zprecise + 2);
                   6736:                         
                   6737:                     }
                   6738:                     else if (atyp != btyp && typemmflag) {
                   6739:                         merr_raise (TYPEMISMATCH);
                   6740:                         return;
                   6741:                     }
                   6742:                 }
                   6743: #endif /* EUR2DEM */
                   6744:                 
                   6745:                 if (comp (tmp, a)) {
                   6746:                     *a = '1';
                   6747:                 }
                   6748:                 else {
                   6749:                     *a = '0';
                   6750:                 }
                   6751:                 
                   6752:                 goto notop;
                   6753: 
                   6754:                 
                   6755:             case LESS:
                   6756: 
                   6757:                 stcpy (tmp, b);
                   6758:                 atyp = numlit (a);
                   6759:                 btyp = numlit (tmp);
                   6760: 
                   6761: #ifdef EUR2DEM
                   6762:                 if (atyp != btyp) {
                   6763:                     char tmp2[256];
                   6764: 
                   6765:                     if ((atyp == 0) && (a[0] == '0')) atyp = btyp;    /* zero is any currency */
                   6766:                     if ((btyp == 0) && (tmp[0] == '0')) btyp = atyp;    /* zero is any currency */
                   6767: 
                   6768:                     if (atyp && btyp) {
                   6769: 
                   6770:                         if (atyp > 1) {
                   6771:                             stcpy (tmp2, EUR2WHR[atyp]);
                   6772:                             mul (tmp, tmp2);
                   6773:                         }
                   6774: 
                   6775:                         if (btyp > 1) {
                   6776:                             stcpy (tmp2, EUR2WHR[btyp]);
                   6777:                             mul (a, tmp2);
                   6778:                         }
                   6779: 
                   6780:                         cond_round (a, zprecise + 2);
                   6781:                         cond_round (tmp, zprecise + 2);
                   6782:                         
                   6783:                     }
                   6784:                     else if (atyp != btyp && typemmflag) {
                   6785:                         merr_raise (TYPEMISMATCH);
                   6786:                         return;
                   6787:                     }
                   6788:                     
                   6789:                 }
                   6790:                 
                   6791: #endif /* EUR2DEM */
                   6792:                 if (comp (a, tmp)) {
                   6793:                     *a = '1';
                   6794:                 }
                   6795:                 else {
                   6796:                     *a = '0';
                   6797:                 }
                   6798:                 
                   6799:                 goto notop;
                   6800: 
                   6801:                 
                   6802:             case AND:
                   6803: 
                   6804:                 if (tvexpr (a)) {
                   6805:                     tvexpr (b);
                   6806:                     *a = *b;
                   6807:                 }
                   6808:                 
                   6809:                 goto notop;
                   6810: 
                   6811:                 
                   6812:             case OR:
                   6813: 
                   6814:                 ch = tvexpr (b);        /* beware case of a="" */
                   6815:                 
                   6816:                 if (tvexpr (a) == FALSE && ch) *a = '1';
                   6817:                 
                   6818:                 goto notop;
                   6819: 
                   6820:                 
                   6821:             case XOR:
                   6822:                 
                   6823:                 ch = tvexpr (b);            /* beware case of a="" */
                   6824:                 *a = (tvexpr(a) == ch) ? '0' : '1';
                   6825: 
                   6826:                 goto notop;
                   6827: 
                   6828:                 
                   6829:             case CONTAINS:
                   6830: 
                   6831:                 if (*b == EOL || find (a, b)) {
                   6832:                     *a = '1';
                   6833:                 }
                   6834:                 else {
                   6835:                     *a = '0';
                   6836:                 }
                   6837:                 
                   6838:                 goto notop;     
                   6839: 
                   6840:                 
                   6841:             case EQFOLLOWS:
                   6842:                 
                   6843:                 if (stcmp (a, b) == 0) {
                   6844:                     a[0] = '1';
                   6845:                     goto notop;
                   6846:                 }
                   6847: 
                   6848:                 
                   6849:             case FOLLOWS:
                   6850: 
                   6851:                 if (*b == EOL) {
                   6852: 
                   6853:                     if (*a == EOL) {
                   6854:                         *a = '0';
                   6855:                     }
                   6856:                     else {
                   6857:                         *a = '1';
                   6858:                     }
                   6859:                     
                   6860:                 }               
                   6861:                 else if (stcmp (a, b) <= 0) {     /* frequent special case */
                   6862:                     *a = '0';
                   6863:                 }
                   6864:                 else {
                   6865:                     *a = '1';
                   6866:                 }
                   6867:                 
                   6868:                 goto notop;
                   6869: 
                   6870:                 
                   6871:             case POWER:
                   6872: 
                   6873:                 stcpy (tmp, b);
                   6874:                 numlit (a);
                   6875:                 numlit (tmp);
                   6876:                 power (a, tmp);
                   6877:                 goto next05;
                   6878: 
                   6879:                 
                   6880:             case EQSORTS:
                   6881:                 
                   6882:                 if (stcmp (a, b) == 0) {
                   6883:                     a[0] = '1';
                   6884:                     goto notop;
                   6885:                 }
                   6886: 
                   6887:                 
                   6888:             case SORTSAFTER:
                   6889: 
                   6890:                 if (collate (b, a)) {
                   6891:                     *a = '1';
                   6892:                 }
                   6893:                 else {
                   6894:                     *a = '0';
                   6895:                 }
                   6896:                 
                   6897:                 goto notop;
                   6898: 
                   6899:                 
                   6900:             case MAXOP:
                   6901: 
                   6902: #ifdef NOSCRAMBL
                   6903:                 if (standard) {
                   6904:                     merr_raise (NOSTAND);
                   6905:                     return;
                   6906:                 }                
                   6907: #endif /* NOSCRAMBL */
                   6908:                 
                   6909:                 stcpy (tmp, b);
                   6910:                 numlit (tmp);
                   6911:                 numlit (a);
                   6912:                 
                   6913:                 if (comp (a, tmp)) stcpy (a, tmp);
                   6914:                 
                   6915:                 goto next05;
                   6916: 
                   6917:                 
                   6918:             case MINOP:
                   6919: 
                   6920: #ifdef NOSCRAMBL
                   6921:                 if (standard) {
                   6922:                     merr_raise (NOSTAND);
                   6923:                     return;
                   6924:                 }                
                   6925: #endif /* NOSCRAMBL */
                   6926: 
                   6927:                 stcpy (tmp, b);
                   6928:                 numlit (tmp);
                   6929:                 numlit (a);
                   6930:                 
                   6931:                 if (comp (a, tmp) == 0) stcpy (a, tmp);
                   6932:                 
                   6933:                 goto next05;
                   6934: 
                   6935:                 
                   6936:             default:
                   6937:                 merr_raise (ILLOP);
                   6938:                 return;
                   6939: 
                   6940:         }
                   6941:     }                   /* end binary operators */
                   6942: 
                   6943:     switch (f) {
                   6944: 
                   6945:         case INDIRECT:
                   6946: 
                   6947: 
                   6948: indirect:
                   6949: 
                   6950:             if (*++codptr == '@' && *(codptr + 1) == '(') {
                   6951: 
                   6952:                 if (a[stlen (a) - 1] == ')') {
                   6953:                     codptr += 2;
                   6954:                     a[stlen (a) - 1] = ',';
                   6955:                 }
                   6956:                 else {
                   6957:                     codptr++;
                   6958:                 }
                   6959: 
                   6960:             }
                   6961:             
                   6962:             stcpy (a + stlen (a), codptr);
                   6963:             stcpy (&code[1], a);
                   6964:             codptr = code;
                   6965:             *codptr = SP;
                   6966:             arg--;
                   6967:             
                   6968:             if (spx <= 0) {
                   6969:                 op_stck[0] = 0;
                   6970:                 codptr++;
                   6971: 
                   6972:                 goto nextchr;
                   6973:             }
                   6974:             
                   6975:             if ((op_stck[spx] & 0177) != PATTERN) goto text;
                   6976: 
                   6977:             a = argstck[arg];
                   6978:             goto scan_pattern;
                   6979: 
                   6980:             
                   6981:         case MINUS:         /* unary minus */
                   6982: 
                   6983:             b = a + stlen (a) + 1;
                   6984: 
                   6985:             while (b > a) {
                   6986:                 *b = *(b - 1);
                   6987:                 b--;
                   6988:             }
                   6989:             
                   6990:             *a = '-';
                   6991: 
                   6992:             
                   6993:         case PLUS:              /* unary plus */
                   6994: 
                   6995:             atyp = numlit (a);
                   6996:             
                   6997: #ifdef EUR2DEM
                   6998:             if (atyp) {
                   6999:                 stcat (a, WHR[atyp]);
                   7000:             }
                   7001: #endif /* EUR2DEM */
                   7002:             goto nxt_operator;
                   7003: 
                   7004:             
                   7005:         case NOT:               /* unary not */
                   7006: 
                   7007:             tvexpr (a);
                   7008:             toggle (*a);
                   7009:             
                   7010:             goto nxt_operator;
                   7011: 
                   7012:             
                   7013:         default:
                   7014:             merr_raise (MISSOPD);
                   7015:             return;
                   7016:             
                   7017:     }                   /* end unary operators */
                   7018: 
                   7019:     
                   7020: }                   /* end expr() */
                   7021: 
                   7022: 
                   7023: /******************************************************************************/
                   7024: /* $ZSYNTAX */
                   7025: /* a simple syntax check.                                    */
                   7026: /* $ZSYNTAX expects one argument. If it finds no fault, it   */
                   7027: /* returns an empty string. Otherwise it returns a pair of   */
                   7028: /* integers separated by a comma. The first number indicates */
                   7029: /* the position where the error has been found. The second   */
                   7030: /* number returns an error code (same meaning as in $ZE)     */
                   7031: /* only the most frequent errors are searched for:           */
                   7032: /* - illegal commands                                        */
                   7033: /* - not matching brackets                                   */
                   7034: /* - not matching quotes                                     */
                   7035: /* - missing or surplus arguments                            */
                   7036: /* - surplus commata                                         */
                   7037: 
                   7038: void zsyntax(char *a)
                   7039: {
                   7040:     register int i;
                   7041:     register int j;
                   7042:     register int f;
                   7043:     register int ch;
                   7044:     
                   7045:     char    tmp[256];
                   7046:     char   *b;
                   7047:     short   cmnd;
                   7048:     short   forline;            /* flag: FOR encountered */
                   7049: 
                   7050:     b = a;
                   7051:     forline = FALSE;
                   7052:     while ((ch = *b) == '.' || ch == SP)
                   7053:         b++;                /* level points for blockstr. */
                   7054:     while ((ch = *b++) != EOL) {    /* scan command */
                   7055:         if (ch == ';' || ch == '!')
                   7056:             break;          /* comment or unix_call */
                   7057:         if (ch >= 'A' && ch <= 'Z')
                   7058:             ch += 32;           /* uppercase to lowercase */
                   7059:         f = ch;
                   7060:         cmnd = f;
                   7061:         if (ch < 'b' || ch > 'z' || /* illegal char in cmmd position */
                   7062:             ch == 'm' || ch == 't' || ch == 'y') {
                   7063:             j = CMMND;
                   7064: 
                   7065:             
                   7066: zserr:
                   7067: 
                   7068:             intstr (a, b - a);
                   7069:             a[i = stlen (a)] = ',';
                   7070: 
                   7071:             merr_num_to_code (j, &a[++i]);
                   7072:             stcnv_c2m (a);
                   7073:             
                   7074:             return;
                   7075:         }
                   7076:         i = 1;
                   7077:         while (((tmp[++i] = ch = *b++) != EOL) &&   /* check full command name */
                   7078:                ((ch >= 'A' && ch <= 'Z') ||
                   7079:                 (ch >= 'a' && ch <= 'z')))
                   7080:             if (ch < 'a')
                   7081:                 tmp[i] = ch + 32;
                   7082:         if (f != 'z') {
                   7083:             if (i > 2) {
                   7084:                 tmp[0] = SP;
                   7085:                 tmp[1] = f;
                   7086:                 tmp[i] = SP;
                   7087:                 tmp[++i] = EOL;
                   7088:                 if (find (
                   7089:                         " break close do else for goto hang halt if job kill lock new open quit read set use view write xecute "
                   7090:                         ,tmp) == FALSE) {
                   7091:                     j = CMMND;
                   7092:                     goto zserr;
                   7093:                 }
                   7094:             }
                   7095:         }
                   7096:         i = 0;              /* quote */
                   7097:         j = 0;              /* bracket */
                   7098:         if (ch == ':') {        /*  scan postcond */
                   7099:             while ((ch = *b++) != EOL) {
                   7100:                 if (ch == '*' && *b == ch)
                   7101:                     b++;        /* exponentiation */
                   7102:                 if (ch == '!' && *b == ch)
                   7103:                     b++;                /* XOR */
                   7104:                 if (ch == ']') {
                   7105:                     if (*b == ch)
                   7106:                         b++;        /* SORTSAFTER */
                   7107:                     if (*b == '=')
                   7108:                         b++;        /* EQFOLLOWS or EQSORTS */
                   7109:                 }
                   7110:                 if (ch == '"') {
                   7111:                     toggle (i);
                   7112:                     continue;
                   7113:                 }
                   7114:                 if (i)
                   7115:                     continue;
                   7116:                 if (ch == SP)
                   7117:                     break;
                   7118:                 if (ch == '$') {
                   7119:                     ch = *b++;
                   7120:                     if (ch >= 'A' && ch <= 'Z')
                   7121:                         ch += 32;
                   7122:                     if ((ch < 'a' || ch > 'z' || ch == 'b' ||
                   7123:                          ch == 'm' || ch == 'u' || ch == 'w') && ch != '$') {
                   7124:                         j = ILLFUN;
                   7125:                         goto zserr;
                   7126:                     }
                   7127:                     if (ch == 's') {    /* $SELECT */
                   7128:                         int     xch,
                   7129:                             xi,
                   7130:                             xj;
                   7131:                         char   *xb;
                   7132:                         int     sfl;
                   7133:                         
                   7134:                         xi = 0;     /* quotes */
                   7135:                         xj = 0;     /* brackets */
                   7136:                         xb = b;     /* do not change old 'b' pointer */
                   7137:                         sfl = TRUE; /* first ':' expected */
                   7138:                         for (;;)
                   7139:                         {
                   7140:                             if ((xch = *xb++) == EOL ||
                   7141:                                 ((xch == SP || xch == ',') && xj == 0)) {
                   7142:                                 if (xj == 0)
                   7143:                                     break;  /* $STORAGE */
                   7144:                                 j = SELER;
                   7145:                                 b = xb;
                   7146:                                 goto zserr;
                   7147:                             }
                   7148:                             if (xch == '"') {
                   7149:                                 toggle (xi);
                   7150:                                 continue;
                   7151:                             }
                   7152:                             if (xi)
                   7153:                                 continue;
                   7154:                             if (xch == ':') {
                   7155:                                 if (xj > 1)
                   7156:                                     continue;
                   7157:                                 if (sfl) {
                   7158:                                     sfl = FALSE;
                   7159:                                     continue;
                   7160:                                 }
                   7161:                                 j = SELER;
                   7162:                                 b = xb;
                   7163:                                 goto zserr;
                   7164:                             }
                   7165:                             if (xch == ',') {
                   7166:                                 if (xj > 1)
                   7167:                                     continue;
                   7168:                                 if (!sfl) {
                   7169:                                     sfl = TRUE;
                   7170:                                     continue;
                   7171:                                 }
                   7172:                                 j = SELER;
                   7173:                                 b = xb;
                   7174:                                 goto zserr;
                   7175:                             }
                   7176:                             if (xch == '(') {
                   7177:                                 xj++;
                   7178:                                 continue;
                   7179:                             }
                   7180:                             if (xch == ')') {
                   7181:                                 if ((xj--) > 1)
                   7182:                                     continue;
                   7183:                                 if (sfl) {
                   7184:                                     j = SELER;
                   7185:                                     b = xb;
                   7186:                                     goto zserr;
                   7187:                                 }
                   7188:                                 break;
                   7189:                             }
                   7190:                         }
                   7191:                     }
                   7192: /* end select check */
                   7193:                     else if (ch == 'd' ||   /* $DATA */
                   7194:                              ch == 'g' ||    /* $GET */
                   7195:                              ch == 'o' ||    /* $ORDER */
                   7196:                              ch == 'n' ||    /* $NEXT */
                   7197:                              ch == 'q' ||    /* $QUERY */
                   7198:                              ch == 'i') {    /* $INCREMENT */
                   7199:                         int     xch,
                   7200:                             xi,
                   7201:                             xj;
                   7202:                         char   *xb;
                   7203:                         
                   7204:                         xb = b;     /* do not change old 'b' pointer */
                   7205: /* skip name */
                   7206:                         while (((xch = (*xb)) >= 'A' && xch <= 'Z') ||
                   7207:                                (xch >= 'a' && xch <= 'z'))
                   7208:                             xb++;
                   7209:                         if (xch == '(') {
                   7210:                             if ((xch = (*++xb)) == '^' || xch == '%' ||
                   7211:                                 (xch >= 'A' && xch <= 'Z') ||
                   7212:                                 (xch >= 'a' && xch <= 'z')) {
                   7213:                                 xi = xch;
                   7214:                                 if (xch == '^' && *(xb + 1) == '%')
                   7215:                                     xb++;
                   7216:                                 while
                   7217:                                     (((xch = (*++xb)) >= 'A' && xch <= 'Z') ||
                   7218:                                      (xch >= 'a' && xch <= 'z') ||
                   7219:                                      (xch >= '0' && xch <= '9') ||
                   7220:                                      (xch == '.') ||
                   7221:                                      (xch == '/' && xi <= '^') ||
                   7222:                                      (xch == '%' && *(xb - 1) == '/')) ;
                   7223:                             } else {
                   7224:                                 if (xch == '@')
                   7225:                                     continue;
                   7226:                                 j = INVEXPR;
                   7227:                                 b = xb;
                   7228:                                 goto zserr;
                   7229:                             }
                   7230:                             xi = 0; /* quotes */
                   7231:                             xj = 0; /* brackets */
                   7232:                             for (;;)
                   7233:                             {
                   7234:                                 xch = *xb++;
                   7235:                                 if (xch == '"' && xj) {
                   7236:                                     toggle (xi);
                   7237:                                     continue;
                   7238:                                 }
                   7239:                                 if (xi && (xch != EOL))
                   7240:                                     continue;
                   7241:                                 if (xch == '(') {
                   7242:                                     xj++;
                   7243:                                     continue;
                   7244:                                 }
                   7245:                                 if (xch == ')') {
                   7246:                                     if (xj-- > 0)
                   7247:                                         continue;
                   7248:                                     break;
                   7249:                                 }
                   7250:                                 if (xj && xch != EOL)
                   7251:                                     continue;
                   7252:                                 if (xch == ',' &&
                   7253:                                     (ch == 'g' || ch == 'q' || ch == 'o'))
                   7254:                                     break;
                   7255:                                 j = INVEXPR;
                   7256:                                 b = xb;
                   7257:                                 goto zserr;
                   7258:                             }
                   7259:                         }
                   7260:                     }           /* end data/order/query check */
                   7261:                     if (ch == 'e' ||    /* $EXTRACT */
                   7262:                         ch == 'p' ||    /* $PIECE */
                   7263:                         ch == 'a' ||    /* $ASCII */
                   7264:                         ch == 'g' ||    /* $GET */
                   7265:                         ch == 'j' ||    /* $JUSTIFY */
                   7266:                         ch == 'l' ||    /* $LENGTH */
                   7267:                         ch == 'r' ||    /* $RANDOM/REVERSE */
                   7268:                         ch == 't' ||    /* $TEXT/TRANSLATE */
                   7269:                         ch == 'f') {    /* $FIND/FNUMBER */
                   7270:                         int     xch,
                   7271:                             xi,
                   7272:                             xj,
                   7273:                             xa;
                   7274:                         char   *xb;
                   7275:                         
                   7276:                         xb = b;     /* do not change old 'b' pointer */
                   7277: /* skip name */
                   7278:                         while (((xch = (*xb)) >= 'A' && xch <= 'Z') ||
                   7279:                                (xch >= 'a' && xch <= 'z'))
                   7280:                             xb++;
                   7281:                         if (xch == '(') {
                   7282:                             xi = 0; /* quotes */
                   7283:                             xj = 0; /* brackets */
                   7284:                             xa = 1;
                   7285:                             for (;;)
                   7286:                             {
                   7287:                                 xch = (*++xb);
                   7288:                                 if (xch == EOL)
                   7289:                                     break;
                   7290:                                 if (xch == '"') {
                   7291:                                     toggle (xi);
                   7292:                                     continue;
                   7293:                                 }
                   7294:                                 if (xi)
                   7295:                                     continue;
                   7296:                                 if (xch == '(') {
                   7297:                                     xj++;
                   7298:                                     continue;
                   7299:                                 }
                   7300:                                 if (xch == ')') {
                   7301:                                     if (xj-- > 0)
                   7302:                                         continue;
                   7303:                                     break;
                   7304:                                 }
                   7305:                                 if (xj == 0 && xch == ',') {
                   7306:                                     xa++;
                   7307:                                     continue;
                   7308:                                 }
                   7309:                             }
                   7310:                             if ((ch == 'e' && (xa > 3)) ||  /* $EXTRACT */
                   7311:                                 (ch == 'p' && (xa < 2 || xa > 4)) ||    /* $PIECE */
                   7312:                                 (ch == 'a' && (xa > 2)) ||  /* $ASCII */
                   7313:                                 (ch == 'g' && (xa > 2)) ||  /* $GET */
                   7314:                                 (ch == 'j' && (xa < 2 || xa > 3)) ||    /* $JUSTIFY */
                   7315:                                 (ch == 'l' && (xa > 2)) ||  /* $LENGTH */
                   7316:                                 (ch == 'r' && (xa > 1)) ||  /* $RANDON/$REVERSE */
                   7317:                                 (ch == 't' && (xa > 3)) ||  /* $TEXT/TRANSLATE */
                   7318:                                 (ch == 'f' && (xa < 2 || xa > 3))) {    /* $FIND/FNUMBER */
                   7319:                                 j = FUNARG;
                   7320:                                 b = xb;
                   7321:                                 goto zserr;
                   7322:                             }
                   7323:                         }
                   7324:                     }           /* end number of args check */
                   7325:                     continue;
                   7326:                 }
                   7327:                 if (ch == '(') {
                   7328:                     j++;
                   7329:                     continue;
                   7330:                 }
                   7331:                 if (ch == ')') {
                   7332:                     if (j--)
                   7333:                         continue;
                   7334:                     break;
                   7335:                 }
                   7336:                 if (ch == ',') {
                   7337:                     if ((ch = *b) == SP || ch == EOL || ch == ',') {
                   7338:                         j = ARGLIST;
                   7339:                         goto zserr;
                   7340:                     }
                   7341:                 }
                   7342:             }
                   7343:             if (i)
                   7344:                 j = QUOTER;
                   7345:             else if (j)
                   7346:                 j = j < 0 ? INVEXPR : BRAER;
                   7347:             if (j == OK && ch != EOL && ch != SP)
                   7348:                 j = SPACER;
                   7349:             if (j)
                   7350:                 goto zserr;
                   7351:         }               /* end postcond */
                   7352:         if (ch == SP)
                   7353:             ch = *b;
                   7354:         else if (ch != EOL) {
                   7355:             j = SPACER;
                   7356:             goto zserr;
                   7357:         }
                   7358:         if ((ch == SP || ch == EOL) &&  /* never argumentless */
                   7359:             (f == 'j' || f == 'o' || f == 'r' ||
                   7360:              f == 's' || f == 'u' || f == 'x' ||
                   7361:              f == 'g')) {
                   7362:             j = ARGLIST;
                   7363:             goto zserr;
                   7364:         }
                   7365: /* or.. always argumentless */
                   7366:         if ((ch != SP && ch != EOL) && (f == 'e' || (f == 'q' && forline))) {
                   7367:             j = SPACER;
                   7368:             goto zserr;
                   7369:         }
                   7370:         if (f == 'f')
                   7371:             forline = TRUE;
                   7372:         if (ch == EOL)
                   7373:             break;
                   7374: /* scan argument */
                   7375:         i = 0;              /* quotes */
                   7376:         j = 0;              /* brackets */
                   7377:         ch = SP;            /* init: previous character */
                   7378:         for (;;)                /* scan argument */
                   7379:         {
                   7380:             f = ch;         /* f=previous character */
                   7381:             if ((ch = *b++) == EOL)
                   7382:                 break;
                   7383:             if (ch == '*' && *b == ch)
                   7384:                 b++;            /* exponentiation */
                   7385:             if (ch == '!' && *b == ch)
                   7386:                 b++;                /* XOR */
                   7387:             if (ch == ']') {
                   7388:                 if (*b == ch)
                   7389:                     b++;        /* SORTSAFTER */
                   7390:                 if (*b == '=')
                   7391:                     b++;        /* EQFOLLOWS or EQSORTS */
                   7392:             }
                   7393:             if (ch == '"') {
                   7394:                 toggle (i);
                   7395:                 continue;
                   7396:             }
                   7397:             if (i)
                   7398:                 continue;
                   7399:             if (ch == '$') {
                   7400:                 ch = *b++;
                   7401:                 if (ch >= 'A' && ch <= 'Z')
                   7402:                     ch += 32;
                   7403:                 if ((ch < 'a' || ch > 'z' || ch == 'b' ||
                   7404:                      ch == 'm' || ch == 'u' || ch == 'w') && ch != '$') {
                   7405:                     j = ILLFUN;
                   7406:                     goto zserr;
                   7407:                 }
                   7408:                 if (ch == 's') {    /* $SELECT */
                   7409:                     int     xch,
                   7410:                         xi,
                   7411:                         xj;
                   7412:                     char   *xb;
                   7413:                     int     sfl;
                   7414:                     
                   7415:                     xi = 0;     /* quotes */
                   7416:                     xj = 0;     /* brackets */
                   7417:                     xb = b;     /* do not change old 'b' pointer */
                   7418:                     sfl = TRUE;     /* first ':' expected */
                   7419:                     for (;;)
                   7420:                     {
                   7421:                         if ((xch = *xb++) == EOL ||
                   7422:                             ((xch == SP || xch == ',') && xj == 0)) {
                   7423:                             if (xj == 0)
                   7424:                                 break;  /* $STORAGE */
                   7425:                             j = SELER;
                   7426:                             b = xb;
                   7427:                             goto zserr;
                   7428:                         }
                   7429:                         if (xch == '"') {
                   7430:                             toggle (xi);
                   7431:                             continue;
                   7432:                         }
                   7433:                         if (xi)
                   7434:                             continue;
                   7435:                         if (xch == ':') {
                   7436:                             if (xj > 1)
                   7437:                                 continue;
                   7438:                             if (sfl) {
                   7439:                                 sfl = FALSE;
                   7440:                                 continue;
                   7441:                             }
                   7442:                             j = SELER;
                   7443:                             b = xb;
                   7444:                             goto zserr;
                   7445:                         }
                   7446:                         if (xch == ',') {
                   7447:                             if (xj > 1)
                   7448:                                 continue;
                   7449:                             if (!sfl) {
                   7450:                                 sfl = TRUE;
                   7451:                                 continue;
                   7452:                             }
                   7453:                             j = SELER;
                   7454:                             b = xb;
                   7455:                             goto zserr;
                   7456:                         }
                   7457:                         if (xch == '(') {
                   7458:                             xj++;
                   7459:                             continue;
                   7460:                         }
                   7461:                         if (xch == ')') {
                   7462:                             if ((xj--) > 1)
                   7463:                                 continue;
                   7464:                             if (sfl) {
                   7465:                                 j = SELER;
                   7466:                                 b = xb;
                   7467:                                 goto zserr;
                   7468:                             }
                   7469:                             break;
                   7470:                         }
                   7471:                     }
                   7472:                 }
                   7473: /* end select check */
                   7474:                 else if (ch == 'd' ||   /* $DATA */
                   7475:                          ch == 'g' ||    /* $GET */
                   7476:                          ch == 'o' ||    /* $ORDER */
                   7477:                          ch == 'n' ||    /* $NEXT */
                   7478:                          ch == 'q') {    /* $QUERY */
                   7479:                     int     xch,
                   7480:                         xi,
                   7481:                         xj;
                   7482:                     char   *xb;
                   7483:                     
                   7484:                     xb = b;     /* do not change old 'b' pointer */
                   7485: /* skip name */
                   7486:                     while (((xch = (*xb)) >= 'A' && xch <= 'Z') ||
                   7487:                            (xch >= 'a' && xch <= 'z'))
                   7488:                         xb++;
                   7489:                     if (xch == '(') {
                   7490:                         if ((xch = (*++xb)) == '^' || xch == '%' ||
                   7491:                             (xch >= 'A' && xch <= 'Z') ||
                   7492:                             (xch >= 'a' && xch <= 'z')) {
                   7493:                             xi = xch;
                   7494:                             if (xch == '^' && *(xb + 1) == '%')
                   7495:                                 xb++;
                   7496:                             while
                   7497:                                 (((xch = (*++xb)) >= 'A' && xch <= 'Z') ||
                   7498:                                  (xch >= 'a' && xch <= 'z') ||
                   7499:                                  (xch >= '0' && xch <= '9') ||
                   7500:                                  (xch == '.') ||
                   7501:                                  (xch == '/' && xi <= '^') ||
                   7502:                                  (xch == '%' && *(xb - 1) == '/')) ;
                   7503:                             
                   7504:                         } else {
                   7505:                             if (xch == '@')
                   7506:                                 continue;
                   7507:                             j = INVEXPR;
                   7508:                             b = xb;
                   7509:                             goto zserr;
                   7510:                         }
                   7511:                         xi = 0;     /* quotes */
                   7512:                         xj = 0;     /* brackets */
                   7513:                         for (;;)
                   7514:                         {
                   7515:                             xch = *xb++;
                   7516:                             if (xch == '"' && xj) {
                   7517:                                 toggle (xi);
                   7518:                                 continue;
                   7519:                             }
                   7520:                             if (xi && (xch != EOL))
                   7521:                                 continue;
                   7522:                             if (xch == '(') {
                   7523:                                 xj++;
                   7524:                                 continue;
                   7525:                             }
                   7526:                             if (xch == ')') {
                   7527:                                 if (xj-- > 0)
                   7528:                                     continue;
                   7529:                                 break;
                   7530:                             }
                   7531:                             if (xj && xch != EOL)
                   7532:                                 continue;
                   7533:                             if (xch == ',' &&
                   7534:                                 (ch == 'g' || ch == 'q' || ch == 'o'))
                   7535:                                 break;
                   7536:                             j = INVEXPR;
                   7537:                             b = xb;
                   7538:                             goto zserr;
                   7539:                         }
                   7540:                     }
                   7541:                 }           /* end data/order/query check */
                   7542:                 if (ch == 'e' ||    /* $EXTRACT */
                   7543:                     ch == 'p' ||    /* $PIECE */
                   7544:                     ch == 'a' ||    /* $ASCII */
                   7545:                     ch == 'g' ||    /* $GET */
                   7546:                     ch == 'j' ||    /* $JUSTIFY */
                   7547:                     ch == 'l' ||    /* $LENGTH */
                   7548:                     ch == 'r' ||    /* $RANDON/$REVERSE */
                   7549:                     ch == 't' ||    /* $TEXT/TRANSLATE */
                   7550:                     ch == 'f') {    /* $FIND/FNUMBER */
                   7551:                     int     xch,
                   7552:                         xi,
                   7553:                         xj,
                   7554:                         xa;
                   7555:                     char   *xb;
                   7556:                     
                   7557:                     xb = b;     /* do not change old 'b' pointer */
                   7558: /* skip name */
                   7559:                     while (((xch = (*xb)) >= 'A' && xch <= 'Z') ||
                   7560:                            (xch >= 'a' && xch <= 'z'))
                   7561:                         xb++;
                   7562:                     if (xch == '(') {
                   7563:                         xi = 0;     /* quotes */
                   7564:                         xj = 0;     /* brackets */
                   7565:                         xa = 1;
                   7566:                         for (;;)
                   7567:                         {
                   7568:                             xch = (*++xb);
                   7569:                             if (xch == EOL)
                   7570:                                 break;
                   7571:                             if (xch == '"') {
                   7572:                                 toggle (xi);
                   7573:                                 continue;
                   7574:                             }
                   7575:                             if (xi)
                   7576:                                 continue;
                   7577:                             if (xch == '(') {
                   7578:                                 xj++;
                   7579:                                 continue;
                   7580:                             }
                   7581:                             if (xch == ')') {
                   7582:                                 if (xj-- > 0)
                   7583:                                     continue;
                   7584:                                 break;
                   7585:                             }
                   7586:                             if (xj == 0 && xch == ',') {
                   7587:                                 xa++;
                   7588:                                 continue;
                   7589:                             }
                   7590:                         }
                   7591:                         if ((ch == 'e' && (xa > 3)) ||  /* $EXTRACT */
                   7592:                             (ch == 'p' && (xa < 2 || xa > 4)) ||    /* $PIECE */
                   7593:                             (ch == 'a' && (xa > 2)) ||  /* $ASCII */
                   7594:                             (ch == 'o' && (xa > 2)) ||  /* $ORDER */
                   7595:                             (ch == 'q' && (xa > 2)) ||  /* $QUERY */
                   7596:                             (ch == 'g' && (xa > 2)) ||  /* $GET */
                   7597:                             (ch == 'j' && (xa < 2 || xa > 3)) ||    /* $JUSTIFY */
                   7598:                             (ch == 'l' && (xa > 2)) ||  /* $LENGTH */
                   7599:                             (ch == 't' && (xa > 3)) ||  /* $TEXT/TRANSLATE */
                   7600:                             (ch == 'f' && (xa < 2 || xa > 3))) {    /* $FIND/FNUMBER */
                   7601:                             j = FUNARG;
                   7602:                             b = xb;
                   7603:                             goto zserr;
                   7604:                         }
                   7605:                     }
                   7606:                 }           /* end number of args check */
                   7607:                 continue;
                   7608:             }
                   7609:             if (ch == '(') {
                   7610:                 if (f == ')' || f == '"') {
                   7611:                     j = ARGLIST;
                   7612:                     goto zserr;
                   7613:                 }
                   7614:                 j++;
                   7615:                 continue;
                   7616:             }
                   7617:             if (ch == ')') {
                   7618:                 tmp[0] = f;
                   7619:                 tmp[1] = EOL;
                   7620:                 if (find (" !#&'(*+,-/:<=>?@[\\]_\201", tmp)) {
                   7621:                     j = MISSOPD;
                   7622:                     goto zserr;
                   7623:                 }
                   7624:                 if (j--)
                   7625:                     continue;
                   7626:                 break;
                   7627:             }
                   7628:             if (ch == SP)
                   7629:                 break;
                   7630:             tmp[0] = ch;
                   7631:             tmp[1] = EOL;
                   7632:             if (ch == '/' && (cmnd == 'r' || cmnd == 'w') && (f == SP || f == ',')) {
                   7633:                 int     xch,
                   7634:                     xi,
                   7635:                     xj;
                   7636:                 char   *xb;
                   7637:                 
                   7638:                 xi = 0;         /* quotes */
                   7639:                 xj = 0;         /* brackets */
                   7640:                 xb = b;         /* do not change old 'b' pointer */
                   7641:                 while ((xch = *xb++) != EOL) {
                   7642:                     if (xch == '"') {
                   7643:                         toggle (xi);
                   7644:                         continue;
                   7645:                     }
                   7646:                     if (xi)
                   7647:                         continue;
                   7648:                     if (xch == '(') {
                   7649:                         xj++;
                   7650:                         continue;
                   7651:                     }
                   7652:                     if (xch == ')') {
                   7653:                         if ((xj--) > 1)
                   7654:                             continue;
                   7655:                         xch = *xb++;
                   7656:                         break;
                   7657:                     }
                   7658:                     if (xj)
                   7659:                         continue;
                   7660:                     if ((xch < 'A' || xch > 'Z') &&
                   7661:                         (xch < '1' || xch > '3'))
                   7662:                         break;
                   7663:                 }
                   7664:                 if (xch != ',' && xch != SP && xch != EOL) {
                   7665:                     b = xb;
                   7666:                     j = SPACER;
                   7667:                     goto zserr;
                   7668:                 }
                   7669:                 if (--xb == b) {
                   7670:                     j = ARGLIST;
                   7671:                     goto zserr;
                   7672:                 }
                   7673:             }
                   7674:             if (f == '?' && cmnd != 'r' && cmnd != 'w' &&
                   7675:                 find ("@1234567890.\201", tmp) == 0) {  /* pattern match */
                   7676:                 j = MISSOPD;
                   7677:                 goto zserr;
                   7678:             }
                   7679: /* note: write/read may have !?*#/ not as binary op */
                   7680:             if (find ("&<=>[\\]_\201", tmp) ||  /* binary operator */
                   7681:                 (find ("!?*#/\201", tmp) && cmnd != 'r' && cmnd != 'w'))
                   7682: /* some may be negated */
                   7683:             {
                   7684:                 if (find ("#*/\\_\201", tmp) || f != NOT) {
                   7685:                     tmp[0] = f;
                   7686:                     if (find (" &'(+-<=>[\\]_\201", tmp) ||
                   7687:                         (find ("!?*#/\201", tmp) && cmnd != 'r' && cmnd != 'w')) {
                   7688:                         j = MISSOPD;
                   7689:                         goto zserr;
                   7690:                     }
                   7691:                 }
                   7692:                 continue;
                   7693:             }
                   7694:             if (ch == '+' || ch == '-') {
                   7695:                 if (f == NOT) {
                   7696:                     j = MISSOPD;
                   7697:                     goto zserr;
                   7698:                 }
                   7699:                 continue;
                   7700:             }
                   7701:             if (ch == ':') {
                   7702:                 if (f == ',') {
                   7703:                     j = MISSOPD;
                   7704:                     goto zserr;
                   7705:                 }
                   7706:                 continue;
                   7707:             }
                   7708:             if (ch == '`' || ch == ';' || ch == '{' || ch == '|' ||
                   7709:                 ch == '}' || ch == '~') {   /* illegal characters */
                   7710:                 j = ILLOP;
                   7711:                 goto zserr;
                   7712:             }
                   7713:             if (ch == '$') {        /* check function */
                   7714:                 if (((f = *b | 0140) < 'a' || f > 'z') && f != '$') {
                   7715:                     j = ILLFUN;
                   7716:                     goto zserr;
                   7717:                 }
                   7718:                 continue;
                   7719:             }
                   7720:             if (ch == ',') {        /* comma is a delimiter! */
                   7721:                 if (*(b - 2) == SP || (f = *b) == SP || f == EOL || f == ',') {
                   7722:                     j = ARGLIST;
                   7723:                     goto zserr;
                   7724:                 }
                   7725:             }
                   7726:         }
                   7727:         if (i)
                   7728:             j = QUOTER;
                   7729:         else if (j)
                   7730:             j = j > 0 ? INVEXPR : BRAER;
                   7731:         if (j)
                   7732:             goto zserr;
                   7733:         if (ch == EOL)
                   7734:             break;
                   7735: /* skip spaces before next command */
                   7736:         while (ch == SP || ch == TAB)
                   7737:             ch = *b++;
                   7738:         b--;
                   7739:     }
                   7740:     *a = EOL;               /* no error found */
                   7741:     return;
                   7742: }                   /* end zsyntax() */
                   7743: 
                   7744: time_t horolog_to_unix (char *horo)
                   7745: {
                   7746:     
                   7747:     char *ptr = horo;
                   7748:     register char ch;
                   7749:     register short i;
                   7750:     
                   7751:     char horo_days[10];
                   7752:     char horo_seconds[10];
                   7753: 
                   7754:     time_t seconds;
                   7755: 
                   7756:     i = 0;
                   7757:     
                   7758:     while ((ch = *(ptr++)) != ',') {
                   7759:         horo_days[i++] = ch;
                   7760:     }
                   7761:     horo_days[i] = '\0';
                   7762: 
                   7763:     i = 0;
                   7764:     while ((ch = *(ptr++)) != EOL) {
                   7765:         horo_seconds[i++] = ch;
                   7766:     }
                   7767:     horo_seconds[i] = '\0';
                   7768: 
                   7769:     seconds = (((atol (horo_days) - 47117L) * 86400L) + 43200 + atol (horo_seconds) + tzoffset);
                   7770: 
                   7771:     return (time_t) seconds;
                   7772:     
                   7773: }
                   7774: 
                   7775: 
                   7776: /* a    = result string
                   7777:  * type = type of transform
                   7778:  */
                   7779: void zkey (char *a, long type)
                   7780: {
                   7781: 
                   7782:     char del0;
                   7783:     char del1;
                   7784:     char del2;
                   7785:     char del3;
                   7786:     char del4;
                   7787: 
                   7788:     int f;
                   7789:     char prod_rule[256];
                   7790:     int i;
                   7791:     int ncs;            /* flag: non_collating_substring */
                   7792: 
                   7793:     if (type == 0) type = (-v93);          /* zero is reverse of default type */
                   7794:     if ((f = (type < 0))) type = (-type);
                   7795:     
                   7796:     if (type-- > NO_V93) {
                   7797:         merr_raise (ARGER);
                   7798:         return;
                   7799:     }
                   7800:     
                   7801:     del2 = v93a[type][0];       /* delimiter between primary/seconary key */
                   7802:     del0 = v93a[type][1];       /* delimiter between 'from' and 'to' substring */
                   7803:     del3 = '(';             /* introducer for 'non-collating' substrings */
                   7804:     del4 = ')';             /* terminator for 'non-collating' substring */
                   7805:     ncs = FALSE;            /* non_collating_substring flag */
                   7806: 
                   7807:     if (del0 == EOL) return;             /* no rule under of this type */
                   7808: 
                   7809:     del1 = v93a[type][2];       /* delimiter between different from/to pairs */
                   7810: /* production rule, stripped from delimiter declaration */
                   7811: /* with an added separator character at both ends */
                   7812: 
                   7813:     i = stcpy (prod_rule, &v93a[type][2]);
                   7814:     prod_rule[i] = del1;
                   7815:     prod_rule[++i] = EOL;
                   7816: 
                   7817:     if (f) goto backw;         /* negative is backward transform */
                   7818:     
                   7819: /* forward transform */
                   7820:     i = stlen (a);
                   7821: 
                   7822:     if (i == 0) return;             /* string empty - nothing to do */
                   7823:     
                   7824:     {
                   7825:         char ct0[256];
                   7826:         char ct1[256];
                   7827:         int ch = 0;
                   7828:         int d = 0;
                   7829:         int i1 = 0;
                   7830:         int j = 0;
                   7831:         int n0 = 0;
                   7832:         int n1 = 0;
                   7833:         int pos = 0;
                   7834:         char c;
                   7835:         
                   7836:         i = 0;
                   7837:         n0 = 0;
                   7838:         n1 = 0;
                   7839:         
                   7840:         while ((c = a[i]) != EOL) { /* non-collating substring? */
                   7841: 
                   7842:             if (c == del3) {        /* introducer valid only with matching terminator! */
                   7843: 
                   7844:                 j = i;
                   7845: 
                   7846:                 while ((ch = a[++j]) != EOL) {
                   7847:                     if (ch == del4) break;
                   7848:                 }
                   7849:                 
                   7850:                 if (ch == del4) {
                   7851: 
                   7852:                     while (i <= j) ct1[n1++] = a[i++];
                   7853:                     continue;
                   7854:                     
                   7855:                 }
                   7856:                 
                   7857:             }
                   7858:             
                   7859:             j = 0;
                   7860:             d = 0;
                   7861:             
                   7862: /* search for longest matching string */
                   7863:             while ((ch = prod_rule[j++]) != EOL) {
                   7864: 
                   7865:                 if (ch == del1) {
                   7866:                     
                   7867:                     if (prod_rule[j] != c) continue;
                   7868:                     
                   7869:                     i1 = i;
                   7870: 
                   7871:                     while ((ch = prod_rule[j++]) != del0 && ch == a[i1++]) ;
                   7872: 
                   7873:                     if (ch != del0) continue;
                   7874:                     
                   7875:                     if ((ch = i1 - i) > d) {
                   7876:                         d = ch;
                   7877:                         pos = j;
                   7878:                     }
                   7879:                     
                   7880:                 }
                   7881:                 
                   7882:             }
                   7883:             
                   7884:             if (n0 > STRLEN) {
                   7885:                 merr_raise (M75);
                   7886:                 return;
                   7887:             }               /* string too long */
                   7888:             
                   7889:             if (d == 0) {
                   7890: 
                   7891:                 ct0[n0++] = c;
                   7892:                 ct1[n1++] = '0';
                   7893:                 i++;
                   7894: 
                   7895:                 continue;
                   7896:                 
                   7897:             }
                   7898:             
                   7899:             j = 0;
                   7900:             c = prod_rule[pos];
                   7901:             ch = '0';
                   7902: 
                   7903:             if (c == del1) {
                   7904:                 
                   7905:                 ct1[n1++] = ' ';
                   7906:                 
                   7907:                 while (j <= pos) {
                   7908: 
                   7909:                     if (prod_rule[j] == del0) ch++;
                   7910: 
                   7911:                     j++;
                   7912:                     
                   7913:                 }
                   7914:                 
                   7915:             }
                   7916:             else {
                   7917: 
                   7918:                 while (j <= pos) {
                   7919: 
                   7920:                     if (prod_rule[j] == del0 && prod_rule[j + 1] == c) ch++;
                   7921:                     
                   7922:                     j++;
                   7923:                     
                   7924:                 }
                   7925:                 
                   7926:             }
                   7927:             
                   7928:             j = 0;
                   7929:             i += d;
                   7930:             ct1[n1++] = ch;
                   7931: 
                   7932:             while ((ct0[n0++] = prod_rule[pos++]) != del1) {
                   7933: 
                   7934:                 if (n1 > STRLEN) {
                   7935:                     merr_raise (M75);
                   7936:                     return;
                   7937:                 }           /* string too long */
                   7938:                 
                   7939:             }
                   7940:             
                   7941:             n0--;
                   7942:             
                   7943:         }
                   7944:         
                   7945:         ct0[n0++] = del2;
                   7946:         ct0[n0] = EOL;
                   7947:         ct1[n1] = EOL;
                   7948: 
                   7949: /* purge trailing zeroes */
                   7950:         while (ct1[--n1] == '0') {
                   7951: 
                   7952:             ct1[n1] = EOL;
                   7953: 
                   7954:             if (n1 == 0) {
                   7955:                 n0--;
                   7956:                 break;
                   7957:             }
                   7958:             
                   7959:         }
                   7960:         
                   7961:         if (n0 + n1 > STRLEN) {
                   7962:             merr_raise (M75);
                   7963:             return;
                   7964:         }               /* string too long */
                   7965:         
                   7966:         stcpy (a, ct0);
                   7967:         stcpy (&a[n0], ct1);
                   7968:         
                   7969:     }
                   7970:     
                   7971:     return;
                   7972: 
                   7973:     
                   7974: /* backward transform */
                   7975: backw:
                   7976: 
                   7977:     i = stlen (a);
                   7978: 
                   7979:     if (i == 0) return;             /* string empty */
                   7980:     
                   7981:     {
                   7982:         int c;
                   7983:         int ch;
                   7984:         int d;
                   7985:         int n0;
                   7986:         int n1;
                   7987:         int n2;
                   7988:         int j;
                   7989:         char z[256];
                   7990:         
                   7991:         stcpy (z, a);
                   7992:         n0 = 0;
                   7993:         n1 = 0;
                   7994:         n2 = 0;
                   7995:         
                   7996:         while ((d = z[n1++]) != EOL && (d != del2)) ;
                   7997: 
                   7998:         if (d == EOL) return;         /* nothing to change */
                   7999: 
                   8000:         for (;;) {
                   8001:             
                   8002:             c = z[n0];
                   8003:             d = z[n1];
                   8004: 
                   8005:             if (c == del2 && d == EOL) break;
                   8006: 
                   8007:             if (d == EOL) {
                   8008:                 d = '0';
                   8009:             }
                   8010:             else {
                   8011:                 n1++;
                   8012:             }
                   8013: 
                   8014:             
                   8015:             if (d == del3) {
                   8016: 
                   8017:                 a[n2++] = d;
                   8018:                 ncs = TRUE;
                   8019:                 
                   8020:                 continue;
                   8021:                 
                   8022:             }
                   8023: 
                   8024:             if (ncs) {
                   8025: 
                   8026:                 a[n2++] = d;
                   8027:                 
                   8028:                 if (d == del4) ncs = FALSE;
                   8029:                 
                   8030:                 continue;
                   8031:                 
                   8032:             }
                   8033:             
                   8034:             if (d == ' ') {     /* replacement with no chars */
                   8035: 
                   8036:                 d = z[n1++] - '0';
                   8037:                 j = 1;
                   8038: 
                   8039:                 while ((ch = prod_rule[j++]) != EOL) {
                   8040:                     if (ch == del0 && (--d) == 0) break;
                   8041:                 }
                   8042:                 
                   8043:             }
                   8044:             else {
                   8045: 
                   8046:                 if ((d -= '0') == 0) {
                   8047: 
                   8048:                     a[n2++] = c;
                   8049:                     n0++;
                   8050: 
                   8051:                     continue;
                   8052:                     
                   8053:                 }
                   8054:                 
                   8055:                 j = 1;
                   8056: 
                   8057:                 while ((ch = prod_rule[j++]) != EOL) {
                   8058:                     if (ch == del0 && prod_rule[j] == c && (--d) == 0) break;
                   8059:                 }
                   8060:                 
                   8061:             }
                   8062:             
                   8063:             d = j;
                   8064: 
                   8065:             while ((ch = prod_rule[j++]) != EOL) {
                   8066: 
                   8067:                 if (ch == del1) break;
                   8068:                 
                   8069:                 n0++;
                   8070:                 
                   8071:             }
                   8072:             
                   8073:             d--;
                   8074: 
                   8075:             while (prod_rule[d--] != del1) ;
                   8076: 
                   8077:             if (prod_rule[d + 2] == EOL) {
                   8078:                 merr_raise (ARGER);
                   8079:                 return;
                   8080:             }               /* string is not of proper format */
                   8081: 
                   8082:             d++;
                   8083: 
                   8084:             while ((ch = prod_rule[++d]) != del0) a[n2++] = ch;
                   8085:             
                   8086:         }
                   8087:         
                   8088:         a[n2] = EOL;
                   8089:         
                   8090:     }
                   8091:     
                   8092:     return;
                   8093: }                   /* end zkey() */
                   8094: 
                   8095: int levenshtein (char *word1, char *word2)
                   8096: {
                   8097:     int l1 = 0;
                   8098:     int l2 = 0;
                   8099:     int i = 0;
                   8100:     int j = 0;
                   8101:     int m = 0;
                   8102:     int t = 0;
                   8103:     int x = 0;
                   8104:     char    d[2][256];
                   8105: 
                   8106:     l1 = stlen (word1);
                   8107:     word1--;
                   8108:     
                   8109:     l2 = stlen (word2);
                   8110:     word2--;
                   8111:     
                   8112:     if (l1 == 0) return (l2);
                   8113:     if (l2 == 0) return (l1);
                   8114:     
                   8115:     t = 0;
                   8116: 
                   8117:     for (i = 0; i <= l1; i++) d[0][i] = i;
                   8118:     
                   8119:     for (j = 1; j <= l2; j++) {
                   8120: 
                   8121:         t ^= 1;
                   8122:         d[t][0] = j;
                   8123: 
                   8124:         for (i = 1; i <= l1; i++) {
                   8125: 
                   8126:             m = d[t ^ 1][i - 1];
                   8127:             if (word1[i] != word2[j]) m++;
                   8128: 
                   8129:             x = d[t ^ 1][i];
                   8130:             if (++x < m) m = x;
                   8131: 
                   8132:             x = d[t][i - 1];
                   8133:             if (++x < m) m = x;
                   8134: 
                   8135:             d[t][i] = m;
                   8136:             
                   8137:         }
                   8138:         
                   8139:     }
                   8140:     
                   8141:     return (m);
                   8142: }
                   8143: 
                   8144: /* conditional rounding */
                   8145: /* 'a' is assumed to be a 'canonic' numeric string           */
                   8146: /* it is rounded to 'digits' fractional digits provided that */
                   8147: /* the canonic result has at most (digits-2) frac.digits     */
                   8148: void cond_round (char *a, int digits)
                   8149: {
                   8150:     int ch;
                   8151:     int i;
                   8152:     int point;
                   8153:     int lena;
                   8154: 
                   8155:     point = -1;
                   8156: 
                   8157:     i = 0;
                   8158:     i = 0;
                   8159: 
                   8160:     while (a[i] != EOL) {
                   8161: 
                   8162:         if (a[i] == '.') point = i;
                   8163:         i++;
                   8164:         
                   8165:     }
                   8166:     
                   8167:     lena = i;
                   8168: 
                   8169:     if (point < 0) point = i;
                   8170:     if ((point + digits + 1) >= i) return;             /* nothing to round */
                   8171:     
                   8172:     i = point + digits + 1;
                   8173: 
                   8174:     if (a[i] < '5') {
                   8175: 
                   8176:         if ((a[i - 1] != '0') || (a[i - 2] != '0')) return;         /* condition! */
                   8177:         
                   8178:         a[i] = EOL;
                   8179: 
                   8180:         while (a[--i] == '0') a[i] = EOL;
                   8181:         
                   8182:         if (a[i] == '.') {
                   8183: 
                   8184:             a[i] = EOL;
                   8185: 
                   8186:             if (i == 0 || (i == 1 && a[0] == '-')) a[0] = '0';
                   8187:             
                   8188:         }
                   8189:         
                   8190:         return;
                   8191:         
                   8192:     }
                   8193:     
                   8194:     if (a[i - 1] != '9' || a[i - 2] != '9') return;             /* condition */
                   8195:     
                   8196:     for (;;) {
                   8197:         
                   8198:         if (i >= point) {
                   8199:             a[i] = EOL;
                   8200:         }
                   8201:         else {
                   8202:             a[i] = '0';
                   8203:         }
                   8204:         
                   8205:         if (--i < (a[0] == '-')) {
                   8206: 
                   8207:             for (i = lena; i >= 0; i--) a[i + 1] = a[i];
                   8208: 
                   8209:             a[a[0] == '-'] = '1';
                   8210: 
                   8211:             break;
                   8212:             
                   8213:         }
                   8214:         
                   8215:         if ((ch = a[i]) == '.') continue;
                   8216:         
                   8217:         if (a[i] < '9' && ch >= '0') {
                   8218:             a[i] = ++ch;
                   8219:             break;
                   8220:         }
                   8221:         
                   8222:     }
                   8223: 
                   8224:     return;
                   8225:     
                   8226: }                   /* end cond_round */
                   8227: 
                   8228: short is_horolog(char *s)
                   8229: {
                   8230:     
                   8231:     register int i;
                   8232:     char ch;
                   8233:     int commata = 0;
                   8234:     int digits = 0;   
                   8235: 
                   8236:     if (!isdigit (s[0])) return FALSE;
                   8237: 
                   8238:     for (i = 0; i < stlen (s); i++) {
                   8239: 
                   8240:         ch = s[i];
                   8241: 
                   8242:         if (isdigit (ch)) {
                   8243:             digits++;
                   8244:         }
                   8245:         else if (ch == ',' && commata == 0) {
                   8246:             commata++;
                   8247:         }
                   8248:         else if (ch == ',' && commata > 0) {
                   8249:             return FALSE;         
                   8250:         }
                   8251:         else {
                   8252:             return FALSE;
                   8253:         }
                   8254: 
                   8255:     }
                   8256: 
                   8257:     if (commata != 1) {
                   8258:         return FALSE;
                   8259:     }
                   8260:     else {
                   8261:         return TRUE;
                   8262:     }
                   8263:     
                   8264: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>