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

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

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