コード例 #1
0
ファイル: path.c プロジェクト: seem8/friendup
Path* PathNew( const char* path )
{
	if( !path ) return NULL;
	
	Path* p = (Path*) calloc( 1, sizeof( Path ) );
	if( p == NULL )
	{
		ERROR("[PathNew] Cannot allocate memory for path\n");
		return NULL;
	}

	int len = strlen( path );
	if( len > 0 )
	{
		//DEBUG( "[PathNew] Here it is: %d\n", len );
		p->raw = calloc( len + 1, sizeof( char ) );
		p->p_CopyRaw = calloc( len + 1, sizeof( char ) );
		memcpy( p->raw, path, len );
		memcpy( p->p_CopyRaw, path, len );
		p->rawSize = len;
		PathSplit( p );

		// If we have a file segment
		if( path[ p->rawSize - 1 ] != '/' && p->size >= 1 )
		{
			p->file = p->parts[p->size - 1];
			p->extension = strrchr( p->file, '.' );
			if( p->extension )
			{
				p->extension++;
			}
		}
	}
	else
	{
		//DEBUG( "[PathNew] It is nothing.\n" );
		p->raw = NULL;
		p->rawSize = 0;
		p->file = NULL;
		p->extension = 0;
	}

	// Update the raw path (Double slashes, etc will be removed from the raw string);
	PathMake( p );

	return p;
}
コード例 #2
0
ファイル: sdd1.cpp プロジェクト: dtzWill/supernes
static int S9xGetSDD1Dir(char * packdir)
{
	char dir[_MAX_DIR + 1];
	char drive[_MAX_DRIVE + 1];
	char name[_MAX_FNAME + 1];
	char ext[_MAX_EXT + 1];

	PathSplit(S9xGetFilename(FILE_ROM), drive, dir, name, ext);

	if (strncmp(Memory.ROMName, "Star Ocean", 10) == 0) {
        PathMake(packdir, drive, dir, "socnsdd1", 0);
        return 1;
	} else if(strncmp(Memory.ROMName, "STREET FIGHTER ALPHA2", 21) == 0) {
		PathMake(packdir, drive, dir, "sfa2sdd1", 0);
		return 1;
	} else {
		S9xMessage(S9X_WARNING, S9X_ROM_INFO,
			"WARNING: No default SDD1 pack for this ROM");
		return 0;
	}
}
コード例 #3
0
//----------------------------------
//  'User Function' private: FileOpen
//----------------------------------
PAPSZ ProjWin::FileOpen(void)
{
    static char Directory[MAXPATHSIZE];
    /*****************************************************************/
    /* Initially set all fields to 0                                 */
    /*****************************************************************/
    static FILEDLG fild;                                    // File dialog info structure
    char pszFullFile[CCHMAXPATH];
    strcpy(pszFullFile,Directory);
    strcat(pszFullFile,"*.c*;*.h*;*.rc;*.inc");             // File filter string
    memset(&fild, 0, sizeof(FILEDLG));

    /*****************************************************************/
    /* Initialize those fields in the FILEDLG structure that are     */
    /* used by the application                                       */
    /*****************************************************************/
    fild.cbSize = sizeof(FILEDLG);            // Size of structure
    fild.fl = FDS_CENTER | FDS_OPEN_DIALOG |FDS_MULTIPLESEL;

                                                    // FDS_* flags
    fild.pszTitle = "Add Path/File To Project List";// Dialog title string
    strcpy(fild.szFullFile, pszFullFile);           // Initial path,
                                                    // file name, or
                                                    // file filter

    /*****************************************************************/
    /* Display the dialog and get the file                           */
    /*****************************************************************/
    HWND  hwndDlg = WinFileDlg(HWND_DESKTOP, HWindow, &fild);
    if (hwndDlg && (fild.lReturn == DID_OK))
    {
        char dummy[MAXPATHSIZE];
        PathSplit(Directory,dummy,fild.szFullFile);   // remember directory
        return( fild.papszFQFilename );
    }
    return(NULL);
}
コード例 #4
0
uint8_t    picHeader::open(char *inname)
{

uint32_t		nnum;
uint32_t		*fcc;
uint8_t			fcc_tab[4];
FILE 			*fd;
char 			*end;
uint32_t			w=0,h=0;

	// 1- identity the file type
	//
	fcc=(uint32_t *)fcc_tab;
	fd=fopen(inname,"rb");
	if(!fd)
		{
			printf("\n Cannot open that file!\n");
			return 0;
		}
	fread(fcc_tab,4,1,fd);
	fclose(fd);
	if(fourCC::check(*fcc,(uint8_t *)"RIFF"))
	{
		_type=PIC_BMP;
		printf("\n It looks like BMP (RIFF)...\n");
	}
	else
	{
		if(fcc_tab[0]=='B' && fcc_tab[1]=='M')
		{
			_type=PIC_BMP2;
			printf("\n It looks like BMP (BM)...\n");
		}
		else	
		if(fcc_tab[0]==0xff && fcc_tab[1]==0xd8)
		{
		 	_type=PIC_JPEG;
			printf("\n It looks like Jpg...\n");
		}
		else
		{
			printf("\n Cannot identify file (%x %x)\n",*fcc,*fcc&0xffff);
			return 0;
		}
	}

	// Then spit the name in name and extension
	char *name;
	char *extension;
	 PathSplit(inname, &name, &extension);


     	nnum=1;

     	end=name+strlen(name)-1;
     	while(( *end>='0') && (*end<='9'))
     		{
            		end--;
        	      	nnum++;
         	};
      if(nnum==1)
      	{
          	printf("\n only one file!");
          	return 0;

         }
        nnum--;
        end++;
       _first=atoi(end);
       printf("\n First : %lu, num digit :%lu",_first,nnum);
       *(end)=0;
       printf("\n Path : %s\n",name);

       char realname[250];
       char realstring[250];

            	sprintf(realstring,"%%s%%0%lud.%s",nnum,extension);
              printf("\n string : %s",realstring);

       _nb_file=0;

       for(uint32_t i=0;i<MAX_ACCEPTED_OPEN_FILE;i++)
       	{
              sprintf(realname,realstring,name,i+_first);
              printf("\n %lu : %s",i,realname);
              fd=fopen(realname,"rb");
              if(fd==NULL) break;
              fclose(fd);
              _nb_file++;
          }
	printf("\n found %lu images\n",_nb_file);


	_fd=(FILE **)ADM_alloc(_nb_file*sizeof(FILE*));
	_imgSize=new uint32_t[_nb_file];
	  //_________________________________
          // now open them and assign fd && imgSize
	  //__________________________________
          for(uint32_t i=0;i<_nb_file;i++)
          {
              sprintf(realname,realstring,name,i+_first);
              printf("\n %lu : %s",i,realname);
              _fd[i]=fopen(realname,"rb");
	      fseek(_fd[i],0,SEEK_END);
	      _imgSize[i]=ftell( _fd[i] );
		fseek(_fd[i],0,SEEK_SET);
              ADM_assert(_fd[i]!=NULL);
            }

	delete [] name;
	delete [] extension;


	//
	//	Image is bmp type
	//________________________
	switch(_type)
	{
		case PIC_BMP:
			{
			BITMAPHEADER bmph;

              		fread(&s16,2,1, _fd[0]);
              		if(s16!=0x4D42)
              		{
                		printf("\n incorrect bmp sig.\n");
              			return 0;
               		}
              		fread(&s32,4,1, _fd[0]);
              		fread(&s32,4,1, _fd[0]);
              		fread(&s32,4,1, _fd[0]);
               		fread(&bmph, sizeof(bmph), 1, _fd[0]);
               		if(bmph.compressionScheme!=0)
               		{
                 		printf("\ncannot handle compressed bmp\n");
	               		return 0;
                	}
              		_offset=bmph.size+14;
			w=bmph.width ;
			h=bmph.height ;
			}
			break;
	

		 // Jpeg : Grab the size
		//____________________
		case PIC_JPEG:
			{
			uint16_t tag=0,count=0,off;

			_offset=0;
			fseek(_fd[0],0,SEEK_SET);
			read16(_fd[0]); // skip jpeg ffd8
			while(count<10 && tag!=0xFFC0)
			{

				tag=read16(_fd[0]);
				if( (tag >>8 ) !=0xff)
				{
					printf("invalid jpeg tag found (%x)\n",tag);
				}
				if(tag==0xFFC0)
				{
					read16(_fd[0]); // size
					read8(_fd[0]);  // precision
					h=read16(_fd[0]);
					w=read16(_fd[0]);
				}
				else
				{

					off=read16(_fd[0]);
					if(off<2)
						{
							printf("Offset too short!\n");
							return 0;
						}
					aprintf("Found tag : %x , jumping %d bytes\n",tag,off);
					fseek(_fd[0],off-2,SEEK_CUR);
				}
				count++;
			}
			if(tag!=0xffc0)
			{
				printf("Cannot fint start of frame\n");
				return 0;
			}
			printf("\n %lu x %lu..\n",w,h);
			}
			break;

		case PIC_BMP2:
			{
			BITMAPINFOHEADER bmph;

			fseek(_fd[0],10,SEEK_SET);

			#define MK32() (fcc_tab[0]+(fcc_tab[1]<<8)+(fcc_tab[2]<<16)+ \
						(fcc_tab[3]<<24))

              		fread(fcc_tab,4,1, _fd[0]);
              		_offset=MK32();
			// size, width height follow as int32 
               		fread(&bmph, sizeof(bmph), 1, _fd[0]);
#ifdef ADM_BIG_ENDIAN
			Endian_BitMapInfo(&bmph);	
#endif
               		if(bmph.biCompression!=0)
               		{
                 		printf("\ncannot handle compressed bmp\n");
	               		return 0;
                	}
			w=bmph.biWidth ;
			h=bmph.biHeight ;
			printf("W: %d H: %d offset : %d\n",w,h,_offset);
			}
	
			break;
		default:
			ADM_assert(0);
		}

