Skip to content

Commit

Permalink
Remove redundant header and respect C89
Browse files Browse the repository at this point in the history
  • Loading branch information
emilienlemaire committed Sep 11, 2023
1 parent 9ca841a commit 9b436b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
50 changes: 27 additions & 23 deletions libcob/cobprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
along with GnuCOBOL. If not, see <https://www.gnu.org/licenses/>.
*/

#define COB_LIB_EXPIMP

#include "config.h"
#include "cobprof.h"

#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* include internal and external libcob definitions, forcing exports */
#define COB_LIB_EXPIMP
#include "coblocal.h"

#include "tarstamp.h"
#include "config.h"
#include "cobprof.h"

#if HAVE_XLSXWRITER_H
#include <xlsxwriter.h>
#elif HAVE_XLSXWRITER_XLSXWRITER_H
#include <xlsxwriter/xlsxwriter.h>
#endif

static bool is_init = false;


static int is_init = 0;

static size_t called_paragraphs[255][2];
static long start_times[255];
Expand All @@ -62,7 +66,7 @@ get_str_index(const char *str, const char **arr, size_t arr_len)

static long
get_time(long start_time, struct timespec stop_time) {
// This allows to count the number of times a procedure is ran while testing the compiler
/* This allows to count the number of times a procedure is ran while testing the compiler */
if (getenv ("COB_IS_RUNNING_IN_TESTMODE")) {
return 1;
}
Expand Down Expand Up @@ -99,7 +103,7 @@ cob_prof_init(long (*total_times_p)[255],
start_times[i] = ULONG_MAX;
}

is_init = true;
is_init = 1;
}

void
Expand All @@ -111,21 +115,21 @@ cob_prof_enter_paragraph(const char *section, const char *paragraph)

if (!is_init) return;

// We should always have a section when entering a paragraph.
/* We should always have a section when entering a paragraph. */
if (!section) return;

sec_idx = get_str_index (section, sections, sections_count);
if (sec_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find section %s, aborting profiling.\n", section);
is_init = false;
is_init = 0;
return;
}

para_idx = get_str_index (paragraph, para_per_sections[sec_idx], max_paragraphs_count);
if (para_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find paragraph %s IN %s, aborting profiling.\n",
section, paragraph);
is_init = false;
is_init = 0;
return;
}

Expand All @@ -149,7 +153,7 @@ cob_prof_enter_section(const char *section)

if (sec_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find section %s, aborting profiling.\n", section);
is_init = false;
is_init = 0;
return;
}

Expand All @@ -174,7 +178,7 @@ cob_prof_exit_paragraph(const char *section, const char *paragraph)

if (sec_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find section %s, aborting profiling.\n", section);
is_init = false;
is_init = 0;
return;
}

Expand All @@ -183,7 +187,7 @@ cob_prof_exit_paragraph(const char *section, const char *paragraph)
if (para_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find paragraph %s IN %s, aborting profiling.\n",
section, paragraph);
is_init = false;
is_init = 0;
return;
}

Expand Down Expand Up @@ -214,7 +218,7 @@ cob_prof_exit_section(const char *section)

if (sec_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find section %s, aborting profiling.\n", section);
is_init = false;
is_init = 0;
return;
}

Expand All @@ -224,7 +228,7 @@ cob_prof_exit_section(const char *section)
size_t curr_sec = called_paragraphs[current_idx][0];
size_t curr_para = called_paragraphs[current_idx][1];

if (curr_sec != sec_idx) return; // We exited all paragraphs entered in this section
if (curr_sec != sec_idx) return; /* We exited all paragraphs entered in this section */

if (curr_para == ULONG_MAX) {
total_times[curr_sec][254] += get_time (start_times[current_idx], ts);
Expand All @@ -233,7 +237,7 @@ cob_prof_exit_section(const char *section)
}
current_idx--;
if (curr_sec == sec_idx && curr_para == ULONG_MAX) {
// We exit the last PERFORM of this section
/* We exit the last PERFORM of this section */
return;
}
}
Expand All @@ -253,12 +257,12 @@ cob_prof_goto(const char *section, const char *paragraph)

if (section == NULL) {

// GO TO exit : section = NULL, paragraph = invalid section name
/* GO TO exit : section = NULL, paragraph = invalid section name */
if (get_str_index (paragraph, sections, sections_count) == ULONG_MAX) {
return;
}

// GO TO section : section = NULL, paragraph = target section name
/* GO TO section : section = NULL, paragraph = target section name */
while (current_idx != ULONG_MAX) {
cob_prof_exit_section (sections[called_paragraphs[current_idx][0]]);
}
Expand All @@ -270,7 +274,7 @@ cob_prof_goto(const char *section, const char *paragraph)

if (sec_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find section %s, aborting profiling.\n", section);
is_init = false;
is_init = 0;
return;
}

Expand All @@ -279,7 +283,7 @@ cob_prof_goto(const char *section, const char *paragraph)
if (para_idx == ULONG_MAX) {
fprintf (stderr, "[cob_prof] Could not find paragraph %s IN %s, aborting profiling\n",
section, paragraph);
is_init = false;
is_init = 0;
return;
}

Expand Down Expand Up @@ -423,7 +427,7 @@ cob_prof_end()

total_times = NULL;

is_init = false;
is_init = 0;

}

27 changes: 1 addition & 26 deletions libcob/cobprof.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2003-2023 Free Software Foundation, Inc.
Copyright (C) 2023 Free Software Foundation, Inc.
Written by Emilien Lemaire
This file is part of GnuCOBOL.
Expand All @@ -21,31 +21,6 @@
#ifndef cob_prof_h
#define cob_prof_h

#ifndef COB_EXT_EXPORT
#if ((defined(_WIN32) || defined(__CYGWIN__)) && !defined(__clang__))
#define COB_EXT_EXPORT __declspec(dllexport) extern
#else
#define COB_EXT_EXPORT extern
#endif
#endif
#ifndef COB_EXT_IMPORT
#if ((defined(_WIN32) || defined(__CYGWIN__)) && !defined(__clang__))
#define COB_EXT_IMPORT __declspec(dllimport) extern
#else
#define COB_EXT_IMPORT extern
#endif
#endif

#ifndef COB_EXPIMP
#ifdef COB_LIB_EXPIMP
#define COB_EXPIMP COB_EXT_EXPORT
#else
#define COB_EXPIMP COB_EXT_IMPORT
#endif
#endif

#include <limits.h>
#include <stdbool.h>
#include <stddef.h>

COB_EXPIMP void cob_prof_init(long(*)[255], /* total_times */
Expand Down
2 changes: 1 addition & 1 deletion libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
along with GnuCOBOL. If not, see <https://www.gnu.org/licenses/>.
*/

#include "cobprof.h"
#include "tarstamp.h"
#include "config.h"

Expand Down Expand Up @@ -162,6 +161,7 @@
/* include internal and external libcob definitions, forcing exports */
#define COB_LIB_EXPIMP
#include "coblocal.h"
#include "cobprof.h"

#include "cobgetopt.h"

Expand Down

0 comments on commit 9b436b8

Please sign in to comment.