
#ifdef FOR_OS_WINDOWSNT
#	include <sys/timeb.h>
#	include <sys/types.h>
#endif

# include "version.h"
# include "decl.h"
# include "macros.h"
# include "ifunc.h"
# include <time.h>

	/* define macros.	*/


/* Refal interpreter auxiliary function. */

/* Memory allocation routines. */

/* # define NUM_OF_LINKS_AT_A_GULP 512 */
# define NUM_OF_LINKS_AT_A_GULP 1024
# define RI_MEMORY_LIMIT 16
/* Real space is RI_MEMORY_LIMIT Mbytes */
		
unsigned REFLONG ul_limitSizeCode = DEFAULT_CODE_LIMIT * 1024;

/* For copying of trace informations */
extern FILE * fp_debugInfo;

/* interactive stop on an internal error: YES/NO */
static char stop_on_error;	

LINK *ri_getmem (void) {
	register int i;
	register LINK *q, *qn;
	LINK *first;

	/* allocate space for 512 links */
	q = (LINK *) malloc(NUM_OF_LINKS_AT_A_GULP * sizeof(LINK));
	if (q == NULL) return NULL;
	first = qn = q;
	/*	structure it. */
	i = NUM_OF_LINKS_AT_A_GULP;
	while (-- i) q = q -> foll = ++ qn;
	q -> foll = NULL;
	return first;
}

static int memory_used = 0;
LINK *ri_fmout()
	{
	int error = 0;
	LINK *newp = NULL;

	if ((memory_limit > 0) && (memory_used >= memory_limit)) error = 11;
	else if ((newp = ri_getmem()) == NULL) error = 9;
	if (error)
		{
		if (lfm == NULL)
			{
			lfm = malloc(sizeof(LINK));
			if (NULL == lfm) {
			  fprintf (stderr, "No memory for module\n");
			  exit (1);
			}
			lfm->foll = NULL;
			}
			/* clear out the partially formed right side. */
		rdy(0);
		ri_out(2);
		ri_error(error);
		return NULL;
		}
	memory_used++; 
	return newp;
	}

/* Stop function. */
int ri_stop (void) {
/*	if (flags[0] != '\0')
		fprintf(ref_err_file(), "REFAL: NORMAL STOP.\n");*/
	ri_error(0);
	return 0;
}

/* Fuctions cotroling the interrupt status specified by an user. 77777, Nemytykh, 27-02-2026 */
void ri_interrupt_init (void) {
   interrupt_bound = 0; /* The zero value stands for unspecified status. */
	interrupt_st = INTERRUPT_MAY_BE_CANCELLED;
	return;
}

int ri_interrupt (void) {
   char *interrupt_st_message[2] = { "Undoubtedly", "Regular" };
	/* if there is a freezer, freeze and return. */
	if (exists_freeze()) {
		return ri_frz (2); 
	}

   int i = (interrupt_st == INTERRUPT_UNDOUBTEDLY) ? 0:1;
	fprintf(ref_err_file(), "User interruption:  %s.\n",interrupt_st_message[i]);
	ri_error(17);
	return 0;
}

/* IMP function. */
int ri_imp (void) {
	/* if there is a freezer, freeze and return. */
	if (exists_freeze()) {
		return ri_frz (2); 
	}

	/* print message and call error (which calls exit()) */
	fprintf(ref_err_file(), "REFAL ERROR:  RECOGNITION IMPOSSIBLE\n");
	ri_error(12);
	return 0;
}

/* VERSION function. */
void ri_version (char reftr) {
   ri_rc_version ();
 	fprintf(stdout, version, "System", _refal_build_version);
	fprintf(stdout,"Copyright: Refal Systems Inc.\n");
   return;
} 


