Esempio n. 1
0
ymbool	CYmMusic::ymDecode(void)
 {
 ymu8 *pUD;
 ymu8	*ptr;
 ymint skip;
 ymint i;
 ymu32 sampleSize;
 yms32 tmp;
 ymu32 id;
 

		id = ReadBigEndian32((unsigned char*)pBigMalloc);
		switch (id)
		{
			case e_YM2a://'YM2!':		// MADMAX specific.
				songType = YM_V2;
				nbFrame = (fileSize-4)/14;
				loopFrame = 0;
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("Converted by Leonard.");
				pSongType = mstrdup("YM 2");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM3a://'YM3!':		// Standart YM-Atari format.
				songType = YM_V3;
				nbFrame = (fileSize-4)/14;
				loopFrame = 0;
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("");
				pSongType = mstrdup("YM 3");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM3b://'YM3b':		// Standart YM-Atari format + Loop info.
				pUD = (ymu8*)(pBigMalloc+fileSize-4);
				songType = YM_V3;
				nbFrame = (fileSize-4)/14;
				loopFrame = ReadLittleEndian32(pUD);
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("");
				pSongType = mstrdup("YM 3b (loop)");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM4a://'YM4!':		// Extended ATARI format.
				setLastError("No more YM4! support. Use YM5! format.");
				return YMFALSE;
				break;

			case e_YM5a://'YM5!':		// Extended YM2149 format, all machines.
			case e_YM6a://'YM6!':		// Extended YM2149 format, all machines.
				if (strncmp((const char*)(pBigMalloc+4),"LeOnArD!",8))
				{
					setLastError("Not a valid YM format !");
					return YMFALSE;
				}
				ptr = pBigMalloc+12;
				nbFrame = readMotorolaDword(&ptr);
				setAttrib( readMotorolaDword(&ptr) | A_TIMECONTROL);
				nbDrum = readMotorolaWord(&ptr);
				ymChip.setClock(readMotorolaDword(&ptr));
				setPlayerRate(readMotorolaWord(&ptr));
				loopFrame = readMotorolaDword(&ptr);
				skip = readMotorolaWord(&ptr);
				ptr += skip;
				if (nbDrum>0)
				{
					pDrumTab=(digiDrum_t*)malloc(nbDrum*sizeof(digiDrum_t));
					for (i=0;i<nbDrum;i++)
					{
						pDrumTab[i].size = readMotorolaDword(&ptr);
						if (pDrumTab[i].size)
						{
							pDrumTab[i].pData = (ymu8*)malloc(pDrumTab[i].size);
							memcpy(pDrumTab[i].pData,ptr,pDrumTab[i].size);
							if (attrib&A_DRUM4BITS)
							{
								ymu32 j;
								ymu8 *pw = pDrumTab[i].pData;
								for (j=0;j<pDrumTab[i].size;j++)
								{
									*pw = ymVolumeTable[(*pw)&15]>>7;
									pw++;
								}
							}
							ptr += pDrumTab[i].size;
						}
						else
						{
Esempio n. 2
0
data_item *InitParams(char *params) {

  data_item *d = new data_item;

  InitRestore(NULL, params);   
    
  // get message      
  char *str = RestoreStr();
  if (!lstrcmp(str, "global"))
  {
    d->state_type = STATE_GLOBAL;
    d->state = NULL;
  }
  else if (!lstrcmp(str, "new"))
  {
    d->state_type = STATE_NEW;
    d->state = NULL;
  }
  else
  {
    d->state_type = STATE_REUSE;
    d->state = new_state();
  }

  str = RestoreStr();
  if (str)
  {
    d->script = findfile(str);
  }
  else
  {
    d->script = NULL;
  }

  int i=0;

  str = RestoreStr();
  if (str)
  {
    d->command = mstrdup(str);
  }
  else
  {
    d->command = NULL;
  }

  str = RestoreStr();
  if (str)
  {
    d->args = mstrdup(str);
  }
  else
  {
    d->args = NULL;
  }


  EndRestore();

  return d;
}
Esempio n. 3
0
int GetScriptDetails(char *szFileName, s_commandData **pCmdData)
{
  if (!szFileName) return 0;

  int iCmdData = NULL;

  FILE *pFile;
  pFile = fopen (szFileName, "r");

  if (pFile != NULL)
  {
    char szLine[1024+1];
    BOOL bInitLine;

    do
    {
      fgets (szLine, 1024, pFile);
      char *c = szLine;

      // strip off any trailing newline characters
      while ( *c && '\n' != *c && '\r' != *c) c++;
      if (*c) *c = '\0';

      if( StrStartsWith(szLine, "--!SI:") )
      {
        bInitLine = TRUE;
        char *szArgsDesc = NULL;
        char *szCmdName = NULL;
        char *szCmdData = NULL;

        char *szData = szLine + lstrlen("--!SI:");

        // check for @ArgsDescription
        if (*szData == '@')
        {
          szArgsDesc = szData + 1;

          szCmdName = strchr(szArgsDesc, ':');
          if ( szCmdName )
          {
            *szCmdName = 0;
            szCmdName++;
          }
        }
        else
          szCmdName = szData;

        // check for Name:Command
        szCmdData = strchr(szCmdName, ':');
        if ( szCmdData )
        {
          *szCmdData='\0'; // null terminate the 'data'
          szCmdData++; // skip past the ':'
          
          pCmdData[iCmdData] = new s_commandData;
          pCmdData[iCmdData]->bHasArgs = (szArgsDesc != NULL);
          pCmdData[iCmdData]->szArgsDesc = mstrdup(szArgsDesc);
          pCmdData[iCmdData]->szCmdData = mstrdup(szCmdData);
          pCmdData[iCmdData]->szCmdName = mstrdup(szCmdName);

          iCmdData++;
        }
        
      }
      else
      {
        bInitLine = FALSE;
      }
    } while(bInitLine);

    fclose (pFile);
  }

  return iCmdData;
}
Esempio n. 4
0
File: fcc.c Progetto: 8l/FUZIX
static void build_command(void)
{
  char buf[128];

  add_argument("sdcc");
  /* Set up the basic parameters we will inflict on the user */
  add_argument("--std-c99");
  add_option("-m", cpu?cpu:"z80");
  if (mode == MODE_LINK) {
    add_argument("--no-std-crt0");
    add_argument("--nostdlib");
    add_argument("--code-loc");
    snprintf(buf, sizeof(buf), "%d", progbase);
    add_argument(mstrdup(buf));
    add_argument("--data-loc");
    add_argument("0x0");
  }
  /* Parse the specials */
  if (pedantic == 0)
    add_argument("--less-pedantic");
  if (werror == 1)
    add_argument("--Werror");
  if (unschar == 1)
    add_argument("-funsigned-char");
  if (debug == 1)
    add_argument("--debug");
  /* Turn -O1/2/3/4 into something meaningful */
  if (opt != NULL) {
    if (optcode > 0)
      add_argument("--max-allocs-per-node");
    if (optcode == 1)
      add_argument("30000");
    if (optcode == 2 || optcode == 3)
      add_argument("100000");
    if (optcode == 4)
      add_argument("250000");
    if (optcode > 2)
      add_argument("-D__FUZIX_OPT_SPEED__");
  }
  /* Size optimise for all but high -O values */
  if (opt == NULL || optcode < 3)
    add_argument("--opt-code-size");
  /* Macros */
  add_argument("-D__FUZIX__");
  /* Suppress the warnings when sharing code across architectures */
  add_argument("-Ddouble=float");
  /* User provided macros */
  add_argument_list(machead);
  /* Paths */
  add_option_list("-I", includehead);
  if (mode == MODE_LINK)
    add_option_list("-L", libphead);
  if (mode == MODE_CPP)
    add_argument("-E");
  if (mode == MODE_ASM)
    add_argument("-S");
  if (mode == MODE_OBJ) {
    if (srchead == NULL) {
      fprintf(stderr, "The -c option requires an input.\n");
      exit(1);
    }
    add_argument("-c");
    if (srchead->next && target) {
      fprintf(stderr, "Cannot use -c together with -o with multiple input files.\n");
      exit(1);
    }
  }
  if (mode == MODE_LINK) {
    if (target == NULL)
      autotarget();
    if (target == NULL) {
      fprintf(stderr, "no target.\n");
      exit(1);
    }
    add_option("-o", target);
    if (nostdio)
      snprintf(buf, sizeof(buf), FCC_DIR "/lib/crt0nostdio%s.rel", platform);
    else
      snprintf(buf, sizeof(buf), FCC_DIR "/lib/crt0%s.rel", platform);
    add_argument(mstrdup(buf));
  }
  if (srchead) {
    if (mode == MODE_OBJ)
      add_argument(srchead->p);
    else
      add_argument_list(srchead);
  }
  else {
    fprintf(stderr, "fcc: No sources specified.\n");
    exit(1);
  }
  if (mode == MODE_LINK)
    add_option_list("-l", libhead);
}
Esempio n. 5
0
/* This mega-function reads in the rules file, and loads 
    all the rules into the rmi->parse_rules data structure */
void init_metadata_parser(RIP_MANAGER_INFO * rmi, char *rules_file)
{
	FILE *fp;
	int ri;			/* Rule index */
	int rn;			/* Number of rules allocated */

	if (!rules_file || !*rules_file) {
		use_default_rules(rmi);
		return;
	}
	fp = fopen(rules_file, "r");
	if (!fp) {
		use_default_rules(rmi);
		return;
	}

	rmi->parse_rules = 0;
	ri = rn = 0;
	while (1) {
		char rule_buf[MAX_RULE_SIZE];
		char match_buf[MAX_RULE_SIZE];
		char subst_buf[MAX_RULE_SIZE];
		mchar w_match_buf[MAX_RULE_SIZE];
		mchar w_subst_buf[MAX_RULE_SIZE];
		char *rbp;
		char *rp;
		int got_command;
		int rc;

		/* Allocate memory for rule, if necessary. */
		/* If there are no more rules in the file, */
		/* this rule will become the sentinel null rule */
		if (ri + 1 != rn) {
			rmi->parse_rules = realloc(rmi->parse_rules, (ri + 1) * sizeof(Parse_Rule));
			memset(&rmi->parse_rules[ri], 0, sizeof(Parse_Rule));
			rn = ri + 1;
		}

		/* Get next line from file */
		rp = fgets(rule_buf, 2048, fp);
		if (!rp)
			break;

		/* Skip leading whitespace */
		rbp = rule_buf;
		while (*rbp && isspace(*rbp))
			rbp++;
		if (!*rbp)
			continue;

		/* Get command */
		got_command = 0;
		switch (*rbp++) {
		case 'm':
			got_command = 1;
			rmi->parse_rules[ri].cmd = PARSERULE_CMD_MATCH;
			break;
		case 's':
			got_command = 1;
			rmi->parse_rules[ri].cmd = PARSERULE_CMD_SUBST;
			break;
		case '#':
			got_command = 0;
			break;
		default:
			got_command = 0;
			printf("Warning: malformed command in rules file:\n%s\n", rule_buf);
			break;
		}
		if (!got_command)
			continue;

		/* Skip past fwd slash */
		if (*rbp++ != '/') {
			printf("Warning: malformed command in rules file:\n%s\n", rule_buf);
			continue;
		}

		/* Parse match string */
		rbp = parse_escaped_string(match_buf, rbp);
		debug_printf("match_buf=%s\n", match_buf);
		if (!rbp) {
			printf("Warning: malformed command in rules file:\n%s\n", rule_buf);
			continue;
		}

		/* Parse subst string */
		if (rmi->parse_rules[ri].cmd == PARSERULE_CMD_SUBST) {
			rbp = parse_escaped_string(subst_buf, rbp);
			debug_printf("subst_buf=%s\n", subst_buf);
			if (!rbp) {
				printf("Warning: malformed command in rules file:\n%s\n", rule_buf);
				continue;
			}
		}

		/* Parse flags */
		rc = parse_flags(&rmi->parse_rules[ri], rbp);
		if (!rc) {
			printf("Warning: malformed command in rules file:\n%s\n", rule_buf);
			continue;
		}

		/* Compile the rule */
		debug_printf("Compiling the rule\n");
		gstring_from_string(rmi, w_match_buf, MAX_RULE_SIZE, match_buf, CODESET_UTF8);
		if (!compile_rule(&rmi->parse_rules[ri], w_match_buf)) {
			printf("Warning: malformed regular expression:\n%s\n", match_buf);
			continue;
		}

		/* Copy rule strings */
		debug_printf("Copying rule string (1)\n");
		debug_mprintf(m_("String is ") m_S m_("\n"), w_match_buf);
		rmi->parse_rules[ri].match = mstrdup(w_match_buf);
		debug_printf("Copying rule string (2)\n");
		if (rmi->parse_rules[ri].cmd == PARSERULE_CMD_SUBST) {
			debug_printf("Copying rule string (3)\n");
			gstring_from_string(rmi, w_subst_buf, MAX_RULE_SIZE, subst_buf, CODESET_UTF8);
			debug_printf("Copying rule string (4)\n");
			rmi->parse_rules[ri].subst = mstrdup(w_subst_buf);
			debug_printf("Copying rule string (5)\n");
		}

		debug_printf("End of loop\n");
		ri++;
	}
	fclose(fp);
}
Esempio n. 6
0
char *PathResolver::normalizeFilename( const char *path )
{
	switch (path[0])
	{
	case '<': // Input
			return prettyPath(mstrcat(project_root, path+1));
	case '>': // Output
			return prettyPath(mstrcat(out_root, path+1));
	case '~': // Output
		return prettyPath(mstrcat(getenv("HOME"), path+1));
	case '@': // Auto path
		{
			/***** Expand the path *****/
			char *p = mstrdup(path);
			char *pf = p;
			if ( p[1] != '/' ) p[0] = '!';
			else               p++;
			char *b = normalizeFilename(p);
			free(pf);

			char *n = NULL;

			size_t olen = strlen(out_root);
			size_t plen = strlen(project_root);
			size_t blen = strlen(b);

			if (!strncmp(b, out_root, olen))
			{
				n = b; // Already in the out directory.
			}
			else if (!strncmp(b, project_root, plen))
			{
				n = myalloc(blen - plen + olen + 1);

				strcpy(n,      out_root);
				strcpy(n+olen, b+plen);

				free(b);
			}
			else // Outside of our directories
			{
				n = myalloc(olen + blen + 1);

				strcpy(n,      out_root);
				strcpy(n+olen, b);

				free(b);
			}

			return prettyPath(n);
		}
	case '*': // System path
		{
			path = mstrdup(path);

			DIR *cwd  = opendir(".");

			char *pathdir = mstrdup(getenv("PATH"));
			char *nt = pathdir; // NULL-terminator
			bool moredirs = true;

			const char *exename = path + 1;
			while ( moredirs )
			{
				/*** NULL-terminate the end of the next dir ***/
				pathdir = nt;
				while ( *nt != '\0' && *nt != ':' )
					nt++;
				if (!*nt)
					moredirs = false;
				*(nt++) = '\0';

				/*** Check for executable ***/
				chdir(pathdir);
				FILE *e = fopen(exename, "r");
				if (e) // Found it.
				{
					char *n = mstrcat(pathdir, '/', exename);

					fchdir(dirfd(cwd));
					closedir(cwd);

					return prettyPath(n);
				}
			}

			fchdir(dirfd(cwd));
			closedir(cwd);
		}

		msg::error("System path \"%s\" not found.", path);
		exit(EX_DATAERR);
	case '/': // Already absolute
		return prettyPath(mstrdup(path));
	}

	// Regular relative path

	if ( *path == '!' ) path++; // We didn't want the first character
	                            // to be looked at.

	char *n = getcwd(NULL, 0);
	int cwdlen = strlen(n);

	n = (char*)realloc(n, (cwdlen+2+strlen(path))*sizeof(char));
	if ( cwdlen > 1 )
	{
		n[cwdlen]   = '/' ;
		n[cwdlen+1] = '\0';
	}
	strcat(n, path);

	return prettyPath(n);
}
Esempio n. 7
0
void PathResolver::setOutRoot(const char *path)
{
	free(out_root);
	out_root = mstrdup(path);
	out_root_len = strlen(out_root);
}
Esempio n. 8
0
void PathResolver::setProjectRoot(const char *path)
{
	free(project_root);
	project_root = mstrdup(path);
	project_root_len = strlen(project_root);
}