int struct_create_h2() { int tmpi; char tmpstr[256]; char szFile[256]; char szPath[256]; FILE *fpbase; strcpy( szPath, CLIENT_CREATE_PATH ); struct_reset(); sprintf( szFile, "%s/z_client_struct_auto.lua", szPath ); fpbase = fopen( szFile, "wb" ); if( fpbase == NULL ) return -1; fprintf( fpbase, "--client_struct_auto.lua\r\n\r\n"); fprintf( fpbase, "CMDS_BASE = 0;\r\n" ); fprintf( fpbase, "CMDC_BASE = 0;\r\n" ); fprintf( fpbase, "\r\n" ); for( tmpi = 0; tmpi < g_netscmd_count; tmpi++ ) { if( g_netscmd[tmpi].m_cmdstr[0] ) { strcpy( tmpstr, g_netscmd[tmpi].m_cmdstr ); u_str_toupper( tmpstr ); if( g_netscmd[tmpi].m_cmdid >= 0 ) fprintf( fpbase, "CMDS_%s = CMDS_BASE+%d;\r\n", tmpstr, g_netscmd[tmpi].m_cmdid ); else fprintf( fpbase, "CMDS_%s = CMDS_BASE%d;\r\n", tmpstr, g_netscmd[tmpi].m_cmdid ); } } fprintf( fpbase, "\r\n" ); for( tmpi = 0; tmpi < g_netccmd_count; tmpi++ ) { if( g_netccmd[tmpi].m_cmdid < 0 ) continue; if( g_netccmd[tmpi].m_cmdstr[0] ) { strcpy( tmpstr, g_netccmd[tmpi].m_cmdstr ); u_str_toupper( tmpstr ); if( g_netccmd[tmpi].m_cmdid >= 0 ) fprintf( fpbase, "CMDC_%s = CMDC_BASE+%d;\r\n", tmpstr, g_netccmd[tmpi].m_cmdid ); else fprintf( fpbase, "CMDC_%s = CMDC_BASE%d;\r\n", tmpstr, g_netccmd[tmpi].m_cmdid ); } } fprintf( fpbase, "\r\n" ); fclose( fpbase ); return 0; }
int struct_create_h_srv() { int tmpi, tmpj; char tmpstr[256]; char szFile[256]; char szPath[256]; FILE *fp; strcpy( szPath, SCUI_IN_CREATE_PATH ); struct_reset( "scsrv_in_struct" ); sprintf( szFile, "%s/include/script_auto.h", szPath ); fp = fopen( szFile, "wb" ); if( fp == NULL ) return -1; fprintf( fp, "#ifndef __SCRIPT_auto_H\r\n" ); fprintf( fp, "#define __SCRIPT_auto_H\r\n" ); fprintf( fp, "\r\n" ); fprintf( fp, "void lua_func_register();\r\n" ); fprintf( fp, "void lua_func_function();\r\n" ); fprintf( fp, "\r\n" ); for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, "int sc_%s(", g_struct[tmpi].m_name ); for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count+g_struct[tmpi].m_rtn_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] >= 0 ) continue; if( tmpj > 0 ) fprintf( fp, ", " ); else fprintf( fp, " " ); fprintf( fp, "%s%s", struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, NULL ), g_struct[tmpi].m_arg[tmpj] ); } if( tmpj > 0 ) fprintf( fp, " " ); fprintf( fp, ");\r\n" ); } } fprintf( fp, "\r\n#endif\r\n" ); fclose( fp ); return 0; }
void ft_post_floatflags(long double nb, t_pf *pf) { if (pf->width > 0 && pf->minus == 1 && pf->zero == 0) ft_print_numwidth(nb, 10, pf); struct_reset(pf); }
void ft_post_numflags(unsigned long long int nb, char base, t_pf *pf) { if (pf->width > 0 && pf->minus == 1 && pf->zero == 0) ft_print_numwidth(nb, base, pf); struct_reset(pf); }
void ft_post_charflags(t_pf *pf) { if (pf->width > 0 && pf->minus == 1) ft_print_charwidth(pf); struct_reset(pf); }
void ft_post_wstrflags(wchar_t *str, t_pf *pf) { if (pf->width > 0 && pf->minus == 1) ft_print_wstrwidth(str, pf); struct_reset(pf); }
void struct_create_srv() { int tmpi,tmpj; FILE *fp; char lkset[256]; char tmpstr[256]; char szFile[256]; char szPath[256]; struct_reset( "scsrv_in_struct" ); strcpy( szPath, SCUI_IN_CREATE_PATH ); sprintf( szFile, "%s/src/script_auto.cpp", szPath ); fp = fopen( szFile, "wb" ); if( fp == NULL ) return; fprintf( fp, "extern \"C\" {\r\n" ); fprintf( fp, " #include \"lua.h\"\r\n" ); fprintf( fp, " #include \"lualib.h\"\r\n" ); fprintf( fp, " #include \"lauxlib.h\"\r\n" ); fprintf( fp, "}\r\n" ); fprintf( fp, "\r\n" ); fprintf( fp, "#include \"script.h\"\r\n" ); fprintf( fp, "#include \"define.h\"\r\n" ); fprintf( fp, "#include \"thread.h\"\r\n" ); fprintf( fp, "#include \"utils.h\"\r\n" ); fprintf( fp, "\r\n" ); fprintf( fp, "extern lua_State* servL;\r\n" ); fprintf( fp, "//--Automatically define function\r\n" ); fprintf( fp, "\r\n" ); for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, "static int _%s_ref;\r\n", g_struct[tmpi].m_name ); } } fprintf( fp, "\r\n" ); fprintf( fp, "void lua_func_function()\r\n{\r\n" ); for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, " lua_getglobal(servL, \"IN_%s\");\r\n", g_struct[tmpi].m_name ); fprintf( fp, " _%s_ref = luaL_ref( servL, LUA_REGISTRYINDEX );\r\n", g_struct[tmpi].m_name ); } } fprintf( fp, "}\r\n" ); fprintf( fp, "\r\n" ); for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, "int sc_%s(", g_struct[tmpi].m_name ); for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] >= 0 ) continue; if( tmpj > 0 ) fprintf( fp, ", " ); else fprintf( fp, " " ); fprintf( fp, "%s%s", struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, NULL ), g_struct[tmpi].m_arg[tmpj] ); } if( tmpj > 0 ) fprintf( fp, " " ); for ( tmpj = 0; tmpj < g_struct[tmpi].m_rtn_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] <= 0 ) continue; if( tmpj > 0 ) fprintf( fp, ", " ); else fprintf( fp, " " ); fprintf( fp, "%s*%s", struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, NULL ), g_struct[tmpi].m_arg[tmpj] ); } if( tmpj > 0 ) fprintf( fp, " " ); fprintf( fp, ")\r\n{\r\n" ); fprintf( fp, " int nResult = 0;\r\n" ); fprintf( fp, " lua_rawgeti( servL, LUA_REGISTRYINDEX, _%s_ref );\r\n", g_struct[tmpi].m_name ); for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] >= 0 ) continue; struct_getdatatype( -g_struct[tmpi].m_type[tmpj], tmpstr, lkset ); fprintf( fp, " %s( servL, %s );\r\n", lkset, g_struct[tmpi].m_arg[tmpj] ); } if ( g_struct[tmpi].m_rtn_count > 1 ) { fprintf( fp, " lua_call( servL, %d, %d );\r\n", g_struct[tmpi].m_arg_count, g_struct[tmpi].m_rtn_count ); for ( tmpj = 0; tmpj < g_struct[tmpi].m_rtn_count; tmpj++ ) { fprintf( fp, " *%s = (int)lua_tonumber( servL, %d );\r\n", g_struct[tmpi].m_arg[tmpj], -(tmpj+1) ); fprintf( fp, " lua_pop( servL, %d );\r\n", g_struct[tmpi].m_rtn_count ); } fprintf( fp, " return nResult;\r\n" ); } else { fprintf( fp, " lua_call( servL, %d, 1 );\r\n", g_struct[tmpi].m_arg_count ); fprintf( fp, " nResult = (int)lua_tonumber( servL, -1 );\r\n" ); fprintf( fp, " lua_pop( servL, 1 );\r\n" ); fprintf( fp, " return nResult;\r\n" ); } fprintf( fp, "}\r\n" ); fprintf( fp, "\r\n" ); } } fclose( fp ); }
void struct_create_srvreg() { int tmpi,tmpj; FILE *fp; char lkset[256]; char tmpstr[256]; char szFile[256]; char szPath[256]; char **linebuf = NULL; int linecount; char has; int isbegin; struct_reset( "scsrv_c_struct" ); strcpy( szPath, SCUI_IN_CREATE_PATH ); sprintf( szFile, "%s/src/script_reg_auto.cpp", szPath ); fp = fopen( szFile, "rb" ); if( fp != NULL ) { linebuf = u_load_file( fp, &linecount ); fclose( fp ); } fp = fopen( szFile, "wb" ); if( fp == NULL ) return; if( linebuf == NULL ) { fprintf( fp, "extern \"C\" {\r\n" ); fprintf( fp, " #include \"lua.h\"\r\n" ); fprintf( fp, " #include \"lualib.h\"\r\n" ); fprintf( fp, " #include \"lauxlib.h\"\r\n" ); fprintf( fp, "}\r\n" ); fprintf( fp, "#include \"script.h\"\r\n" ); fprintf( fp, "#include \"define.h\"\r\n" ); fprintf( fp, "#include \"thread.h\"\r\n" ); fprintf( fp, "#include \"utils.h\"\r\n" ); fprintf( fp, "\r\n" ); fprintf( fp, "extern lua_State* servL;\r\n" ); fprintf( fp, "//--Automatically define function\r\n" ); } else { for( tmpi = 0; tmpi < linecount; tmpi++ ) { fprintf( fp, "%s\n", linebuf[tmpi] ); if( u_frontcmp( linebuf[tmpi], "//--Automatically define function" ) ) break; } } for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, "static int lua_%s( lua_State *servL );\r\n", g_struct[tmpi].m_name ); } } fprintf( fp, "\r\n" ); fprintf( fp, "void lua_func_register()\r\n{\r\n" ); for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { fprintf( fp, " lua_register(servL, \"%s\", lua_%s);\r\n", g_struct[tmpi].m_name, g_struct[tmpi].m_name ); } } fprintf( fp, "}\r\n" ); fprintf( fp, "\r\n" ); if( linebuf == NULL ) { fprintf( fp, "//--Automatically main function\r\n" ); } else { isbegin = 0; for( tmpi = 0; tmpi < linecount; tmpi++ ) { if( isbegin == 0 && u_frontcmp( linebuf[tmpi], "//--Automatically main function" ) ) isbegin = tmpi+1; if( isbegin == 0 ) continue; fprintf( fp, "%s\n", linebuf[tmpi] ); } } for( tmpi = 0; tmpi < g_struct_count; tmpi++ ) { if( g_struct[tmpi].m_name[0] ) { has = 0; if( linebuf ) { sprintf( tmpstr, "static int lua_%s( lua_State *servL )", g_struct[tmpi].m_name ); for( tmpj = isbegin; tmpj < linecount; tmpj++ ) { if( u_frontcmp( linebuf[tmpj], tmpstr ) ) { has = 1; break; } } } if( has ) continue; fprintf( fp, "static int lua_%s( lua_State *servL )\r\n{\r\n", g_struct[tmpi].m_name ); fprintf( fp, " int num = lua_gettop(servL);\r\n" ); if( g_struct[tmpi].m_limit_count > 0 ) fprintf( fp, " if ( num < %d )\r\n", g_struct[tmpi].m_limit_count ); else fprintf( fp, " if ( num != %d )\r\n", g_struct[tmpi].m_arg_count ); fprintf( fp, " {\r\n" ); fprintf( fp, " char szErrorMsg[128];\r\n" ); fprintf( fp, " sprintf( szErrorMsg, \"Incorrect argument to function '%%s'\", __FUNCTION__ );\r\n" ); fprintf( fp, " lua_pushstring( servL, szErrorMsg );\r\n" ); fprintf( fp, " lua_error( servL );\r\n" ); fprintf( fp, " return 0;\r\n" ); fprintf( fp, " }\r\n" ); for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count+g_struct[tmpi].m_rtn_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] >= 0 ) continue; struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, lkset ); if( g_struct[tmpi].m_limit_count > 0 && tmpj >= g_struct[tmpi].m_limit_count ) { fprintf( fp, " %s%s = 0; if( num > %d ) %s = (%s)%s( servL, %d );\r\n", tmpstr, g_struct[tmpi].m_arg[tmpj], tmpj, g_struct[tmpi].m_arg[tmpj], tmpstr, lkset, tmpj+1 ); } else { fprintf( fp, " %s%s = (%s)%s( servL, %d );\r\n", tmpstr, g_struct[tmpi].m_arg[tmpj], tmpstr, lkset, tmpj+1 ); } } fprintf( fp, " //--Process script\r\n" ); for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count+g_struct[tmpi].m_rtn_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] <= 0 ) continue; struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, lkset ); fprintf( fp, " %s%s = 0;\r\n", tmpstr, g_struct[tmpi].m_arg[tmpj] ); } for( tmpj = 0; tmpj < g_struct[tmpi].m_arg_count+g_struct[tmpi].m_rtn_count; tmpj++ ) { if( g_struct[tmpi].m_type[tmpj] <= 0 ) continue; struct_getdatatype( g_struct[tmpi].m_type[tmpj], tmpstr, lkset ); fprintf( fp, " %s( servL, %s );\r\n", lkset, g_struct[tmpi].m_arg[tmpj] ); } fprintf( fp, " return %d;\r\n", g_struct[tmpi].m_rtn_count ); fprintf( fp, "}\r\n" ); fprintf( fp, "\r\n" ); } } fclose( fp ); if( linebuf ) u_free_vec( linebuf ); }