File:  [Coherent Logic Development] / freem / src / cmd_tstart.c
Revision 1.2: download - view: text, annotated - select for diffs
Sun Mar 9 15:20:18 2025 UTC (5 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Begin formatting overhaul and REUSE compliance

    1: /*
    2:  *                            *
    3:  *                           * *
    4:  *                          *   *
    5:  *                     ***************
    6:  *                      * *       * *
    7:  *                       *  MUMPS  *
    8:  *                      * *       * *
    9:  *                     ***************
   10:  *                          *   *
   11:  *                           * *
   12:  *                            *
   13:  *
   14:  *   cmd_tstart.c
   15:  *    Implementation of the TSTART command
   16:  *
   17:  *  
   18:  *   Author: Serena Willis <snw@coherent-logic.com>
   19:  *    Copyright (C) 1998 MUG Deutschland
   20:  *    Copyright (C) 2023 Coherent Logic Development LLC
   21:  *
   22:  *
   23:  *   This file is part of FreeM.
   24:  *
   25:  *   FreeM is free software: you can redistribute it and/or modify
   26:  *   it under the terms of the GNU Affero Public License as published by
   27:  *   the Free Software Foundation, either version 3 of the License, or
   28:  *   (at your option) any later version.
   29:  *
   30:  *   FreeM is distributed in the hope that it will be useful,
   31:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   32:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   33:  *   GNU Affero Public License for more details.
   34:  *
   35:  *   You should have received a copy of the GNU Affero Public License
   36:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
   37:  *
   38:  **/
   39: 
   40: #include <string.h>
   41: #include <stdlib.h>
   42: #include <ctype.h>
   43: #include "mpsdef.h"
   44: #include "mcommand.h"
   45: #include "consttbl.h"
   46: #include "transact.h"
   47: 
   48: MRESULT cmd_tstart(MACTION *ra)
   49: {
   50:     register char ch;
   51:     short serial = FALSE;
   52:     short restartable = FALSE;
   53:     char tran_ident[50];
   54:     char tre_offset[50];
   55:     short parct = 0;
   56:     
   57:     if ((rtn_dialect () != D_M95) &&
   58:         (rtn_dialect () != D_MDS) &&
   59:         (rtn_dialect () != D_M5) &&
   60:         (rtn_dialect () != D_FREEM)) {
   61:         return NOSTAND;
   62:     }
   63:     
   64:     uuid_v4 (tran_ident);
   65:     
   66:     if (((ch = *codptr) == SP) || ch == EOL) {
   67:         
   68:         serial = FALSE;
   69:         restartable = FALSE;
   70:         
   71:         goto exec_tstart;
   72:         
   73:     }
   74:     
   75:     restartable = TRUE;
   76:     getraddress (tre_offset, nstx);
   77:     
   78:     //printf ("tre_offset = '%s'\r\n", tre_offset);
   79:     
   80:     if (ch == ':') {
   81:         restartable = FALSE;
   82:         goto tstart_param;
   83:     }
   84:     else if (ch == '(') {
   85:         ch = *codptr++;
   86:         
   87:         if (ch == ')') goto tstart_param;
   88:     }
   89:     else if (ch == '*') {
   90:         printf ("all varnames\r\n");
   91:     }
   92:     else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
   93:         printf ("one varname\r\n");
   94:     }
   95:     
   96:     
   97: tstart_param:           
   98:     
   99:     codptr++;    
  100:     ch = *codptr;
  101:     
  102:     switch (ch) {
  103:         
  104:         case ':':            
  105:             goto tstart_param;
  106:             
  107:         case 's':
  108:         case 'S':
  109:             
  110:             expr (NAME);            
  111:             if (merr ()) return merr ();
  112:             
  113:             stcnv_m2c (varnam);
  114:             {
  115:                 int stct;
  116:                 for (stct = 0; stct < strlen (varnam); stct++) {
  117:                     varnam[stct] = toupper (varnam[stct]);
  118:                 }
  119:             }
  120:             
  121:             if ((strcmp (varnam, "S") == 0) ||
  122:                 (strcmp (varnam, "SERIAL") == 0)) {
  123:                 serial = TRUE;
  124:             }
  125:             else {
  126:                 return SYNTERR;
  127:             }
  128:             
  129:             goto tstart_param;
  130:             
  131:         case 't':
  132:         case 'T':
  133:             
  134:             expr (NAME);            
  135:             if (merr ()) return merr ();
  136:             
  137:             stcnv_m2c (varnam);			
  138:             {
  139:                 int stct;
  140:                 for (stct = 0; stct < strlen (varnam); stct++) {
  141:                     varnam[stct] = toupper (varnam[stct]);
  142:                 }
  143:             }
  144:             
  145:             if ((strcmp (varnam, "T") == 0) ||
  146:                 (strcmp (varnam, "TRANSACTIONID") == 0)) {
  147:                 
  148:                 codptr++;
  149:                 
  150:                 if ((ch = *codptr) != '=') {
  151:                     return ASSIGNER;
  152:                 }
  153:                 
  154:                 codptr++;                        
  155:                 
  156:                 expr (STRING);                
  157:                 if (merr () == BRAER) merr_clear ();                       
  158:                 if (merr () > OK) {
  159:                     return merr ();
  160:                 }
  161:                 
  162:                 stcnv_m2c (argptr);
  163:                 strcpy (tran_ident, argptr);
  164:                 
  165:                 codptr--;
  166:                 
  167:                 goto tstart_param;
  168:                 
  169:             }
  170:             break;
  171:             
  172:         case '(':
  173:             
  174:             parct++;
  175:             
  176:             if (parct > 1) {
  177:                 return SYNTERR;
  178:             }
  179:             
  180:             goto tstart_param;
  181:             
  182:             break;
  183:             
  184:         case ')':
  185:             
  186:             parct--;
  187:             
  188:             if (parct < 0) {
  189:                 return SYNTERR;
  190:             }
  191:             
  192:             goto exec_tstart;
  193:             
  194:         case SP:
  195:         case EOL:
  196:             
  197:             if (parct > 0) {
  198:                 return BRAER;
  199:             }
  200:             
  201:             goto exec_tstart;
  202:             
  203:         default:
  204:             
  205:             return SYNTERR;
  206:             
  207:     }
  208:     
  209:     
  210: exec_tstart:            
  211:     tp_tstart (tran_ident, serial, restartable, NULL);
  212:     
  213:     while ((ch = *(codptr++)) != SP && ch != EOL) ; /* skip to the end of the command */            
  214:     *ra = RA_NEXTCMND;
  215:     return OK;    
  216: }

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