/* * execute_file executes a plain text script that has already been assigned * as the input file. * * The arguments must have been assigned, too. * * The return value is the value that the main routine should return to the OS. */ static int execute_file( tsd_t *TSD ) { FILE *fptr = TSD->systeminfo->input_fp; internal_parser_type parsing; streng *string; int RetCode; /* * From here we are interpreting... */ fetch_file( TSD, fptr ? fptr : stdin, &parsing ); if ( fptr ) fclose( fptr ); TSD->systeminfo->input_fp = NULL; if ( parsing.result != 0 ) exiterror( ERR_YACC_SYNTAX, 1, parsing.tline ); else TSD->systeminfo->tree = parsing; #if !defined(MINIMAL) && !defined(VMS) && !defined(DOS) && !defined(_MSC_VER) && !defined(__IBMC__) && !defined(MAC) if ( !fptr ) { struct stat buffer; int rc; rc = fstat( fileno( stdin ), &buffer ); if ( ( rc == 0 ) && S_ISCHR( buffer.st_mode ) ) { /* * FIXME. MH and FGC. * When does this happen. Add debugging code to determine this, because * after 2 glasses of rocket fuel it seems silly to have this code! * 13-5-2004. */ printf( " \b\b" ); fflush( stdout ); rewind( stdin ); } } #endif flush_trace_chars( TSD ); string = interpret( TSD, TSD->systeminfo->tree.root ); RetCode = codeFromString( TSD, string ); if ( string ) Free_stringTSD( string ); return RetCode; }
/** * @brief Parse an S3 Error element. * * This function parses Error XML elements. * * For example: * * @code{xml} * <Error> * <Code>NoSuchKey</Code> * <Message>The resource you requested does not exist</Message> * <Resource>/mybucket/myfoto.jpg</Resource> * <RequestId>4442587FB7D0A2F9</RequestId> * </Error> * @endcode * * @param xml XML stream to parse. */ void S3ErrorPrivate::parse(QXmlStreamReader & xml) { if ((xml.tokenType() == QXmlStreamReader::NoToken) && (!xml.readNextStartElement())) { return; } Q_ASSERT(xml.name() == QLatin1String("Error")); while (xml.readNextStartElement()) { if (xml.name() == QLatin1String("Code")) { code = codeFromString(rawCode = xml.readElementText()); } else if (xml.name() == QLatin1String("Message")) { message = xml.readElementText(); } else { detail.insert(xml.name().toString(), xml.readElementText()); } } }
int main(int argc,char *argv[]) # define CALL_MAIN main #endif { tsd_t *TSD; int processed; int compile_to_tokens=0; int execute_from_tokens=0; int locale_set=0; int stdinput, rcode; jmp_buf jbuf; #ifdef MAC InitCursorCtl( nil ); #endif if ( argv0 == NULL ) argv0 = GetArgv0( argv[0] ); TSD = GLOBAL_ENTRY_POINT(); setup_system( TSD, 0 ); if ( setjmp( jbuf ) ) { /* * We may either be jumped normally after an EXIT instruction or after * an error. The first reason means normal continuation, the other * means that we have to do an immediate stop. */ if ( !TSD->instore_is_errorfree ) { if ( TSD->systeminfo->result ) return atoi( TSD->systeminfo->result->value ); return -1; } else { if ( TSD->systeminfo->result ) rcode = codeFromString( TSD, TSD->systeminfo->result ); else rcode = EXIT_SUCCESS; } } else { TSD->systeminfo->script_exit = &jbuf; processed = check_args( TSD, argc, argv, &compile_to_tokens, &execute_from_tokens, &locale_set ); if ( processed == 0 ) return 0; if ( !locale_set ) { /* * Check for a comma separated default locale in REGINA_LANG. */ char *ptr = getenv( "REGINA_LANG" ); if ( ptr ) ptr = strchr( ptr, ',' ); if ( ptr ) set_locale_info( ptr + 1 ); } if ( processed < argc ) { stdinput = 0; TSD->systeminfo->input_file = get_external_routine( TSD, argv[processed], &TSD->systeminfo->input_fp ); if ( !TSD->systeminfo->input_file ) { TSD->systeminfo->input_file = Str_crestrTSD( argv[processed] ); exiterror( ERR_PROG_UNREADABLE, 1, "Program was not found" ); } processed++; } else { stdinput = 1; TSD->systeminfo->input_file = Str_crestrTSD( "<stdin>" ); TSD->systeminfo->input_fp = NULL; if ( compile_to_tokens ) exiterror( ERR_PROG_UNREADABLE, 1, "Too few arguments when " "tokenising. Usage: -c inputfile outputfile" ); if ( execute_from_tokens ) exiterror( ERR_PROG_UNREADABLE, 1, "Cannot run tokenised code " "from stdin." ); } /* * -c switch specified - tokenise the input file before mucking around * with parameters etc. */ if ( compile_to_tokens ) { if ( processed >= argc ) exiterror( ERR_PROG_UNREADABLE, 1, "Too few arguments when " "tokenising. Usage: -c inputfile outputfile" ); if ( processed + 1 < argc ) exiterror( ERR_PROG_UNREADABLE, 1, "Too many arguments when " "tokenising. Usage: -c inputfile outputfile" ); just_compile( TSD, argv[processed] ); return 0; } /* * Under DJGPP setmode screws up Parse Pull and entering code * interactively :-( */ #if defined(__EMX__) || (defined(_MSC_VER) && !defined(__WINS__)) || (defined(__WATCOMC__) && !defined(__QNX__)) setmode( fileno( stdin ), O_BINARY ); setmode( fileno( stdout ), O_BINARY ); setmode( fileno( stderr ), O_BINARY ); #endif assign_args( TSD, argc, processed, argv ); signal_setup( TSD ); /* * -e switch specified - execute from tokenised code */ if ( execute_from_tokens ) rcode = execute_tokenized( TSD ); else rcode = execute_file( TSD ); } #if defined(DEBUG) || defined(TRACEMEM) /* * Now do the cleanup. We don't need in real life, but for a proper cleanup * and for debugging aid it is a good idea to track down the whole beast. */ purge_stacks( TSD ); purge_filetable( TSD ); # if defined(FLISTS) && defined(NEW_FLISTS) free_flists(); # endif # ifdef DYNAMIC /* * Remove all external function package functions * and libraries. Only valid for the DYNAMIC library. */ purge_library( TSD ); # endif # ifdef TRACEMEM if ( TSD->listleakedmemory ) listleaked( TSD, MEMTRC_LEAKED ); # endif TSD->systeminfo->script_exit = NULL; /* cannot be freed, it's on the stack*/ killsystem( TSD, TSD->systeminfo ); TSD->systeminfo = NULL; /* * Remove all memory allocated by the flists internal memory manager. */ # ifdef FLISTS purge_flists( TSD ); # endif #endif /* DEBUG */ return rcode; }
/* * execute_tokenized executes a tokenized script that has already been assigned * as the input file. * * The arguments must have been assigned, too. * * The return value is the value that the main routine should return to the OS. */ static int execute_tokenized( tsd_t *TSD ) { void *TinnedTree; unsigned long TinnedTreeLen; streng *command; streng *result; streng *environment; int err,RetCode; /* * Read the file into TinnedTree. */ fseek( TSD->systeminfo->input_fp, 0, SEEK_END ); TinnedTreeLen = ftell( TSD->systeminfo->input_fp ); rewind( TSD->systeminfo->input_fp ); TinnedTree = MallocTSD( TinnedTreeLen ); if ( TinnedTree == NULL ) exiterror( ERR_STORAGE_EXHAUSTED, 0 ); if ( fread( TinnedTree, TinnedTreeLen, 1, TSD->systeminfo->input_fp ) != 1 ) exiterror( ERR_PROG_UNREADABLE, 1, "Unable to read input file" ); /* * Don't close the file because the plain text file remains open as well. * This inhibits the deletion or modification on most systems. */ /* * Check if the file being read is a valid tokenised file. */ if ( !IsValidTin( (const external_parser_type *)TinnedTree, TinnedTreeLen ) ) exiterror( ERR_PROG_UNREADABLE, 1, "The supplied file is not a valid Regina tokenised file" ); /* * Set program file name and environment. The argument have been assigned * already. */ command = Str_dupTSD( TSD->systeminfo->input_file ); /* * Changed after 3.3RC1: The environment is set to SYSTEM instead of * the externally bound (ENVIR_PIPE) "DEFAULT". */ environment = Str_creTSD( "SYSTEM" ); flush_trace_chars( TSD ); /* * do_instore() actually does the execution... */ result = do_instore( TSD, command, TSD->currlevel->args, environment, &err, 0, TinnedTree, TinnedTreeLen, NULL, 0, /* source file contents */ NULL, TSD->systeminfo->invoked ); FreeTSD( TinnedTree ); Free_stringTSD( command ); Free_stringTSD( environment ); if ( result ) { RetCode = codeFromString( TSD, result ); Free_stringTSD( result ); } else RetCode = err; return RetCode; }