int main( int argc, char **argv ) { void *pTaskHandle = NULL; enable_log( 1 ); set_log( LOG_TYPE_CONSOLE, NULL, 0 ); if( init_session( ) < 0 ) return -1; pTaskHandle = create_task( task_test, 5, 100 ); if ( pTaskHandle ) { CMessage stMsg; memset( &stMsg, 0x00, sizeof(stMsg) ); post_task_msg( pTaskHandle, &stMsg ); log_print( "create task ok................." ); } else log_print( "create task failed?????????????????????" ); while ( 1 ) os_sleep( 1000 ); release_session( ); return 0; }
void key_xchg (void) { if (init_session()) // initialize session key { if (recv_pkt()) // receive public key { modexp(); // encrypt the session key send_pkt(); // send session key } } }
/*********************************************************************** * DllMain (URLMON.init) */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) { TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad); switch(fdwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); URLMON_hInstance = hinstDLL; init_session(TRUE); break; case DLL_PROCESS_DETACH: if (hCabinet) FreeLibrary(hCabinet); hCabinet = NULL; init_session(FALSE); URLMON_hInstance = 0; break; } return TRUE; }
PyObject *init_guava(void) { PyObject *guava_module = NULL; PyObject *request_module = NULL; PyObject *server_module = NULL; PyObject *handler_module = NULL; PyObject *controller_module = NULL; PyObject *router_module = NULL; PyObject *session_module = NULL; PyObject *cookie_module = NULL; PyEval_InitThreads(); guava_module = Py_InitModule("guava", NULL); request_module = init_request(); if (!register_module(guava_module, "request", request_module)) { return NULL; } server_module = init_server(); if (!register_module(guava_module, "server", server_module)) { return NULL; } handler_module = init_handler(); if (!register_module(guava_module, "handler", handler_module)) { return NULL; } router_module = init_router(); if (!register_module(guava_module, "router", router_module)) { return NULL; } controller_module = init_controller(); if (!register_module(guava_module, "controller", controller_module)) { return NULL; } session_module = init_session(); if (!register_module(guava_module, "session", session_module)) { return NULL; } cookie_module = init_cookie(); if (!register_module(guava_module, "cookie", cookie_module)) { return NULL; } PyModule_AddStringConstant(guava_module, "version", GUAVA_VERSION); return guava_module; }
void login_page() { set_http_response_header_content_type("text/html;charset=utf-8"); output_header(); if(0 != init_session()){ printf("init_session ERROR !\n"); return; } send_redirect_to_page(PAGE_LOGIN); }
static void process_detach(void) { HINTERNET internet_session; internet_session = get_internet_session(NULL); if(internet_session) InternetCloseHandle(internet_session); if (hCabinet) FreeLibrary(hCabinet); init_session(FALSE); free_session(); free_tls_list(); }
int session_reset_handler(void) { static Uint32 last_click = 0; /* provide some protection for inadvertent pressing (double click that can be disabled) */ if (safe_button_click(&last_click)) { init_session(); set_session_exp_to_current(); session_start_time = cur_time; reset_session_counters(); range_critical_hits = 0; range_success_hits = 0; range_total_shots = 0; } return 0; }
int main(int argc, char **argv) { TABLE intab, outtab; TIGERfile intig, outtig; char **argval, **argname; char text[1024]; float x, y; set_arglist("-in none -out null"); init_session(argv, argc, &argname, &argval); if (open_tiger_frame(&intig,argval[0],"I") < 0) { sprintf(text, "Unable to open input datacube '%s'", argval[0]); print_error(text); exit_session(ERR_OPEN); } }
//Fonction principale int main(int argc, char const *argv[]) { //Déclaration des variables int nb_players = 0; //Nombre de musiciens int mode, port; //Mode d'ouverture du journal (identifier du journal commun à tous --> variable globale) et numéro de port //Vérification des arguments if (argc < NB_ARG) { erreur_IO("usage : port nb_players\n"); } else //on affecte les valeurs des arguments à des variables au nom plus évocateur { nb_players = atoi(argv[2]); //Récupération du nombre de musiciens port = atoi(argv[1]); //Récupération du numéro de port pour la connexion principale } //Ouverture ou création du journal mode = O_WRONLY|O_APPEND|O_CREAT; journal = open("journal.log", mode, 0660); if (journal == -1) { erreur_IO("open journal"); } //Gestion des connexions if(nb_players<=0 || nb_players > MAX_PLAYERS) //On vérifie que le nombre de musiciens est correct { erreur_IO("\nwrong number of players\n"); } if (sem_init(&sem_libres, 0, nb_players) == -1) //On initialise le sémaphore qui compte les threads libres. { erreur_IO("sem_init libres"); } init_workers(nb_players); //On crée notre pool de workers qu'on met en attente de connexion ensuite init_session(); //On initialise la session, en créant un thread consommateur qui redirige ensuite les données vers tous les clients (lorsque ceux-ci sont connectés) listen_socket(port, nb_players);//On écoute le socket entrant pour récupérer les connexions et les affecter aux threads return 0; }
/*********************************************************************** * DllMain (URLMON.init) */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) { TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad); URLMON_DllMain( hinstDLL, fdwReason, fImpLoad ); switch(fdwReason) { case DLL_PROCESS_ATTACH: init_session(TRUE); break; case DLL_PROCESS_DETACH: process_detach(); break; case DLL_THREAD_DETACH: detach_thread(); break; } return TRUE; }
int begin(void) { const char *scheme = use_secure?"https":"http"; char *space; static const char blanks[] = " "; static const char stars[] = "**********************************"; i_session = ne_session_create(scheme, i_hostname, i_port); CALL(init_session(i_session)); ne_hook_pre_send(i_session, i_pre_send, "X-Prestan"); space = ne_concat(i_path, "davtest/", NULL); ne_delete(i_session, space); if (ne_mkcol(i_session, space)) { t_context("Could not create new collection `%s' for tests: %s\n" "Server must allow `MKCOL %s' for tests to proceed", space, ne_get_error(i_session), space); return FAILHARD; } free(i_path); i_path = space; warmup(); printf("\nStart Testing %s:\n\n",pget_option.URL) ; printf("\n%s%s\n", blanks, stars); printf("\n%s* Number of Requests\t\t%d\n", blanks, pget_option.requests); printf("\n%s* Number of Dead Properties\t%d\n", blanks, pget_option.numprops); printf("\n%s* Depth of Collection\t\t%d\n", blanks, pget_option.depth); printf("\n%s* Width of Collection\t\t%d\n", blanks, pget_option.width); printf("\n%s* Type of Methods\t\t%s\n", blanks, pget_option.methods); printf("\n%s%s\n", blanks, stars); printf("\n\n"); return OK; }
/*********************************************************************** * DllMain (URLMON.init) */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) { TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad); URLMON_DllMain( hinstDLL, fdwReason, fImpLoad ); switch(fdwReason) { case DLL_PROCESS_ATTACH: urlmon_instance = hinstDLL; init_session(); break; case DLL_PROCESS_DETACH: if (fImpLoad) break; process_detach(); DeleteCriticalSection(&tls_cs); break; case DLL_THREAD_DETACH: detach_thread(); break; } return TRUE; }
int main(int argc_orig, char **argv) #endif { int i; /* We want the current value of argc to persist across a LONGJMP from int_error(). * Without this the compiler may put it on the stack, which LONGJMP clobbers. * Here we try make it a volatile variable that optimization will not affect. * Why do we not have to do the same for argv? I don't know. * But the test cases that broke with generic argc seem fine with generic argv. */ static volatile int argc; argc = argc_orig; #ifdef LINUXVGA LINUX_setup(); /* setup VGA before dropping privilege DBT 4/5/99 */ drop_privilege(); #endif /* make sure that we really have revoked root access, this might happen if gnuplot is compiled without vga support but is installed suid by mistake */ #ifdef __linux__ if (setuid(getuid()) != 0) { fprintf(stderr,"gnuplot: refusing to run at elevated privilege\n"); exit(EXIT_FAILURE); } #endif /* HBB: Seems this isn't needed any more for DJGPP V2? */ /* HBB: disable all floating point exceptions, just keep running... */ #if defined(DJGPP) && (DJGPP!=2) _control87(MCW_EM, MCW_EM); #endif #if defined(OS2) { int rc; #ifdef OS2_IPC char semInputReadyName[40]; sprintf(semInputReadyName, "\\SEM32\\GP%i_Input_Ready", getpid()); rc = DosCreateEventSem(semInputReadyName, &semInputReady, 0, 0); if (rc != 0) fputs("DosCreateEventSem error\n", stderr); #endif rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL); } #endif /* malloc large blocks, otherwise problems with fragmented mem */ #ifdef MALLOCDEBUG malloc_debug(7); #endif /* init progpath and get helpfile from executable directory */ #if defined(MSDOS) || defined(OS2) { char *s; #ifdef __EMX__ _execname(progpath, sizeof(progpath)); #else safe_strncpy(progpath, argv[0], sizeof(progpath)); #endif /* convert '/' to '\\' */ for (s = progpath; *s != NUL; s++) if (*s == DIRSEP2) *s = DIRSEP1; /* cut program name */ s = strrchr(progpath, DIRSEP1); if (s != NULL) s++; else s = progpath; *s = NUL; /* init HelpFile */ strcpy(HelpFile, progpath); strcat(HelpFile, "gnuplot.gih"); /* remove trailing "bin/" from progpath */ if ((s != NULL) && (s - progpath >= 4)) { s -= 4; if (strncasecmp(s, "bin", 3) == 0) *s = NUL; } } #endif /* DJGPP */ #if (defined(PIPE_IPC) || defined(_WIN32)) && (defined(HAVE_LIBREADLINE) || (defined(HAVE_LIBEDITLINE) && defined(X11))) /* Editline needs this to be set before the very first call to readline(). */ /* Support for rl_getc_function is broken for utf-8 in editline. Since it is only really required for X11, disable this section when building without X11. */ rl_getc_function = getc_wrapper; #endif #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) /* T.Walter 1999-06-24: 'rl_readline_name' must be this fix name. * It is used to parse a 'gnuplot' specific section in '~/.inputrc' * or gnuplot specific commands in '.editrc' (when using editline * instead of readline) */ rl_readline_name = "Gnuplot"; rl_terminal_name = getenv("TERM"); #if defined(HAVE_LIBREADLINE) using_history(); #else history_init(); #endif #endif #if defined(HAVE_LIBREADLINE) && !defined(MISSING_RL_TILDE_EXPANSION) rl_complete_with_tilde_expansion = 1; #endif for (i = 1; i < argc; i++) { if (!argv[i]) continue; if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--version")) { printf("gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); return 0; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { printf( "Usage: gnuplot [OPTION] ... [FILE]\n" #ifdef X11 "for X11 options see 'help X11->command-line-options'\n" #endif " -V, --version\n" " -h, --help\n" " -p --persist\n" " -s --slow\n" " -d --default-settings\n" " -c scriptfile ARG1 ARG2 ... \n" " -e \"command1; command2; ...\"\n" "gnuplot %s patchlevel %s\n", gnuplot_version, gnuplot_patchlevel); #ifdef DEVELOPMENT_VERSION printf( #ifdef DIST_CONTACT "Report bugs to "DIST_CONTACT"\n" " or %s\n", #else "Report bugs to %s\n", #endif bug_email); #endif return 0; } else if (!strncmp(argv[i], "-persist", 2) || !strcmp(argv[i], "--persist") #ifdef _WIN32 || !stricmp(argv[i], "-noend") || !stricmp(argv[i], "/noend") #endif ) { persist_cl = TRUE; } else if (!strncmp(argv[i], "-slow", 2) || !strcmp(argv[i], "--slow")) { slow_font_startup = TRUE; } else if (!strncmp(argv[i], "-d", 2) || !strcmp(argv[i], "--default-settings")) { /* Skip local customization read from ~/.gnuplot */ skip_gnuplotrc = TRUE; } } #ifdef X11 /* the X11 terminal removes tokens that it recognizes from argv. */ { int n = X11_args(argc, argv); argv += n; argc -= n; } #endif setbuf(stderr, (char *) NULL); #ifdef HAVE_SETVBUF /* This was once setlinebuf(). Docs say this is * identical to setvbuf(,NULL,_IOLBF,0), but MS C * faults this (size out of range), so we try with * size of 1024 instead. [SAS/C does that, too. -lh] */ if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0) (void) fputs("Could not linebuffer stdout\n", stderr); /* Switching to unbuffered mode causes all characters in the input * buffer to be lost. So the only safe time to do it is on program entry. * Do any non-X platforms suffer from this problem? * EAM - Jan 2013 YES. */ setvbuf(stdin, (char *) NULL, _IONBF, 0); #endif gpoutfile = stdout; /* Initialize pre-loaded user variables */ /* "pi" is hard-wired as the first variable */ (void) add_udv_by_name("GNUTERM"); (void) add_udv_by_name("NaN"); init_constants(); udv_user_head = &(udv_NaN->next_udv); init_memory(); interactive = FALSE; /* April 2017: We used to call init_terminal() here, but now */ /* We defer initialization until error handling has been set up. */ # if defined(_WIN32) && !defined(WGP_CONSOLE) interactive = TRUE; # else interactive = isatty(fileno(stdin)); # endif /* Note: we want to know whether this is an interactive session so that we can * decide whether or not to write status information to stderr. The old test * for this was to see if (argc > 1) but the addition of optional command line * switches broke this. What we really wanted to know was whether any of the * command line arguments are file names or an explicit in-line "-e command". */ for (i = 1; i < argc; i++) { # ifdef _WIN32 if (!stricmp(argv[i], "/noend")) continue; # endif if ((argv[i][0] != '-') || (argv[i][1] == 'e') || (argv[i][1] == 'c') ) { interactive = FALSE; break; } } /* Need this before show_version is called for the first time */ if (interactive) show_version(stderr); else show_version(NULL); /* Only load GPVAL_COMPILE_OPTIONS */ update_gpval_variables(3); /* update GPVAL_ variables available to user */ #ifdef VMS /* initialise screen management routines for command recall */ { unsigned int ierror; if (ierror = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL) done(ierror); if (ierror = smg$create_key_table(&vms_ktid) != SS$_NORMAL) done(ierror); } #endif /* VMS */ if (!SETJMP(command_line_env, 1)) { /* first time */ interrupt_setup(); get_user_env(); init_loadpath(); init_locale(); memset(&sm_palette, 0, sizeof(sm_palette)); init_fit(); /* Initialization of fitting module */ #ifdef READLINE /* When using the built-in readline, we set the initial encoding according to the locale as this is required to properly handle keyboard input. */ init_encoding(); #endif init_gadgets(); /* April 2017: Now that error handling is in place, it is safe parse * GNUTERM during terminal initialization. * atexit processing is done in reverse order. We want * the generic terminal shutdown in term_reset to be executed before * any terminal specific cleanup requested by individual terminals. */ init_terminal(); push_terminal(0); /* remember the initial terminal */ gp_atexit(term_reset); /* Execute commands in ~/.gnuplot */ init_session(); if (interactive && term != 0) { /* not unknown */ #ifdef GNUPLOT_HISTORY #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && !defined(_WIN32) expanded_history_filename = tilde_expand(GNUPLOT_HISTORY_FILE); #else expanded_history_filename = gp_strdup(GNUPLOT_HISTORY_FILE); gp_expand_tilde(&expanded_history_filename); #endif read_history(expanded_history_filename); /* * It is safe to ignore the return values of 'atexit()' and * 'on_exit()'. In the worst case, there is no history of your * currrent session and you have to type all again in your next * session. */ gp_atexit(wrapper_for_write_history); #endif /* GNUPLOT_HISTORY */ #if defined(READLINE) && defined(WGP_CONSOLE) fprintf(stderr, "Encoding set to '%s'.\n", encoding_names[encoding]); #endif } /* if (interactive && term != 0) */ } else { /* come back here from int_error() */ if (!successful_initialization) { /* Only print the warning once */ successful_initialization = TRUE; fprintf(stderr,"WARNING: Error during initialization\n\n"); } if (interactive == FALSE) exit_status = EXIT_FAILURE; #ifdef HAVE_READLINE_RESET else { /* reset properly readline after a SIGINT+longjmp */ rl_reset_after_signal (); } #endif load_file_error(); /* if we were in load_file(), cleanup */ SET_CURSOR_ARROW; #ifdef VMS /* after catching interrupt */ /* VAX stuffs up stdout on SIGINT while writing to stdout, so reopen stdout. */ if (gpoutfile == stdout) { if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) { /* couldn't reopen it so try opening it instead */ if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) { /* don't use int_error here - causes infinite loop! */ fputs("Error opening SYS$OUTPUT as stdout\n", stderr); } } gpoutfile = stdout; } #endif /* VMS */ /* Why a goto? Because we exited the loop below via int_error */ /* using LONGJMP. The compiler was not expecting this, and */ /* "optimized" the handling of argc and argv such that simply */ /* entering the loop again from the top finds them messed up. */ /* If we reenter the loop via a goto then there is some hope */ /* that code reordering does not hurt us. */ if (reading_from_dash && interactive) goto RECOVER_FROM_ERROR_IN_DASH; reading_from_dash = FALSE; if (!interactive && !noinputfiles) { term_reset(); gp_exit(EXIT_FAILURE); /* exit on non-interactive error */ } } /* load filenames given as arguments */ while (--argc > 0) { ++argv; c_token = 0; if (!strncmp(*argv, "-persist", 2) || !strcmp(*argv, "--persist") #ifdef _WIN32 || !stricmp(*argv, "-noend") || !stricmp(*argv, "/noend") #endif ) { FPRINTF((stderr,"'persist' command line option recognized\n")); } else if (strcmp(*argv, "-") == 0) { #if defined(_WIN32) && !defined(WGP_CONSOLE) TextShow(&textwin); interactive = TRUE; #else interactive = isatty(fileno(stdin)); #endif RECOVER_FROM_ERROR_IN_DASH: reading_from_dash = TRUE; while (!com_line()); reading_from_dash = FALSE; interactive = FALSE; noinputfiles = FALSE; } else if (strcmp(*argv, "-e") == 0) { int save_state = interactive; --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -e \"commands\"\n"); return 0; } interactive = FALSE; noinputfiles = FALSE; do_string(*argv); interactive = save_state; } else if (!strncmp(*argv, "-slow", 2) || !strcmp(*argv, "--slow")) { slow_font_startup = TRUE; } else if (!strncmp(*argv, "-d", 2) || !strcmp(*argv, "--default-settings")) { /* Ignore this; it already had its effect */ FPRINTF((stderr, "ignoring -d\n")); } else if (strcmp(*argv, "-c") == 0) { /* Pass command line arguments to the gnuplot script in the next * argument. This consumes the remainder of the command line */ interactive = FALSE; noinputfiles = FALSE; --argc; ++argv; if (argc <= 0) { fprintf(stderr, "syntax: gnuplot -c scriptname args\n"); gp_exit(EXIT_FAILURE); } call_argc = GPMIN(9, argc - 1); for (i=0; i<=call_argc; i++) { /* Need to stash argv[i] somewhere visible to load_file() */ call_args[i] = gp_strdup(argv[i+1]); } load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), 5); gp_exit(EXIT_SUCCESS); } else if (*argv[0] == '-') { fprintf(stderr, "unrecognized option %s\n", *argv); } else { interactive = FALSE; noinputfiles = FALSE; load_file(loadpath_fopen(*argv, "r"), gp_strdup(*argv), 4); } } /* take commands from stdin */ if (noinputfiles) { while (!com_line()) ctrlc_flag = FALSE; /* reset asynchronous Ctrl-C flag */ } #ifdef _WIN32 /* On Windows, handle 'persist' by keeping the main input loop running (windows/wxt), */ /* but only if there are any windows open. Note that qt handles this properly. */ if (persist_cl) { if (WinAnyWindowOpen()) { #ifdef WGP_CONSOLE if (!interactive) { /* no further input from pipe */ while (WinAnyWindowOpen()) win_sleep(100); } else #endif { interactive = TRUE; while (!com_line()) ctrlc_flag = FALSE; /* reset asynchronous Ctrl-C flag */ interactive = FALSE; } } } #endif #if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE)) && defined(GNUPLOT_HISTORY) #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT) /* You should be here if you neither have 'atexit()' nor 'on_exit()' */ wrapper_for_write_history(); #endif /* !HAVE_ATEXIT && !HAVE_ON_EXIT */ #endif /* (HAVE_LIBREADLINE || HAVE_LIBEDITLINE) && GNUPLOT_HISTORY */ #ifdef OS2 RexxDeregisterSubcom("GNUPLOT", NULL); #endif /* HBB 20040223: Not all compilers like exit() to end main() */ /* exit(exit_status); */ #if ! defined(_WIN32) /* Windows does the cleanup later */ gp_exit_cleanup(); #endif return exit_status; }
static void gwget_application_init (GwgetApplication *gwget_application) { init_session (gwget_application); }
int main( int argc, char **argv ) { CSession *pSession = NULL; CSessionParam stSessionParam; const int8_t *pPeerIP = "www.lelsen.sinaapp.com"; //const int8_t *pPeerIP = "www.baidu.com"; const int8_t *pURL = "/business/api/punch.php"; //const int8_t *pURL = "/index.html"; const int16u_t iPeerPort = 80; enable_log( 1 ); set_log( LOG_TYPE_CONSOLE, NULL, 0 ); pHandle = fopen( "./log.txt", "wb" ); if ( !pHandle ) return -1; if ( init_session( ) < 0 ) return -1; log_print( "init_session ok.................." ); memset( &stSessionParam, 0x00, sizeof(stSessionParam) ); memcpy( stSessionParam.pIP, pPeerIP, strlen(pPeerIP) + 1 ); stSessionParam.iPort = iPeerPort; log_print( "start to create session............" ); pSession = create_session( SESSION_TYPE_HTTP_CLIENT, &stSessionParam ); if ( pSession ) { log_print( "create tcp session ok................" ); if ( set_session_business( pSession, stream_session_business, NULL ) >= 0 ) { if ( set_session_event( pSession, stream_session_event ) >= 0 ) { CHttpData stHttpData; memset( &stHttpData, 0x00, sizeof(stHttpData) ); stHttpData.pHost = pPeerIP; stHttpData.pURL = pURL; stHttpData.eHttpAction = SESSION_HTTP_GET; while ( 1 ) { int i, iNSent = -1; //printf( "Please enter 1 to send http request:\r\n" ); i = 0; // scanf( "%d", &i ); //if ( i == 1 ) iNSent = send_session_data( pSession, &stHttpData, sizeof(stHttpData), NULL ); os_sleep( 1000 * 2); } } } } else log_print( "create udp session failed????????????????????????" ); while ( 1 ) os_sleep( 1000 ); destroy_session( pSession ); pSession = NULL; release_session( ); return 0; }
int main(int argc, char **argv) { int nocol_short, nocol_long, nocol_float, nocol_double; int status; char **argval, **arglabel; int i, nbrow = NBROW, nbcol=NBCOL, sel[NBROW]; short sval, s_colbuf[NBROW], s_key; long lval, l_colbuf[NBROW]; float fval, f_colbuf[NBROW]; double dval, d_colbuf[NBROW]; char ident[20]; char selection[30]; TABLE table; /* init_session() checking */ printf("IOLIB environment routines :\n\n"); fflush(stdout); init_session(argv,argc,&arglabel,&argval); /* set_control_level(WARNING); */ printf("Table creation ..."); fflush(stdout); strcpy(ident,"Dummy table"); create_table(&table,"chk_tbl_io",nbrow,nbcol,'W',ident); printf("Ok\n"); fflush(stdout); /* printf("Column creation ...(format Characters) "); fflush(stdout); nocol_char = create_col(&table,":TEXT",CHAR,'N',"A20",NULL); if (nocol_char < 0) { printf("Problem creating column TEXT, status returned = %d\n", nocol_char); exit (-1); } printf("Ok\n"); fflush(stdout); printf("Writing into created column ..."); fflush(stdout); for (i=0; i<nbrow; i++) { sprintf(text,"String no %2d",i); WR_tbl(&table,i,nocol_char,text); } printf("Ok\n"); fflush(stdout); */ printf("Column creation ...(format Short) "); fflush(stdout); nocol_short = create_col(&table,":SHORT",SHORT,'N',"I2",NULL); if (nocol_short < 0) { printf("Problem creating column SHORT, status returned = %d\n", nocol_short); exit (-1); } printf("Ok\n"); fflush(stdout); printf("Writing into created column ..."); fflush(stdout); for (i=0; i<nbrow; i++) { sval = (short)i; WR_tbl(&table,i,nocol_short,&sval); } printf("Ok\n"); fflush(stdout); printf("Column creation ...(format Long) "); fflush(stdout); nocol_long = create_col(&table,":LONG",LONG,'N',"I4",NULL); if (nocol_long < 0) { printf("Problem creating column LONG, status returned = %d\n", nocol_long); exit (-1); } printf("Ok\n"); fflush(stdout); printf("Writing into created column ..."); fflush(stdout); for (i=0; i<nbrow; i++) { lval = (long)i; WR_tbl(&table,i,nocol_long,&lval); } printf("Ok\n"); fflush(stdout); printf("Column creation ...(format Float) "); fflush(stdout); nocol_float = create_col(&table,":FLOAT",FLOAT,'N',"F9.6",NULL); if (nocol_float < 0) { printf("Problem creating column FLOAT, status returned = %d\n", nocol_float); exit (-1); } printf("Ok\n"); fflush(stdout); printf("Writing into created column ..."); fflush(stdout); for (i=0; i<nbrow; i++) { fval = (float)i; WR_tbl(&table,i,nocol_float,&fval); } printf("Ok\n"); fflush(stdout); printf("Column creation ...(format Double) "); fflush(stdout); nocol_double = create_col(&table,":DOUBLE",DOUBLE,'N',"E15.5",NULL); if (nocol_double < 0) { printf("Problem creating column DOUBLE, status returned = %d\n", nocol_double); exit (-1); } printf("Ok\n"); fflush(stdout); printf("Writing into created column ..."); fflush(stdout); for (i=0; i<nbrow; i++) { dval = (double)i; WR_tbl(&table,i,nocol_double,&dval); } printf("Ok\n\n"); fflush(stdout); for (i=0; i<nbrow; i++) { if (i%2 == 0) sel[i] = 0; else sel[i] = 1; } write_selection(&table,sel,"check_selection"); printf("Saving created table ..."); fflush(stdout); close_table(&table); printf("Ok\n"); fflush(stdout); printf("Opening previous table ..."); fflush(stdout); open_table(&table,"chk_tbl_io","I"); printf("Ok\n"); fflush(stdout); printf("Handling selection ..."); fflush(stdout); handle_select_flag(&table,'W',selection); printf("Ok\n"); fflush(stdout); printf("Reading columns info ..."); fflush(stdout); /* nocol_char = get_col_ref(&table,":TEXT"); */ nocol_short = get_col_ref(&table,":SHORT"); nocol_long = get_col_ref(&table,":LONG"); nocol_float = get_col_ref(&table,":FLOAT"); nocol_double = get_col_ref(&table,":DOUBLE"); printf("Ok\n"); nbrow = table.row; /* printf("Reading previous column ...(format Characters) "); fflush(stdout); RD_col(&table,nocol_char,c_colbuf); for (i=0; i<nbrow; i++) { sprintf(text,"String no %2d",i); if (strcmp(text,(c_colbuf+i*21)) != 0) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column item by item ...(format Characters) "); fflush(stdout); for (i=0; i<nbrow; i++) { RD_tbl(&table,i,nocol_char,Rtext); sprintf(text,"String no %2d",i); if (strcmp(text,Rtext) != 0) { printf("FATAL : Unexpected values in table, line %d\n",i); printf("*%s* is not *%s*\n", Rtext, text); return(-1); } } printf("Ok\n"); */ printf("Reading previous column ...(format Short) "); fflush(stdout); s_colbuf[0] = 0; RD_col(&table,nocol_short,s_colbuf); printf("Ok\n"); printf("Searching for no 501 ... "); fflush(stdout); s_key = 501; status = search_in_col(&table,nocol_short,&s_key); if (status >= 0) printf("Found in line %d\n",status); else { printf("Unable to find it\n"); return(-1); } printf("Searching for no 500 ... "); fflush(stdout); s_key = 500; status = search_in_col(&table,nocol_short,&s_key); if (status >= 0) printf("Found in line %d\n",status); else { printf("Unable to find it (not selected)\n"); } for (i=0; i<nbrow; i++) { if (s_colbuf[i] != (short)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); printf("Read %d, Expected %d\n",s_colbuf[i],2*i+1); return(-1); } } printf("Ok\n"); printf("Reading previous column item by item ...(format Short) "); fflush(stdout); for (i=0; i<nbrow; i++) { RD_tbl(&table,i,nocol_short,&sval); if (sval != (short)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column ..(format Long) "); fflush(stdout); RD_col(&table,nocol_long,l_colbuf); for (i=0; i<nbrow; i++) { if (l_colbuf[i] != (long)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column item by item ...(format Long) "); fflush(stdout); for (i=0; i<nbrow; i++) { RD_tbl(&table,i,nocol_long,&lval); if (lval != (long)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column ...(format Float) "); fflush(stdout); RD_col(&table,nocol_float,f_colbuf); for (i=0; i<nbrow; i++) { if (f_colbuf[i] != (float)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column item by item ...(format Float) "); fflush(stdout); for (i=0; i<nbrow; i++) { RD_tbl(&table,i,nocol_float,&fval); if (fval != (float)(2*i+1)) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column ..(format Double) "); fflush(stdout); RD_col(&table,nocol_double,d_colbuf); for (i=0; i<nbrow; i++) { if (ABS(d_colbuf[i] - (double)(2*i+1)) > 1e-8) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); printf("Reading previous column item by item ...(format Double) "); fflush(stdout); for (i=0; i<nbrow; i++) { RD_tbl(&table,i,nocol_double,&dval); if (ABS(dval - (double)(2*i+1)) > 1e-8) { printf("FATAL : Unexpected values in table, line %d\n",i); return(-1); } } printf("Ok\n"); fflush(stdout); printf("Deleting previous table ..."); fflush(stdout); delete_table(&table); printf("Ok\n"); fflush(stdout); exit_session(0); return(0); }
int main(int argc, char **argv) { TIGERfile image; SPECTRUM signal,noise; SLICE s_signal; char **argval, **arglabel, toto[50]; int nolens, i,j, npix=300, nb_spec=100, status, nol[105]; double start, step; short sval; long lval; float fval, x[105],y[105]; double dval; step = 1; start = 1; printf("IOLIB routines for Tiger format:\n\n"); init_session(argv,argc,&arglabel,&argval); /* set_control_level(WARNING); */ printf("\nOnly signal spectra:\n\n"); /* 1 - Type SHORT */ for (nolens=1;nolens<=nb_spec+5;nolens++) { nol[nolens-1] = nolens; x[nolens-1] = (float)nolens; y[nolens-1] = (float)nolens; } printf("Image creation (type of storage = Short) ..."); fflush(stdout); create_tiger_frame(&image,"s_chk_tiger_io",npix,start,step,SHORT, "associated_tbl","dummy frame",NULL); printf("Ok\n"); printf("Writing into created image ..."); fflush(stdout); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(short)(nolens*j)); } put_tiger_spec(&image,&signal,NULL,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); WR_desc(&image,"TOTO",CHAR,10,"tototototo"); fval = 25.6; WR_desc(&image,"FTOTO",FLOAT,1,&fval); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); image.history[0] = '\0'; open_tiger_frame(&image,"s_chk_tiger_io","I"); printf("Ok\n"); printf("%s\n",image.history); nolens = (int)(nb_spec/2); status = exist_lens(&image,nolens); if (status < 0) { printf("unable to locate signal for lens #%d\n",nolens); fflush(stdout); return(-1); } printf("Reading image values slice by slice ..."); fflush(stdout); for (i=0;i<npix;i++) { get_tiger_slice(&image,&s_signal,NULL,i); for (j=0;j<s_signal.npts;j++) { nolens = s_signal.specId[j]; sval = (short)RD_slice(&s_signal,j); if (sval != (short)(nolens*i)) { printf("FATAL : Unexpected values in image\n"); printf("expected value = %d, got %d\n",(short)(nolens*i),sval); printf("at slice %d, pixel %d\n",i,j); return(-1); } } } printf("Ok\n"); RD_desc(&image,"TOTO",CHAR,10,toto); printf("TOTO = %s\n",toto); printf("Closing image ..."); close_tiger_frame(&image); printf("Ok\n"); /* printf("Opening previous image in IO mode..."); fflush(stdout); open_tiger_frame(&image,"s_chk_tiger_io","IO"); printf("Ok\n"); printf("Writing image values spectrum by spectrum ..."); fflush(stdout); for (nolens=nb_spec+1;nolens<=nb_spec+5;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(short)(nolens*j)); } put_tiger_spec(&image,&signal,NULL,nolens); } printf("Ok\n"); close_tiger_frame(&image); printf("Opening previous image ..."); open_tiger_frame(&image,"s_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values spectrum by spectrum ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec+5;nolens++) { get_tiger_spec(&image,&signal,NULL,nol[nolens-1]); for (j=0;j<signal.npts;j++) { sval = (short)RD_spec(&signal,j); if (sval != (short)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); printf("expected value = %d, got %d\n",(short)(nolens*j),sval); printf("at nolens %d, pixel %d\n",nolens,j); return(-1); } } } printf("Ok\n"); close_tiger_frame(&image); */ printf("Deleting previous image ..."); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); printf("Image creation slice by slice (type of storage = Short) ..."); fflush(stdout); create_tiger_frame(&image,"s_chk_tiger_io",npix,start,step,SHORT, "associated_tbl","dummy frame",NULL); printf("Ok\n"); if (has_common_bounds(&image)) printf("Common bounds Ok\n"); printf("Setting lenses coordinates ..."); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Ok\n"); printf("Writing into created image ..."); fflush(stdout); for (i=0;i<npix;i++) { init_new_tiger_slice(&image,&s_signal,nb_spec); for (j=0;j<s_signal.npts;j++) { nolens = s_signal.specId[j]; WR_slice(&s_signal,j,(short)(nolens*i)); } put_tiger_slice(&image,&s_signal,NULL,i); } printf("Ok\n"); printf("Closing image ..."); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"s_chk_tiger_io","I"); printf("Ok\n"); get_lenses_no(&image,nol); printf("Reading image values spectrum by spectrum ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,NULL,nol[nolens-1]); for (j=0;j<signal.npts;j++) { sval = (short)RD_spec(&signal,j); if (sval != (short)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); printf("expected value = %d, got %d\n",(short)(nolens*j),sval); printf("at nolens %d, pixel %d\n",nolens,j); return(-1); } } } printf("Ok\n"); close_tiger_frame(&image); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 2 - Type LONG */ printf("Image creation (type of storage = Long) ..."); fflush(stdout); create_tiger_frame(&image,"l_chk_tiger_io",-1,start,step,LONG,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(long)(nolens*j)); } put_tiger_spec(&image,&signal,NULL,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"l_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values spectrum by spectrum ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,NULL,nolens); for (j=0;j<signal.npts;j++) { lval = (long)RD_spec(&signal,j); if (lval != (long)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Reading image values slice by slice ..."); fflush(stdout); for (i=0;i<npix;i++) { get_tiger_slice(&image,&s_signal,NULL,i); for (j=0;j<s_signal.npts;j++) { nolens = s_signal.specId[j]; lval = (long)RD_slice(&s_signal,j); if (lval != (long)(nolens*i)) { printf("FATAL : Unexpected values in image\n"); printf("expected value = %ld, got %ld\n",(long)(nolens*i),lval); printf("at slice %d, pixel %d\n",i,j); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 3 - Type FLOAT */ printf("Image creation (type of storage = Float) ..."); fflush(stdout); create_tiger_frame(&image,"f_chk_tiger_io",npix,start,step,FLOAT,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(float)(nolens*j)); } put_tiger_spec(&image,&signal,NULL,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"f_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,NULL,nolens); for (j=0;j<signal.npts;j++) { fval = (float)RD_spec(&signal,j); if (fval != (float)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 4 - Type DOUBLE */ printf("Image creation (type of storage = Double) ..."); fflush(stdout); create_tiger_frame(&image,"d_chk_tiger_io",npix,start,step,DOUBLE,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(double)(nolens*j)); } put_tiger_spec(&image,&signal,NULL,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"d_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,NULL,nolens); for (j=0;j<signal.npts;j++) { dval = (double)RD_spec(&signal,j); if (dval != (double)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); #ifdef nonEURO3D printf("Only noise spectra:\n\n"); /* 1 - Type SHORT */ printf("Image creation (type of storage = Short) ..."); fflush(stdout); create_tiger_frame(&image,"s_chk_tiger_io",npix,start,step,SHORT, "associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<noise.npts;j++) { WR_spec(&noise,j,(short)(nolens*j)); } put_tiger_spec(&image,NULL,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"s_chk_tiger_io","I"); printf("Ok\n"); nolens = (int)(nb_spec/2); status = exist_lens(&image,nolens); if (status < 0) { printf("unable to locate noise from lens no %d\n",nolens); fflush(stdout); return(-1); } printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,NULL,&noise,nolens); for (j=0;j<noise.npts;j++) { sval = (short)RD_spec(&noise,j); if (sval != (short)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 2 - Type LONG */ printf("Image creation (type of storage = Long) ..."); fflush(stdout); create_tiger_frame(&image,"l_chk_tiger_io",npix,start,step,LONG,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<noise.npts;j++) { WR_spec(&noise,j,(long)(nolens*j)); } put_tiger_spec(&image,NULL,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"l_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,NULL,&noise,nolens); for (j=0;j<noise.npts;j++) { lval = (long)RD_spec(&noise,j); if (lval != (long)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 3 - Type FLOAT */ printf("Image creation (type of storage = Float) ..."); fflush(stdout); create_tiger_frame(&image,"f_chk_tiger_io",npix,start,step,FLOAT,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<noise.npts;j++) { WR_spec(&noise,j,(float)(nolens*j)); } put_tiger_spec(&image,NULL,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"f_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,NULL,&noise,nolens); for (j=0;j<noise.npts;j++) { fval = (float)RD_spec(&noise,j); if (fval != (float)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 4 - Type DOUBLE */ printf("Image creation (type of storage = Double) ..."); fflush(stdout); create_tiger_frame(&image,"d_chk_tiger_io",npix,start,step,DOUBLE,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<noise.npts;j++) { WR_spec(&noise,j,(double)(nolens*j)); } put_tiger_spec(&image,NULL,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"d_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,NULL,&noise,nolens); for (j=0;j<noise.npts;j++) { dval = (double)RD_spec(&noise,j); if (dval != (double)(nolens*j)) { printf("FATAL : Unexpected values in image\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); #endif printf("Signal & noise spectra:\n\n"); /* 1 - Type SHORT */ printf("Image creation (type of storage = Short) ..."); fflush(stdout); create_tiger_frame(&image,"s_chk_tiger_io",npix,start,step,SHORT, "associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(short)(nolens*j)); WR_spec(&noise,j,(short)(nolens*j)); } put_tiger_spec(&image,&signal,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"s_chk_tiger_io","I"); printf("Ok\n"); nolens = (int)(nb_spec/2); status = exist_lens(&image,nolens); if (status < 0) { printf("unable to locate signal from lens no %d\n",nolens); fflush(stdout); return(-1); } printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,&noise,nolens); for (j=0;j<signal.npts;j++) { sval = (short)RD_spec(&signal,j); if (sval != (short)(nolens*j)) { printf("FATAL : Unexpected values in signal\n"); return(-1); } sval = (short)RD_spec(&noise,j); if (sval != (short)(nolens*j)) { printf("FATAL : Unexpected values in noise\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 2 - Type LONG */ printf("Image creation (type of storage = Long) ..."); fflush(stdout); create_tiger_frame(&image,"l_chk_tiger_io",npix,start,step,LONG,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(long)(nolens*j)); WR_spec(&noise,j,(long)(nolens*j)); } put_tiger_spec(&image,&signal,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"l_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,&noise,nolens); for (j=0;j<signal.npts;j++) { lval = (long)RD_spec(&signal,j); if (lval != (long)(nolens*j)) { printf("FATAL : Unexpected values in signal\n"); return(-1); } lval = (long)RD_spec(&noise,j); if (lval != (long)(nolens*j)) { printf("FATAL : Unexpected values in noise\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 3 - Type FLOAT */ printf("Image creation (type of storage = Float) ..."); fflush(stdout); create_tiger_frame(&image,"f_chk_tiger_io",npix,start,step,FLOAT,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(float)(nolens*j)); WR_spec(&noise,j,(float)(nolens*j)); } put_tiger_spec(&image,&signal,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"f_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,&noise,nolens); for (j=0;j<signal.npts;j++) { fval = (float)RD_spec(&signal,j); if (fval != (float)(nolens*j)) { printf("FATAL : Unexpected values in signal\n"); return(-1); } fval = (float)RD_spec(&noise,j); if (fval != (float)(nolens*j)) { printf("FATAL : Unexpected values in noise\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); /* 4 - Type DOUBLE */ printf("Image creation (type of storage = Double) ..."); fflush(stdout); create_tiger_frame(&image,"d_chk_tiger_io",npix,start,step,DOUBLE,"associated_tbl","dummy frame",NULL); printf("Ok\n"); set_lenses_coord(&image,"XPOS","YPOS",nb_spec,nol,x,y); printf("Writing into created image ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { init_new_tiger_spec(&image,&signal,npix,start); init_new_tiger_spec(&image,&noise,npix,start); for (j=0;j<signal.npts;j++) { WR_spec(&signal,j,(double)(nolens*j)); WR_spec(&noise,j,(double)(nolens*j)); } put_tiger_spec(&image,&signal,&noise,nolens); } printf("Ok\n"); printf("Saving created image ..."); fflush(stdout); close_tiger_frame(&image); printf("Ok\n"); printf("Opening previous image ..."); fflush(stdout); open_tiger_frame(&image,"d_chk_tiger_io","I"); printf("Ok\n"); printf("Reading image values ..."); fflush(stdout); for (nolens=1;nolens<=nb_spec;nolens++) { get_tiger_spec(&image,&signal,&noise,nolens); for (j=0;j<signal.npts;j++) { dval = (double)RD_spec(&signal,j); if (dval != (double)(nolens*j)) { printf("FATAL : Unexpected values in signal\n"); return(-1); } dval = (double)RD_spec(&noise,j); if (dval != (double)(nolens*j)) { printf("FATAL : Unexpected values in noise\n"); return(-1); } } } printf("Ok\n"); printf("Deleting previous image ..."); fflush(stdout); delete_tiger_frame(&image); printf("Ok\n\n"); exit_session(0); return(0); }
/* Initialize application data. */ static void initialize_data (void) { char *current_dir; char *path, *filename; int i = 0; convert_to_new_comment_system (); create_default_categories_if_needed (); eel_gconf_monitor_add ("/apps/gthumb"); gth_monitor = gth_monitor_new (); /* Icon theme */ icon_theme = gtk_icon_theme_get_default (); g_signal_connect (icon_theme, "changed", G_CALLBACK (theme_changed_cb), NULL); /* Default windows icon */ init_icon_pixbufs (); g_set_application_name (_("gThumb")); gtk_window_set_default_icon_name ("gthumb"); /**/ init_session ("gthumb"); if (session_is_restored ()) return; /* Parse command line arguments. */ if (remaining_args == NULL) { /* No arguments specified. */ reset_command_line_catalog (); return; } current_dir = g_get_current_dir (); while ((filename = remaining_args[i++]) != NULL) { char *tmp1 = NULL; gboolean is_dir; if (uri_has_scheme (filename) || g_path_is_absolute (filename)) tmp1 = gnome_vfs_make_uri_from_shell_arg (filename); else tmp1 = g_strconcat (current_dir, "/", filename, NULL); path = remove_special_dirs_from_path (tmp1); g_free (tmp1); if (path_is_dir (path)) is_dir = TRUE; else if (path_is_file (path)) is_dir = FALSE; else { g_free (path); continue; } if (is_dir) { dir_urls = g_list_prepend (dir_urls, add_scheme_if_absent (path)); g_free (path); } else file_urls = g_list_prepend (file_urls, path); } n_file_urls = g_list_length (file_urls); n_dir_urls = g_list_length (dir_urls); if (n_file_urls == 1) view_single_image = TRUE; if (n_file_urls > 1) { /* Create a catalog with the command line list. */ Catalog *catalog; char *catalog_path; GList *scan; catalog = catalog_new (); catalog_path = get_command_line_catalog_path (); catalog_set_path (catalog, catalog_path); g_free (catalog_path); for (scan = file_urls; scan; scan = scan->next) catalog_add_item (catalog, scan->data); catalog->sort_method = GTH_SORT_METHOD_MANUAL; catalog_write_to_disk (catalog, NULL); catalog_free (catalog); view_comline_catalog = TRUE; } else reset_command_line_catalog (); g_free (current_dir); }
void get_the_stats(Sint16 *stats, size_t len_in_bytes) { have_stats=1; memset(&your_info, 0, sizeof(your_info)); // failsafe incase structure changes //initiate the function pointers init_attribf(); your_info.phy.cur=SDL_SwapLE16(stats[0]); your_info.phy.base=SDL_SwapLE16(stats[1]); your_info.coo.cur=SDL_SwapLE16(stats[2]); your_info.coo.base=SDL_SwapLE16(stats[3]); your_info.rea.cur=SDL_SwapLE16(stats[4]); your_info.rea.base=SDL_SwapLE16(stats[5]); your_info.wil.cur=SDL_SwapLE16(stats[6]); your_info.wil.base=SDL_SwapLE16(stats[7]); your_info.ins.cur=SDL_SwapLE16(stats[8]); your_info.ins.base=SDL_SwapLE16(stats[9]); your_info.vit.cur=SDL_SwapLE16(stats[10]); your_info.vit.base=SDL_SwapLE16(stats[11]); your_info.human_nex.cur=SDL_SwapLE16(stats[12]); your_info.human_nex.base=SDL_SwapLE16(stats[13]); your_info.animal_nex.cur=SDL_SwapLE16(stats[14]); your_info.animal_nex.base=SDL_SwapLE16(stats[15]); your_info.vegetal_nex.cur=SDL_SwapLE16(stats[16]); your_info.vegetal_nex.base=SDL_SwapLE16(stats[17]); your_info.inorganic_nex.cur=SDL_SwapLE16(stats[18]); your_info.inorganic_nex.base=SDL_SwapLE16(stats[19]); your_info.artificial_nex.cur=SDL_SwapLE16(stats[20]); your_info.artificial_nex.base=SDL_SwapLE16(stats[21]); your_info.magic_nex.cur=SDL_SwapLE16(stats[22]); your_info.magic_nex.base=SDL_SwapLE16(stats[23]); your_info.manufacturing_skill.cur=SDL_SwapLE16(stats[24]); your_info.manufacturing_skill.base=SDL_SwapLE16(stats[25]); your_info.harvesting_skill.cur=SDL_SwapLE16(stats[26]); your_info.harvesting_skill.base=SDL_SwapLE16(stats[27]); your_info.alchemy_skill.cur=SDL_SwapLE16(stats[28]); your_info.alchemy_skill.base=SDL_SwapLE16(stats[29]); your_info.overall_skill.cur=SDL_SwapLE16(stats[30]); your_info.overall_skill.base=SDL_SwapLE16(stats[31]); your_info.attack_skill.cur=SDL_SwapLE16(stats[32]); your_info.attack_skill.base=SDL_SwapLE16(stats[33]); your_info.defense_skill.cur=SDL_SwapLE16(stats[34]); your_info.defense_skill.base=SDL_SwapLE16(stats[35]); your_info.magic_skill.cur=SDL_SwapLE16(stats[36]); your_info.magic_skill.base=SDL_SwapLE16(stats[37]); your_info.potion_skill.cur=SDL_SwapLE16(stats[38]); your_info.potion_skill.base=SDL_SwapLE16(stats[39]); your_info.carry_capacity.cur=SDL_SwapLE16(stats[40]); your_info.carry_capacity.base=SDL_SwapLE16(stats[41]); your_info.material_points.cur=SDL_SwapLE16(stats[42]); your_info.material_points.base=SDL_SwapLE16(stats[43]); your_info.ethereal_points.cur=SDL_SwapLE16(stats[44]); your_info.ethereal_points.base=SDL_SwapLE16(stats[45]); your_info.food_level=SDL_SwapLE16(stats[46]); your_info.manufacturing_exp=SDL_SwapLE32(*((Uint32 *)(stats+49))); your_info.manufacturing_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+51))); your_info.harvesting_exp=SDL_SwapLE32(*((Uint32 *)(stats+53))); your_info.harvesting_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+55))); your_info.alchemy_exp=SDL_SwapLE32(*((Uint32 *)(stats+57))); your_info.alchemy_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+59))); your_info.overall_exp=SDL_SwapLE32(*((Uint32 *)(stats+61))); your_info.overall_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+63))); your_info.attack_exp=SDL_SwapLE32(*((Uint32 *)(stats+65))); your_info.attack_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+67))); your_info.defense_exp=SDL_SwapLE32(*((Uint32 *)(stats+69))); your_info.defense_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+71))); your_info.magic_exp=SDL_SwapLE32(*((Uint32 *)(stats+73))); your_info.magic_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+75))); your_info.potion_exp=SDL_SwapLE32(*((Uint32 *)(stats+77))); your_info.potion_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+79))); your_info.summoning_skill.cur=SDL_SwapLE16(stats[83]); your_info.summoning_skill.base=SDL_SwapLE16(stats[84]); your_info.summoning_exp=SDL_SwapLE32(*((Uint32 *)(stats+85))); your_info.summoning_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+87))); your_info.crafting_skill.cur=SDL_SwapLE16(stats[89]); your_info.crafting_skill.base=SDL_SwapLE16(stats[90]); your_info.crafting_exp=SDL_SwapLE32(*((Uint32 *)(stats+91))); your_info.crafting_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+93))); your_info.engineering_skill.cur=SDL_SwapLE16(stats[95]); your_info.engineering_skill.base=SDL_SwapLE16(stats[96]); your_info.engineering_exp=SDL_SwapLE32(*((Uint32 *)(stats+97))); your_info.engineering_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+99))); your_info.tailoring_skill.cur=SDL_SwapLE16(stats[101]); your_info.tailoring_skill.base=SDL_SwapLE16(stats[102]); your_info.tailoring_exp=SDL_SwapLE32(*((Uint32 *)(stats+103))); your_info.tailoring_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+105))); your_info.ranging_skill.cur=SDL_SwapLE16(stats[107]); your_info.ranging_skill.base=SDL_SwapLE16(stats[108]); your_info.ranging_exp=SDL_SwapLE32(*((Uint32 *)(stats+109))); your_info.ranging_exp_next_lev=SDL_SwapLE32(*((Uint32 *)(stats+111))); your_info.research_completed=SDL_SwapLE16(stats[47]); your_info.researching=SDL_SwapLE16(stats[81]); your_info.research_total=SDL_SwapLE16(stats[82]); check_book_known(); // can be removed test when we change protocol number for 1.9.2 if (len_in_bytes <= 2*114) { your_info.action_points.cur=0; your_info.action_points.base=0; } else { your_info.action_points.cur=SDL_SwapLE16(stats[113]); your_info.action_points.base=SDL_SwapLE16(stats[114]); } init_session(); check_castability(); }
void handle_connection(const int listen_fd, short event, void *arg) { struct sockaddr_storage tmp_ss; struct sockaddr *client_sa, *server_sa, *fixed_server_sa; struct sockaddr *proxy_to_server_sa; struct session *s; socklen_t len; int client_fd, fc, on; event_add(&listen_ev, NULL); if ((event & EV_TIMEOUT)) /* accept() is no longer paused. */ return; /* * We _must_ accept the connection, otherwise libevent will keep * coming back, and we will chew up all CPU. */ client_sa = sstosa(&tmp_ss); len = sizeof(struct sockaddr_storage); if ((client_fd = accept(listen_fd, client_sa, &len)) < 0) { logmsg(LOG_CRIT, "accept() failed: %s", strerror(errno)); /* * Pause accept if we are out of file descriptors, or * libevent will haunt us here too. */ if (errno == ENFILE || errno == EMFILE) { struct timeval pause = { 1, 0 }; event_del(&listen_ev); evtimer_add(&pause_accept_ev, &pause); } else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED) logmsg(LOG_CRIT, "accept() failed: %s", strerror(errno)); return; } /* Refuse connection if the maximum is reached. */ if (session_count >= max_sessions) { logmsg(LOG_ERR, "client limit (%d) reached, refusing " "connection from %s", max_sessions, sock_ntop(client_sa)); close(client_fd); return; } /* Allocate session and copy back the info from the accept(). */ s = init_session(); if (s == NULL) { logmsg(LOG_CRIT, "init_session failed"); close(client_fd); return; } s->client_fd = client_fd; memcpy(sstosa(&s->client_ss), client_sa, client_sa->sa_len); /* Cast it once, and be done with it. */ client_sa = sstosa(&s->client_ss); server_sa = sstosa(&s->server_ss); proxy_to_server_sa = sstosa(&s->proxy_ss); fixed_server_sa = sstosa(&fixed_server_ss); /* Log id/client early to ease debugging. */ logmsg(LOG_DEBUG, "#%d accepted connection from %s", s->id, sock_ntop(client_sa)); /* * Find out the real server and port that the client wanted. */ len = sizeof(struct sockaddr_storage); if (getsockname(s->client_fd, server_sa, &len) < 0) { logmsg(LOG_CRIT, "#%d getsockname failed: %s", s->id, strerror(errno)); goto fail; } len = sizeof(s->client_rd); if (getsockopt(s->client_fd, SOL_SOCKET, SO_RTABLE, &s->client_rd, &len) && errno != ENOPROTOOPT) { logmsg(LOG_CRIT, "#%d getsockopt failed: %s", s->id, strerror(errno)); goto fail; } if (fixed_server) { memcpy(sstosa(&s->orig_server_ss), server_sa, server_sa->sa_len); memcpy(server_sa, fixed_server_sa, fixed_server_sa->sa_len); } /* XXX: check we are not connecting to ourself. */ /* * Setup socket and connect to server. */ if ((s->server_fd = socket(server_sa->sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0) { logmsg(LOG_CRIT, "#%d server socket failed: %s", s->id, strerror(errno)); goto fail; } if (fixed_proxy && bind(s->server_fd, sstosa(&fixed_proxy_ss), fixed_proxy_ss.ss_len) != 0) { logmsg(LOG_CRIT, "#%d cannot bind fixed proxy address: %s", s->id, strerror(errno)); goto fail; } /* Use non-blocking connect(), see CONNECT_TIMEOUT below. */ if ((fc = fcntl(s->server_fd, F_GETFL)) == -1 || fcntl(s->server_fd, F_SETFL, fc | O_NONBLOCK) == -1) { logmsg(LOG_CRIT, "#%d cannot mark socket non-blocking: %s", s->id, strerror(errno)); goto fail; } if (connect(s->server_fd, server_sa, server_sa->sa_len) < 0 && errno != EINPROGRESS) { logmsg(LOG_CRIT, "#%d proxy cannot connect to server %s: %s", s->id, sock_ntop(server_sa), strerror(errno)); goto fail; } len = sizeof(struct sockaddr_storage); if ((getsockname(s->server_fd, proxy_to_server_sa, &len)) < 0) { logmsg(LOG_CRIT, "#%d getsockname failed: %s", s->id, strerror(errno)); goto fail; } logmsg(LOG_INFO, "#%d FTP session %d/%d started: client %s to server " "%s via proxy %s", s->id, session_count, max_sessions, sock_ntop(client_sa), sock_ntop(server_sa), sock_ntop(proxy_to_server_sa)); /* Keepalive is nice, but don't care if it fails. */ on = 1; setsockopt(s->client_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof on); setsockopt(s->server_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof on); /* * Setup buffered events. */ s->client_bufev = bufferevent_new(s->client_fd, &client_read, NULL, &client_error, s); if (s->client_bufev == NULL) { logmsg(LOG_CRIT, "#%d bufferevent_new client failed", s->id); goto fail; } bufferevent_settimeout(s->client_bufev, timeout, 0); bufferevent_enable(s->client_bufev, EV_READ | EV_TIMEOUT); s->server_bufev = bufferevent_new(s->server_fd, &server_read, NULL, &server_error, s); if (s->server_bufev == NULL) { logmsg(LOG_CRIT, "#%d bufferevent_new server failed", s->id); goto fail; } bufferevent_settimeout(s->server_bufev, CONNECT_TIMEOUT, 0); bufferevent_enable(s->server_bufev, EV_READ | EV_TIMEOUT); return; fail: end_session(s); }