Clicky
Showing changes from revision #3 to #4:
(追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)
I use the jsu_readline, probably from ‘urbanjost’, found many years ago somewhere in the internet. It works fine for a long time, still with some warnings compiling the subroutine FCreadline.c. Since debian 13 gfortran (gcc version 14.2.0) it rejects this subroutine as erroneous.
I found this subroutine in the Fortran Wiki as iso_readline(3f). Compiling it results in the same error (the comment marker in the 6th line of this example should read read / instead of / ?):
fcreadline.c:24:1: error: return type defaults to ‘int’ [-Wimplicit-int] 24 | FCreadline(int len, charmyline, char prompt[]){ | ^~~~~~~~~~ My work around: using the object file FCreadline.o from debian12, which is not as it should work.
(削除ここまで)fcreadline.c:24:1: error: return type defaults to 'int' [-Wimplicit-int]
24 | FCreadline(int *len, char *myline, char prompt[]){
| ^~~~~~~~~~
(追記ここまで)
(追記) My work around: using the object file FCreadline.o from debian12, which is not as it should work.
(追記ここまで)(追記) (追記ここまで)Is there a corrected ersion available? Thanks in advance.
The message is indicating the return value needs explicitly declared, or in this case, needs set to void. Place the word "void" in front of FCreadline. I am not at a place were I can verify that is all that is needed, but I will change the entry found here on the Fortran wiki accordingly. https://github.com/urbanjost/general-purpose-fortran contains the latest version of this and a few thousand other routines as well.
Reply:
Well, ‘void’ did the job to get rif of the error flag, the warnings still arose. With the help of a friend (Andreas) we were able to loacate two statements in ‘FCreadline.c’, which need to be changed (see below). The ‘testit’ example works as well as my Fortran applications.
I enclose the complete function. German comments denote the modifications. Thank you.
—————————– 8>< ——————————————————— /* @(#) Fortran-callable C routine that calls readline(3c) The Fortran routine can use the f2003 ISO_C_BINDING module to do this in a portable manner. assumes you have the GNU readline library libreadline.a available /
(削除ここまで)/*
@(#) Fortran-callable C routine that calls readline(3c)
The Fortran routine can use the f2003 ISO_C_BINDING module
to do this in a portable manner.
assumes you have the GNU readline library libreadline.a available
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <readline/readline.h>
#include <readline/history.h>
/* --------------------------------------------------------------------- */
void show_history_list() {
HISTORY_STATE *state = history_get_history_state();
int i;
printf("History list now:\n");
for (i=0; i < state->length; i++) {
printf("%d: '%s'%s\n", i, state->entries[i]->line, (i == state->offset? "*":""));
}
}
/* -------------------------------------------------------------------------- */
// void FCreadline(int *len, char *myline, char prompt[]){
void FCreadline(int len, char *myline, const char *prompt){
/*
@(#)FCreadline.sh return line from readline(3c) to Fortran. John S. Urban, 20100323
Simple procedure that uses readline in "normal" (i.e. non-callback) mode.
len -- number of characters in argument "myline"
myline -- Fortran CHARACTER variable to receive the line read by readline(3c)
prompt -- prompt string to precede read
*/
/* readline(3c) will return the read line to this pointer */
char *line;
/* counter for padding returned line with spaces */
int i;
using_history();
/* use readline(3c) to read a line of input in edit mode */
line=readline(prompt);
add_history(line);
/* if the "h" command is on a line by itself show history */
if(strcmp(line,"h")==0){
show_history_list();
}
/* copy line returned by readline(3c) to MYLINE up to length of MYLINE */
// ersetzt: strncpy(myline,line,(size_t)*len);
strncpy(myline,line,(size_t)len);
/* starting with null, pad with spaces to end */
// ersetzt: for(i=strlen(line);i<(int)*len;i++){
for(i=strlen(line);i<len;i++){
myline[i]=' ';
}
/* free memory used to return line from readline(3c) */
if (line) // neu: als sicherheit wenn readline mal
// NULL zurückgeben sollte. Dann würde ohne diese Abfrage
// der Aufruf von free() crashen.
free(line);
}
(追記ここまで)/* ——————————————————————— / void show_history_list() { HISTORY_STATEstate = history_get_history_state(); int i; printf("History list now:\n"); for (i=0; i < state->length; i++) { printf("%d: ‘%s’%s\n", i, state->entries[i]->line, (i == state->offset? "":"")); }
} / ————————————————————————– / // void FCreadline(intlen, char myline, char prompt[]){ void FCreadline(int len, charmyline, const char prompt){ / @(#)FCreadline.sh return line from readline(3c) to Fortran. John S. Urban, 20100323
Simple procedure that uses readline in "normal" (i.e. non-callback) mode.
(削除ここまで)len – number of characters in argument "myline" myline – Fortran CHARACTER variable to receive the line read by readline(3c) prompt – prompt string to precede read
(削除ここまで)/ / readline(3c) will return the read line to this pointer / charline; /* counter for padding returned line with spaces / int i;
(削除ここまで)using_history();
/* use readline(3c) to read a line of input in edit mode / line=readline(prompt); add_history(line);
/* if the "h" command is on a line by itself show history / if(strcmp(line,"h")==0){ show_history_list(); }
(削除ここまで)/* copy line returned by readline(3c) to MYLINE up to length of MYLINE / // ersetzt: strncpy(myline,line,(size_t)len); strncpy(myline,line,(size_t)len);
(削除ここまで)/* starting with null, pad with spaces to end / // ersetzt: for(i=strlen(line);i<(int)len;i++){ for(i=strlen(line);i
(削除ここまで)/* free memory used to return line from readline(3c) / if (line) // neu: als sicherheit wenn readline mal // NULL zurückgeben sollte. Dann würde ohne diese Abfrage // der Aufruf von free() crashen. free(line);
}