/*
void ri_version (char reftr) {
	char * cp;
	version = VERSION_ENG;

# ifdef FOR_OS_WINDOWS_UTF8
   FILE *streamtmp;
   char line[256];
   // char * fnametmp = "r5_init_tmp.r5tmp"; // 77777, Nemytykh 26-04-2025
 
   if ( (system("ver > r5_init_tmp.r5tmp") == 0) && (system("chcp >> r5_init_tmp.r5tmp") == 0) 
        && ( fopen_s( &streamtmp, "r5_init_tmp.r5tmp", "r" ) == 0 )
      )
   {   /+* Empty string and "Microsoft Windows [Version dd.0.26100.3775]", 0 < dd < 100 *+/
      if ( (fgets( line, 3, streamtmp ) != NULL) && (fgets( line, 256, streamtmp ) != NULL) &&
           (((strncmp("Version ", (char *)line+19, 8) == 0)) && ( line[29] == '.')) &&
           ('0' < line[27]) && (line[27] <= '9') && ('0' <= line[28]) && (line[28] <= '9')
         ) {   /+* "Active code page: 65001" -- UTF-8 *+/
         if ( (fgets( line, 256, streamtmp ) != NULL) &&
              ((strncmp("code page: 65001", (char *)line+7, 16) == 0))
            )
         version = VERSION;
      }
     fclose( streamtmp );
     system("del r5_init_tmp.r5tmp");
   }
# else /+* LINUX-UTF8 *+/

	if ( (NULL != (cp = getenv ("LANG"))) &&
	     (((strncmp("ru_", cp, 3) == 0)) && ((strcmp(".UTF-8", cp+5) == 0)))
	   ) {
		version = VERSION;
	} /+* else {
		version = VERSION_ENG;
	} *+/
# endif
//	printf (VERSION_ENG, "System", _refal_build_version);

	fprintf(stdout, version, "System", _refal_build_version);
	fprintf(stdout,"Copyright: Refal Systems Inc.\n");
   return;
}	
*/


# ifdef BY_GCC_MINGW_WIN
#   define REF_NB_STEPS_LU  "*** Number of Steps = %2lld\n"
#   define MEMORY_ALLOC_LU  "Memory allocated = %9lld Bytes\n"
#   define MEMORY_LIMIT_LU  "%s limit: %9d*%lld\n"
#   define MEMORY_USED_LU   "%s used: %9d*%lld\n"
#   define MEMORY_USED_FOR_VIEW_FIELD  "memory used for view field is \'-l%lld\'"

# else
#   define REF_NB_STEPS_LU  "*** Number of Steps = %2ld\n"
#   define MEMORY_ALLOC_LU  "Memory allocated = %9ld Bytes\n"
#   define MEMORY_LIMIT_LU  "%s limit: %9d*%ld\n"
#   define MEMORY_USED_LU  "%s used: %9d*%ld\n"
#   define MEMORY_USED_FOR_VIEW_FIELD  "memory used for view field is \'-l%ld\'"
# endif

extern FILE* ref_err_file();

void ri_information (ri_time_strct tm, int code) {
	FILE * ferr = ref_err_file();

	if (code != 0 && flags[0] == '\0') {
		char *token, line[100];

                if ( stop_on_error == YES ) {
              		fprintf(ferr, "Do you want to print view-field? [Yn]");
	            	if (fp_debugInfo != NULL) fprintf (fp_debugInfo, "Do you want to print view-field? ...\n");

        	      	fgets(line, sizeof(line)-1, stdin);
      	        	token = strtok(line, " \n\t\f");
            		if (token == NULL || *token == 'y' || *token == 'Y') strcpy(flags, "a");
                };
	}
	if (strchr(flags, 'a')) {
		fprintf(ferr, VERSION, "System", _refal_build_version);
		if (fp_debugInfo != NULL) fprintf (fp_debugInfo, VERSION, "System", _refal_build_version);
	}
	if (code > 0) {
		char * cp_w = actfun - 1;
		char * act_mss = "*** Active";
		char * fun_mss = "function:";
		char * expr_mss = "expression:";

		fprintf(ferr, "%s %s ",act_mss,fun_mss);
		for (cp_w --; '\0' != * cp_w; cp_w --);
		cp_w ++;
		ri_actput (cp_w, ferr);
		putc ('\n', ferr);
		fprintf(ferr, "%s %s\n",act_mss,expr_mss);
		ri_putmb (tbel (1), tbel (2), ferr);
		if (fp_debugInfo != NULL) {
			fprintf(fp_debugInfo, "%s %s ",act_mss,fun_mss);
			ri_actput (cp_w, fp_debugInfo);
			fprintf(fp_debugInfo, "\n%s %s\n",act_mss,expr_mss);
			ri_putmb (tbel (1), tbel (2), fp_debugInfo);
		}
	}
	if (strchr (flags, 'a') || strchr (flags, 'v')) {
		fprintf(ferr, "*** The View Field:\n");
		ri_putmb (vf, vfend, ferr);
		if (fp_debugInfo != NULL) {
			fprintf(fp_debugInfo, "*** The View Field:\n");
			ri_putmb (vf, vfend, fp_debugInfo);
		}
	}
	if (strchr (flags, 'a') || strchr (flags, 'n')) {
		// Was: fprintf(ferr, "*** Number of Steps = %2ld\n", nst);
		fprintf(ferr, REF_NB_STEPS_LU, nst); // 7777, Nemytykh
		if (fp_debugInfo != NULL) fprintf(fp_debugInfo, REF_NB_STEPS_LU, nst);
	}
	if (strchr (flags, 't') || strchr (flags, 'a')) {
   	char cu_refTime [50];
  		sprintf (cu_refTime, "%lu.%03u", (unsigned long) 0,0); /* temprary definition for uknown oper. systems */
      ri_time ((char *)cu_refTime, tm, whens);
		fprintf (ferr, "Elapsed system time: %s seconds\n", cu_refTime);
		if (fp_debugInfo != NULL)
		   fprintf (fp_debugInfo, "Elapsed system time: %s seconds\n", cu_refTime);
	}
	if (strchr (flags, 'a') || strchr (flags, 'k')) {
		fprintf(ferr, "*** Buried:\n");
		ri_putmb (stock, stock -> pair.b, ferr);
		if (fp_debugInfo != NULL) {
			fprintf(fp_debugInfo, "*** Buried:\n");
			ri_putmb (stock, stock -> pair.b, fp_debugInfo);
		}
	}
	if (strchr (flags, 'a') || strchr (flags, 's')) {
		unsigned REFLONG space = memory_used * sizeof (LINK) * NUM_OF_LINKS_AT_A_GULP;
		fprintf(ferr, MEMORY_ALLOC_LU, space);
		if (fp_debugInfo != NULL) fprintf(fp_debugInfo, MEMORY_ALLOC_LU, space);
	}
}

int ri_error (int code) {
	FILE *ferr = ref_err_file();
	ri_time_strct t;

	ri_gettime(& t);
	//? ltelaps = t;

/*** Was: 13-04-2026
#ifdef FOR_OS_WINDOWSNT
	_ftime (& t);
#else
#  ifdef BY_GCC_MINGW_WIN // 7777, Nemytykh 20-02-2026
	_ftime (& t);
#  else
	//Was: t = time (NULL); // For Linux x32
#  endif
#endif
***/

	ri_print_error_code(ferr, code);
	if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo, code);
	ri_information (t, code);

# ifdef VMS
	/* On VAX/VMS the return code must be odd, otherwise the
		operating system complains. July 1 1986. DT. */
	code = 2*code + 1;
	if (code == 1) exit (code);
#endif

# ifdef PCAT
	if (flags[0] != '\0')
# endif
		putc ('\n', ferr);
	exit (code);
	return 0;
}

/* exploding or imploding functions. */

/* Get the address of the compound symbol *s, assuming that *s consists of only upper-case letters, digits or underscore. */
char *ri_cs_impl (char * s) {
	int i;
	char *q;

	i = ri_hash (s);
	q = ri_cs_exist (i, s);
	if (q != NULL) return q;

	/* if we got here then the compound symbol was not found. */
	/* create it and insert it into the hash table. */

	q = malloc (strlen (s) + 1);
	/* 191 line. Not check result of malloc. Shura. 29.01.98 */
	if (NULL == q) {
	  fprintf (stderr, "No memory for string\n");
	  exit (1);
	}
	strcpy (q, s);
	ri_cs_ins (i, q);
	return q;
}


