Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hal/classicladder/classicladder_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ cairo_t * InitExportSurface( int SurfaceWidth, int SurfaceHeight, char * SvgFile

void ExportSvgOrPngFile( char * FileToCreate, char GoForSvgExport )
{
cairo_t *cr;
cairo_t *cr = NULL;
int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;
if ( iCurrentLanguage==SECTION_IN_LADDER )
{
Expand Down
11 changes: 6 additions & 5 deletions src/hal/classicladder/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ int PrintRightMarginNumExpr = 0;
int PrintRightMarginPosiX;
int PrintRightMarginWidth;

void CreateVarNameForElement( char * pBuffToWrite, StrElement * pElem, char SymbolsVarsNamesIfAvail )
void CreateVarNameForElement( char * pBuffToWrite, size_t BuffSize, StrElement * pElem, char SymbolsVarsNamesIfAvail )
{
char VarIndexBuffer[20];
if ( pElem->IndexedVarType!=-1 )
{
// buffer for index required as CreateVarName() returns on a static buffer !
rtapi_strxcpy( VarIndexBuffer, CreateVarName(pElem->IndexedVarType,pElem->IndexedVarNum,SymbolsVarsNamesIfAvail) );
snprintf( pBuffToWrite, sizeof(pBuffToWrite), "%s", CreateVarName(pElem->VarType,pElem->VarNum,SymbolsVarsNamesIfAvail) );
snprintf( pBuffToWrite, BuffSize, "%s", CreateVarName(pElem->VarType,pElem->VarNum,SymbolsVarsNamesIfAvail) );
}
else
{
Expand Down Expand Up @@ -215,11 +215,12 @@ char * DrawExprForCompareOperate( cairo_t * cr, int BaseX, int BaseY, int Width,
if ( DrawingOption==DRAW_FOR_PRINT )
{
// print the expression entirely in the right margin
char * pReportNumAndText = malloc( strlen(Text)+10 );
size_t TextSize;
char * pReportNumAndText = malloc( TextSize = strlen(Text)+10 );
if ( pReportNumAndText )
{
int Hgt;
snprintf( pReportNumAndText, sizeof(pReportNumAndText), "(*%d) ", PrintRightMarginNumExpr );
snprintf( pReportNumAndText, TextSize, "(*%d) ", PrintRightMarginNumExpr );
strcat( pReportNumAndText, Text );
Hgt = DrawPangoTextOptions( cr, PrintRightMarginPosiX, PrintRightMarginExprPosiY, PrintRightMarginWidth, 0/*Height*/, pReportNumAndText, FALSE/*CenterAlignment*/ );
PrintRightMarginExprPosiY += Hgt;
Expand Down Expand Up @@ -744,7 +745,7 @@ cairo_stroke( cr );
case ELE_OUTPUT_NOT:
case ELE_OUTPUT_SET:
case ELE_OUTPUT_RESET:
CreateVarNameForElement( BufTxt, &Element, InfosGene->DisplaySymbols );
CreateVarNameForElement( BufTxt, sizeof(BufTxt), &Element, InfosGene->DisplaySymbols );
DrawPangoText( cr, x, y+HeiDiv4+1, Width, -1, BufTxt );
break;
case ELE_OUTPUT_JUMP:
Expand Down
2 changes: 1 addition & 1 deletion src/hal/classicladder/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define DRAW_FOR_TOOLBAR 1
#define DRAW_FOR_PRINT 2

void CreateVarNameForElement( char * pBuffToWrite, StrElement * pElem, char SymbolsVarsNamesIfAvail );
void CreateVarNameForElement( char * pBuffToWrite, size_t BuffSize, StrElement * pElem, char SymbolsVarsNamesIfAvail );
char * DisplayArithmExpr(char * Expr, char SymbolsVarsNamesIfAvail);
void CreateFontPangoLayout( cairo_t *cr, int BlockPxHeight, char DrawingOption );
int DrawPangoText( cairo_t * cr, int BaseX, int BaseY, int Width, int Height, char * Text );
Expand Down
2 changes: 1 addition & 1 deletion src/hal/classicladder/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void LoadElementProperties(StrElement * Element)
case ELE_OUTPUT_SET:
case ELE_OUTPUT_RESET:
rtapi_strxcpy(TextToWrite,CreateVarName(Element->VarType,Element->VarNum, InfosGene->DisplaySymbols));
// CreateVarNameForElement( TextToWrite, Element, InfosGene->DisplaySymbols );
// CreateVarNameForElement( TextToWrite, sizeof(TextToWrite), Element, InfosGene->DisplaySymbols );
SetProperty(0,_("Variable"),TextToWrite,TRUE);
break;
case ELE_OUTPUT_JUMP:
Expand Down
22 changes: 16 additions & 6 deletions src/hal/classicladder/files_project.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ char JoinFiles( char * DirAndNameOfProject, char * TmpDirectoryFiles )
while( !feof( pParametersFile ) )
{
char Buff[ 300 ];
fgets( Buff, 300, pParametersFile );
if (!feof(pParametersFile))
if (!fgets( Buff, sizeof(Buff), pParametersFile ) )
{
fputs( Buff, pProjectFile );
break;
}
fputs( Buff, pProjectFile );
}
fclose( pParametersFile );
snprintf(BuffTemp, sizeof(BuffTemp), "_/FILE-%s\n", pEnt->d_name );
Expand Down Expand Up @@ -271,13 +271,20 @@ char SplitFiles( char * DirAndNameOfProject, char * TmpDirectoryFiles )
{

/* start line of project ?*/
fgets( Buff, 300, pProjectFile );
if( !fgets( Buff, sizeof(Buff), pProjectFile ) )
{
fclose(pProjectFile);
return FALSE;
}
if ( strncmp( Buff, "_FILES_CLASSICLADDER", strlen( "_FILES_CLASSICLADDER" ) )==0 )
{

while( !feof( pProjectFile ) )
{
fgets( Buff, 300, pProjectFile );
if( !fgets( Buff, sizeof(Buff), pProjectFile ) )
{
break;
}
if ( !feof( pProjectFile ) )
{
// header line for a file parameter ?
Expand Down Expand Up @@ -306,7 +313,10 @@ ParametersFile[ strlen(ParametersFile)-1 ] = '\0';
fputs( Buff, pParametersFile );
while( !feof( pProjectFile ) && !cEndOfFile )
{
fgets( Buff, 300, pProjectFile );
if ( !fgets( Buff, sizeof(Buff), pProjectFile ) )
{
break;
}
if (strncmp(Buff,"_/FILE-",strlen("_/FILE-")) !=0)
{
if (!feof(pProjectFile))
Expand Down
41 changes: 40 additions & 1 deletion src/hal/classicladder/serial_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ void SerialSetRTS( int State )

void SerialSend( char *Buff, int BuffLength )
{
ssize_t written = 0;

if ( BuffLength <= 0 )
return; // write() on zero length is undefined

if ( PortIsOpened )
{
if ( ModbusConfig.ModbusSerialUseRtsToSend )
Expand All @@ -191,7 +196,41 @@ void SerialSend( char *Buff, int BuffLength )
}
if ( ModbusConfig.ModbusDebugLevel>=2 )
printf(_("Serial writing...\n"));
write(fd,Buff,BuffLength);
// Writing a buffer to a serial port may write fewer than
// requested. We must repeat the write from where it stopped.
while ( BuffLength - written > 0 )
{
ssize_t n = write(fd, Buff + written, BuffLength - written);
if (n < 0)
{
// Interrupted by signal
if (errno == EINTR)
continue;

// We shouldn't be able to get EAGAIN because
// fd is changed from non-blocking to blocking
// after open.

// Getting here means something went really
// wrong... What else to do?
perror(_("Serial port write failed"));
if ( ModbusConfig.ModbusSerialUseRtsToSend )
{
tcdrain( fd );
DoPauseMilliSecs( 10 );
SerialSetRTS( 0 );
}
// SerialClose(); // This might be prudent after the failure...
return;
}
// n being zero could happen if another thread closes
// fd causing a spectacular problem. But I guess we are
// single threaded here. So we will take it to be a
// 'warning' and try to continue. It would busy-loop if
// we only get zero back, but you should get an error
// somewhere down the line.
written += n; // We have written n bytes this round
}
if ( ModbusConfig.ModbusDebugLevel>=2 )
printf(_("Writing done!\n"));
if ( ModbusConfig.ModbusSerialUseRtsToSend )
Expand Down