u_char read_db_hdr(DCC_EMSG emsg, DB_HDR *hdrp, int fd, const char *file_nm) { int i; i = read_db(emsg, hdrp, sizeof(*hdrp), fd, 0, file_nm); if (i == sizeof(*hdrp)) return 1; if (i >= 0) dcc_pemsg(EX_DATAERR, emsg, "found only %d bytes in %s", i, file_nm); return 0; }
int main(int argc,char **argv) { anthy_context_t ac; FILE *fp; struct input cur_input; struct res_db *db; struct condition cond; cur_input.serial = 0; cur_input.str = 0; init_condition(&cond); parse_args(&cond, argc, argv); db = create_db(); read_db(db, expdata); printf("./test_anthy --help to print usage.\n"); print_run_env(); fp = fopen(testdata, "r"); if (!fp) { printf("failed to open %s.\n", testdata); return 0; } ac = init_lib(cond.use_utf8); /* ファイルを読んでいくループ */ while (!read_file(fp, &cur_input)) { if (check_cond(&cond, &cur_input)) { set_string(&cond, db, &cur_input, ac); } } anthy_release_context(ac); anthy_quit(); if (cond.ask) { /* ユーザに聞く */ ask_results(db); } show_stat(db); save_db(expdata, db); return 0; }
u_short reload(void) { u_short i = 0; tell_chans("reloading databases..."); log("reloading databases..."); del_all_clone_allows(); del_all_snuggles(); if ((i = read_db(0)) > 0) { tell_chans("\2[ERROR]\2 Unable to read %s: %s", databases[i], strerror(errno)); goto r_err; } tell_chans("done!"); log("done!"); return 0; r_err: return tell_chans("\2[ERROR]\2 Error while rehashing!"); }
struct database *open_db(char *fn, int wr) { struct database *db; DB_NEW(db); db->fh = open_file(fn, wr); if (!db->fh) { DBerror("Cannot open database %s\n", fn); free(db); return NULL; } db->fn = xstrdup(fn); if (read_db(db) < 0) { free(db->fn); free(db); return NULL; } return db; }
static int print_budget_verbose(int summary) { struct tm *stime; int monthly_budget, daily_budget, spent, budget_today, remaining, next_day; int ret; if((ret = read_db(&monthly_budget, &spent)) != EXIT_SUCCESS) return ret; stime = local_time(); daily_budget = monthly_budget / days_this_month(); budget_today = monthly_budget * stime->tm_mday / days_this_month(); remaining = budget_today - spent; if(summary) { printf("--------------------------------------\n"); printf(" JUNK FOOD SUMMARY:\n"); printf("--------------------------------------\n"); printf(" Today is %02d.%02d.%4d.\n", stime->tm_mday, stime->tm_mon + 1, stime->tm_year + 1900); printf(" Your monthly budget is: %d.%02d " CURRENCY "\n", BREAKUP(monthly_budget)); printf(" You spent: %d.%02d " CURRENCY "\n", BREAKUP(spent)); printf(" Budget until today: %d.%02d " CURRENCY "\n", BREAKUP(budget_today)); printf("--------------------------------------\n\n"); } printf("You can spend "); if(remaining >= 0) { printf("%d.%02d " CURRENCY "\n\n", BREAKUP(remaining)); } else if(spent < monthly_budget) { next_day = days_this_month() - (monthly_budget - spent) / daily_budget; if(spent % daily_budget == 0) next_day++; printf("again on %02d.%02d.%4d\n\n", next_day, stime->tm_mon + 1, stime->tm_year + 1900); } else { printf("again next month.\n\n"); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { /*initialize the connection to the freedb server */ cddb_conn_t *conn = NULL; cddb_disc_t *disc; cddb_track_t *track; conn = init_conn(); /* set track info */ if (argc != 4) { fprintf(stderr, "usage: cddb_query <discid> <category> <track number>\n"); return -1; } char *p; unsigned long discid = strtoul(argv[1], &p, 16); char *cat = argv[2]; lowercase(cat); int tracknum = atoi(argv[3]); /* initialize the disc */ disc = init_disc(); cddb_disc_set_discid(disc, discid); cddb_disc_set_category_str(disc, cat); /* query the database to populate the disc info */ read_db(conn, disc); /* extract the track from the disc */ track = cddb_disc_get_track(disc, tracknum - 1); /* format an output track info */ const char *title = cddb_track_get_title(track); const char *artist = cddb_disc_get_artist(disc); const char *album = cddb_disc_get_title(disc); unsigned int date = cddb_disc_get_year(disc); const char *label = ""; const char *genre = cddb_disc_get_genre(disc); printf("%s\t%s\t%s\t%d\t%s\t%s\t", title, artist, album, date, label, genre); return 0; }
Reader() { while (TRUE) { down(&mutex); reader_count = reader_count + 1; if (reader_count == 1){ down(&db);} up(&mutex); read_db(); down(&mutex); reader_count = reader_count - 1; if (reader_count == 0){ up(&db);} up(&mutex);} Writer() { while (TRUE) { create_data(); down(&db); write_db(); up(&db);}
/*}}}*/ static void read_multi(const char *dbname, struct node *top, struct prune_data *prunings)/*{{{*/ { FILE *in; char line[256], *p; in = fopen(dbname, "r"); if (!in) { fprintf(stderr, "Could not open %s\n", dbname); exit(2); } while (fgets(line, sizeof(line), in)) { if (line[0] == '#') continue; p = line + strlen(line); assert(*p == 0); p--; while((p >= line) && isspace(*p)) { *p = 0; p--; } if (p > line) { read_db(line, top, prunings); } } fclose(in); }
void Write_setting::run(int ID) { createConnection(); motor motor1 = read_db(ID); closeDBConnection(); // qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); char setting_filename[50]; itoa(int(ID), setting_filename, 50); strcat(setting_filename,".ini"); QSettings M_settings(setting_filename, QSettings::IniFormat); // M_settings.beginGroup("motor"); // QStringList keys = M_settings.allKeys(); // motor1.set_power(M_settings.value("power").toInt()); M_settings.setValue("var_stator_DiaGap", motor1.Stator.DiaGap); M_settings.setValue("var_stator_DiaYoke", motor1.Stator.DiaYoke); M_settings.setValue("var_stator_Length", motor1.Stator.Length); M_settings.setValue("var_stator_Skew", motor1.Stator.Skew); M_settings.setValue("var_stator_Slots", motor1.Stator.Slots); M_settings.setValue("var_stator_SlotType", motor1.Stator.SlotType); M_settings.setValue("var_stator_Hs0", motor1.Stator.Hs0); M_settings.setValue("var_stator_Hs01", motor1.Stator.Hs01); M_settings.setValue("var_stator_Hs1", motor1.Stator.Hs1); M_settings.setValue("var_stator_Hs2", motor1.Stator.Hs2); M_settings.setValue("var_stator_Bs0", motor1.Stator.Bs0); M_settings.setValue("var_stator_Bs1", motor1.Stator.Bs1); M_settings.setValue("var_stator_Bs2", motor1.Stator.Bs2); M_settings.setValue("var_stator_Rs", motor1.Stator.Rs); M_settings.setValue("var_stator_FilletType", motor1.Stator.FilletType); M_settings.setValue("var_stator_HalfSlot", motor1.Stator.HalfSlot); M_settings.setValue("var_stator_SegAngle", motor1.Stator.SegAngle); M_settings.setValue("var_stator_LenRegion", motor1.Stator.LenRegion); M_settings.setValue("var_stator_InfoCore", motor1.Stator.InfoCore); M_settings.setValue("var_rotor_DiaGap", motor1.Rotor.DiaGap); M_settings.setValue("var_rotor_DiaYoke", motor1.Rotor.DiaYoke); M_settings.setValue("var_rotor_Length", motor1.Rotor.Length); M_settings.setValue("var_rotor_Poles", motor1.Rotor.Poles); M_settings.setValue("var_rotor_PoleType", motor1.Rotor.PoleType); M_settings.setValue("var_rotor_D1", motor1.Rotor.D1); M_settings.setValue("var_rotor_O1", motor1.Rotor.O1); M_settings.setValue("var_rotor_O2", motor1.Rotor.O2); M_settings.setValue("var_rotor_B1", motor1.Rotor.B1); M_settings.setValue("var_rotor_Rib", motor1.Rotor.Rib); M_settings.setValue("var_rotor_HRib", motor1.Rotor.HRib); M_settings.setValue("var_rotor_DminMag", motor1.Rotor.DminMag); M_settings.setValue("var_rotor_thickMag", motor1.Rotor.thickMag); M_settings.setValue("var_rotor_WidthMag", motor1.Rotor.WidthMag); M_settings.setValue("var_rotor_LenRegion", motor1.Rotor.LenRegion); M_settings.setValue("var_rotor_InfoCore", motor1.Rotor.InfoCore); M_settings.setValue("var_coil_DiaGap", motor1.Coil.DiaGap); M_settings.setValue("var_coil_DiaYoke", motor1.Coil.DiaYoke); M_settings.setValue("var_coil_Length", motor1.Coil.Length); M_settings.setValue("var_coil_Skew", motor1.Coil.Skew); M_settings.setValue("var_coil_Slots", motor1.Coil.Slots); M_settings.setValue("var_coil_SlotType", motor1.Coil.SlotType); M_settings.setValue("var_coil_Hs0", motor1.Coil.Hs0); M_settings.setValue("var_coil_Hs1", motor1.Coil.Hs1); M_settings.setValue("var_coil_Hs2", motor1.Coil.Hs2); M_settings.setValue("var_coil_Bs0", motor1.Coil.Bs0); M_settings.setValue("var_coil_Bs1", motor1.Coil.Bs1); M_settings.setValue("var_coil_Bs2", motor1.Coil.Bs2); M_settings.setValue("var_coil_Rs", motor1.Coil.Rs); M_settings.setValue("var_coil_FilletType", motor1.Coil.FilletType); M_settings.setValue("var_coil_Layers", motor1.Coil.Layers); M_settings.setValue("var_coil_CoilPitch", motor1.Coil.CoilPitch); M_settings.setValue("var_coil_EndExt", motor1.Coil.EndExt); M_settings.setValue("var_coil_SpanExt", motor1.Coil.SpanExt); M_settings.setValue("var_coil_SegAngle", motor1.Coil.SegAngle); M_settings.setValue("var_coil_LenRegion", motor1.Coil.LenRegion); M_settings.setValue("var_coil_InfoCore", motor1.Coil.InfoCore); M_settings.setValue("var_magnet_DiaGap", motor1.Magnet.DiaGap); M_settings.setValue("var_magnet_DiaYoke", motor1.Magnet.DiaYoke); M_settings.setValue("var_magnet_Length", motor1.Magnet.Length); M_settings.setValue("var_magnet_Poles", motor1.Magnet.Poles); M_settings.setValue("var_magnet_PoleType", motor1.Magnet.PoleType); M_settings.setValue("var_magnet_D1", motor1.Magnet.D1); M_settings.setValue("var_magnet_O1", motor1.Magnet.O1); M_settings.setValue("var_magnet_O2", motor1.Magnet.O2); M_settings.setValue("var_magnet_B1", motor1.Magnet.B1); M_settings.setValue("var_magnet_Rib", motor1.Magnet.Rib); M_settings.setValue("var_magnet_HRib", motor1.Magnet.HRib); M_settings.setValue("var_magnet_DminMag", motor1.Magnet.DminMag); M_settings.setValue("var_magnet_thickMag", motor1.Magnet.thickMag); M_settings.setValue("var_magnet_WidthMag", motor1.Magnet.WidthMag); M_settings.setValue("var_magnet_LenRegion", motor1.Magnet.LenRegion); M_settings.setValue("var_magnet_InfoCore", motor1.Magnet.InfoCore); // qDebug() << M_settings.value("power"); // qDebug() << motor1.read_power(); //qDebug() << "From worker thread: " << currentThreadId(); qDebug() << "Writing ini file finished"; }
int main(int argc, char *argv[]) { int i=0, pos=0, pos_e=0, next_option, no_download=0, count_match=0, only_refresh=0, print_only_date=0; char str[LENGTH_STRING_IN_FILE], str_out[LENGTH_STRING_IN_FILE], file_name[LENGTH_OF_FILENAME], name[LENGTH_STRING_IN_FILE], link[LENGTH_STRING_IN_FILE]; FILE *ep_serial=NULL, *l_db; //this should be in imdb.h ldb char str_se[LENGTH_STRING_IN_FILE]="Season "; struct stat st; const char* number_season=NULL; const char* episode=NULL; const struct option long_options[] = { { "help", 0, NULL, 'h'}, { "serial", 1, NULL, 's'}, { "no-download",0, NULL, 'd'}, { "season", 1, NULL, 'S'}, { "update", 0, NULL, 'u'}, { "episode", 1, NULL, 'e'}, { "date", 0, NULL, 'D'}, { NULL, 0, NULL, 0 } }; const char* const short_options = "hs:dS:ue:D"; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': /* -h --help*/ print_usage (stdout, 0, argv[0]); case 's': /* -s --serial*/ if(strlen(optarg) < LENGTH_STRING_IN_FILE) strcpy(serial_name, optarg); else { printf("\nUnknown defintion of [serial] option\nYou entired: <%s>\n", optarg); exit (1); } break; case 'd': //-d for no download no_download=1; break; case 'S': //it will season number_season = optarg; break; case 'u': //for refresh option only_refresh=1; break; case 'e': //for only episode print episode=optarg; break; case 'D': //for print only date of needed episode print_only_date=1; break; case '?': /*uknowkn option*/ print_usage (stderr, 1, argv[0]); case -1: /*no options*/ break; default: //unknokwn result abort (); } } while (next_option != -1); //getting our variable strcpy(config_directory, getenv("HOME")); //copy variable HOME strcat(config_directory, "/.imdb"); //added /.imdb to this variable strcpy(config_file,config_directory); strcat(config_file, "/links_db"); strcpy(working_file, config_directory); strcat(working_file, "/"); if(stat(config_directory, &st)) //checking for existence of our configuration directory mkdir(config_directory, 0777); if(stat(config_file, &st)) { //checking for existence for configuration file if ((l_db = fopen(config_file, "w")) == NULL) { printf("Error while open file %s\n", config_file); perror(""); exit (1); } if (fwrite(text_of_config, sizeof(char), strlen(text_of_config), l_db) < strlen(text_of_config)) { printf("Error while writing to file %s\n", config_file); perror(""); exit (1); } fclose (l_db); //replace this to read_db function } if (argc == 1) { print_usage (stderr, 1, argv[0]); } if (only_refresh) { //change all if to case download_all_files(); exit (0); } if(number_season != NULL && strlen(number_season) > 2) { printf("\nUnknown defintion of [season] option\nYou entired: <%s>\n", number_season); exit(1); } if(number_season != NULL) strcat(str_se, number_season); if(episode != NULL && number_season != NULL && strlen(episode) < 4) { strcat(str_se, ", Episode "); strcat(str_se, episode); strcat(str_se, ":"); } else if (number_season == NULL && episode != NULL) { printf("\n---You should define [episode] option with [season]---\n"); exit (1); } else if (number_season != NULL && episode !=NULL && strlen(episode) > 4) { printf("\nUnknown definition of [episode] option\nYou entired: <%s>\n", episode); exit (1); } else if ((episode == NULL || number_season == NULL) && print_only_date) { printf("\n---You should define [season] and [episode] for use option [date]---\n"); exit (1); } if(strlen(serial_name) <= 4) { printf("\n\n----You must specify more then %d symbols in [serial] variable----\n\n", strlen(serial_name)); exit(1); } if(!read_db('n', name)) { printf("!!!No match found by serial name!!!\nYou entired: <%s>\n", serial_name); exit(1); } else { read_db('l', link); //read_db('n', name); read_db('f', file_name); strcat(working_file, file_name); } if(no_download) { if((ep_serial = fopen(working_file, "r"))==NULL) { printf("Error while open file %s", file_name); perror(""); exit(1); } } else { if (get_episodes(working_file, link)) printf("No connection ?\n"); ep_serial = fopen(working_file, "r"); } while(!feof(ep_serial)) { if(fgets(str, LENGTH_STRING_IN_FILE - 1, ep_serial)) { if(!i) { if (print_only_date); else { printf("\n\t /-------------The name of serial is %s-------------\\\n\n", name); printf("--------Season----------------Date-------------------Title------------------\n"); } } for(i=0; i<= strlen(str); i++) { if(copy_check(i, str, str_out, strlen(str_s), str_s) != -1 && pos_e) { pos=copy_check(i, str, str_out, strlen(str_s), str_s); if (print_only_date) print_result(pos, str); else { print_season_episode(pos_e, str); printf("\t| "); print_result(pos, str); printf(" \t| "); print_result(pos_e, str); printf("\n----------------------------------------------------------------------------\n"); } count_match++; pos_e=0; pos=0; } if(copy_check(i, str, str_out, strlen(str_se), str_se) != -1) //it will find Season info which is first in string - so pos_e can't be 0 when we try find Original Air Date pos_e=copy_check(i, str, str_out, strlen(str_se), str_se); } } } if(!count_match) printf("\n----------------------------!!!No match found!!!----------------------------\n"); fclose(ep_serial); return 0; }
int main(int argc, char **argv) { int x; umask(0077); /* initialize stuff */ memset(&me, 0, sizeof(me)); me.argc = argc; me.argv = argv; me.start = time(NULL); me.settime = time(NULL) + (60*60*4); /* setup signals */ signal(SIGHUP, do_signal); signal(SIGINT, do_signal); signal(SIGQUIT, do_signal); signal(SIGILL, do_signal); signal(SIGTRAP, do_signal); signal(SIGBUS, do_signal); signal(SIGSEGV, do_signal); signal(SIGSYS, do_signal); signal(SIGALRM, SIG_IGN); signal(SIGTERM, do_signal); signal(SIGPIPE, SIG_IGN); signal(SIGUSR1, SIG_IGN); signal(SIGUSR2, SIG_IGN); while ((x = getopt(me.argc, me.argv, "qd")) != -1) { switch (x) { case 'd': me.debug = 1; break; } } if (me.debug == 0) printf("%s by %s\n", VER_STR, MYEMAIL); if (read_conf()) err(1, "ERROR! Unable to read configuration file"); if (!me.servname || !me.servdesc) errx(1, "ERROR! Your M: line is invalid, incomplete, or missing!"); for (x = 0; x < ALL; x++) if (!me.sclients[x].nick || check_nick(NULL, me.sclients[x].nick) || !me.sclients[x].username || check_um(NULL, me.sclients[x].username) || !me.sclients[x].realname || check_rm(NULL, me.sclients[x].realname)) errx(1, "ERROR! Your N: line for %d is invalid, incomplete, or missing!", x); if (!me.chans[0]) errx(1, "ERROR! You need at least one R: line in %s", CONF); if (!(me.logfd = fopen(PIDFILE, "w"))) err(1, "ERROR! Unable to open pidfile"); fprintf(me.logfd, "%d\n", getpid()); fclose(me.logfd); if (!(me.logfd = fopen(LOGFILE, "a"))) err(1, "ERROR! Unable to open logfile"); if ((x = read_db(0)) > 0) err(1, "ERROR! Unable to read %s", databases[x]); if (me.ip.s_addr == NULL) { if (!self_lookup()) err(1, "ERROR! self-lookup failed!"); else printf("WARNING: no vhost defined in conf, using default of %s\n", inet_ntoa(me.ip)); } if (me.debug == 0) switch (me.pid = fork()) { case -1: err(1, "ERROR! Unable to fork"); case 0: for (x = 0; x < 12; x++) if (x != fileno(me.logfd)) close(x); break; default: printf("forked into the background: pid = %d\n", me.pid); return 0; } listen_sock(7272); try_next_hub(); add_event(1, SERVTIMEOUT / 2, &ping_hub); add_event(1, CONNTIMEOUT / 3, &cleanup_dcc); io_loop(); /* NOTREACHED */ exit(0); }