Exemplo n.º 1
0
//
// Create the default  set attributes dialog box for this class of
// Interactor.
//
SetAttrDialog *SelectionInstance::newSetAttrDialog(Widget parent)
{
    Node *n = this->getNode();
    char *name = (char*)n->getClassName();
    ASSERT(name);
    name = DuplicateString(name);
    char *p = strstr(name,"Node");
    if (p)
	*p = '\0';
    char title[128];
    sprintf(title,"Set %s Attributes...",name);
    SetAttrDialog *d = new SelectionAttrDialog(parent, title, this);
    delete name;
    return d;
}
Exemplo n.º 2
0
PacketHandler::PacketHandler(int plinger,
				 int ptype,
				 int pnumber,
				 PacketHandlerCallback pcallback,
				 void *pclientData,
				 const char *matchString)

{
    this->linger = plinger;
    this->type = ptype;
    this->number = pnumber;
    this->callback = pcallback;
    this->clientData = pclientData;
    this->matchString = matchString? DuplicateString(matchString): NULL;
    this->matchLen = matchString? STRLEN(matchString): 0;
}
char *PrintProgramFileDialog::getDefaultFileName()
{
   char *newfile = NULL; 
   const char *file = this->network->getFileName();

   if (file) {
	newfile = DuplicateString(file);
        char *c = strstr(newfile,".net");
        if (c) {
            strcpy(c,".ps");
        } else {
            strcat(newfile,".ps");
        }
   }
   return newfile;
}
Exemplo n.º 4
0
void DXWindow::getGeometryNameHierarchy(char* names[], int* count, int max)
{
    int cnt = *count;
    if (cnt >= (max-1)) {
	this->IBMMainWindow::getGeometryNameHierarchy(names, count, max);
	return ;
    }

#ifdef DXD_NON_UNIX_DIR_SEPARATOR
    char fsep = '\\';
#else
    char fsep = '/';
#endif

    const char* fname = theDXApplication->network->getFileName();
    //
    // Remove the extension and all leading names, leaving 
    // only WindVorticity for examples
    //
    if ((!fname) || (!fname[0])) {
	this->IBMMainWindow::getGeometryNameHierarchy(names, count, max);
	return ;
    }

    int len = strlen(fname);
    int i;
    int last_slash = -1;
    for (i=len-1; i>=0; i--) {
	if ((fname[i] == fsep) || (fname[i] == '/')) {
	    last_slash = i;
	    break;
	}
    }
    last_slash++;
    char* file;
    file = DuplicateString(&fname[last_slash]);

    len = strlen(file);
    for (i=len-1; i>=0; i--) if (file[i]=='.') {file[i] = '\0'; break; }

    if (file[0]) {
	names[cnt++] = file;
	*count = cnt;
    }

    this->IBMMainWindow::getGeometryNameHierarchy(names, count, max);
}
Exemplo n.º 5
0
void ImageFormatREX::eraseOutputFile(const char *fname)
{
    char *cp;
    char *srcfile = DuplicateString(fname);
    char *file_to_delete = new char[strlen(fname) + 8];
    if ( (cp = strstr (srcfile, ".r")) ) cp[0] = '\0';
    sprintf (file_to_delete, "%s.r", srcfile);
    unlink (file_to_delete);
    sprintf (file_to_delete, "%s.g", srcfile);
    unlink (file_to_delete);
    sprintf (file_to_delete, "%s.b", srcfile);
    unlink (file_to_delete);
    sprintf (file_to_delete, "%s.size", srcfile);
    unlink (file_to_delete);

    delete file_to_delete;
    delete srcfile;
}
Exemplo n.º 6
0
TickLabel::TickLabel (double dval, const char *str, int pos, 
TickSelectCB tscb, void *clientData) :
	UIComponent("tickLabel")
{
    this->dval = dval;
    this->str = DuplicateString(str);
    this->pos = pos;

    this->dirty = 0; 
    //this->number = NUL(Widget);
    //this->text = NUL(Widget);
    //this->form = NUL(Widget);

    this->selected = false;
    this->tscb = tscb;
    this->clientData = clientData;
    this->ignoreVerifyCallback = false;
}
Exemplo n.º 7
0
DirTree * DirTree_AddFile(DirTree *Tree, const char *Path, geBoolean IsDirectory)
{
	DirTree *		NewEntry;
	const char *	LeftOvers;

	assert(Tree);
	assert(Path);
	assert(IsDirectory == GE_TRUE || IsDirectory == GE_FALSE);

	assert(strlen(Path) > 0);

	if	(PathHasDir(Path))
	{
		Tree = DirTree_FindPartial(Tree, Path, &LeftOvers);
		if	(!Tree)
			return NULL;
	
		if	(PathHasDir(LeftOvers))
			return NULL;
	
		Path = LeftOvers;
	}

	NewEntry = geRam_Allocate(sizeof(*NewEntry));
	if	(!NewEntry)
		return NULL;

	memset(NewEntry, 0, sizeof(*NewEntry));
	NewEntry->Name = DuplicateString(Path);
	if	(!NewEntry->Name)
	{
		geRam_Free(NewEntry->Name);
		geRam_Free(NewEntry);
		return NULL;
	}

	NewEntry->Siblings = Tree->Children;
						 Tree->Children = NewEntry;

	if	(IsDirectory == GE_TRUE)
		NewEntry->AttributeFlags |= GE_VFILE_ATTRIB_DIRECTORY;

	return NewEntry;
}
//
// Look for type that matches the type for the value given. 
// If found, set the value of the default for this instance and return 
// success, otherwise the given value was not in this parameter's type
// list and so we fail.
//
bool
ParameterDefinition::setDefaultValue(const char *value)
{
    List	typelist;

    //
    // Make sure the value provided is recognized as one of the supported types.
    //
    if (value != NULL && DXType::ValueToType(value, typelist) == 0)
	return false;		// Unrecognized value

    if (DEFAULT_VALUE_NEEDS_DELETING(this))
	delete[] this->default_value;

    this->descriptive_default = false; 
    this->default_value = DuplicateString(value);
    return true;

}
Exemplo n.º 9
0
// Retrieves the current directory for the current process.
// Return boost::shared_array<TCHAR>
boost::shared_array<TCHAR> GetCurrDirectory_sa()
{
	int bufferLen = MAX_PATH + 2;
	
	boost::scoped_array<TCHAR> buffer(new TCHAR[bufferLen]);
	
	if(!GetCurrentDirectory(bufferLen, buffer.get()))
	{
		throw WIN32EXCEPTION_1("GetCurrentDirectory");
	}
	
	HRESULT hResult = StringCchCat(buffer.get(), bufferLen, TEXT("\\"));
	if(FAILED(hResult))
	{
		throw WIN32EXCEPTION_FROM_HRESULT_2(hResult, "StringCchCat");
	}
	
	return DuplicateString(buffer.get());  // reduce allocated string size
}	
Exemplo n.º 10
0
BOOL
InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout)
{
    WCHAR szIndicator[MAX_STR_LEN];
    INPUT_LIST_NODE *pInput;

    if (pLocale == NULL || pLayout == NULL)
    {
        return FALSE;
    }

    for (pInput = _InputList; pInput != NULL; pInput = pInput->pNext)
    {
        if (pInput->pLocale == pLocale && pInput->pLayout == pLayout)
        {
            return FALSE;
        }
    }

    pInput = InputList_AppendNode();

    pInput->wFlags = INPUT_LIST_NODE_FLAG_ADDED;

    pInput->pLocale = pLocale;
    pInput->pLayout = pLayout;

    if (GetLocaleInfoW(LOWORD(pInput->pLocale->dwId),
                       LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE,
                       szIndicator,
                       ARRAYSIZE(szIndicator)))
    {
        size_t len = wcslen(szIndicator);

        if (len > 0)
        {
            szIndicator[len - 1] = 0;
            pInput->pszIndicator = DuplicateString(szIndicator);
        }
    }

    return TRUE;
}
Exemplo n.º 11
0
//
// Get the text from a text widget and clip off the leading and
// trailing white space.
// The return string must be deleted by the caller.
//
char *SetMacroNameDialog::GetTextWidgetToken(Widget textWidget)
{
    char *name = XmTextGetString(textWidget);
    ASSERT(name);
    int i,len = STRLEN(name);

    for (i=len-1 ; i>=0 ; i--) {
	if (IsWhiteSpace(name,i))
	    name[i] = '\0';
	else
	    break;
    }

    i=0; SkipWhiteSpace(name,i);
     
    char *s = DuplicateString(name+i);
    XtFree(name);
    return s;

}
Exemplo n.º 12
0
DirTree *DirTree_Create(void)
{
	DirTree *	Tree;

	Tree = geRam_Allocate(sizeof(*Tree));
	if	(!Tree)
		return Tree;

	memset(Tree, 0, sizeof(*Tree));
	Tree->Name = DuplicateString("");
	if	(!Tree->Name)
	{
		geRam_Free(Tree);
		return NULL;
	}

	Tree->AttributeFlags |= GE_VFILE_ATTRIB_DIRECTORY;

	return Tree;
}
Exemplo n.º 13
0
static int InsertAt(ElementType *SC,size_t idx,const CHAR_TYPE *newval)
{
    CHAR_TYPE *p;
    if (SC == NULL) {
        return NullPtrError("InsertAt");
    }
    if (newval == NULL) {
        return BadArgError(SC,"InsertAt");
    }
    if (SC->Flags & CONTAINER_READONLY) {
        return ReadOnlyError(SC,"InsertAt");
    }
    if (idx >= SC->count) {
        return IndexError(SC,idx,"InsertAt");
    }
    if ((SC->count+1) >= SC->capacity) {
        int r = Resize(SC);
        if (r <= 0)
            return r;
    }
    p = DuplicateString(SC,newval,"InsertAt");
    if (p == NULL) {
        return NoMemoryError(SC,"InsertAt");
    }

    if (idx == 0) {
        if (SC->count > 0)
            memmove(SC->contents+1,SC->contents,SC->count*sizeof(CHAR_TYPE *));
        SC->contents[0] = p;
    }
    else if (idx == SC->count) {
        SC->contents[idx] = p;
    }
    else if (idx < SC->count) {
        memmove(SC->contents+idx+1,SC->contents+idx,(SC->count-idx+1)*sizeof(CHAR_TYPE *));
        SC->contents[idx] = p;
    }
    SC->timestamp++;
    ++SC->count;
    return 1;
}
//
// Add the given value to the list of suggested values for this parameter 
//
bool ParameterDefinition::addValueOption(const char *value)
{
    int position;

    if (!this->valueOptions) {
	int size = 4;
	this->valueOptions = (char**)MALLOC(size * sizeof(char*));
	memset(this->valueOptions,0, size * sizeof(char*));
	position = 0;
    } else {
	position = 0;
	while (this->valueOptions[position])
	    position++;	
	int nextpos = position + 1;
	switch (nextpos) {
	    case 4:
	    case 8:
	    case 16:
	    case 32:
	    case 64:
		this->valueOptions = (char**)REALLOC((void*)this->valueOptions,
					2 * nextpos * sizeof(char*));
		memset(this->valueOptions + nextpos, 0, nextpos*sizeof(char*));
		break;
	    default:
		if (nextpos > 64) {
		    fprintf(stderr,
			"Too many value options for parameter (ignoring)");
		    position = -1;
		}
		break;
	}
    }
    if (position >= 0) {
	this->valueOptions[position] = DuplicateString(value);
	return true;
    } else {
	return false;
    }

}
Exemplo n.º 15
0
static int PushBack(ElementType *SC,const CHAR_TYPE *str)
{
    CHAR_TYPE *r;

    if (SC == NULL)
        return NullPtrError("PushBack");
    if (SC->Flags&CONTAINER_READONLY) {
        return ReadOnlyError(SC,"PushBack");
    }
    if (SC->count >= SC->capacity-1) {
        int res = Resize(SC);
        if (res <= 0)
            return res;
    }
    r = DuplicateString(SC,str,"Push");
    if (r == NULL)
        return 0;
    SC->contents[SC->count++] = r;
    SC->timestamp++;
    return 1;
}
Exemplo n.º 16
0
/* [email protected] (gerome) proposed calling DuplicateString. Good
suggestion */
static int ReplaceAt(ElementType *SC,size_t idx,CHAR_TYPE *newval)
{
    CHAR_TYPE *r;

    if (SC == NULL) {
        return NullPtrError("ReplaceAt");
    }
    if (SC->Flags & CONTAINER_READONLY) {
        return ReadOnlyError(SC,"ReplaceAt");
    }
    if (idx >= SC->count) {
        return IndexError(SC,idx,"ReplaceAt");
    }
    SC->Allocator->free(SC->contents[idx]);
    r = DuplicateString(SC,newval,(char *)"ReplaceAt");
    if (r == NULL) {
        return NoMemoryError(SC,"ReplaceAt");
    }
    SC->contents[idx] = r;
    SC->timestamp++;
    return 1;
}
Exemplo n.º 17
0
static int PushFront(ElementType *SC,CHAR_TYPE *str)
{
    CHAR_TYPE *r;

    if (SC == NULL)
        return NullPtrError("PushFront");
    if (str == NULL)
        return BadArgError(SC,"PushFront");
    if (SC->Flags&CONTAINER_READONLY)
        return 0;
    if (SC->count >= SC->capacity-1) {
        int res = Resize(SC);
        if (res <= 0)
            return res;
    }
    r = DuplicateString(SC,str,"PushFront");
    if (r == NULL)
        return NoMemoryError(SC,"PushFront");
    memmove(SC->contents+1,SC->contents,SC->count*sizeof(void *));
    SC->contents[0] = r;
    SC->timestamp++;
    SC->count++;
    return 1;
}
Exemplo n.º 18
0
MOZ_MUST_USE mozilla::Maybe<SharedImmutableTwoByteString>
SharedImmutableStringsCache::getOrCreate(const char16_t* chars, size_t length)
{
    return getOrCreate(chars, length, [&]() { return DuplicateString(chars, length); });
}
Exemplo n.º 19
0
int EOF_EXPORT_TO_LC(EOF_VOCAL_TRACK * tp, char *outputfilename, char *string2, int format)
{
	unsigned long linectr = 0, lyrctr = 0, lastlyrtime = 0, linestart = 0, lineend = 0;
	unsigned char pitch = 0;
	FILE *outf = NULL;			//Used to open output file
	FILE *pitchedlyrics = NULL;	//Used to open output pitched lyric fle
	char *vrhythmid = NULL;
	EOF_PHRASE_SECTION temp;	//Used to store the first lyric line in the project, which gets overridden with one covering all lyrics during RS1 export
	unsigned long original_lines;
	char *tempoutputfilename = "lyrics.temp";

	eof_log("EOF_EXPORT_TO_LC() entered", 1);

	if((tp == NULL) || (outputfilename == NULL) || (tp->lyrics == 0))
		return -1;	//Return failure

//Initialize variables
	InitLyrics();	//Initialize all variables in the Lyrics structure
	InitMIDI();		//Initialize all variables in the MIDI structure

	qsort(tp->line, (size_t)tp->lines, sizeof(EOF_PHRASE_SECTION), eof_song_qsort_phrase_sections);	//Sort the lyric lines
	temp = tp->line[0];			//Preserve the original lyric line information
	original_lines = tp->lines;

//Set export-specific settings
	if(format == SCRIPT_FORMAT)
	{
		Lyrics.grouping = 2;	//Enable line grouping for script.txt export
		Lyrics.nohyphens = 3;	//Disable hyphen output
		Lyrics.noplus = 1;	//Disable plus output
		Lyrics.filter = DuplicateString("^=%#/");	//Use default filter list
		Lyrics.defaultfilter = 1;	//Track that the above string will need to be freed
	}
	else if((format == RS_FORMAT) || (format == RS2_FORMAT))
	{
		Lyrics.noplus = 1;	//Disable plus output
		Lyrics.filter = DuplicateString("^=%#/");	//Use default filter list
		Lyrics.defaultfilter = 1;	//Track that the above string will need to be freed
		if((format == RS_FORMAT) || (!tp->lines))
		{	//If exporting to Rocksmith 1 format or if the lyrics don't have any lines defined
			tp->lines = 0;		//Temporarily disregard any existing lyric lines
			(void) eof_vocal_track_add_line(tp, 0, tp->lyric[tp->lyrics - 1]->pos + 1, 0xFF);	//Create a single line encompassing all lyrics
		}
	}
	else if(format == PLAIN_FORMAT)
	{	//This format option is meant to invoke script export with the plain flag set and filtering enabled
		Lyrics.nohyphens = 3;	//Disable hyphen output
		Lyrics.noplus = 1;	//Disable plus output
		Lyrics.filter = DuplicateString("^=%#/");	//Use default filter list
		Lyrics.defaultfilter = 1;	//Track that the above string will need to be freed
		format = SCRIPT_FORMAT;
		Lyrics.plain = 1;
		Lyrics.grouping = 2;	//Enable line grouping for script.txt export
	}

//Import lyrics from EOF structure
	lyrctr = 0;		//Begin indexing into lyrics from the very first
	lastlyrtime = 0;	//First lyric is expected to be greater than or equal to this timestamp
	for(linectr = 0; linectr < (unsigned long)tp->lines; linectr++)
	{	//For each line of lyrics in the EOF structure
		linestart = (tp->line[linectr]).start_pos;
		lineend = (tp->line[linectr]).end_pos;

		if(linestart > lineend)	//If the line starts after it ends
		{
			ReleaseMemory(1);
			return -1;			//Return failure
		}

		if(lyrctr < tp->lyrics)	//If there are lyrics remaining
			CreateLyricLine();	//Initialize new line of lyrics

		if((tp->line[linectr]).flags & EOF_LYRIC_LINE_FLAG_OVERDRIVE)	//If this line is overdrive
			Lyrics.overdrive_on = 1;
		else
			Lyrics.overdrive_on = 0;

		while(lyrctr < tp->lyrics)
		{	//For each lyric
			if((tp->lyric[lyrctr])->text[0] != '\0')
			{	//If this lyric's text isn't an empty string
				if((tp->lyric[lyrctr])->pos < lastlyrtime)	//If this lyric precedes the previous lyric
				{
					(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tLogic error while preparing lyrics for export to file \"%s\"", tempoutputfilename);
					eof_log(eof_log_string, 1);
					ReleaseMemory(1);
					return -1;				//Return failure
				}
				if((tp->lyric[lyrctr])->pos < linestart)		//If this lyric precedes the beginning of the line
				{
					(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tWarning:  Lyric \"%s\" at %lums is outside of defined lyric lines", tp->lyric[lyrctr]->text, tp->lyric[lyrctr]->pos);
					eof_log(eof_log_string, 1);
					CreateLyricLine();	//Initialize new line of lyrics
				}
				if((tp->lyric[lyrctr])->pos > lineend)		//If this lyric is placed beyond the end of this line
				{
					break;					//Break from this while loop to have another line created
				}

				pitch = (tp->lyric[lyrctr])->note;			//Store the lyric's pitch
				if((tp->lyric[lyrctr])->note == 0)			//Remap EOF's pitchless value to FLC's pitchless value
					pitch = PITCHLESS;

				if(!Lyrics.line_on)		//If a lyric line is not in progress
					CreateLyricLine();	//Force one to be before adding the next lyric
				AddLyricPiece((tp->lyric[lyrctr])->text, (tp->lyric[lyrctr])->pos, (tp->lyric[lyrctr])->pos+(tp->lyric[lyrctr])->length, pitch, 0);
					//Add the lyric to the Lyrics structure

				if((Lyrics.lastpiece != NULL) && (Lyrics.lastpiece->lyric[strlen(Lyrics.lastpiece->lyric)-1] == '-'))	//If the piece that was just added ended in a hyphen
					Lyrics.lastpiece->groupswithnext = 1;	//Set its grouping status
			}//If this lyric's text isn't an empty string

			lyrctr++;	//Advance to next lyric
		}

		ForceEndLyricLine();	//End the current line of lyrics
	}

	if(Lyrics.piececount == 0)	//No lyrics imported
	{
		ReleaseMemory(1);
		return 0;		//Return no lyrics found
	}

//Load chart tags
	if(eof_song->tags->artist[0] != '\0')
		Lyrics.Artist = DuplicateString(eof_song->tags->artist);
	if(eof_song->tags->title[0] != '\0')
		Lyrics.Title = DuplicateString(eof_song->tags->title);
	if(eof_song->tags->frettist[0] != '\0')
		Lyrics.Editor = DuplicateString(eof_song->tags->frettist);
	if(eof_song->tags->album[0] != '\0')
		Lyrics.Album = DuplicateString(eof_song->tags->album);

	PostProcessLyrics();	//Perform hyphen and grouping validation/handling

	Lyrics.outfilename = tempoutputfilename;
	Lyrics.out_format = format;

	//If the export format is MIDI-based, write a MIDI file header and a MIDI track (track 0) specifying a tempo of 120BPM
	if((Lyrics.out_format == MIDI_FORMAT) || (Lyrics.out_format == VRHYTHM_FORMAT) || (Lyrics.out_format == SKAR_FORMAT) || (Lyrics.out_format == KAR_FORMAT))
	{
		outf = fopen_err(Lyrics.outfilename,"wb");	//These are binary formats
		Write_Default_Track_Zero(outf);
	}

//Export lyrics
	switch(Lyrics.out_format)
	{
		case SCRIPT_FORMAT:	//Export as script.txt format file
			outf = fopen_err(Lyrics.outfilename,"wt");	//Script.txt is a text format
			Export_Script(outf);
		break;

		case VL_FORMAT:	//Export as VL format file
			outf = fopen_err(Lyrics.outfilename,"wb");	//VL is a binary format
			Export_VL(outf);
		break;

		case MIDI_FORMAT:	//Export as MIDI format file.  Default export track is "PART VOCALS"
			if(string2 == NULL)						//If a destination track name wasn't given
				Lyrics.outputtrack = DuplicateString("PART VOCALS");	//Write track name as PART VOCALS by default
			else
				Lyrics.outputtrack = DuplicateString(string2);
			Export_MIDI(outf);
		break;

		case USTAR_FORMAT:	//Export as UltraStar format file
			outf = fopen_err(Lyrics.outfilename,"wt");	//UltraStar is a text format
			Export_UStar(outf);
		break;

		case LRC_FORMAT:	//Export as simple LRC
		case ELRC_FORMAT:	//Export as extended LRC
			outf = fopen_err(Lyrics.outfilename,"wt");	//LRC is a text format
			Export_LRC(outf);
		break;

		case VRHYTHM_FORMAT:	//Export as Vocal Rhythm (MIDI and text file)
			if(string2 == NULL)	//If a pitched lyric file wasn't given
			{
				fclose_err(outf);
				return -1;	//Return failure
			}

			pitchedlyrics = fopen_err(string2,"wt");	//Pitched lyrics is a text format
			vrhythmid = DuplicateString("G4");
			Export_Vrhythm(outf, pitchedlyrics, vrhythmid);
			fflush_err(pitchedlyrics);	//Commit any pending pitched lyric writes to file
			fclose_err(pitchedlyrics);	//Close pitched lyric file
			free(vrhythmid);
		break;

		case SKAR_FORMAT:	//Export as Soft Karaoke.  Default export track is "Words"
			if(string2 == NULL)						//If a destination track name wasn't given
				Lyrics.outputtrack = DuplicateString("Words");	//Write track name as "Words" by default
			else
				Lyrics.outputtrack = DuplicateString(string2);
			Export_SKAR(outf);
		break;

		case KAR_FORMAT:	//Export as unofficial KAR.  Default export track is "Melody"
			if(Lyrics.outputtrack == NULL)
			{
				(void) puts("\aNo ouput track name for KAR file was given.  A track named \"Melody\" will be used by default");
				Lyrics.outputtrack = DuplicateString("Melody");
			}
			Export_MIDI(outf);
		break;

		case RS_FORMAT:	//Export as Rocksmith XML
			outf = fopen_err(Lyrics.outfilename,"wt");	//XML is a text format
			Lyrics.rocksmithver = 1;
			Export_RS(outf);
		break;

		case RS2_FORMAT:	//Export as Rocksmith 2 XML
			outf = fopen_err(Lyrics.outfilename,"wt");	//XML is a text format
			Lyrics.rocksmithver = 2;
			Export_RS(outf);
		break;

		default:
			(void) puts("Unexpected error in export switch\nAborting");
			exit_wrapper(4);
		break;
	}

	if((Lyrics.out_format == MIDI_FORMAT) || (Lyrics.out_format == VRHYTHM_FORMAT) || (Lyrics.out_format == SKAR_FORMAT) || (Lyrics.out_format == KAR_FORMAT))
	{	//Update the MIDI header to reflect the number of MIDI tracks written to file for all applicable export formats
		fseek_err(outf, 10, SEEK_SET);		//The number of tracks is 10 bytes in from the start of the file header
		fputc_err(MIDIstruct.trackswritten>>8, outf);
		fputc_err(MIDIstruct.trackswritten&0xFF, outf);
	}
Exemplo n.º 20
0
int EOF_IMPORT_VIA_LC(EOF_VOCAL_TRACK *tp, struct Lyric_Format **lp, int format, char *inputfilename, char *string2)
{
	char * returnedfn = NULL;	//Return string from dialog window
	FILE *inf;	  //Used to open the input file
	struct Lyric_Format *detectionlist;
	unsigned long i;
	int jumpcode = 0;

	eof_log("EOF_IMPORT_VIA_LC() entered", 1);

//Validate parameters
	if((tp == NULL) || (inputfilename == NULL))
		return 0;	//Return failure

	if((format == 0) && (lp == NULL))
		return 0;	//Return failure

//Perform detection logic
	InitLyrics();	//Initialize all variables in the Lyrics structure
	InitMIDI();		//Initialize all variables in the MIDI structure
	if(format == 0)		//Auto-detect lyric format
	{
		detectionlist=DetectLyricFormat(inputfilename);
		if(detectionlist == NULL)
			return 0;	//Return invalid lyric file

		if(detectionlist->format == PITCHED_LYRIC_FORMAT)
		{	//If the detection format is Pitched Lyrics, the user must specify the corresponding Vocal Rhythm MIDI
			*lp=detectionlist;	//Return the detected lyric information via the lp pointer
			return -1;			//Return prompt for user selection
		}

		if(detectionlist->next != NULL)
		{	//If there was more MIDI track with lyrics, the user must specify which track to import
			*lp=detectionlist;	//Return the detected lyric information via the lp pointer
			return -2;			//Return prompt for user selection
		}

		Lyrics.in_format=detectionlist->format;		//Format to import
		if(detectionlist->track != NULL)
			Lyrics.inputtrack=detectionlist->track;	//Track to import from
		DestroyLyricFormatList(detectionlist);		//Deallocate the linked list returned by DetectLyricFormat()
		detectionlist=NULL;
	}
	else			//Import specific format
	{
		Lyrics.in_format=format;

		if(Lyrics.in_format == KAR_FORMAT)
		{	//If this is a format for which string2 (pitched file or track name) must be specified
			if(string2 == NULL)	//If the track name to import is not given
				return 0;	//Return failure

			Lyrics.inputtrack=DuplicateString(string2);	//Make a duplicate, so its de-allocation won't affect calling function
		}
		else if(Lyrics.in_format == PITCHED_LYRIC_FORMAT)
		{	//If importing Pitched Lyrics, user must provide the Vocal Rhythm MIDI
			returnedfn = ncd_file_select(0, eof_filename, "Select Vocal Rhythm MIDI", eof_filter_midi_files);
			eof_clear_input();
			if(!returnedfn)
				return 0;	//Return error or user canceled
		}
	}

	Lyrics.infilename=DuplicateString(inputfilename);	//Make a duplicate, so it's de-allocation won't affect calling function

	jumpcode=setjmp(jumpbuffer); //Store environment/stack/etc. info in the jmp_buf array
	if(jumpcode!=0) //if program control returned to the setjmp() call above returning any nonzero value
	{
		(void) puts("Assert() handled sucessfully!");
		free(Lyrics.infilename);
		Lyrics.infilename = NULL;
		ReleaseMemory(1);	//Release memory allocated during lyric import
		return 0;	//Return error
	}

//Import lyrics
	switch(Lyrics.in_format)
	{
		case SCRIPT_FORMAT:	//Load script.txt format file as input
			inf=fopen_err(Lyrics.infilename,"rt");	//Script is a text format
			Script_Load(inf);
		break;

		case VL_FORMAT:	//Load VL format file as input
			inf=fopen_err(Lyrics.infilename,"rb");	//VL is a binary format
			VL_Load(inf);
		break;

		case MIDI_FORMAT:	//Load MIDI format file as input
			if(string2 == NULL)	//If no track name was given
				Lyrics.inputtrack=DuplicateString("PART VOCALS");	//Default to PART VOCALS
			else
				Lyrics.inputtrack=DuplicateString(string2);	//Make a duplicate, so its de-allocation won't affect calling function

			inf=fopen_err(Lyrics.infilename,"rb");	//MIDI is a binary format
			Parse_Song_Ini(Lyrics.infilename,1,1);	//Load ALL tags from song.ini first, as the delay tag will affect timestamps
			MIDI_Load(inf,Lyric_handler,0);		//Call MIDI_Load, specifying the new KAR-compatible Lyric Event handler
		break;

		case USTAR_FORMAT:	//Load UltraStar format file as input
			inf=fopen_err(Lyrics.infilename,"rt");	//UltraStar is a text format
			UStar_Load(inf);
		break;

		case LRC_FORMAT:	//Load LRC format file as input
		case ELRC_FORMAT:
			inf=fopen_err(Lyrics.infilename,"rt");	//LRC is a text format
			LRC_Load(inf);
		break;

		case VRHYTHM_FORMAT:	//Load vocal rhythm (MIDI) and pitched lyrics
			inf=fopen_err(returnedfn,"rb");	//Vrhythm is a binary format
			VRhythm_Load(inputfilename,returnedfn,inf);
		break;

		case PITCHED_LYRIC_FORMAT:
			inf=fopen_err(returnedfn,"rb");	//Vrhythm is a binary format
			VRhythm_Load(eof_filename,returnedfn,inf);
		break;

		case KAR_FORMAT:	//Load KAR MIDI file
			inf=fopen_err(Lyrics.infilename,"rb");	//KAR is a binary format
			MIDI_Load(inf,Lyric_handler,0);	//Call MIDI_Load, specifying the new KAR-compatible Lyric Event handler
		break;

		case SKAR_FORMAT:	//Load SKAR MIDI file
			inf=fopen_err(Lyrics.infilename,"rb");	//KAR is a binary format
			Lyrics.inputtrack=DuplicateString("Words");
			MIDI_Load(inf,SKAR_handler,0);	//Call MIDI_Load, specifying the Simple Karaoke Event handler
			EndLyricLine();	//KAR files do not mark the end of the last line of lyrics
		break;

		case ID3_FORMAT:	//Load MP3 ID3 tag
			inf=fopen_err(Lyrics.infilename,"rb");	//MP3 is a binary format
			ID3_Load(inf);
		break;

		case SRT_FORMAT:	//Load SRT file
			inf=fopen_err(Lyrics.infilename,"rt");	//SRT is a text format
			SRT_Load(inf);
		break;

		case XML_FORMAT:	//Load XML file
			inf=fopen_err(Lyrics.infilename,"rt");	//XML is a text format
			XML_Load(inf);
		break;

		case C9C_FORMAT:	//Load JamBand file
			inf=fopen_err(Lyrics.infilename,"rt");	//JamBand is a text format
			JB_Load(inf);
		break;

		case RS_FORMAT:		//Load Rocksmith XML file
		case RS2_FORMAT:
			inf=fopen_err(Lyrics.infilename,"rt");	//Rocksmith XML is a text format
			RS_Load(inf);
		break;

		default:
		return 0;	//Return failure
	}//switch(Lyrics.in_format)

	free(Lyrics.infilename);
	Lyrics.infilename = NULL;

//Validate imported lyrics
	if((Lyrics.piececount == 0) || (MIDI_Lyrics.head != NULL))	//If the imported MIDI track had no valid lyrics or otherwise was incorrectly formatted
	{
		ReleaseMemory(1);	//Release memory allocated during lyric import
		fclose_err(inf);
		return 0;	  //Return no EOF lyric structure
	}

	PostProcessLyrics();	//Perform validation of pointers, counters, etc.

	if(Lyrics.pitch_tracking)
	{	//Only perform input pitch validation and remapping if the import lyrics had pitch information
		RemapPitches();		//Ensure pitches are within the correct range (except for pitchless lyrics)
	}

	//Delete any existing lyrics and lines
	for(i = 0; i < tp->lyrics; i++)
	{
		free(tp->lyric[i]);
	}
	tp->lyrics = 0;
	tp->lines = 0;
	fclose_err(inf);	//Ensure this file gets closed
	inf=NULL;

	if(EOF_TRANSFER_FROM_LC(tp,&Lyrics) != 0)	//Pass the Lyrics global variable by reference
	{
		ReleaseMemory(1);	//Release memory allocated during lyric import
		return 0;		//Return error (failed to import into EOF lyric structure)
	}

	ReleaseMemory(1);	//Release memory allocated during lyric import
	return 1;	 		//Return finished EOF lyric structure
}
Exemplo n.º 21
0
OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
        const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
        const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
        const char *modelNumber, const char *platformVersion, const char *supportUrl,
        const char *version)
{

    bool success = true;

    if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
    {
        return OC_STACK_INVALID_PARAM;
    }

    if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
    {
        return OC_STACK_INVALID_PARAM;
    }

    if(!DuplicateString(&deviceInfo.contentType, contentType))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.dateOfManufacture, dateOfManufacture))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.deviceUUID, deviceUUID))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.firmwareVersion, firmwareVersion))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.hostName, hostName))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.manufacturerName, manufacturerName))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.manufacturerUrl, manufacturerUrl))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.modelNumber, modelNumber))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.platformVersion, platformVersion))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.supportUrl, supportUrl))
    {
        success = false;
    }

    if(!DuplicateString(&deviceInfo.version, version))
    {
        success = false;
    }

    if(success)
    {
        return OC_STACK_OK;
    }

    DeleteDeviceInfo();
    return OC_STACK_ERROR;
}
OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerName,
    const char *manufacturerUrl, const char *modelNumber, const char *dateOfManufacture,
    const char *platformVersion, const char* operatingSystemVersion, const char* hardwareVersion,
    const char *firmwareVersion, const char* supportUrl, const char* systemTime)
{

    bool success = true;

    if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
    {
        return OC_STACK_INVALID_PARAM;
    }

    if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
    {
        return OC_STACK_INVALID_PARAM;
    }

    if(!DuplicateString(&platformInfo.platformID, platformID))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.manufacturerName, manufacturerName))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.modelNumber, modelNumber))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.platformVersion, platformVersion))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.hardwareVersion, hardwareVersion))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.firmwareVersion, firmwareVersion))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.supportUrl, supportUrl))
    {
        success = false;
    }

    if(!DuplicateString(&platformInfo.systemTime, systemTime))
    {
        success = false;
    }

    if(success)
    {
        return OC_STACK_OK;
    }

    DeletePlatformInfo();
    return OC_STACK_ERROR;
}
Exemplo n.º 23
0
void VL_Load(FILE *inf)
{
    unsigned long ctr=0;				//Generic counter
    unsigned long start_off=0;			//Starting offset of a lyric piece in milliseconds
    unsigned long end_off=0;			//Ending offset of a lyric piece in milliseconds
    char *temp=NULL;					//Pointer for string manipulation
    struct VL_Text_entry *curtext=NULL;	//Conductor for text chunk linked list
    struct VL_Sync_entry *cursync=NULL;	//Conductor for sync chunk linked list
    unsigned short cur_line_len=0;		//The length of the currently line of lyrics
    unsigned short start_char=0;		//The starting character offset for the current sync entry
    unsigned short end_char=0;			//The ending character offset for the current sync entry
    char groupswithnext=0;				//Tracks grouping, passed to AddLyricPiece()

    assert_wrapper(inf != NULL);	//This must not be NULL

    Lyrics.freestyle_on=1;		//VL is a pitch-less format, so import it as freestyle

    if(Lyrics.verbose)	printf("Importing VL lyrics from file \"%s\"\n\n",Lyrics.infilename);

//Build the VL storage structure
    (void) VL_PreLoad(inf,0);

//Process offset
    if(Lyrics.offsetoverride == 0)
    {
        if(Lyrics.Offset == NULL)
        {
            if(Lyrics.verbose)	(void) puts("No offset defined in VL file, applying offset of 0");

            Lyrics.realoffset=0;
        }
        else if(strcmp(Lyrics.Offset,"0") != 0)
        {   //If the VL file's offset is not zero and the command line offset is not specified
            assert_wrapper(Lyrics.Offset != NULL);	//atol() crashes if NULL is passed to it

            Lyrics.realoffset=atol(Lyrics.Offset); //convert to number
            if(Lyrics.realoffset == 0)	//atol returns 0 on error
            {
                printf("Error converting \"%s\" to integer value\nAborting\n",Lyrics.Offset);
                exit_wrapper(1);
            }

            if(Lyrics.verbose) printf("Applying offset defined in VL file: %ldms\n",Lyrics.realoffset);
        }	//if the VL file's offset is defined as 0, that's what Lyrics.realoffset is initialized to already
    }

    if(Lyrics.verbose)	(void) puts("Processing lyrics and sync entries");

//Process sync points, adding lyrics to Lyrics structure
    cursync=VL.Syncs;	//Begin with first sync entry
    while(cursync != NULL)	//For each sync point
    {
        groupswithnext=0;	//Reset this condition
        start_off=cursync->start_time*10;	//VL stores offsets as increments of 10 milliseconds each
        end_off=cursync->end_time*10;

        //Validate the lyric line number
        if(cursync->lyric_number >= VL.numlines)	//lyric_number count starts w/ 0 instead of 1 and should never meet/exceed numlines
        {
            (void) puts("Error: Invalid line number detected during VL load\nAborting");
            exit_wrapper(2);
        }

        //Validate the start and end character numbers in the sync entry
        start_char=cursync->start_char;
        end_char=cursync->end_char;
        if(start_char == 0xFFFF)
        {
            (void) puts("Error: Sync entry has no valid lyric during VL load\nAborting");
            exit_wrapper(3);
        }

        //Seek to the correct lyric entry
        curtext=VL.Lyrics;	//Point conductor to first text entry
        for(ctr=0; ctr<cursync->lyric_number; ctr++)
            if(curtext->next == NULL)
            {
                (void) puts("Error: Unexpected end of text piece linked list\nAborting");
                exit_wrapper(4);
            }
            else
                curtext=curtext->next;	//Seek forward to next piece

        cur_line_len = (unsigned short) strlen(curtext->text);	//This value will be used several times in the rest of the loop
        if(start_char >= cur_line_len)				//The starting offset cannot be past the end of the line of lyrics
        {
            (void) puts("Error: Sync entry has invalid starting offset during VL load\nAborting");
            exit_wrapper(5);
        }
        if((end_char!=0xFFFF) && (end_char >= cur_line_len))
        {   //The ending offset cannot be past the end of the line of lyrics
            (void) puts("Error: Sync entry has invalid ending offset during VL load\nAborting");
            exit_wrapper(6);
        }

        //Build the lyric based on the start and end character offsets
        temp=DuplicateString(curtext->text+start_char);
        //Copy the current text piece into a new string, starting from the character indexed by the sync entry

        if(Lyrics.verbose>=2)	printf("\tProcessing sync entry #%lu: \"%s\"\tstart char=%u\tend char=%u\t\n",ctr,curtext->text,start_char,end_char);

        if(end_char != 0xFFFF)	//If the sync entry ends before the end of the text piece
        {   //"abcdef"	strlen=6	st=2,en=4->"cde"
            if((isspace((unsigned char)temp[end_char-start_char-1])==0) && (isspace((unsigned char)temp[end_char-start_char])==0))
                //if this sync entry's text doesn't end in whitespace and the next entry's doesn't begin in whitespace
                groupswithnext=1;	//Allow AddLyricPiece to handle grouping and optional hyphen insertion

//I've had to go back and forth on this line, but currently, end_char-start_char seems to mark the location at which to truncate, not the last character to keep before truncating
            temp[end_char-start_char]='\0';	//Truncate the string as indicated by the sync entry's end index (after the end_char)
        }

        //Add lyric to Lyric structure
        if(cursync->start_char == 0)	//If this piece is the beginning of a line of lyrics
        {
            //Ensure a line of lyrics isn't already in progress
            if(Lyrics.line_on == 1)
            {
                (void) puts("Error: Lyric lines overlap during VL load\nAborting");
                exit_wrapper(7);
            }

            if(Lyrics.verbose>=2)	(void) puts("New line of lyrics:");

            CreateLyricLine();	//Initialize the line
        }

//Add lyric to Lyrics structure.
        AddLyricPiece(temp,start_off,end_off,PITCHLESS,groupswithnext);	//Add the lyric piece to the Lyric structure, no defined pitch
        free(temp);	//Release memory for this temporary string

        if((end_char == 0xFFFF) || (end_char == cur_line_len))	//If this piece ends a line of lyrics
        {
            //Ensure a line of lyrics is in progress
            if(Lyrics.line_on == 0)
            {
                (void) puts("Error: End of lyric line detected when none is started during VL load\nAborting");
                exit_wrapper(8);
            }

            if(Lyrics.verbose>=2)	(void) puts("End line of lyrics");

            EndLyricLine();		//End the line
        }

        cursync=cursync->next;
    }//end while(cursync != NULL)

    ForceEndLyricLine();

    if(Lyrics.verbose)	printf("VL import complete.  %lu lyrics loaded\n",Lyrics.piececount);

    ReleaseVL();	//Release memory used to build the VL structure
}
Exemplo n.º 24
0
static void *_DuplicateString(const void *s)
{
	return (void*) DuplicateString((const char*)s);
}
Exemplo n.º 25
0
struct _VLSTRUCT_ *VL_PreWrite(void)
{
    struct _VLSTRUCT_ *OutVL=NULL;		//Create a VL structure to build the exported VL format
    char *lyrline=NULL;					//A pointer to an array large enough to store the largest line of lyrics
    char *temp=NULL;
    unsigned long maxlength=0;			//The calculated length of the longest lyric line (excluding null terminator)
    unsigned long charcount=0;			//The running sum of the length of all lyric pieces in a line
    unsigned long index=0;				//The current index into the lyric line, stored with each sync entry
    unsigned long linenum=0;			//The number of the currently-processed lyric line
    struct Lyric_Piece *curpiece=NULL;	//Conductor for lyric piece linked list
    struct Lyric_Line *curline=NULL;	//Conductor for lyric line linked list
    struct VL_Text_entry *curtext=NULL;	//Text entry for current lyric piece
    struct VL_Sync_entry *cursync=NULL;	//Sync entry for current lyric piece
    struct VL_Sync_entry *newsync=NULL;	//Used to build new sync entries to insert into list
    struct VL_Text_entry *newtext=NULL;	//Used to build new text entries to insert into list
    unsigned long lastendtime=0;		//The end time for the last lyric piece.  The next lyric's timestamp must be at least 1 more than this
    static const struct _VLSTRUCT_ empty_VLSTRUCT_;	//Auto-initialize all members to 0/NULL

