mrg_ui/src/mtktextbuffer.cxx
//============================================================================
// Load this textBuffer with the contents of the named file.
//
Load this textBuffer with the contents of the named file.
Load this textBuffer with the contents of the named file .
void textBuffer::LoadFile(char *fname)
{
	FILE *fl = fopen(fname, "r");
	if(fl == NULL)
		return;
	fseek(fl, 0, SEEK_END);
	long size = ftell(fl);
	fseek(fl, 0, SEEK_SET);
	char *ptr = (char *)malloc(size + 1);
	if(ptr == NULL){
		fclose(fl);
		return;
	}
	int actual_size = fread(ptr, 1, size, fl);
	if(actual_size == 0){
		fclose(fl);
		free(ptr);
		return;
	}
	ptr[actual_size] = 0;
	fclose(fl);
	framework.Tcl("%s cget -state", tk_name.str());
	boolean read_only = (strcmp(framework.interp->result, "disabled") == 0);
	if (read_only) {
	    framework.Tcl("%s configure -state normal", tk_name.str());
	}
	SetText(ptr);
	if (read_only) {
	    framework.Tcl("%s configure -state disabled", tk_name.str());
	}
	free(ptr);
}
void textBuffer :: LoadFile ( char * fname ) { FILE * fl = fopen ( fname , " " ) ; if ( fl == NULL ) return ; fseek ( fl , 0 , SEEK_END ) ; long size = ftell ( fl ) ; fseek ( fl , 0 , SEEK_SET ) ; char * ptr = ( char * ) malloc ( size + 1 ) ; if ( ptr == NULL ) { fclose ( fl ) ; return ; } int actual_size = fread ( ptr , 1 , size , fl ) ; if ( actual_size == 0 ) { fclose ( fl ) ; free ( ptr ) ; return ; } ptr [ actual_size ] = 0 ; fclose ( fl ) ; framework . Tcl ( " " , tk_name . str ( ) ) ; boolean read_only = ( strcmp ( framework . interp -> result , " " ) == 0 ) ; if ( read_only ) { framework . Tcl ( " " , tk_name . str ( ) ) ; } SetText ( ptr ) ; if ( read_only ) { framework . Tcl ( " " , tk_name . str ( ) ) ; } free ( ptr ) ; }
Load this textBuffer with the contents of the named file.
Load this textBuffer with the contents of the named file .