/* * Construct system object and reset some global variables */ void create_system(void) { int i; amsys = (SYS_OBJECT) malloc(sizeof *amsys); if (!amsys) { fprintf(stderr, "Mamnuts: Failed to create system object in create_system().\n"); boot_exit(21); return; } memset(amsys, 0, (sizeof *amsys)); #ifdef NETLINKS amsys->auto_connect = 1; #endif amsys->max_users = 50; amsys->max_clones = 1; amsys->ban_swearing = 0; amsys->heartbeat = 2; #ifdef NETLINKS amsys->keepalive_interval = 60; /* DO NOT TOUCH!!! */ amsys->net_idle_time = 300; /* Must be > than the above */ #endif amsys->login_idle_time = 180; amsys->user_idle_time = 300; amsys->time_out_afks = 0; #ifdef WIZPORT amsys->wizport_level = WIZ; #endif amsys->minlogin_level = NUM_LEVELS; amsys->mesg_life = 1; amsys->num_of_users = 0; amsys->num_of_logins = 0; amsys->logging = SYSLOG | REQLOG | NETLOG | ERRLOG; amsys->ignore_sigterm = 0; amsys->crash_action = 0; amsys->prompt_def = 1; amsys->colour_def = 1; amsys->charecho_def = 0; amsys->passwordecho_def = 0; amsys->time_out_maxlevel = USER; amsys->mesg_check_hour = 0; amsys->mesg_check_min = 0; amsys->mesg_check_done = -1; amsys->rs_countdown = 0; amsys->rs_announce = 0; amsys->rs_which = -1; amsys->rs_user = NULL; amsys->gatecrash_level = NUM_LEVELS; /* minimum user level which can enter private rooms */ amsys->min_private_users = 2; /* minimum num. of users in room before can set to priv */ amsys->ignore_mp_level = GOD; /* User level which can ignore the above var. */ #ifdef NETLINKS amsys->rem_user_maxlevel = USER; amsys->rem_user_deflevel = USER; #endif amsys->logons_old = 0; amsys->logons_new = 0; amsys->purge_count = 0; amsys->purge_skip = 0; amsys->users_purged = 0; amsys->auto_purge_date = -1; amsys->suggestion_count = 0; amsys->forwarding = 1; amsys->user_count = 0; amsys->allow_recaps = 1; amsys->auto_promote = 1; amsys->personal_rooms = 1; amsys->startup_room_parse = 1; amsys->motd1_cnt = 0; amsys->motd2_cnt = 0; amsys->random_motds = 1; amsys->last_cmd_cnt = 0; amsys->resolve_ip = 1; /* auto resolve ip */ amsys->flood_protect = 1; amsys->boot_off_min = 0; amsys->stop_logins = 0; *amsys->default_warp = '\0'; *amsys->default_jail = '\0'; #ifdef GAMES *amsys->default_bank = '\0'; *amsys->default_shoot = '\0'; #endif amsys->mport_socket = -1; *amsys->mport_port = '\0'; #ifdef WIZPORT amsys->wport_socket = -1; *amsys->wport_port = '\0'; #endif #ifdef NETLINKS amsys->nlink_socket = -1; *amsys->nlink_port = '\0'; *amsys->verification = '\0'; #endif #ifdef IDENTD amsys->ident_pid = 0; amsys->ident_socket = -1; amsys->ident_state = 0; #endif amsys->is_pager = 0; time(&amsys->boot_time); if (uname(&amsys->uts) < 0) { *amsys->uts.sysname = '\0'; *amsys->uts.machine = '\0'; *amsys->uts.release = '\0'; *amsys->uts.version = '\0'; *amsys->uts.nodename = '\0'; strncat(amsys->uts.sysname, "[undetermined]", (sizeof amsys->uts.sysname)); strncat(amsys->uts.machine, "[undetermined]", (sizeof amsys->uts.machine)); strncat(amsys->uts.release, "[undetermined]", (sizeof amsys->uts.release)); strncat(amsys->uts.version, "[undetermined]", (sizeof amsys->uts.version)); strncat(amsys->uts.nodename, "[undetermined]", (sizeof amsys->uts.nodename)); } user_first = NULL; user_last = NULL; room_first = NULL; room_last = NULL; /* This variable is not used yet */ first_user_entry = NULL; last_user_entry = NULL; first_command = NULL; force_listen = 0; no_prompt = 0; logon_flag = 0; for (i = 0; i < LASTLOGON_NUM; ++i) { *last_login_info[i].name = '\0'; *last_login_info[i].time = '\0'; last_login_info[i].on = 0; } for (i = 0; i < 16; ++i) { *cmd_history[i] = '\0'; } clear_words(); #ifdef NETLINKS nl_first = NULL; nl_last = NULL; #endif }
/*** Construct system object and reset some global variables ***/ void create_system(void) { int i; struct utsname uts; set_crash(); if ((amsys=(SYS_OBJECT)malloc(sizeof(struct system_struct)))==NULL) { fprintf(stderr,"Lotos: Failed to create system object in create_system().\n"); boot_exit(21); } amsys->auto_connect=1; amsys->max_users=50; amsys->max_clones=1; amsys->ban_swearing=0; amsys->heartbeat=2; amsys->keepalive_interval=60; /* DO NOT TOUCH!!! */ amsys->net_idle_time=300; /* Must be > than the above */ amsys->login_idle_time=180; amsys->user_idle_time=300; amsys->time_out_afks=0; amsys->wizport_level=WIZ; amsys->minlogin_level=-1; amsys->mesg_life=1; amsys->num_of_logins=0; amsys->logging=BIT_SET(amsys->logging,SYSLOG); amsys->logging=BIT_SET(amsys->logging,REQLOG); #ifdef NETLOG amsys->logging=BIT_SET(amsys->logging,NETLOG); #endif #ifdef DEBUG amsys->logging=BIT_SET(amsys->logging,DEBLOG); #endif amsys->logging=BIT_SET(amsys->logging,ERRLOG); amsys->password_echo=0; amsys->ignore_sigterm=0; amsys->crash_action=2; amsys->prompt_def=1; amsys->colour_def=1; amsys->charecho_def=0; amsys->time_out_maxlevel=USER; amsys->mesg_check_hour=0; amsys->mesg_check_min=0; amsys->rs_countdown=0; amsys->rs_announce=0; amsys->rs_which=-1; amsys->rs_user=NULL; amsys->gatecrash_level=GOD+1; /* minimum user level which can enter private rooms */ amsys->min_private_users=2; /* minimum num. of users in room before can set to priv */ amsys->ignore_mp_level=GOD; /* User level which can ignore the above var. */ amsys->rem_user_maxlevel=USER; amsys->rem_user_deflevel=USER; amsys->logons_old=0; amsys->logons_new=0; amsys->purge_count=0; amsys->purge_skip=0; amsys->users_purged=0; amsys->purge_date=1; amsys->suggestion_count=0; amsys->forwarding=1; amsys->auto_purge=0; amsys->user_count=0; amsys->auto_promote=1; amsys->personal_rooms=1; amsys->startup_room_parse=1; amsys->motd1_cnt=0; amsys->motd2_cnt=0; amsys->random_motds=1; amsys->last_cmd_cnt=0; amsys->resolve_ip=1; /* auto resolve ip */ amsys->flood_protect=1; amsys->pid=(unsigned int)getpid(); time(&amsys->boot_time); if ((uname(&uts))<0) { strcpy(amsys->sysname,"[undetermined]"); strcpy(amsys->sysmachine,"[undetermined]"); strcpy(amsys->sysrelease,"[undetermined]"); strcpy(amsys->sysversion,"[undetermined]"); strcpy(amsys->sysnodename,"[undetermined]"); } else { strncpy(amsys->sysname,uts.sysname,63); strncpy(amsys->sysmachine,uts.machine,63); strncpy(amsys->sysrelease,uts.release,63); strncpy(amsys->sysversion,uts.version,63); strncpy(amsys->sysnodename,uts.nodename,63); } user_first=NULL; user_last=NULL; room_first=NULL; room_last=NULL; /* This variable isn't used yet */ transport_first=NULL; transport_last=NULL; first_dir_entry=NULL; first_command=NULL; first_wiz_entry=NULL; last_wiz_entry=NULL; force_listen=0; no_prompt=0; logon_flag=0; for (i=0;i<port_total;i++) { port[i]=0; listen_sock[i]=0; } for (i=0;i<LASTLOGON_NUM;i++) { last_login_info[i].name[0]='\0'; last_login_info[i].time[0]='\0'; last_login_info[i].on=0; } for (i=0;i<16;i++) cmd_history[i][0]='\0'; clear_words(); #ifdef NETLINKS verification[0]='\0'; nl_first=NULL; nl_last=NULL; #endif strcpy(susers_restrict, RESTRICT_MASK); }
paramsettings::~paramsettings() { delete ui; clear_words(); }
int main(int argc, char *argv[]) { uint32_t i, j, n; double runtime, memused; int32_t x, *val; if (argc != 2) { fprintf(stderr, "Usage: %s filename\n", argv[0]); fprintf(stderr, " filename must contain a set of strings, one per line, less than 100 char long\n"); fflush(stderr); exit(1); } words_from_file(argv[1]); init_stbl(&sym_table, 0); val = (int32_t *) malloc(n_words * sizeof(int32_t)); if (val == NULL) { fprintf(stderr, "Failed to allocate array val\n"); exit(1); } for (i=0; i<n_words; i++) { x = stbl_find(&sym_table, words[i]); if (x < 0) { stbl_add(&sym_table, words[i], i); val[i] = i; } else { val[i] = x; } } printf("\n--- checking ---\n"); for (i=0; i<n_words; i++) { x = stbl_find(&sym_table, words[i]); if (x != val[i]) { printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[i], x, val[i]); fflush(stdout); exit(1); } } printf("\n*** Added %"PRIu32" words from %s ***\n", n_words, argv[1]); // repeated additions of the same symbols with multiple lookups // warning: this code does not work (may give a false alarm) // if the input file contains duplicates. n = (n_words < 200) ? n_words : 200; printf("\n*** Repeated symbol addition ***\n"); runtime = get_cpu_time(); for (i=0; i<10000; i++) { for (j=0; j<n; j++) { stbl_add(&sym_table, words[j], new_val(i, j)); } for (j=0; j<n; j++) { x = stbl_find(&sym_table, words[j]); if (x != new_val(i, j)) { printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j)); fflush(stdout); exit(1); } } for (j=0; j<n; j++) { x = stbl_find(&sym_table, words[j]); if (x != new_val(i, j)) { printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j)); fflush(stdout); exit(1); } } for (j=0; j<n_words; j++) { x = stbl_find(&sym_table, words[j]); } for (j=0; j<n; j++) { x = stbl_find(&sym_table, words[j]); if (x != new_val(i, j)) { printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j)); fflush(stdout); exit(1); } } for (j=0; j<n_words; j++) { x = stbl_find(&sym_table, words[j]); } } runtime = get_cpu_time() - runtime; memused = mem_size() / (1024 * 1024); printf("Adding 10000 times the same %"PRIu32" words + repeated lookups\n", n); printf("Runtime: %.4f s\n", runtime); printf("Table size: %"PRIu32" (nelems = %"PRIu32", ndeleted = %"PRIu32")\n", sym_table.size, sym_table.nelems, sym_table.ndeleted); if (memused > 0) { printf("Memory used: %.2f MB\n", memused); } clear_words(); free(val); delete_stbl(&sym_table); return 0; }