Skip to content
Snippets Groups Projects
Commit 1d83d4f1 authored by zi ming's avatar zi ming
Browse files

revised lab3

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 248 additions and 0 deletions
import locale
import time
## Sets locale to sweden
locale.setlocale(locale.LC_ALL, "sv_SE.UTF8")
## random float
f = 1.2345
## Change float to use Swedish numeric system (up to 6 s.f)
f = locale.format_string("%.6g", f)
print(f)
## Prints out the current time in swedish datetime format
print (time.strftime("%a, %d %b %Y %H:%M:%S"))
cpp-linux
cpp-*.txt
win32.txt
Makefile.qt
QtCopyFile
qt.txt
SOURCE=马Häst马.txt
all: cpp-linux.txt win32.txt cpp-win32.txt
ls -lh $^
win32.txt: win32.exe $(SOURCE)
rm -f $@
wine $<
test -f $@
win32.exe: win32.c
x86_64-w64-mingw32-gcc -o $@ $<
cpp-win32.txt: cpp-win32.exe $(SOURCE)
rm -f $@
wine $< $@
test -f $@
cpp-win32.exe: cpp17.cpp
x86_64-w64-mingw32-g++ -o $@ -std=c++17 cpp17.cpp -static -lstdc++fs
cpp-linux.txt: cpp-linux $(SOURCE)
rm -f $@
./$< $@
cpp-linux: cpp17.cpp
clang++ -Wall -std=c++17 -o $@ $< -lstdc++fs
qt.txt: QtCopyFile
rm -f $@
./$< $@
QtCopyFile: Makefile.qt qt.cpp
$(MAKE) -f Makefile.qt
Makefile.qt: Qt.pro
qmake -o $@ $<
QT += core
TARGET = QtCopyFile
SOURCES += qt.cpp
/* In case the C++-compiler is too old for std::filesystem */
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
#include <assert.h>
int main(int argc, char** argv)
{
assert(argc==2); /* argv[1] is the destination file */
/* Your code here */
fs::path p = fs::u8path(u8"马Häst马.txt");
fs::copy(p, "cpp17.txt");
return 0;
}
Häst is the Swedish word for horse.
马 is the Chinese word for horse.
Horse is the English word for horse.
#include <assert.h>
#include <QTextCodec>
#include <QFile>
#include <QString>
int main(int argc, char** argv)
{
/* Make sure we use UTF-8 for file names; this is needed for the IDA labs */
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
assert(argc==2); /* argv[1] is the destination file */
/* Your code here */
QString unicodeString = QString::fromUtf8("马Häst马.txt");
QFile::copy(unicodeString, "qt.txt");
return 0;
}
/*
This is an example of what cp --reflink=always does. It only works on
filesystems that support cloning of files. In most Linux filesystems,
you can hardlink two files, making them the same. But if you update
either file, both are updated (they are the same). With a reflink, when
you update one of the files a copy is created at that time (making the
write expensive but the copy fast); perhaps only creating copies of some
blocks in the file.
This is not part of the labs since the file systems at IDA will not support it.
*/
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(int argc, char **argv) {
int dest_fd, src_fd;
src_fd = open("a", O_RDONLY);
dest_fd = open("b", O_WRONLY); /* Needs to exist; not checking this */
if (ioctl(dest_fd, FICLONE, src_fd) < 0) {
fprintf(stderr, "error: %s\n", strerror(errno));
return 1;
}
return 0;
}
#include <windows.h>
#include <assert.h>
int main(int argc, char **argv)
{
assert(argc==1);
/* Your code here. */
wchar_t *str = L"马Häst马.txt";
wchar_t *str2 = L"win32.txt";
CopyFileW(str,str2,0);
// printf("Press Any Key to Continue\n");
// getchar();
return 0;
}
File added
Häst is the Swedish word for horse.
马 is the Chinese word for horse.
Horse is the English word for horse.
*-main.c*
*.mo
gettext
*.qm
qt-linguist
Makefile.linguist
QT += core
TARGET = qt-linguist
SOURCES += linguist-main.cpp setuplocale.c linguist.cpp
TRANSLATIONS = example_sv.ts
.PHONY: qt-linguist
all: gettext-main.c linguist-main.cpp gettext qt-linguist
gettext: gettext-main.c setuplocale.c gettext.c
gettext-main.c: base.c
cp $< $@
linguist-main.cpp: base.c
cp $< $@
qt-linguist: Makefile.linguist
$(MAKE) -f Makefile.linguist
Makefile.linguist: Linguist.pro
qmake -o $@ $<
#include <stdio.h>
#if __cplusplus
extern "C" void setuplocale();
#else
void setup();
void setuplocale();
#endif
int main(int argc, char** argv)
{
setuplocale();
#if __cplusplus
/* For Qt: Your code here as it is more convenient than a separate function in C++.
* Setup a QCoreApplication (an application without GUI) and install a translator.
*/
#else
setup();
#endif
/* You need to update this code to output translated strings
* Note that you should make gettext-main.c linguist-main.c and modify
* those files rather than base.c
*/
puts("The current language is the default (C/POSIX)\n");
puts("The horse can run.\n");
puts("How fast can the horse run?\n");
puts("It typically runs at speed of less than 50 km/h.\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <locale.h>
#define _(STRING) gettext(STRING)
void setup()
{
/* Your code here. Setup a domain for gettext. */
bindtextdomain ("messages", ".");
bind_textdomain_codeset("messages", "utf8");
textdomain ("messages");
}
/* You may use this file if you prefer it over writing directly in linguist-main.cpp */
File added
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
void setuplocale()
{
/* Usually, the locale is taken from the user's environment.
* We have hard-coded a locale for purposes of this lab.
*/
char *newlocale, *targetLocale = "sv_SE.utf8";
setenv("LANGUAGE", targetLocale, 1);
setenv("LANG", targetLocale, 1);
setenv("LC_MESSAGES", targetLocale, 1);
newlocale = setlocale(LC_MESSAGES, targetLocale);
if (newlocale == NULL) {
fprintf(stderr, "Error: %s locale not installed (perhaps use a different hard-coded locale as a work-around)\n", targetLocale);
exit(1);
}
printf("Set locale to: %s\n", newlocale);
}
test*
unicode
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment