Skip to content

Commit

Permalink
Changed windows Resources and TinyURL.c to load from stringtables.
Browse files Browse the repository at this point in the history
  • Loading branch information
AraHaan committed Sep 12, 2017
1 parent 3ed8827 commit e3863b3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ app/TinyURL.rc
app/TinyURL.sln
app/TinyURL.vcxproj
app/TinyURL.vcxproj.filters
app/__main__.py

# Installer logs
pip-log.txt
Expand Down
22 changes: 21 additions & 1 deletion app/make_msvc_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def generate_tinyurl_rc():
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -70,7 +71,22 @@ def generate_tinyurl_rc():
//
// RCDATA
//
IDR_RCDATA1 RCDATA \"__main__.py\"
IDR_RCDATA1 RCDATA \"__main__.py\"
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING1 \"Fatal error: out of memory\\n\"
IDS_STRING2 \"Fatal error: unable to decode the command line argument #%i\\n\"
IDS_STRING3 \"Fatal error: Python script is empty.\\n\"
IDS_STRING4 \"Fatal error: Python is not initialized.\\n\"
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -99,6 +115,10 @@ def generate_resource_h():
//
#define IDI_MAINICON 1
#define IDR_RCDATA1 1
#define IDS_STRING1 1
#define IDS_STRING2 2
#define IDS_STRING3 3
#define IDS_STRING4 4
// Next default values for new objects
//
Expand Down
27 changes: 23 additions & 4 deletions app/make_tinyurl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,34 @@ def generate_tinyurl_c():
int i;
argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
if (!argv_copy) {
fprintf(stderr, "out of memory\\n");
#ifdef _WIN32
LPSTR buffer1[28];
LoadString(GetModuleHandle(NULL), IDS_STRING1, (LPSTR)buffer1, 28);
fprintf(stderr, (const char *const)buffer1);
#else
fprintf(stderr, "Fatal error: out of memory\\n");
#endif
exit(1);
}
for (i = 0; i < argc; i++) {
argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
if (!argv_copy[i]) {
#ifdef _WIN32
LPSTR buffer2[61];
LoadString(GetModuleHandle(NULL), IDS_STRING2, (LPSTR)buffer2, 61);
fprintf(stderr, (const char *const)buffer2, i + 1);
#else
fprintf(stderr, "Fatal error: "
"unable to decode the command line argument #%i\\n",
i + 1);
#endif
exit(1);
}
}
argv_copy[argc] = NULL;
Py_SetProgramName(argv_copy[0]);
Py_Initialize();
int initialized = Py_IsInitialized();
if (initialized != 0) {
if (Py_IsInitialized() != 0) {
/*
* allows use of sys.argv to be possible
* with no tracebacks.
Expand All @@ -75,7 +86,9 @@ def generate_tinyurl_c():
if (script_size >= 0) {
err = PyRun_SimpleString((const char *)pmain_script);
} else {
fprintf(stderr, "Fatal error: Python script is empty.\\n");
LPSTR buffer3[38];
LoadString(GetModuleHandle(NULL), IDS_STRING3, (LPSTR)buffer3, 38);
fprintf(stderr, (const char *const)buffer3);
}
#else
err = PyRun_SimpleString(\""""
Expand All @@ -90,7 +103,13 @@ def generate_tinyurl_c():
PyErr_Print();
Py_Finalize();
} else {
#ifdef _WIN32
LPSTR buffer4[41];
LoadString(GetModuleHandle(NULL), IDS_STRING4, (LPSTR)buffer4, 41);
fprintf(stderr, (const char *const)buffer4);
#else
fprintf(stderr, "Fatal error: Python is not initialized.\\n");
#endif
}
for (i = 0; i < argc; i++) {
PyMem_RawFree(argv_copy[i]);
Expand Down

0 comments on commit e3863b3

Please sign in to comment.