/* Dumps a range of bucket's(in sequence) bit values into the given file @param Bitmapper* the mapepr object to use @param FILE* the file pointer to the opened file @param unsigned long long int start index to the bucket to consider(inclusive) @param unsigned long long int end index to the bucket to consider(inclusive) */ int dump_bucket_range_str_to_file(Bitmapper* map, FILE* fp, unsigned long long int start, unsigned long long int end){ BitBucket* tmp; unsigned long long int i; FileBuffer buf; if(map->bkt_count<=end) return 1; buf.buffer = '\0'; buf.buff_fill_count = 0; buf.string = (unsigned char*)malloc(map->bkt_size/8+1); buf.str_length = map->bkt_size; for(i=start; i<=end ;i++){ if(map->bkts[i] == NULL) tmp = bit_bucket_create(map->bkt_size); else tmp = map->bkts[i]; bit_bucket_string(tmp, buf.string); append_to_file(fp, buf); if(map->bkts[i] == NULL) bit_bucket_free(tmp); } if(buf.string != NULL) free(buf.string); buf.str_length = 0; append_to_file(fp, buf); return 0; }
/* * the main method (including program loop) */ int main(int argc, char* argv[]) { Event* event = read_data(); int running = 1; int input; int t_index = 0; /* the index for the times */ char* times_file; char* log_file; printf("Please enter times file: "); times_file = readline(); printf("Please enter log file: "); log_file = readline(); t_index = refresh(event, times_file, t_index); display_event_header(event); while (running) { input = display_menu(event); t_index = refresh(event, times_file, t_index); switch (input) { case 1: locate_entrant(event); append_to_file(log_file, "EM: entrant query"); break; case 2: printf("\t%d\n", count_by_status(event, NOT_STARTED)); append_to_file(log_file, "EM: entrants counted - not started"); break; case 3: printf("\t%d\n", count_by_status(event, STARTED) + count_by_status(event, STOPPED)); append_to_file(log_file, "EM: entrants counted - running"); break; case 4: printf("\t%d\n", count_by_status(event, FINISHED)); append_to_file(log_file, "EM: entrants counted - finished"); break; case 5: list_excluded_safety(event); append_to_file(log_file, "EM: entrants listed - excluded"); break; case 6: list_excluded_incorrect(event); append_to_file(log_file, "EM: entrants listed - disqualified"); break; case 7: display_results(event); append_to_file(log_file, "EM: results displayed"); break; case 8: running = 0; append_to_file(log_file, "EM: quitting"); break; default: /* invalid input, do nothing */ break; } } return EXIT_SUCCESS; }
// --------------------------------------------------------------------------- /// Converts given file to legacy vtk format: extracts separate data chunks /// into tmp files and than merges all of them using 'append_to_file'. // --------------------------------------------------------------------------- static void convert_to_vtk (const char *name_in, const char *name_out) { FILE *fin = cfg_open(name_in, "rt", __func__), *fpoints = cfg_open(".points", "wt", __func__), *fspeeds = cfg_open(".speeds", "wt", __func__), *fcharge = cfg_open(".charge", "wt", __func__); int N = 0; char x[31], y[31], z[31], u[31], v[31], w[31], rho[31]; while (7 == fscanf(fin, "%30s %30s %30s %30s %30s %30s %30s ", x, y, z, u, v, w, rho)) { fprintf(fpoints, "%s %s %s\n", x, y, z); fprintf(fspeeds, "%s %s %s\n", u, v, w); fprintf(fcharge, "%s\n", rho); N++; } fclose(fin); fclose(fpoints); fclose(fspeeds); fclose(fcharge); fflush(NULL); FILE *res = cfg_open(name_out, "wt", __func__); fprintf(res, "# vtk DataFile Version 2.0\n" "Particles distribution.\n" "ASCII\n" "\n" "DATASET UNSTRUCTURED_GRID\n" "POINTS %d float\n", N); append_to_file(res, ".points"); fprintf(res, "\n\n" "CELL_TYPES 2\n" "1\n" "1\n" "\n" "POINT_DATA %d\n" "VECTORS speed float\n", N); append_to_file(res, ".speeds"); fprintf(res, "\n\n" "SCALARS charge float 1\n" "LOOKUP_TABLE default\n"); append_to_file(res, ".charge"); fclose(res); }
// update items array into file static int store_history_item_array(history_value_item_t* items, int count) { update_history_values_header(count); append_to_file(g_history_path, items, sizeof(history_value_item_t) * count); cross_date_switch(); return STATUS_OK; }
bool core::archive::image_cache::update_file_from_tmp_files() { const bool to_add_exists = tools::system::is_exist(tmp_to_add_storage_->get_file_name()); if (to_add_exists) { images_map_t to_add; if (!read_file(*tmp_to_add_storage_, to_add)) return false; add_images_to_tree(to_add); if (!append_to_file(*storage_, to_add)) return false; } const bool to_delete_exists = tools::system::is_exist(tmp_to_delete_storage_->get_file_name()); if (to_delete_exists) { bool need_to_save_all = false; if (!process_deleted(need_to_save_all)) return false; if (need_to_save_all && !save_all()) return false; } delete_tmp_files(); return true; }
int update_data_group(int data_group) { g_data_group = data_group; g_statistics_header.data_group = data_group; g_statistics_header_offset = get_file_length(g_statistics_path); if (g_statistics_header_offset < 0) return STATUS_FAILED; if (append_to_file(g_statistics_path, &g_statistics_header, sizeof(statistics_header_t)) != STATUS_OK) return STATUS_FAILED; g_history_values_header.data_group = data_group; g_history_values_header_offset = get_file_length(g_history_path); if (g_history_values_header_offset < 0) return STATUS_FAILED; if (append_to_file(g_history_path, &g_history_values_header, sizeof(history_values_header_t)) != STATUS_OK) return STATUS_FAILED; return STATUS_OK; }
int update_user_name(char* user_name) { strncpy(g_user_name, user_name, USER_NAME_LENGTH - 1); strncpy(g_statistics_header.user_name, user_name, USER_NAME_LENGTH - 1); g_statistics_header_offset = get_file_length(g_statistics_path); if (g_statistics_header_offset < 0) return STATUS_FAILED; if (append_to_file(g_statistics_path, &g_statistics_header, sizeof(statistics_header_t)) != STATUS_OK) return STATUS_FAILED; strncpy(g_history_values_header.user_name, user_name, USER_NAME_LENGTH - 1); g_history_values_header_offset = get_file_length(g_history_path); if (g_history_values_header_offset < 0) return STATUS_FAILED; if (append_to_file(g_history_path, &g_history_values_header, sizeof(history_values_header_t)) != STATUS_OK) return STATUS_FAILED; return STATUS_OK; }
void add_member(char *name, char *shortname) { char buf[MAX_STRING_LENGTH]; char fbuf[MAX_STRING_LENGTH]; if(name[0] == '\0' || !name) { bug("add_member: No name!\n\r"); return; } if(shortname[0] == '\0' || !shortname) { bug("add_member: No shortname!\n\r"); return; } sprintf(fbuf, "%s%s.list", CLAN_DIR, shortname); sprintf(buf, "%s~", name); append_to_file(fbuf, buf); } void remove_member(char *name, char *shortname) {
void input_string(char *op, user_info *p) { //read and process user input printf("Enter name: "); fflush(stdout); fgets(p->name, 30, stdin); //sets last char of input to be end string char p->name[strlen(p->name)-1] = '\0'; //read and process user input printf("Enter phone number: "); fflush(stdout); fgets(p->phonenumber, 20, stdin); //sets last char of input to be end string char p->phonenumber[strlen(p->phonenumber)-1] = '\0'; //read and process user input printf("Enter student number: "); fflush(stdout); fgets(p->studentnum, 20, stdin); //sets last char of input to be end string char p->studentnum[strlen(p->studentnum)-1] = '\0'; //if user wishes to write new file if(*op == 'w') { //calls function to write new file, overwriting existing file write_to_file(p); } //if user wishes to append data to end of file else if(*op == 'a') { //calls function to append data to end of existing file, //keeping existing data intact. append_to_file(p); } //prints current struct data to screen output_string(p); }//end input function
void advance_class_level( CHAR_DATA *ch ) { /* ONLY called for multiclasses */ int level = 0; if ( ch->firstexp >= exp_class_level( ch, ch->firstlevel + 1, ch->Class ) ) { /* Levelled */ ch_printf( ch, "\r\n&WYou have now obtained %s level %d!&D\r\n", class_table[ch->Class]->who_name, ++ch->firstlevel ); ch->firstexp = URANGE( 0, ( ch->firstexp - exp_class_level( ch, ch->firstlevel, ch->Class ) ), ch->firstexp ); advance_level( ch ); } if ( IS_SECONDCLASS( ch ) && ch->secondexp >= exp_class_level( ch, ch->secondlevel + 1, ch->secondclass ) ) { /* Again */ ch_printf( ch, "\r\n&WYou have now obtained %s level %d!&D\r\n", class_table[ch->secondclass]->who_name, ++ch->secondlevel ); ch->secondexp = URANGE( 0, ( ch->secondexp - exp_class_level( ch, ch->secondlevel, ch->secondclass ) ), ch->secondexp ); advance_level( ch ); } if ( IS_THIRDCLASS( ch ) && ch->thirdexp >= exp_class_level( ch, ch->thirdlevel + 1, ch->thirdclass ) ) { /* Made * a * level! */ ch_printf( ch, "\r\n&WYou have now obtained %s level %d!&D\r\n", class_table[ch->thirdclass]->who_name, ++ch->thirdlevel ); ch->thirdexp = URANGE( 0, ( ch->thirdexp - exp_class_level( ch, ch->thirdlevel, ch->thirdclass ) ), ch->thirdexp ); advance_level( ch ); } if ( IS_THIRDCLASS( ch ) ) level = ( ( ch->firstlevel + 1 + ch->secondlevel + ch->thirdlevel ) / 3 ); else if ( IS_SECONDCLASS( ch ) ) level = ( ( ch->firstlevel + 1 + ch->secondlevel ) / 2 ); else level = ( ch->firstlevel + 1 ); if ( level > ch->level ) { /* Should have gained! */ char buf[MSL]; if ( xIS_SET( ch->act, PLR_EXTREME ) ) { ch_printf( ch, "&GPlaying 6D EXTREME you gain 5 glory!&D\r\n" ); ch->quest_curr += 5; } ch_printf( ch, "\r\n&WYou have now obtained an overall experience level %d!&D\r\n", ++ch->level ); restore_char( ch ); send_to_char_color( "&YYou have gained insight in the realms, and have been restored!\r\n", ch ); snprintf( buf, MSL, "The realms rejoice as %s has just achieved level %d!&D", ch->name, ch->level ); announce( buf ); snprintf( buf, MSL, "%24.24s: %s obtained level %d!%s%s&D", ctime( ¤t_time ), ch->name, ch->level, ( doubleexp ? " (Double)" : "" ), ( happyhouron ? " (HappyHour)" : "" ) ); append_to_file( PLEVEL_FILE, buf ); } }
static void populate_multiboot(struct dirent *root, struct bootinfo *bi) { lvaddr_t data; size_t len; errval_t err; assert(root != NULL); // create bootscript file struct dirent *bootscript_f; err = ramfs_create(root, BOOTSCRIPT_FILE_NAME, &bootscript_f); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error creating bootscript file"); } debug_printf("pre-populating from boot image...\n"); for (int i = 0; i < bi->regions_length; i++) { struct mem_region *region = &bi->regions[i]; if (region->mr_type != RegionType_Module) { /* Not of module type */ continue; } const char *name = remove_prefix(multiboot_module_name(region)); // is this a ramfs image we should unpack? if (strstr(name, "_ramfs.cpio.gz") != NULL) { debug_printf("unpacking Gzipped CPIO %s\n", name); err = spawn_map_module(region, &len, &data, NULL); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error in spawn_map_module"); } err = unpack_cpiogz(root, (void *)data, len); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error unpacking ramfs image"); } // TODO: unmap } else if (strstr(name, "_ramfs.cpio") != NULL) { debug_printf("unpacking CPIO %s\n", name); err = spawn_map_module(region, &len, &data, NULL); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error in spawn_map_module"); } err = unpack_cpio(root, (void *)data, len); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error unpacking ramfs image"); } // TODO: unmap } else { // map the image err = getimage(region, &len, &data); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error in getimage"); } // copy to ramfs err = write_file(root, name, (void *)data, len); if (err_is_fail(err)) { if (err_no(err) == FS_ERR_EXISTS) { debug_printf("%s already exists, skipping it\n", name); } else { USER_PANIC_ERR(err, "error in write_file"); } } // TODO: unmap // append line to bootscript const char *args = remove_prefix(multiboot_module_rawstring(region)); err = append_to_file(bootscript_f, args); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error appending to bootscript"); } } } debug_printf("ready\n"); }
int store_one_statistics_item(statistics_item_t* item) { update_statistics_header(); return append_to_file(g_statistics_path, item, sizeof(statistics_item_t)); }
void DBSystem::insertRecord(string tableName, string record) { string table; //get pagefile count int pagefile_count = DiskMap[tableName].size(); //tokenize record vector<string>record_row = tokenize(record); PageFileInfo temp = *(DiskMap[tableName].rbegin()); int pgno = checkRecordInMemory(tableName, temp.end_record_id); int already_in_mem = 1; //bring record in memory, if not present if(pgno == -1) { already_in_mem = 0; pgno = getRecordIntoMemory(tableName, temp.end_record_id); } //assuming page already in memory, try to insert if(MainMemory[pgno].insert_record(record_row, page_size) != -1) { //update record IDs in DiskMap temp.end_record_id++; *(DiskMap[tableName].rbegin()) = temp; //write to page file PageFileInfo pfi; char intconversionptr[16]; sprintf(intconversionptr,"%d", pagefile_count - 1); pfi.path = pagefilepath + tableName + "_PageFile_" + string(intconversionptr) + ".csv"; MainMemory[pgno].write_page_file(pfi.path); //write to original CSV file table = path + tableName + ".csv"; append_to_file(table, record); LRU_timer++; MainMemory[pgno].LRU_age = LRU_timer; return; } else { //page not in memory, but new record cant be inserted if(already_in_mem == 0) { PageFileInfo pfi; pfi.start_record_id = temp.end_record_id + 1; //record can't be inserted into current page, insert into new page MainMemory[pgno].generate_page(tableName, temp.end_record_id + 1); pfi.end_record_id = MainMemory[pgno].insert_record(record_row, page_size); // This is why C++ sucks sweaty donkey balls; // TODO: Fix this to use sstream/ostream magic. char intconversionptr[16]; sprintf(intconversionptr,"%d", pagefile_count); // Damn you C++, just give me a to_string() already. pfi.path = pagefilepath + tableName + "_PageFile_" + string(intconversionptr) + ".csv"; MainMemory[pgno].write_page_file(pfi.path); //write to original CSV file table = path + tableName + ".csv"; append_to_file(table, record); LRU_timer++; MainMemory[pgno].LRU_age = LRU_timer; DiskMap[tableName].push_back(pfi); } //page in memory, but new record cant be inserted else { PageFileInfo pfi; pfi.start_record_id = temp.end_record_id + 1; // Find LRU Page. int min_index = 0; for(int i=1; i<num_pages; i++){ if(MainMemory[i].LRU_age < MainMemory[min_index].LRU_age) min_index = i; } pgno = min_index; //record can't be inserted into current page, insert into new page MainMemory[pgno].generate_page(tableName, temp.end_record_id + 1); pfi.end_record_id = MainMemory[pgno].insert_record(record_row, page_size); // TODO: Fix this to use sstream/ostream magic. char intconversionptr[16]; sprintf(intconversionptr,"%d", pagefile_count); pfi.path = pagefilepath + tableName + "_PageFile_" + string(intconversionptr) + ".csv"; MainMemory[pgno].write_page_file(pfi.path); //write to original CSV file table = path + tableName + ".csv"; append_to_file(table, record); LRU_timer++; MainMemory[pgno].LRU_age = LRU_timer; DiskMap[tableName].push_back(pfi); } } }
int bootup_main(int argc, char **argv) { FILE *fp; DIR *dp; struct dirent *dt; int t=0, rc; char cmd[1024], buf[1024], name[1024]; time_t curtime; struct tm *loctime; signal(SIGINT,SIG_IGN); putenv("PATH=/bin"); putenv("TERM=linux"); umask(0770); chdir("/"); putchar('\n'); print_banner(); putchar('\n'); xsystem("mount -t proc -o ro virtual /proc"); xsystem("mount -t sysfs -o ro virtual /sys"); // STAGE 1 calculate_mem(); fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE); xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE); chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC); chdir("/ramd"); if((dp=opendir("/")) == NULL) { perror("opendir"); exit(1); } while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") || !strcmp(dt->d_name,"lost+found") || !strcmp(dt->d_name,"ramd") || !strcmp(dt->d_name,"proc") || !strcmp(dt->d_name,"dev") || !strcmp(dt->d_name,"sys")) continue; xsystem("cp -dpR /%s /ramd/",dt->d_name); } closedir(dp); xmkdir("dev/pts"); xmkdir("initrd"); umount("/proc"); umount("/sys"); // STAGE 2 rc=pivot_root(".","initrd"); if(rc==-1) { fprintf_stdout("#### ERROR: Change root file system failed!\n"); exit(1); } chdir("/"); xmkdir("proc"); xmkdir("sys"); xsystem("mount -t proc -o rw virtual /proc"); xsystem("mount -t sysfs -o rw virtual /sys"); save_to_file("/proc/sys/kernel/printk","0 0 0 0\n"); if((dp=opendir("/tmp")) == NULL) { perror("opendir"); exit(1); } fprintf_stdout("-> Extracting base tools: "); while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue; if(strstr(dt->d_name,".mpk")) { fprintf_stdout("#"); xsystem("tar -C / -axf /tmp/%s",dt->d_name); } } free(dt); closedir(dp); fprintf_stdout("\r* Extracting base tools. Done.%s\n",SPACE); save_to_file("/proc/sys/kernel/modprobe","/bin/modprobe\n"); xsystem("depmod -a"); // STAGE 3 chdir("/"); xsystem("mdev -s"); xsystem("mount -t devpts /dev/devpts /dev/pts -o \"rw,gid=0,mode=620\""); rename("/dev/random","/dev/random-block"); symlink("/dev/urandom","/dev/random"); xsystem("chmod 700 *"); if((fp=fopen("/etc/inittab","w"))!=NULL) { fprintf(fp,"::sysinit:/etc/init.boot/rc.init\n"); fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 115200 linux\n"); fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 115200 vt100\n"); fprintf(fp,"tty7::respawn:/bin/chkprog\n"); fprintf(fp,"tty8::respawn:/bin/trafficd\n"); fprintf(fp,"::restart:/bin/init\n"); fprintf(fp,"::ctrlaltdel:/bin/bootdown\n"); fprintf(fp,"::ctrlaltdel:/bin/reset\n"); fprintf(fp,"::ctrlaltdel:/bin/reboot\n"); fprintf(fp,"::shutdown:/bin/bootdown\n"); fclose(fp); } curtime=time(NULL); loctime=localtime(&curtime); strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime); append_to_file("/tmp/bootup",cmd); if(file_exists("/bin/getkey")) { if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) { fprintf_stdout("\r#### WARNING: LOGIN DISABLED\n"); xtouch("/etc/noconsole"); } else { fprintf_stdout("\r* Starting Init. Done.\n"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s\n","/bin/mdev"); save_to_file("/proc/sys/kernel/hotplug",buf); do_chroot(); signal(SIGINT,SIG_DFL); fprintf_stdout("#### ERROR: Failed to boot file system!\n"); fprintf_stdout("#### ERROR: Press Ctrl+Alt+Del or switch off/on for reboot.\n"); while(1); exit(0); }
bool core::archive::image_cache::update(const history_block& _block) { if (!tree_is_consistent_) { image_vector_t to_add; image_vector_t to_delete; for (const auto& it : _block) { const history_message& message = *it; if (message.is_patch()) to_delete.emplace_back(image_data(message.get_msgid())); else extract_images(message, to_add); } const bool add_result = append_to_file(*tmp_to_add_storage_, to_add); const bool delete_result = append_to_file(*tmp_to_delete_storage_, to_delete); return add_result && delete_result; } const auto end = image_by_msgid_.end(); bool need_to_save_all = false; image_vector_t to_add; for (const auto& it : _block) { const history_message& message = *it; const auto msgid = message.get_msgid(); if (message.is_patch()) { auto to_delete = image_by_msgid_.find(msgid); if (to_delete != end) { need_to_save_all = true; image_by_msgid_.erase(to_delete); } } else { extract_images(message, to_add); } } if (need_to_save_all) { return save_all(); } else if (!to_add.empty()) { archive::storage_mode mode; mode.flags_.write_ = true; mode.flags_.append_ = true; if (!storage_->open(mode)) return false; core::tools::auto_scope lb([this]{ storage_->close(); }); add_images_to_tree(to_add); return serialize_block(*storage_, to_add); } return true; }
int bootup_main(int argc, char **argv) { FILE *fp; int t=0; char cmd[1024], buf[1024], name[1024]; time_t curtime; struct tm *loctime; signal(SIGINT,SIG_IGN); putenv("PATH=/bin"); putenv("TERM=linux"); umask(0770); chdir("/"); print_file("/etc/banner"); xsystem("mount -t proc -o ro virtual /proc"); xsystem("mount -t sysfs -o ro virtual /sys"); stage1(); stage2(); // STAGE 3 chdir("/"); read_cmdline(); xsystem("mdev -s"); xsystem("mount -t devpts -o \"rw,gid=0,mode=620\""); mk_dev("/dev/ppp",108,0); if(LCD_PROG==1 && file_exists("/tmp/tools/lcd/lcd.bz2")) { mk_dev("/dev/parport0",99,0); mk_dev("/dev/lp0",6,0); xsystem("tar -C / -jxf /tmp/tools/lcd/lcd.bz2"); } else { LCD_PROG=0; } rename("/dev/random","/dev/random-block"); symlink("/dev/urandom","/dev/random"); xmkdir("/strg"); if(LCD_DEV[0]!='\0') { snprintf(buf,sizeof(buf),"/dev/%s",LCD_DEV); if(file_exists(buf)) { save_to_file("/var/sys/lcd_dev",buf); if(LCD_PROG==1) save_to_file("/var/sys/lcd_proc","%d",LCD_PROG); symlink(buf,"/dev/lcd"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","-> STORAGE ON"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV); if(xsystem("mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV)==0) { if(file_exists("/strg/.mount_strg")) { unlink("/strg/.mount_strg"); if(xsystem("umount /strg")==0) { fprintf_stdout("**** MYBOX SYSTEM APPEARS TO HAVE SHUT DOWN UNCLEANLY ****\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","-> FIX STORAGE"); xsystem("e2fsck -y %s",STRG_DEV); t=1; } } if(t==0) xsystem("umount /strg"); } else { fprintf_stdout("**** MOUNTING STORAGE DISK FAILED! ****\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","STORAGE FAILED !"); xtouch("/strg/.nostrg"); xtouch("/var/sys/nolog"); } if(!file_exists("/strg/.nostrg")) { if(xsystem("mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV)==0) { memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s:%s\n",STRG_DEV,STRG_FS); save_to_file("/strg/.mount_strg",buf); save_to_file("/var/sys/.mount_strg",buf); save_to_file("/var/sys/.mount_strg","%s:%s\n",BOOT_DEV,BOOT_FS); } } if(xsystem("swapon %s",SWAP_DEV)==0) { memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s:swap\n",SWAP_DEV); save_to_file("/var/sys/.mount_swap",buf); } xsystem("chmod 700 *"); if((fp=fopen("/etc/inittab","w"))!=NULL) { fprintf(fp,"::sysinit:/bin/initrc\n"); fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 9600 linux\n"); fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 9600 vt100\n"); fprintf(fp,"null::respawn:/bin/chkprog\n"); fprintf(fp,"::restart:/bin/init\n"); fprintf(fp,"::ctrlaltdel:/bin/bootdown\n"); fprintf(fp,"::ctrlaltdel:/bin/reset\n"); fprintf(fp,"::ctrlaltdel:/bin/reboot\n"); fprintf(fp,"::shutdown:/bin/bootdown\n"); fclose(fp); } if((fp=fopen("/etc/profile","a"))!=NULL) { fprintf(fp,"xexit() {\n"); fprintf(fp," if [ \"$PPID\" = \"1\" ]; then\n"); fprintf(fp," local logname=\"/strg/mybox/logs/auth-$(date \"+%s\").log\"\n","%Y%m%d"); fprintf(fp," local msg=\"[$(date \"+%s\")] TYPE=console USER=console IP=$(basename $(tty)) MSG=Session logout.\"\n","%d/%m/%Y %H:%M:%S"); fprintf(fp," echo \"$msg\" >> $logname\n"); fprintf(fp," [ ! -z \"$ME\" -a -f \"$ME\" ] && rm -f /tmp/console.session/console_*\n"); fprintf(fp," fi\n"); fprintf(fp," exit\n"); fprintf(fp,"}\n"); fprintf(fp,"alias exit='xexit'\n"); fprintf(fp,"export HISTFILE=/.consolehistory\n"); fprintf(fp,"lcdd_msg() {\n"); fprintf(fp," if [ -f \"/bin/lcdd\" -a -c \"/dev/lcd\" ]; then\n"); fprintf(fp," if [ -f \"/var/sys/lcd_proc\" ]; then\n"); fprintf(fp," echo \"$2\" > /var/sys/lcd_msg\n"); fprintf(fp," else\n"); fprintf(fp," /bin/lcdd \"$1\" \"$2\"\n"); fprintf(fp," fi\n"); fprintf(fp," fi\n"); fprintf(fp,"}\n"); fprintf(fp,"if [ -z $DO_SINGLE ]; then\n"); fprintf(fp," if [ -f \"/bin/iosh\" ]; then\n"); fprintf(fp," XTTY=\"SSL\";\n"); fprintf(fp," if [ -f \"/var/sys/init_start\" ]; then\n"); fprintf(fp," trap : 1 2 3 15\n"); fprintf(fp," echo \"System loading in progress..please wait or login back in a minute\"\n"); fprintf(fp," while [ -f \"/var/sys/init_start\" ]; do sleep 1;done\n"); fprintf(fp," trap 1 2 3 15\n"); fprintf(fp," fi\n"); fprintf(fp," if [ \"$PPID\" = \"1\" ]; then\n"); fprintf(fp," export ME=\"/tmp/console.session/console_${PPID}_$(basename $(tty))_$(date \"+%s\")\";\n","%d:%m:%Y_%H:%M:%S"); fprintf(fp," touch $ME\n"); fprintf(fp," XTTY=\"console\";\n"); fprintf(fp," fi\n"); fprintf(fp," /bin/iosh $XTTY\n"); fprintf(fp," if [ $? != 5 ]; then\n"); fprintf(fp," clear;reset\n"); fprintf(fp," exit\n"); fprintf(fp," fi\n"); fprintf(fp," else\n"); fprintf(fp," echo \"** FAILED TO RUN IO SHELL **\"\n"); fprintf(fp," read io\n"); fprintf(fp," exit\n"); fprintf(fp," fi\n"); fprintf(fp,"else \n"); fprintf(fp," echo \"** MAINTENANCE MODE **\"\n"); fprintf(fp," lcdd_msg \"SYSTEM LOADING.." "-> MAINTENANCE\"\n"); fprintf(fp," read io\n"); fprintf(fp,"fi\n"); fclose(fp); } unlink("/strg/mybox/debug.log"); curtime=time(NULL); loctime=localtime(&curtime); memset(name,0x0,sizeof(name)); strftime(name, sizeof(name),"system-%Y%m%d.log",loctime); memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s/%s",LOGPATH,name); memset(cmd,0x0,sizeof(cmd)); strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime); append_to_file(buf,cmd); if(file_exists("/bin/getkey")) { if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) { fprintf_stdout("\r*** BYPASS CONSOLE LOGIN ***\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","BYPASS CONSOLE !"); xtouch("/etc/noconsole"); } else { fprintf_stdout("\r* Starting Init. Done.\n"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s\n","/bin/mdev"); save_to_file("/proc/sys/kernel/hotplug",buf); if(NUM_NET!=0) save_to_file("/var/sys/numnet_veto","%d",NUM_NET); do_chroot(); signal(SIGINT,SIG_DFL); lcd_msg(LCD_PROG,"SYSTEM LOADING..","ERROR !"); fprintf_stdout("You are not supposed to be here, something went wrong!\n"); fprintf_stdout("Press Ctrl+Alt+Del or switch off/on for reboot.\n"); while(1); exit(0); }
int main(int argc, char *argv[]) { int opt; char *basedir = NULL, *driver_name = NULL; int server = 0, mod_unloaded = 0; int modid, found; char maj_num[MAX_STR_MAJOR + 1]; int err; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); /* must be run by root */ if (getuid() != 0) { (void) fprintf(stderr, gettext(ERR_NOT_ROOT)); exit(1); } while ((opt = getopt(argc, argv, "b:")) != -1) { switch (opt) { case 'b' : server = 1; basedir = calloc(strlen(optarg) + 1, 1); if (basedir == NULL) { (void) fprintf(stderr, gettext(ERR_NO_MEM)); exit(1); } (void) strcat(basedir, optarg); break; case '?' : usage(); exit(1); } } if (argv[optind] != NULL) { driver_name = calloc(strlen(argv[optind]) + 1, 1); if (driver_name == NULL) { (void) fprintf(stderr, gettext(ERR_NO_MEM)); exit(1); } (void) strcat(driver_name, argv[optind]); /* * check for extra args */ if ((optind + 1) != argc) { usage(); exit(1); } } else { usage(); exit(1); } /* set up add_drv filenames */ if ((build_filenames(basedir)) == ERROR) { exit(1); } /* must be only running version of add_drv/mod_drv/rem_drv */ enter_lock(); if ((check_perms_aliases(1, 1)) == ERROR) err_exit(); if ((check_name_to_major(R_OK | W_OK)) == ERROR) err_exit(); /* look up the major number of the driver being removed. */ if ((found = get_major_no(driver_name, name_to_major)) == ERROR) { (void) fprintf(stderr, gettext(ERR_MAX_MAJOR), name_to_major); err_exit(); } if (found == UNIQUE) { (void) fprintf(stderr, gettext(ERR_NOT_INSTALLED), driver_name); err_exit(); } if (!server) { mod_unloaded = 1; /* get the module id for this driver */ get_modid(driver_name, &modid); /* module is installed */ if (modid != -1) { if (modctl(MODUNLOAD, modid) < 0) { perror(NULL); (void) fprintf(stderr, gettext(ERR_MODUN), driver_name); mod_unloaded = 0; } } /* unload driver.conf file */ if (modctl(MODUNLOADDRVCONF, (major_t)found) < 0) { perror(NULL); (void) fprintf(stderr, gettext("cannot unload %s.conf\n"), driver_name); } } if (mod_unloaded && (modctl(MODREMMAJBIND, (major_t)found) < 0)) { perror(NULL); (void) fprintf(stderr, gettext(ERR_MODREMMAJ), found); } /* * add driver to rem_name_to_major; if this fails, don`t * delete from name_to_major */ (void) sprintf(maj_num, "%d", found); if (append_to_file(driver_name, maj_num, rem_name_to_major, ' ', " ") == ERROR) { (void) fprintf(stderr, gettext(ERR_NO_UPDATE), rem_name_to_major); err_exit(); } /* * If removing the driver from the running system, notify * kernel dynamically to remove minor perm entries. */ if (basedir == NULL || (strcmp(basedir, "/") == 0)) { err = devfs_rm_minor_perm(driver_name, log_minorperm_error); if (err != 0) { (void) fprintf(stderr, gettext(ERR_UPDATE_PERM), driver_name, err); } } /* * delete references to driver in add_drv/rem_drv database */ remove_entry(CLEAN_ALL, driver_name); /* * Clean up any dangling devfs shadow nodes for this * driver so that, in the event the driver is re-added * to the system, newly created nodes won't incorrectly * pick up these stale shadow node permissions. */ if (basedir == NULL || (strcmp(basedir, "/") == 0)) { err = modctl(MODREMDRVCLEANUP, driver_name, 0, NULL); if (err != 0) { (void) fprintf(stderr, gettext(ERR_REMDRV_CLEANUP), driver_name, err); } } exit_unlock(); return (NOERR); }
void CompressSword2::execute() { int j; uint32 indexSize; uint32 totalSize; uint32 length; Common::Filename inpath(_inputPaths[0].path); Common::Filename &outpath = _outputPath; if (outpath.empty()) // Extensions change between the in/out files, so we can use the same directory outpath = inpath; switch (_format) { case AUDIO_MP3: _audioOutputFilename = TEMP_MP3; outpath.setExtension(".cl3"); break; case AUDIO_VORBIS: _audioOutputFilename = TEMP_OGG; outpath.setExtension(".clg"); break; case AUDIO_FLAC: _audioOutputFilename = TEMP_FLAC; outpath.setExtension(".clf"); break; default: throw ToolException("Unknown audio format"); break; } _input.open(inpath, "rb"); indexSize = _input.readUint32LE(); totalSize = 12 * (indexSize + 1); if (_input.readUint32BE() != 0xfff0fff0) { error("This doesn't look like a cluster file"); } _output_idx.open(TEMP_IDX, "wb"); _output_snd.open(TEMP_DAT, "wb"); _output_idx.writeUint32LE(indexSize); _output_idx.writeUint32BE(0xfff0fff0); _output_idx.writeUint32BE(0xfff0fff0); for (int i = 0; i < (int)indexSize; i++) { // Update progress, this loop is where most of the time is spent updateProgress(i, indexSize); uint32 pos; uint32 enc_length; _input.seek(8 * (i + 1), SEEK_SET); pos = _input.readUint32LE(); length = _input.readUint32LE(); if (pos != 0 && length != 0) { uint16 prev; Common::File f(TEMP_WAV, "wb"); /* * The number of decodeable 16-bit samples is one less * than the length of the resource. */ length--; /* * Back when this tool was written, encodeAudio() had * no way of encoding 16-bit data, so it was simpler to * output a WAV file. */ f.writeUint32BE(0x52494646); /* "RIFF" */ f.writeUint32LE(2 * length + 36); f.writeUint32BE(0x57415645); /* "WAVE" */ f.writeUint32BE(0x666d7420); /* "fmt " */ f.writeUint32LE(16); f.writeUint16LE(1); /* PCM */ f.writeUint16LE(1); /* mono */ f.writeUint32LE(22050); /* sample rate */ f.writeUint32LE(44100); /* bytes per second */ f.writeUint16LE(2); /* basic block size */ f.writeUint16LE(16); /* sample width */ f.writeUint32BE(0x64617461); /* "data" */ f.writeUint32LE(2 * length); _input.seek(pos, SEEK_SET); /* * The first sample is stored uncompressed. Subsequent * samples are stored as some sort of 8-bit delta. */ prev = _input.readUint16LE(); f.writeUint16LE(prev); for (j = 1; j < (int)length; j++) { byte data; uint16 out; data = _input.readByte(); if (GetCompressedSign(data)) out = prev - (GetCompressedAmplitude(data) << GetCompressedShift(data)); else out = prev + (GetCompressedAmplitude(data) << GetCompressedShift(data)); f.writeUint16LE(out); prev = out; } f.close(); encodeAudio(TEMP_WAV, false, -1, tempEncoded, _format); enc_length = append_to_file(_output_snd, tempEncoded); _output_idx.writeUint32LE(totalSize); _output_idx.writeUint32LE(length); _output_idx.writeUint32LE(enc_length); totalSize = totalSize + enc_length; } else { _output_idx.writeUint32LE(0); _output_idx.writeUint32LE(0); _output_idx.writeUint32LE(0); } } _output_snd.close(); _output_idx.close(); Common::File output(outpath, "wb"); append_to_file(output, TEMP_IDX); append_to_file(output, TEMP_DAT); output.close(); Common::removeFile(TEMP_DAT); Common::removeFile(TEMP_IDX); Common::removeFile(TEMP_MP3); Common::removeFile(TEMP_OGG); Common::removeFile(TEMP_FLAC); Common::removeFile(TEMP_WAV); }
/* Duplicate of to_channel from act_comm.c modified for dynamic channels */ void send_tochannel( char_data * ch, mud_channel * channel, string & argument ) { int speaking = -1; for( int lang = 0; lang < LANG_UNKNOWN; ++lang ) { if( ch->speaking == lang ) { speaking = lang; break; } } if( ch->isnpc( ) && channel->type == CHAN_GUILD ) { ch->print( "Mobs can't be in clans/guilds.\r\n" ); return; } if( ch->has_pcflag( PCFLAG_SILENCE ) ) { ch->printf( "You can't %s.\r\n", channel->name.c_str( ) ); return; } if( ch->has_aflag( AFF_SILENCE ) ) { ch->print( "You are unable to utter a sound!\r\n" ); return; } if( !ch->IS_PKILL( ) && channel->type == CHAN_PK ) { if( !ch->is_immortal( ) ) { ch->print( "Peacefuls have no need to use PK channels.\r\n" ); return; } } if( ch->in_room->flags.test( ROOM_SILENCE ) || ch->in_room->flags.test( ROOM_NOYELL ) || ch->in_room->area->flags.test( AFLAG_SILENCE ) ) { ch->print( "The room absorbs your words!\r\n" ); return; } if( ch->isnpc( ) && ch->has_aflag( AFF_CHARM ) ) { if( ch->master ) ch->master->print( "I don't think so...\r\n" ); return; } if( argument.empty( ) ) { if( !channel->flags.test( CHAN_KEEPHISTORY ) ) { ch->printf( "%s what?\r\n", capitalize( channel->name ).c_str( ) ); return; } show_channel_history( ch, channel ); return; } // Adaptation of Smaug 1.8b feature. Stop whitespace abuse now! strip_spaces( argument ); string arg, word; char_data *victim = nullptr; social_type *social = nullptr; string socbuf_char, socbuf_vict, socbuf_other; arg = argument; arg = one_argument( arg, word ); if( word[0] == '@' && ( social = find_social( word.substr( 1, word.length( ) ) ) ) != nullptr ) { if( !arg.empty( ) ) { string name; one_argument( arg, name ); if( ( victim = ch->get_char_world( name ) ) ) arg = one_argument( arg, name ); if( !victim ) { socbuf_char = social->char_no_arg; socbuf_vict = social->others_no_arg; socbuf_other = social->others_no_arg; if( socbuf_char.empty( ) && socbuf_other.empty( ) ) social = nullptr; } else if( victim == ch ) { socbuf_char = social->char_auto; socbuf_vict = social->others_auto; socbuf_other = social->others_auto; if( socbuf_char.empty( ) && socbuf_other.empty( ) ) social = nullptr; } else { socbuf_char = social->char_found; socbuf_vict = social->vict_found; socbuf_other = social->others_found; if( socbuf_char.empty( ) && socbuf_other.empty( ) && socbuf_vict.empty( ) ) social = nullptr; } } else { socbuf_char = social->char_no_arg; socbuf_vict = social->others_no_arg; socbuf_other = social->others_no_arg; if( socbuf_char.empty( ) && socbuf_other.empty( ) ) social = nullptr; } } bool emote = false; if( word[0] == ',' ) { emote = true; argument = argument.substr( 1, argument.length( ) ); } if( social ) { act_printf( AT_PLAIN, ch, argument.c_str( ), victim, TO_CHAR, "&W[&[%s]%s&W] &[%s]%s", channel->colorname.c_str( ), capitalize( channel->name ).c_str( ), channel->colorname.c_str( ), socbuf_char.c_str( ) ); } else if( emote ) { ch->printf( "&W[&[%s]%s&W] &[%s]%s %s\r\n", channel->colorname.c_str( ), capitalize( channel->name ).c_str( ), channel->colorname.c_str( ), ch->name, argument.c_str( ) ); } else { if( ch->has_pcflag( PCFLAG_WIZINVIS ) ) ch->printf( "&[%s](%d) You %s '%s'\r\n", channel->colorname.c_str( ), ( !ch->isnpc( ) ? ch->pcdata->wizinvis : ch->mobinvis ), channel->name.c_str( ), argument.c_str( ) ); else ch->printf( "&[%s]You %s '%s'\r\n", channel->colorname.c_str( ), channel->name.c_str( ), argument.c_str( ) ); } if( ch->in_room->flags.test( ROOM_LOGSPEECH ) ) append_to_file( LOG_FILE, "%s: %s (%s)", ch->isnpc( )? ch->short_descr : ch->name, argument.c_str( ), channel->name.c_str( ) ); /* * Channel history. Records the last MAX_CHANHISTORY messages to channels which keep historys */ if( channel->flags.test( CHAN_KEEPHISTORY ) ) update_channel_history( ch, channel, argument, emote ); list < char_data * >::iterator ich; for( ich = pclist.begin( ); ich != pclist.end( ); ++ich ) { char_data *vch = *ich; /* * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 */ bool mapped = false; int origmap = -1, origx = -1, origy = -1; if( vch == ch || !vch->desc ) continue; if( vch->desc->connected == CON_PLAYING && hasname( vch->pcdata->chan_listen, channel->name ) ) { string sbuf = argument; char lbuf[MIL + 4]; /* invis level string + buf */ if( vch->level < channel->level ) continue; if( vch->in_room->flags.test( ROOM_SILENCE ) || vch->in_room->area->flags.test( AFLAG_SILENCE ) ) continue; if( channel->type == CHAN_ROOM ) { if( vch->in_room != ch->in_room ) continue; /* * Check to see if a player on a map is at the same coords as the recipient */ if( !is_same_char_map( ch, vch ) ) continue; } if( channel->type == CHAN_ZONE && ( vch->in_room->area != ch->in_room->area || vch->in_room->flags.test( ROOM_NOYELL ) ) ) continue; if( channel->type == CHAN_PK && !vch->IS_PKILL( ) && !vch->is_immortal( ) ) continue; if( channel->type == CHAN_GUILD ) { if( vch->isnpc( ) ) continue; if( vch->pcdata->clan != ch->pcdata->clan ) continue; } int position = vch->position; vch->position = POS_STANDING; if( ch->has_pcflag( PCFLAG_WIZINVIS ) && vch->can_see( ch, false ) && vch->is_immortal( ) ) snprintf( lbuf, MIL + 4, "&[%s](%d) ", channel->colorname.c_str( ), ( !ch->isnpc( ) ) ? ch->pcdata->wizinvis : ch->mobinvis ); else lbuf[0] = '\0'; if( speaking != -1 && ( !ch->isnpc( ) || ch->speaking ) ) { int speakswell = UMIN( knows_language( vch, ch->speaking, ch ), knows_language( ch, ch->speaking, vch ) ); if( speakswell < 85 ) sbuf = translate( speakswell, argument, lang_names[speaking] ); } /* * Check to see if target is ignoring the sender */ if( is_ignoring( vch, ch ) ) { /* * If the sender is an imm then they cannot be ignored */ if( !ch->is_immortal( ) || vch->level > ch->level ) { /* * Off to oblivion! */ continue; } } MOBtrigger = false; /* * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 */ if( ch->has_pcflag( PCFLAG_ONMAP ) ) { mapped = true; origx = ch->mx; origy = ch->my; origmap = ch->wmap; } if( ch->isnpc( ) && ch->has_actflag( ACT_ONMAP ) ) { mapped = true; origx = ch->mx; origy = ch->my; origmap = ch->wmap; } fix_maps( vch, ch ); char buf[MSL]; if( !social && !emote ) { snprintf( buf, MSL, "&[%s]$n %ss '$t&[%s]'", channel->colorname.c_str( ), channel->name.c_str( ), channel->colorname.c_str( ) ); mudstrlcat( lbuf, buf, MIL + 4 ); act( AT_PLAIN, lbuf, ch, sbuf.c_str( ), vch, TO_VICT ); } if( emote ) { snprintf( buf, MSL, "&W[&[%s]%s&W] &[%s]$n $t", channel->colorname.c_str( ), capitalize( channel->name ).c_str( ), channel->colorname.c_str( ) ); mudstrlcat( lbuf, buf, MIL + 4 ); act( AT_PLAIN, lbuf, ch, sbuf.c_str( ), vch, TO_VICT ); } if( social ) { if( vch == victim ) { act_printf( AT_PLAIN, ch, nullptr, vch, TO_VICT, "&W[&[%s]%s&W] &[%s]%s", channel->colorname.c_str( ), capitalize( channel->name ).c_str( ), channel->colorname.c_str( ), socbuf_vict.c_str( ) ); } else { act_printf( AT_PLAIN, ch, vch, victim, TO_THIRD, "&W[&[%s]%s&W] &[%s]%s", channel->colorname.c_str( ), capitalize( channel->name ).c_str( ), channel->colorname.c_str( ), socbuf_other.c_str( ) ); } } vch->position = position; /* * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 */ if( mapped ) { ch->wmap = origmap; ch->mx = origx; ch->my = origy; if( ch->isnpc( ) ) ch->set_actflag( ACT_ONMAP ); else ch->set_pcflag( PCFLAG_ONMAP ); } else { if( ch->isnpc( ) ) ch->unset_actflag( ACT_ONMAP ); else ch->unset_pcflag( PCFLAG_ONMAP ); ch->wmap = -1; ch->mx = -1; ch->my = -1; } } } }