    if(Lyrics.verbose)	(void) puts("Building VL structure");

//Allocate the Export_VL structure
    OutVL=malloc_err(sizeof(struct _VLSTRUCT_));
    *OutVL=empty_VLSTRUCT_;	//Reliably initialize all values to 0/NULL

//Initialize the Export_VL structure
    OutVL->numlines=Lyrics.linecount;
    OutVL->numsyncs=Lyrics.piececount;

//Find the length of the longest line of lyrics
    maxlength=0;
    curline=Lyrics.lines;		//Conductor points to first line of lyrics
    while(curline != NULL)	//For each line of lyrics
    {
        charcount=0;	//reset count
        curpiece=curline->pieces;	//Conductor points to first lyric in the line
        while(curpiece != NULL)		//For each lyric piece in the line
        {
            if(curpiece->lyric != NULL)
                charcount+=strlen(curpiece->lyric);	//Add the length of the lyric

            curpiece=curpiece->next;	//Point to next lyric piece
        }

        if(charcount>maxlength)		//If this line has more characters than any other so far
            maxlength=charcount;	//store the number of characters

        curline=curline->next;		//Point to next lyric line
    }

//Initialize lyrline
    lyrline=malloc_err((size_t)(maxlength+1+Lyrics.piececount));	//Add piececount to allow for spacing between each word

//Process lyric pieces
    curline=Lyrics.lines;	//Conductor points to first line of lyrics
    lastendtime=0;
    linenum=0;	//This will be used to index into the lyric array
    cursync=OutVL->Syncs;	//Point conductor to first link in sync chunk list

