tHistory * historyCreate (int nSectors, int nTracks) { tHistory * h; h = myAlloc(sizeof (tHistory)); h->size = nSectors + (2 * nTracks); h->buf = myAlloc(h->size * sizeof (int)); h->ini = h->buf; h->end = h->buf; return h; }
static int ini_handler(__UNUSED__ void* userData, const char* section, const char* name, const char* value) { if (0 == strcmp(section, "ignore_classes")) { sm_put(gdata->ignore_classes, name, (void*)1); } else if (0 == strcmp(section, "ignore_referenced_by")) { char* endptr, *classname; IgnoreField* old = NULL; int v = strtol(value, &endptr, 10); int idx, nameLen; IgnoreField* newElement; if (*endptr != '\0') { alert("Error: Bad value for [%s] %s which is (%s)\n", section, name, value); return 0; } nameLen = strlen(name); for (idx = nameLen; idx >= 0 && name[idx] != '.'; idx--); if (idx < 0) { alert("Error: Cannot find class name for %s\n", name); return 0; } if (nameLen-idx == 1) { alert("Error: Cannot find field name for %s\n", name); return 0; } newElement = (IgnoreField*)myAlloc(sizeof(IgnoreField)); memset(newElement, 0, sizeof(*newElement)); newElement->fieldName = (char*)myAlloc(nameLen-idx); strcpy(newElement->fieldName, name+idx+1); classname = (char*)myAlloc(idx + 1); strncpy(classname, name, idx); classname[idx] = 0; newElement->threshold = v; debug("Parsing class name [%s], field [%s], limit %d\n", classname, newElement->fieldName, v); sm_get(gdata->ignore_referenced_by, classname, (void**)&old); newElement->next = old; sm_put(gdata->ignore_referenced_by, classname, newElement); myFree(classname); } return 1; }
/* Funcion para la lista que usa obtenerSectores() */ tSectorId * commandTosectorList (ShellCommand * c) { int i; tSectorId *buf = myAlloc(SECTORLIST_SIZE * sizeof (tSectorId)); for(i=0; (i<c->argsCount) && (i<=SECTORLIST_SIZE); i++) buf[i] = atoi(c->args[i]); return buf; }
/*! * \fn void rankCalculation(csuStruct *ptr_csu_struct) * Calculate the rank * \param[in,out] *ptr_csu_struct a pointer on a csuStruct */ void rankCalculation(csuStruct *ptr_csu_struct) { float *sort_points; int i; int j; sort_points=(float *)myAlloc(sizeof(float)*ptr_csu_struct->nb_player); for(i=0 ; i<ptr_csu_struct->nb_player ; i++) sort_points[i]=ptr_csu_struct->total_points[i]; /*Sort the points base on the first way*/ if(ptr_csu_struct->config.first_way == 1) qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatDescending); else qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatAscending); /*Loop on the sort points from the smallest*/ for(i=ptr_csu_struct->nb_player -1 ; i>=0 ; i--) { /*Loop on the total points*/ for(j=0 ; j<ptr_csu_struct->nb_player ; j++) { if (sort_points[i]==ptr_csu_struct->total_points[j]) ptr_csu_struct->rank[j]=i+1; } } free(sort_points); }
static long CopyFile( int in, int out, char *infile, char *outfile ) { unsigned size; unsigned len; unsigned bufsize; long totalsize; void *buff; buff = myAlloc( IO_BUFF ); bufsize = IO_BUFF; totalsize = 0L; for( ;; ) { size = read( in, buff, bufsize ); if( size == 0 ) { break; } if( size == -1 ) { doError( "Error reading file \"%s\"", infile ); } len = write( out, buff, size ); if( len != size ) { doError( "Error writing file \"%s\"", outfile ); } totalsize += len; if( (unsigned) size != bufsize ) { break; } } free( buff ); return( totalsize ); }
infoCHS * disk_getCHS(tDiskParm * d) { infoCHS * chs = myAlloc(sizeof(infoCHS)); chs->cilinders = d->nTracks; chs->heads = DISK_HEADS; chs->sectors = d->nSectors; return chs; }
/*! * \fn float rankAtTurn(csuStruct *ptr_csu_struct, int player_index, int turn) * Return the ranking of a player at a specific turn * \param[in] *ptr_csu_struct a pointer on a csuStruct * \param[in] player_index the index of the player * \param[in] turn she turn * \return the ranking or 0 if the game configuration is not turn based */ int rankAtTurn(csuStruct *ptr_csu_struct, int player_index, int turn) { float *sort_points; int i; int ranking; if (ptr_csu_struct->config.turn_based == 0) return 0; sort_points=(float *)myAlloc(sizeof(float)*ptr_csu_struct->nb_player); for(i=0 ; i<ptr_csu_struct->nb_player ; i++) sort_points[i]=pointsAtTurn(ptr_csu_struct,i,turn); /*Sort the points base on the first way*/ if(ptr_csu_struct->config.first_way == 1) qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatDescending); else qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatAscending); /*Loop on the sort points from the smallest*/ for(i=0 ; i<ptr_csu_struct->nb_player ; i++) { if (sort_points[i] == pointsAtTurn(ptr_csu_struct,player_index,turn)) { ranking = i+1; break; } } free(sort_points); return ranking; }
LogicalSector * sector_BuildLogical (tSectorId sid, char * content) { /* Reserva memoria */ LogicalSector * ls; //if (sectorInvalido(sid)) // return NULL; ls = myAlloc(sizeof (LogicalSector)); sector_BuildLogical_nr(ls, sid, content); return ls; }
GettingTransferSector * sector_BuildGetting(LogicalSector * ls1, LogicalSector * ls2) { GettingTransferSector * gts; if ((ls1 == NULL) || (ls2 == NULL)) return NULL; gts = myAlloc(sizeof (GettingTransferSector)); memcpy(gts->sectorContent1, ls1->sectorContent, SECTOR_SIZE); memcpy(gts->sectorContent2, ls2->sectorContent, SECTOR_SIZE); return gts; }
/*! * \fn int lastRankAtTurn(csuStruct *ptr_csu_struct, int turn) * Return the last rank at a specific turn * \param[in] *ptr_csu_struct a pointer on a csuStruct * \param[in] turn she turn * \return the last rank or 0 if the game configuration is not turn based */ int lastRankAtTurn(csuStruct *ptr_csu_struct, int turn) { float *sort_points; int i,j; int *rank; int last_rank=0; if (ptr_csu_struct->config.turn_based == 0) return 0; sort_points=(float *)myAlloc(sizeof(float)*ptr_csu_struct->nb_player); rank=(int *)myAlloc(sizeof(int)*ptr_csu_struct->nb_player); for(i=0 ; i<ptr_csu_struct->nb_player ; i++) sort_points[i]=pointsAtTurn(ptr_csu_struct,i,turn); /*Sort the points base on the first way*/ if(ptr_csu_struct->config.first_way == 1) qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatDescending); else qsort(sort_points,ptr_csu_struct->nb_player,sizeof(float),compareFloatAscending); /*Loop on the sort points from the smallest*/ for(i=ptr_csu_struct->nb_player -1 ; i>=0 ; i--) { /*Loop on the total points*/ for(j=0 ; j<ptr_csu_struct->nb_player ; j++) { if (sort_points[i]==pointsAtTurn(ptr_csu_struct,j,turn)) rank[j]=i+1; } } for (i=0 ; i<ptr_csu_struct->nb_player ; i++) { if (rank[i] > last_rank) last_rank = rank[i]; } free(sort_points); free(rank); return last_rank; }
char * sector_getFirstLastBytes(LogicalSector * ls) { char *buf = myAlloc(30 * sizeof (char)); *buf='\"'; memcpy(buf+1, ls->sectorContent, 10); strcpy_s(buf+11, 6, "\"...\""); memcpy(buf+16, ls->sectorContent + SECTOR_SIZE - 11, 10); *(buf+26)='\"'; *(buf+27)='\0'; return buf; }
/*! * \fn csuStruct *newCsuStruct(float nb_player , game_config config) * Create a new csuStruct from a game configuration and the number of player. * \param[in] nb_player the number of player * \param[in] config the game configuration */ csuStruct *newCsuStruct(float nb_player , game_config config) { csuStruct *ptr_csu_struct; int i; time_t timestamp; struct tm *t; /*Memory allocation of the structure*/ ptr_csu_struct=(csuStruct *)myAlloc(sizeof(csuStruct)); /*Copy the a few variable on the structure*/ ptr_csu_struct->size_max_name=SIZE_MAX_NAME; ptr_csu_struct->version=VERSION; ptr_csu_struct->nb_player=nb_player; ptr_csu_struct->distributor=0; ptr_csu_struct->config=config; /*Memory allocation of the number of turn*/ ptr_csu_struct->nb_turn=(float *)myAlloc(nb_player*sizeof(float*)); /*Memory allocation of the player's names*/ ptr_csu_struct->player_names=(char **)myAlloc(nb_player*sizeof(char*)); for (i=0 ; i<nb_player ; i++) ptr_csu_struct->player_names[i]=(char *)myAlloc(SIZE_MAX_NAME*sizeof(char)); /*Memory allocation of the total points and the ranking*/ ptr_csu_struct->total_points=(float *)myAlloc(nb_player*sizeof(float)); ptr_csu_struct->rank=(float *)myAlloc(nb_player*sizeof(float)); /*Memory allocation of the points*/ ptr_csu_struct->point=(float **)myAlloc(ptr_csu_struct->nb_player*sizeof(float*)); for (i=0 ; i<nb_player ; i++) ptr_csu_struct->point[i]=(float*)myAlloc(1*sizeof(float)); /*Initialization of the total points,the rank and the number of turns*/ for (i=0 ; i<nb_player ; i++) { ptr_csu_struct->total_points[i]=ptr_csu_struct->config.begin_score; ptr_csu_struct->rank[i]=1; ptr_csu_struct->nb_turn[i]=1; ptr_csu_struct->point[i][0]=ptr_csu_struct->config.begin_score; } /*Save the current date*/ timestamp = time(NULL); t = localtime(×tamp); ptr_csu_struct->year=(t->tm_year+1900); ptr_csu_struct->month=(t->tm_mon+1); ptr_csu_struct->day=(t->tm_mday); return ptr_csu_struct; }
char * search_getHistory(tSearchParm * s) { int sid; char aux[SECTOR_STRBUF]; char *str = myAlloc(SECTOR_STRBUF * s->history->size); *str = '\0'; sid = historyExtract(s->history); while (sid != -1) { _itoa_s(sid, aux, SECTOR_STRBUF, 10); strcat_s(str, SECTOR_STRBUF * s->history->size, aux ); strcat_s(str, SECTOR_STRBUF * s->history->size, ", "); sid = historyExtract(s->history); } if (strlen(str)>=2) *(str + (strlen(str)-2)) = '\0'; return str; }
char * randomBytes(int size) { int n; char * p; char * buf = myAlloc(size * sizeof (char)); p=buf; srand((unsigned)time( NULL )); while (p < (buf + size -4)) { n = rand() % 127; if ((n>=33) && (n<=126)) (*p) = (char) n; else (*p) = '-'; p++; } *p='x';p++;*p='y';p++;*p='z';p++;*p='\0'; return buf; //return "Esta es una frase para persistir, hoy es un lindo dia."; }
/*! * \fn csuStruct *copyCsuStruct(csuStruct *ptr_csu_struct) * Copy a csu structure * \param[in] *ptr_csu_struct a pointer on a csuStruct * \return a pointer on the new csu structure */ csuStruct *copyCsuStruct(csuStruct *ptr_csu_struct) { csuStruct *ptr_copy_csu_struct=(csuStruct *)myAlloc(sizeof(csuStruct)); int i; ptr_copy_csu_struct->version = ptr_csu_struct->version; ptr_copy_csu_struct->size_max_name = ptr_csu_struct->size_max_name; ptr_copy_csu_struct->day = ptr_csu_struct->day; ptr_copy_csu_struct->month = ptr_csu_struct->month; ptr_copy_csu_struct->year = ptr_csu_struct->year; ptr_copy_csu_struct->nb_player = ptr_csu_struct->nb_player; ptr_copy_csu_struct->config = ptr_csu_struct->config; ptr_copy_csu_struct->player_names=(char **)myAlloc(ptr_csu_struct->nb_player*sizeof(char*)); for (i=0 ; i<ptr_csu_struct->nb_player ; i++) { ptr_copy_csu_struct->player_names[i]=(char *)myAlloc(ptr_csu_struct->size_max_name*sizeof(char)); memcpy(ptr_copy_csu_struct->player_names[i],ptr_csu_struct->player_names[i],sizeof(char)*ptr_copy_csu_struct->size_max_name); } ptr_copy_csu_struct->total_points=(float *)myAlloc(ptr_csu_struct->nb_player*sizeof(float)); memcpy(ptr_copy_csu_struct->total_points,ptr_csu_struct->total_points,sizeof(float)*ptr_copy_csu_struct->nb_player); ptr_copy_csu_struct->rank=(float *)myAlloc(ptr_csu_struct->nb_player*sizeof(float)); memcpy(ptr_copy_csu_struct->rank,ptr_csu_struct->rank,sizeof(float)*ptr_copy_csu_struct->nb_player); ptr_copy_csu_struct->nb_turn=(float *)myAlloc(ptr_csu_struct->nb_player*sizeof(float)); memcpy(ptr_copy_csu_struct->nb_turn,ptr_csu_struct->nb_turn,sizeof(float)*ptr_copy_csu_struct->nb_player); ptr_copy_csu_struct->distributor = ptr_csu_struct->distributor; ptr_copy_csu_struct->point=(float **)myAlloc(ptr_csu_struct->nb_player*sizeof(float*)); for (i=0 ; i<ptr_csu_struct->nb_player ; i++) { ptr_copy_csu_struct->point[i]=(float *)myAlloc(ptr_csu_struct->nb_turn[i]*sizeof(float)); memcpy(ptr_copy_csu_struct->point[i],ptr_csu_struct->point[i],sizeof(float)*ptr_csu_struct->nb_turn[i]); } return ptr_copy_csu_struct; }
char * sector_getFirstLastBytes(LogicalSector * ls) { int i; char * p; char *buf = myAlloc(28 * sizeof (char)); //char buf[28]; buf[0]='\"'; p = ls->sectorContent; i = 1; while ((*p != '\0') && (i<=10)){ buf[i] = *p; i++; p++; } while (i<=10) { buf[i] = ' '; i++; } strcpy_s(buf+11, 6, "\"...\""); p = ls->sectorContent + 10; while (p < ls->sectorContent + SECTOR_SIZE - 11) { if (*p == '\0') { strcpy_s(buf+16, 12, " \""); return buf; } p++; } i=16; while ((*p != '\0') && (i<=25)){ buf[i] = *p; i++; p++; } while (i<=25) { buf[i] = ' '; i++; } buf[26]='\"'; buf[27]='\0'; return buf; }
void* operator new (size_t size) throw (std::bad_alloc) { return myAlloc(size); }
char * disk_getHeadPos_s(tDiskParm * d) { char *buf = myAlloc(6 * sizeof (char)); sprintf_s(buf, 6, "%d", disk_getHeadPos(d)); return buf; }
//########################################### // Если блоки конвертируемы один в другой, тогда имеет смысл оставить только один, // наиболее полный тип. Именно это и делает эта функция. // CPAGE_FUNC(Bool32) CPAGE_UpdateBlocks( Handle hPage, Handle type ) { PROLOG; Bool32 rc = TRUE; uint32_t size = 0; char * lpData = NULL; Handle temporaray = 0; SetReturnCode_cpage(IDS_ERR_NO); #ifdef _DEBUG _ASSERT(CPAGE_GetNameInternalType(type)); #endif SetReturnCode_cpage(IDS_ERR_NO); Handle hBlock = CPAGE_GetBlockFirst(hPage,type); if(!hBlock) { rc = TRUE; goto lOut; } // Создадим временные блоки и удалим старые. // Тем самым предотвращаем зацикливание. temporaray = CPAGE_GetInternalType("temporary"); while(hBlock) { Handle hNextBlock = CPAGE_GetBlockNext(hPage,hBlock,type);// type - запрашиваемый тип блока Handle dwType = CPAGE_GetBlockType(hPage,hBlock); // dwType - Реальный тип блока if(dwType != type) // Была произведена конвертация из типа dwType ! { uint32_t UserNum = CPAGE_GetBlockUserNum(hPage,hBlock); uint32_t Flags = CPAGE_GetBlockFlags(hPage,hBlock); if(lpData == NULL) { // Определим необходимый размер и отведем память. size = CPAGE_GetBlockData(hPage,hBlock,type,NULL,0); if(size) { lpData = (char *)myAlloc(size); if(!lpData) { rc = FALSE; SetReturnCode_cpage(IDS_ERR_NO_MEMORY); break; } } else { SetReturnCode_cpage(IDS_ERR_DISCREP); rc = FALSE; break; } } if(CPAGE_GetBlockData(hPage,hBlock,type,lpData,size)==size) { CPAGE_DeleteBlock(hPage,hBlock); if(!CPAGE_CreateBlock(hPage,temporaray, UserNum , Flags, lpData, size)) { SetReturnCode_cpage(IDS_ERR_NO_MEMORY); rc = FALSE; break; } } } hBlock = hNextBlock; } // Переименуем временные блоки if(lpData) // Проверка на существование таких блоков { myFree(lpData); for(hBlock = CPAGE_GetBlockFirst(hPage,temporaray); hBlock; hBlock = CPAGE_GetBlockNext(hPage,hBlock,temporaray)) { BLOCK_H_H(hPage,hBlock).SetType(type); } } lOut:EPILOG; return rc; }
int main( int argc, char *argv[] ) { int in, out, i, rcparm = 0, pcnt; int Rflag = FALSE, nflag = FALSE; int uflag = FALSE; int dllflag = FALSE; char *wext = NULL; long tsize = 0; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME]; char ext[_MAX_EXT]; char rex[_MAX_PATH]; char exe[_MAX_PATH]; char dll[_MAX_PATH]; char res[_MAX_PATH]; char winext[_MAX_PATH]; char rc[256]; long totalsize; const char **arglist; char *path = NULL; int currarg,len; simple_header re; long exelen; char *desc = NULL; /* * get parms */ if( argc < 2 ) { doUsage( NULL ); } currarg=1; while( currarg < argc ) { #ifdef __UNIX__ if( argv[ currarg ][0] == '-' ) { #else if( argv[ currarg ][0] == '/' || argv[ currarg ][0] == '-' ) { #endif len = strlen( argv[ currarg ] ); for( i=1; i<len; i++ ) { switch( argv[ currarg ][i] ) { case '?': doUsage( NULL ); case 'D': currarg++; desc = argv[ currarg ]; break; case 's': currarg++; wext = argv[ currarg ]; break; case 'q': quietFlag = TRUE; break; case 'u': uflag = TRUE; break; case 'n': nflag = TRUE; break; case 'd': dllflag = TRUE; break; case 'R': case 'r': Rflag=TRUE; rcparm = currarg+1; if( rcparm == argc ) { doUsage("must specify resource compiler command line" ); } break; } } if( Rflag ) { break; } } else { if( path != NULL ) { doUsage( "Only one executable may be specified" ); } path = argv[ currarg ]; } currarg++; } if( path == NULL ) { doUsage( "No executable to bind" ); } doBanner(); /* * get files to use */ _splitpath( path, drive, dir, fname, ext ); _makepath( rex, drive, dir, fname, ".rex" ); if( dllflag ) { _makepath( dll, drive, dir, fname, ".dll" ); } _makepath( exe, drive, dir, fname, ".exe" ); _makepath( res, drive, dir, fname, "" ); /* * do the unbind */ if( uflag ) { if( ext[0] == 0 ) { path = exe; } in = open( path, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", path ); } out = open( rex, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, PMODE_RWX ); if( out < 0 ) { doError( "Could not open %s", rex ); } lseek( in, MAGIC_OFFSET, SEEK_SET ); read( in, &exelen, sizeof( unsigned_32 ) ); lseek( in, exelen, SEEK_SET ); read( in, &re, sizeof( re ) ); if( re.signature != ('M' & ('Q' << 8)) ) { doError( "Not a bound Open Watcom 32-bit Windows application" ); } lseek( in, exelen, SEEK_SET ); CopyFile( in, out, path, rex ); close( in ); close( out ); myPrintf( ".rex file %s created", rex ); exit( 0 ); } if( wext == NULL ) { if( dllflag ) { FindExtender( "w386dll.ext", winext ); } else { FindExtender( "win386.ext", winext ); } } else { strcpy( winext, wext ); } if( dllflag ) { myPrintf("Loading 32-bit Windows DLL Supervisor \"%s\"\n",winext ); } else { myPrintf("Loading 32-bit Windows Supervisor \"%s\"\n",winext ); } /* * open files */ in = open( winext, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", winext ); } out = open( exe, O_CREAT | O_TRUNC|O_WRONLY | O_BINARY, PMODE_RWX ); if( out < 0 ) { doError( "Could not open %s", exe ); } /* * copy extender over */ CopyFile( in, out, winext, exe ); close( in ); close( out ); /* * run the resource compiler */ if( !nflag ) { myPrintf( "Invoking the resource compiler...\n" ); if( Rflag ) { strcpy( rc, RC_STR ); arglist = myAlloc( sizeof(char *) *(argc-rcparm +3) ); pcnt = 1; for( i=rcparm;i<argc;i++ ) { arglist[pcnt++] = argv[i]; strcat( rc," " ); strcat( rc, argv[i] ); } } else { sprintf( rc, RC_STR " %s", res ); arglist = myAlloc( sizeof(char *) * 3 ); arglist[1] = res; pcnt = 2; } arglist[0] = RC_STR; arglist[pcnt] = NULL; myPrintf( "%s\n",rc ); i = spawnvp( P_WAIT, RC_STR, arglist ); if( i == -1 ) { remove( exe ); switch( errno ) { case E2BIG: doError( "Argument list too big. Resource compiler step failed." ); break; case ENOENT: doError( "Could not find " RC_STR ".exe." ); break; case ENOMEM: doError( "Not enough memory. Resource compiler step failed." ); break; } doError( "Unknown error %d, resource compiler step failed.", errno ); } if( i != 0 ) { remove( exe ); errPrintf( "Resource compiler failed, return code = %d\n", i ); exit( i ); } } /* * copy the rex file onto the end */ in = open( rex, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", rex ); } out = open( exe, O_RDWR | O_BINARY ); if( out < 0 ) { doError( "Could not open %s", exe ); } lseek( out, 0, SEEK_END ); tsize = tell( out ); totalsize = CopyFile( in, out, rex, exe ); close( in ); /* * noodle the file: change name, and then * write the file size into the old exe header (for * use by the loader) */ lseek( out, MAGIC_OFFSET, SEEK_SET ); write( out, &tsize, sizeof( tsize ) ); len = strlen( fname ); memset( &fname[len],' ',8-len ); updateNHStuff( out, fname, desc ); close( out ); if( dllflag ) { remove( dll ); rename( exe,dll ); myPrintf("Created \"%s\" (%ld + %ld = %ld bytes)\n", dll, tsize,totalsize, tsize+totalsize ); } else { myPrintf("Created \"%s\" (%ld + %ld = %ld bytes)\n", exe, tsize,totalsize, tsize+totalsize ); } return( 0 ); } /* main */
void initAFSM_ ( surface_mesh *pm, CGMmodel model ) { int i, j, k, iLine, iSurface, iVert; int nVVert = CGM_NumVertices(model); int nLine = CGM_NumEdges(model); int nSurface = CGM_NumFaces(model); int vBegin, vEnd, iSurf, iNorm, iV_U; double tBegin, tEnd; double uMin, uMax, vMin, vMax; int bInverse, bCut, iLabel, nBoundTria=0; int nSub; int nVert; double x, y, z, u, p[3], uv[2], pmin[3], pmax[3]; int *boundVert, *vVert; double *boundT; StrucLine3 *line; StrucSurface *surface; CGMvertex vertex; CGMedge edge; CGMface face; init(pm); user3initCGM(pm); CGM_ModelBoundingBox(model, pmin, pmax); // printf("BOX:%lf %lf %lf -- %lf %lf %lf\n", pmin[0], pmin[1], pmin[2], pmax[0], pmax[1], pmax[2]); pm->S0 = (pmax[0]-pmin[0]); if (pmax[1]-pmin[1] > pm->S0) pm->S0 = pmax[1]-pmin[1]; if (pmax[2]-pmin[2] > pm->S0) pm->S0 = pmax[2]-pmin[2]; pm->S0 *= surfacesizeratio; // printf("S0: %lf\n", S0); pm->boxcx = 0.5*(pmin[0]+pmax[0]); pm->boxcy = 0.5*(pmin[1]+pmax[1]); pm->boxcz = 0.5*(pmin[2]+pmax[2]); pm->boxsize = pmax[0]-pmin[0]; if (pmax[1]-pmin[1]>pm->boxsize) pm->boxsize = pmax[1]-pmin[1]; if (pmax[2]-pmin[2]>pm->boxsize) pm->boxsize = pmax[2]-pmin[2]; vVert = (int*)myAlloc(nVVert*sizeof(int)); for (i=0; i<nVVert; i++) { vertex = CGM_ithVertex(model, i); CGM_GetVertexCoords(vertex, p); vVert[i] = pm->nPoint; addPoint(pm, p[0], p[1], p[2]); } line = (StrucLine3 *)myAlloc(2*nLine * sizeof(StrucLine3) ); for (iLine=0; iLine<nLine; iLine++) { edge = CGM_ithEdge(model, iLine); vBegin = CGM_VertexIndex(model, CGM_EdgeStartVertex(edge)); vEnd = CGM_VertexIndex(model, CGM_EdgeEndVertex(edge)); nSub = 1; line[iLine].vBegin = vBegin; line[iLine].vEnd = vEnd; line[iLine].nSub = nSub; line[iLine].sub = (StrucSub *)myAlloc(nSub * sizeof(StrucSub)); iSurf = -1; iV_U = iLine; tBegin = CGM_EdgeStartParam(edge); tEnd = CGM_EdgeEndParam(edge); line[iLine].sub[0].iSurf = iSurf; line[iLine].sub[0].iV_U = iV_U; line[iLine].sub[0].tBegin = tBegin; line[iLine].sub[0].tEnd = tEnd; } surface = (StrucSurface *)myAlloc(nSurface * sizeof(StrucSurface)); for (iSurface=0; iSurface<nSurface; iSurface++) { if (VERBOSE_CONSTRUCT) printf("Surface %d:\n", iSurface); face = CGM_ithFace(model, iSurface); i = CGM_NumEdgesInFace(face); iSurf = -1; iLabel = iSurface + 1; // bCut = -1; iNorm = 0; for (j=0; j<CGM_NumVolumes(model); j++) { k = CGM_VolumeFaceOrientation(CGM_ithVolume(model, j), face); if (VERBOSE_CONSTRUCT) printf("Surface %d, volume %d, orientation: %d\n", iSurface, j, k); if (k<0) { // printf("AniFrtCad: CGM_VolumeFaceOrientation returned %d\n", k); continue; } bCut++; iNorm = k; } if ((bCut<0) || (bCut>1)) { printf("Face #%d share %d volumes\n", iSurface, bCut+1); bCut = 0; } CGM_GetFaceParamRange(face, &uMin, &uMax, &vMin, &vMax); surface[iSurface].nLine = i; surface[iSurface].line = (int *)myAlloc(i * sizeof(int)); surface[iSurface].inverse = (int *)myAlloc(i * sizeof(int)); // printf("surface %d:\n", iSurface); for (j=0; j<i; j++) { edge = CGM_ithEdgeInFace(face, j); k = CGM_EdgeIndex(model, edge); bInverse = CGM_FaceEdgeOrientation(face, edge); if (VERBOSE_CONSTRUCT) printf("Surface %d, edge %d, orientation: %d\n", iSurface, j, bInverse); // if (bInverse < 0) { // printf("AniFrtCad: CGM_FaceEdgeOrientation returned %d\nAssuming internal edge\n", bInverse); // } // if (iNorm && bInverse==0) bInverse = 1; // if (iNorm && bInverse==1) bInverse = 0; surface[iSurface].line[j] = k; surface[iSurface].inverse[j] = bInverse; // printf("\tline %d [%c]\n", k, (bInverse==1)?'*':((bInverse==0)?' ':'?')); } surface[iSurface].iSurf = iSurf; surface[iSurface].iLabel = iLabel; surface[iSurface].bCut = bCut; surface[iSurface].iNorm = iNorm; surface[iSurface].uMin = uMin; surface[iSurface].uMax = uMax; surface[iSurface].vMin = vMin; surface[iSurface].vMax = vMax; } boundVert = (int *)myAlloc(MAX1 * sizeof(int)); boundT = (double *)myAlloc(MAX1 * sizeof(double)); for (iLine=0; iLine<nLine; iLine++) { edge = CGM_ithEdge(model, iLine); vBegin = line[iLine].vBegin; vEnd = line[iLine].vEnd; iSurf = line[iLine].sub[0].iSurf; pm->tBegin = tBegin = line[iLine].sub[0].tBegin; pm->tEnd = tEnd = line[iLine].sub[0].tEnd; iV_U = line[iLine].sub[0].iV_U; nVert = 0; boundT[nVert] = tBegin; boundVert[nVert++] = vVert[vBegin]; u = tBegin; for (j=0; ; j++) { if (nVert >= MAX1) errorExit3(4, "MAX1"); if (nextUinEdge(pm, edge, u, &u)) break; pm->vert[pm->nPoint].u = u; CGM_GetEdgeCoordsFromU(edge, u, p); x = p[0]; y = p[1]; z = p[2]; boundT[nVert] = u; boundVert[nVert++] = pm->nPoint; addPoint(pm, x, y, z); }/* for(j) */ boundT[nVert] = tEnd; boundVert[nVert++] = vVert[vEnd]; smoothingLineCGM(pm, boundVert, boundT, 0, 0, iSurf, iV_U, nVert, edge); line[iLine].nVert = nVert; line[iLine].vert = (int *)myAlloc(nVert * sizeof(int)); line[iLine].sub[0].u = (double *)myAlloc(nVert * sizeof(double)); line[iLine].sub[0].v = 0; for (j=0; j<nVert; j++) { line[iLine].vert[j] = boundVert[j]; line[iLine].sub[0].u[j] = boundT[j]; } }/* for iLine */ pm->nLinePoint = pm->nPoint; pm->maxTria = pm->maxFace; pm->v1 = (int *)myAlloc(pm->maxTria * sizeof(int)); pm->v2 = (int *)myAlloc(pm->maxTria * sizeof(int)); pm->v3 = (int *)myAlloc(pm->maxTria * sizeof(int)); pm->countCrvT = 0; pm->cbnd = (int *)myAlloc(pm->maxTria * sizeof(int)); pm->ciSurf = (int *)myAlloc(pm->maxTria * sizeof(int)); pm->cu1 = (double *)myAlloc(pm->maxTria * sizeof(double)); pm->cu2 = (double *)myAlloc(pm->maxTria * sizeof(double)); pm->cu3 = (double *)myAlloc(pm->maxTria * sizeof(double)); pm->cv1 = (double *)myAlloc(pm->maxTria * sizeof(double)); pm->cv2 = (double *)myAlloc(pm->maxTria * sizeof(double)); pm->cv3 = (double *)myAlloc(pm->maxTria * sizeof(double)); for (iSurf=0; iSurf<nSurface; iSurf++) { face = CGM_ithFace(model, iSurf); pm->nEdge = 0; nLine = surface[iSurf].nLine; iLabel = surface[iSurf].iLabel; bCut = surface[iSurf].bCut; prepTree32(pm, pm->nnEdge); pm->nTria = 0; pm->uMin = surface[iSurf].uMin; pm->uMax = surface[iSurf].uMax; pm->vMin = surface[iSurf].vMin; pm->vMax = surface[iSurf].vMax; pm->iSurf = surface[iSurf].iSurf; pm->iNorm = surface[iSurf].iNorm; pm->cgmface = face; for (iLine=0; iLine<nLine; iLine++) { i = surface[iSurf].line[iLine]; j = line[i].nSub; for (k=0; k<line[i].nVert; k++) { iVert = line[i].vert[k]; p[0] = pm->vert[iVert].x; p[1] = pm->vert[iVert].y; p[2] = pm->vert[iVert].z; CGM_GetFaceUVFromCoords(face, p, uv); pm->vert[iVert].u = uv[0]; pm->vert[iVert].v = uv[1]; // printf("Vertex %d: x=%lf, y=%lf, z=%lf, \tu=%lf, v=%lf\n", iVert, pm->vert[iVert].x, pm->vert[iVert].y, pm->vert[iVert].z, pm->vert[iVert].u, pm->vert[iVert].v); } bInverse = surface[iSurf].inverse[iLine]; makeAFLine(pm, line[i].vert, line[i].nVert, bInverse); }/*for(iLine<nLine)*/ makeTria(pm); for (i=0; i<5; i++) { smoothingSurf(pm); } nBoundTria += writeBoundCGM(pm); /* make AF for surface */ for (i=0; i<pm->nTria; i++) { addFace(pm, pm->v1[i], pm->v2[i], pm->v3[i], 0, iLabel); if (bCut) addFace(pm, pm->v1[i], pm->v3[i], pm->v2[i], 1, iLabel); } }/*for(iSurf<nSurface)*/ pm->nBoundPoint = pm->nPoint; // outBound(nBoundTria); free(boundVert); free(boundT); free(vVert); nLine = CGM_NumEdges(model); for (iLine=0; iLine<nLine; iLine++) { free(line[iLine].vert); free(line[iLine].sub[0].u); free(line[iLine].sub); } free(line); for (iLine=0; iLine<nSurface; iLine++) { free(surface[iLine].line); free(surface[iLine].inverse); } free(surface); free(pm->v1); free(pm->v2); free(pm->v3); free(pm->cbnd); free(pm->ciSurf); free(pm->cu1); free(pm->cu2); free(pm->cu3); free(pm->cv1); free(pm->cv2); free(pm->cv3); return; }
void* operator new[] ( size_t size ) { return myAlloc( size ); }
/* * ======== RMAN_freeResources ======== * Free resources held by the algorithm resource handle */ IRES_Status RMAN_freeResources(IALG_Handle alg, IRES_Fxns * resFxns, Int scratchGroupId) { short numResources; short i; size_t resDescSize; IRESMAN_Fxns * resman = NULL; IArg key; IRES_Status status = IRES_OK; IRES_ResourceDescriptor * resDesc = NULL; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_freeResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_freeResources> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(resFxns != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print3(Diags_ENTRY, "[+E] RMAN_freeResources> Enter " "(alg=0x%x, resFxns=0x%x, scratchGroupId=%d)", (IArg)alg, (IArg)resFxns, (IArg)scratchGroupId); /* * Get resource descriptors held by the algorithm */ numResources = (resFxns->numResourceDescriptors)(alg); resDescSize = numResources * sizeof(IRES_ResourceDescriptor); /* Allocate memory for algorithm's resource descriptors */ if ((resDesc = myAlloc(resDescSize, 0)) == NULL) { Log_print0(Diags_USER7, "[+7] RMAN_freeResources> Memory " "allocation failed"); status = IRES_ENOMEM; } if (status == IRES_OK) { if (IRES_OK != (resFxns->getResourceDescriptors(alg, resDesc))) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> Error " "obtaining Resource Descriptors from alg 0x%x with IRES " "interface 0x%x", (IArg)alg, (IArg)resDesc); status = IRES_ENORESOURCE; } } if (status == IRES_OK) { /* Deinit the Resources that were granted to the algorithm */ if (IRES_OK != (resFxns->deinitResources(alg, resDesc))) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> " "De-init failed on alg 0x%x IRES interface 0x%x", (IArg)alg, (IArg)resDesc); status = IRES_EALG; } for (i = 0 ; i < numResources; i++) { resman = getResman(resDesc[i].resourceName, resDesc[i].revision); if (NULL == resman) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> IRESMAN " "handle not found for resource %s version 0x%x", (IArg)(resDesc[i].resourceName), (IArg)(resDesc[i].revision)); status = IRES_ENOTFOUND; } else { /* * Call freeHandle on resman Implementation and deinit * resources held by the algorithm */ key = IGateProvider_enter(gate); status = resman->freeHandle(alg, resDesc[i].handle, &resDesc[i], scratchGroupId); IGateProvider_leave(gate, key); if (status != IRES_OK) { /* TODO: Some SYS ABORT type error here */ Log_print1(Diags_USER7, "[+7] RMAN_freeResources> Free handle failed on IRESMAN" " implementation 0x%x", (IArg)resman); status = IRES_EFAIL; } } } } //if (FALSE == freeVTableEntry((IALG_Fxns *)alg->fxns, resFxns)) { if (FALSE == freeVTableEntry((IALG_Handle )alg, resFxns)) { /* TODO: Add trace */ status = IRES_EFAIL; } if (resDesc) { myFree(resDesc, resDescSize); } Log_print1(Diags_EXIT, "[+X] RMAN_freeResources> Exit (status=%d)", (IArg)status); return (status); }
char * itoa_buf(int n) { char * buf = myAlloc(SECTOR_STRBUF * sizeof (char)); _itoa_s(n, buf, SECTOR_STRBUF, 10); return buf; }
/* * ======== RMAN_assignResources ======== * Assign resources to the algorithm indicated by alg. The resource * requirements can be determined by using the IRES_Fxns implementation */ IRES_Status RMAN_assignResources(IALG_Handle alg, IRES_Fxns * resFxns, Int scratchGroupId) { Int numResources; Int k; Int n = 0; size_t resDescSize; IRESMAN_Fxns * resman = NULL; IRES_Status status = IRES_OK; IRES_Status freeStatus = IRES_OK; IRES_Status algStatus = IRES_OK; IRES_YieldFxn yieldFxn = NULL; IRES_YieldArgs * yieldArgs = NULL; IRES_ResourceDescriptor * resDesc = NULL; IArg key; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_assignResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_assignResources> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(resFxns != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print3(Diags_ENTRY, "[+E] RMAN_assignResources> " "Enter (alg=0x%x, resFxns=0x%x, scratchGroupId=%d)", (IArg)alg, (IArg)resFxns, (IArg)scratchGroupId); /* * Get resource requirements of the algorithm */ numResources = (resFxns->numResourceDescriptors)(alg); resDescSize = numResources * sizeof(IRES_ResourceDescriptor); /* Allocate memory to hold algorithm's resource descriptors */ if ((resDesc = myAlloc(resDescSize, 0)) == NULL) { Log_print1(Diags_USER7, "[+7] RMAN_assignResources> " "Could not allocate memory size 0x%x in space " "IALG_EXTERNAL of type IALG_PERSIST", (IArg)resDescSize); Log_print0(Diags_EXIT, "[+X] RMAN_assignResources> " "Exit (status=IRES_ENOMEM)"); return (IRES_ENOMEM); } algStatus = resFxns->getResourceDescriptors(alg, resDesc); if (algStatus != IRES_OK) { Log_print3(Diags_USER7, "[+7] RMAN_assignResources> Error obtaining " "Resource Descriptors [status: %d] from alg 0x%x, " "IRES interface 0x%x", (IArg)algStatus, (IArg)alg, (IArg)resDesc); status = IRES_EALG; } if (status == IRES_OK) { /* For each requested resource */ for (n = 0 ; n < numResources; n++) { /* If someone populated the resource descriptor improperly, bail */ if ((resDesc[n].resourceName == NULL) || (resDesc[n].revision == NULL)) { Log_print0(Diags_USER7, "[+7] RMAN_assignResources> " "Resource protocol and/or version were NULL. " "Most likely an issue with the algorithm's " "getResourceRequestDescriptor implementation."); status = IRES_EALG; break; } resman = getResman(resDesc[n].resourceName, resDesc[n].revision); if (resman != NULL) { /* * Call getHandle on the IRESMAN implementation using * the protocolArgs extracted. */ Log_print1(Diags_USER2, "[+2] RMAN_assignResources> Call " "getHandle on the IRESMAN implementation 0x%x", (IArg)resman); /* Acquire lock */ key = IGateProvider_enter(gate); resDesc[n].handle = resman->getHandle(alg, &resDesc[n], scratchGroupId, &status); /* Release lock */ IGateProvider_leave(gate, key); if (IRES_OK != status) { break; } } else { Log_print2(Diags_USER7, "[+7] RMAN_assignResources> " "Resource protocol %s and version 0x%x didn't match " "any registered protocol.", (IArg)(resDesc[n].resourceName), (IArg)(resDesc[n].revision)); status = IRES_ENOTFOUND; break; } } } /* n = number of resources allocated */ /* * Return those handles to IALG using the appropriate IRES call */ if (IRES_OK == status) { if ((RMAN_PARAMS.yieldFxn != NULL) && (ti_sdo_fc_rman_RMAN_setYieldArgs != NULL)) { yieldFxn = RMAN_PARAMS.yieldFxn; yieldArgs = ti_sdo_fc_rman_RMAN_setYieldArgs(scratchGroupId, RMAN_PARAMS.yieldSamePriority); } /* Acquire lock */ key = IGateProvider_enter(gate); algStatus = resFxns->initResources(alg, resDesc, yieldFxn, yieldArgs); /* Release lock */ IGateProvider_leave(gate, key); if (algStatus != IRES_OK) { Log_print1(Diags_USER7, "[+7] RMAN_assignResources> " "resFxns->initResources() failed [%d]", (IArg)algStatus); status = IRES_EALG; } } if (status != IRES_OK) { /* * Error somewhere in initialization of resource handles * Free all allocated handles. */ for (k = 0; k < n; k++) { resman = getResman(resDesc[k].resourceName, resDesc[k].revision); if (NULL == resman) { /* Resource table is messed up - bail out */ Log_print2(Diags_USER7, "[+7] RMAN_assignResources> Could " "not find IRESMAN matching resource %s version 0x%x", (IArg)(resDesc[k].resourceName), (IArg)(resDesc[k].revision)); status = IRES_EFAIL; break; } /* Acquire lock */ key = IGateProvider_enter(gate); freeStatus = resman->freeHandle(alg, resDesc[k].handle, &resDesc[k], scratchGroupId); /* Release lock */ IGateProvider_leave(gate, key); if (freeStatus != IRES_OK) { /* * If we can't free the resource handle, something is really * messed up. Don't try to free anything else. */ status = IRES_EFAIL; Log_print2(Diags_USER7, "[+7] RMAN_assignResources> Free " "handle failed [%d] on IRESMAN implementation 0x%x", (IArg)status, (IArg)resman); break; } } } else { /* Status is OKAY, add entry to table */ /* if (FALSE == addVTableEntry((IALG_Fxns *)alg->fxns, resFxns)) { */ if (FALSE == addVTableEntry((IALG_Handle)alg, resFxns)) { /* TODO: Add trace */ status = IRES_EFAIL; RMAN_freeResources(alg, resFxns, scratchGroupId); } } if (resDesc) { myFree(resDesc, resDescSize); } Log_print1(Diags_EXIT, "[+X] RMAN_assignResources> Exit (status=%d)", (IArg)status); return (status); }