gimp/app/unittest/parse_gimprc.c

160 lines
4.0 KiB
C
Raw Normal View History

1999-09-26 01:19:32 +08:00
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "unittest.h"
#include "globals.c"
#include "../gimprc.c"
static void
parse_show_tokens (GList *list)
{
UnknownToken *ut;
while (list)
{
ut = (UnknownToken *) list->data;
printf("value=%10d token=%s\n",ut->value,ut->token);
list = list->next;
}
}
1999-09-27 23:23:58 +08:00
static void global_parse_init(int showit)
1999-09-26 01:19:32 +08:00
{
GList *list;
list = parse_add_directory_tokens();
1999-09-27 23:23:58 +08:00
if (showit)
{
printf("----- Directory Tokens:\n");
parse_show_tokens (list);
}
1999-09-26 01:19:32 +08:00
parse_buffers_init();
/* next_token = -1;*/
}
static void parse_get_absolute_gimprc_file (char *filename)
{
char rfilename[MAXPATHLEN];
if (!g_path_is_absolute (filename))
{
if (g_get_home_dir () != NULL)
{
g_snprintf (rfilename, sizeof (rfilename),
"%s" G_DIR_SEPARATOR_S "%s",
g_get_home_dir (), filename);
strcpy (filename,rfilename);
}
}
}
static void parse_get_system_file(char *alternate, char *libfilename)
{
strcpy (libfilename, gimp_system_rc_file ());
if (alternate != NULL)
strncpy (libfilename, alternate, MAXPATHLEN);
parse_get_absolute_gimprc_file(libfilename);
}
static void parse_get_alt_personal_gimprc(char *alternate, char *filename)
{
if (alternate != NULL)
strncpy (filename, alternate, MAXPATHLEN);
else
strncpy (filename, gimp_personal_rc_file ("gimprc"), MAXPATHLEN);
parse_get_absolute_gimprc_file(filename);
}
1999-10-01 23:16:15 +08:00
static gboolean p_asb_show_result(char *filename)
1999-09-26 01:19:32 +08:00
{
1999-10-01 23:16:15 +08:00
gboolean status;
status = parse_absolute_gimprc_file (filename);
printf("----- Parse Result:%d,filename=%s\n", status,filename);
if (status)
parse_show_tokens (unknown_tokens);
return (status);
}
1999-09-26 01:19:32 +08:00
1999-10-01 23:16:15 +08:00
static void p_show_default_files ()
{
char libfilename[MAXPATHLEN];
char filename[MAXPATHLEN];
1999-09-26 01:19:32 +08:00
1999-10-01 23:16:15 +08:00
parse_get_system_file (alternate_system_gimprc, libfilename);
parse_get_alt_personal_gimprc (alternate_gimprc, filename);
printf("\n----- Parse files: \n");
printf("libfilename= %s\n", libfilename);
printf("filename= %s\n\n", filename);
1999-09-26 01:19:32 +08:00
}
int
main (int argc, char **argv)
{
char libfilename[MAXPATHLEN];
char filename[MAXPATHLEN];
gboolean status;
1999-09-27 23:23:58 +08:00
int showit = 1;
1999-09-26 01:19:32 +08:00
1999-10-01 23:16:15 +08:00
if (argc < 2)
{
printf("%s [option] \n\n",argv[0]);
printf("ex: %s -a # call alternative gimprc parsing\n",argv[0]);
printf("ex: %s -p # call parse_gimprc ()\n",argv[0]);
printf("ex: %s -h # show default files\n",argv[0]);
parse_get_system_file (alternate_system_gimprc, libfilename);
printf("ex: %s -f%s # parse a files\n",argv[0], libfilename);
exit (1);
}
if (strcmp (argv[1], "-h") == 0)
{
p_show_default_files ();
exit (0);
}
if (strcmp (argv[1], "-p") == 0)
1999-09-27 23:23:58 +08:00
showit = 0;
global_parse_init(showit);
1999-09-26 01:19:32 +08:00
1999-10-01 23:16:15 +08:00
if (strcmp (argv[1], "-a") == 0)
1999-09-27 23:23:58 +08:00
{
1999-10-01 23:16:15 +08:00
p_show_default_files ();
1999-09-27 23:23:58 +08:00
parse_get_system_file (alternate_system_gimprc, libfilename);
parse_get_alt_personal_gimprc(alternate_gimprc, filename);
1999-10-01 23:16:15 +08:00
status = p_asb_show_result(libfilename);
status = p_asb_show_result(filename);
}
else if (strncmp (argv[1], "-f",2) == 0)
{
strcpy (filename, argv[1] + 2);
status = p_asb_show_result(filename);
1999-09-27 23:23:58 +08:00
}
1999-10-01 23:16:15 +08:00
else if (strcmp (argv[1], "-p") == 0)
1999-09-27 23:23:58 +08:00
{
parse_gimprc ();
1999-09-26 01:19:32 +08:00
parse_show_tokens (unknown_tokens);
1999-09-27 23:23:58 +08:00
}
1999-09-26 01:19:32 +08:00
}