From aa46197d66ce70ece382bf955326c46b13f35864 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sat, 14 Nov 2020 22:55:31 +0100 Subject: Weed out proj_api.h datatypes and replace them with their proj.h counterparts --- src/fileapi.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/fileapi.cpp') diff --git a/src/fileapi.cpp b/src/fileapi.cpp index 70be2502..0af83926 100644 --- a/src/fileapi.cpp +++ b/src/fileapi.cpp @@ -36,7 +36,7 @@ #include "proj_internal.h" #include "filemanager.hpp" -static PAFile stdio_fopen(projCtx ctx, const char *filename, +static PAFile stdio_fopen(PJ_CONTEXT *ctx, const char *filename, const char *access); static size_t stdio_fread(void *buffer, size_t size, size_t nmemb, PAFile file); @@ -53,7 +53,7 @@ static projFileAPI default_fileapi = { }; typedef struct { - projCtx ctx; + PJ_CONTEXT *ctx; FILE *fp; } stdio_pafile; @@ -70,7 +70,7 @@ projFileAPI *pj_get_default_fileapi(void) /* stdio_fopen() */ /************************************************************************/ -static PAFile stdio_fopen(projCtx ctx, const char *filename, +static PAFile stdio_fopen(PJ_CONTEXT *ctx, const char *filename, const char *access) { stdio_pafile *pafile; @@ -140,7 +140,7 @@ static void stdio_fclose(PAFile file) /* Open a file using the provided file io hooks. */ /************************************************************************/ -PAFile pj_ctx_fopen(projCtx ctx, const char *filename, const char *access) +PAFile pj_ctx_fopen(PJ_CONTEXT *ctx, const char *filename, const char *access) { return ctx->fileapi_legacy->FOpen(ctx, filename, access); } @@ -148,7 +148,7 @@ PAFile pj_ctx_fopen(projCtx ctx, const char *filename, const char *access) /************************************************************************/ /* pj_ctx_fread() */ /************************************************************************/ -size_t pj_ctx_fread(projCtx ctx, void *buffer, size_t size, size_t nmemb, PAFile file) +size_t pj_ctx_fread(PJ_CONTEXT *ctx, void *buffer, size_t size, size_t nmemb, PAFile file) { return ctx->fileapi_legacy->FRead(buffer, size, nmemb, file); } @@ -156,7 +156,7 @@ size_t pj_ctx_fread(projCtx ctx, void *buffer, size_t size, size_t nmemb, PAFile /************************************************************************/ /* pj_ctx_fseek() */ /************************************************************************/ -int pj_ctx_fseek(projCtx ctx, PAFile file, long offset, int whence) +int pj_ctx_fseek(PJ_CONTEXT *ctx, PAFile file, long offset, int whence) { return ctx->fileapi_legacy->FSeek(file, offset, whence); } @@ -164,7 +164,7 @@ int pj_ctx_fseek(projCtx ctx, PAFile file, long offset, int whence) /************************************************************************/ /* pj_ctx_ftell() */ /************************************************************************/ -long pj_ctx_ftell(projCtx ctx, PAFile file) +long pj_ctx_ftell(PJ_CONTEXT *ctx, PAFile file) { return ctx->fileapi_legacy->FTell(file); } @@ -172,7 +172,7 @@ long pj_ctx_ftell(projCtx ctx, PAFile file) /************************************************************************/ /* pj_ctx_fclose() */ /************************************************************************/ -void pj_ctx_fclose(projCtx ctx, PAFile file) +void pj_ctx_fclose(PJ_CONTEXT *ctx, PAFile file) { ctx->fileapi_legacy->FClose(file); } @@ -185,7 +185,7 @@ void pj_ctx_fclose(projCtx ctx, PAFile file) /* taken. */ /************************************************************************/ -char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file) +char *pj_ctx_fgets(PJ_CONTEXT *ctx, char *line, int size, PAFile file) { long start = pj_ctx_ftell(ctx, file); size_t bytes_read; @@ -218,7 +218,7 @@ char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file) /* pj_ctx_set_fileapi() */ /************************************************************************/ -void pj_ctx_set_fileapi( projCtx ctx, projFileAPI *fileapi ) +void pj_ctx_set_fileapi( PJ_CONTEXT *ctx, projFileAPI *fileapi ) { if (nullptr==ctx) @@ -230,7 +230,7 @@ void pj_ctx_set_fileapi( projCtx ctx, projFileAPI *fileapi ) /* pj_ctx_get_fileapi() */ /************************************************************************/ -projFileAPI *pj_ctx_get_fileapi( projCtx ctx ) +projFileAPI *pj_ctx_get_fileapi( PJ_CONTEXT *ctx ) { if (nullptr==ctx) -- cgit v1.2.3 From 7f79fe7325a74d2a9eac93d7081a107ae54bb877 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Mon, 16 Nov 2020 21:10:45 +0100 Subject: Remove legacy file API --- src/fileapi.cpp | 240 -------------------------------------------------------- 1 file changed, 240 deletions(-) delete mode 100644 src/fileapi.cpp (limited to 'src/fileapi.cpp') diff --git a/src/fileapi.cpp b/src/fileapi.cpp deleted file mode 100644 index 0af83926..00000000 --- a/src/fileapi.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/****************************************************************************** - * Project: PROJ.4 - * Purpose: Implementation of the pj_ctx_* file api, and the default stdio - * based implementation. - * Author: Frank Warmerdam, warmerdam@pobox.com - * - ****************************************************************************** - * Copyright (c) 2013, Frank Warmerdam - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - *****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "proj.h" -#include "proj_internal.h" -#include "filemanager.hpp" - -static PAFile stdio_fopen(PJ_CONTEXT *ctx, const char *filename, - const char *access); -static size_t stdio_fread(void *buffer, size_t size, size_t nmemb, - PAFile file); -static int stdio_fseek(PAFile file, long offset, int whence); -static long stdio_ftell(PAFile file); -static void stdio_fclose(PAFile file); - -static projFileAPI default_fileapi = { - stdio_fopen, - stdio_fread, - stdio_fseek, - stdio_ftell, - stdio_fclose -}; - -typedef struct { - PJ_CONTEXT *ctx; - FILE *fp; -} stdio_pafile; - -/************************************************************************/ -/* pj_get_default_fileapi() */ -/************************************************************************/ - -projFileAPI *pj_get_default_fileapi(void) -{ - return &default_fileapi; -} - -/************************************************************************/ -/* stdio_fopen() */ -/************************************************************************/ - -static PAFile stdio_fopen(PJ_CONTEXT *ctx, const char *filename, - const char *access) -{ - stdio_pafile *pafile; - FILE *fp; - - fp = fopen(filename, access); - if (fp == nullptr) - { - return nullptr; - } - - pafile = (stdio_pafile *) malloc(sizeof(stdio_pafile)); - if (!pafile) - { - pj_ctx_set_errno(ctx, ENOMEM); - fclose(fp); - return nullptr; - } - - pafile->fp = fp; - pafile->ctx = ctx; - return (PAFile) pafile; -} - -/************************************************************************/ -/* stdio_fread() */ -/************************************************************************/ - -static size_t stdio_fread(void *buffer, size_t size, size_t nmemb, - PAFile file) -{ - stdio_pafile *pafile = (stdio_pafile *) file; - return fread(buffer, size, nmemb, pafile->fp); -} - -/************************************************************************/ -/* stdio_fseek() */ -/************************************************************************/ -static int stdio_fseek(PAFile file, long offset, int whence) -{ - stdio_pafile *pafile = (stdio_pafile *) file; - return fseek(pafile->fp, offset, whence); -} - -/************************************************************************/ -/* stdio_ftell() */ -/************************************************************************/ -static long stdio_ftell(PAFile file) -{ - stdio_pafile *pafile = (stdio_pafile *) file; - return ftell(pafile->fp); -} - -/************************************************************************/ -/* stdio_fclose() */ -/************************************************************************/ -static void stdio_fclose(PAFile file) -{ - stdio_pafile *pafile = (stdio_pafile *) file; - fclose(pafile->fp); - free(pafile); -} - -/************************************************************************/ -/* pj_ctx_fopen() */ -/* */ -/* Open a file using the provided file io hooks. */ -/************************************************************************/ - -PAFile pj_ctx_fopen(PJ_CONTEXT *ctx, const char *filename, const char *access) -{ - return ctx->fileapi_legacy->FOpen(ctx, filename, access); -} - -/************************************************************************/ -/* pj_ctx_fread() */ -/************************************************************************/ -size_t pj_ctx_fread(PJ_CONTEXT *ctx, void *buffer, size_t size, size_t nmemb, PAFile file) -{ - return ctx->fileapi_legacy->FRead(buffer, size, nmemb, file); -} - -/************************************************************************/ -/* pj_ctx_fseek() */ -/************************************************************************/ -int pj_ctx_fseek(PJ_CONTEXT *ctx, PAFile file, long offset, int whence) -{ - return ctx->fileapi_legacy->FSeek(file, offset, whence); -} - -/************************************************************************/ -/* pj_ctx_ftell() */ -/************************************************************************/ -long pj_ctx_ftell(PJ_CONTEXT *ctx, PAFile file) -{ - return ctx->fileapi_legacy->FTell(file); -} - -/************************************************************************/ -/* pj_ctx_fclose() */ -/************************************************************************/ -void pj_ctx_fclose(PJ_CONTEXT *ctx, PAFile file) -{ - ctx->fileapi_legacy->FClose(file); -} - -/************************************************************************/ -/* pj_ctx_fgets() */ -/* */ -/* A not very optimal implementation of fgets on top of */ -/* fread(). If we end up using this a lot more care should be */ -/* taken. */ -/************************************************************************/ - -char *pj_ctx_fgets(PJ_CONTEXT *ctx, char *line, int size, PAFile file) -{ - long start = pj_ctx_ftell(ctx, file); - size_t bytes_read; - int i; - int max_size; - - line[size-1] = '\0'; - bytes_read = pj_ctx_fread(ctx, line, 1, size-1, file); - if(bytes_read == 0) - return nullptr; - if(bytes_read < (size_t)size) - { - line[bytes_read] = '\0'; - } - - max_size = (int)MIN(bytes_read, (size_t)(size > 2 ? size - 2 : 0)); - for( i = 0; i < max_size; i++) - { - if (line[i] == '\n') - { - line[i+1] = '\0'; - pj_ctx_fseek(ctx, file, start + i + 1, SEEK_SET); - break; - } - } - return line; -} - -/************************************************************************/ -/* pj_ctx_set_fileapi() */ -/************************************************************************/ - -void pj_ctx_set_fileapi( PJ_CONTEXT *ctx, projFileAPI *fileapi ) - -{ - if (nullptr==ctx) - return; - ctx->fileapi_legacy = fileapi; -} - -/************************************************************************/ -/* pj_ctx_get_fileapi() */ -/************************************************************************/ - -projFileAPI *pj_ctx_get_fileapi( PJ_CONTEXT *ctx ) - -{ - if (nullptr==ctx) - return nullptr; - return ctx->fileapi_legacy; -} - -- cgit v1.2.3