    while(curline != NULL)	//For each line of lyrics
    {
        lyrline[0]='\0';	//Empty the string buffer
        index=0;			//Reset index to 0
        curpiece=curline->pieces;	//Conductor points to first lyric in the line

        while(curpiece != NULL)	//For each lyric piece in this line
        {
            if(curpiece->lyric != NULL)	//Only process if there is actual lyric text for this lyric piece
            {
                //Allocate a new sync list link
                newsync=malloc_err(sizeof(struct VL_Sync_entry));

                //Build sync entry
                newsync->lyric_number=linenum;	//Initialize lyric number, which should be the lyric line number it refers to
                newsync->start_char=index;		//Initialize sync entry start index

                if(curpiece->next != NULL)	//If there's another lyric piece in this line
                    newsync->end_char=index+strlen(curpiece->lyric)-1;	//Find ending offset of this sync entry
                else
                    newsync->end_char=0xFFFF;	//The lyric reaches the end of the line of lyrics

                newsync->start_time=curpiece->start/10;	//VL stores timestamps in 10ms increments
                newsync->end_time=(curpiece->start+curpiece->duration)/10;

                if(newsync->end_time <= newsync->start_time)	//If the duration of the lyric was less than 10ms (became 0 during the division)
                    newsync->end_time+=1;						//add the minimum duration of 10ms

                if((lastendtime != 0) && (newsync->start_time < lastendtime))	//Ensure that this doesn't overlap with last piece
                    newsync->start_time=lastendtime+1;

                lastendtime=newsync->end_time;	//Store this to prevent overlapping with next piece
                index=newsync->end_char+1;	//Set lyric character index one higher than the end of this sync entry
                newsync->next=NULL;			//This will be the last link in the list

                //Insert sync entry into linked list
                if(OutVL->Syncs == NULL)		//This is the first sync entry in the list
                    OutVL->Syncs=newsync;
                else						//Last link points forward to this link
                    cursync->next=newsync;

                cursync=newsync;			//This becomes the new last link in the list

                //Append lyric piece to string and append a space if necessary
                strcat(lyrline,curpiece->lyric);
                if((curpiece->next != NULL) && (curpiece->groupswithnext == 0))
                {   //There is another lyric piece in this line and this piece does not group with it
                    strcat(lyrline," ");
                    index++;				//Increment the index to preserve subsequent sync piece placement
                }
            }

            curpiece=curpiece->next;	//Point to next lyric piece
        }//end while(curpiece != NULL)

        //Make a permanent copy of the combined lyric string and store it in the lyric array
        temp=DuplicateString(lyrline);	//Copy completed lyric line into new string
        linenum++;							//Iterate lyric line number
        //Allocate new text link
        newtext=malloc_err(sizeof(struct VL_Text_entry));

        //Build new link and insert into list
        newtext->text=temp;
        newtext->next=NULL;
        if(OutVL->Lyrics == NULL)	//This is the first text chunk entry
            OutVL->Lyrics=newtext;
        else							//Last link points forward to this link
        {
            assert_wrapper(curtext != NULL);
            curtext->next=newtext;
        }
        curtext=newtext;				//This becomes the last link in the list

        curline=curline->next;			//Point to next lyric line

        if(Lyrics.verbose>=2)	printf("\tStored text chunk entry \"%s\"\n",temp);
    }//end while(curline != NULL)

