void delete_at(int id) { if (((id + 1) > get_length()) || id < 0) { printf("Eroare: index indicat in afara diapazonului.\n\n"); return; } int i = -1; Node* tmp = root; Node* prev; while (root->next != NULL) { prev = root; root = root->next; i++; if (i == id) { if (root->next != NULL) { prev->next = root->next; free(root); root = prev->next; } else { prev->next = NULL; free(root); break; } } } root = tmp; save_to_file(); printf("Sters cu success!!"); }
void generate_url(char *buffer, char *slug, size_t slug_length, struct client_data data) { int i; memset(slug, '\0', slug_length); for (i = 0; i <= SLUG_SIZE - 1; i++) { #if defined(BSD) int symbol_id = arc4random() % strlen(symbols); #else int symbol_id = rand_r(&time_seed) % strlen(symbols); #endif slug[i] = symbols[symbol_id]; } while (create_directory(slug) == -1) { #if defined(BSD) int symbol_id = arc4random() % strlen(symbols); #else int symbol_id = rand_r(&time_seed) % strlen(symbols); #endif slug[strlen(slug)] = symbols[symbol_id]; } save_to_file(slug, buffer, data); }
void Replay::save_as_auto_replay(const Level* const lev) { bool multi = (players.size() > 1); if (( multi && ! gloB->replay_auto_multi) || (! multi && ! gloB->replay_auto_single)) return; std::ostringstream outfile; outfile << (multi ? gloB->file_replay_auto_multi.get_rootful() : gloB->file_replay_auto_single.get_rootful()); int nr = 0; const int nrmax = gloB->replay_auto_max; if (multi) nr = gloB->replay_auto_next_m; else nr = gloB->replay_auto_next_s; if (nr >= nrmax) nr = 0; if (nr < 100) outfile << "0"; if (nr < 10) outfile << "0"; outfile << nr << gloB->ext_replay; // Done putting the number into 'outfile', now increasing global variable if (multi) gloB->replay_auto_next_m = (nr + 1 > nrmax ? 0 : nr + 1); else gloB->replay_auto_next_s = (nr + 1 > nrmax ? 0 : nr + 1); Filename outfile_filename(outfile.str()); save_to_file(outfile_filename, lev); }
void close_tab(void) { Document *doc; GtkWidget *scroll; int index; /* Since a keypress only works on the currently active * tab anyway, we might as well ask the index of the current * page here and use that, instead of passing the index as * a parameter. * Also, since we need both the GtkScrolledWindow and the Document * it is of no use to call get_active_document(). */ index = gtk_notebook_get_current_page(GTK_NOTEBOOK(lightpad->tabs)); scroll = gtk_notebook_get_nth_page(GTK_NOTEBOOK(lightpad->tabs), index); doc = g_object_get_data(G_OBJECT(scroll), "doc"); if(doc->modified) { int save = check_for_save(doc); switch(save) { case GTK_RESPONSE_YES: if(save_to_file(doc, TRUE) < 0) return; case GTK_RESPONSE_NO: break; default: return; } } gtk_widget_destroy(scroll); /* this destroys both scroll's child and its container */ }
static void run_check(void) { int i; time_t curtime; struct tm *loctime; char fname[150]; char info[150]; if(taskq==0 && file_exists("/bin/taskq-check")) { run_daemon("taskq-check","/bin/taskq-check"); } if(!file_exists(DIRQUE)) xmkdir(DIRQUE); for(i=0; i < listcnt;i++) { if(listq[i].cmd && listq[i].status==0) { curtime=time(NULL); loctime=localtime(&curtime); memset(fname,0x0,sizeof(fname)); snprintf(fname,sizeof(fname),"%s/%s",DIRQUE,listq[i].cmd); if(file_exists(fname)) continue; strftime(info, sizeof(info), "%d/%m/%Y %T",loctime); save_to_file(fname,"%s",info); //printf("[%s] Service %s down\n",info,listq[i].prog); memset(info,0x0,sizeof(info)); __log(listq[i].prog); } } }
int main(int argc, char* argv[]) { assert(argc>3); Bayesian bayesian(256, 256); std::string output_folder = argv[1]; std::string train_folder = argv[2]; std::string filename = argv[3]; fs::path path_to_output_folder(output_folder); path_to_output_folder/=filename; fs::path path_to_train_folder(train_folder); bayesian.train_from_folder<0,1>(path_to_train_folder); auto bayesian_m = bayesian.model(); std::ofstream file(path_to_output_folder.string()); bayesian_m.save_to_file(file); bayesian_m.gaussian_blur(5,5,1,1); cv::Mat color_map = bayesian_m.representation(); cv::imwrite(path_to_output_folder.string() + ".jpg",color_map); cv::imshow("color map",color_map); cv::waitKey(0); return 0; }
void save_record() { // {{{ static int last_minute = -1; time_t now = time(NULL); struct tm* timeinfo = localtime(&now); int minute = timeinfo->tm_yday * 1440 + timeinfo->tm_hour * 24 + timeinfo->tm_min; if (minute != last_minute) { if (last_minute != -1) { unsigned int sum = 0; for (size_t i = 0; i < RECORD_KEY; ++i) { sum += minute_record.record[i]; } if (sum > 0) // do not save if no key press, reduce disk usage { // First element may be 0 all the time, use it to save sum of all value minute_record.record[0] = sum; minute_record.t = now; char file_name[100]; snprintf(file_name, 1000, "kbd_%04d-%02d-%02d.log", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday); save_to_file(file_name, minute_record); } } memset(&minute_record, 0, sizeof(Record)); last_minute = minute; } } // }}}
void callback_save( GtkWidget *widget, gpointer data){ if(!strcmp(window_title,"unnamed show")){ save_as_popup (widget, data); } else{ save_to_file(widget, (gpointer)window_title); } }
int main(void) { int ch; list L=creat_list(); init_from_file(L); for(;;) { CLS; main_menu(); scanf("%d",&ch); rst_stdin(); switch(ch) { case 1: CLS; insert_list(L); save_to_file(L); break; case 2: CLS; print_list(L); break; case 3: CLS; serch_list(L); break; case 4: CLS; delete_list_menu(L); save_to_file(L); break; case 5: CLS; update_list_menu(L); save_to_file(L); break; case 0: save_to_file(L); return 0; } } return 0; }
void save_fib(const std::string& ext) { std::string output_name = file_name; output_name += ext; begin_prog("saving data"); gz_mat_write mat_writer(output_name.c_str()); save_to_file(mat_writer); voxel.end(mat_writer); std::string final_report = voxel.report.c_str(); final_report += voxel.recon_report.str(); mat_writer.write("report",final_report.c_str(),1,final_report.length()); }
void CRefresher::deal(workbench_t &bench) { char * tmp; tmp = create_cp(bench); string new_cp(tmp); bool changed = false; int old_timeout = bench.timeout; #ifndef _TEST //if there is no url=bench.url in our file, we write delete log too if (bench.reply.status.code == 404) { time_t timep; time(&timep); // fprintf(deletelog,"delete url %s %s\n", // bench.url->str().c_str(), ctime(&timep)); return; } #endif if (bench.timeout == 0) { changed = true; //first time crawled time_t timep; time(&timep); // fprintf(newlog,"new url %s %s\n", // bench.url->str().c_str(), ctime(&timep)); } else{ if (new_cp != bench.checkpoint) { //changed changed = true; time_t timep; time(&timep); // fprintf(changelog,"change url %s %s\n", // bench.url->str().c_str(), ctime(&timep)); } } bench.changed = changed; bench.timeout = rconfig.calculate(bench.url.str().c_str(),old_timeout,changed,bench.depth); CTime_struct real_time = get_real_time(bench.timeout); #ifdef _TEST cout << "new real_time = " << real_time.time_to_string() << endl; #endif #ifndef _TEST bench.checkpoint = new_cp; #endif save_to_file(bench,real_time); }
static void wait_prog(const char *msg, const char *path,const char *prog, const char *argz) { FILE *f; char spin[]={'-','\\','|','/','-','\\','|','/'}; int numspin=sizeof(spin); int i=0, ok=0, pt=0; char filetmp[1024], buf[1024]; memset(filetmp,0x0,sizeof(filetmp)); snprintf(filetmp,sizeof(filetmp),"/tmp/%s.log",prog); save_to_file(filetmp,""); xsystem("php -q %s/%s %s >> %s 2>&1 && rm -f %s >>/dev/null 2>&1 &",path,prog,argz,filetmp,filetmp); while(file_exists(filetmp)) { for(i=0;i<numspin;i++) { fprintf_stdout("\r-> %s [%c]",msg,spin[i]); usleep(100000); } memset(buf,0x0,sizeof(buf)); if((f=fopen(filetmp,"r"))!=NULL) { while(fgets(buf,sizeof(buf),f)!=NULL) { trim(buf); if(buf[0]=='\0') continue; if(strstr(buf,"unlicensed")) { fprintf_stdout("\r* %s Unlicensed.\n",msg); unlink(filetmp);ok=1; } else if(strstr(buf,"Internal error")) { fprintf_stdout("\r* %s Internal error.\n",msg); unlink(filetmp);ok=1; } else if(strstr(buf,"failed") || strstr(buf,"Failed") ) { fprintf_stdout("\r* %s Failed.\n",msg); unlink(filetmp);ok=1; } else if(strstr(buf,"disabled") || strstr(buf,"Disabled")) { fprintf_stdout("\r* %s Disabled.\n",msg); unlink(filetmp);ok=1; } memset(buf,0x0,sizeof(buf)); } fclose(f); } // more than 1 minutes if(pt > 60) { fprintf_stdout("\r* %s Timeout.\n",msg); unlink(filetmp);ok=1; } pt++; sleep(1); } if(ok==0) { fprintf_stdout("\r* %s Done.\n",msg); unlink(filetmp); } }
Handle<Value> ImageView::save(const Arguments& args) { HandleScope scope; if (!args.Length() >= 1 || !args[0]->IsString()){ return ThrowException(Exception::TypeError( String::New("filename required"))); } std::string filename = TOSTR(args[0]); std::string format(""); if (args.Length() >= 2) { if (!args[1]->IsString()) return ThrowException(Exception::TypeError( String::New("both 'filename' and 'format' arguments must be strings"))); format = mapnik::guess_type(TOSTR(args[1])); if (format == "<unknown>") { std::ostringstream s(""); s << "unknown output extension for: " << filename << "\n"; return ThrowException(Exception::Error( String::New(s.str().c_str()))); } } ImageView* im = ObjectWrap::Unwrap<ImageView>(args.This()); try { save_to_file(*im->get(),filename); } catch (const std::exception & ex) { return ThrowException(Exception::Error( String::New(ex.what()))); } catch (...) { return ThrowException(Exception::TypeError( String::New("unknown exception happened while saving an image, please submit a bug report"))); } return Undefined(); }
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer) { if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fprintf(stderr, "img transfer status %d?\n", transfer->status); img_transfer = NULL; request_exit(2); return; } printf("Image callback\n"); save_to_file(imgbuf); if (next_state() < 0) { request_exit(2); return; } if (libusb_submit_transfer(img_transfer) < 0) request_exit(2); }
void handleClick(int x, int y) { if (menu_active) { if ((y > menu_height - 4 * button_size_y) && (y < menu_height - 3 * button_size_y) && (x > 0) && (x < button_size_x)) { selected = 3; cube_color[0] = 1.0f; cube_color[1] = 0.0f; cube_color[2] = 0.0f; cube_color[3] = 1.0f; } else if ((y > menu_height - 3 * button_size_y) && (y < menu_height - 2 * button_size_y) && (x > 0) && (x < button_size_x)) { selected = 2; cube_color[0] = 0.0f; cube_color[1] = 1.0f; cube_color[2] = 0.0f; cube_color[3] = 1.0f; } else if ((y > menu_height - 2 * button_size_y) && (y < menu_height - button_size_y) && (x > 0) && (x < button_size_x)) { selected = 1; cube_color[0] = 0.0f; cube_color[1] = 0.0f; cube_color[2] = 1.0f; cube_color[3] = 1.0f; } else if ((y > menu_height - button_size_y) && (y < menu_height) && (x > 0) && (x < button_size_x)) { selected = 0; cube_color[0] = 1.0f; cube_color[1] = 1.0f; cube_color[2] = 0.0f; cube_color[3] = 1.0f; } else { menu_hide_animation = true; menu_show_animation = false; menu_active = false; } //Save current state to a file save_to_file(); } }
int main () { //main program for volume rendering Volume* ct = new Volume; read_from_file("smallHead.den", ct); //print_ct_volume(ct); Volume* color = new Volume; compute_shading_volume(ct, color); //print_ct_volume(color); ImagePanel* img = new ImagePanel; init_img_panel(img); foreach_pixel_exec(img, volume_ray_tracing, ct, color); save_to_file(img, "output.raw"); //save result to binary file delete img; delete ct; delete color; return 0; }
void network_touch(void) { int pt=0,x=0; fprintf_stdout("* Detecting network interfaces: "); pt=get_eth(); lcd_msg("SYSTEM LOADING..","-> CHECKING NIC"); if(pt!=0) { for(x=0;x<pt;x++) { fprintf_stdout("%s ",eth_list[x].name); } putchar('\n'); if(pt < 4) pt=4; save_to_file("/var/sys/numnet","%d\n",pt); numdev=pt; } else { fprintf_stdout("* No network device found\n"); lcd_msg("SYSTEM LOADING..","-> NO NIC FOUND"); xtouch("/var/sys/nonetwork"); nonetwork=1; } }
//********************************************************************************* void partMover::sequence_save(GtkButton *button, partMover* currentPart) { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Save File", (GtkWindow*) window, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filenameIn; filenameIn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); save_to_file (filenameIn,currentPart); g_free (filenameIn); } gtk_widget_destroy (dialog); return; }
void on________s_1_activate (GtkMenuItem *menuitem, AD data) // 儲å˜æª”案 { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Save File", GTK_WINDOW(data->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); if (0)//user_edited_a_new_document) { gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), "NEW.txt");//default_folder_for_saving); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document"); } else gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), "OLD.txt");//filename_for_existing_document); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); save_to_file (filename, GTK_TEXT_VIEW (data->textview)); gtk_window_set_title (GTK_WINDOW (data->window), filename); g_free (filename); } gtk_widget_destroy (dialog); }
void update() { angle = fmod((angle + 1.0f), 360.0 ); if (menu_show_animation) { if (menu_animation < menu_height) { menu_animation += 7.0f; } else { menu_show_animation = false; menu_active = true; //Save current state to a file save_to_file(); } } else if (menu_hide_animation) { if (menu_animation > 0.0f) { menu_animation -= 7.0f; } else { menu_hide_animation = false; } } pos_y = height - menu_animation; }
/** * input_file * * Función principal para operar sobre el fichero de texto * * Primero intentamos leer el fichero, a continuación * lo procesamos y pedimos las opciones correspondientes * al usuario */ int input_file(char* filename) { FILE *ifile; ifile = fopen(filename, "r"); PLANNER_INPUT data_input; // fichero inaccesible if(ifile == NULL) { printf(ERROR_FILEOPEN, filename); return -1; } // fichero abierto, podemos proseguir data_input = process_file(ifile); printf(INFO_OPTIONFILE); char* opt = read_from_input(stdin); // tanto si es 'v' como 'c', imprimimos la información if(strcmp(opt, "v") == 0 || strcmp(opt, "c") == 0) { // imprimir en 'stdout' output_algorithm_result(&data_input, stdout); } // si es 'w' o 'c', escribimos la información en un fichero if(strcmp(opt, "w") == 0 || strcmp(opt, "c") == 0) { save_to_file(&data_input); } return 0; }
void session_file_storage::save(std::string const &sid,time_t timeout,std::string const &in) { locked_file file(this,sid); save_to_file(file.handle(),timeout,in); }
/* appends app to type in Added Associations */ void mime_type_append_action( const char* type, const char* desktop_id ) { //sfm 0.7.7+ added // http://www.freedesktop.org/wiki/Specifications/mime-actions-spec GKeyFile* file; gsize len = 0; char* data = NULL; char** apps; gsize n_apps, i; char* str; if ( !( type && type[0] != '\0' && desktop_id && desktop_id[0] != '\0' ) ) return; char* dir = g_build_filename( g_get_user_data_dir(), "applications", NULL ); char* path = g_build_filename( dir, "mimeapps.list", NULL ); g_mkdir_with_parents( dir, 0700 ); g_free( dir ); // Load old file content, if available file = g_key_file_new(); g_key_file_load_from_file( file, path, 0, NULL ); // append app to [Added Associations] char* new_action = NULL; gboolean is_present = FALSE; apps = g_key_file_get_string_list( file, "Added Associations", type, &n_apps, NULL ); if ( apps ) { for ( i = 0; i < n_apps; ++i ) { g_strstrip( apps[i] ); if ( apps[i][0] != '\0' ) { if ( !strcmp( apps[i], desktop_id ) ) { is_present = TRUE; break; } str = new_action; new_action = g_strdup_printf( "%s%s;", str ? str : "", apps[i] ); g_free( str ); } } g_strfreev( apps ); } // update key file - added if ( !is_present ) { str = new_action; new_action = g_strdup_printf( "%s%s;", str ? str : "", desktop_id ); g_free( str ); g_key_file_set_string( file, "Added Associations", type, new_action ); } g_free( new_action ); // remove app from [Removed Associations] char* removed = NULL; apps = g_key_file_get_string_list( file, "Removed Associations", type, &n_apps, NULL ); if ( apps ) { for ( i = 0; i < n_apps; ++i ) { g_strstrip( apps[i] ); if ( apps[i][0] != '\0' && strcmp( apps[i], desktop_id ) ) { str = removed; removed = g_strdup_printf( "%s%s;", str ? str : "", apps[i] ); g_free( str ); } } g_strfreev( apps ); } // update key file - removed if ( removed ) g_key_file_set_string( file, "Removed Associations", type, removed ); else g_key_file_remove_key( file, "Removed Associations", type, NULL ); g_free( removed ); // save data = g_key_file_to_data( file, &len, NULL ); g_key_file_free( file ); save_to_file( path, data, len ); g_free( path ); g_free( data ); }
static char* make_custom_desktop_file( const char* desktop_id, const char* mime_type ) { char *name = NULL, *cust_template = NULL, *cust = NULL, *path, *dir; char* file_content = NULL; gsize len = 0; guint i; if( G_LIKELY( g_str_has_suffix(desktop_id, ".desktop") ) ) { GKeyFile *kf = g_key_file_new(); char* name = mime_type_locate_desktop_file( NULL, desktop_id ); if( G_UNLIKELY( ! name || ! g_key_file_load_from_file( kf, name, G_KEY_FILE_KEEP_TRANSLATIONS, NULL ) ) ) { g_free( name ); return NULL; /* not a valid desktop file */ } g_free( name ); /* FIXME: If the source desktop_id refers to a custom desktop file, and value of the MimeType key equals to our mime-type, there is no need to generate a new desktop file. if( G_UNLIKELY( is_custom_desktop_file( desktop_id ) ) ) { } */ /* set our mime-type */ g_key_file_set_string_list( kf, group_desktop, key_mime_type, &mime_type, 1 ); /* store id of original desktop file, for future use. */ g_key_file_set_string( kf, group_desktop, "X-MimeType-Derived", desktop_id ); g_key_file_set_string( kf, group_desktop, "NoDisplay", "true" ); name = g_strndup( desktop_id, strlen(desktop_id) - 8 ); cust_template = g_strdup_printf( "%s-usercustom-%%d.desktop", name ); g_free( name ); file_content = g_key_file_to_data( kf, &len, NULL ); g_key_file_free( kf ); } else /* it's not a desktop_id, but a command */ { char* p; const char file_templ[] = "[Desktop Entry]\n" "Encoding=UTF-8\n" "Name=%s\n" "Exec=%s\n" "MimeType=%s\n" "Icon=exec\n" "NoDisplay=true\n"; /* FIXME: Terminal? */ /* Make a user-created desktop file for the command */ name = g_path_get_basename( desktop_id ); if( (p = strchr(name, ' ')) ) /* FIXME: skip command line arguments. is this safe? */ *p = '\0'; file_content = g_strdup_printf( file_templ, name, desktop_id, mime_type ); len = strlen( file_content ); cust_template = g_strdup_printf( "%s-usercreated-%%d.desktop", name ); g_free( name ); } /* generate unique file name */ dir = g_build_filename( g_get_user_data_dir(), "applications", NULL ); g_mkdir_with_parents( dir, 0700 ); for( i = 0; ; ++i ) { /* generate the basename */ cust = g_strdup_printf( cust_template, i ); path = g_build_filename( dir, cust, NULL ); /* test if the filename already exists */ if( g_file_test( path, G_FILE_TEST_EXISTS ) ) { g_free( cust ); g_free( path ); } else /* this generated filename can be used */ break; } g_free( dir ); if( G_LIKELY( path ) ) { save_to_file( path, file_content, len ); g_free( path ); /* execute update-desktop-database" to update mimeinfo.cache */ update_desktop_database(); } return cust; }
void startprog(void) { char host[40]; xsystem("mkdir -p /tmp/sessions"); chmod("/tmp/sessions",S_IREAD | S_IWRITE | S_IEXEC); save_to_file("/etc/resolv.conf",""); xtouch("/var/sys/init_no_restart"); xtouch("/var/sys/init_start"); xsystem("ps |grep getkey |awk '{print $1}' |xargs kill -9 >/dev/null 2>&1"); chk_prog_stat(); if(file_exists("/service/init/misc.init")) { if(xsystem("/service/init/misc.init keymap >/dev/null 2>&1")==0) { fprintf_stdout("* Setting keymap. Done.\n"); lcd_msg("SYSTEM SETTING..","-> KEYMAP"); } if(xsystem("/service/init/misc.init clock >/dev/null 2>&1")==0) { fprintf_stdout("* Setting clock: "); print_date(); lcd_msg("SYSTEM SETTING..","-> CLOCK"); } if(xsystem("/service/init/misc.init dnshost >/dev/null 2>&1")==0) { gethostname(host,sizeof(host)); fprintf_stdout("* Setting system hostname: %s\n",host); lcd_msg("SYSTEM SETTING..","-> HOSTNAME"); } } xsystem("iptables -P INPUT DROP >/dev/null 2>&1"); xsystem("iptables -P FORWARD DROP >/dev/null 2>&1"); xsystem("iptables -P OUTPUT DROP >/dev/null 2>&1"); xsystem("iptables -A INPUT -i lo -s 127.0.0.1 -j ACCEPT >/dev/null 2>&1"); xsystem("iptables -A INPUT -o lo -s 127.0.0.1 -j ACCEPT >/dev/null 2>&1"); if(nonetwork==0) { if(file_exists("/service/init/network.init")) { lcd_msg("START SERVICES..","-> NETWORKING"); wait_prog("Bringing up network interfaces.","/service/init","network.init","start"); } if(file_exists("/service/init/dns.init")) { lcd_msg("START SERVICES..","-> DNS RESOLVER"); wait_prog("Starting DNS Resolver Agent.","/service/init","dns.init","start"); } if(file_exists("/service/init/policy.init")) { lcd_msg("START SERVICES..","-> PACKET FILTER"); wait_prog("Applying packet filter rules.","/service/init","policy.init","start"); } } if(file_exists("/service/init/syslog.init")) { lcd_msg("START SERVICES..","-> SYSTEM LOGGER"); wait_prog("Starting Syslog.","/service/init","syslog.init","start"); } if(file_exists("/service/tools/mfs-query.exc")) { lcd_msg("START SERVICES..","-> MYBOX AGENTS"); fprintf_stdout("* Starting Mybox Agents: "); xsystem("/service/tools/mfs-query.exc q >/dev/null 2>&1"); fprintf_stdout(" query"); xsystem("/service/tools/mfs-query.exc i >/dev/null 2>&1"); fprintf_stdout(" ips"); xsystem("/service/tools/mfs-query.exc o >/dev/null 2>&1"); fprintf_stdout(" others"); putchar('\n'); } if(nonetwork==0) { if(snmp_stat==1) { if(file_exists("/service/init/snmp.init")) { lcd_msg("START SERVICES..","-> SNMP AGENT"); wait_prog("Starting SNMP Agent.","/service/init","snmp.init","start"); } } if(ips_stat==1) { if(file_exists("/service/init/ips.init")) { lcd_msg("START SERVICES..","-> IPS AGENT"); wait_prog("Starting IPS Agent.","/service/init","ips.init","start"); } } if(auth_ad==1) { if(file_exists("/service/init/auth.init")) { lcd_msg("START SERVICES..","-> AUTH AD AGENT"); wait_prog("Starting Auth AD Agent.","/service/init","auth.init","start"); } } if(pptp_stat==1) { if(file_exists("/service/init/pptp.init")) { lcd_msg("START SERVICES..","-> PPTP VPN"); wait_prog("Starting PPTP VPN Agent.","/service/init","pptp.init","start"); } } if(dhcp_stat==1) { if(file_exists("/service/init/dhcp.init")) { lcd_msg("START SERVICES..","-> DHCP AGENT"); wait_prog("Starting DHCP Agent.","/service/init","dhcp.init","start"); } } if(ftp_stat==1) { if(file_exists("/service/init/ftp.init")) { lcd_msg("START SERVICES..","-> FTP AGENT"); wait_prog("Starting FTP Agent.","/service/init","ftp.init","start"); } } if(https_stat==1) { if(file_exists("/service/init/https.init")) { lcd_msg("START SERVICES..","-> MYADMIN AGENT"); wait_prog("Starting MyAdmin HTTPS Agent.","/service/init","https.init","start"); } } if(ssh_stat==1) { if(file_exists("/service/init/ssh.init")) { lcd_msg("START SERVICES..","-> SSH AGENT"); wait_prog("Starting SSH Agent.","/service/init","ssh.init","start"); } } if(ddns_stat==1) { if(file_exists("/service/init/ddns.init")) { lcd_msg("START SERVICES..","-> DYNAMIC DNS"); wait_prog("Starting Dynamic DNS Agent.","/service/init","ddns.init","start"); } } if(shaper_stat==1) { if(file_exists("/service/init/shaper.init")) { lcd_msg("START SERVICES..","-> SHAPER"); wait_prog("Starting bandwidth shaper.","/service/init","shaper.init","start"); } } if(file_exists("/service/init/misc.init")) { lcd_msg("START SERVICES..","-> STATIC ARP"); wait_prog("Starting static ARP.","/service/init","misc.init","staticarp"); } } if(file_exists("/service/tools/mfs-graph.exc")) { lcd_msg("START SERVICES..","-> GRAPH"); wait_prog("Creating diagnostic graphs.","/service/tools","mfs-graph.exc","--"); } if(file_exists("/service/tools/mfs-query.exc")) { lcd_msg("START SERVICES..","-> GRAPH"); wait_prog("Compressing logs","/service/tools","mfs-query.exc","l"); } if(file_exists("/service/init/cron.init")) { lcd_msg("START SERVICES..","-> SCHEDULER"); wait_prog("Starting scheduler Agent.","/service/init","cron.init","start"); } unlink("/var/sys/init_no_restart"); }
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); }
void build_menu() { Preparat p; system("color 02"); menustart: system("cls"); printf("Alegeti optiunea:\n\n"); printf("1. Adauga element la inceputul listei.\n"); printf("2. Adauga element la sfarsitul listei.\n"); printf("3. Afiseaza lista din memorie.\n"); printf("4. Afiseaza lista din fisier.\n"); printf("5. Sterge un element din lista.\n"); printf("6. Incarca lista din fisier in memorie.\n"); printf("7. Sterge toate elementele listei din memorie.\n"); printf("8. Sorteaza elementele in fisier dupa metoda Shell.\n"); printf("9. Salveaza lista in fisier.\n"); printf("10. Modifica un element din lista.\n"); printf("11. Iesire din program.\n\n"); int option; scanf("%d", &option); system("cls"); switch (option) { case 1: printf("Nume preparat:"); scanf("%s", &p.nume); printf("Pret:"); scanf("%d", &p.pret); printf("Este nevoie de prescriptie medicala? (Da/Nu):"); scanf("%s", &p.pr_med); printf("Tip Preperat:"); scanf("%s", &p.tip); add_first(p); goto menustart; break; case 2: printf("Nume preparat:"); scanf("%s", &p.nume); printf("Pret:"); scanf("%d", &p.pret); printf("Este nevoie de prescriptie medicala? (Da/Nu):"); scanf("%s", &p.pr_med); printf("Tip Preperat:"); scanf("%s", &p.tip); add_last(p); goto menustart; break; case 3: display(0); getch(); goto menustart; break; case 4: display(1); getch(); goto menustart; break; case 5: printf("Indicati indexul elementului pentru a fi sters:"); int index; scanf("%d", &index); delete_at(index); getch(); goto menustart; break; case 6: read_from_file(); goto menustart; break; case 7: clear_list(); printf("Sters cu success!!"); getch(); goto menustart; break; case 8: file_shell_sort(); getch(); goto menustart; break; case 9: save_to_file(); goto menustart; break; case 10: printf("\nDati indexul elementului ce necesita modificare:"); int ind; scanf("%d", &ind); edit_at(ind); goto menustart; case 11: exit(0); break; default: printf("Optiune indicata gresit."); break; } }
int initrc_main(int argc, char **argv) { DIR *dp; struct dirent *dt; char cmd[1024]; (void) signal(SIGINT,SIG_IGN); freopen("/dev/null", "w", stderr); putenv("PATH=/bin"); putenv("TERM=linux"); umask(0770); chdir("/"); if(file_exists("/strg/.nostrg")) { unlink("/strg/.nostrg"); DO_SINGLE=1; } save_to_file("/proc/sys/kernel/printk","0 0 0 0\n"); //clean rc.bootup stuff umount("/initrd/sys"); umount("/initrd"); xsystem("rm -rf /initrd /bootup"); save_to_file("/bin/groups","#!/bin/sh\necho \"mfs\"\n"); chmod("/bin/groups",S_IREAD | S_IWRITE | S_IEXEC); if(is_dir("/tmp/tools")) { if((dp=opendir("/tmp/tools")) == NULL) { perror("opendir"); exit(1); } fprintf_stdout("-> Extracting helper tools."); while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue; if(strstr(dt->d_name,".bz2")) { fprintf_stdout("."); xsystem("tar -C / -jxf /tmp/tools/%s",dt->d_name); usleep(10000); } } free(dt); closedir(dp); fprintf_stdout("\r* Extracting helper tools. Done.%s\n",SPACE); } memset(cmd,0x0,sizeof(cmd)); if(is_dir("/tmp/modules")) { if((dp=opendir("/tmp/modules")) == NULL) { perror("opendir"); exit(1); } fprintf_stdout("-> Extracting system modules."); while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue; if(strstr(dt->d_name,".bz2")) { fprintf_stdout("."); xsystem("tar -C / -jxf /tmp/modules/%s",dt->d_name); usleep(10000); } } free(dt); closedir(dp); fprintf_stdout("\r* Extracting system modules. Done.%s\n",SPACE); } memset(cmd,0x0,sizeof(cmd)); if(file_exists("/etc/microcode.dat")) xsystem("/bin/microcode_ctl -Qui"); // chk network device network_touch(); //default domain save_to_file("/proc/sys/kernel/hostname","fw.mybox.local\n"); xsystem("chmod 700 /service/www/*.html"); xsystem("chmod 700 /service/tools/*.exc"); //if(DO_SINGLE==0) startprog(); if(DO_SINGLE==0 && file_exists("/etc/rc.start/sh")) { xsystem("/etc/rc.start/sh"); } // post-boot if(file_exists("/strg/mybox/post-boot") && DO_SINGLE==0) { chmod("/strg/mybox/post-boot",S_IREAD | S_IWRITE | S_IEXEC); fprintf_stdout("* Executing post-boot: /strg/mybox/post-boot\n"); xsystem("/strg/mybox/post-boot >/dev/null 2>&1"); } // clean space xsystem("rm -rf /etc/inittab /etc/microcode.dat /bin/microcode_ctl /strg/mybox/download/* /var/sys/init_no_restart /bin/initrc /tmp/* /usr/share/fonts /var/sys/init_start /etc/rc.start"); //clean unuse modules if(file_exists("/service/tools/mfs-rmmod.exc")) { xsystem("/bin/php -f /service/tools/mfs-rmmod.exc >/dev/null 2>&1"); } if(file_exists("/etc/rc.sysctl/sh")) { fprintf_stdout("* Setting kernel parameters. Done.\n"); lcd_msg("SYSTEM LOADING..","-> TUNE KERNEL"); xsystem("/etc/rc.sysctl/sh >/dev/null 2>&1"); } //console session xsystem("mkdir -p /tmp/console.session"); if(is_dir("/strg/mybox/")) { xsystem("dmesg -c -s 131072 > /strg/mybox/boot.msg"); } xflush_stdout(); (void) signal(SIGINT,SIG_DFL); if(DO_SINGLE==1) run_shell(); if(DO_SINGLE==1) xsystem("/bin/reboot"); save_to_file("/proc/sys/kernel/printk","6 0 0 0\n"); xsystem("chmod 700 /*"); if(file_exists("/dev/lcd") && file_exists("/bin/lcdd")) { xsystem("/bin/lcdd"); xtouch("/var/sys/chk_lcdd"); } exit(0); }
LRESULT CALLBACK BROWSEDlghandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static int t,port=DEF_MIDIPORT,midichn=1,instrument=11; static char szFileName[MAX_PATH]; static int oldtone=0; switch( message ) { case WM_INITDIALOG: { SCROLLINFO lpsi; init_midi(); strcpy(LOADSCALE.name,"Chromatic1-127"); for (t=1;t<128;t++) LOADSCALE.tones[t-1]=t; LOADSCALE.len=127; SetDlgItemText(hDlg, IDC_HARMONICNAME, LOADSCALE.name); for (t=0;t<255;t++) SendDlgItemMessage(hDlg, IDC_MIDIINSTCOMBO, CB_ADDSTRING, 0,(LPARAM) (LPSTR) midi_instnames[t]) ; SendDlgItemMessage( hDlg, IDC_MIDIINSTCOMBO, CB_SETCURSEL, instrument, 0L ) ; for (t = 0; t < midiports; t++) if(MIDIPORTS[t].midiout) SendDlgItemMessage(hDlg, IDC_MIDIPORTCOMBO, CB_ADDSTRING, 0, (LPARAM) (LPSTR) MIDIPORTS[t].portname ) ; SetDlgItemText(hDlg, IDC_MIDIPORTCOMBO, MIDIPORTS[port].portname); lpsi.cbSize=sizeof(SCROLLINFO); lpsi.fMask=SIF_RANGE|SIF_POS; lpsi.nMin=1; lpsi.nMax=127; SetScrollInfo(GetDlgItem(hDlg,IDC_TONEBAR),SB_CTL,&lpsi,TRUE); SetScrollPos(GetDlgItem(hDlg, IDC_TONEBAR), SB_CTL, 64, 1); SetDlgItemInt(hDlg, IDC_ACTTONE, 64,0); SetDlgItemInt(hDlg, IDC_MIDICHN, midichn,0); midi_Instrument(&(MIDIPORTS[port].midiout),midichn,instrument); update_harmonic(GetDlgItem(hDlg, IDC_HARMONICLIST)); } return TRUE; case WM_CLOSE: midi_NoteOff(&(MIDIPORTS[port].midiout), midichn,oldtone); EndDialog(hDlg, LOWORD(wParam)); return TRUE; break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_MIDIPORTCOMBO: if (HIWORD(wParam)==CBN_SELCHANGE) port=get_listed_midiport(SendMessage(GetDlgItem(hDlg, IDC_MIDIPORTCOMBO), CB_GETCURSEL , 0, 0)); midi_Instrument(&(MIDIPORTS[port].midiout),midichn,instrument); break; case IDC_MIDIINSTCOMBO: instrument=SendMessage(GetDlgItem(hDlg, IDC_MIDIINSTCOMBO), CB_GETCURSEL , 0, 0); midi_Instrument(&(MIDIPORTS[port].midiout),midichn,instrument); break; case IDC_MIDICHN: midichn=GetDlgItemInt(hDlg, IDC_MIDICHN, NULL, 0); midi_Instrument(&(MIDIPORTS[port].midiout),midichn,instrument); break; case IDC_DELTONE: { int select; select=SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_GETCURSEL , 0, 0L ) ; if ((select>=0)&&(select<LOADSCALE.len)) { SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_DELETESTRING , (WPARAM) select, 0L ) ; LOADSCALE.len--; SetFocus(GetDlgItem(hDlg,IDC_HARMONICLIST)); SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_SETCURSEL , (WPARAM) select, 0L ) ; apply_harmonic(hDlg); } // else report("Nothing selected"); } break; case IDC_HARMONICNAME: GetDlgItemText(hDlg, IDC_HARMONICNAME, LOADSCALE.name, 256); break; case IDC_ADDTONE: { int index,dataint,select; char szdata[5]; if (LOADSCALE.len<MAX_HARMONICTONES-1) { select=SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_GETCURSEL , 0, 0L )+1 ; if ((select<1)||(select>LOADSCALE.len)) select=LOADSCALE.len; GetDlgItemText(hDlg, IDC_ACTTONE, szdata, 4); dataint=GetDlgItemInt(hDlg, IDC_ACTTONE, 0,0); index=SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_INSERTSTRING , (WPARAM) select, (LPARAM) szdata) ; SendDlgItemMessage(hDlg, IDC_HARMONICLIST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)dataint); LOADSCALE.len++; SetFocus(GetDlgItem(hDlg,IDC_HARMONICLIST)); apply_harmonic(hDlg); } ; } break; case IDC_HARMONICCLEAR: SendDlgItemMessage(hDlg, IDC_HARMONICLIST, LB_RESETCONTENT, 0, 0); LOADSCALE.len=0; apply_harmonic(hDlg); break; case IDC_LOADHARMONIC: { strcpy(szFileName,DEFPATH); strcat(szFileName,"TONESCALES\\default.sc"); if (open_file_dlg(hDlg, szFileName, OPEN_LOAD)) { /* char tmp[256],*p1,*p2,diff=0; strcpy(tmp,DEFPATH); strcat(tmp,"TONESCALES\\"); for (p1=tmp,p2=szFileName;(*p1) && (*p2) && (!diff);p1++,p2++) if (tolower(*p1)!=tolower(*p2)) diff=1; if (diff||(strlen(tmp)>strlen(szFileName))) report("Please use Tonescales-subfolder of brainbay application to load/store palette files"); else*/ { if (!load_from_file(szFileName, &LOADSCALE, sizeof(struct SCALEStruct))) report("Could not load Harmonic Scale"); else { update_harmonic(GetDlgItem(hDlg, IDC_HARMONICLIST)); SetDlgItemText(hDlg, IDC_HARMONICNAME, LOADSCALE.name); } } } else report("Could not load Harmonic Scale"); } break; case IDC_SAVEHARMONIC: { char temp[100]; strcpy(szFileName,DEFPATH); strcat(szFileName,"TONESCALES\\"); GetDlgItemText(hDlg, IDC_HARMONICNAME, temp, MAX_PATH); strcat (szFileName,temp); strcat (szFileName,".sc"); if (open_file_dlg(hDlg, szFileName, OPEN_SAVE)) { /* char tmp[256],*p1,*p2,diff=0; strcpy(tmp,DEFPATH); strcat(tmp,"TONESCALES\\"); for (p1=tmp,p2=szFileName;(*p1) && (*p2) && (!diff);p1++,p2++) if (tolower(*p1)!=tolower(*p2)) diff=1; if (diff||(strlen(tmp)>strlen(szFileName))) report("Please use Tonescales-subfolder of brainbay application to load/store palette files"); else*/ { if (!save_to_file(szFileName, &LOADSCALE, sizeof(struct SCALEStruct))) report("Could not save Scale"); } } } break; case IDC_HARMONICLIST: if (HIWORD(wParam)==LBN_SELCHANGE) { int dataint,sel; sel=SendDlgItemMessage( hDlg, IDC_HARMONICLIST, LB_GETCURSEL , 0, 0L ) ; dataint=SendDlgItemMessage(hDlg, IDC_HARMONICLIST, LB_GETITEMDATA, (WPARAM)sel, 0); midi_NoteOff(&(MIDIPORTS[port].midiout), midichn,oldtone); oldtone=dataint; midi_NoteOn(&(MIDIPORTS[port].midiout), midichn, dataint,127); } break; } return TRUE; case WM_HSCROLL: { int nNewPos; if ((nNewPos=get_scrollpos(wParam,lParam))>=0) { if (lParam == (long) GetDlgItem(hDlg,IDC_TONEBAR)) { SetDlgItemInt(hDlg, IDC_ACTTONE,nNewPos,0); midi_NoteOff(&(MIDIPORTS[port].midiout), midichn,oldtone); oldtone=nNewPos; midi_NoteOn(&(MIDIPORTS[port].midiout), midichn,nNewPos,127); apply_harmonic(hDlg); } } } break; case WM_SIZE: case WM_MOVE: ; break; return TRUE; } return FALSE; }
static void save_to_file( const T& v, const std::string& p, bool pretty = true, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH ) { save_to_file( variant(v, max_depth), fc::path(p), pretty, format, max_depth ); }