]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
opt-docs: make sure all man pages have examples
authorDaniel Stenberg <daniel@haxx.se>
Wed, 1 Sep 2021 07:23:37 +0000 (09:23 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 4 Sep 2021 09:27:04 +0000 (11:27 +0200)
Extended manpage-syntax.pl (run by test 1173) to check that every man
page for a libcurl option has an EXAMPLE section that is more than two
lines. Then fixed all errors it found and added examples.

Reviewed-by: Daniel Gustafsson
Closes #7656

docs/libcurl/opts/CURLOPT_DEBUGDATA.3
docs/libcurl/opts/CURLOPT_FTP_USE_EPRT.3
docs/libcurl/opts/CURLOPT_NOSIGNAL.3
docs/libcurl/opts/CURLOPT_PIPEWAIT.3
docs/libcurl/opts/CURLOPT_PROGRESSDATA.3
docs/libcurl/opts/CURLOPT_PROGRESSFUNCTION.3
docs/libcurl/opts/CURLOPT_PUT.3
docs/libcurl/opts/CURLOPT_WILDCARDMATCH.3
docs/libcurl/opts/CURLOPT_XFERINFODATA.3
docs/libcurl/opts/CURLOPT_XFERINFOFUNCTION.3
tests/manpage-syntax.pl

index 6031a90e4688a752e7b6d4be86fab30265ca15db..6803abcf00c4a2789438869103877afb8ddb4df9 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -36,7 +36,31 @@ NULL
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-https://curl.se/libcurl/c/debug.html
+.nf
+int main(void)
+{
+  CURL *curl;
+  CURLcode res;
+  struct data my_tracedata;
+
+  curl = curl_easy_init();
+  if(curl) {
+    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
+
+    curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &my_tracedata);
+
+    /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
+    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+    res = curl_easy_perform(curl);
+
+    /* always cleanup */
+    curl_easy_cleanup(curl);
+  }
+  return 0;
+}
+.fi
 .SH AVAILABILITY
 Always
 .SH RETURN VALUE
index 39fe8c02200bde62da8c18bcc4f217570f7809d9..e11bde4b5af5be75b28206bd1056288dedc8aba4 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -39,6 +39,22 @@ necessary then.
 .SH DEFAULT
 .SH PROTOCOLS
 .SH EXAMPLE
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
+
+  /* contact us back, aka "active" FTP */
+  curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
+
+  /* FTP the way the neanderthals did it */
+  curl_easy_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
+
+  ret = curl_easy_perform(curl);
+
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.10.5
 .SH RETURN VALUE
index 460a8e6b2fd83c2d0ff1ca416714a6bd72a85079..3ee715ea10a81cc1401b774b6ab7da532245756b 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -49,6 +49,19 @@ cases when they may still happen, contrary to our desire. In addition, using
 raised.
 .SH DEFAULT
 0
+.SH EXAMPLE
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+
+  curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
+
+  ret = curl_easy_perform(curl);
+
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.10
 .SH RETURN VALUE
index 8b85b468cf51e28bda4fa2f17b85b771e421b24b..abc2fd5dfa60ab7d51d148209decc2cd4ae1d190 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -54,6 +54,15 @@ and support level.
 .SH PROTOCOLS
 HTTP(S)
 .SH EXAMPLE
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
+  curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
+
+  /* now add this easy handle to the multi handle */
+}
+.fi
 .SH AVAILABILITY
 Added in 7.43.0
 .SH RETURN VALUE
index bcab72400e54aab0140fd2f86130a41fdc25ecdf..bcfcfb9e74d581ed72e14729161485522e1bb89b 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -35,7 +35,32 @@ The default value of this parameter is NULL.
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-https://curl.se/libcurl/c/progressfunc.html
+.nf
+ struct progress {
+   char *private;
+   size_t size;
+ };
+
+ static size_t progress_callback(void *clientp,
+                                 double dltotal,
+                                 double dlnow,
+                                 double ultotal,
+                                 double ulnow)
+ {
+   struct memory *progress = (struct progress *)userp;
+
+   /* use the values */
+
+   return 0; /* all is good */
+ }
+
+ struct progress data;
+
+ /* pass struct to callback  */
+ curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, &data);
+
+ curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
+.fi
 .SH AVAILABILITY
 Always
 .SH RETURN VALUE
index 44921371601983103af1ac50ff990839351def0c..e21ca1ccb2a561847a6a1094157b6cb5063fb2cb 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -78,7 +78,32 @@ users.
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-https://curl.se/libcurl/c/progressfunc.html
+.nf
+ struct progress {
+   char *private;
+   size_t size;
+ };
+
+ static size_t progress_callback(void *clientp,
+                                 double dltotal,
+                                 double dlnow,
+                                 double ultotal,
+                                 double ulnow)
+ {
+   struct memory *progress = (struct progress *)userp;
+
+   /* use the values */
+
+   return 0; /* all is good */
+ }
+
+ struct progress data;
+
+ /* pass struct to callback  */
+ curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, &data);
+
+ curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
+.fi
 .SH AVAILABILITY
 Always
 .SH RETURN VALUE