/* check to see if the compound symol is already in the table. */
char *ri_cs_exist (int i, char * s) {
	struct cshte *ptr;
	char *q;

	for (ptr = csht[i]; ptr != NULL; ptr = ptr -> next) {
		q = ptr -> cs;
		if (strcmp (s, q) == 0) return q;
	}
	return NULL;
}

/* insert the compound symbol q with hash value hv into the table. */
int ri_cs_ins (int hv, char * q) {
	struct cshte *ptr;

	ptr = (struct cshte *) malloc (sizeof (struct cshte));
	/* 221 line. Not check result of malloc. Shura. 29.01.98 */
	if (NULL == ptr) {
	  fprintf (stderr, "No memory for symbols\n");
	  exit (1);
	}
	ptr -> cs = q;
	ptr -> next = csht[hv];
	csht[hv] = ptr;
	return 0;
}

int ri_hash (char * s) {
	int base = 38, h = 0, i;

	while (*s != '\0') {
		switch (*s) {
		case '-':
		case '_':
			i = 36;
			break;

		case '$':
			i = 37;
			break;

		default:
			if (isupper (*s)) i = *s - 'A';
			else if (islower (*s)) i = *s - 'a';
			else if (isdigit (*s)) i = *s - '0' + 26;
			else return h;
		}
		s++;
		h = (h*base + i) % HASH_SIZE;
	}
	return h;
}

int ri_print_error_code(FILE * fp, int err_code) {
   unsigned REFLONG m;
   char * err_mss = "Error";
   char * mem_mss = "Memory";

	if (err_code == 0) return 0;
	if ( err_code != 17 ) {
   	fprintf(fp, "Refal system %s: ",err_mss);
	} else {
# if defined FOR_OS_WINDOWSNT || defined BY_GCC_MINGW_WIN
   	time_t timer; 
# else
   	long timer;
# endif
	   timer = time (NULL);
    	fprintf(fp, "Refal user Exit at %s", ctime (&timer)); // User inerruption.
	};
	switch(err_code) { /* Do neither reorder nor change the err_code values, */ 
	case 0:            /* since some of them may be used by a meta-program, as results of the exit calls */
		fprintf(fp, "Refal normal stop\n");
		break;
	case 1:
		fprintf(fp, "%s allocation error\n",mem_mss);
		break;
	case 2:
		fprintf(fp, "File error.\n");
		break;
	case 3:
		fprintf(fp, "%s: Freeze occured and no Freezer found.\n",err_mss);
		break;
	case 4:
		fprintf(fp, "Illegal instruction\n");
		break;
	case 5:
		fprintf(fp, "%s in FREEZER.\n",err_mss);
		break;
	case 6:
		fprintf(fp, "%s in Freezer metacode.\n",err_mss);
		break;
	case 7:
		fprintf(fp, "%s in function Mu\n",err_mss);
		break;
	case 8:
		fprintf(fp, "Format error in built-in function.\n");
		break;
	case 9:
		fprintf(fp, "No more free memory\n");
		break;
	case 10:
		fprintf(fp, "Unknown link type.\n");
		break;
	case 11:
      m = sizeof (LINK) * NUM_OF_LINKS_AT_A_GULP;
		fprintf(fp, "%s limit reached\n",mem_mss);
		fprintf(fp, MEMORY_LIMIT_LU,mem_mss,memory_limit,m);
		fprintf(fp, MEMORY_USED_LU,mem_mss,memory_used,m);
		fprintf(fp, OPTION_MESS);
		fprintf(fp, MEMORY_USED_FOR_VIEW_FIELD,(m*memory_limit)/(1024*1024));
		fprintf(fp, INCREASE_MESS);
		break;
	case 12:
		fprintf(fp, "Recognition impossible.\n");
		break;
	case 13:
		fprintf(fp, "Stack of the variable tables overflow. ");
		fprintf(fp, OPTION_MESS);
		fprintf(fp, "stack is \'-V%d\'", size_table_element/DEFAULT_TABLE_SIZE);
		fprintf(fp, INCREASE_MESS);
		break;
	case 14:
		fprintf(fp, "Stack of the function calls from the left sides of sentences overflow. ");
		fprintf(fp, OPTION_MESS);
		fprintf(fp, "stack is \'-C%d\'", size_local_stack/DEFAULT_STACK_SIZE);
		fprintf(fp, INCREASE_MESS);
		break;
	case 15:
		fprintf(fp, "Length of a string-argument of a built-in function is too long.\n");
		break;
	case 16:
		fprintf(fp, "Length of an input line is too long.\n");
		break;
	case 17:   
		fprintf(fp, "User interruption.\n");
		break;
	case 18:   
		fprintf(fp, "OSname: the function popen failed.\n");
		break;
	case 19:   
		fprintf(fp, "Input and oputput code pages do not coincide.\n");
		break;
	default:
		fprintf(fp, "%s code %d\n", err_mss, err_code);
		break;
	}
	return 0;
}

