예제 #1
0
파일: getmacfont.C 프로젝트: arpruss/ozdev
void process(FILE *f,long namepos,unsigned long datapos)
{
    byte name[1040];
    byte namelen;
    static int count=0;
    FILE *out;
    int i;
    unsigned long len;
    if(namepos==-1)
        sprintf(name,"%s%d.data",thename,count++);
    else
    {
        myseek(f,namepos);
        namelen=getbyte(f);
        if((int)fread(name,1,namelen,f)!=(int)namelen) err("Error reading resource name\n");
        name[namelen]=0;
        for(i=0;i<namelen;i++)
        {
            if(name[i]>126 || name[i]<32 ||
                name[i]=='\\' || name[i]=='?' || name[i]==':'
                || name[i]=='/' || name[i]=='%' || name[i]=='<'
                || name[i]=='>' || name[i]=='*' || name[i]=='"')
                name[i]='_';
        }
        strcat(name,".data");
    }
    out=myfopen(name,"wb");
    printf("Extracting: %s\n",name);
    myseek(f,datapos);
    len=getdword(f);
    while(len--)
        fputc(myfgetc(f),out);
    fclose(out);
}
예제 #2
0
/* _______________________________________________________________ */
int copy(MY_FILE* fsrc, MY_FILE* fdst) {
    int c, d;
    while ((c = myfgetc(fsrc)) != MY_EOF) {
        d = myfputc(c, fdst);
        if (d == MY_EOF)
            error("Erreur d'écriture dans le fichier destination.");
        if (d != c)
            error("Erreur: myfputc retourne une valeur inattendue.");
    }
    return 0;
}
예제 #3
0
파일: main.cpp 프로젝트: Astade/Astade
 void process(const char *ifname, const char *ofname)
 {
 	FILE *ifile, *ofile;

 	ifile = fopen(ifname, "rb");
 	if (ifile == NULL) {
 		fprintf(stderr, "cannot open %s for reading\n", ifname);
 		exit(1);
 	}
 	ofile = fopen(ofname, "w");
 	if (ofile == NULL) {
 		fprintf(stderr, "cannot open %s for writing\n", ofname);
 		exit(1);
 	}

	struct stat statbuf;
	stat(ifname, &statbuf);

 	char buf[PATH_MAX], *p;
 	const char *cp;
 	if ((cp = strrchr(ifname, '/')) != NULL)
 		++cp;
 	else if ((cp = strrchr(ifname, '\\')) != NULL)
 		++cp;
 	else
 		cp = ifname;
 	strcpy(buf, cp);
 	for (p = buf; *p != '\0'; ++p)
 		if (!isalnum(*p))
 			*p = '_';
 	fprintf(ofile, "static %sunsigned char %s[] = {\n", useconst ? "const " : "", buf);
 	int c, col = 1;
 	while ((c = myfgetc(ifile)) != EOF) {
 		if (col >= 78 - 6) {
 			fputc('\n', ofile);
 			col = 1;
 		}
 		fprintf(ofile, "0x%.2x, ", c);
 		col += 6;

 	}
 	fprintf(ofile, "\n};\n");

 	fclose(ifile);
 	fclose(ofile);

	struct utimbuf times;
	times.actime  = statbuf.st_mtime;
	times.modtime = statbuf.st_mtime;
	utime(ofname, &times);
 }
