int useepsv = 0;
int useepsv = 1;
CurlFetchCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]){	int theResult = TCL_OK;	CURL* theHandle = NULL;	FILE* theFile = NULL;	do {		long theResponseCode = 0;		int noprogress = 1;		int useepsv = 0;		const char* theUserPassString = NULL;		int optioncrsr;		int lastoption;		const char* theURL;		const char* theFilePath;		CURLcode theCurlCode;				/* we might have options and then the url and the file */		/* let's process the options first */				optioncrsr = 2;		lastoption = objc - 3;		while (optioncrsr <= lastoption) {			/* get the option */			const char* theOption = Tcl_GetString(objv[optioncrsr]);						if (strcmp(theOption, "-v") == 0) {				noprogress = 0;			} else if (strcmp(theOption, "--disable-epsv") == 0) {				useepsv = 1;			} else if (strcmp(theOption, "-u") == 0) {				/* check we also have the parameter */				if (optioncrsr < lastoption) {					optioncrsr++;					theUserPassString = Tcl_GetString(objv[optioncrsr]);				} else {					Tcl_SetResult(interp,						"curl fetch: -u option requires a parameter",						TCL_STATIC);					theResult = TCL_ERROR;					break;									}			} else {				char theErrorString[512];				(void) snprintf(theErrorString, sizeof(theErrorString),					"curl fetch: unknown option %s", theOption);				Tcl_SetResult(interp, theErrorString, TCL_VOLATILE);				theResult = TCL_ERROR;				break;			}						optioncrsr++;		}				if (optioncrsr <= lastoption) {			/* something went wrong */			break;		}		/*	first (second) parameter is -v or the url,			second (third) parameter is the file */		if (objc >= 4) {			/* Retrieve the url */			theURL = Tcl_GetString(objv[objc - 2]);				/* Retrieve the file path */			theFilePath = Tcl_GetString(objv[objc - 1]);		} else {			Tcl_WrongNumArgs(interp, 1, objv, "fetch [options] url file");			theResult = TCL_ERROR;			break;		}				/* Open the file */		theFile = fopen( theFilePath, "w" );		if (theFile == NULL) {			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);			theResult = TCL_ERROR;		}		/* Create the CURL handle */		theHandle = curl_easy_init();				/* Setup the handle */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* -L option */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FOLLOWLOCATION, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* -f option */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FAILONERROR, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* write to the file */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_WRITEDATA, theFile);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* we want/don't want progress */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_NOPROGRESS, noprogress);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* we want/don't want to use epsv */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FTP_USE_EPSV, useepsv);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* set the l/p, if any */		if (theUserPassString) {			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_USERPWD, theUserPassString);			if (theCurlCode != CURLE_OK) {				theResult = SetResultFromCurlErrorCode(interp, theCurlCode);				break;			}		}		/* actually fetch the resource */		theCurlCode = curl_easy_perform(theHandle);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* close the file */		(void) fclose( theFile );		theFile = NULL;				/* check everything went fine */		theCurlCode = curl_easy_getinfo(theHandle, CURLINFO_RESPONSE_CODE, &theResponseCode);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* we need something between 200 (incl.) and 300 (excl.). */		if ((theResponseCode < 200) || (theResponseCode >= 300)) {			char theErrorString[512];			(void) snprintf(theErrorString, sizeof(theErrorString),				"Download failed (code = %li)", theResponseCode);			Tcl_SetResult(interp, theErrorString, TCL_VOLATILE);			theResult = TCL_ERROR;			break;		}				/* clean up */		curl_easy_cleanup( theHandle );		theHandle = NULL;    } while (0);        if (theHandle != NULL) {    	curl_easy_cleanup( theHandle );    }    if (theFile != NULL) {    	fclose( theFile );    }    	return theResult;}