/usr/include/fcitx-config/fcitx-config.h is in fcitx-libs-dev 1:4.2.9.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | /***************************************************************************
* Copyright (C) 2010~2010 by CSSlayer *
* wengxt@gmail.com *
* *
* 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., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
/**
* @defgroup FcitxConfig FcitxConfig
*
* FcitxConfig includes a lot of configuration related macro and function.
* Macro can be easily used to bind a struct with configuration
*
* Fcitx configuration file can be easily mapped to corresponding user interface,
* and you don't need to write any user interface at all.
*
* FcitxConfig can be also used to implement native user interface.
*
* Here is a common example for use macro binding with a struct
*
* @code
* typedef struct _FcitxProfile {
* FcitxGenericConfig gconfig;
* boolean bUseRemind;
* char* imName;
* boolean bUseWidePunc;
* boolean bUseFullWidthChar;
* boolean bUsePreedit;
* char* imList;
* } FcitxProfile;
* @endcode
*
* A config struct need to put FcitxGenericConfig as first field.
* Following code will define a function
*
* @code
* CONFIG_BINDING_BEGIN_WITH_ARG(FcitxProfile, FcitxInstance* instance)
* CONFIG_BINDING_REGISTER("Profile", "FullWidth", bUseFullWidthChar)
* CONFIG_BINDING_REGISTER("Profile", "UseRemind", bUseRemind)
* CONFIG_BINDING_REGISTER_WITH_FILTER_ARG("Profile", "IMName", imName, FilterIMName, instance)
* CONFIG_BINDING_REGISTER("Profile", "WidePunc", bUseWidePunc)
* CONFIG_BINDING_REGISTER("Profile", "PreeditStringInClientWindow", bUsePreedit)
* CONFIG_BINDING_REGISTER_WITH_FILTER_ARG("Profile", "EnabledIMList", imList, FilterIMList, instance)
* CONFIG_BINDING_END()
* @endcode
*
* Then you will get following function:
*
* @code
* void FcitxProfileConfigBind( FcitxProfile* config, FcitxConfigFile* cfile, FcitxConfigFileDesc* cfdesc, FcitxInstance* instance )
* @endcode
*
* If you need forward declaration, you can used
* @code
* CONFIG_BINDING_DECLARE_WITH_ARG(FcitxProfile, FcitxInstance* instance)
* @endcode
*
* The FcitxConfigFileDesc pointer is coresponding to the .desc file, which need to be placed
* under share/fcitx/configdesc/
*
* You can use following macro to define a define to load FcitxConfigFileDesc* pointer,
* second argument is the .desc file name.
*
* The FcitxConfigFileDesc pointer returned by this macro is a static variable, so it should not be
* free'd, and will only load once.
*
* @code
* CONFIG_DESC_DEFINE(GetProfileDesc, "profile.desc")
* @endcode
*/
/**
* @addtogroup FcitxConfig
* @{
*/
/**
* @file fcitx-config.h
* @author CSSlayer wengxt@gmail.com
* @date 2010-04-30
*
* Fcitx configure file read-write
*/
#ifndef _FCITX_FCITX_CONFIG_H_
#define _FCITX_FCITX_CONFIG_H_
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <fcitx-utils/uthash.h>
#include <fcitx-utils/utils.h>
#include <fcitx-utils/log.h>
#include <fcitx-config/xdg.h>
#include <fcitx-config/hotkey.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
* The Color type in config file
**/
typedef struct _FcitxConfigColor {
double r; /**< red */
double g; /**< green */
double b; /**< blue */
} FcitxConfigColor;
/**
* config value type
**/
typedef enum _FcitxConfigType {
T_Integer,
T_Color,
T_String,
T_Char,
T_Boolean,
T_Enum,
T_File,
T_Hotkey,
T_Font,
T_I18NString
} FcitxConfigType;
/**
* The sync direction
**/
typedef enum _FcitxConfigSync {
Raw2Value,
Value2Raw,
ValueFree
} FcitxConfigSync;
/**
* Sync result
**/
typedef enum _FcitxConfigSyncResult {
SyncSuccess,
SyncNoBinding,
SyncInvalid
} FcitxConfigSyncResult;
/**
* The value of config
**/
typedef union _FcitxConfigValueType {
void *untype; /**< simple pointer */
int *integer; /**< pointer to integer */
boolean *boolvalue; /**< pointer to boolean */
struct _FcitxHotkey *hotkey; /**< pointer to two hotkeys */
FcitxConfigColor *color; /**< pointer to color */
int *enumerate; /**< pointer to enum */
char **string; /**< pointer to string */
char *chr; /**< pointer to char */
} FcitxConfigValueType;
typedef struct _FcitxConfigGroup FcitxConfigGroup; /**< FcitxConfigGroup */
typedef struct _FcitxConfigOption FcitxConfigOption; /**< FcitxConfigOption */
typedef struct _FcitxConfigFileDesc FcitxConfigFileDesc; /**< FcitxConfigFileDesc */
typedef struct _FcitxConfigGroupDesc FcitxConfigGroupDesc; /**< FcitxConfigGroupDesc */
typedef struct _FcitxConfigOptionDesc FcitxConfigOptionDesc; /**< FcitxConfigOptionDesc */
typedef struct _FcitxConfigOptionDesc2 FcitxConfigOptionDesc2; /**< FcitxConfigOptionDesc2 */
typedef struct _FcitxGenericConfig FcitxGenericConfig; /**< FcitxGenericConfig */
typedef struct _FcitxConfigOptionSubkey FcitxConfigOptionSubkey; /**< FcitxConfigOptionSubkey */
typedef union _FcitxConfigConstrain FcitxConfigConstrain /** < FcitxConfigConstrain */;
/**
* sync filter function
**/
typedef void (*FcitxSyncFilter)(FcitxGenericConfig* config, FcitxConfigGroup *group, FcitxConfigOption *option, void* value, FcitxConfigSync sync, void* arg);
/**
* Enum value type description
**/
typedef struct _FcitxConfigEnum {
char **enumDesc; /**< enum string description, a user visble string */
int enumCount; /**< length of enumDesc */
} FcitxConfigEnum;
/**
* Config file contains multiple config groups, and the opposite config file description
**/
typedef struct _FcitxConfigFile {
FcitxConfigFileDesc *fileDesc; /**< configuration file description */
FcitxConfigGroup* groups; /**< contained group */
} FcitxConfigFile;
/**
* A generic config struct, config struct can derive from it.
* @code
* struct TestConfig {
* FcitxGenericConfig gconfig;
* int own_value;
* };
* @endcode
**/
struct _FcitxGenericConfig {
/**
* config file pointer
**/
FcitxConfigFile *configFile;
};
/**
* Config Option Description, it describe a Key=Value entry in config file.
**/
struct _FcitxConfigOptionDesc {
char *optionName; /**< option name */
char *desc; /**< optiont description string, user visible */
FcitxConfigType type; /**< value type */
char *rawDefaultValue; /**< raw string default value */
FcitxConfigEnum configEnum; /**< if type is enum, the enum item info */
UT_hash_handle hh; /**< hash handle */
};
union _FcitxConfigConstrain {
struct {
int min;
int max;
} integerConstrain;
struct {
size_t maxLength;
} stringConstrain;
struct {
boolean disallowNoModifer;
boolean allowModifierOnly;
} hotkeyConstrain;
void* padding[10];
};
/**
* Config option description v2
*/
struct _FcitxConfigOptionDesc2 {
struct _FcitxConfigOptionDesc optionDesc;
boolean advance;
FcitxConfigConstrain constrain;
char* longDesc;
void* padding[16];
};
/**
* Config Group Description, it describe a [Gruop] in config file
**/
struct _FcitxConfigGroupDesc {
char *groupName; /**< Group Name */
FcitxConfigOptionDesc *optionsDesc; /**< Hash table for option description */
UT_hash_handle hh; /**< hash handle */
};
/**
* Description of a config file
**/
struct _FcitxConfigFileDesc {
FcitxConfigGroupDesc *groupsDesc; /**< group description */
char* domain; /**< domain for translation */
};
/**
* Config Option in config file, Key=Value entry
**/
struct _FcitxConfigOption {
char *optionName; /**< option name */
char *rawValue; /**< raw string value */
FcitxConfigValueType value; /**< value type */
FcitxSyncFilter filter; /**< filter function */
void *filterArg; /**< argument for filter function */
union {
FcitxConfigOptionDesc *optionDesc; /**< option description pointer */
FcitxConfigOptionDesc2 *optionDesc2; /**< option description pointer */
};
FcitxConfigOptionSubkey *subkey; /**< subkey which only used with I18NString */
UT_hash_handle hh; /**< hash handle */
} ;
/**
* Config Option subkey in config file, Key[Subkey]=Value entry
**/
struct _FcitxConfigOptionSubkey {
char *subkeyName; /**< subkey name */
char *rawValue; /**< subkey raw value */
UT_hash_handle hh; /**< hash handle */
};
/**
* Config group in config file, [Group] Entry
**/
struct _FcitxConfigGroup {
/**
* Group Name, unique in FcitxConfigFile
**/
char *groupName;
/**
* Group Description
**/
FcitxConfigGroupDesc *groupDesc;
/**
* Option store with a hash table
**/
FcitxConfigOption* options;
/**
* UTHash handler
**/
UT_hash_handle hh;
};
/**
* declare the binding function
**/
#define CONFIG_BINDING_DECLARE(config_type) \
void config_type##ConfigBind(config_type* config, FcitxConfigFile* cfile, FcitxConfigFileDesc* cfdesc);
/**
* declare the binding function, with extra argument
**/
#define CONFIG_BINDING_DECLARE_WITH_ARG(config_type, arg...) \
void config_type##ConfigBind(config_type* config, FcitxConfigFile* cfile, FcitxConfigFileDesc* cfdesc, arg);
/**
* define the binding function
* each binding group for a config file will define a new function
* the structure is like: <br>
* CONFIG_BINDING_BEGIN <br>
* CONFIG_BINDING_REGISTER <br>
* .... <br>
* CONFIG_BINDING_REGISTER <br>
* CONFIG_BINDING_END
**/
#define CONFIG_BINDING_BEGIN(config_type) \
void config_type##ConfigBind(config_type* config, FcitxConfigFile* cfile, FcitxConfigFileDesc* cfdesc) { \
(void) cfdesc; \
FcitxGenericConfig *gconfig = (FcitxGenericConfig*) config; \
if (gconfig->configFile) { \
FcitxConfigFreeConfigFile(gconfig->configFile); \
} \
gconfig->configFile = cfile;
/** register binding and call it with extra argument */
#define CONFIG_BINDING_BEGIN_WITH_ARG(config_type, arg...) \
void config_type##ConfigBind(config_type* config, FcitxConfigFile* cfile, FcitxConfigFileDesc* cfdesc, arg) { \
(void) cfdesc; \
FcitxGenericConfig *gconfig = (FcitxGenericConfig*) config; \
if (gconfig->configFile) { \
FcitxConfigFreeConfigFile(gconfig->configFile); \
} \
gconfig->configFile = cfile;
/**
* register a binding
**/
#define CONFIG_BINDING_REGISTER(g, o, var) \
do { \
FcitxConfigBindValue(cfile, g, o, &config->var, NULL, NULL); \
} while(0);
/**
* register a binding with filter
**/
#define CONFIG_BINDING_REGISTER_WITH_FILTER(g, o, var, filter_func) \
do { \
FcitxConfigBindValue(cfile, g, o, &config->var, filter_func, NULL); \
} while(0);
/**
* register a binding with filter and extra argument
**/
#define CONFIG_BINDING_REGISTER_WITH_FILTER_ARG(g, o, var, filter_func, arg) \
do { \
FcitxConfigBindValue(cfile, g, o, &config->var, filter_func, arg); \
} while(0);
/**
* binding group end
**/
#define CONFIG_BINDING_END() }
/**
* define a singleton function to load config file description
**/
#define CONFIG_DESC_DEFINE(funcname, path) \
FcitxConfigFileDesc *funcname() \
{ \
static FcitxConfigFileDesc *configDesc = NULL; \
if (!configDesc) \
{ \
FILE *tmpfp; \
tmpfp = FcitxXDGGetFileWithPrefix("configdesc", path, "r", NULL); \
if (tmpfp == NULL) \
{ \
FcitxLog(ERROR, "Load Config Description File %s Error, Please Check your install.", path); \
return NULL; \
} \
configDesc = FcitxConfigParseConfigFileDescFp(tmpfp); \
fclose(tmpfp); \
} \
return configDesc; \
}
#define CONFIG_DEFINE_LOAD_AND_SAVE(name, type, config_name) \
CONFIG_DESC_DEFINE(Get##name##Desc, config_name ".desc") \
void name##SaveConfig(type* _cfg) \
{ \
FcitxConfigFileDesc* configDesc = Get##name##Desc(); \
FILE *fp = FcitxXDGGetFileUserWithPrefix("conf", config_name ".config", "w", NULL); \
FcitxConfigSaveConfigFileFp(fp, &_cfg->gconfig, configDesc); \
if (fp) \
fclose(fp); \
} \
boolean name##LoadConfig(type* _cfg) { \
FcitxConfigFileDesc* configDesc = Get##name##Desc(); \
if (configDesc == NULL) \
return false; \
\
FILE *fp; \
fp = FcitxXDGGetFileUserWithPrefix("conf", config_name ".config", "r", NULL); \
if (!fp) { \
if (errno == ENOENT) \
name##SaveConfig(_cfg); \
} \
FcitxConfigFile *cfile = FcitxConfigParseConfigFileFp(fp, configDesc); \
type##ConfigBind(_cfg, cfile, configDesc); \
FcitxConfigBindSync((FcitxGenericConfig*)_cfg); \
if (fp) \
fclose(fp); \
return true; \
} \
/**
* parse a config file with file name.
* even the file cannot be read, or with wrong format,
* it will try to return a usable FcitxConfigFile (missing
* entry with defaul value).
*
* @param filename file name of a configfile
* @param cfdesc config file description
* @return FcitxConfigFile*
**/
FcitxConfigFile *FcitxConfigParseConfigFile(char *filename, FcitxConfigFileDesc* cfdesc);
/**
* parse multi config file, the main difference
* between ParseConfigFile is that it parse multiple file
* and the duplicate entry will be overwritten with the
* file behind the previous one.
*
* @see ParseConfigFile
* @param filename filenames
* @param len len of filenames
* @param cfdesc config file description
* @return FcitxConfigFile*
**/
FcitxConfigFile *FcitxConfigParseMultiConfigFile(char **filename, int len, FcitxConfigFileDesc* cfdesc);
/**
* same with ParseConfigFile, the input is FILE*
*
* @see ParseConfigFile
* @param fp file pointer
* @param fileDesc config file description
* @return FcitxConfigFile*
**/
FcitxConfigFile *FcitxConfigParseConfigFileFp(FILE* fp, FcitxConfigFileDesc* fileDesc);
/**
* same with FcitxConfigParseMultiConfigFileFp, the input is array of FILE*
*
* @see FcitxConfigParseMultiConfigFileFp
* @param fp array of file pointers
* @param len length of fp
* @param fileDesc config file description
* @return FcitxConfigFile*
**/
FcitxConfigFile *FcitxConfigParseMultiConfigFileFp(FILE **fp, int len, FcitxConfigFileDesc* fileDesc);
/**
* Check the raw FcitxConfigFile and try to fill the default value
*
* @param configFile config file
* @param fileDesc config file description
* @return boolean
**/
boolean FcitxConfigCheckConfigFile(FcitxConfigFile *configFile, FcitxConfigFileDesc* fileDesc);
/**
* parse config file description from file
*
* @param filename filename
* @return FcitxConfigFileDesc*
**/
FcitxConfigFileDesc *FcitxConfigParseConfigFileDesc(char* filename);
/**
* parse config file description from file pointer
*
* @see ParseConfigFileDesc
* @param fp file pointer
* @return FcitxConfigFileDesc*
**/
FcitxConfigFileDesc *FcitxConfigParseConfigFileDescFp(FILE* fp);
/**
* internal raw file parse, it can merge the config to existing config file
*
* @param filename file
* @param reuse NULL or existing config file
* @return FcitxConfigFile*
**/
FcitxConfigFile* FcitxConfigParseIni(char* filename, FcitxConfigFile* reuse);
/**
* internal raw file parse, it can merge the config to existing config file
*
* @see ParseIni
* @param fp file pointer
* @param reuse NULL or existing config file
* @return FcitxConfigFile*
**/
FcitxConfigFile* FcitxConfigParseIniFp(FILE* fp, FcitxConfigFile* reuse);
/**
* free a config file
*
* @param cfile config file
* @return void
**/
void FcitxConfigFreeConfigFile(FcitxConfigFile* cfile);
/**
* free a config file description
*
* @param cfdesc config file description
* @return void
**/
void FcitxConfigFreeConfigFileDesc(FcitxConfigFileDesc* cfdesc);
/**
* free a config group
*
* @param group config group
* @return void
**/
void FcitxConfigFreeConfigGroup(FcitxConfigGroup *group);
/**
* free a config group description
*
* @param cgdesc config group description
* @return void
**/
void FcitxConfigFreeConfigGroupDesc(FcitxConfigGroupDesc *cgdesc);
/**
* free a config option
*
* @param option config option
* @return void
**/
void FcitxConfigFreeConfigOption(FcitxConfigOption *option);
/**
* free a config option description
*
* @param codesc config option description
* @return void
**/
void FcitxConfigFreeConfigOptionDesc(FcitxConfigOptionDesc *codesc);
/**
* Save config file to fp, it will do the Value2Raw sync
*
* @param filename file name
* @param cfile config
* @param cdesc config file description
* @return boolean
**/
boolean FcitxConfigSaveConfigFile(char *filename, FcitxGenericConfig *cfile, FcitxConfigFileDesc* cdesc);
/**
* Save config file to fp
*
* @see SaveConfigFile
* @param fp file pointer
* @param cfile config
* @param cdesc config file dsecription
* @return boolean
**/
boolean FcitxConfigSaveConfigFileFp(FILE* fp, FcitxGenericConfig *cfile, FcitxConfigFileDesc* cdesc);
/**
* sync a single value
*
* @param config config
* @param group config group
* @param option config option
* @param sync sync direction
* @return Svoid
**/
void FcitxConfigSyncValue(FcitxGenericConfig* config, FcitxConfigGroup* group, FcitxConfigOption* option, FcitxConfigSync sync);
/**
* Get the binded value type
*
* @param config config
* @param group group name
* @param option option name
* @return FcitxConfigValueType
**/
FcitxConfigValueType FcitxConfigGetBindValue(FcitxGenericConfig *config, const char *group, const char* option);
/**
* Get a option description from config file description, return NULL if not found.
*
* @param cfdesc config file description
* @param groupName group name
* @param optionName option name
* @return const FcitxConfigOptionDesc*
**/
const FcitxConfigOptionDesc* FcitxConfigDescGetOptionDesc(FcitxConfigFileDesc* cfdesc, const char* groupName, const char* optionName);
/**
* Get a option description from config file description, return NULL if not found.
*
* @param cfile config file
* @param groupName group name
* @param optionName option name
* @return const FcitxConfigOptionDesc*
*
* @since 4.1.2
**/
FcitxConfigOption* FcitxConfigFileGetOption(FcitxConfigFile* cfile, const char* groupName, const char* optionName);
/**
* Get the I18NString value from current locale
*
* @param option config option
* @return const char*
**/
const char* FcitxConfigOptionGetLocaleString(FcitxConfigOption* option);
/**
* do the Raw2Value sync for config
*
* @param config config
* @return void
**/
void FcitxConfigBindSync(FcitxGenericConfig* config);
/**
* reset a config to default value
*
* @param config config
* @return Svoid
**/
void FcitxConfigResetConfigToDefaultValue(FcitxGenericConfig* config);
/**
* bind a value with a struct, normally you should use
* CONFIG_BINDING_ series macro, not directly this function.
*
* @param cfile config file
* @param groupName group name
* @param optionName option name
* @param var pointer to value
* @param filter filter function
* @param arg extra argument
* @return void
**/
void FcitxConfigBindValue(FcitxConfigFile* cfile, const char *groupName, const char *optionName, void* var, FcitxSyncFilter filter, void *arg);
/**
* free a binded config struct with all related value
* @param config config
* @return void
*/
void FcitxConfigFree(FcitxGenericConfig* config);
#ifdef __cplusplus
}
#endif
#endif
/**
* @}
*/
// kate: indent-mode cstyle; space-indent on; indent-width 0;
|