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

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

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