index a8697da2f35d27256f8f7535df6ea37a8107b93d..68f18977a44543941d1d95444ad45ecc64186b65 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -38,6 +38,29 @@ This option is \fBdeprecated\fP since version 7.12.1. Use
 0, disabled
 .SH PROTOCOLS
 HTTP
+.SH EXAMPLE
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  /* we want to use our own read function */
+  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+
+  /* enable PUT */
+  curl_easy_setopt(curl, CURLOPT_PUT, 1L);
+
+  /* specify target */
+  curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
+
+  /* now specify which pointer to pass to our callback */
+  curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
+
+  /* Set the size of the file to upload */
+  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
+
+  /* Now run off and do what you've been told! */
+  curl_easy_perform(curl);
+}
+.fi
 .SH AVAILABILITY
 Deprecated since 7.12.1. Do not use.
 .SH RETURN VALUE
index 628b4297d1adf551865d5fe2bc41a970840f88fc..67931354bf495c270295a243c5e2d90fa7527f12 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -78,7 +78,21 @@ Using the rules above, a file name pattern can be constructed:
 .SH PROTOCOLS
 This feature is only supported for FTP download.
 .SH EXAMPLE
-See https://curl.se/libcurl/c/ftp-wildcard.html
+.nf
+  /* initialization of easy handle */
+  handle = curl_easy_init();
+
+  /* turn on wildcard matching */
+  curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
+
+  /* callback is called before download of concrete file started */
+  curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
+
+  /* callback is called after data from the file have been transferred */
+  curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
+
+  /* See more on https://curl.se/libcurl/c/ftp-wildcard.html */
+.fi
 .SH AVAILABILITY
 Added in 7.21.0
 .SH RETURN VALUE
index 1d3ea2ed064532abb9b6e989a40e42d044a02789..d7aa4a77c3c3fd45a7ab0de37c8f5841d0362172 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -37,7 +37,32 @@ The default value of this parameter is NULL.
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-https://curl.se/libcurl/c/progressfunc.html
+.nf
+ struct progress {
+   char *private;
+   size_t size;
+ };
+
+ static size_t progress_callback(void *clientp,
+                                 curl_off_t dltotal,
+                                 curl_off_t dlnow,
+                                 curl_off_t ultotal,
+                                 curl_off_t ulnow)
+ {
+   struct memory *progress = (struct progress *)userp;
+
+   /* use the values */
+
+   return 0; /* all is good */
+ }
+
+ struct progress data;
+
+ /* pass struct to callback  */
+ curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
+
+ curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
+.fi
 .SH AVAILABILITY
 Added in 7.32.0
 .SH RETURN VALUE
index c9857046cb2c7648c6709444b255c6c9b6b1e1cd..72c500e922a7948fc904fdde81ad68617ee736ed 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -75,7 +75,32 @@ users.
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-https://curl.se/libcurl/c/progressfunc.html
+.nf
+ struct progress {
+   char *private;
+   size_t size;
+ };
+
+ static size_t progress_callback(void *clientp,
+                                 curl_off_t dltotal,
+                                 curl_off_t dlnow,
+                                 curl_off_t ultotal,
+                                 curl_off_t ulnow)
+ {
+   struct memory *progress = (struct progress *)userp;
+
+   /* use the values */
+
+   return 0; /* all is good */
+ }
+
+ struct progress data;
+
+ /* pass struct to callback  */
+ curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
+
+ curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
+.fi
 .SH AVAILABILITY
 Added in 7.32.0. This callback replaces \fICURLOPT_PROGRESSFUNCTION(3)\fP
 .SH RETURN VALUE
index 8885ec8ceba8b80809691ba75c2b165cc0eb9728..5a3bcec0dca5ecc9fdf834cdb338ceccf94f1041 100644 (file)
@@ -34,11 +34,28 @@ my $errors = 0;
 
 sub scanmanpage {
     my ($file) = @_;
+    my $reqex = 0;
+    my $inex = 0;
+    my $exsize = 0;
 
     print "Check $file\n";
     open(M, "<$file") || die "no such file: $file";
+    if($file =~ /\/CURL[^\/]*.3/) {
+        # This is the man page for an libcurl option. It requires an example!
+        $reqex = 1;
+    }
     my $line = 1;
     while(<M>) {
+        if($_ =~ /^.SH EXAMPLE/) {
+            $inex = 1;
+        }
+        elsif($_ =~ /^.SH/) {
+            $inex = 0;
+        }
+        elsif($inex)  {
+            $exsize++;
+        }
+
         if($_ =~ /^\'/) {
             print STDERR "$file:$line line starts with single quote!\n";
             $errors++;
@@ -57,6 +74,11 @@ sub scanmanpage {
         $line++;
     }
     close(M);
+
+    if($reqex && ($exsize < 2)) {
+        print STDERR "$file:$line missing EXAMPLE section\n";
+        $errors++;
+    }
 }