From 67ecd4b00a7aedac5117a87307d3e594bd254d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Wed, 7 Sep 2011 19:43:11 +0000 Subject: [PATCH] [INTERPRETER] * NEW: New syntax for GB.AddString() and GB.ExtendString() interpreter API. Do not pass the string by reference anymore. * NEW: GB.AddChar() is a new API for adding just a char to a string. [GB.DB.SQLITE2] * BUG: Fix ignored system call return values. [GB.DB.SQLITE3] * BUG: Fix ignored system call return values. [GB.DB.NET] * BUG: Fix ignored system call return values. [GB.V4L] * BUG: Remove some unused local variables. git-svn-id: svn://localhost/gambas/trunk@4105 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- app/src/gambas3/.lang/.pot | 14 ++-- .../.src/Connection/FNewConnection.form | 1 - gb.db.postgresql/src/main.c | 4 +- gb.db.sqlite2/src/main.cpp | 69 +++++++---------- gb.db.sqlite3/src/main.cpp | 75 +++++++------------ gb.dbus/src/c_dbusobserver.c | 30 ++++---- gb.dbus/src/helper.c | 2 +- gb.desktop/src/x11.c | 2 +- gb.net.curl/src/CCurl.c | 2 +- gb.net.curl/src/CFtpClient.c | 2 +- gb.net.curl/src/CHttpClient.c | 2 +- gb.net.curl/src/gbcurl.c | 18 ++--- gb.net.smtp/src/CSmtpClient.c | 4 +- gb.net/src/CDnsClient.c | 49 ++++++++---- gb.pdf/src/CPdfDocument.cpp | 6 +- gb.qt4/share/gb.form.picture.h | 6 +- gb.qt4/src/webkit/cwebdownload.cpp | 4 +- gb.v4l/src/CWebcam.h | 2 +- gb.v4l/src/gv4l2.c | 18 ++--- main/gbx/gbx_api.c | 9 ++- main/gbx/gbx_api.h | 2 - main/lib/db/main.c | 4 +- main/lib/db/sqlite.c | 12 +-- main/lib/debug/debug.c | 2 +- main/lib/eval/CHighlight.c | 8 +- main/lib/eval/eval.c | 2 +- main/lib/eval/eval_analyze.c | 8 +- main/share/gambas.h | 5 +- 28 files changed, 171 insertions(+), 191 deletions(-) diff --git a/app/src/gambas3/.lang/.pot b/app/src/gambas3/.lang/.pot index bbfd62052..be419f9f2 100644 --- a/app/src/gambas3/.lang/.pot +++ b/app/src/gambas3/.lang/.pot @@ -370,7 +370,7 @@ msgstr "" #: FFieldChooser.form:138 FFontChooser.form:40 FForm.class:2923 #: FGotoLine.form:23 FHelpBrowser.form:60 FIconEditor.class:1413 #: FList.form:121 FMain.class:200 FMakeInstall.class:327 FMenu.form:369 -#: FNewConnection.form:244 FNewTable.form:86 FNewTranslation.form:21 +#: FNewConnection.form:243 FNewTable.form:86 FNewTranslation.form:21 #: FOpenProject.form:168 FOption.class:618 FPasteSpecial.form:77 #: FPasteTable.form:107 FPropertyComponent.form:230 FPropertyProject.form:124 #: FReportBorderChooser.form:45 FReportBrushChooser.form:34 @@ -409,7 +409,7 @@ msgstr "" #: Design.module:396 FColorChooser.form:54 FCommit.form:223 #: FConnectionEditor.class:441 FCreateFile.form:430 FFieldChooser.form:132 #: FFontChooser.form:34 FGotoLine.form:17 FInfo.form:167 FList.form:115 -#: FMain.form:1314 FMenu.form:364 FNewConnection.form:238 FNewTable.form:80 +#: FMain.form:1314 FMenu.form:364 FNewConnection.form:237 FNewTable.form:80 #: FNewTranslation.form:15 FOpenProject.form:162 FPasteSpecial.form:71 #: FPropertyComponent.form:224 FPropertyProject.form:118 #: FReportBorderChooser.form:51 FReportBrushChooser.form:40 @@ -551,15 +551,15 @@ msgstr "" msgid "Authentification" msgstr "" -#: FCommit.form:169 FNewConnection.form:122 +#: FCommit.form:169 FNewConnection.form:121 msgid "User" msgstr "" -#: FCommit.form:184 FNewConnection.form:136 +#: FCommit.form:184 FNewConnection.form:135 msgid "Password" msgstr "" -#: FCommit.form:197 FNewConnection.form:156 +#: FCommit.form:197 FNewConnection.form:155 msgid "Remember password" msgstr "" @@ -2989,11 +2989,11 @@ msgstr "" msgid "Path" msgstr "" -#: FNewConnection.form:166 Project.module:186 +#: FNewConnection.form:165 Project.module:186 msgid "Database" msgstr "" -#: FNewConnection.form:223 +#: FNewConnection.form:222 msgid "Ignore database charset" msgstr "" diff --git a/app/src/gambas3/.src/Connection/FNewConnection.form b/app/src/gambas3/.src/Connection/FNewConnection.form index ca1a8e90d..621115375 100644 --- a/app/src/gambas3/.src/Connection/FNewConnection.form +++ b/app/src/gambas3/.src/Connection/FNewConnection.form @@ -53,7 +53,6 @@ { txtPath ButtonBox MoveScaled(27,0,23,4) Expand = True - ReadOnly = True } } { panLogin VBox diff --git a/gb.db.postgresql/src/main.c b/gb.db.postgresql/src/main.c index 0dfeb8e84..e20141829 100644 --- a/gb.db.postgresql/src/main.c +++ b/gb.db.postgresql/src/main.c @@ -1464,8 +1464,8 @@ static int table_list_73(DB_DATABASE *db, char ***tables) else { (*tables)[i] = GB.NewZeroString(schema); - GB.AddString(&((*tables)[i]), ".", 1); - GB.AddString(&((*tables)[i]), PQgetvalue(res, i, 0), 0); + (*tables)[i] = GB.AddChar((*tables)[i], '.'); + (*tables)[i] = GB.AddString((*tables)[i], PQgetvalue(res, i, 0), 0); } } } diff --git a/gb.db.sqlite2/src/main.cpp b/gb.db.sqlite2/src/main.cpp index 25e849be2..ac0b0339b 100644 --- a/gb.db.sqlite2/src/main.cpp +++ b/gb.db.sqlite2/src/main.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "sqlitedataset.h" @@ -369,8 +370,8 @@ static char *FindDatabase (const char *name, const char *hostName) /* Hostname contains home area */ fullpath = GB.NewZeroString(hostName); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) return fullpath; @@ -381,8 +382,8 @@ static char *FindDatabase (const char *name, const char *hostName) if (dbhome) { fullpath = GB.NewZeroString(dbhome); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) return fullpath; @@ -397,8 +398,8 @@ static char *FindDatabase (const char *name, const char *hostName) #endif fullpath = GB.NewZeroString(GB.TempDir()); - GB.AddString(&fullpath, "/sqlite/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddString(fullpath, "/sqlite/", 0); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) return fullpath; @@ -441,40 +442,11 @@ static char *GetDatabaseHome() return dbhome; } -// BM: not used anymore -#if 0 -/* Return Fullpath for database */ -char *FullPath( char *name ) -{ - char *db_fullpath = NULL; - char *dbhome = NULL; - dbhome = GetDatabaseHome(); +// Internal function to walk a directory and list files +// Used by database_list - if (!dbhome) - return NULL; - - GB.Alloc ((void **)&db_fullpath, strlen(name)+strlen(dbhome)+2); /* leave room - for \0 and / */ - /* start with an empty string */ - db_fullpath[0] = '\0'; - - strcpy(db_fullpath, dbhome); - if (db_fullpath[strlen(db_fullpath)-1] != '/') { - strcat(db_fullpath, "/"); - } - - strcat(db_fullpath, name); - - GB.Free((void **)&dbhome); - return db_fullpath; - -} -#endif - -/* Internal function to walk a dirctory and list files */ -/* Used by database_list */ -static int WalkDirectory(const char *dir, char ***databases ) +static int WalkDirectory(const char *dir, char ***databases) { DIR *dp; struct dirent *entry; @@ -484,9 +456,17 @@ static int WalkDirectory(const char *dir, char ***databases ) if ((dp = opendir(dir)) == NULL) return -1; - getcwd(cwd, MAX_PATH); + if (getcwd(cwd, MAX_PATH) == NULL) + { + fprintf(stderr, "gb.db.sqlite2: warning: getcwd: %s\n", strerror(errno)); + return -1; + } - chdir(dir); + if (chdir(dir)) + { + fprintf(stderr, "gb.db.sqlite2: warning: chdir: %s\n", strerror(errno)); + return -1; + } while ((entry = readdir(dp)) != NULL) { @@ -499,9 +479,12 @@ static int WalkDirectory(const char *dir, char ***databases ) } } - chdir(cwd); // BM: you must call closedir() closedir(dp); + + if (chdir(cwd)) + fprintf(stderr, "gb.db.sqlite2: warning: chdir: %s\n", strerror(errno)); + return GB.Count(databases); } @@ -2093,9 +2076,9 @@ static int database_create(DB_DATABASE *db, const char *name) } if (fullpath[strlen(fullpath) - 1] != '/') - GB.AddString(&fullpath, "/", 0); + fullpath = GB.AddChar(fullpath, '/'); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddString(fullpath, name, 0); _CREATE_DATABASE: diff --git a/gb.db.sqlite3/src/main.cpp b/gb.db.sqlite3/src/main.cpp index 23bb28c97..56ff1a217 100644 --- a/gb.db.sqlite3/src/main.cpp +++ b/gb.db.sqlite3/src/main.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "sqlitedataset.h" @@ -438,8 +439,8 @@ static char *FindDatabase(const char *name, const char *hostName) /* Hostname contains home area */ fullpath = GB.NewZeroString(hostName); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { return fullpath; @@ -452,8 +453,8 @@ static char *FindDatabase(const char *name, const char *hostName) if (dbhome != NULL) { fullpath = GB.NewZeroString(dbhome); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { @@ -472,8 +473,8 @@ static char *FindDatabase(const char *name, const char *hostName) #endif fullpath = GB.NewZeroString(GB.TempDir()); - GB.AddString(&fullpath, "/sqlite/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddString(fullpath, "/sqlite/", 0); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { @@ -519,40 +520,10 @@ static char *GetDatabaseHome() return dbhome; } -// BM: not used anymore -#if 0 -/* Return Fullpath for database */ -char *FullPath(char *name) -{ - char *db_fullpath = NULL; - char *dbhome = NULL; - dbhome = GetDatabaseHome(); +// Internal function to walk a directory and list files +// Used by database_list - if (!dbhome) - return NULL; - - GB.Alloc((void **) &db_fullpath, strlen(name) + strlen(dbhome) + 2); /* leave room - for \0 and / */ - /* start with an empty string */ - db_fullpath[0] = '\0'; - - strcpy(db_fullpath, dbhome); - if (db_fullpath[strlen(db_fullpath) - 1] != '/') - { - strcat(db_fullpath, "/"); - } - - strcat(db_fullpath, name); - - GB.Free((void **) &dbhome); - return db_fullpath; - -} -#endif - -/* Internal function to walk a dirctory and list files */ -/* Used by database_list */ static int WalkDirectory(const char *dir, char ***databases) { DIR *dp; @@ -561,33 +532,41 @@ static int WalkDirectory(const char *dir, char ***databases) char cwd[MAX_PATH]; if ((dp = opendir(dir)) == NULL) + return -1; + + if (getcwd(cwd, MAX_PATH) == NULL) { + fprintf(stderr, "gb.db.sqlite3: warning: getcwd: %s\n", strerror(errno)); return -1; } - getcwd(cwd, MAX_PATH); + if (chdir(dir)) + { + fprintf(stderr, "gb.db.sqlite3: warning: chdir: %s\n", strerror(errno)); + return -1; + } - chdir(dir); - - while ((entry = readdir(dp)) != NULL) + while ((entry = readdir(dp)) != NULL) { stat(entry->d_name, &statbuf); - if (S_ISREG(statbuf.st_mode)) + if (S_ISREG(statbuf.st_mode)) { if (IsDatabaseFile(entry->d_name)) - { *(char **)GB.Add(databases) = GB.NewZeroString(entry->d_name); - } } } - chdir(cwd); // BM: you must call closedir() closedir(dp); + + if (chdir(cwd)) + fprintf(stderr, "gb.db.sqlite3: warning: chdir: %s\n", strerror(errno)); + return GB.Count(databases); } + /* Internal function to check database version number */ static int db_version() { @@ -2300,9 +2279,9 @@ static int database_create(DB_DATABASE * db, const char *name) } if (fullpath[strlen(fullpath) - 1] != '/') - GB.AddString(&fullpath, "/", 0); + fullpath = GB.AddChar(fullpath, '/'); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddString(fullpath, name, 0); _CREATE_DATABASE: diff --git a/gb.dbus/src/c_dbusobserver.c b/gb.dbus/src/c_dbusobserver.c index 4b5efad23..469bdb954 100644 --- a/gb.dbus/src/c_dbusobserver.c +++ b/gb.dbus/src/c_dbusobserver.c @@ -36,21 +36,21 @@ void DBUS_raise_observer(CDBUSOBSERVER *_object) GB.Raise(THIS, EVENT_MESSAGE, 0); } -static void add_rule(char **match, const char *name, const char *rule) +static char *add_rule(char *match, const char *name, const char *rule) { if (!rule) - return; + return match; if (rule[0] == '*' && rule[1] == 0) - return; + return match; - if (*match) - GB.AddString(match, ",", 1); + if (match) + match = GB.AddChar(match, ','); - GB.AddString(match, name, 0); - GB.AddString(match, "='", 2); - GB.AddString(match, rule, 0); - GB.AddString(match, "'", 1); + match = GB.AddString(match, name, 0); + match = GB.AddString(match, "='", 2); + match = GB.AddString(match, rule, 0); + match = GB.AddChar(match, '\''); } static void set_filter(char **property, const char *str, int len) @@ -74,16 +74,16 @@ static void update_match(CDBUSOBSERVER *_object, bool noerr) DBusError error; if (THIS->type >= 0 && THIS->type <= 3) - add_rule(&match, "type", type[THIS->type]); + match = add_rule(match, "type", type[THIS->type]); - add_rule(&match, "path", THIS->object); - add_rule(&match, "member", THIS->member); - add_rule(&match, "interface", THIS->interface); + match = add_rule(match, "path", THIS->object); + match = add_rule(match, "member", THIS->member); + match = add_rule(match, "interface", THIS->interface); if (THIS->destination && *(THIS->destination)) - add_rule(&match, "destination", THIS->destination); + match = add_rule(match, "destination", THIS->destination); else - add_rule(&match, "destination", dbus_bus_get_unique_name(THIS->connection)); + match = add_rule(match, "destination", dbus_bus_get_unique_name(THIS->connection)); dbus_error_init(&error); diff --git a/gb.dbus/src/helper.c b/gb.dbus/src/helper.c index 11e4c98da..efab2ff50 100644 --- a/gb.dbus/src/helper.c +++ b/gb.dbus/src/helper.c @@ -869,7 +869,7 @@ bool DBUS_error(DBusConnection *connection, DBusMessage *message, const char *ty else { full_type = GB.NewZeroString("org.freedesktop.org.DBus.Error."); - GB.AddString(&full_type, type, 0); + full_type = GB.AddString(full_type, type, 0); } reply = dbus_message_new_error(message, full_type, error); diff --git a/gb.desktop/src/x11.c b/gb.desktop/src/x11.c index 42833b0d5..bc6a1449e 100644 --- a/gb.desktop/src/x11.c +++ b/gb.desktop/src/x11.c @@ -168,7 +168,7 @@ char *X11_get_property(Window wid, Atom prop, Atom *type, int *format, int *pcou //fprintf(stderr, "X11_get_property: format = %d size = %d count = %ld after = %ld next offset = %ld\n", *format, size, count, after, offset); - GB.AddString(&_property_value, (char *)data, count * size); + _property_value = GB.AddString(_property_value, (char *)data, count * size); XFree(data); } diff --git a/gb.net.curl/src/CCurl.c b/gb.net.curl/src/CCurl.c index 9c5da2747..320190984 100644 --- a/gb.net.curl/src/CCurl.c +++ b/gb.net.curl/src/CCurl.c @@ -437,7 +437,7 @@ BEGIN_PROPERTY(Curl_URL) if (strncmp(url, protocol, strlen(protocol))) { tmp = GB.NewZeroString(protocol); - GB.AddString(&tmp, url, GB.StringLength(url)); + tmp = GB.AddString(tmp, url, GB.StringLength(url)); GB.FreeString(&url); url = tmp; } diff --git a/gb.net.curl/src/CFtpClient.c b/gb.net.curl/src/CFtpClient.c index 9cad3f3cd..ce1ff7a65 100644 --- a/gb.net.curl/src/CFtpClient.c +++ b/gb.net.curl/src/CFtpClient.c @@ -68,7 +68,7 @@ static int ftp_write_curl(void *buffer, size_t size, size_t nmemb, void *_object } else { - GB.AddString(&THIS->data, buffer, nmemb); + THIS->data = GB.AddString(THIS->data, buffer, nmemb); } if (THIS->async) diff --git a/gb.net.curl/src/CHttpClient.c b/gb.net.curl/src/CHttpClient.c index ee38e1b55..4e1f1bf5e 100644 --- a/gb.net.curl/src/CHttpClient.c +++ b/gb.net.curl/src/CHttpClient.c @@ -133,7 +133,7 @@ static int http_write_curl(void *buffer, size_t size, size_t nmemb, void *_objec } else { - GB.AddString(&THIS->data, buffer, nmemb); + THIS->data = GB.AddString(THIS->data, buffer, nmemb); } if (THIS->async) diff --git a/gb.net.curl/src/gbcurl.c b/gb.net.curl/src/gbcurl.c index 2387086ff..6014096b9 100644 --- a/gb.net.curl/src/gbcurl.c +++ b/gb.net.curl/src/gbcurl.c @@ -158,9 +158,9 @@ bool CURL_check_userpwd(CURL_USER *user) if (user->user || user->pwd) { - GB.AddString(&tmp, user->user, 0); - GB.AddString(&tmp, ":", 1); - GB.AddString(&tmp, user->pwd, 0); + tmp = GB.AddString(tmp, user->user, 0); + tmp = GB.AddChar(tmp, ':'); + tmp = GB.AddString(tmp, user->pwd, 0); } if (tmp && user->userpwd) @@ -200,9 +200,9 @@ void CURL_proxy_set(CURL_PROXY *proxy, CURL *curl) if (proxy->user || proxy->pwd) { - GB.AddString(&proxy->userpwd, proxy->user, 0); - GB.AddString(&proxy->userpwd, ":", 1); - GB.AddString(&proxy->userpwd, proxy->pwd, 0); + proxy->userpwd = GB.AddString(proxy->userpwd, proxy->user, 0); + proxy->userpwd = GB.AddChar(proxy->userpwd, ':'); + proxy->userpwd = GB.AddString(proxy->userpwd, proxy->pwd, 0); } if (!proxy->host) @@ -295,9 +295,9 @@ void CURL_user_set(CURL_USER *user, CURL *curl) } GB.FreeString(&user->userpwd); - GB.AddString(&user->userpwd, user->user, 0); - GB.AddString(&user->userpwd, ":", 1); - GB.AddString(&user->userpwd, user->pwd, 0); + user->userpwd = GB.AddString(user->userpwd, user->user, 0); + user->userpwd = GB.AddChar(user->userpwd, ':'); + user->userpwd = GB.AddString(user->userpwd, user->pwd, 0); curl_easy_setopt(curl, CURLOPT_USERPWD, user->userpwd); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, user->auth); diff --git a/gb.net.smtp/src/CSmtpClient.c b/gb.net.smtp/src/CSmtpClient.c index 064284ff9..8b266b907 100644 --- a/gb.net.smtp/src/CSmtpClient.c +++ b/gb.net.smtp/src/CSmtpClient.c @@ -49,8 +49,8 @@ static char *get_address(char *address) return address; _tmp = GB.NewString("<", 1); - GB.AddString(&_tmp, address, len); - GB.AddString(&_tmp, ">", 1); + _tmp = GB.AddString(_tmp, address, len); + _tmp = GB.AddChar(_tmp, '>'); return _tmp; } diff --git a/gb.net/src/CDnsClient.c b/gb.net/src/CDnsClient.c index c333b4219..a855656c1 100644 --- a/gb.net/src/CDnsClient.c +++ b/gb.net/src/CDnsClient.c @@ -58,6 +58,18 @@ DECLARE_EVENT(EVENT_Finished); 2) Action : '0' --> dns_get_name, '1' --> dns_get_ip 3) Result : string finished with '\x10' *********************************************************/ + +static bool read_dns_pipe(void *data, size_t length) +{ + if (read_dns_pipe( data, length) != length) + { + fprintf(stderr, "gb.net: cannot read DNS pipe: %s\n", strerror(errno)); + return TRUE; + } + + return FALSE; +} + void dns_callback(intptr_t lParam) { /*********************************************************** @@ -89,14 +101,14 @@ void dns_callback(intptr_t lParam) mypoll.revents=0; idata=poll(&mypoll,1,0); if (!idata) break; - read (dns_r_pipe,&v_obj,sizeof(void*)); - read (dns_r_pipe,&test_id,sizeof(int)); - read (dns_r_pipe,Action,sizeof(char)); + read_dns_pipe(&v_obj,sizeof(void*)); + read_dns_pipe(&test_id,sizeof(int)); + read_dns_pipe(Action,sizeof(char)); GB.Alloc(POINTER(&Buf),sizeof(char)); while (BufRead[0] != '\x10') { - read(dns_r_pipe,BufRead,sizeof(char)); + read_dns_pipe(BufRead,sizeof(char)); if (BufRead[0]!='\x10') { Buf[Position]=BufRead[0]; @@ -158,6 +170,12 @@ void dns_event(CDNSCLIENT *mythis) GB.Unref(POINTER(&mythis)); } +static void write_dns_pipe(void *data, size_t length) +{ + if (write(dns_w_pipe, data, length) != length) + fprintf(stderr, "gb.net: cannot write to DNS pipe: %s\n", strerror(errno)); +} + void* dns_get_name(void* v_obj) { /**************************************************************** @@ -192,11 +210,11 @@ void* dns_get_name(void* v_obj) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); sem_wait(&dns_th_pipe); - write (dns_w_pipe,&v_obj,sizeof(void*)); /* object */ - write (dns_w_pipe,&myid,sizeof(int)); /* id */ - write (dns_w_pipe,Buf,sizeof(char)); /* Action */ - if (!res) write (dns_w_pipe,host,strlen(host)*sizeof(char)); - write (dns_w_pipe,"\x10",sizeof(char)); + write_dns_pipe(&v_obj,sizeof(void*)); /* object */ + write_dns_pipe(&myid,sizeof(int)); /* id */ + write_dns_pipe(Buf,sizeof(char)); /* Action */ + if (!res) write_dns_pipe(host,strlen(host)*sizeof(char)); + write_dns_pipe("\x10",sizeof(char)); sem_post(&dns_th_pipe); return NULL; } @@ -207,6 +225,7 @@ This function will run in a thread different from main thread, and when it finish its proccess, it sends a message to the main thread using a pipe *****************************************************************/ + void* dns_get_ip(void* v_obj) { char Buf[1]; @@ -230,16 +249,18 @@ void* dns_get_ip(void* v_obj) sem_wait(&dns_th_pipe); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); - write (dns_w_pipe,&v_obj,sizeof(void*)); /* object */ - write (dns_w_pipe,&myid,sizeof(int)); /* id */ - write (dns_w_pipe,Buf,sizeof(char)); /* action */ + + write_dns_pipe(&v_obj, sizeof(void*)); /* object */ + write_dns_pipe(&myid, sizeof(int)); /* id */ + write_dns_pipe(Buf, sizeof(char)); /* action */ + if (stHost!=NULL) { addr=(struct sockaddr_in*)stHost[0].ai_addr; BufData=inet_ntoa(addr->sin_addr); - if (BufData) write (dns_w_pipe,BufData,strlen(BufData)*sizeof(char)); + if (BufData) write_dns_pipe(BufData,strlen(BufData)*sizeof(char)); } - write (dns_w_pipe,"\x10",sizeof(char)); + write_dns_pipe("\x10",sizeof(char)); sem_post(&dns_th_pipe); return NULL; } diff --git a/gb.pdf/src/CPdfDocument.cpp b/gb.pdf/src/CPdfDocument.cpp index 3a1c9631d..153156986 100644 --- a/gb.pdf/src/CPdfDocument.cpp +++ b/gb.pdf/src/CPdfDocument.cpp @@ -144,7 +144,7 @@ static void aux_return_unicode_string(Unicode *uni, int32_t len) char *ret=NULL; for (bc=0; bchasUnicodeMarker()) { GB.ConvString (&uni,tmp->getCString()+2,tmp->getLength()-2,"UTF-16BE","UTF-8"); - GB.AddString (&vl,uni,0); + vl = GB.AddString(vl, uni, 0); } else - GB.AddString(&vl,tmp->getCString(),tmp->getLength()); + vl = GB.AddString(vl,tmp->getCString(),tmp->getLength()); return vl; diff --git a/gb.qt4/share/gb.form.picture.h b/gb.qt4/share/gb.form.picture.h index 64d7ff688..1bd9e8064 100644 --- a/gb.qt4/share/gb.form.picture.h +++ b/gb.qt4/share/gb.form.picture.h @@ -102,10 +102,10 @@ bool LOAD_IMAGE_FUNC(IMAGE_TYPE **p, const char *path, int lenp) pos--; } path_theme = GB.NewString(path, pos >= 0 ? pos : lenp); - GB.AddString(&path_theme, "_", 1); - GB.AddString(&path_theme, APPLICATION_THEME, GB.StringLength(APPLICATION_THEME)); + path_theme = GB.AddChar(path_theme, '_'); + path_theme = GB.AddString(path_theme, APPLICATION_THEME, GB.StringLength(APPLICATION_THEME)); if (pos >= 0) - GB.AddString(&path_theme, &path[pos], lenp - pos); + path_theme = GB.AddString(path_theme, &path[pos], lenp - pos); ok = !GB.LoadFile(path_theme, GB.StringLength(path_theme), &addr, &len); GB.Error(NULL); GB.FreeString(&path_theme); diff --git a/gb.qt4/src/webkit/cwebdownload.cpp b/gb.qt4/src/webkit/cwebdownload.cpp index b63e3f236..5def80276 100644 --- a/gb.qt4/src/webkit/cwebdownload.cpp +++ b/gb.qt4/src/webkit/cwebdownload.cpp @@ -312,8 +312,8 @@ void CWebDownload::readyRead() if (!THIS->output->open(QIODevice::WriteOnly)) { char *error = NULL; - GB.AddString(&error, "Unable to save file: ", 0); - GB.AddString(&error, TO_UTF8(THIS->output->errorString()), 0); + error = GB.AddString(error, "Unable to save file: ", 0); + error = GB.AddString(error, TO_UTF8(THIS->output->errorString()), 0); abort_download(THIS, error); return; } diff --git a/gb.v4l/src/CWebcam.h b/gb.v4l/src/CWebcam.h index 719ca4e25..0ff29025a 100644 --- a/gb.v4l/src/CWebcam.h +++ b/gb.v4l/src/CWebcam.h @@ -167,7 +167,7 @@ void yuv420p_to_rgb (unsigned char *image, unsigned char *image2, int x, int y, // ++ V4L2 int gv4l2_available(CWEBCAM * _object); -void gv4l2_debug( char *s ); +void gv4l2_debug(const char *s); int gv4l2_xioctl( int fd,int request,void * arg); int gv4l2_open_device( char* name ); void gv4l2_close_device( int id ); diff --git a/gb.v4l/src/gv4l2.c b/gb.v4l/src/gv4l2.c index f05a38391..ab10acf27 100644 --- a/gb.v4l/src/gv4l2.c +++ b/gb.v4l/src/gv4l2.c @@ -66,12 +66,12 @@ int gv4l2_available(CWEBCAM * _object) // // Debugging routine for V4L2 // -void gv4l2_debug( char *s ) +void gv4l2_debug(const char *s) { - if( ! gv4l2_debug_mode ) return; - printf("gambas v4l2: %s [%d]\n",s,errno); - fflush(stdout); + if (!gv4l2_debug_mode) return; + fprintf(stderr, "gb.v4l: v4l2: %s: %s\n", s, strerror(errno)); } + //============================================================================= // // xioctl( fd,request,arg ) @@ -80,11 +80,11 @@ void gv4l2_debug( char *s ) // int gv4l2_xioctl( int fd,int request,void * arg) { - int r; + int r; - do r = ioctl (fd, request, arg); - while (-1 == r && EINTR == errno); - return r; + do r = ioctl (fd, request, arg); + while (-1 == r && EINTR == errno); + return r; } // //============================================================================= @@ -595,8 +595,6 @@ void gv4l1_process_image (CWEBCAM * _object, void *start) void gv4l2_process_image (CWEBCAM * _object, void *start) { struct v4l2_format dest = THIS->fmt; - int format,w,h; - int size; if (THIS->format != GB_IMAGE_BGR) gv4l2_debug("Destination format not supported"); diff --git a/main/gbx/gbx_api.c b/main/gbx/gbx_api.c index 43ce8ce84..a71c03662 100644 --- a/main/gbx/gbx_api.c +++ b/main/gbx/gbx_api.c @@ -152,8 +152,9 @@ void *GAMBAS_Api[] = (void *)GB_NewZeroString, (void *)GB_TempString, (void *)GB_FreeString, - (void *)GB_ExtendString, - (void *)GB_AddString, + (void *)STRING_extend, + (void *)STRING_add, + (void *)STRING_add_char, (void *)GB_StringLength, (void *)GB_ToZeroString, (void *)REGEXP_match, @@ -1983,7 +1984,7 @@ bool GB_ExistClassLocal(const char *name) return CLASS_look(name, strlen(name)) != NULL; } -void GB_AddString(char **ptr, const char *src, int len) +/*void GB_AddString(char **ptr, const char *src, int len) { *ptr = STRING_add(*ptr, src, len); } @@ -1991,4 +1992,4 @@ void GB_AddString(char **ptr, const char *src, int len) void GB_ExtendString(char **ptr, int new_len) { *ptr = STRING_extend(*ptr, new_len); -} +}*/ diff --git a/main/gbx/gbx_api.h b/main/gbx/gbx_api.h index be139ec37..3e11e6777 100644 --- a/main/gbx/gbx_api.h +++ b/main/gbx/gbx_api.h @@ -158,8 +158,6 @@ char *GB_TempString(char *src, int len); void GB_FreeString(char **str); int GB_StringLength(const char *str); bool GB_ConvString(char **result, const char *str, int len, const char *src, const char *dst); -void GB_AddString(char **ptr, const char *src, int len); -void GB_ExtendString(char **ptr, int new_len); bool GB_Conv(GB_VALUE *, GB_TYPE); diff --git a/main/lib/db/main.c b/main/lib/db/main.c index 656cacd00..6fee6d66c 100644 --- a/main/lib/db/main.c +++ b/main/lib/db/main.c @@ -382,7 +382,7 @@ static void q_dump_temp(void) if (!_temp_len) return; - GB.AddString(&_query, _temp, _temp_len); + _query = GB.AddString(_query, _temp, _temp_len); _temp_len = 0; } @@ -395,7 +395,7 @@ void q_add_length(const char *str, int len) q_dump_temp(); if (len > TEMP_MAX) - GB.AddString(&_query, str, len); + _query = GB.AddString(_query, str, len); else { memcpy(&_temp[_temp_len], str, len); diff --git a/main/lib/db/sqlite.c b/main/lib/db/sqlite.c index 025290a36..8bb8a27b6 100644 --- a/main/lib/db/sqlite.c +++ b/main/lib/db/sqlite.c @@ -107,8 +107,8 @@ static char *FindDatabase(char *name, char *hostName) /* Hostname contains home area */ fullpath = GB.NewZeroString(hostName); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { return fullpath; @@ -121,8 +121,8 @@ static char *FindDatabase(char *name, char *hostName) if (dbhome != NULL) { fullpath = GB.NewZeroString(dbhome); - GB.AddString(&fullpath, "/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddChar(fullpath, '/'); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { @@ -131,8 +131,8 @@ static char *FindDatabase(char *name, char *hostName) } fullpath = GB.NewZeroString(GB.TempDir()); - GB.AddString(&fullpath, "/sqlite/", 0); - GB.AddString(&fullpath, name, 0); + fullpath = GB.AddString(fullpath, "/sqlite/", 0); + fullpath = GB.AddString(fullpath, name, 0); if (IsDatabaseFile(fullpath)) { diff --git a/main/lib/debug/debug.c b/main/lib/debug/debug.c index 25c6a90b1..3b715c7e8 100644 --- a/main/lib/debug/debug.c +++ b/main/lib/debug/debug.c @@ -914,7 +914,7 @@ void DEBUG_main(bool error) break; if (!*cmdbuf) continue; - GB.AddString(&cmd, cmdbuf, 0); + cmd = GB.AddString(cmd, cmdbuf, 0); if (cmd[GB.StringLength(cmd) - 1] == '\n') break; } diff --git a/main/lib/eval/CHighlight.c b/main/lib/eval/CHighlight.c index 1e7f28399..390361d03 100644 --- a/main/lib/eval/CHighlight.c +++ b/main/lib/eval/CHighlight.c @@ -93,7 +93,7 @@ static char *purge(const char *s, int len_s, bool comment, bool string) if (string) { if (i < len_s) - GB.AddString(&r, &c, 1); + r = GB.AddChar(r, c); //r += c; i++; c = s[i]; @@ -103,7 +103,7 @@ static char *purge(const char *s, int len_s, bool comment, bool string) { i++; if (i < len_s) - GB.AddString(&r, " ", 1); + r = GB.AddChar(r, ' '); //r += ' '; c = ' ', lc = 1; } @@ -117,9 +117,9 @@ static char *purge(const char *s, int len_s, bool comment, bool string) } if (lc == 1) - GB.AddString(&r, &c, 1); + r = GB.AddChar(r, c); else - GB.AddString(&r, &s[i], lc); + r = GB.AddString(r, &s[i], lc); } GB.FreeString(&_purged_line); diff --git a/main/lib/eval/eval.c b/main/lib/eval/eval.c index 6f4306491..ada3f13a6 100644 --- a/main/lib/eval/eval.c +++ b/main/lib/eval/eval.c @@ -203,7 +203,7 @@ void EVAL_new(EXPRESSION **expr, char *src, int len) GB.Alloc((void **)expr, sizeof(EXPRESSION)); CLEAR(*expr); (*expr)->source = GB.NewString(src, len); - GB.AddString(&((*expr)->source), "\n\0", 2); + (*expr)->source = GB.AddString((*expr)->source, "\n\0", 2); (*expr)->len = len + 2; /*(*expr)->option = option;*/ } diff --git a/main/lib/eval/eval_analyze.c b/main/lib/eval/eval_analyze.c index 5e2d66337..4ddbf06f9 100644 --- a/main/lib/eval/eval_analyze.c +++ b/main/lib/eval/eval_analyze.c @@ -224,7 +224,7 @@ static void flush_result(EVAL_ANALYZE *result) { if (_analyze_buffer_pos > 0) { - GB.AddString(&result->str, _analyze_buffer, _analyze_buffer_pos); + result->str = GB.AddString(result->str, _analyze_buffer, _analyze_buffer_pos); _analyze_buffer_pos = 0; } } @@ -235,7 +235,7 @@ static void add_result(EVAL_ANALYZE *result, const char *str, int len) flush_result(result); if (len > sizeof(_analyze_buffer)) - GB.AddString(&result->str, str, len); + result->str = GB.AddString(result->str, str, len); else { memcpy(&_analyze_buffer[_analyze_buffer_pos], str, len); @@ -529,7 +529,7 @@ PUBLIC void EVAL_analyze(const char *src, int len, int state, EVAL_ANALYZE *resu EVAL_clear(EVAL, FALSE); EVAL->source = GB.NewString(src, len); - GB.AddString(&EVAL->source, "\0\0", 2); + EVAL->source = GB.AddString(EVAL->source, "\0\0", 2); EVAL->len = len; EVAL->analyze = TRUE; @@ -565,7 +565,7 @@ PUBLIC void EVAL_analyze(const char *src, int len, int state, EVAL_ANALYZE *resu while (nspace > 0) { - GB.AddString(&result->str, " ", nspace > 8 ? 8 : nspace); + result->str = GB.AddString(result->str, " ", nspace > 8 ? 8 : nspace); nspace -= 8; } } diff --git a/main/share/gambas.h b/main/share/gambas.h index b8f8a0d66..b111f89de 100644 --- a/main/share/gambas.h +++ b/main/share/gambas.h @@ -874,8 +874,9 @@ typedef char *(*NewZeroString)(const char *); char *(*TempString)(const char *, int); void (*FreeString)(char **); - void (*ExtendString)(char **, int); - void (*AddString)(char **, const char *, int); + char *(*ExtendString)(char *, int); + char *(*AddString)(char *, const char *, int); + char *(*AddChar)(char *, char); int (*StringLength)(char *); char *(*ToZeroString)(GB_STRING *); bool (*MatchString)(const char *, int, const char *, int);