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

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

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