    free(lyrline);	//No longer needed
    return OutVL;	//Return completed structure
}
Exemplo n.º 26
0
//
// format:
//	// annotation %s_begin: NO_TEXT_SYMBOL\n
//	// annotation %s: %s\n
//	// annotation %s_end: NO_TEXT_SYMBOL\n
//
boolean CommentStyle::printComment (FILE* f)
{
char begin_stmnt[64];
char end_stmnt[64];

    sprintf (begin_stmnt, "%s_begin", this->getKeyword());
    sprintf (end_stmnt, "%s_end", this->getKeyword());

    const char* cp = this->getPrintableText();

    if ((cp) && (cp[0])) {

	if (fprintf (f, "    // annotation %s: %ld\n", begin_stmnt, strlen(cp)) < 0)
	    return FALSE;

	char* line_to_print = DuplicateString(cp);
	//
	// The constant PBS imposes a maximum line length.
	//
#	define PBS 256
	char print_buf[PBS];
	int line_len_exceeded = 0;
	int i = 0, next = 0;
	while (1) {
	    print_buf[next] = line_to_print[i];
	    if (next == (PBS-2)) {
		print_buf[++next] = '\n';
		line_len_exceeded++;
	    }
	    if (print_buf[next] == '\n') {
		print_buf[next] = '\0';
		int j;
		boolean is_line_whitespace = TRUE;
		for (j=0; j<next; j++) {
		    if ((print_buf[j] != ' ') &&
			(print_buf[j] != '\t')) {
			is_line_whitespace = FALSE;
			break;
		    }
		}
		if (!is_line_whitespace) {
		    if (fprintf (f, 
			"    // annotation %s: %s\n", this->getKeyword(), print_buf) < 0)
			return FALSE;
		} else {
		    if (fprintf (f, "    // annotation %s: %s\n", 
			this->getKeyword(), NO_TEXT_SYMBOL) < 0)
			return FALSE;
		}
		next = 0;
	    } else if (print_buf[next] == '\0') {
		int j;
		boolean is_line_whitespace = TRUE;
		for (j=0; j<next; j++) {
		    if ((print_buf[j] != ' ') &&
			(print_buf[j] != '\t')) {
			is_line_whitespace = FALSE;
			break;
		    }
		}
		if (!is_line_whitespace) {
		    if (fprintf (f, "    // annotation %s: %s\n", 
			this->getKeyword(), print_buf) < 0)
			return FALSE;
		} else {
		    if (fprintf (f, "    // annotation %s: %s\n", 
			this->getKeyword(), NO_TEXT_SYMBOL) < 0)
			return FALSE;
		}
		break;
	    } else {
		next++;
	    }
	    i++;
	}
	if (line_len_exceeded) {
	    WarningMessage ("%d lines of program annotation"
		"exceeded maximum length of %d", line_len_exceeded, PBS);
	}
	delete line_to_print;

	if (fprintf (f, "    // annotation %s: %s\n", end_stmnt, NO_TEXT_SYMBOL) < 0)
	    return FALSE;
    }
    return TRUE;
}
Exemplo n.º 27
0
void PixelImageFormat::setCommandActivation()
{
int x,y,height;
double hd, aspect;
char size_val[64];
ImageNode *node = this->dialog->getNode();

    //
    // Flags which will tell use what to do...
    //
    boolean rescon = node->isRecordResolutionConnected();
    boolean resset = rescon || node->isRecordResolutionSet();
    boolean aspcon = node->isRecordAspectConnected();
    boolean aspset = aspcon || node->isRecordAspectSet();
    boolean dirty_res = (this->dirty & PixelImageFormat::DirtyResolution);
    boolean dirty_asp = (this->dirty & PixelImageFormat::DirtyAspect);
    boolean rerender = this->dialog->isRerenderAllowed();

    //
    // What are the node's values?
    //
    boolean resfetched = FALSE;
    boolean aspfetched = FALSE;
    if (rescon) {
	node->getRecordResolution(x,y);
	resfetched = TRUE;
    } 
    if (aspcon) {
	node->getRecordAspect(aspect);
	aspfetched = TRUE;
    } 
    if ((rerender) && (!resfetched) && (resset)) {
	node->getRecordResolution(x,y);
	resfetched = TRUE;
    }
    if ((rerender) && (!aspfetched) && (aspset)) {
	node->getRecordAspect(aspect);
	aspfetched = TRUE;
    }
    if (!resfetched) 
	node->getResolution(x,y);
    if (!aspfetched)
	node->getAspect(aspect);

    //
    // Do we use the node's value or our own?
    //
    this->use_nodes_resolution = (rescon || !rerender || (resset && !dirty_res));
    this->use_nodes_aspect = (aspcon || !rerender || (aspset && !dirty_asp));

    //
    // If we know we're using the node's value, then disable the text widget so
    // that the user sees she can't enter her own value.
    //
    if (this->size_text) {
	if (((rescon) && (aspcon)) || (!rerender))
	    this->setTextSensitive (this->size_text, False);
	else
	    this->setTextSensitive (this->size_text, True);
    }

    //
    // Based on what we already know, lets put a value into the text widget.
    //
    if ((this->use_nodes_resolution) && (this->use_nodes_aspect)) {
	this->aspect = aspect;
	this->width = x;
	hd = (double)this->width * this->aspect;
	this->dirty = 0;


    //
    // Only use the node's resolution value, use a stored 
    // aspect to compute the height.
    //
    } else if (this->use_nodes_resolution) {
	this->width = x;
	hd = (double)this->width * this->aspect;
	this->dirty&= ~PixelImageFormat::DirtyResolution;


    //
    // Use the node's apsect value.  Use a stored resolution value to
    // compute the height.
    //
    } else if (this->use_nodes_aspect) {
	this->aspect = aspect;
	hd = (double)this->width * this->aspect;
	this->dirty&= ~PixelImageFormat::DirtyAspect;


    //
    // Use only the values store here.
    //
    } else {
	hd = (double)this->width * this->aspect;
    }

    //
    // Round the float value for height and put the result into
    // the text widget.
    //
    height = (int)hd;
    if ((hd - height) >= 0.5) height++;
    sprintf (size_val, "%dx%d", this->width, height);
    if (this->size_val) delete this->size_val;
    this->size_val = DuplicateString(size_val);
    if (this->size_text) {
	if (this->size_timer)
	    XtRemoveTimeOut (this->size_timer);
	this->size_timer = 0;
	XtRemoveCallback (this->size_text, XmNmodifyVerifyCallback,
	    (XtCallbackProc)PixelImageFormat_ModifyCB, (XtPointer)this);
	XmTextSetString (this->size_text, this->size_val);
	XtAddCallback (this->size_text, XmNmodifyVerifyCallback,
	    (XtCallbackProc)PixelImageFormat_ModifyCB, (XtPointer)this);
    }
}
Exemplo n.º 28
0
boolean TutorApplication::initialize(unsigned int* argcp,
			       char**        argv)
{
    ASSERT(argcp);
    ASSERT(argv);

    //
    // Initialize Xt Intrinsics; create the initial shell widget.
    //
    if (!this->IBMApplication::initializeWindowSystem (argcp, argv))
	return FALSE;
    if (!this->IBMApplication::initialize (argcp, argv))
	return FALSE;

    InitializeSignals();
    this->parseCommand(argcp, argv, _TutorOptionList, XtNumber(_TutorOptionList));


    //
    // Get and save the X display structure pointer.
    //
    this->display = XtDisplay(this->getRootWidget());

    //
    // Center the shell and make sure it is not visible.
    //
    XtVaSetValues
	(this->getRootWidget(),
	 XmNmappedWhenManaged, FALSE,
	 XmNx,                 DisplayWidth(this->display, 0) / 2,
	 XmNy,                 DisplayHeight(this->display, 0) / 2,
	 XmNwidth,             1,
	 XmNheight,            1,
	 NULL);

    //
    // Since the instance name of this object was set in the UIComponent
    // constructor before the name of the program was visible, delete the
    // old name and set it to argv[0].
    //
    delete this->name;
    this->name = DuplicateString(argv[0]);

    //
    //
    // Force the initial shell window to exist so dialogs popped up
    // from this shell behave correctly.
    //
    XtRealizeWidget(this->getRootWidget());

    this->setDefaultResources(this->getRootWidget(), _defaultTutorResources);	

    //
    // Get application resources.
    //
    if (NOT TutorApplication::TutorApplicationClassInitialized)
    {
	this->getResources((XtPointer)&TutorApplication::resource,
			   _TutorResourceList,
			   XtNumber(_TutorResourceList));
	TutorApplication::TutorApplicationClassInitialized = TRUE;
    }

    //
    // setup resources that can be environment varialbles.
    //
    if (TutorApplication::resource.UIRoot == NULL) {
        char *s = getenv("DXROOT");
        if (s)
            // POSIX says we better copy the result of getenv(), so...
            // This will show up as a memory leak, not worth worrying about
            TutorApplication::resource.UIRoot = DuplicateString(s);
        else
            TutorApplication::resource.UIRoot =  "/usr/local/dx";
    }

    this->mainWindow = new TutorWindow();
    this->mainWindow->manage();

    this->setBusyCursor(TRUE);

    //
    // Load the initial tutorial page. 
    //
    this->helpOn(TutorApplication::resource.tutorFile);

    //
    // Refresh the screen.
    //
    XmUpdateDisplay(this->getRootWidget());


    this->setBusyCursor(FALSE);

    return TRUE;
}
Exemplo n.º 29
0
void PixelImageFormat::parseImageSize(const char *str)
{
    if ((!str) || (!str[0])) return ;

    char *dimstr = DuplicateString(str);

    boolean width_parsed = FALSE;
    boolean height_parsed = FALSE;
    int width, height;

    char *cp = strchr(dimstr, (int)'x');
    if (!cp) cp = strchr(dimstr, (int)'X');
    if (cp) {
	*cp = '\0';
    }
    if ((!cp) || (cp != dimstr)) {
	int items_parsed = sscanf (dimstr, "%d", &width);
	if (items_parsed == 1) width_parsed = TRUE;
    }
    delete dimstr;


    dimstr = DuplicateString(str);
    cp = strchr(dimstr, (int)'x');
    if (!cp) cp = strchr(dimstr, (int)'X');
    if (cp) {
	cp++;
	if (cp[0]) {
	    int items_parsed = sscanf (cp, "%d", &height);
	    if (items_parsed == 1) height_parsed = TRUE;
	}
    }
    delete dimstr;

    if ((width_parsed) && (height_parsed)) {
	double wd = width;
	double hd = height;
	this->width = width;
	this->aspect = hd / wd;
	this->dirty|= PixelImageFormat::DirtyResolution;
	this->dirty|= PixelImageFormat::DirtyAspect;


    } else if (width_parsed) {
	ImageNode *node = this->dialog->getNode();
	this->width = width;
	node->getAspect(this->aspect);
	this->dirty|= PixelImageFormat::DirtyResolution;
	this->dirty&= ~PixelImageFormat::DirtyAspect;

    } else if (height_parsed) {
	ImageNode *node = this->dialog->getNode();
	node->getAspect(this->aspect);
	double hd = height;
	double wd = hd / this->aspect;
	this->width = (int)wd;
	this->dirty|= PixelImageFormat::DirtyResolution;
	this->dirty&= ~PixelImageFormat::DirtyAspect;

    } else {
	// The user can't type very well.
	int y;
	ImageNode *node = this->dialog->getNode();
	node->getResolution (this->width,y);
	node->getAspect(this->aspect);
	this->dirty&= ~PixelImageFormat::DirtyResolution;
	this->dirty&= ~PixelImageFormat::DirtyAspect;
    }
}
Exemplo n.º 30
0
VOID
InputList_Create(VOID)
{
    INT iLayoutCount;
    HKL *pLayoutList;

    iLayoutCount = GetKeyboardLayoutList(0, NULL);
    pLayoutList = (HKL*) malloc(iLayoutCount * sizeof(HKL));

    if (pLayoutList != NULL)
    {
        if (GetKeyboardLayoutList(iLayoutCount, pLayoutList) > 0)
        {
            INT iIndex;

            for (iIndex = 0; iIndex < iLayoutCount; iIndex++)
            {
                LOCALE_LIST_NODE *pLocale = LocaleList_GetByHkl(pLayoutList[iIndex]);
                LAYOUT_LIST_NODE *pLayout = LayoutList_GetByHkl(pLayoutList[iIndex]);

                if (pLocale != NULL && pLayout != NULL)
                {
                    WCHAR szIndicator[MAX_STR_LEN] = { 0 };
                    INPUT_LIST_NODE *pInput;
                    HKL hklDefault;

                    pInput = InputList_AppendNode();

                    pInput->pLocale = pLocale;
                    pInput->pLayout = pLayout;
                    pInput->hkl     = pLayoutList[iIndex];

                    if (SystemParametersInfoW(SPI_GETDEFAULTINPUTLANG,
                                              0,
                                              (LPVOID)((LPDWORD)&hklDefault),
                                              0) == FALSE)
                    {
                        hklDefault = GetKeyboardLayout(0);
                    }

                    if (pInput->hkl == hklDefault)
                    {
                        pInput->wFlags |= INPUT_LIST_NODE_FLAG_DEFAULT;
                    }

                    if (GetLocaleInfoW(LOWORD(pInput->pLocale->dwId),
                                       LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE,
                                       szIndicator,
                                       ARRAYSIZE(szIndicator)))
                    {
                        size_t len = wcslen(szIndicator);

                        if (len > 0)
                        {
                            szIndicator[len - 1] = 0;
                            pInput->pszIndicator = DuplicateString(szIndicator);
                        }
                    }
                }
            }
        }

        free(pLayoutList);
    }
}