*> ************************************************************** *> * access libcurl to update current OC1.1 source archive *> ************************************************************** *> Authors: Brian Tiffin, Joseph James Frantz *> Dates: 22-Jul-2008, 29-Jul-2008, 19-Nov-2008, 22-Jan-2009 *> Purpose: Sample calls to occurl wrapper to fetch OC1.1 tar *> Wasn't designed to be called a binding *> Tectonics: cobc -c -Wall occurl.c *> cobc -x -lcurl occurlrefresh.cbl occurl.o *> ./occurlrefresh [-v|-q|-b] [url file] [-v|-q url file] replace ==#display-attributes#== by ==background-color 7 foreground-color 0==. identification division. program-id. occurlrefresh. data division. working-storage section. copy occurlsym. 01 newline constant as 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. 01 builder pic 9 usage binary value 0. 88 building value 1. 01 buildit pic x. 01 hitanykey pic x. 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. 01 progress-callback-pointer usage procedure-pointer. *> 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 "--help" perform helping when "-h" perform helping when "-q" set quiet to true when "-v" set veryverbose to true when "-b" set building to true move 1 to verbosity 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 "--help" perform helping when "-h" perform helping 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 function concatenate ( "file: " function trim(filearg trailing) " from url: " function trim(urlarg trailing) ) at 0101 with #display-attributes# blank screen 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 set progress-callback-pointer to address of program "progress-callback" call "CBL_OC_CURL_PROGRESS" using by value curl by value verbosity by value progress-callback-pointer 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 *> report the results 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 function concatenate( "Done in " showtime) at 0301 with #display-attributes# end-display if result not = 0 display "result: " result " - " CURLEMSG(result) end-display end-if end-if *> release the libcurl resources call "CBL_OC_CURL_CLEANUP" using by value curl end-call *> if results not good, end the run if result not = 0 stop run returning result end-if *> if building, call the system to configure and make OC if building display "Do a build? (y/N):" with no advancing end-display accept buildit end-accept if function upper-case(buildit) = "Y" call "SYSTEM" using by reference function concatenate( "mv open-cobol-1.1 open-cobol-1.1-" function current-date(1:14) "; tar xvf "; function trim(filearg trailing); " && cd open-cobol-1.1" " && ./configure && make") returning result if result not = 0 stop run returning result end-if display "OpenCOBOL 1.1 ready to install in open-cobol-1.1" end-display end-if end-if *> we're done display "Hit any key..." at 0401 with #display-attributes# end-display *> Rely on fact that curses still active call "noecho" end-call call "cbreak" end-call call "getch" end-call move result to return-code goback. *> the help paragraph helping. display "./occurlrefresh [-h|-v|-q|-b] [url file]" & " [-h|-v|-q url file]" end-display display "Where: -h or --help displays this help" end-display display " -v turns on maximum verbosity" end-display display " -q turns off output" end-display display " -b builds OpenCOBOL" end-display display "Defaults are:" end-display set urlarg-oc to true set filearg-oc to true display " url: " function trim(urlarg) end-display display " file: " function trim(filearg) end-display display "build in: open-cobol-1.1 " & "archive in open-cobol-1.1-YYYMMDDhhmmss" end-display move 0 to return-code goback. *> *************************************************************** end program occurlrefresh. *> *************************************************************** *> Author: Brian Tiffin *> Date: 20090313 *> Purpose: callback for progress display *> *************************************************************** identification division. program-id. progress-callback. data division. working-storage section. 01 percent pic 999v99. 01 progress pic 999. 01 progress-bar pic x(51) value all "+". 01 display-bar pic x(51) value spaces. local-storage section. linkage section. 01 bar usage float-long. 01 dltotal usage float-long. 01 dlnow usage float-long. 01 ultotal usage float-long. 01 ulnow usage float-long. *> *************************************************************** procedure division using by value size 4 bar by value size 8 dltotal by value size 8 dlnow by value size 8 ultotal by value size 8 ulnow. compute percent = dlnow / dltotal * 100. move percent to progress move progress-bar ( 1 : 1 + percent / 2) to display-bar display progress at 0201 with #display-attributes# end-display display display-bar at 0205 with #display-attributes# end-display goback. end program progress-callback.