//_______________________________________
//		Now build header info
//_______________________________________
	      _isaudiopresent=0; // Remove audio ATM
              _isvideopresent=1; // Remove audio ATM

#define CLR(x)              memset(& x,0,sizeof(  x));

               CLR( _videostream);
               CLR(  _mainaviheader);

    			_videostream.dwScale=1;
              _videostream.dwRate=25;
              _mainaviheader.dwMicroSecPerFrame=40000;;     // 25 fps hard coded
              _videostream.fccType=fourCC::get((uint8_t *)"vids");

               _video_bih.biBitCount=24;

              _videostream.dwLength= _mainaviheader.dwTotalFrames=_nb_file;
               _videostream.dwInitialFrames= 0;
               _videostream.dwStart= 0;
               //
               //_video_bih.biCompression= 24;
               //
               _video_bih.biWidth=_mainaviheader.dwWidth		=w ;
               _video_bih.biHeight=_mainaviheader.dwHeight	=h;
               //_video_bih.biPlanes= 24;

	         if(PIC_JPEG==_type)
		 {
			          _video_bih.biCompression=_videostream.fccHandler=fourCC::get((uint8_t *)"MJPG");;
		 }
		 else
		 {
  				_video_bih.biCompression=_videostream.fccHandler=0;
		 }
		printf("Offset : %lu\n",_offset);
       return 1;
}
コード例 #5
0
////////////////////////////
/// GENERATE MAKE FILE !
////////////////////////////
int CreateMakeFile(char *makename, char *ResourceFile, char* ListOfFiles[], char *objdir, char *LinkSwitches)
{
    int fObjPath=FALSE;
    if(strcmp(".",objdir) != 0)
        fObjPath = TRUE;

    char FMake[MAXPATHSIZE];
    strcpy(FMake,makename);
    //
    ForceExt(FMake,".MAK");
    FILE *fMak = fopen(FMake,"wt");
    if(!fMak)
    {
        return 1;
    }

    //
    char FCfg[MAXPATHSIZE];
    strcpy(FCfg,FMake);
    ForceExt(FCfg,".CFG");

    char *commentdash = "#=============================================================\n";
    char *commentline = "#\n";
    char buf[128+1];
    fprintf(fMak,commentdash);
    fprintf(fMak,commentline);
    fprintf(fMak,"#   %s  MakeFile Generated by %s\n",FMake,PROFESSOR_OWL_VERSION);
    ExpandDollar("$TIME",buf,"");
    fprintf(fMak,"#       Created on %s\n",buf);
    fprintf(fMak,commentline);
    fprintf(fMak,"%s\n",commentdash);
    fprintf(fMak,".AUTODEPEND\n\n");

    if(fObjPath)
    {
        fprintf(fMak,"# OBJ Files Are Located In Another Directory\n");
        fprintf(fMak,"OBJ_DIR = %s\n",objdir);
        fprintf(fMak,".PATH.obj = $(OBJ_DIR)\n\n");
    }

    fprintf(fMak,commentdash);
    fprintf(fMak,"#       Translator Definitions\n");
    fprintf(fMak,commentdash);
    fprintf(fMak,"CC = bcc +%s\n",FCfg);
    fprintf(fMak,"TASM = tasm\n");
    fprintf(fMak,"TLIB = tlib\n");
    fprintf(fMak,"TLINK = tlink\n");
    fprintf(fMak,"RC = brcc.exe\n");
    char LibPath[128+1];
    strcpy(LibPath,UserSetup.IncludePath);
    strupr(LibPath);
    char *p = strstr(LibPath,"\\INCLUDE");
    if(p)
    {
        strcpy(p,"\\LIB");
    }
    else
    {
        strcpy(LibPath,"C:\\BCOS2\\LIB");
    }
    fprintf(fMak,"LIBPATH = %s\n",LibPath);
    fprintf(fMak,"INCLUDEPATH = %s\n\n\n",UserSetup.IncludePath);
    fprintf(fMak,commentdash);
    fprintf(fMak,"#       Implicit Rules\n");
    fprintf(fMak,commentdash);
    fprintf(fMak,".c.obj:\n");
    fprintf(fMak,"  $(CC) -c {$< }\n");
    fprintf(fMak,"\n");
    fprintf(fMak,".cpp.obj:\n");
    fprintf(fMak,"  $(CC) -c {$< }\n");
    fprintf(fMak,"\n");
    fprintf(fMak,".asm.obj:\n");
    fprintf(fMak,"  $(TASM) -Mx $*.asm,$*.obj\n");
    fprintf(fMak,"\n");
    fprintf(fMak,".rc.res:\n");
    fprintf(fMak,"  $(RC) -r $*.rc\n");
    fprintf(fMak,"\n");
    fprintf(fMak,commentdash);
    fprintf(fMak,"#       List Macros\n");
    fprintf(fMak,commentdash);
    /////////////////////////////
    ForceExt(ResourceFile,"");
    fprintf(fMak,"LINK_EXCLUDE = \\\n %s.RES\n\n",ResourceFile);
    fprintf(fMak,"LINK_INCLUDE = \\\n");
    //
    for(int index=0; ListOfFiles[index]!= NULL; index++)
    {
        char ss[MAXPATHSIZE];
        strcpy(ss,ListOfFiles[index]);
        ForceExt(ss,".OBJ");
        fprintf(fMak," %s",ss,objdir);
        if(ListOfFiles[index+1] != NULL)
            fprintf(fMak," \\\n");
    }
    fprintf(fMak,"\n\n");
    /////////////////////////////
    fprintf(fMak,commentdash);
    fprintf(fMak,"#       Explicit Rules\n");
    fprintf(fMak,commentdash);
    ForceExt(FMake,"");
    fprintf(fMak,"%s.exe: %s.cfg $(LINK_INCLUDE) $(LINK_EXCLUDE)\n",FMake,FMake);
    fprintf(fMak,"  $(TLINK) %s /L$(LIBPATH) @&&|\n",LinkSwitches);
    fprintf(fMak,"%s\\C02.OBJ+\n",LibPath);
    //
    for(index=0; ListOfFiles[index]!= NULL; index++)
    {
        char s[MAXPATHSIZE];
        strcpy(s,ListOfFiles[index]);
        ForceExt(s,".OBJ");

        if(fObjPath)
        {
            char sp[MAXPATHSIZE];
            char sf[MAXPATHSIZE];
            PathSplit(sp,sf,s);
            fprintf(fMak,"$(OBJ_DIR)\\%s",sf); // macro path & file name
        }
        else
        {
            fprintf(fMak,"%s",s);       // path/filename.obj
        }
        if(ListOfFiles[index+1] != NULL)
            fprintf(fMak,"+\n");
        else
            fprintf(fMak,"\n");
    }
    fprintf(fMak,"%s,%s\n",FMake,FMake);
    fprintf(fMak,"$(LIBPATH)\\BIDS2.LIB+\n");
    fprintf(fMak,"$(LIBPATH)\\OWLPM.LIB+\n");
    fprintf(fMak,"$(LIBPATH)\\C2MT.LIB+\n");
    fprintf(fMak,"$(LIBPATH)\\OS2.LIB\n");
    fprintf(fMak,"\n");
    fprintf(fMak,"|\n");
    fprintf(fMak,"  RC.EXE %s.RES %s.exe\n\n",ResourceFile,FMake);
    /////////////////////////////
    fprintf(fMak,commentdash);
    fprintf(fMak,"#       Individual File Dependencies\n");
    fprintf(fMak,commentdash);
    fprintf(fMak,"%s.RES: %s.cfg %s.RC\n",ResourceFile,FMake,ResourceFile);
    fprintf(fMak,"    $(RC) -R -I$(INCLUDEPATH) -FO %s.RES %s.RC\n\n",ResourceFile,ResourceFile);
    //
    //
    for(index=0; ListOfFiles[index]!= NULL; index++)
    {
        char s[MAXPATHSIZE];
        strcpy(s,ListOfFiles[index]);
        ForceExt(s,"");
        fprintf(fMak,"%s.obj: %s.cfg %s.cpp\n\n",s,FMake,s);
    }
    /////////////////////////////
    fprintf(fMak,commentdash);
    fprintf(fMak,"#       Compiler Configuration File\n");
    fprintf(fMak,commentdash);
    fprintf(fMak,"%s.cfg: %s.mak\n",FMake,FMake);
    fprintf(fMak,"  copy &&|\n");
    fprintf(fMak,"-R\n");
    fprintf(fMak,"-L$(LIBPATH)\n");
    fprintf(fMak,"-I$(INCLUDEPATH)\n");
    ExpandDollar("$PATH",buf,"");
    fprintf(fMak,"-H=%s\\%s.CSM\n",buf,FMake);
    fprintf(fMak,"-vi-\n");
    fprintf(fMak,"-sm\n");
    fprintf(fMak,"-y\n");
    fprintf(fMak,"-v\n");
    fprintf(fMak,"-N\n");
    if(fObjPath)
    {
        fprintf(fMak,"-n$(OBJ_DIR)\n");
    }
    fprintf(fMak,"| %s.CFG\n",FMake);
    fprintf(fMak,commentdash);
    fclose(fMak);
    ///
    return 0;
}