Skip to content

Commit

Permalink
Fix build failure in mingw.
Browse files Browse the repository at this point in the history
  • Loading branch information
virxkane committed Apr 30, 2021
1 parent 4290b99 commit eb92a18
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fc-lang_conv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ set(SRC_LIST
main.c
)

if(WIN32)
set(SRC_LIST ${SRC_LIST}
getline_win32.c
)
endif(WIN32)

set(LDADD_LIBS)
if(WIN32)
# -mconsole -> console application (with terminal screen)
Expand Down
56 changes: 56 additions & 0 deletions fc-lang_conv/getline_win32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "getline_win32.h"
#include <stdlib.h>

#ifdef _WIN32
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
{
if (!lineptr || !n || !stream)
return -1;
if (*n == 0)
{
if (!*lineptr)
{
*lineptr = (char*)malloc(16);
if (*lineptr)
*n = 16;
else
return -1;
}
else
return -1;
}
char c;
ssize_t count = 0;
size_t ret;
char* ptr = *lineptr;
while (1)
{
ret = fread(&c, 1, 1, stream);
if (ret != 1)
break;
if (*n <= count + 1)
{
char* tmp = (char*)realloc(*lineptr, *n + 16);
if (tmp)
{
*lineptr = tmp;
*n += 16;
ptr = *lineptr + count;
}
else
{
// memory error
count = -1;
break;
}
}
*ptr = c;
ptr++;
count++;
if (c == '\n')
break;
}
*ptr = 0;
return count;
}
#endif
20 changes: 20 additions & 0 deletions fc-lang_conv/getline_win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef GETLINE_WIN32_H
#define GETLINE_WIN32_H

#include <stdio.h>

#ifdef _WIN32

#ifdef __cplusplus
extern "C" {
#endif

ssize_t getline(char **lineptr, size_t *n, FILE *stream);

#ifdef __cplusplus
}
#endif

#endif // _WIN32

#endif // GETLINE_WIN32_H
5 changes: 5 additions & 0 deletions src/mainwnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ GMainWindow::GMainWindow(QWidget *parent)
ui->textColorBox->setDefaultColor(QColor(Qt::black));
ui->backgroundColorBox->setDefaultColor(QColor::fromRgb(200, 240, 255));

#ifdef _WIN32
// Override default font file
ui->fontLineEdit->setText("c:/Windows/Fonts/NotoSerif-Regular.ttf");
#endif

onFontChanged();
}

Expand Down

0 comments on commit eb92a18

Please sign in to comment.