void Java_com_test_lame_TestLameActivity_convertMP3(JNIEnv* env,jobject thiz,jstring inFile ,jstring outFile, jstring progF, int sampleRate, int bitRate){ userCancel=0; totBytes=0; lame_global_flags *gf = lame_init(); lame_set_num_channels(gf, 1); lame_set_in_samplerate(gf,sampleRate); lame_set_brate(gf,bitRate); lame_set_bWriteVbrTag(gf,0); int ipr = lame_init_params(gf); const char* outfs; outfs = (*env)->GetStringUTFChars(env, outFile, NULL); const char* infs; infs = (*env)->GetStringUTFChars(env,inFile, NULL); int enc_delay = -1; int enc_padding = -1; const char* progfs; progfs = (*env)->GetStringUTFChars(env, progF, NULL); //set the global progress file variable to be accessed in lame_encoder() progFile = fopen(progfs,"w"); FILE *outf = init_files(gf,infs,outfs,&enc_delay,&enc_padding); lame_encoder(gf, outf,0 ,infs ,outfs ); }
static void remove_cb(GtkWidget * w, gpointer data) { vcedit_state *state; vorbis_comment *comment; if (!g_strncasecmp(vte.filename, "http://", 7)) return; state = vcedit_new_state(); pthread_mutex_lock(&vf_mutex); if (init_files(state) < 0) { fail(_("Failed to modify tag")); goto close; } comment = vcedit_comments(state); vorbis_comment_clear(comment); if (close_files(state) < 0) fail(_("Failed to modify tag")); close: vcedit_clear(state); pthread_mutex_unlock(&vf_mutex); gtk_widget_destroy(window); }
/* RECUPERATION DES PROPRIETE DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->debug = 0; /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "debug")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } //INITAILISATION DES FICHIER DE SORTIES init_files(); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* RECUPERATION DES PROPRIETES DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->alpha = 1; entitydata->c = 0; entitydata->eps = 0.01; entitydata->debug = 0; //entitydata->debut = time_seconds_to_nanos(3); //entitydata->periodEVE = time_seconds_to_nanos(1); /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "alpha")) { if (get_param_integer(param->value, &(entitydata->alpha))) { goto error; } } if (!strcmp(param->key, "c")) { if (get_param_integer(param->value, &(entitydata->c))) { goto error; } } if (!strcmp(param->key, "eps")) { if (get_param_double(param->value, &(entitydata->eps))) { goto error; } } if (!strcmp(param->key, "debut")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } init_files(); set_entity_private_data(c, entitydata); printf("dlbip : alpha : %d ; c : %d\n", entitydata->alpha, entitydata->c); return 0; error: free(entitydata); return -1; }
t_loadmod *loadmod_init(const char *module_path, double program_version) { t_loadmod *t; version = program_version; t = malloc(sizeof(*t)); list_init(&(t->file_list)); list_init(&(t->module_list)); init_files(&(t->file_list), module_path); init_modules(t); return (t); }
int main(int argc, char **argv) { int i; MEMORY_init(); COMMON_init(); TRY { get_arguments(argc, argv); COMPILE_init(); // Remove information files if we are compiling everything if (main_compile_all) { if (main_verbose) puts("Removing .info and .list files"); FILE_chdir(FILE_get_dir(COMP_project)); FILE_unlink(".info"); FILE_unlink(".list"); } init_files(FILE_get_dir(COMP_project)); for (i = 0; i < ARRAY_count(_files); i++) compile_file(_files[i]); exit_files(); COMPILE_exit(); puts("OK"); } CATCH { fflush(NULL); COMPILE_print(MSG_ERROR, -1, NULL); ERROR_print(); exit(1); } END_TRY return 0; }
int main (int argc, char *argv[]) { int i; set_debug_handlers (); progname = argv[0]; if (argc == 1) { usage(); return 2; } while ((i = getopt (argc, argv, "hu:")) != -1) { switch (i) { case 'h': usage (); return 2; case 'u': username = optarg; break; } } if (argc != optind + 2) { usage(); return 2; } if (change_user (username) < 0) { fprintf (stderr, "fatal: cannot change user to %s\n", username ? username : "******"); exit (1); } init_files (3); open_file (0, argv[optind], 0); open_file (1, argv[optind + 1], 0); fd[2] = 1; run(); flush_w_buff(); fsync (fd[2]); // assert (fsync (fd[2]) >= 0); // fails when stdout is a pipe return 0; }
int main(int argc, char *argv[]) { int retval; retval = DC_initClient(); if (retval) { fprintf(stderr, "APP: Failed to initialize the DC-API. Return " "value was %d\n", retval); DC_finishClient(1); } fprintf(stderr, "APP: DC-API initialization was successful.\n"); init_files(); do_work(); fprintf(stderr, "APP: Work finished.\n"); DC_finishClient(0); return(0); // Tho' we never reach this line }
int main(int argc,char *argv[]) { init_files(); int srvfd; if (server_init() < 0) { return -1; } srvfd = create_server_proc(IPADDR, PORT); if (srvfd < 0) { fprintf(stderr, "socket create or bind fail.\n"); server_uninit(); return -1; } handle_client_proc(srvfd); return 0; }
void output(const char *fname, const char *msg, va_list l) { char clos = 0; FILE *f; if(fname){ f = fopen(fname, "a"); if(!f){ /* attempt to create dir again */ if(init_files() == 0) f = fopen(fname, "a"); /*else p the error */ } clos = 1; }else f = stderr; if(f){ vfprintf(f, msg, l); if(clos) fclose(f); }else perrorf("fopen(): %s", fname); }
/*---------------------------------------------------------------------------* * program entry *---------------------------------------------------------------------------*/ int main(int argc, char **argv) { int i; int kchar; struct pollfd set[1]; char *ncp; const char *aliasfile = ALIASFILE; int rrtimeout = REREADTIMEOUT; extern char *optarg; setlocale( LC_ALL, ""); while ((i = getopt(argc, argv, "a:d:p:t:")) != -1) { switch (i) { case 'a': aliasfile = optarg; break; case 'd': spooldir = optarg; break; case 'p': playstring = optarg; break; case 't': rrtimeout = strtoul(optarg, &ncp, 10); if (*ncp) usage(); break; case '?': default: usage(); break; } } if (rrtimeout < 10) rrtimeout = 10; if ((chdir(spooldir)) != 0) fatal("cannot change directory to spooldir %s!", spooldir); init_alias(aliasfile); init_screen(); init_files(0); /* go into loop */ set[0].fd = STDIN_FILENO; set[0].events = POLLIN; for (;;) { /* if no char is available within timeout, reread spool */ if ((poll(set, 1, rrtimeout * 1000)) <= 0) { reread(); continue; } kchar = wgetch(main_w); /* get char */ switch (kchar) { case CR: case LF: #ifdef KEY_ENTER case KEY_ENTER: #endif do_menu(); break; case KEY_UP: /* up-move cursor */ if (cur_file && cur_file->prev) { cur_file = cur_file->prev; cur_pos--; } break; case TAB: case KEY_DOWN: /* down-move cursor */ if (cur_file && cur_file->next) { cur_file = cur_file->next; cur_pos++; } break; case KEY_HOME: /* move cursor to first dir */ break; case KEY_LL: /* move cursor to last file */ break; case CNTRL_D: do_quit(0); break; case CNTRL_L: /* refresh */ touchwin(curscr); wrefresh(curscr); break; } makecurrent(cur_pos, cur_file, 0); } do_quit(0); return(0); }
int lame_main(lame_t gf, int argc, char **argv) { char inPath[PATH_MAX + 1]; char outPath[PATH_MAX + 1]; char nogapdir[PATH_MAX + 1]; /* support for "nogap" encoding of up to 200 .wav files */ #define MAX_NOGAP 200 int nogapout = 0; int max_nogap = MAX_NOGAP; char nogap_inPath_[MAX_NOGAP][PATH_MAX + 1]; char *nogap_inPath[MAX_NOGAP]; int ret; int i; FILE *outf; lame_set_msgf(gf, &frontend_msgf); lame_set_errorf(gf, &frontend_errorf); lame_set_debugf(gf, &frontend_debugf); if (argc <= 1) { usage(stderr, argv[0]); /* no command-line args, print usage, exit */ return 1; } memset(inPath, 0, sizeof(inPath)); memset(nogap_inPath_, 0, sizeof(nogap_inPath_)); for (i = 0; i < MAX_NOGAP; ++i) { nogap_inPath[i] = &nogap_inPath_[i][0]; } /* parse the command line arguments, setting various flags in the * struct 'gf'. If you want to parse your own arguments, * or call libmp3lame from a program which uses a GUI to set arguments, * skip this call and set the values of interest in the gf struct. * (see the file API and lame.h for documentation about these parameters) */ ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap); if (ret < 0) { return ret == -2 ? 0 : 1; } if (global_ui_config.update_interval < 0.) global_ui_config.update_interval = 2.; if (outPath[0] != '\0' && max_nogap > 0) { strncpy(nogapdir, outPath, PATH_MAX + 1); nogapout = 1; } /* initialize input file. This also sets samplerate and as much other data on the input file as available in the headers */ if (max_nogap > 0) { /* for nogap encoding of multiple input files, it is not possible to * specify the output file name, only an optional output directory. */ parse_nogap_filenames(nogapout, nogap_inPath[0], outPath, nogapdir); outf = init_files(gf, nogap_inPath[0], outPath); } else { outf = init_files(gf, inPath, outPath); } if (outf == NULL) { return -1; } /* turn off automatic writing of ID3 tag data into mp3 stream * we have to call it before 'lame_init_params', because that * function would spit out ID3v2 tag data. */ lame_set_write_id3tag_automatic(gf, 0); /* Now that all the options are set, lame needs to analyze them and * set some more internal options and check for problems */ ret = lame_init_params(gf); if (ret < 0) { if (ret == -1) { display_bitrates(stderr); } error_printf("fatal error during initialization\n"); return ret; } if (global_ui_config.silent > 0) { global_ui_config.brhist = 0; /* turn off VBR histogram */ } if (lame_get_decode_only(gf)) { /* decode an mp3 file to a .wav */ ret = lame_decoder(gf, outf, inPath, outPath); } else if (max_nogap == 0) { /* encode a single input file */ ret = lame_encoder(gf, outf, 0, inPath, outPath); } else { /* encode multiple input files using nogap option */ for (i = 0; i < max_nogap; ++i) { int use_flush_nogap = (i != (max_nogap - 1)); if (i > 0) { parse_nogap_filenames(nogapout, nogap_inPath[i], outPath, nogapdir); /* note: if init_files changes anything, like samplerate, num_channels, etc, we are screwed */ outf = init_files(gf, nogap_inPath[i], outPath); /* reinitialize bitstream for next encoding. this is normally done * by lame_init_params(), but we cannot call that routine twice */ lame_init_bitstream(gf); } lame_set_nogap_total(gf, max_nogap); lame_set_nogap_currentindex(gf, i); ret = lame_encoder(gf, outf, use_flush_nogap, nogap_inPath[i], outPath); } } return ret; }
int main(int argc, char **argv) { char *name = NULL; int i = 1, ret = 0, daemon = 0; if(argc > 1 && !strcmp(argv[1], "-d")){ i++; daemon = 1; } for(; i < argc; i++) if(!name) name = argv[i]; else if(!host) host = argv[i]; else if(!port) port = argv[i]; else{ fprintf(stderr, "Unknown option: ``%s''\n", argv[i]); goto usage; } if(!host || !name) goto usage; if(!port) port = DEFAULT_PORT; if(setjmp(allocerr)){ perror("malloc()"); return 1; } if((ret = init_files())) return ret; if(daemon && daemonise()){ term_files(); return 1; } comm_init(&commt); if(comm_connect(&commt, host, port, name)){ outputf(file_err, "%s: couldn't connect: %s\n", *argv, comm_lasterr(&commt)); term_files(); return 1; } ret = lewp(); comm_close(&commt); term_files(); return ret; usage: printf("Usage: %s [-d] name host [port]\n" " -d: daemonise\n" , *argv); return 1; }
int main(int argc, char **argv) { int ret; lame_global_flags *gf; char outPath[PATH_MAX + 1]; char nogapdir[PATH_MAX + 1]; char inPath[PATH_MAX + 1]; /* support for "nogap" encoding of up to 200 .wav files */ #define MAX_NOGAP 200 int nogapout = 0; int max_nogap = MAX_NOGAP; char *nogap_inPath[MAX_NOGAP]; int i; FILE *outf; #if macintosh argc = ccommand(&argv); #endif #if defined(_WIN32) /* set affinity back to all CPUs. Fix for EAC/lame on SMP systems from "Todd Richmond" <*****@*****.**> */ typedef BOOL (WINAPI *SPAMFunc)(HANDLE, DWORD); SPAMFunc func; SYSTEM_INFO si; if ((func = (SPAMFunc)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "SetProcessAffinityMask")) != NULL) { GetSystemInfo(&si); func(GetCurrentProcess(), si.dwActiveProcessorMask); } #endif #ifdef __EMX__ /* This gives wildcard expansion on Non-POSIX shells with OS/2 */ _wildcard(&argc, &argv); #endif for (i = 0; i < max_nogap; ++i) { nogap_inPath[i] = malloc(PATH_MAX + 1); } memset(inPath, 0, sizeof(inPath)); /* initialize libmp3lame */ input_format = sf_unknown; if (NULL == (gf = lame_init())) { fprintf(stderr, "fatal error during initialization\n"); return 1; } if (argc <= 1) { usage(stderr, argv[0]); /* no command-line args, print usage, exit */ return 1; } /* parse the command line arguments, setting various flags in the * struct 'gf'. If you want to parse your own arguments, * or call libmp3lame from a program which uses a GUI to set arguments, * skip this call and set the values of interest in the gf struct. * (see the file API and lame.h for documentation about these parameters) */ parse_args_from_string(gf, getenv("LAMEOPT"), inPath, outPath); ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap); if (ret < 0) return ret == -2 ? 0 : 1; if (update_interval < 0.) update_interval = 2.; if (outPath[0] != '\0' && max_nogap>0) { strncpy(nogapdir, outPath, PATH_MAX + 1); nogapout = 1; } /* initialize input file. This also sets samplerate and as much other data on the input file as available in the headers */ if (max_nogap > 0) { /* for nogap encoding of multiple input files, it is not possible to * specify the output file name, only an optional output directory. */ parse_nogap_filenames(nogapout,nogap_inPath[0],outPath,nogapdir); outf = init_files(gf, nogap_inPath[0], outPath); } else { outf = init_files(gf, inPath, outPath); } if (outf == NULL) { return -1; } /* Now that all the options are set, lame needs to analyze them and * set some more internal options and check for problems */ i = lame_init_params(gf); if (i < 0) { if (i == -1) { display_bitrates(stderr); } fprintf(stderr, "fatal error during initialization\n"); return i; } if (silent > 0 #ifndef RH_HIST || lame_get_VBR(gf) == vbr_off #endif ) { brhist = 0; /* turn off VBR histogram */ } if (lame_get_decode_only(gf)) { /* decode an mp3 file to a .wav */ if (mp3_delay_set) lame_decoder(gf, outf, mp3_delay, inPath, outPath); else lame_decoder(gf, outf, 0, inPath, outPath); } else { if (max_nogap > 0) { /* * encode multiple input files using nogap option */ for (i = 0; i < max_nogap; ++i) { int use_flush_nogap = (i != (max_nogap - 1)); if (i > 0) { parse_nogap_filenames(nogapout,nogap_inPath[i],outPath,nogapdir); /* note: if init_files changes anything, like samplerate, num_channels, etc, we are screwed */ outf = init_files(gf, nogap_inPath[i], outPath); } brhist_init_package(gf); lame_set_nogap_total(gf, max_nogap); lame_set_nogap_currentindex(gf, i); ret = lame_encoder(gf, outf, use_flush_nogap, nogap_inPath[i], outPath); if (silent<=0) print_lame_tag_leading_info(gf); lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */ if (silent<=0) print_trailing_info(gf); fclose(outf); /* close the output file */ close_infile(); /* close the input file */ /* reinitialize bitstream for next encoding. this is normally done * by lame_init_params(), but we cannot call that routine twice */ if (use_flush_nogap) lame_init_bitstream(gf); } lame_close(gf); } else { /* * encode a single input file */ brhist_init_package(gf); ret = lame_encoder(gf, outf, 0, inPath, outPath); if (silent<=0) print_lame_tag_leading_info(gf); lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */ if (silent<=0) print_trailing_info(gf); fclose(outf); /* close the output file */ close_infile(); /* close the input file */ lame_close(gf); } } return ret; }
static void save_cb(GtkWidget * w, gpointer data) { gchar *track_name, *performer, *album_name, *date, *track_number; gchar *genre, *user_comment; #ifdef ALL_VORBIS_TAGS gchar *description, *version, *isrc, *copyright, *organization; gchar *location; #endif gchar *rg_track_gain, *rg_album_gain, *rg_track_peak, *rg_album_peak; char **comment_list; vcedit_state *state; vorbis_comment *comment; if (!g_strncasecmp(vte.filename, "http://", 7)) return; state = vcedit_new_state(); pthread_mutex_lock(&vf_mutex); if(init_files(state) < 0) { fail(_("Failed to modify tag")); goto close; } comment = vcedit_comments(state); comment_list = get_comment_list(comment); vorbis_comment_clear(comment); track_name = gtk_entry_get_text(GTK_ENTRY(title_entry)); performer = gtk_entry_get_text(GTK_ENTRY(performer_entry)); album_name = gtk_entry_get_text(GTK_ENTRY(album_entry)); track_number = gtk_entry_get_text(GTK_ENTRY(tracknumber_entry)); genre = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(genre_combo)->entry)); date = gtk_entry_get_text(GTK_ENTRY(date_entry)); user_comment = gtk_entry_get_text(GTK_ENTRY(user_comment_entry)); #ifdef ALL_VORBIS_TAGS location = gtk_entry_get_text(GTK_ENTRY(location_entry)); description = gtk_entry_get_text(GTK_ENTRY(description_entry)); version = gtk_entry_get_text(GTK_ENTRY(version_entry)); isrc = gtk_entry_get_text(GTK_ENTRY(isrc_entry)); organization = gtk_entry_get_text(GTK_ENTRY(organization_entry)); copyright = gtk_entry_get_text(GTK_ENTRY(copyright_entry)); #endif rg_track_gain = gtk_entry_get_text(GTK_ENTRY(rg_track_entry)); rg_album_gain = gtk_entry_get_text(GTK_ENTRY(rg_album_entry)); rg_track_peak = gtk_entry_get_text(GTK_ENTRY(rg_track_peak_entry)); rg_album_peak = gtk_entry_get_text(GTK_ENTRY(rg_album_peak_entry)); comment_list = add_tag(comment_list, "title", track_name); comment_list = add_tag(comment_list, "artist", performer); comment_list = add_tag(comment_list, "album", album_name); comment_list = add_tag(comment_list, "tracknumber", track_number); comment_list = add_tag(comment_list, "genre", genre); comment_list = add_tag(comment_list, "date", date); comment_list = add_tag(comment_list, "comment", user_comment); #ifdef ALL_VORBIS_TAGS comment_list = add_tag(comment_list, "location", location); comment_list = add_tag(comment_list, "description", description); comment_list = add_tag(comment_list, "version", version); comment_list = add_tag(comment_list, "isrc", isrc); comment_list = add_tag(comment_list, "organization", organization); comment_list = add_tag(comment_list, "copyright", copyright); #endif comment_list = add_tag(comment_list, "replaygain_track_gain", rg_track_gain); comment_list = add_tag(comment_list, "replaygain_album_gain", rg_album_gain); comment_list = add_tag(comment_list, "replaygain_track_peak", rg_track_peak); comment_list = add_tag(comment_list, "replaygain_album_peak", rg_album_peak); add_list(comment, comment_list); g_strfreev(comment_list); if (close_files(state) < 0) fail(_("Failed to modify tag")); close: vcedit_clear(state); pthread_mutex_unlock(&vf_mutex); gtk_widget_destroy(window); }
/** * main - */ int main(int argc, char **argv) { int c; int state; int index; int indicator; int rc = 0; int trunc = 0; int truncated = 0; int platform = 0; char temp[LOCATION_LENGTH]; char dloc[LOCATION_LENGTH]; char *dvalue = NULL; char *lvalue = NULL; char *svalue = NULL; char *othervalue = NULL; struct loc_code *current; struct loc_code *list = NULL; platform = get_platform(); if (platform != PLATFORM_PSERIES_LPAR) { fprintf(stderr, "%s is not supported on the %s platform\n", argv[0], __power_platform_name(platform)); return 1; } opterr = 0; while ((c = getopt(argc, argv, CMD_LINE_OPTIONS)) != -1) { switch (c) { case 'd': /* Device name */ dvalue = optarg; break; case 'l': /* Location code */ lvalue = optarg; break; case 's': /* Enable/disable */ svalue = optarg; break; case '-': /* All location code */ othervalue = optarg; break; case 't': /* truncate location code */ trunc = 1; break; case 'V': fprintf(stdout, "%s %s\n", argv[0], VERSION); fflush(stdout); return 0; case 'h': print_usage(argv[0]); return 0; case '?': if (isprint(optopt)) fprintf(stderr, "Unrecognized option: -%c\n\n", optopt); else fprintf(stderr, "Unrecognized option character %x\n\n", optopt); print_usage(argv[0]); return 1; default: print_usage(argv[0]); return 1; } } /* Option checking */ for (index = optind; index < argc; index++) { fprintf(stderr, "Unrecognized argument : %s\n\n", argv[index]); print_usage(argv[0]); return 1; } if (dvalue && !strstr(argv[0], CMD_IDENTIFY)) { fprintf(stderr, "Unrecognized option: -d\n\n"); print_usage(argv[0]); return 1; } if (dvalue && lvalue) { fprintf(stderr, "The -d and -l options cannot be used together.\n\n"); print_usage(argv[0]); return 1; } if (svalue && strstr(argv[0], CMD_IDENTIFY)) { if (!strcmp(svalue, "identify")) c = INDICATOR_ON; else if (!strcmp(svalue, "normal")) c = INDICATOR_OFF; else { fprintf(stderr, "The -s option must be either " "\"identify\" or \"normal\".\n\n"); print_usage(argv[0]); return 1; } } if (svalue && (strstr(argv[0], CMD_FAULT) || strstr(argv[0], CMD_ATTN))) { if (!strcmp(svalue, "normal")) c = INDICATOR_OFF; else { fprintf(stderr, "The -s option must be \"normal\".\n\n"); print_usage(argv[0]); return 1; } } if (svalue && !(dvalue || lvalue)) { if (strstr(argv[0], CMD_IDENTIFY)) fprintf(stderr, "The -s option requires the -d or -l " "option to also be used.\n\n"); else fprintf(stderr, "The -s option requires the -l " "option to also be used.\n\n"); print_usage(argv[0]); return 1; } if (svalue && geteuid() != 0) { fprintf(stderr, "%s: Turning indicator on/off requires " "superuser privileges.\n\n", argv[0]); return 1; } if (trunc && !(dvalue || lvalue)) { if (strstr(argv[0], CMD_IDENTIFY)) fprintf(stderr, "The -t option requires the -d or -l " "option to also be used.\n\n"); else fprintf(stderr, "The -t option requires the -l " "option to also be used.\n\n"); print_usage(argv[0]); return 1; } if (othervalue && strstr(argv[0], CMD_IDENTIFY)) { if (!strcmp(othervalue, "all-on")) c = INDICATOR_ON; else if (!strcmp(othervalue, "all-off")) c = INDICATOR_OFF; else { fprintf(stderr, "Unrecognized option: --%s\n\n", othervalue); print_usage(argv[0]); return 1; } } if (othervalue && (strstr(argv[0], CMD_ATTN) || strstr(argv[0], CMD_FAULT))) { if (!strcmp(othervalue, "all-off")) c = INDICATOR_OFF; else { fprintf(stderr, "Unrecognized option: --%s\n\n", othervalue); print_usage(argv[0]); return 1; } } if (othervalue && argc > 2) { fprintf(stderr, "\"--%s\" cannot be used with any other options.\n\n", othervalue); print_usage(argv[0]); return 1; } if (strstr(argv[0], CMD_IDENTIFY)) indicator = IDENT_INDICATOR; else if (strstr(argv[0], CMD_FAULT) || strstr(argv[0], CMD_ATTN)) indicator = ATTN_INDICATOR; else return 1; /* initialize */ program_name = argv[0]; lp_error_log_fd = 1; /* log message to stdout */ rc = init_files(); if (rc) { fprintf(stderr, "Unable to open log file.\n"); return 1; } /* Light Path operating mode */ if (indicator == ATTN_INDICATOR) { rc = check_operating_mode(); if (rc) return rc; } /* get indicator list */ rc = get_indicator_list(indicator, &list); if (rc) goto file_cleanup; if (argc == 1) { current = list; while (current) { /* get and print all indicators current state */ rc = get_indicator_state(indicator, current, &state); if (rc) /* failed to get indicator state */ current->state = -1; else current->state = state; print_indicator_state(current); current = current->next; } } /* Turn on/off indicator based on device name */ if (dvalue) { if (get_loc_code_for_dev(dvalue, dloc, LOCATION_LENGTH) != 0) { fprintf(stderr, "\"%s\" is not a valid device or " "it does not have location code.\n", dvalue); rc = 2; } else { lvalue = dloc; fprintf(stdout, "%s is at location code %s.\n", dvalue, lvalue); } } /* Turn on/off indicator based on location code */ if (lvalue) { strncpy(temp, lvalue, LOCATION_LENGTH); retry: current = get_indicator_for_loc_code(list, lvalue); if (!current) { if (trunc) { if (truncate_loc_code(lvalue)) { truncated = 1; goto retry; } } fprintf(stdout, "There is no %s indicator at location " "code %s.\n", INDICATOR_TYPE(indicator), temp); rc = 1; } else { /* Found location code */ if (truncated) fprintf(stdout, "Truncated location code : " "%s\n", lvalue); if (svalue) { rc = get_indicator_state(indicator, current, &state); if (rc || state != c) { rc = set_indicator_state(indicator, current, c); if (rc) goto indicator_cleanup; indicator_log_state(indicator, current->code, c); } } rc = get_indicator_state(indicator, current, &state); if (!rc) { if (dvalue) fprintf(stdout, "%s\t[%s]\n", lvalue, state ? "on" : "off"); else fprintf(stdout, "%s\n", state ? "on" : "off"); } } /* if-else end */ } /* lvalue end */ /* Turn on/off all indicators */ if (othervalue) { current = list; while (current) { rc = get_indicator_state(indicator, current, &state); if (rc) /* failed to get indicator state */ current->state = -1; else current->state = state; if (state != c) { set_indicator_state(indicator, current, c); rc = get_indicator_state(indicator, current, &state); if (rc) /* failed to get indicator state */ current->state = -1; else current->state = state; } print_indicator_state(current); current = current->next; } /* If enclosure ident indicator is turned ON explicitly, * then turning OFF all components ident indicator inside * enclosure does not turn OFF enclosure ident indicator. */ if (indicator == IDENT_INDICATOR && c == INDICATOR_OFF) set_indicator_state(indicator, &list[0], c); indicator_log_write("All %s Indicators : %s", indicator == IDENT_INDICATOR ? "Identify" : "Fault", c == INDICATOR_ON ? "ON" : "OFF"); } indicator_cleanup: free_indicator_list(list); file_cleanup: close_files(); return rc; }
int main(int argc, char* argv[]) { init_trace_flag("RFS_CONTROLLER_TRACE"); trace_startup("RFS_C", "RFS_CONTROLLER_LOG", argv[0]); int port = default_controller_port; if (argc > 1) { port = atoi(argv[1]); } // auto mode for test purposes if (argc > 2 && strcmp(argv[2], "emulate") == 0) { emulate = true; } int sd = socket(AF_INET, SOCK_STREAM, 0); if (sd == -1) { perror("Socket"); exit(1); } struct sockaddr_in sin; memset(&sin, 0, sizeof (sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(port); if (bind(sd, (struct sockaddr *) & sin, sizeof (sin)) == -1) { if (errno != EADDRINUSE) { perror("Error opening port: "); exit(2); } trace("Searching for available port...\n", port); int bind_rc; do { sin.sin_port = htons(++port); trace("\t%d...\n", port); bind_rc = bind(sd, (struct sockaddr *) &sin, sizeof (sin)); } while (bind_rc == -1 && port < 99999); if (bind_rc == -1) { perror("port"); exit(4); } }; /* show that we are willing to listen */ if (listen(sd, 5) == -1) { perror("listen"); exit(1); } if (!init()) { report_error("Initialization error\n"); exit(8); } if (!init_files()) { report_error("Error when initializing files\n"); exit(8); } // print port later, when we're done with initializing files fprintf(stdout, "PORT %d\n", port); fflush(stdout); pthread_t ping_pong_thread; pthread_create(&ping_pong_thread, NULL /*&attr*/, (void *(*) (void *)) check_stdout_pipe, NULL); pthread_detach(ping_pong_thread); while (1) { /* wait for a client to talk to us */ connection_data* conn_data = (connection_data*) malloc(sizeof (connection_data)); int addrlen = sizeof (conn_data->pin); if ((conn_data->sd = accept(sd, (struct sockaddr *) & conn_data->pin, &addrlen)) == -1) { perror("accept"); exit(1); } pthread_t thread; pthread_create(&thread, NULL /*&attr*/, (void *(*) (void *)) serve_connection, conn_data); pthread_detach(thread); } // the code below is unreachable, so I commented it out // TODO: (?) more accurate shutdon? // close(sd); // trace_shutdown(); }
int main(int argc, char **argv) { struct stat buf; int ret; char scratch[BUFSIZ]; char log[BUFSIZ]; char olog[BUFSIZ]; char *scratch_p = scratch; char *mytag_p; FILE *fp; extern char *getenv(); char *parse(); int c; extern char *optarg; extern int optind; int i; char *Mytag_p = Mytag; /* Get my port monitor tag out of the environment */ if ((mytag_p = getenv("PMTAG")) == NULL) { /* no place to write */ exit(1); } strcpy(Mytag, mytag_p); /* open log file */ sprintf(log, "%s/%s/%s", ALTDIR, Mytag_p, LOGNAME); sprintf(olog, "%s/%s/%s", ALTDIR, Mytag_p, OLOGNAME); if (stat(log, &buf) == 0) { /* file exists, try and save it but if we can't don't worry */ unlink(olog); rename(log, olog); } if ((i = open(log, O_WRONLY|O_CREAT|O_APPEND, 0444)) < 0) logexit(1, nologfile); /* as stated above, the log file should be file descriptor 5 */ if ((ret = fcntl(i, F_DUPFD, 5)) != 5) logexit(1, nologfile); Logfp = fdopen(ret, "a+"); /* Get my port monitor tag out of the environment */ if ((mytag_p = getenv("PMTAG")) == NULL) { logexit(1, nopmtag); } strcpy(Mytag, mytag_p); (void) umask(022); Readdb = FALSE; if (geteuid() != (uid_t) 0) { logmessage("Must be root to start listener"); logexit(1, badstart); } while ((c = getopt(argc, argv, "m:")) != EOF) switch (c) { case 'm': Minor_prefix = optarg; break; default: logexit(1, usage); break; } if ((Netspec = argv[optind]) == NULL) { logexit(1, usage); } if ((Netconf = getnetconfigent(Netspec)) == NULL) { sprintf(scratch, "no netconfig entry for <%s>", Netspec); logmessage(scratch); logexit(1, badstart); } if (!Minor_prefix) Minor_prefix = argv[optind]; if ((int) strlen(Netspec) > PATHSIZE) { logmessage(badnspmsg); logexit(1, badstart); } /* * SAC will start the listener in the correct directory, so we * don't need to chdir there, as we did in older versions */ strcpy(Provbuf, "/dev/"); strcat(Provbuf, Netspec); (void) umask(0); init_files(); /* open Accept, Sac, Pm, Pass files */ pid_open(); /* create pid file */ #ifdef DEBUGMODE sprintf(scratch, "%s/%s/%s", ALTDIR, Mytag, DBGNAME); Debugfp = fopen(scratch, "w"); #endif #ifdef DEBUGMODE if ((!Logfp) || (!Debugfp)) #else if (!Logfp) #endif logexit(1, badstart); /* * In case we started with no environment, find out what timezone we're * in. This will get passed to children, so only need to do once. */ if (getenv("TZ") == NULL) { fp = fopen(TZFILE, "r"); if (fp) { while (fgets(tzenv, BUFSIZ, fp)) { if (tzenv[strlen(tzenv) - 1] == '\n') tzenv[strlen(tzenv) - 1] = '\0'; if (!strncmp(TZSTR, tzenv, strlen(TZSTR))) { putenv(parse(tzenv)); break; } } fclose(fp); } else { sprintf(scratch, "couldn't open %s, default to GMT", TZFILE); logmessage(scratch); } } logmessage("@(#)listen:listen.c 1.19.9.1"); #ifdef DEBUGMODE logmessage("Listener process with DEBUG capability"); #endif sprintf(scratch, "Listener port monitor tag: %s", Mytag_p); logmessage(scratch); DEBUG((9, "Minor prefix: %s Netspec %s", Minor_prefix, Netspec)); /* fill in Pmmesg fields that always stay the same */ Pmmsg.pm_maxclass = MAXCLASS; strcpy(Pmmsg.pm_tag, Mytag_p); Pmmsg.pm_size = 0; /* Find out what state to start in. If not in env, exit */ if ((scratch_p = getenv("ISTATE")) == NULL) logexit(1, "ERROR: ISTATE variable not set in environment"); if (!strcmp(scratch_p, "enabled")) { State = PM_ENABLED; logmessage("Starting state: ENABLED"); } else { State = PM_DISABLED; logmessage("Starting state: DISABLED"); } /* try to get my "basename" */ Progname = strrchr(argv[0], '/'); if (Progname && Progname[1]) ++Progname; else Progname = argv[0]; catch_signals(); /* * Allocate memory for private address and file descriptor table * Here we are assuming that no matter how many private addresses * exist in the system if the system limit is 20 then we will only * get 20 file descriptors */ Ndesc = ulimit(4,0L); /* get num of file des on system */ read_dbf(DB_INIT); net_open(); /* init, open, bind names */ for (i = 3; i < Ndesc; i++) { /* leave stdout, stderr open */ fcntl(i, F_SETFD, 1); /* set close on exec flag*/ } logmessage("Initialization Complete"); listen(); return (0); }
void commcallback(enum comm_callbacktype type, const char *fmt, ...) { va_list l; const char *pre = NULL, *fname = NULL; #define TYPE(e, f, p) case e: fname = f; pre = p; break switch(type){ TYPE(COMM_INFO, file_info, "info"); TYPE(COMM_SERVER_INFO, file_info, "server info"); TYPE(COMM_CLIENT_CONN, file_info, "client connected"); TYPE(COMM_CLIENT_DISCO, file_info, "client disconnected"); TYPE(COMM_RENAME, file_info, "client renamed"); TYPE(COMM_ERR, file_err, "error"); case COMM_PRIVMSG: pre = "privmsg"; case COMM_MSG: fname = file_output; break; case COMM_DRAW: case COMM_DRAW_CLEAR: return; case COMM_CLIENT_LIST: case COMM_SELF_RENAME: { FILE *f = fopen(file_clients, "w"); /* truncate */ struct list *l; if(!f && init_files() == 0) f = fopen(file_clients, "w"); if(!f){ perrorf("fopen(): %s", file_clients); }else{ fprintf(f, "me: %s\n", comm_getname(&commt)); for(l = comm_clientlist(&commt); l; l = l->next) fprintf(f, "client: %s\n", l->name); fclose(f); } return; } case COMM_STATE_CHANGE: switch(comm_state(&commt)){ case COMM_DISCONNECTED: outputf(file_info, "Connection closed: %s\n", comm_lasterr(&commt)); finito = 1; case COMM_CONNECTING: case COMM_VERSION_WAIT: case COMM_NAME_WAIT: case COMM_ACCEPTED: break; } return; } #undef TYPE if(pre) outputf(fname, "%s: ", pre); va_start(l, fmt); output(fname, fmt, l); va_end(l); outputf(fname, "\n"); }
int main(int argc, char *argv[]) { // Set directory structure directory_init(argc, argv); printf("Initializing...\n"); fflush(stdout); // Read input file main_read_input(); // Read and sort output directory for finding files within our time limits init_files(); // Initialize domain and flow arrays domain_init(); // Create output directory create_output(); get_sigfigs(); // Pull initial time step tt = 0; cgns_fill(); // Find min and max and set up bins minmax(&min_vf, &max_vf, volume_fraction); minmax(&min_wp, &max_wp, part_w); minmax(&min_ke, &max_ke, part_ke); bin_init(min_vf, max_vf, &dBin_vf, &binStart_vf, &binEnd_vf); bin_init(min_wp, max_wp, &dBin_wp, &binStart_wp, &binEnd_wp); bin_init(min_ke, max_ke, &dBin_ke, &binStart_ke, &binEnd_ke); #ifdef DEBUG printf(" Bin Start (vf) = %lf\n", binStart_vf); printf(" Min (vf) = %lf\n", min_vf); printf(" dBin (vf) = %lf\n", dBin_vf); printf(" Max (vf) = %lf\n", max_vf); printf(" Bin End (vf) = %lf\n", binEnd_vf); #endif printf(" Bin Start (ke) = %lf\n", binStart_ke); printf(" Min (ke) = %lf\n", min_ke); printf(" dBin (ke) = %lf\n", dBin_ke); printf(" Max (ke) = %lf\n", max_ke); printf(" Bin End (ke) = %lf\n", binEnd_ke); // normalization for means double norm = 1./(dom.Gcc.s3 * nFiles); // Loop over time and bin printf("Looping...\n"); fflush(stdout); int ind, ind_vf, ind_wp; for (tt = 0; tt < nFiles; tt++) { printf(" Timestep = %d of %d\n", tt+1, nFiles); fflush(stdout); // Fill data from cgns file cgns_fill(); // Loop over space for (int cc = 0; cc < dom.Gcc.s3; cc++) { /* Volume Fraction */ mean_vf += norm*volume_fraction[cc]; // calculate index ind = (volume_fraction[cc] - binStart_vf)/dBin_vf; // if ind < 0, make it zero // if ind > nBins + 1, make it nBins +1 ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_vf[ind]++; ind_vf = ind; /* Part Wp */ mean_wp += norm*part_w[cc]; ind = (part_w[cc] - binStart_wp)/dBin_wp; ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_wp[ind]++; ind_wp = ind; /* Bivariate */ bihistogram_vf_wp[ind_wp + (nBins + 2)*ind_vf]++; /* Kinetic Energy */ mean_ke += norm*part_ke[cc]; ind = (part_ke[cc] - binStart_ke)/dBin_ke; ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_ke[ind]++; } // keep track of min max mean std for ALL files? // have bin padding as an input parameter? } // write to file write_field(); // Free and exit printf("Done!\n"); free_vars(); return EXIT_SUCCESS; }