예제 #4
0
파일: bin2c.c 프로젝트: Kassen/chugins
void process(const char *ifname, const char *ofname)
{
    FILE *ifile, *ofile;
    ifile = fopen(ifname, "rb");
    if (ifile == NULL) {
        fprintf(stderr, "cannot open %s for reading\n", ifname);
        exit(1);
    }
//    ofile = fopen(ofname, "wb");
//    if (ofile == NULL) {
//        fprintf(stderr, "cannot open %s for writing\n", ofname);
//        exit(1);
//    }
    ofile = stdout;
    char buf[PATH_MAX], *p;
    const char *cp;
    if ((cp = strrchr(ifname, '/')) != NULL)
        ++cp;
    else {
        if ((cp = strrchr(ifname, '\\')) != NULL)
            ++cp;
        else
            cp = ifname;
    }
    strcpy(buf, cp);
    for (p = buf; *p != '\0'; ++p)
        if (!isalnum(*p))
            *p = '_';
    fprintf(ofile, "const unsigned char %s[] = \n{\n",
            buf);
    int c, col = 1;
    size_t nBytes = 0;
    while ((c = myfgetc(ifile)) != EOF) {
        if (col >= 78 - 6) {
            fputc('\n', ofile);
            col = 1;
        }
        fprintf(ofile, "0x%.2x, ", c);
        nBytes++;
        col += 6;
        
    }
    fprintf(ofile, "\n};\n");
    fprintf(ofile, "const size_t %s_length = %zu;\n\n",
            buf, nBytes);
    
    fclose(ifile);
    fclose(ofile);
}
예제 #5
0
파일: NLCEI14.C 프로젝트: jbailhache/log
int mygetchar2 ()
{
int c;

debut:
	if (file_level <= 0)
		c = mygetchar1 ();
	else
	{
		c = myfgetc (files+file_level);
		if (c == EOF)
		{
			myclose (files+file_level);
			file_level--;
			goto debut;
		}
	}
	return c;
}
예제 #6
0
bool Cce152::GetWav(void)
{
	if (mode != PLAY) return false;			// Return 0 If not PLAY mode

    if (first_state == 0) {
        counter = 1;
        first_state = pTIMER->state;
    }

	// Calculate nb of byte to skip corresponding to the CPU frequency
    qint64 wait =  (pTIMER->pPC->getfrequency() / info.freq);
    //qint64 delta = (pTIMER->state - first_state);
    while ((pTIMER->state - first_state) >= wait) {
		GetWav_Val = myfgetc(&info);
        fprintf(fp_tape,
                "delta=%lld val=%s c=%i c=%lld\n",
                (pTIMER->state - first_state),
                (GetWav_Val>0x10)?"1":"0",GetWav_Val,counter);
		counter++;
        first_state +=wait;
	}

	return ((GetWav_Val>0x10)?true:false);
}
예제 #7
0
void process(const char *ifname, const char *ofname)
{
  FILE *ifile, *ocfile, *ohfile;
  char buf[PATH_MAX+1], *p;
  char obasename[PATH_MAX+1];
  char ocname[PATH_MAX+1];
  char ohname[PATH_MAX+1];
  const char *cp;
  size_t len;

  ocfile = NULL;
  ohfile = NULL;

  /* Error check */
  if ( !ifname || !ofname ) {
    fprintf(stderr, "process has NULL filename\n");
    exit(1);
  }

  strncpy( obasename, ofname, PATH_MAX );
  len = strnlen( obasename, PATH_MAX );
  if ( len >= 2 ) {
    if ( obasename[len-2] == '.' ) {
      if ( (obasename[len-1] == 'c') || (obasename[len-1] == 'h') )
        obasename[len-2] = '\0';
    }
  }

  sprintf( ocname, "%s.c", obasename );
  sprintf( ohname, "%s.h", obasename );

  if ( verbose ) {
    fprintf(
      stderr,
      "in file: %s\n"
      "c file: %s\n"
      "h file: %s\n",
      ifname,
      ocname,
      ohname
    );
  }

  /* Open input and output files */
  ifile = fopen(ifname, "rb");
  if (ifile == NULL) {
    fprintf(stderr, "cannot open %s for reading\n", ifname);
    exit(1);
  }

  if ( createC ) {
    ocfile = fopen(ocname, "wb");
    if (ocfile == NULL) {
      fprintf(stderr, "cannot open %s for writing\n", ocname);
      exit(1);
    }
  }

  if ( createH ) {
    ohfile = fopen(ohname, "wb");
    if (ohfile == NULL) {
      fprintf(stderr, "cannot open %s for writing\n", ohname);
      exit(1);
    }
  }

  /* find basename */
  char *ifbasename_to_free = strdup(ifname);
  if ( ifbasename_to_free == NULL ) {
    fprintf(stderr, "cannot allocate memory\n" );
    fclose(ifile);
    if ( createC ) { fclose(ocfile); }
    if ( createH ) { fclose(ohfile); }
    exit(1);
  }

  char *ifbasename;
  ifbasename = basename(ifbasename_to_free);

  strcpy(buf, ifbasename);
  for (p = buf; *p != '\0'; ++p) {
    if (!isalnum((unsigned char)*p)) /* cast to avoid negative indexing */
      *p = '_';
  }

  if ( createC ) {
    /* print C file header */
    fprintf(
      ocfile,
      "/*\n"
      " *  Declarations for C structure representing binary file %s\n"
      " *\n"
      " *  WARNING: Automatically generated -- do not edit!\n"
      " */\n"
      "\n"
      "#include <sys/types.h>\n"
      "\n",
      ifbasename
    );

    /* print structure */
    fprintf(
      ocfile,
      "%s%sunsigned char %s[] = {\n  ",
      ((usestatic) ? "static " : ""),
      ((useconst) ? "const " : ""),
      buf
    );
    int c, col = 1;
    while ((c = myfgetc(ifile)) != EOF) {
      if (col >= 78 - 6) {
        fprintf(ocfile, "\n  ");
        col = 1;
      }
      fprintf(ocfile, "0x%.2x, ", c);
      col += 6;

    }
    fprintf(ocfile, "\n};\n");

    /* print sizeof */
    fprintf(
      ocfile,
      "\n"
      "%s%ssize_t %s_size = sizeof(%s);\n",
      ((usestatic) ? "static " : ""),
      ((useconst) ? "const " : ""),
      buf,
      buf
    );
  } /* createC */

  /*****************************************************************/
  /******                    END OF C FILE                     *****/
  /*****************************************************************/

  if ( createH ) {
    /* print H file header */
    char hbasename[PATH_MAX];
    char* p;
    /* Clean up the file name if it is an abs path */
    strcpy(
      hbasename,
      obasename
    );
    p = hbasename;
    while (*p != '\0') {
      if (*p < '0' || *p > 'z')
        *p = '_';
      ++p;
    }
    fprintf(
      ohfile,
      "/*\n"
      " *  Extern declarations for C structure representing binary file %s\n"
      " *\n"
      " *  WARNING: Automatically generated -- do not edit!\n"
      " */\n"
      "\n"
      "#ifndef __%s_h\n"
      "#define __%s_h\n"
      "\n"
      "#include <sys/types.h>\n"
      "\n",
      ifbasename,  /* header */
      hbasename,  /* ifndef */
      hbasename   /* define */
    );

    /* print structure */
    fprintf(
      ohfile,
      "extern %s%sunsigned char %s[];",
      ((usestatic) ? "static " : ""),
      ((useconst) ? "const " : ""),
      buf
    );
    /* print sizeof */
    fprintf(
      ohfile,
      "\n"
      "extern %s%ssize_t %s_size;\n",
      ((usestatic) ? "static " : ""),
      ((useconst) ? "const " : ""),
      buf
    );

    fprintf(
      ohfile,
      "\n"
      "#endif\n"
    );
  } /* createH */

  /*****************************************************************/
  /******                    END OF H FILE                     *****/
  /*****************************************************************/

  fclose(ifile);
  if ( createC ) { fclose(ocfile); }
  if ( createH ) { fclose(ohfile); }
  free(ifbasename_to_free);
}