Example #1
0
void colorsload(){
std::wstring pathc=appRootPath;
    pathc+=L"color\\color.txt";

    HANDLE filec=CreateFile(pathc.c_str(), 
        GENERIC_READ , 
        FILE_SHARE_READ, NULL, 
        OPEN_EXISTING ,
        0, NULL);

    if (filec==INVALID_HANDLE_VALUE) return;
    int size=GetFileSize(filec, NULL);
    if (size>64000) {CloseHandle(filec); return; }

    char *colorch=new char[size+1];
DWORD rd;
    ReadFile(filec, colorch, size, &rd, NULL);     
    CloseHandle(filec);

    colorch[rd]=NULL;

for ( int fff=0 ; fff<=18 ; fff++ ){
	iii=fff*7;
COLORS[fff]=1048576*chartoint(colorch[iii])+65536*chartoint(colorch[iii+1])+4096*chartoint(colorch[iii+2])+256*chartoint(colorch[iii+3])+16*chartoint(colorch[iii+4])+chartoint(colorch[iii+5]);

}
}
Example #2
0
// The next functions writes and reads from the file "puzzles.txt"
int getNumPuz(void)
{
  FILE *fptr;
  fptr = fopen(PUZZLES,"r");
  int ones, tens, hunds;
  ones = chartoint((char)fgetc(fptr));
  tens = chartoint((char)fgetc(fptr));
  hunds = chartoint((char)fgetc(fptr));
  fclose(fptr);

  int numpuz;
  numpuz = 100*hunds + 10*tens + ones;
  return numpuz;
}
Example #3
0
char LoadConfig(char *Soubor){
	FILE *F;
	char S[256],T[10];
	int I,J;

	if ((F=fopen(Soubor,"r"))==NULL)
		return 0;
	while (!feof(F)){
		fgets (S,255,F);
		while ((strlen(S)>0)&&(S[strlen(S)-1]<' '))
			S[strlen(S)-1]='\0';
		if ((S[0]!='\0')&&(S[0]!='#')){
//			printf("%s\n",S);
				if (!strcmp(S,"shades=none"))
					Shades=0;
				else
				if (!strcmp(S,"shades=solid"))
					Shades=255;
				else
				if (!strcmp(S,"shades=transparent"))
					Shades=128;
				else
				if (!strncmp(S,"fullscreen=",11))
					FULLSCR=chartoint(S[11]);

		}
	}
	fclose (F);
	return 1;
}
Example #4
0
int myatoi(char Co[]){
int I=strlen(Co)-1,Exp=1,Res=0;

while ((Exp!=-1)&&(I>=0)&&(Co[I]!='-')){
	Res+=Exp*chartoint(Co[I]);
	if (Exp<10000)
		Exp*=10;
	else
		Exp=-1;
	I--;
}
if ((I>=0)&&(Co[I]=='-')) Res*=-1;
return Res;
}
Example #5
0
static int cmd_x(char *args)
{
	char *arg = strtok(NULL," ");
	int n = chartoint(args);
	arg = arg + strlen(arg) + 1;
	int len = strlen(arg);
	int i, m, re=0;
	for(i = len - 1, m = 1; len >= 2; len--){
		re = re + (arg[i] - '0') * m;
		m = m << 4;
	}
	for(i = 0; i < n;i++)
    		printf("0x%x\n", hwaddr_read(re + i, 4));
	return 0;
}
Example #6
0
char LoadLevels(char *Soubor){
	FILE *F;
	char S[256],T[10];
	int I=0,J,L=-1;
	
	for (J=0;J<100;J++)
		Lvl[J].Name[0]='\0';

	if ((F=fopen(Soubor,"r"))==NULL)
		return 0;
	while ((!feof(F))&&(fgets(S,255,F)!=NULL)){
		while ((strlen(S)>0)&&(S[strlen(S)-1]<' '))
			S[strlen(S)-1]='\0';
		if ((S[0]!='\0')&&(S[0]!='#')){
//			printf("%s\n",S);
			if ((S[0]=='>')&&(S[strlen(S)-1]=='-')){
				L++;
				Lvl[L].Name[0]='\0';
				Lvl[L].Pw[0]='\0';
				Lvl[L].BgFile[0]='\0';
				Lvl[L].Bg=NULL;
				Lvl[L].DL=0;
				for (I=0;I<20;I++)
					for (J=0;J<20;J++){
						Lvl[L].M[I][J].FSpr=' ';
						Lvl[L].M[I][J].FTyp=' ';
						Lvl[L].M[I][J].BSpr=' ';
						Lvl[L].M[I][J].BTyp=' ';
						Lvl[L].M[I][J].x=0;
						Lvl[L].M[I][J].y=0;
						Lvl[L].M[I][J].px=0;
						Lvl[L].M[I][J].py=0;
						Lvl[L].M[I][J].f=0;
						Lvl[L].M[I][J].txt=-1;
					}
				for (I=0;I<10;I++)
					Lvl[L].Text[I][0]='\0';

				I=0;
//				fprintf(stdout,"Level(%d) loaded...\n",L);
			}else{// LEVEL
				if ((S[1]=='=')&&(chartoint(S[0])>=0))
					for (J=2;J<=strlen(S);J++)
						Lvl[L].Text[chartoint(S[0])][J-2]=S[J];
				else
				if (!strncmp(S,"name=",5))
					for (J=5;J<=strlen(S);J++)
						Lvl[L].Name[J-5]=S[J];
				else
				if (!strncmp(S,"password="******"deadline=",5)){
					for (J=9;J<=strlen(S);J++)
						T[J-9]=S[J];
					Lvl[L].DL=myatoi(T);
				}
				else
				if (!strncmp(S,"background=",5)){
					for (J=11;J<=strlen(S);J++)
						T[J-11]=S[J];
					strcpy(Lvl[L].BgFile,T);
				}
				else
				if ((I<20)&&(strlen(S)>=20*7)&&(S[0]==',')){
					for (J=0;J<20*7;J+=7){
							Lvl[L].M[J/7][I].FTyp=S[J+1];
							Lvl[L].M[J/7][I].FSpr=S[J+2];
							Lvl[L].M[J/7][I].BTyp=S[J+3];
							Lvl[L].M[J/7][I].BSpr=S[J+4];
							Lvl[L].M[J/7][I].x=0;
							Lvl[L].M[J/7][I].y=0;
							Lvl[L].M[J/7][I].px=0;
							Lvl[L].M[J/7][I].py=0;
							Lvl[L].M[J/7][I].f=chartoint(S[J+5]);
							Lvl[L].M[J/7][I].txt=chartoint(S[J+6]);
					}
					I++;
				}
			}

		}
	}
	fclose (F);
	return 1;
}
Example #7
0
int main(int argc, char **argv)
{
	int lockfd;
    bool restore_vrf_pluto = 0;
	
	/*此开关必须放在所有动态内存分配之前*/
	leak_detective=0;
	
	debug_info_control* dic=alloc_bytes(sizeof(debug_info_control), "malloc debug_info_control in main");

	openswan_passert_fail = passert_fail;

	/*设备类型初始化*/
	ipsec_device_type_init();
	{
		u32 pseudo_start_pluto = 0;

		for (;;)
		{
#define DBG_OFFSET 256
			static const struct option long_opts[] = {
				/* name, has_arg, flag, val */
				{ "help", no_argument, NULL, 'h' },
				{ "version", no_argument, NULL, 'v' },
				{ "start", no_argument, NULL, 'B' },
                { "quit", no_argument, NULL, 'D' },    
				{ "user", no_argument, NULL, 'u' },
				{ "krl", no_argument, NULL, 'K' },
				{ "debug-nat", no_argument, NULL, '5' },
				{ "debug-none", no_argument, NULL, 'N' },
				{ "debug-all", no_argument, NULL, 'A' },
				{ "debug-raw", no_argument, NULL, DBG_RAW + DBG_OFFSET },	
				{ "debug-crypto", no_argument, NULL, DBG_CRYPT + DBG_OFFSET },
				{ "debug-parsing", no_argument, NULL, DBG_PARSING + DBG_OFFSET },
				{ "debug-emitting", no_argument, NULL, DBG_EMITTING + DBG_OFFSET },
				{ "debug-control", no_argument, NULL, DBG_CONTROL + DBG_OFFSET },
				{ "debug-lifecycle", no_argument, NULL, DBG_LIFECYCLE + DBG_OFFSET },
				{ "debug-klips", no_argument, NULL, DBG_KLIPS + DBG_OFFSET },
				{ "debug-netkey", no_argument, NULL, DBG_NETKEY + DBG_OFFSET },
				{ "debug-dns", no_argument, NULL, DBG_DNS + DBG_OFFSET },
				{ "debug-oppoinfo", no_argument, NULL, DBG_OPPOINFO + DBG_OFFSET },
				{ "debug-controlmore", no_argument, NULL, DBG_CONTROLMORE + DBG_OFFSET },
				{ "debug-dpd", no_argument, NULL, DBG_DPD + DBG_OFFSET },
				{ "debug-xauth", no_argument, NULL, DBG_XAUTH+ DBG_OFFSET },
				{ "debug-x509", no_argument, NULL, DBG_X509 + DBG_OFFSET },
				{ "debug-private", no_argument, NULL, DBG_PRIVATE + DBG_OFFSET },
				{ "debug-pfkey", no_argument, NULL, DBG_PFKEY + DBG_OFFSET },
                { "debug-ifchange", no_argument, NULL, DBG_IF_CHANGE + DBG_OFFSET },
                
				{ "log-openinfo", no_argument, NULL, 'i' },
				{ "log-openwar", no_argument, NULL, 'w' },
				{ "log-openerr", no_argument, NULL, 'r' },
				{ "log-openuserlog", no_argument, NULL, 'e' },				
				{ "log-openradiuslog", no_argument, NULL, 'c' },
				{ "log-openpri", no_argument, NULL, 'p' },
				{ "log-opensyserr", no_argument, NULL, 'q' },
				{ "log-closeall", no_argument, NULL, 'a' },

				{ "debug-connection", required_argument, NULL, 'O' },
				{ "debug-host", required_argument, NULL, 'H' },
				{ "debug-stop", no_argument, NULL, 'S' },
				{ "counter", no_argument, NULL, 'b' },				
				{ "isa-counter", no_argument, NULL, 'x' },

				{ "krc", no_argument, NULL, 'E'},
				{ "kss", required_argument, NULL, 'F'},
				{ "kpc", no_argument, NULL, 'G'},
				{ "kprt", required_argument, NULL, 'L'},
				{ "kspi", required_argument, NULL, 'M' },
				{ "kdst", required_argument, NULL, 'P' },
				{ "kdnet", required_argument, NULL, 'R' },
				{ "kid",  required_argument, NULL, 'Q' },
				{ "restore-vrf", no_argument, NULL, 'V' },	
				{ 0,0,0,0 }
			};

			int c = getopt_long(argc, argv, "", long_opts, NULL);
			ip_address dst_tmp;
			ip_subnet subnet_tmp;

			switch (c)
			{
				case EOF:	/* end of flags */
					break;

				case 0: /* long option already handled */
					continue;

				case ':':	/* diagnostic already printed by getopt_long */
				case '?':	/* diagnostic already printed by getopt_long */
					usage("");
					break;   

				case 'h':	
					usage(NULL);
					break;	

				case 'v':	
				{
					const char **sp = ipsec_copyright_notice();

					printf("%s%s\n", ipsec_version_string(),compile_time_interop_options);
					for (; *sp != NULL; sp++)
					{
						puts(*sp);
					}
				}
					exit(0);	
					break;	

				case 'i':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_INFO;
					continue;

				case 'w':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_WARNING;
					continue;

				case 'r':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_ERROR;
					continue;

				case 'e':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_USER_LOG;
					continue;
					
				case 'c':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_RADIUS_LOG;
					continue;
					
				case 'p':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_PRIVATE;
					continue;
					
				case 'q':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info |= IPSEC_LOGLEVEL_SYSERROR;
					continue;

				case 'a':
					dic->public_info.log_falg = 1;
					dic->public_info.log_level_info=IPSEC_LOGLEVEL_CLOSE;
					continue;
                    
				case 'B': 				    
					dic->com_type=IPSEC_DEBUG_STAR_HANDLE;
					continue;                   

                case 'D':
                    dic->com_type=IPSEC_DEBUG_QUIT_HANDLE;
					continue;

				case 'u':                    
					dic->com_type=IPSEC_DEBUG_USER_HANDLE;
					continue;

				case 'K':	
					dic->com_type=IPSEC_DEBUG_KERNEL_HANDLE;
					continue;

				case 'N':	/* --debug-none */
					dic->public_info.public_info_flag=1;
					dic->public_info.public_info_value=DBG_NONE;
					continue;

				case 'A':	/* --debug-all */
					dic->public_info.public_info_flag=1;
					dic->public_info.public_info_value=DBG_ALL;
					continue;

				case 'O':
					if(optarg != NULL)
					{
						strcpy(dic->child_info.child_info_optarg,optarg);
						dic->child_info.child_info_type=IPSEC_CHILD_DEBUG_INFO_CON_NAME;
					}
					else
					{
						return 0;
					}
					break;

				case 'H':
					if(optarg != NULL)
					{
						strcpy(dic->child_info.child_info_optarg,optarg);
						dic->child_info.child_info_type=IPSEC_CHILD_DEBUG_INFO_HOST;
					}
					else
					{
						return 0;
					}
					break;

				case 'S':
					dic->child_info.child_info_type=IPSEC_CHILD_DEBUG_INFO_STOP;
					break;
				case 'b':
					dic->child_info.child_info_type=IPSEC_CHILD_DEBUG_INFO_PRINT_COUNTER;
					break;
                case 'x':
					dic->child_info.child_info_type=IPSEC_CHILD_DEBUG_INFO_PRINT_ISA_COUNTER;
					break;
				case 'E':	
					pseudo_start_pluto = 1;
					dic->kernel_info.flag= IPSEC_RESET_COUNTER;
					continue;

				case 'F':
					pseudo_start_pluto = 1;
					dic->kernel_info.flag = IPSEC_SET_DEBUG_SIP;
					dic->kernel_info.sip =inet_addr(optarg);
					continue;

				case 'G':
					pseudo_start_pluto = 1;
					dic->kernel_info.flag = IPSEC_DUMP_COUNTER;
					continue;
					
				case 'L':
					pseudo_start_pluto = 1;
					dic->kernel_info.flag=IPSEC_PRINT_INTERFACE_TEMP;
					if_get_index_by_name(optarg, (s32*)(&dic->kernel_info.ifindex));
					continue;	
					
				case 'M':	
					pseudo_start_pluto = 1;
					dic->kernel_info.flag=IPSEC_PRINT_INTERFACE_TEMP;

				    dic->kernel_info.spi = (u32)chartoint(optarg,strlen(optarg));
					if((int)dic->kernel_info.spi < 0)
					{
						fprintf(stderr,"%s IS ERROR INPUT(For Example:0x123...)\n",optarg);
						pfree(dic);
						return 0;
					}
				    continue;
					
				case 'P':
					pseudo_start_pluto = 1;
					dic->kernel_info.flag=IPSEC_PRINT_INTERFACE_TEMP;
					if(ttoaddr(optarg, 0, AF_INET, &dst_tmp))
					{
					    fprintf(stderr,"you must input right IP\n");
						pfree(dic);
						return 0;					    
					}
					else{
						dic->kernel_info.dsc.a4 = dst_tmp.u.v4.sin_addr.s_addr;
					    continue;
					}
				case 'R':
					pseudo_start_pluto = 1;
					dic->kernel_info.flag=IPSEC_PRINT_INTERFACE_TEMP;
					if(ttosubnet(optarg, 0, AF_INET, &subnet_tmp))
					{
					    fprintf(stderr,"you must input right subnet\n");
						pfree(dic);
						return 0;					    
					}
					else{
					    dic->kernel_info.net.a4 = subnet_tmp.addr.u.v4.sin_addr.s_addr;
					    continue;
					}

				case 'Q':	
					pseudo_start_pluto = 1;
					dic->kernel_info.flag=IPSEC_PRINT_INTERFACE_TEMP;
					dic->kernel_info.connid = atoi(optarg);
					continue;

				case 'V':
		        {
					restore_vrf_pluto = 1;
			    }		
				continue;
				
				default:
					if (c >= DBG_OFFSET)
					{
                        dic->public_info.public_info_flag=1;
						dic->public_info.public_info_value |= c - DBG_OFFSET;						
					}
					continue;
				bad_case(c);
			}
			break;

		}
		/**
		if(restore_vrf_pluto)
   	    {
   		   ipsec_restore_vrf_pluto();	   
   	    }
   	    **/
   		ipsec_restore_vrf_pluto();

	{
		u32 err;
		conplat_syscall(MODULEID_OSBASIC, OSBASIC_GET_VRF_ID, &g_ipsec_vrf_id, sizeof(g_ipsec_vrf_id), (s32*)(&err));	
		if(err != 0)
		{
			g_ipsec_vrf_id = 0;
		}

		sprintf(pluto_lock + strlen(pluto_lock), "_%d", g_ipsec_vrf_id);
		sprintf(ctl_addr.sun_path+ strlen(ctl_addr.sun_path), "_%d", g_ipsec_vrf_id);	
		sprintf(ws_ctl_addr.sun_path+ strlen(ws_ctl_addr.sun_path), "_%d", g_ipsec_vrf_id);			
	}

		switch(dic->com_type)
		{
			case IPSEC_DEBUG_STAR_HANDLE:
				if(dic->public_info.public_info_flag)
				{
					cur_debugging = dic->public_info.public_info_value;
				}

				if(dic->public_info.log_falg)
				{				    
					g_log_level = dic->public_info.log_level_info;					
				}
				break;

			case IPSEC_DEBUG_USER_HANDLE:
				send_connection_debug(dic, IPSEC_DEBUG_USER_HANDLE);
				pfree(dic);
				return 0;

			case IPSEC_DEBUG_KERNEL_HANDLE:
				if(pseudo_start_pluto == 1)
				{
					u32 syscall_result = 0;
					if((dic->kernel_info.flag==IPSEC_PRINT_INTERFACE_TEMP)&&(0 == dic->kernel_info.ifindex))
					{
						fprintf(stderr,"you must input the if name\n");
						pfree(dic);
						return 0;
					}
					
					conplat_syscall(MODULEID_IPSEC_POLICY, IPSEC_MODULE_DEBUG_PART, (void *)(&dic->kernel_info), sizeof(struct ipsec_user_debug_info), (s32 *)(&syscall_result));

					if(g_ipsec_device_is_dpx)
					{
						(u32)conplat_syscall(FW_MODULEID_IPSEC | FW_BOARD, IPSEC_MODULE_DEBUG_PART, (void *)(&dic->kernel_info), sizeof(struct ipsec_user_debug_info), (s32 *)(&syscall_result));
					}

				}
				else
				{
					fprintf(stderr,"after --kernel ,you must input the right command\n");
				}
				pfree(dic);
				return 0;
             case IPSEC_DEBUG_QUIT_HANDLE:
                send_connection_debug(dic, IPSEC_DEBUG_QUIT_HANDLE);
                pfree(dic);
                return 0;
			default:
				fprintf(stderr,"you must input --start --quit --user or --kernel\n");
				exit(0);
		}
		pfree(dic);
	}
	
	if (optind != argc)
	{
		usage("unexpected argument");
	}


	//如果你想再重启设备后默认打开调试开关
#if 0
	cur_debugging = DBG_ALL;
#endif

	lockfd = create_lock();
		

    g_log_level |= ws_get_log_level(); //获得显示级别

    g_ipsec_multiout = ws_get_multiOut(); //获取多接口转发标志位

	if(g_ipsec_multiout)
	{
	    int res;
	    conplat_syscall(MODULEID_IPSEC_POLICY, IPSEC_MODULE_MULTI_OUT, &(g_ipsec_multiout), sizeof(g_ipsec_multiout), &res);
	}

	ipsec_restore_tunnel_ipsec();

	ipsec_init_lv2_switch();
	ipsec_init_route_mode();
	ipsec_init_user_syn();
	ipsec_init_compress_enable();
	
	ipsec_init_udp_checksum_switch();

	ipsec_init_cookie();

	ipsec_esp_alg_init();
	
	init_vendorid();
	//daemon之前销毁缓冲池中的数据库句柄,使用make_daemon不用加此函数
	sqlite3_clear_buffer_ex();  
	{
		{
			pid_t pid = fork();

			if (pid < 0)
			{
				int e = errno;
				fprintf(stderr, "pluto: fork failed (%d %s)\n",errno, strerror(e));
				exit_pluto(1);
			}

			if (pid != 0)
			{
				/* parent: die, after filling PID into lock file.
				* must not use exit_pluto: lock would be removed!
				*/
				exit(fill_lock(lockfd, pid)? 0 : 1);
			}
		}

		if (setsid() < 0)
		{
			int e = errno;
			fprintf(stderr, "setsid() failed in main(). Errno %d: %s\n",errno, strerror(e));
			exit_pluto(1);	
		}
	}

	/** Close everything but  and (if needed) stderr.
	* There is some danger that a library that we don't know
	* about is using some fd that we don't know about.
	* I guess we'll soon find out.
	*/
	{
		int i;

		for (i = getdtablesize() - 1; i >= 0; i--)  /* Bad hack */
		{
			close(i);
		}

		/* make sure that stdin, stdout, stderr are reserved */
		if (open("/dev/null", O_RDONLY) != 0)
		{
			IPSEC_abort();
		}

		if (dup2(0, 1) != 1)
		{
			IPSEC_abort();
		}
	}
	init_constants();	

	init_pluto_vendorid();
	ipsec_version_code();

    ipsec_get_slot_bit();   // 需要放在ipsec_template_delete_all 前面
    
    ipsec_template_delete_all();    
    
    ipsec_enable_flag(1);
	ipsec_init_nat_traversal();

	init_rnd_pool();

	init_states();
	init_connections();//添加到elist链中phase2 pending timer
	init_crypto();
	ipsec_drv_rsa_para_init();   //初始化使用硬件模幂运算时的固定参数
	load_oswcrypto();
	init_demux();

	/* loading X.509 CA certificates */
	load_authcerts("CA cert", "/config/sys/certificate/cacerts", AUTH_CA);
	/* loading X.509 CRLs */
	load_crls();   
    
	fflush(stderr);
	fflush(stdout);
	
	IPSEC_dbg("listening for IKE messages");	

    init_ws_ctl_socket(); 
    
    /*初始化dpdns守护进程*/
    ipsec_dpdns_init_helper();   

    /*读取DPVPN相关配置并初始化*/
    //ipsec_dpvpn_init_cfg();

    /*该操作放在操作数据库之后的主进程处理不能再数据操作*/
	sqlite3_clear_buffer_ex();      
	/*初始化子进程*/
	ipsec_child_init_helpers();  	

	ipsec_main_call_server();

	return -1;	/* Shouldn't ever reach this */
}
Example #8
0
// This function actually solves the puzzle.
void solve(int cell, int trial, char * puzzle, int * indexes, int maxIndex)
{

// The following can be viewed if compiled with option -DDEBUG
#ifdef DEBUG
printf("Blah-1  cell=%i  trial=%i   indexes[cell]=%i  a=%i\n", cell, trial, indexes[cell], maxIndex);
#endif

if (maxIndex < 0)
{
  return;
}

// Base case (This means we have reaches the last cell)
if (cell > maxIndex)
{
  printf("\nThat was easy!\n\n");
  return;
}

// No possible number for the cell (means we have to go and try different numbers for the previous cells)
if (trial > 9 && cell > 0)
{
  puzzle[indexes[cell]] = '0';
  return solve(cell - 1, chartoint(puzzle[indexes[cell-1]]) + 1, puzzle, indexes, maxIndex);
}

// If no numbers are possible for the first cell then the puzzle is not solvable!
else if (trial > 9 && cell == 0)
{
  printf("Puzzle not solvable\n");
  return;
}

  
// flag keeps track of whether or not the trial is possible for the current cell
int flag = 1;

    
// Rule for vertical columns
for (int f = 0; f < 81; f++)
{
  if ((f % 9) == (indexes[cell] % 9))
  {
    if (puzzle[f] == inttochar(trial))
    {
      flag = 0;         }
    }
}
        
// Rule for horizontal rows
int b = indexes[cell] - (indexes[cell] % 9);
for (int d = 0; d < 9; ++d, ++b)
{
  if (puzzle[b] == inttochar(trial))
  {
    flag = 0;
  }
}

// Rule for sqaures
int c = (indexes[cell]-(indexes[cell] % 27)+(indexes[cell] % 9)-(indexes[cell] % 3));
for (int z = 0; z < 3; z++)
{
  for (int y = 0; y < 3; y++)
  {
    if (puzzle[9*z + y + c] == inttochar(trial))
    {
      flag = 0;
    }
  }
}


// If the trial works go to the next cell
if (flag == 1)
{
  puzzle[indexes[cell]] = inttochar(trial);
  return solve(cell + 1, 1, puzzle, indexes, maxIndex);
}

// Else try the next number
else
{
  return solve(cell, trial + 1, puzzle, indexes, maxIndex);
}
  
}