Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/02593d170a7163a141acf...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/02593d170a7163a141acf6f...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/02593d170a7163a141acf6f2f...
The branch, master has been updated
via 02593d170a7163a141acf6f2f72686a7bdbfb828 (commit)
via 5a7ddb9e8478e18ac06871dc841cf7069a5ba949 (commit)
from 38c6e95f4e0681221f9a4f1517d68bac6e98da2c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/02593d170a7163a141a...
commit 02593d170a7163a141acf6f2f72686a7bdbfb828
Author: Ole Loots <ole(a)monochrom.net>
Commit: Ole Loots <ole(a)monochrom.net>
Added is_process_running
Now the source code viewer is launched when not already
running (ShelWrite wasn't handling this correctly)
diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c
index 79395ca..1a1755b 100644
--- a/atari/ctxmenu.c
+++ b/atari/ctxmenu.c
@@ -23,7 +23,8 @@
#include <string.h>
#include <stdbool.h>
#include <assert.h>
-#include <windom.h>
+#include <windom.h>
+#include <mint/osbind.h>
#include "desktop/gui.h"
#include "desktop/netsurf.h"
@@ -122,8 +123,8 @@ void context_popup( struct gui_window * gw, short x, short y )
FILE * fp_tmpfile;
char * tempfile;
int err = 0;
- char * editor;
- char cmdline[128];
+ char * editor, *lastslash;
+ char cmdline[PATH_MAX];
pop = get_tree( POP_CTX );
if (pop == NULL)
@@ -239,15 +240,24 @@ void context_popup( struct gui_window * gw, short x, short y )
fp_tmpfile = fopen( tempfile, "w" );
if (fp_tmpfile != NULL){
fwrite(data, size, 1, fp_tmpfile);
- fclose(fp_tmpfile );
-
- // TODO: check if app is runnin, if not, use pexec or such.
- /*
- sprintf((char*)&cmdline, "%s \"%s\"",
nsoption_charp(atari_editor), tempfile );
- system( (char*)&cmdline );
- */
- err = ShelWrite( editor, tempfile , editor, 1, 0);
- LOG(("Launched: %s %s (%d)\n", editor, tempfile, err ));
+ fclose(fp_tmpfile );
+ lastslash = strrchr(editor, '/');
+ if (lastslash == NULL)
+ lastslash = strrchr(editor, '\\');
+ if (lastslash == NULL)
+ lastslash = editor;
+ else
+ lastslash++;
+ if(is_process_running(lastslash)){
+ err = ShelWrite( editor, tempfile , editor, 1, 0);
+ } else {
+ /* check for max length of simple commandline param: */
+ if(strlen(tempfile)<=125){
+ sprintf(cmdline, "%c%s", (char)strlen(tempfile),
+ tempfile);
+ Pexec(100, editor, cmdline, NULL);
+ }
+ }
} else {
printf("Could not open temp file: %s!\n", tempfile );
}
diff --git a/atari/misc.c b/atari/misc.c
index 3721847..054684a 100755
--- a/atari/misc.c
+++ b/atari/misc.c
@@ -45,6 +45,11 @@
#include "cflib.h"
extern void * h_gem_rsrc;
+
+struct is_process_running_callback_data {
+ const char * fname;
+ bool found;
+};
void warn_user(const char *warning, const char *detail)
{
@@ -152,6 +157,86 @@ struct gui_window * find_cmp_window( COMPONENT * c )
gw = gw->next;
}
return( NULL );
+}
+
+static int scan_process_list(scan_process_callback cb, void *data)
+{
+ int pid, count = 0;
+ DIR *dir;
+ char*dirname;
+ struct dirent *de;
+
+ if (( dir = opendir("U:/kern")) == NULL)
+ return(0);
+
+ while ((de = readdir( dir)) != NULL) {
+ dirname = de->d_name;
+
+ if( dirname[0] != '1' && dirname[0] != '2' &&
dirname[0] != '3' && dirname[0] != '4' && dirname[0] !=
'5'
+ && dirname[0] != '6' && dirname[0] != '7' &&
dirname[0] != '8' && dirname[0] != '9')
+ continue;
+
+ count++;
+ if (cb != NULL) {
+ /* when callback returns negative value, we stop scanning: */
+ pid = atoi(dirname);
+ if (cb(pid, data)<0) {
+ break;
+ }
+ }
+ }
+
+ closedir(dir);
+
+ return(count);
+}
+
+static int proc_running_callback(int pid, void * arg)
+{
+ char buf[PATH_MAX], fnamepath[256];
+ FILE *fp;
+ int nread;
+ struct is_process_running_callback_data *data;
+
+ data = (struct is_process_running_callback_data *)arg;
+
+ sprintf(fnamepath, "U:\\kern\\%d\\fname", pid);
+
+ fp = fopen(fnamepath, "r");
+ if(!fp)
+ return(0);
+
+ nread = fread(buf, 1, PATH_MAX-1, fp);
+ fclose(fp);
+
+ if (nread > 0) {
+ buf[nread] = 0;
+
+ char *lastslash = strrchr(buf, '/');
+
+ if(lastslash == NULL)
+ lastslash = strrchr(buf, '\\');
+
+ if(lastslash==NULL)
+ lastslash = buf;
+ else
+ lastslash++;
+
+ if(strcasecmp(lastslash, data->fname)==0){
+ data->found = true;
+ return(-1);
+ }
+ }
+ return(0);
+}
+
+bool is_process_running(const char * name)
+{
+ struct is_process_running_callback_data data = {name, false};
+
+ scan_process_list(proc_running_callback, &data);
+
+ return( (data.found==1) ? true : false );
}
diff --git a/atari/misc.h b/atari/misc.h
index edd026b..612113f 100755
--- a/atari/misc.h
+++ b/atari/misc.h
@@ -39,9 +39,12 @@
/* Modes for find_gui_window: */
#define BY_WINDOM_HANDLE 0x0
#define BY_GEM_HANDLE 0x1
+
+typedef int (*scan_process_callback)(int pid, void *data);
struct gui_window * find_gui_window( unsigned long, short mode );
-struct gui_window * find_cmp_window( COMPONENT * c );
+struct gui_window * find_cmp_window( COMPONENT * c );
+bool is_process_running(const char * name);
OBJECT *get_tree( int idx );
char *get_rsc_string( int idx );
void gem_set_cursor( MFORM_EX * cursor );
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/5a7ddb9e8478e18ac06...
commit 5a7ddb9e8478e18ac06871dc841cf7069a5ba949
Author: Ole Loots <ole(a)monochrom.net>
Commit: Ole Loots <ole(a)monochrom.net>
Use is_dir to validate user selection.
diff --git a/atari/global_evnt.c b/atari/global_evnt.c
index 1a0e8f6..0c9dfdc 100755
--- a/atari/global_evnt.c
+++ b/atari/global_evnt.c
@@ -170,21 +170,9 @@ static void __CDECL menu_save_page(WINDOW *win, int item, int title,
void *data)
do {
// TODO: localize string
- path = file_select( "Select folder", "" );
- if( path ) {
- printf("testing: %s\n", path );
- // dumb check if the selection is an folder:
- /*FILE * fp;
- fp = fopen( path, "r" );
- if( !fp ){
- is_folder = true;
- } else {
- fclose( fp );
- form_alert(1, "[1][Please select an folder or abort!][OK]");
- }
- */
- is_folder = true;
- }
+ path = file_select("Select folder", "");
+ if (path)
+ is_folder = is_dir(path);
} while( !is_folder && path != NULL );
if( path != NULL ){
-----------------------------------------------------------------------
Summary of changes:
atari/ctxmenu.c | 34 +++++++++++++-------
atari/global_evnt.c | 18 ++---------
atari/misc.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
atari/misc.h | 5 ++-
4 files changed, 114 insertions(+), 28 deletions(-)
diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c
index 79395ca..1a1755b 100644
--- a/atari/ctxmenu.c
+++ b/atari/ctxmenu.c
@@ -23,7 +23,8 @@
#include <string.h>
#include <stdbool.h>
#include <assert.h>
-#include <windom.h>
+#include <windom.h>
+#include <mint/osbind.h>
#include "desktop/gui.h"
#include "desktop/netsurf.h"
@@ -122,8 +123,8 @@ void context_popup( struct gui_window * gw, short x, short y )
FILE * fp_tmpfile;
char * tempfile;
int err = 0;
- char * editor;
- char cmdline[128];
+ char * editor, *lastslash;
+ char cmdline[PATH_MAX];
pop = get_tree( POP_CTX );
if (pop == NULL)
@@ -239,15 +240,24 @@ void context_popup( struct gui_window * gw, short x, short y )
fp_tmpfile = fopen( tempfile, "w" );
if (fp_tmpfile != NULL){
fwrite(data, size, 1, fp_tmpfile);
- fclose(fp_tmpfile );
-
- // TODO: check if app is runnin, if not, use pexec or such.
- /*
- sprintf((char*)&cmdline, "%s \"%s\"",
nsoption_charp(atari_editor), tempfile );
- system( (char*)&cmdline );
- */
- err = ShelWrite( editor, tempfile , editor, 1, 0);
- LOG(("Launched: %s %s (%d)\n", editor, tempfile, err ));
+ fclose(fp_tmpfile );
+ lastslash = strrchr(editor, '/');
+ if (lastslash == NULL)
+ lastslash = strrchr(editor, '\\');
+ if (lastslash == NULL)
+ lastslash = editor;
+ else
+ lastslash++;
+ if(is_process_running(lastslash)){
+ err = ShelWrite( editor, tempfile , editor, 1, 0);
+ } else {
+ /* check for max length of simple commandline param: */
+ if(strlen(tempfile)<=125){
+ sprintf(cmdline, "%c%s", (char)strlen(tempfile),
+ tempfile);
+ Pexec(100, editor, cmdline, NULL);
+ }
+ }
} else {
printf("Could not open temp file: %s!\n", tempfile );
}
diff --git a/atari/global_evnt.c b/atari/global_evnt.c
index 1a0e8f6..0c9dfdc 100755
--- a/atari/global_evnt.c
+++ b/atari/global_evnt.c
@@ -170,21 +170,9 @@ static void __CDECL menu_save_page(WINDOW *win, int item, int title,
void *data)
do {
// TODO: localize string
- path = file_select( "Select folder", "" );
- if( path ) {
- printf("testing: %s\n", path );
- // dumb check if the selection is an folder:
- /*FILE * fp;
- fp = fopen( path, "r" );
- if( !fp ){
- is_folder = true;
- } else {
- fclose( fp );
- form_alert(1, "[1][Please select an folder or abort!][OK]");
- }
- */
- is_folder = true;
- }
+ path = file_select("Select folder", "");
+ if (path)
+ is_folder = is_dir(path);
} while( !is_folder && path != NULL );
if( path != NULL ){
diff --git a/atari/misc.c b/atari/misc.c
index 3721847..054684a 100755
--- a/atari/misc.c
+++ b/atari/misc.c
@@ -45,6 +45,11 @@
#include "cflib.h"
extern void * h_gem_rsrc;
+
+struct is_process_running_callback_data {
+ const char * fname;
+ bool found;
+};
void warn_user(const char *warning, const char *detail)
{
@@ -152,6 +157,86 @@ struct gui_window * find_cmp_window( COMPONENT * c )
gw = gw->next;
}
return( NULL );
+}
+
+static int scan_process_list(scan_process_callback cb, void *data)
+{
+ int pid, count = 0;
+ DIR *dir;
+ char*dirname;
+ struct dirent *de;
+
+ if (( dir = opendir("U:/kern")) == NULL)
+ return(0);
+
+ while ((de = readdir( dir)) != NULL) {
+ dirname = de->d_name;
+
+ if( dirname[0] != '1' && dirname[0] != '2' &&
dirname[0] != '3' && dirname[0] != '4' && dirname[0] !=
'5'
+ && dirname[0] != '6' && dirname[0] != '7' &&
dirname[0] != '8' && dirname[0] != '9')
+ continue;
+
+ count++;
+ if (cb != NULL) {
+ /* when callback returns negative value, we stop scanning: */
+ pid = atoi(dirname);
+ if (cb(pid, data)<0) {
+ break;
+ }
+ }
+ }
+
+ closedir(dir);
+
+ return(count);
+}
+
+static int proc_running_callback(int pid, void * arg)
+{
+ char buf[PATH_MAX], fnamepath[256];
+ FILE *fp;
+ int nread;
+ struct is_process_running_callback_data *data;
+
+ data = (struct is_process_running_callback_data *)arg;
+
+ sprintf(fnamepath, "U:\\kern\\%d\\fname", pid);
+
+ fp = fopen(fnamepath, "r");
+ if(!fp)
+ return(0);
+
+ nread = fread(buf, 1, PATH_MAX-1, fp);
+ fclose(fp);
+
+ if (nread > 0) {
+ buf[nread] = 0;
+
+ char *lastslash = strrchr(buf, '/');
+
+ if(lastslash == NULL)
+ lastslash = strrchr(buf, '\\');
+
+ if(lastslash==NULL)
+ lastslash = buf;
+ else
+ lastslash++;
+
+ if(strcasecmp(lastslash, data->fname)==0){
+ data->found = true;
+ return(-1);
+ }
+ }
+ return(0);
+}
+
+bool is_process_running(const char * name)
+{
+ struct is_process_running_callback_data data = {name, false};
+
+ scan_process_list(proc_running_callback, &data);
+
+ return( (data.found==1) ? true : false );
}
diff --git a/atari/misc.h b/atari/misc.h
index edd026b..612113f 100755
--- a/atari/misc.h
+++ b/atari/misc.h
@@ -39,9 +39,12 @@
/* Modes for find_gui_window: */
#define BY_WINDOM_HANDLE 0x0
#define BY_GEM_HANDLE 0x1
+
+typedef int (*scan_process_callback)(int pid, void *data);
struct gui_window * find_gui_window( unsigned long, short mode );
-struct gui_window * find_cmp_window( COMPONENT * c );
+struct gui_window * find_cmp_window( COMPONENT * c );
+bool is_process_running(const char * name);
OBJECT *get_tree( int idx );
char *get_rsc_string( int idx );
void gem_set_cursor( MFORM_EX * cursor );
--
NetSurf Browser