Commit 3a6563d6 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

examples: adhere to curl code style

All plain C examples now (mostly) adhere to the curl code style. While
they are only examples, they had diverted so much and contained all
sorts of different mixed code styles by now. Having them use a unified
style helps users and readability. Also, as they get copy-and-pasted
widely by users, making sure they're clean and nice is a good idea.

573 checksrc warnings were addressed.
parent 936d8f07
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2016, 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
@@ -157,7 +157,8 @@ int main(void)
#else
        sleep(L / 1000);
#endif
      } else {
      }
      else {
        T.tv_sec = L/1000;
        T.tv_usec = (L%1000)*1000;

+5 −5
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2016, 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
+19 −19
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2016, 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 −34
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2016, 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
@@ -77,43 +77,58 @@ int main(int argc, char *argv[])
                  "\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n",
                  appname);
          exit(1);
        } else if (strncasecmp(*argv, "-V", 2) == 0) {
        }
        else if(strncasecmp(*argv, "-V", 2) == 0) {
          fprintf(stderr, "\r%s %s - %s\n",
                  appname, CHKSPEED_VERSION, curl_version());
          exit(1);
        } else if (strncasecmp(*argv, "-A", 2) == 0) {
        }
        else if(strncasecmp(*argv, "-A", 2) == 0) {
          prtall = 1;
        } else if (strncasecmp(*argv, "-X", 2) == 0) {
        }
        else if(strncasecmp(*argv, "-X", 2) == 0) {
          prtsep = 1;
        } else if (strncasecmp(*argv, "-T", 2) == 0) {
        }
        else if(strncasecmp(*argv, "-T", 2) == 0) {
          prttime = 1;
        } else if (strncasecmp(*argv, "-M=", 3) == 0) {
        }
        else if(strncasecmp(*argv, "-M=", 3) == 0) {
          long m = strtol((*argv)+3, NULL, 10);
          switch(m) {
            case   1: url = URL_1M;
          case 1:
            url = URL_1M;
            break;
            case   2: url = URL_2M;
          case 2:
            url = URL_2M;
            break;
            case   5: url = URL_5M;
          case 5:
            url = URL_5M;
            break;
            case  10: url = URL_10M;
          case 10:
            url = URL_10M;
            break;
            case  20: url = URL_20M;
          case 20:
            url = URL_20M;
            break;
            case  50: url = URL_50M;
          case 50:
            url = URL_50M;
            break;
            case 100: url = URL_100M;
          case 100:
            url = URL_100M;
            break;
            default:  fprintf(stderr, "\r%s: invalid parameter %s\n",
          default:
            fprintf(stderr, "\r%s: invalid parameter %s\n",
                    appname, *argv + 3);
            exit(1);
          }
        } else {
        }
        else {
          fprintf(stderr, "\r%s: invalid or unknown option %s\n",
                  appname, *argv);
          exit(1);
        }
      } else {
      }
      else {
        url = *argv;
      }
    }
@@ -178,8 +193,8 @@ int main(int argc, char *argv[])
      if((CURLE_OK == res) && (val>0))
        printf("Connect time: %0.3f sec.\n", val);
    }

  } else {
  }
  else {
    fprintf(stderr, "Error while fetching '%s' : %s\n",
            url, curl_easy_strerror(res));
  }
+4 −4
Original line number Diff line number Diff line
@@ -50,9 +50,9 @@ void *my_thread(void *ptr)
  gchar *url = ptr;

  curl = curl_easy_init();
  if(curl)
  {
    outfile = fopen("test.curl", "w");
  if(curl) {
    const char *filename = "test.curl";
    outfile = fopen(filename, "wb");

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
Loading