[COMPILER]
* BUG: As usual, forgot to add the new source files. git-svn-id: svn://localhost/gambas/trunk@5312 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
25b8edfd44
commit
a78a58f0f4
179
main/gbc/gbc_help.c
Normal file
179
main/gbc/gbc_help.c
Normal file
@ -0,0 +1,179 @@
|
||||
/***************************************************************************
|
||||
|
||||
gbc_help.c
|
||||
|
||||
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#define __GBC_HELP_C
|
||||
|
||||
#include "gb_common.h"
|
||||
#include "gb_error.h"
|
||||
#include "gb_file.h"
|
||||
|
||||
#include "gbc_compile.h"
|
||||
#include "gbc_help.h"
|
||||
|
||||
//#define DEBUG_ME 1
|
||||
|
||||
static bool get_help_at(int i, const char **help, int *len)
|
||||
{
|
||||
const char *p;
|
||||
int n = 0;
|
||||
|
||||
if (i < 0 || i >= ARRAY_count(JOB->help))
|
||||
return TRUE;
|
||||
|
||||
p = JOB->help[i];
|
||||
if (!p)
|
||||
return TRUE;
|
||||
|
||||
if (HELP_is_void_line(p))
|
||||
{
|
||||
*help = p;
|
||||
n = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*p == '\'')
|
||||
p++;
|
||||
if (*p == ' ')
|
||||
p++;
|
||||
*help = p;
|
||||
while (*p++ != '\n')
|
||||
n++;
|
||||
}
|
||||
|
||||
*len = n;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void HELP_add_at_current_line(const char *help)
|
||||
{
|
||||
int count = ARRAY_count(JOB->help);
|
||||
int new_max;
|
||||
|
||||
if (!count)
|
||||
{
|
||||
if (HELP_is_void_line(help))
|
||||
return;
|
||||
|
||||
ARRAY_create_inc(&JOB->help, 256);
|
||||
|
||||
JOB->help_first_line = JOB->line;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_max = JOB->line - JOB->help_first_line;
|
||||
|
||||
if (new_max < count) // Already added!
|
||||
return;
|
||||
|
||||
if (new_max > count)
|
||||
ARRAY_add_many_void(&JOB->help, new_max - count);
|
||||
}
|
||||
|
||||
*ARRAY_add(&JOB->help) = help;
|
||||
|
||||
#if DEBUG_ME
|
||||
int len;
|
||||
get_help_at(JOB->line - JOB->help_first_line, &help, &len);
|
||||
fprintf(stderr, "add help comment: %d %p %d: %.*s\n", JOB->line, help, ARRAY_count(JOB->help), len, help);
|
||||
#endif
|
||||
}
|
||||
|
||||
void HELP_search_and_print(FILE *file, int line)
|
||||
{
|
||||
const char *help;
|
||||
int len, i, ii;
|
||||
|
||||
if (!JOB->help)
|
||||
return;
|
||||
|
||||
#if DEBUG_ME
|
||||
fprintf(stderr, "HELP_search_and_print: %s: %d\n", FILE_get_name(JOB->name), line);
|
||||
#endif
|
||||
|
||||
i = line - JOB->help_first_line;
|
||||
|
||||
if (i < 0)
|
||||
return;
|
||||
|
||||
if (JOB->help[i])
|
||||
{
|
||||
if (!get_help_at(i, &help, &len))
|
||||
{
|
||||
#if DEBUG_ME
|
||||
fprintf(stderr, "[%d] '' %.*s\n", line, len, help);
|
||||
#endif
|
||||
fprintf(file, "'%.*s\n", len, help);
|
||||
JOB->help[i] = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ii = i;
|
||||
i--;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (!JOB->help[i] || HELP_is_for_class(JOB->help[i]))
|
||||
break;
|
||||
i--;
|
||||
}
|
||||
|
||||
for (i++; i < ii; i++)
|
||||
{
|
||||
if (HELP_is_void_line(JOB->help[i]))
|
||||
continue;
|
||||
|
||||
if (get_help_at(i, &help, &len))
|
||||
continue;
|
||||
|
||||
#if DEBUG_ME
|
||||
fprintf(stderr, "{%d} ''%.*s\n", line + i - ii, len, help);
|
||||
#endif
|
||||
fprintf(file, "'%.*s\n", len, help);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HELP_search_and_print_for_class(FILE *file)
|
||||
{
|
||||
int i;
|
||||
const char *help;
|
||||
int len;
|
||||
|
||||
if (!JOB->help)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ARRAY_count(JOB->help); i++)
|
||||
{
|
||||
if (!JOB->help[i] || !HELP_is_for_class(JOB->help[i]))
|
||||
break;
|
||||
|
||||
if (get_help_at(i, &help, &len))
|
||||
break;
|
||||
|
||||
#if DEBUG_ME
|
||||
fprintf(stderr, "[%d] '''%.*s\n", JOB->help_first_line + i, len, help);
|
||||
#endif
|
||||
fprintf(file, "'%.*s\n", len, help);
|
||||
}
|
||||
}
|
||||
|
40
main/gbc/gbc_help.h
Normal file
40
main/gbc/gbc_help.h
Normal file
@ -0,0 +1,40 @@
|
||||
/***************************************************************************
|
||||
|
||||
gbc_help.h
|
||||
|
||||
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __GBC_HELP_H
|
||||
#define __GBC_HELP_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef __GBC_HELP_C
|
||||
#endif
|
||||
|
||||
void HELP_add_at_current_line(const char *help);
|
||||
void HELP_search_and_print(FILE *file, int line);
|
||||
void HELP_search_and_print_for_class(FILE *file);
|
||||
|
||||
#define HELP_is_help_comment(_ptr) ((_ptr)[0] == '\'' && ((_ptr)[1] == ' ' || ((_ptr)[1] == '\'' && (_ptr)[2] == ' ')))
|
||||
#define HELP_is_for_class(_help) ((_help)[0] == '\'' && (_help)[1] == '\'')
|
||||
#define HELP_is_void_line(_help) ((_help)[0] == '\n' && (_help)[1] == 0)
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user