void Module::addParsersRecursive(Object &object, const ObjectType &type, const Module &fromModule, const ObjectType &lastType) const { //Building the father list std::list<ObjectType> fathers; ObjectType currentType = type; while(currentType.typeTemplate() != lastType.typeTemplate() && !currentType.isNull()) { fathers.push_front(currentType); currentType = fromModule.getFather(currentType); } //Adding the fathers' parsers for(ObjectType father : fathers) { object.setType(father); const Module* module = handler(father); if(module!=nullptr) { Parser* parser = module->getParser(father, object, fromModule); object.addParser(parser); } } //Type specification ObjectType specification = specify(object.type()); if(!specification.isNull()) { addParsersRecursive(object, specification, fromModule, object.type()); } }
int flpy_read(struct fdd *d, uint32_t lba, uint8_t *buf, uint32_t nr_sectors) { int rc = 0; uint8_t retries; struct chs f_addr; if (d->param->cmos_type == 0) return -1; while (_busy) ; /* Wait while the floppy driver is already busy. BUSY WAIT! */ _busy = TRUE; start_motor(d); specify(d); /* Only retry for 3 times */ for (retries = 0; retries < 3; retries++) { /* Move head to right track */ if (flpy_seek(d, f_addr.c) == 0) { /* If changeline is active, no disk is in drive */ if (inportb(d->fdc->base_port + FDC_DIR) & 0x80) { DEBUG(DL_ERR, ("no disk in drive %d\n", d->number)); rc = -1; goto errorout; } rc = fdc_xfer(d, &f_addr, dma_addr, nr_sectors, FDC_READ); if (rc == 0) break; } else rc = -1; if (retries < 2) recalibrate(d); } /* Copy data from the DMA buffer into the caller's buffer */ if ((rc == 0) && buf) ; errorout: stop_motor(d); _busy = FALSE; return rc; }
void Module::addParsers(Object &object, const ObjectType &type) const { //Building the father list ObjectType currentType = type; ObjectType lastType; while (!currentType.isNull()) { std::list<ObjectType> fathers; while(currentType.typeTemplate() != lastType.typeTemplate() && !currentType.isNull()) { fathers.push_front(currentType); currentType = currentType.parent(); } //Adding the fathers' parsers for(ObjectType father : fathers) { object.setType(father); Parser* parser = father.parseOrGetParser(static_cast<ParsingOption&>(object)); object.addParser(parser); } //Type specification lastType= object.type(); currentType = specify(lastType); } const auto& parsers = object._parsers; if (std::any_of(parsers.begin(), parsers.end(), [](const std::unique_ptr<Parser>& parser) { if (parser) { return parser->needTailParsing(); } else { return false; } })) { object.parse(); }; }
int flpy_write(struct fdd *d, uint32_t lba, const uint8_t buf, uint32_t nr_sectors) { int rc = 0; uint8_t retries; struct chs f_addr; if (d->param->cmos_type == 0) return -1; while (_busy) ; // The BUSY WAIT! _busy = TRUE; start_motor(d); specify(d); for (retries = 0; retries < 3; retries++) { /* Move head to right track */ if (flpy_seek(d, f_addr.c) == 0) { /* If changeline is active, no disk is in drive */ if (inportb(d->fdc->base_port + FDC_DIR) & 0x80) { DEBUG(DL_ERR, ("no disk in drive %d\n", d->number)); rc = -1; break; } rc = fdc_xfer(d, &f_addr, dma_addr, nr_sectors, FDC_WRITE); if (rc == 0) break; } else rc = -1; if (retries < 2 ) recalibrate(d); } stop_motor(d); _busy = FALSE; return rc; }
int main(int argc, char *argv[]) { /* main * The main LEAP program - This performs the display of the * title, and processes the command line. Clean termination * also should occur here. Everywhere else termination is * "unclean", and should return an error status. Define * error status' in the dtypes.h file */ #ifdef FULL_DEBUG /* Test vars */ char source[50],result[50],*sptr; #endif boolean tdebug=FALSE,ttiming=FALSE,ttimelog=FALSE,tlong=FALSE; boolean tquiet=FALSE,ttrace=FALSE,tpad=FALSE,tpjoin=FALSE; time_t tp; char *s; char *argptr; /******************************** * Startup - Firstly set up the * signal handlers ********************************/ /* Signal Interrupt from the keyboard - the daemon should handle it */ signal(SIGINT,&signal_handler); /* MSDOS/Windows does not know SIGQUIT/SIGHUP, whereas * these are important in Unix */ #ifndef __MSDOS__ /* Signal Quit from the keyboard - Ignore it */ signal(SIGQUIT,SIG_IGN); /* Signal Hang up - Handle it */ signal(SIGHUP,&signal_handler); #else #endif define_handle(&default_handler,&errorHandler); raise_message(EVENT, "%s","Event Handler initialised."); define_handle(&default_quiethandler,&messageHandler); raise_message(EVENT,"%s","Message Handler initialised."); /* Signal Terminate - Handle it */ signal(SIGTERM,&signal_handler); /* Perform some configuration... */ build_base_dir(LEAP_DEFAULT_DIR); /* Set the random seed to the time in secs since 01.01.1970 * should be random enough! */ srand(time(NULL)); s=getenv(LEAP_ENV_DIR); strcpy(dbtoopen,""); strcpy(activityfile,""); strcpy(tempdir,""); ACTIVITY_FILE=NULL; if (s!=NULL) { leap_fprintf(stdout,"Using environment variable %s for path (%s).\n",LEAP_ENV_DIR,s); build_base_dir(s); } /* Process the command line Stop if we run out of arguments or we get an argument without a dash */ /* NB. This is based on O'Reilly & Associates "Practical C Programming", by Steve Oualline, 2nd Ed. (pg 178) */ while ((argc > 1) && (argv[1][0] == '-')) { /* * argv[1][1] is the actual option character */ if ((argv[1][0]==ARGUMENT_PREFIX) && (argv[1][1]==ARGUMENT_PREFIX)) { argptr=&argv[1][2]; } else { argptr=&argv[1][1]; } switch (*argptr) { case 'a': case 'A': if ((strcmp(argptr,"activity-file")==0)||(strcmp(argptr,"activity")==0)||(strlen(argptr)==1)) { if (specify(activityfile,argv[2],FILE_PATH_SIZE)){ argv++; argc--; } else { leap_fprintf(stderr,"No file specified. Using %s\n",LEAP_ACTIVITY_FILE); strncpy(activityfile,LEAP_ACTIVITY_FILE,FILE_PATH_SIZE); } ACTIVITY_FILE=fopen(activityfile,"a"); if (ACTIVITY_FILE==NULL) { leap_fprintf(stderr,"Unable to open activity file for appending.\n"); } else { tp=time(NULL); fprintf(ACTIVITY_FILE,"###\n# Activity file STARTED at: %s###\n",ctime(&tp)); leap_printf("Activity file: %s\n",activityfile); } } break; case 'b': case 'B': if (specify(dbtoopen,argv[2],DATABASE_NAME_SIZE)){ argv++; argc--; } else { raise_message(MESSAGE,"No database specified on command line. %s will be used.",DEFAULT_DB); } break; case 'd': case 'D': if ((strcmp(argptr,"dir")==0)||(strcmp(argptr,"directory")==0)||(strlen(argptr)==1)) { if (argv[2]) { build_base_dir(argv[2]); /* Increment the counts... */ argv++; argc--; } else { leap_fprintf(stderr,"ERROR: No directory specified after directory flag.\n"); exit(1); } } else if (strcmp(argptr,"database")==0) { if (specify(dbtoopen,argv[2],DATABASE_NAME_SIZE)){ argv++; argc--; } } else if (strcmp(argptr,"debug")==0) { /* The user wants debug information */ leap_printf("Debug messages enabled\n"); tdebug=TRUE; } break; case 'e': case 'E': if (strlen(argptr)==1) { /* The user wants debug information */ leap_printf("Debug messages enabled\n"); tdebug=TRUE; } else if ((strcmp(argptr,"events")==0)||(strcmp(argptr,"event")==0)) { /* User wants event reports */ define_handle(&default_quiethandler,&eventHandler); raise_message(EVENT,"%s","Event Handler initialised."); } break; case 'h': case '?': case 'H': if ((strcmp(argptr,"help")==0)||(strlen(argptr)==1)) { /* The user wants some help... */ print_help(); /* Exit without an error */ exit(0); /* Lint-ified - The break is not reached */ /* break; */ } case 'i': case 'I': /* The user wants timing information */ leap_printf("Timing information enabled\n"); ttiming=TRUE; break; case 'l': case 'L': if ((strcmp(argptr,"time-logging")==0)||(strlen(argptr)==1)) { /* Do not fetch the system time in log file */ leap_printf("Time logging disabled\n"); ttimelog=FALSE; } else if ((strcmp(argptr,"long-commands")==0)||(strcmp(argptr,"long")==0)){ leap_printf("Long commands enabled\n"); tlong=TRUE; } break; case 'n': case 'N': /* Display warranty information */ do_warranty(); exit(0); /* Lint-ified - The break is not reached */ /* break; */ case 'o': case 'O': leap_printf("Long commands enabled\n"); tlong=TRUE; break; case 'p': case 'P': if ((strcmp(argptr,"padding")==0)||(strlen(argptr)==1)) { leap_printf("Relation Name Padding enabled\n"); tpad=TRUE; } else if ((strcmp(argptr,"product-join")==0)||(strcmp(argptr,"pjoin")==0)) { leap_printf("Product performed in no-condition join\n"); tpjoin=TRUE; } break; case 'q': case 'Q': if ((strcmp(argptr,"quiet")==0)||(strlen(argptr)==1)) { tquiet=TRUE; BEEP=' '; /* Shutdown the message handler */ define_handle(NULL,&messageHandler); } break; case 'r': case 'R': if ((strcmp(argptr,"regression")==0)||(strlen(argptr)==1)) { /* What!? This is to disable outputting * items that might cause regression tests * to fail for no good reason, ie. * temporary relation names which are random, * and will differ between runs. */ status_regression=TRUE; leap_printf("Regression test mode on\n"); } break; case 's': case 'S': if ((strcmp(argptr,"status")==0)||(strlen(argptr)==1)) { /* The user wants status messages to be displayed */ leap_printf("Status messages enabled\n"); status=TRUE; } break; case 't': case 'T': if ((strcmp(argptr,"time")==0)||(strcmp(argptr,"timing")==0)) { /* The user wants timing information */ leap_printf("Timing information enabled\n"); ttiming=TRUE; } else if ((strlen(argptr)==1)||(strcmp(argptr,"trace")==0)||(strcmp(argptr,"tracing")==0)) { /* The user wants tracing information */ leap_printf("Tracing information enabled\n"); ttrace=TRUE; } break; case 'v': case 'V': if ((strcmp(argptr,"version")==0)||(strlen(argptr)==1)) { /* Print BRIEF version information */ print_header(TRUE); exit(0); } break; case 'w': case 'W': if ((strcmp(argptr,"warranty")==0)||(strlen(argptr)==1)) { do_warranty(); exit(0); } break; case 'x': case 'X': if (argv[2]) { strncpy(tempdir,argv[2],FILE_PATH_SIZE); /* Increment the counts... */ argv++; argc--; } else { leap_fprintf(stderr,"ERROR: No directory specified after temporary directory flag.\n"); exit(1); } break; default: raise_error(ERROR_COMMAND_LINE,NONFATAL,argptr); } /* Move the argument list up one and the count down one */ argv++; argc--; } raise_message(EVENT,"%s","Command line processed."); /* First things first, report (verbosely) what we are. */ if ((status_regression!=TRUE) && (tquiet!=TRUE)) print_header(FALSE); if ( (status) && (tquiet!=TRUE) ) { sprintf(temp_80_chars,"LEAP Base directory set to: %s",LEAP_BASE_DIR); leap_printf(temp_80_chars); } /* Call any initialisation routines... */ util_init(); /* This has to be done after the path is read, so that * the variable config file is located. */ if (init_variables()!=RETURN_SUCCESS) { raise_message(MESSAGE,"Directory specified [%s] not valid. Trying [%s]",LEAP_BASE_DIR,LEAP_TRY_DIR); build_base_dir(LEAP_TRY_DIR); if (init_variables()!=RETURN_SUCCESS) { raise_message(MESSAGE,"[%s] is also not valid - Problems are likely",LEAP_TRY_DIR); } else { raise_message(MESSAGE,"Variables are now set."); } } if (tdebug==TRUE) set_variable(STATUS_DEBUG,STATUS_SETTING_ON); if (ttiming==TRUE) set_variable(STATUS_TIMING,STATUS_SETTING_ON); if (ttimelog==TRUE) set_variable(STATUS_TIMELOG,STATUS_SETTING_ON); if (tlong==FALSE) set_variable(STATUS_LONGLINE,STATUS_SETTING_OFF); if (tquiet==TRUE) set_variable(STATUS_QUIET,STATUS_SETTING_ON); if (ttrace==TRUE) set_variable(STATUS_TRACE,STATUS_SETTING_ON); if (tpad==TRUE) set_variable(STATUS_PADDING,STATUS_SETTING_ON); if (tpjoin==TRUE) set_variable(STATUS_PRODUCTJOIN,STATUS_SETTING_ON); /* Display some information */ if (status_quiet!=TRUE) { raise_message(MESSAGE,"LEAP is starting..."); } #ifdef DEBUG status_debug=TRUE; leap_fprintf(stderr,"DEBUG: LEAP debug mode forced on\n"); #endif /* Do the main leap operation */ (void) do_daemon(); print_shutdown(); /* Close the various files opened earlier */ util_close(); if (status_quiet!=TRUE) { /* Inform the user of a clean termination */ raise_message(MESSAGE,"LEAP Terminated successfully!"); } /* Return success. Elsewhere, non-zero should be returned */ return(0); }
bool MTexture::set(MImage &image, Type type, bool mipmapped /* = true */, GLenum target /* = GL_TEXTURE_2D) */) { unsigned int i; // used as a temporary index. // Store the type of texture, and derive other parameters. // (Depth is assumed to be 4 bytes per pixel RGBA. // MImage always returns that pixel format anyway.) m_type = type; if ( (m_type == RGBA) || (m_type == NMAP) ) { m_internalFormat = GL_RGBA8; m_format = GL_RGBA; m_componentFormat = GL_UNSIGNED_BYTE; } else if (m_type == HILO) { #if NVIDIA_SPECIFIC m_internalFormat = GL_SIGNED_HILO_NV; m_format = GL_HILO_NV; m_componentFormat = GL_SHORT; #endif } else assert(0); // Get the dimension of the texture. MStatus stat = image.getSize(m_width, m_height); assert(stat); m_mipmapped = mipmapped; unsigned int maxWidthLevels = highestPowerOf2(m_width); unsigned int maxHeightLevels = highestPowerOf2(m_height); // Standard OpenGL doesn't accept width or height that are not power of 2. // If that's the case we resize the picture to the closest larger valid rectangle. bool widthIsExponent = (m_width == (unsigned int) (1 << maxWidthLevels)); bool heightIsExponent = (m_height == (unsigned int) (1 << maxHeightLevels)); if (!widthIsExponent || !heightIsExponent) { // Calculate the new width/height. if (!widthIsExponent) maxWidthLevels++; if (!heightIsExponent) maxHeightLevels++; // Resize the image, without bothering to preserve the aspect ratio. m_width = 1 << maxWidthLevels; m_height = 1 << maxHeightLevels; image.resize(m_width, m_height, false); } // Deallocate any existing levels if (m_levels != NULL) { for (i=0; i < m_numLevels; i++) { if (m_levels[i]) { xr_free(m_levels[i]); m_levels[i] = NULL; } } xr_free(m_levels); } // The number of mipmap levels cannot be greater than the exponent of width or height. // The number of mipmap levels is 1 for a non-mipmapped texture. // For mipmapped textures, m_numLevels = max level + 1. m_numLevels = mipmapped ? _max(maxWidthLevels, maxHeightLevels) + 1 : 1; // Allocate the proper amount of memory, for the base level and the mipmaps. m_levels = xr_alloc<unsigned char*>(m_numLevels); for (i=0; i < m_numLevels; i++) { m_levels[i] = xr_alloc<unsigned char>(width(i) * height(i) * 4); } // Copy the base level. (the actual file texture) Memory.mem_copy(m_levels[0], image.pixels(), m_width * m_height * 4); // Create the mipmapped levels. // NOTE REGARDING THE width_ratio and height_ratio: // The smallest mipmap levels of non-square textures must be handled // carefully. Say we have a 8x2 texture. Mipmap levels will be // 4x1, 2x1, 1x1. We cannot simply multiply the current st coordinate by // 2 like we do for square textures to find the source st coordinates, // or we'll end up fetching outside of the source level. Instead, we // multiply the target s, t coordinates by the width and height ratio respectively. for (unsigned int current_level = 1; current_level < m_numLevels; current_level++) { unsigned int width_ratio = width(i-1) / width(i); unsigned int height_ratio = height(i-1) / height(i-1); unsigned int previous_level = current_level - 1; for (unsigned int target_t = 0; target_t < height(current_level); target_t++) { for (unsigned int target_s = 0; target_s < width(current_level); target_s++) { // The st coordinates from the source level. unsigned int source_s = target_s * width_ratio; unsigned int source_t = target_t * height_ratio; unsigned int source_s2 = source_s + ((width_ratio == 2) ? 1 : 0); unsigned int source_t2 = source_t + ((height_ratio == 2) ? 1 : 0); unsigned char *destination = internalFetch(target_s, target_t, current_level); unsigned char *source1 = internalFetch(source_s, source_t, previous_level); unsigned char *source2 = internalFetch(source_s2, source_t, previous_level); unsigned char *source3 = internalFetch(source_s, source_t2, previous_level); unsigned char *source4 = internalFetch(source_s2, source_t2, previous_level); // Average byte per byte. unsigned int average1 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; *destination++ = average1; unsigned int average2 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; *destination++ = average2; unsigned int average3 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; *destination++ = average3; unsigned int average4 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; *destination++ = average4; } } } if( type == NMAP ) { // Convert each level to the NORMAL map format // MNormalMapConverter mapConverter; for (unsigned int i = 0; i < m_numLevels; i++) { mapConverter.convertToNormalMap( m_levels[i], width(i), height(i), MNormalMapConverter::RGBA, 2.0f ); } } specify(target); return true; }