Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoize most functions #55

Merged
merged 5 commits into from
Jan 10, 2023
Merged

protoize most functions #55

merged 5 commits into from
Jan 10, 2023

Conversation

schwehr
Copy link
Collaborator

@schwehr schwehr commented Jan 7, 2023

Converts old style K & R function definitions to ANSI style.

  • Converts old style K & R function definitions to ANSI style.
  • Does not change any of the headers or local file prototypes.
  • Does not fix some varargs

The changes are generally of this form:

-xdrposix_putint(xdrs, lp)
-    XDR *xdrs;
-    int *lp;
+xdrposix_putint(XDR *xdrs, int *lp)

@derobins
Copy link
Member

derobins commented Jan 7, 2023

This is great. All K&R C in HDF4 should be converted to ANSI C.

@derobins
Copy link
Member

derobins commented Jan 7, 2023

Can this be fixed via clang format? We have another (draft) PR where we will implement that.

Hmm... It looks like clang format is profoundly confused by K&R C. I think we'll have to do this first (if we can't fix the script) and then implement standardized formatting.

@schwehr
Copy link
Collaborator Author

schwehr commented Jan 7, 2023

Can this be fixed via clang format? We have another (draft) PR where we will implement that.

Hmm... It looks like clang format is profoundly confused by K&R C. I think we'll have to do this first (if we can't fix the script) and then implement standardized formatting.

I don't think clang-format can. And gcc dropped protoize long ago.

https://invisible-island.net/cproto/cproto.html appears to be in debian testing. Haven't tried it yet.

apt-cache show cproto
Package: cproto
Version: 4.7u-1
Installed-Size: 122
Maintainer: Kenneth J. Pronovici <[email protected]>
Architecture: amd64
Depends: libc6 (>= 2.34), gcc
Description: utilities to generate C function prototypes from C source code
 Cproto is a program that generates function prototypes and variable
 declarations from C source code.  It can also convert function
 definitions between the old style and the ANSI C style.  This
 conversion overwrites the original files, so make a backup copy of
 your files in case something goes wrong.
Description-md5: fe74472d82a7bc4da41968b3563d1a85
Homepage: https://invisible-island.net/cproto/cproto.html
Filename: pool/cproto_4.7u-1_amd64_577d011b4aa7a9368b61b500dcb1e268153eda8611c1a3101f4e96424cd11db0.deb
Priority: optional
SHA256: 577d011b4aa7a9368b61b500dcb1e268153eda8611c1a3101f4e96424cd11db0
Section: devel
Size: 58210

@schwehr
Copy link
Collaborator Author

schwehr commented Jan 7, 2023

cproto will take some hacking to get working... I need to tell it where to find includes. But without that after doing to trickery:

cproto xdrposix.c 
/* xdrposix.c */
xdrposix.c:324: syntax error at token 'XDR'
Expected: {
xdrposix.c:326: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:347: syntax error at token 'XDR'
Expected: {
xdrposix.c:351: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:396: syntax error at token 'XDR'
Expected: {
xdrposix.c:397: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:422: syntax error at token 'XDR'
Expected: {
xdrposix.c:423: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:441: syntax error at token 'xdrposix_getlong'
Expected: ',' ';' '=' asm
xdrposix.c:444: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:459: syntax error at token 'xdrposix_putlong'
Expected: ',' ';' '=' asm
xdrposix.c:462: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:479: syntax error at token 'xdrposix_getbytes'
Expected: ',' ';' '=' asm
xdrposix.c:481: syntax error at token 'addr'
xdrposix.c:487: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:496: syntax error at token 'xdrposix_putbytes'
Expected: ',' ';' '=' asm
xdrposix.c:498: syntax error at token 'addr'
xdrposix.c:504: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:514: syntax error at token 'XDR'
Expected: {
xdrposix.c:515: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:522: syntax error at token 'xdrposix_setpos'
Expected: ',' ';' '=' asm
xdrposix.c:525: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:565: syntax error at token '*'
Expected: ',' ';' '=' asm
xdrposix.c:574: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:588: syntax error at token 'xdrposix_getint'
Expected: ',' ';' '=' asm
xdrposix.c:591: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:602: syntax error at token 'xdrposix_putint'
Expected: ',' ';' '=' asm
xdrposix.c:605: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:620: syntax error at token 'XDR'
Expected: {
xdrposix.c:621: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void
xdrposix.c:627: syntax error at token 'XDR'
Expected: {
xdrposix.c:630: syntax error at token '{'
Expected: "end of file" '&' '(' '*' ';' asm auto bool char complex ... void

@schwehr
Copy link
Collaborator Author

schwehr commented Jan 7, 2023

So -I works as expected.

cproto -I../../build-ninja -I../../hdf/src  -I../../build-ninja -I. xdrposix.c 
/* xdrposix.c */
In file included from xdrposix.c:29:
local_nc.h:57:15: fatal error: types.h: No such file or directory
   57 | #include      "types.h"  /* <types.h */
      |               ^~~~~~~~~

@schwehr
Copy link
Collaborator Author

schwehr commented Jan 8, 2023

Trying a bit more, I wasn't successful with cproto.

cproto -i -s -q -a -I../../build-ninja -I../../hdf/src  -I../../build-ninja -I../xdr  -I. xdrposix.c 

/* xdrposix.c */
/usr/include/sys/cdefs.h:591: bad character '0'
/usr/include/sys/cdefs.h:591: syntax error at token ','
Expected: '&' '(' ')' '*' [] auto bool char complex define-name double ... void
/usr/include/string.h:34: cannot read file <stddef.h>
/usr/include/string.h:44: syntax error at token 'size_t'
Expected: ... auto bool char complex define-name double enum extension ... void
/usr/include/string.h:44: bad character '1'
/usr/include/string.h:44: bad character '2'
/usr/include/string.h:47: syntax error at token 'size_t'
Expected: ... auto bool char complex define-name double enum extension ... void
/usr/include/string.h:48: bad character '1'
/usr/include/string.h:48: bad character '2'
...

@schwehr
Copy link
Collaborator Author

schwehr commented Jan 9, 2023

Have been skipping varargs stuff like in error handlers.

There are also these to make sure I get.

find . -name "*.[ch]" | xargs grep PROTOTYPE
./hdf/src/mfgrf.c:#ifdef PROTOTYPE
./hdf/src/mfgrf.c:#endif /* PROTOTYPE */
./hdf/src/mfgrf.c:#ifdef PROTOTYPE 
./hdf/src/mfgrf.c:#endif /* PROTOTYPE */

[SNIP]

./mfhdf/fortran/mfsdf.c:#ifdef PROTOTYPE
./mfhdf/fortran/mfsdf.c:#endif /* PROTOTYPE */
./mfhdf/ncgen/genlib.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/nctest/add.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/nctest/emalloc.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/nctest/driver.c:#ifdef PROTOTYPE
./mfhdf/nctest/val.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/nctest/error.h:#ifndef NO_HAVE_PROTOTYPES
./mfhdf/nctest/tests.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/ncdump/vardata.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/ncdump/dumplib.h:#ifndef NO_HAVE_PROTOTYPES 
./mfhdf/test/cdftest.c:#ifdef PROTOTYPE
./mfhdf/libsrc/local_nc.h:#define PROTOTYPE
./mfhdf/libsrc/local_nc.h:#ifndef NO_HAVE_PROTOTYPES

and

find . -name "*.[ch]" | xargs grep NO_STDARG 
./mfhdf/ncgen/genlib.h:#ifndef NO_STDARG
./mfhdf/ncgen/genlib.c:#ifndef NO_STDARG
./mfhdf/ncgen/genlib.c:#endif /* !NO_STDARG */
./mfhdf/ncgen/genlib.c:#ifndef NO_STDARG
./mfhdf/ncgen/genlib.c:#endif /* !NO_STDARG */
./mfhdf/ncgen/genlib.c:#ifndef NO_STDARG
./mfhdf/ncgen/genlib.c:#endif /* !NO_STDARG */
./mfhdf/nctest/error.c:#ifndef NO_STDARG
./mfhdf/nctest/error.c:#ifndef NO_STDARG
./mfhdf/nctest/error.c:#ifndef NO_STDARG
./mfhdf/nctest/error.h:#ifndef NO_STDARG
./mfhdf/ncdump/dumplib.c:#ifndef NO_STDARG
./mfhdf/ncdump/dumplib.c:#ifndef NO_STDARG
./mfhdf/ncdump/dumplib.c:#ifndef NO_STDARG
./mfhdf/ncdump/dumplib.h:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#ifdef NO_STDARG  /* The 4.0 release should be ANSI compliant */
./mfhdf/libsrc/error.c:#undef NO_STDARG
./mfhdf/libsrc/error.c:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#endif /* !NO_STDARG */
./mfhdf/libsrc/error.c:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#endif /* !NO_STDARG */
./mfhdf/libsrc/error.c:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#endif /* !NO_STDARG */
./mfhdf/libsrc/error.c:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#endif /* !NO_STDARG */
./mfhdf/libsrc/error.c:#ifndef NO_STDARG
./mfhdf/libsrc/error.c:#endif /* !NO_STDARG */
./mfhdf/libsrc/error.h:#ifndef NO_STDARG
./mfhdf/libsrc/error.h:#endif /* NO_STDARG */

- Converts old style K & R function definitions to ANSI style.
- Does not change any of the headers or local file prototypes.
- Does not fix some varargs
@schwehr schwehr changed the title xdrposix.c: protoize functions protoize most functions Jan 10, 2023
@schwehr schwehr marked this pull request as ready for review January 10, 2023 07:36
@derobins derobins merged commit 0f574c2 into HDFGroup:master Jan 10, 2023
@schwehr schwehr deleted the protoize branch January 10, 2023 16:47
@schwehr schwehr mentioned this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants