From 8aac47f84d3b77b8108d2a068b499b6de8d497a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 31 Oct 2010 22:05:29 +0000 Subject: [PATCH] [EXAMPLES] * BUG: Fix the Database example. [INTERPRETER] * BUG: Fix unchecked system calls. [ARCHIVER] * BUG: Prevent the archiver from putting the executable file into itself, leading to a endless growing generated file. * NEW: Files having the ".gambas" extension are now excluded from executable archives. [GB.DB.FORM] * BUG: Remove the DataBrowser.Adjust property. git-svn-id: svn://localhost/gambas/trunk@3272 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- TODO | 1 + comp/src/gb.db.form/.info | 6 +-- comp/src/gb.db.form/.lang/.pot | 8 ++-- comp/src/gb.db.form/.src/DataBrowser.class | 25 +++++----- examples/examples/Database/Database/.project | 2 +- .../Database/Database/.src/FRequest.class | 16 +++---- examples/examples/Drawing/Painting/.icon.png | Bin 4159 -> 4175 bytes examples/examples/Drawing/Painting/.project | 2 +- main/gbc/gba.c | 17 +++++-- main/gbc/gbc.c | 14 ++---- main/gbc/gbc_archive.c | 44 ++++++++++++++---- main/gbx/gbx_archive.c | 2 +- main/gbx/gbx_c_application.c | 6 ++- main/gbx/gbx_c_process.c | 8 ++-- main/gbx/gbx_class_load.c | 9 ++-- main/gbx/gbx_project.c | 4 +- main/gbx/gbx_subr_file.c | 2 +- main/share/gb_file_share.h | 2 +- main/share/gb_file_temp.h | 12 ++++- 19 files changed, 110 insertions(+), 70 deletions(-) diff --git a/TODO b/TODO index 80ff8a181..6da2cd88b 100644 --- a/TODO +++ b/TODO @@ -42,6 +42,7 @@ GUI RELATED STUFF - ValueBox.Value should be visible in the IDE. - GridView automatic column resizing by code in gb.gtk, and in gb.qt. - Moveable tabs. +- ListView and GridView selection interface should be the same. DESKTOP COMPONENT diff --git a/comp/src/gb.db.form/.info b/comp/src/gb.db.form/.info index b25afa36e..54edd04a0 100644 --- a/comp/src/gb.db.form/.info +++ b/comp/src/gb.db.form/.info @@ -21,10 +21,6 @@ Orientation p i -Adjust -p -b - Editable p b @@ -32,7 +28,7 @@ b _Properties C s -*,Control=True,Adjust,Columns{Field[]},Editable,Header=True,Orientation{Align.Bottom;Left;Right;Top}=Bottom +*,Control=True,Columns{Field[]},Editable,Header=True,Orientation{Align.Bottom;Left;Right;Top}=Bottom _Group C s diff --git a/comp/src/gb.db.form/.lang/.pot b/comp/src/gb.db.form/.lang/.pot index 2554af1d3..8bc5cf7d1 100644 --- a/comp/src/gb.db.form/.lang/.pot +++ b/comp/src/gb.db.form/.lang/.pot @@ -10,6 +10,10 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#: .project:1 +msgid "Data bound controls" +msgstr "" + #: DataControl.class:84 DataView.class:354 msgid "True" msgstr "" @@ -117,7 +121,3 @@ msgstr "" #: FTest.class:76 msgid "Remove" msgstr "" - -#: .project:1 -msgid "Data bound controls" -msgstr "" diff --git a/comp/src/gb.db.form/.src/DataBrowser.class b/comp/src/gb.db.form/.src/DataBrowser.class index b0b2a6a8d..be9f53121 100644 --- a/comp/src/gb.db.form/.src/DataBrowser.class +++ b/comp/src/gb.db.form/.src/DataBrowser.class @@ -9,10 +9,9 @@ Property Control As Boolean Property Read View As TableView Property Header As Boolean Property Orientation As Integer -Property Adjust As Boolean Property Editable As Boolean -Public Const _Properties As String = "*,Control=True,Adjust,Columns{Field[]},Editable,Header=True,Orientation{Align.Bottom;Left;Right;Top}=Bottom" +Public Const _Properties As String = "*,Control=True,Columns{Field[]},Editable,Header=True,Orientation{Align.Bottom;Left;Right;Top}=Bottom" Public Const _Group As String = "Data" Private $hForm As FBrowser @@ -97,17 +96,17 @@ Private Sub Orientation_Write(Value As Integer) End -Private Function Adjust_Read() As Boolean - - Return $hForm.DataView.Adjust - -End - -Private Sub Adjust_Write(Value As Boolean) - - $hForm.DataView.Adjust = Value - -End +' Private Function Adjust_Read() As Boolean +' +' Return $hForm.DataView.Adjust +' +' End +' +' Private Sub Adjust_Write(Value As Boolean) +' +' $hForm.DataView.Adjust = Value +' +' End Public Sub _OnDatabaseChange() diff --git a/examples/examples/Database/Database/.project b/examples/examples/Database/Database/.project index bcbaa2931..3db87699b 100644 --- a/examples/examples/Database/Database/.project +++ b/examples/examples/Database/Database/.project @@ -1,5 +1,5 @@ # Gambas Project File 3.0 -# Compiled with Gambas 2.99.0 (r3194) +# Compiled with Gambas 2.99.0 Startup=FMain Icon=database.png Version=0.0.1 diff --git a/examples/examples/Database/Database/.src/FRequest.class b/examples/examples/Database/Database/.src/FRequest.class index cb095f350..bff8a5316 100644 --- a/examples/examples/Database/Database/.src/FRequest.class +++ b/examples/examples/Database/Database/.src/FRequest.class @@ -82,35 +82,35 @@ Public Sub tbvData_Data(Row As Integer, Column As Integer) End -Private Function WidthFromType(hCtrl As control, iType As Integer, iLength As Integer, sTitle As String) As Integer +Private Function WidthFromType(hCtrl As Control, iType As Integer, iLength As Integer, sTitle As String) As Integer Dim iWidth As Integer Select Case iType Case gb.Boolean - iWidth = hCtrl.Font.Width(Str(False)) + 32 + iWidth = hCtrl.Font.TextWidth(Str(False)) + 32 Case gb.Integer - iWidth = hCtrl.Font.Width("1234567890") + 16 + iWidth = hCtrl.Font.TextWidth("1234567890") + 16 Case gb.Long - iWidth = hCtrl.Font.Width("12345678901234567890") + 16 + iWidth = hCtrl.Font.TextWidth("12345678901234567890") + 16 Case gb.Float - iWidth = hCtrl.Font.Width(CStr(Pi) & "E+999") + 16 + iWidth = hCtrl.Font.TextWidth(CStr(Pi) & "E+999") + 16 Case gb.Date - iWidth = hCtrl.Font.Width(Str(Now)) + 16 + iWidth = hCtrl.Font.TextWidth(Str(Now)) + 16 Case gb.String If iLength = 0 Then iLength = 255 iLength = Min(32, iLength) - iWidth = hCtrl.Font.Width("X") * iLength + 16 + iWidth = hCtrl.Font.TextWidth("X") * iLength + 16 End Select - iWidth = Max(iWidth, hCtrl.Font.Width(sTitle) + 8) + iWidth = Max(iWidth, hCtrl.Font.TextWidth(sTitle) + 8) Return iWidth diff --git a/examples/examples/Drawing/Painting/.icon.png b/examples/examples/Drawing/Painting/.icon.png index cda5345c354f402a389a51a097e497e873cfd182..40a0b60a4a415ed221632bdee31c2fbd55096960 100644 GIT binary patch delta 24 ecmdn5a9&}83NK5slV=DA5Y%v_bZk_V6952Nj|O%C delta 10 RcmX@FuwP+<%0?4u0RR`$1Csy% diff --git a/examples/examples/Drawing/Painting/.project b/examples/examples/Drawing/Painting/.project index 4467c0cd7..6430248bd 100644 --- a/examples/examples/Drawing/Painting/.project +++ b/examples/examples/Drawing/Painting/.project @@ -1,5 +1,5 @@ # Gambas Project File 3.0 -# Compiled with Gambas 2.99.0 (r3067) +# Compiled with Gambas 2.99.0 Title=Anti-Aliased Drawing Startup=FMain Icon=icon.png diff --git a/main/gbc/gba.c b/main/gbc/gba.c index 1230c523c..d5a0b7636 100644 --- a/main/gbc/gba.c +++ b/main/gbc/gba.c @@ -63,7 +63,7 @@ static char **path_list; static int path_current; static const char *allowed_hidden_files[] = { ".gambas", ".info", ".list", ".lang", ".action", ".connection", NULL }; -static const char *remove_ext_root[] = { "module", "class", "form", "gambas", NULL }; +//static const char *remove_ext_root[] = { "module", "class", "form", "gambas", NULL }; static const char *remove_ext_lang[] = { "pot", "po", NULL }; static bool _extract = FALSE; @@ -193,7 +193,7 @@ static void path_init(const char *first) ARRAY_create(&path_list); if (*first) - chdir(first); + FILE_chdir(first); path_add(FILE_get_current_dir()); @@ -314,6 +314,10 @@ int main(int argc, char **argv) continue; file = FILE_cat(path, file_name, NULL); + + // Do not put the archive file inside itself. + if (!strcmp(file, ARCH_output)) + continue; if (stat(file_name, &info)) { @@ -335,9 +339,9 @@ int main(int argc, char **argv) //printf("path = %s\n", &path[len_prefix]); - if (path[len_prefix] == 0) - remove_ext = remove_ext_root; - else if (strcmp(&path[len_prefix], "/.lang") == 0) + //if (path[len_prefix] == 0) + // remove_ext = remove_ext_root; + if (strcmp(&path[len_prefix], "/.lang") == 0) remove_ext = remove_ext_lang; else remove_ext = 0; @@ -353,6 +357,9 @@ int main(int argc, char **argv) if (*p != NULL) continue; } + + if (strcmp(ext, "gambas") == 0) + continue; ARCH_add_file(file); } diff --git a/main/gbc/gbc.c b/main/gbc/gbc.c index 7cf04d67e..920c92a41 100644 --- a/main/gbc/gbc.c +++ b/main/gbc/gbc.c @@ -215,7 +215,7 @@ static void get_arguments(int argc, char **argv) /*COMP_project = STR_copy(FILE_cat(argv[optind], "Gambas", NULL));*/ if (optind < argc) - chdir(argv[optind]); + FILE_chdir(argv[optind]); dir = FILE_get_current_dir(); if (!dir) @@ -374,17 +374,11 @@ static void init_files(const char *first) ARRAY_create(&_files); if (*first) - { - if (chdir(first)) - { - fprintf(stderr, "gbc: cannot switch to directory: %s\n", first); - exit(1); - } - } + FILE_chdir(first); recursive = chdir(".src") == 0; fill_files(FILE_get_current_dir(), recursive); - if (recursive) chdir(".."); + if (recursive) FILE_chdir(".."); // Sort paths qsort(_files, ARRAY_count(_files), sizeof(*_files), (int (*)(const void *, const void *))compare_path); @@ -424,7 +418,7 @@ int main(int argc, char **argv) { if (main_verbose) puts("Removing .info and .list files"); - chdir(FILE_get_dir(COMP_project)); + FILE_chdir(FILE_get_dir(COMP_project)); unlink(".info"); unlink(".list"); } diff --git a/main/gbc/gbc_archive.c b/main/gbc/gbc_archive.c index ee8b07aaf..b3213a1f2 100644 --- a/main/gbc/gbc_archive.c +++ b/main/gbc/gbc_archive.c @@ -45,6 +45,8 @@ /*#define DEBUG*/ +#define TEMP_EXEC ".temp.gambas" + char *ARCH_project; char *ARCH_project_name; char *ARCH_output = NULL; @@ -101,22 +103,46 @@ static void write_string(const char *str, int len) static void make_executable(void) { + const char *err; struct stat info; - if (stat(ARCH_output, &info) == 0) - if (chmod(ARCH_output, info.st_mode | S_IXUSR | S_IXGRP | S_IXOTH) == 0) - { - FILE_set_owner(ARCH_output, FILE_cat(FILE_get_dir(ARCH_project), ".project", NULL)); - return; - } + FILE_chdir(FILE_get_dir(ARCH_project)); + + if (stat(TEMP_EXEC, &info) || chmod(TEMP_EXEC, info.st_mode | S_IXUSR | S_IXGRP | S_IXOTH)) + { + err = "Cannot change executable permissions"; + goto __ERROR; + } - THROW("Cannot make executable: &1", strerror(errno)); + FILE_set_owner(TEMP_EXEC, FILE_cat(FILE_get_dir(ARCH_project), ".project", NULL)); + + if (FILE_exist(ARCH_output) && unlink(ARCH_output)) + { + err = "Cannot remove previous executable"; + goto __ERROR; + } + + if (rename(TEMP_EXEC, ARCH_output)) + { + err = "Cannot create executable"; + goto __ERROR; + } + + return; + +__ERROR: + + THROW("Cannot make executable: &1: &2", err, strerror(errno)); } void ARCH_define_output(const char *path) { STR_free(ARCH_output); + + if (path && *path != '/') + path = FILE_cat(FILE_get_current_dir(), path, NULL); + ARCH_output = STR_copy(path); } @@ -129,7 +155,7 @@ void ARCH_define_project(const char *project) if (project == NULL) project = FILE_get_current_dir(); - chdir(project); + FILE_chdir(project); dir = STR_copy(FILE_get_current_dir()); arch_dir_pos = strlen(dir) + 1; @@ -159,7 +185,7 @@ void ARCH_init(void) ALLOC(&arch_buffer, 4096, "ARCH_init"); - arch_file = fopen(ARCH_output, "w"); + arch_file = fopen(".temp.gambas", "w"); if (arch_file == NULL) THROW("Cannot create temporary archive file: &1", ARCH_output); diff --git a/main/gbx/gbx_archive.c b/main/gbx/gbx_archive.c index 33ece3893..5e6c72575 100644 --- a/main/gbx/gbx_archive.c +++ b/main/gbx/gbx_archive.c @@ -280,7 +280,7 @@ bool ARCHIVE_get(ARCHIVE *arch, const char **ppath, ARCHIVE_FIND *find) if (get_current(&arch, ppath)) { // no archive found, we try a lstat - chdir(PROJECT_path); + FILE_chdir(PROJECT_path); if (stat(*ppath, &buf)) return TRUE; diff --git a/main/gbx/gbx_c_application.c b/main/gbx/gbx_c_application.c index c508463f1..66af5e97b 100644 --- a/main/gbx/gbx_c_application.c +++ b/main/gbx/gbx_c_application.c @@ -354,8 +354,10 @@ BEGIN_PROPERTY(System_Domain) char buffer[256]; - getdomainname(buffer, 255); - GB_ReturnNewZeroString(buffer); + if (getdomainname(buffer, 255)) + GB_Error("Unable to retrieve domain name: &1", strerror(errno)); + else + GB_ReturnNewZeroString(buffer); END_PROPERTY diff --git a/main/gbx/gbx_c_process.c b/main/gbx/gbx_c_process.c index 018e6852b..c48a090f9 100644 --- a/main/gbx/gbx_c_process.c +++ b/main/gbx/gbx_c_process.c @@ -538,7 +538,7 @@ static void run_process(CPROCESS *process, int mode, void *cmd, CARRAY *env) } // Return to the parent working directory - chdir(PROJECT_oldcwd); + FILE_chdir(PROJECT_oldcwd); if (env) { @@ -569,7 +569,8 @@ static void callback_child(int fd, int type, void *data) /*old = signal(SIGCHLD, signal_child);*/ - read(fd, (char *)&buffer, 1); + if (read(fd, (char *)&buffer, 1) != 1) + ERROR_panic("Cannot read from SIGCHLD pipe"); #ifdef DEBUG_ME fprintf(stderr, "<< callback_child\n"); @@ -615,7 +616,8 @@ static void signal_child(int sig) return; buffer = 42; - write(_pipe_child[1], &buffer, 1); + if (write(_pipe_child[1], &buffer, 1) != 1) + ERROR_panic("Cannot write into SIGCHLD pipe"); } diff --git a/main/gbx/gbx_class_load.c b/main/gbx/gbx_class_load.c index b436eabd9..30d6cf9c2 100644 --- a/main/gbx/gbx_class_load.c +++ b/main/gbx/gbx_class_load.c @@ -532,13 +532,16 @@ static void load_and_relocate(CLASS *class, int len_data, int *pndesc, int *pfir { int fd; - fd = open("/tmp/gambas-bad-header.out", O_CREAT | O_WRONLY, 0666); + fd = open("/tmp/gambas-bad-header.dump", O_CREAT | O_WRONLY, 0666); if (fd >= 0) { - write(fd, class->data, len_data); + if (write(fd, class->data, len_data) != len_data) + fprintf(stderr, "Cannot dump bad class file.\n"); + else + fprintf(stderr, "Bad class file dumped at /tmp/gambas-bad-header.dump\n"); close(fd); - fprintf(stderr, "Bad class file dumped at /tmp/gambas-bad-header.out: %d bytes\n", len_data); } + THROW(E_CLASS, ClassName, "Bad header", ""); } diff --git a/main/gbx/gbx_project.c b/main/gbx/gbx_project.c index 018051803..6b31c2eb5 100644 --- a/main/gbx/gbx_project.c +++ b/main/gbx/gbx_project.c @@ -346,7 +346,7 @@ void PROJECT_init(const char *file) { path = FILE_get_dir(file); - chdir(path); + FILE_chdir(path); path = FILE_getcwd(NULL); if (path == NULL) @@ -389,7 +389,7 @@ void PROJECT_init(const char *file) PROJECT_path = STRING_new(path, len); - chdir(PROJECT_path); + FILE_chdir(PROJECT_path); /* Project name */ diff --git a/main/gbx/gbx_subr_file.c b/main/gbx/gbx_subr_file.c index fdbb95804..178ca8e71 100755 --- a/main/gbx/gbx_subr_file.c +++ b/main/gbx/gbx_subr_file.c @@ -669,7 +669,7 @@ void SUBR_isdir(void) path = get_path(PARAM); - isdir = FILE_isdir(path); + isdir = FILE_is_dir(path); RETURN->type = T_BOOLEAN; RETURN->_integer.value = isdir ? -1 : 0; diff --git a/main/share/gb_file_share.h b/main/share/gb_file_share.h index 5d3d97ebc..ce67506f4 100644 --- a/main/share/gb_file_share.h +++ b/main/share/gb_file_share.h @@ -86,10 +86,10 @@ const char *FILE_set_ext(const char *path, const char *ext); const char *FILE_getcwd(const char *subdir); #define FILE_get_current_dir() FILE_getcwd(NULL) +void FILE_chdir(const char *path); const char *FILE_readlink(const char *link); bool FILE_is_dir(const char *path); -#define FILE_isdir FILE_is_dir const char *FILE_find_gambas(void); diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index 16c0fcb14..ad48ba193 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -433,7 +433,7 @@ bool FILE_exist_real(const char *path) { struct stat buf; - chdir(PROJECT_path); + if (chdir(PROJECT_path)) return FALSE; return (stat(path, &buf) == 0); } @@ -941,3 +941,13 @@ const char *FILE_find_gambas(void) return path; } +void FILE_chdir(const char *path) +{ + #ifdef PROJECT_EXEC + if (chdir(path)) + THROW_SYSTEM(errno, path); + #else + if (chdir(path)) + THROW("Cannot change current directory: &1: &2", path, strerror(errno)); + #endif +}