int ri_memory()
	{
	unsigned REFLONG limit = 0;
	char * fl = flags;
	
	while( ((* fl) != '\0') && !( ((* fl) == '-') && ((* ++fl) == 'l') )
	     ) fl++;
	
	/* -lnnn -- memory_limit */
	if ((* fl) == 'l') {
		for (fl ++; *fl != '\0' && isdigit(* fl); fl ++) {
			limit = (limit + ((* fl) - '0') ) * 10; 
		}
		limit /= 10;
	} else {
		limit = RI_MEMORY_LIMIT;
	}
	memory_limit = (limit * 1024 * 1024)/(sizeof (LINK) * NUM_OF_LINKS_AT_A_GULP) ;
	return 0;
}

int ri_common_stack (void) {
	if (size_local_stack == 0) {
		size_local_stack = DEFAULT_STACK_SIZE;
	}
	if (size_table_element == 0) {
		size_table_element = DEFAULT_TABLE_SIZE;
	}
	if (NULL == (te = (LINK **) malloc (sizeof (LINK *) * size_table_element))) {
		fprintf (stderr, "Cannot allcate memory for a variable stack\n");
		return -1;
	}
	if (NULL == (st = (STACK_STRUCTURE *) malloc (sizeof (STACK_STRUCTURE) * size_local_stack))) {
		fprintf (stderr, "Cannot allocate memory for a calling stack\n");
		return -1;
	}
	return 0;
}

int ri_init_stop() {
	char * fl = flags;
	
	while( ((* fl) != '\0') && !( ((* fl) == '-') && ((* ++fl) == 'e') ) ) fl++;
	
        /* interactive stop on an internal error: YES/NO */
        stop_on_error = ((* fl) == 'e') ? NO : YES;
        return 0;
}

