*> ************************************************************** *> * access libcurl to update current OC1.1 source archive *> ************************************************************** *> Authors: Brian Tiffin, Joseph James Frantz *> Dates: 22-July-2008, 29-July-2008, 19-November-2008 *> Purpose: Sample calls to occurl wrapper *> Wasn't designed to be called a binding *> Tectonics: cobc -c -Wall occurl.c *> cobc -x -lcurl occurlrefresh.cbl occurl.o *> ./occurlrefresh [-v|-q] [url file] [-v|-q url file] identification division. program-id. occurlrefresh. environment division. input-output section. data division. working-storage section. copy occurlsym. 78 newline value x"0a". 01 args pic x(1024). 01 urlarg pic x(255). 88 urlarg-oc value 'http://www.sim-basis.de/open-cobol-1.1.tar.gz'. 01 filearg pic x(255). 88 filearg-oc value 'open-cobol-1.1.tar.gz'. 01 verbarg pic x(255). 01 argcount pic s9(9) comp-5. 01 verbosity pic 9(9) usage binary value 1. 88 quiet value 0. 88 verbose value 1 thru 2. 88 veryverbose value 2. local-storage section. 01 curl usage pointer. 01 result pic s9(9) comp-5. 01 curlurl pic x(256). 01 curlfile pic x(256). 01 starttime pic s9(7)v99 comp-5. 01 endtime pic s9(7)v99 comp-5. 01 showtime pic z(6)9.99. 01 modtime usage binary-c-long. *> Update the OC 1.1 tar if applicable by modification time procedure division. *> Pull any command line arguments accept args from command-line end-accept unstring args delimited by all spaces into verbarg urlarg filearg tallying in argcount end-unstring *> no args is still argcount 1 if verbarg equals spaces subtract 1 from argcount end-subtract end-if evaluate argcount when 0 set urlarg-oc to true set filearg-oc to true when 1 evaluate verbarg when "-q" set quiet to true when "-v" set veryverbose to true when other move 1 to verbosity end-evaluate set urlarg-oc to true set filearg-oc to true when 2 move urlarg to filearg move verbarg to urlarg when 3 evaluate verbarg when "-q" set quiet to true when "-v" set veryverbose to true when other move 1 to verbosity end-evaluate end-evaluate *> null terminate the strings for C string urlarg delimited by space low-value delimited by size into curlurl end-string string filearg delimited by space low-value delimited by size into curlfile end-string *> parameters ready if verbose display "file: " function trim(filearg trailing) " from url: " function trim(urlarg trailing) end-display end-if *> let libcurl do all the hard work call "CBL_OC_CURL_INIT" returning curl end-call. *> Set some verbosity options if verbose call "CBL_OC_CURL_PROGRESS" using by value curl by value verbosity end-call end-if if veryverbose call "CBL_OC_CURL_VERBOSE" using by value curl by value verbosity end-call end-if *> move zero to modtime, retrieve_file will test local modtime move 0 to modtime accept starttime from time end-accept call "CBL_OC_CURL_RETRIEVE_FILE" using by value curl by reference curlurl by reference curlfile by reference modtime returning result end-call if verbose accept endtime from time end-accept subtract starttime from endtime giving starttime end-subtract divide starttime by 100 giving starttime end-divide move starttime to showtime display newline "Done in " showtime end-display if result not = 0 display "result: " result " - " CURLEMSG(result) end-display end-if end-if call "CBL_OC_CURL_CLEANUP" using by value curl end-call stop run giving result continue. exit program.