int ri_help(char reftr) {
 if ( reftr ) printf("Using: reftr [options] MODULE1+MODULE2+... [arguments] \n");
 else         printf("Using: refgo [options] MODULE1+MODULE2+... [arguments] \n");
 
 printf("\nOptions recognized by the Refal system:");
 printf("\n -n : upon normal stop print the number of steps.");
 printf("\n -v :   \"   \"   \"   \"   \"   \"    view field.");
 printf("\n -k :   \"   \"   \"   \"   \"   \"    content of the stock.");
 printf("\n -t :   \"   \"   \"   \"   \"   \"    elapsed time.");
 printf("\n -s :   \"   \"   \"   \"   \"   \"    maximum allocated storage.");
 printf("\n -a : all of the above.");
 printf("\n -e : upon internal error stop do not use interactive mode -");
 printf("\n      \"Do you want to print view-field? [Yn]\", use [n] as default.");
 printf("\n -i : ignore unresolved external references.");

 printf("\n -C[ ]nn or --\"call_stack=nn\" :");
 printf("\n  parameter for the size of the stack of function calls from the left sides");
 printf("\n  of Refal sentences, where \'nn\' is a number ranging from 1 to 10 (recommended).");

 printf("\n -c[ ]nnn or --\"code_limit=nnn\" :");
 printf("\n  limit of the rsl-code size, where \'nnn\' is a number of Kbs.");
 printf("\n  By default it is %dKb.",DEFAULT_CODE_LIMIT);

 printf("\n -lnnn : , where \'nnn\' is a number - memory_limit for the view field,");
 printf("\n           memory = 512*sizeof(LINK)*memory_limit");

 printf("\n -m<option> : option startig with -m or --m is reserved for passing on to the programs invoked by the interpreter.");
 printf("\n -O<option> :  \"   \"   \"   \"   \"  -O or --O \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"  ");
 printf("\n -p<option> :  \"   \"   \"   \"   \"  -p or --p \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"  ");
 printf("\n -R<option> :  \"   \"   \"   \"   \"  -R or --R \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"  ");
 printf("\n -X<option> :  \"   \"   \"   \"   \"  -X or --X \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"   \"  ");
			   /* Do not shift the -p, ... , -X symbols! For some reason they are printed in the same colon with -m.
			      The options startig with -p<option>, -m<option>, -O<option>, -R<option>, -X<option>
			      are reserved for passing on to the various sub-processes invoked by the interpreter.
			      The same holds for similar options starting with two minus signs. 
			    */
 printf("\n -V[ ]nn or --\"var_stack=nn\" :");
 printf("\n  parameter for the size of the stack of variable tables,");
 printf("\n  where \'nn\' is a number ranging from 1 to 10 (recommended).");

 if ( reftr ) printf("\n -f[ ]file_name: copy trace messages to the file name.");

 printf("\n --version : print the version of Refal-5 System.");
 printf("\n -h or --help : print this help message.\n\n");
 exit (0);
 return 1;
}


void ri_IncorrectOptionFormat ( char );

int ri_options(int argc, char * argv [], char reftr) {
	int i; 
	
	r_argv = argv;

	gargc = 0;
	flags [0] = '\0';
	garg = (char **) malloc ((argc + 1) * sizeof (char *));
	
	if (garg == NULL) {
		fprintf(stderr, "Error: Can\'t allocate memory.\n");
		exit (3);
	}
	for (i = 0; i < argc; i ++) garg [i] = NULL;

   r_wargv_init();
	for (i = 1; i < argc; i++) {
		if (*argv[i] == '-') {/* flags */
			if (argv [i][1] == '-') {
				if (strncmp (argv [i] + 2, "help", 4) == 0) {
					goto help;
				} else if (strncmp (argv [i] + 2, "version", 7) == 0) {
					ri_version (reftr);
					exit (0);
				} else if (strncmp (argv [i] + 2, "call_stack=", 11) == 0) {
					size_local_stack = DEFAULT_STACK_SIZE * atoi (argv [i] + 13);
				} else if (strncmp (argv [i] + 2, "var_stack=", 10) == 0) {
					size_table_element = DEFAULT_TABLE_SIZE * atoi (argv [i] + 12);
				} else if (strncmp (argv [i] + 2, "code_limit=", 11) == 0) {
					ul_limitSizeCode = atoi (argv [i] + 13) * 1024;
   			} else if ( (argv [i][2] == 'p') || (argv [i][2] == 'm') || (argv [i][2] == 'O') || (argv [i][2] == 'X')) { /* Nemytykh 24-02-2023 */
			      /* The options startig with --p<option>, --m<option>, --O<option>, --R<option>, --X<option>
			         are reserved for passing on to the various sub-processes invoked by the interpreter. 
			      */
               garg [gargc++] = argv [i]; 
				} else {
					strcat (flags,argv[i]);
				}
			} else if (argv [i][1] == 'V') {
				char * cp = NULL;

				if (argv [i][2] == 0) {
					if ((cp = argv [i + 1]) == NULL) {
					   ri_IncorrectOptionFormat('V');  // 777, Nemytykh, 01-05-2025 -- Here and below for this function.
						continue;
					}
					i ++;
				} else {
					cp = argv [i] + 2;
				}
				if (! isdigit (* cp)) {
				   ri_IncorrectOptionFormat('V');
					continue;
				}
				size_table_element = DEFAULT_TABLE_SIZE * atoi (cp);
			} else if (argv [i][1] == 'C') {
				char * cp = NULL;

				if (argv [i][2] == 0) {
					if ((cp = argv [i + 1]) == NULL) {
					   ri_IncorrectOptionFormat('C');
						continue;
					}
					i ++;
				} else {
					cp = argv [i] + 2;
				}
				if (! isdigit (* cp)) {
				   ri_IncorrectOptionFormat('C');
					continue;
				}
				size_local_stack = DEFAULT_STACK_SIZE * atoi (cp);
			} else if (argv [i][1] == 'c') {
				char * cp = NULL;

				if (argv [i] [2] == 0) {
					if ((cp = argv [i + 1]) == NULL) {
					   ri_IncorrectOptionFormat('c');
						continue;
					}
					i ++;
				} else {
					cp = argv [i] + 2;
				}
				if (! isdigit (*cp)) {
				   ri_IncorrectOptionFormat('c');
					continue;
				}
				ul_limitSizeCode = atoi (cp) * 1024;
			} else if ( (argv [i][1] == 'f') && reftr ) {
				char * cp;

				if (argv [i][2] == 0) {
					if ((cp = argv [i + 1]) == NULL) {
					   ri_IncorrectOptionFormat('f');
						continue;
					}
					i ++;
				} else {
					cp = argv [i] + 2;
				}
				if (NULL == (fp_debugInfo = fopen (cp, "w"))) {
					fprintf (stderr, "Cannot open file \'%s\' for copying of trace informations\n", cp);
				}
			} else if ( argv [i][1] == 'h' ) { 
            help: ri_help( reftr ); 
			} else if ( (argv [i][1] == 'p') || (argv [i][1] == 'm') || (argv [i][1] == 'O') || (argv [i][1] == 'X')) { /* Nemytykh 24-02-2023 */
			   /* The options startig with -p<option>, -m<option>, -O<option>, -R<option>, -X<option>
			      are reserved for passing on to the various sub-processes invoked by the interpreter. 
			    */
               garg [gargc++] = argv [i]; 
			} else {
				strcat (flags,argv[i]);
			}
		} else { /* no flags; i.d. there is no the option sign '-'. */
//Was:		   garg [gargc++] = argv [i];
         garg [gargc++] = r_wgetargvi(argv, i); 

/*
         char * pp = (char *)(garg [gargc-1]);
         wchar_t * qq = (wchar_t *)pp;
         printf("\n options: gargc = %d, i = %d\n", gargc-1,i);
         for(int j=0; qq[j] != L'\0'; j++) printf("%c",qq[j]);
         getchar();
*/
		}
	}
 return 1;
}

// 7777, Nemytykh, 01-05-2025
void ri_IncorrectOptionFormat ( char opt ) {
	fprintf (stderr, "WARNING: Incorrect format for \'-%c\'.\n\t",opt);
	switch (opt) {
		case 'V':
		case 'C':
						fprintf (stderr, " It must be \'-%c nn\' or \'-%cnn\'.",opt,opt);
						break;
		case 'c':   fprintf (stderr, " It must be \'-cnnn\' or \'-c nnn\' or \'--code_limit=nnn\'\n\t Where nnn is number of Kb.");
		   			break;
		case 'f':	fprintf (stderr, " It must be \'-f<file_name>\' or \'-f <file_name>\'");
		default: ;
	};
	fprintf (stderr, " Ignoring the option.\n");
	return;
}